From nobody Mon Oct 23 20:58:57 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4SDnc14N8Hz4yVCP; Mon, 23 Oct 2023 20:58:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SDnc13pByz3SGm; Mon, 23 Oct 2023 20:58:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698094737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=JEOTNHUaouo6PJxJPD5kK3rqBjcgWTF160TBIDX3c0I=; b=pnAwo48WIUnxzbciObgLsxySwGCZargl5+JTMyQRt2BR8j6nDGng0Q1V47+8/Zp+sLexUL xGShjtdhlVDDTZIHKfeyVYhyoaZzmQxG7onTxlxI5a8QGwq5yHeZInxjFx6q5HoJg6k4Ps bA+9eX1wLCQBX7sDrdqwaoI7wk0s/P6nN83EUqS20Ki4Ryru4AMORDqE9bbXSAY5tsWc/L Vb8HIX/bVaITwfr0Ppd4ryc+bwG15eLJ+SIEZRTQMPnHauh6bavpaNJ/P9bInuVJ3oXfOk qnILfxtTsETJq7qTvF0A/zvpoWwuFA+EZtH8dAls5ZFJafbvSthADcEhgXq+xA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1698094737; a=rsa-sha256; cv=none; b=TpWSVK8jUNCGpgVL9ok+FBJd7v2cJdzydOdk7/I6S4p1IJjVjnnzKwZfPeYvEnmegj8MqX 8Bsh1OirdtSMJk9y3L1gPd22apA02PpqElcSW14ptwWOWFE/11MmNENfGsLX/RjZPi2q9K +DIu92JaetTT0EkyK4OW1ssV9hB459AtR/IJifUbTd6y87gUiyg+O/vWGEPBNUF/+21fEA prymz6h6zzGpsn3FOUa9vDJJXkpFJVWqWbA8RnMb9w8K+ZutXglcWn74UmW7wSD0Y+CIHk uOdiBp+tESqoT2Xdf+QlfRHxAnQxohqXdrkXjh73PmkYdoqjN7IR4Amd4xle2Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698094737; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=JEOTNHUaouo6PJxJPD5kK3rqBjcgWTF160TBIDX3c0I=; b=PlMYSTTKCNu3DJu2cuNURrZ+DiQK7RbFa93Vx+nQKp4lV1yqpaE2+wptDJEpIJtdheXWiN E3BK6sTNRIuZS2IegzBEPuGvdcn+VxkICCMafRyR7m+7dXk1LjDN3SPnnfRXPPF1oebEgY 5kX6AcvexnldzmeedmFmfbyGhhWYnAqJFge8UVEbKewiifxBzR7iBeD2HnKgk0oUX9qEJb QgnPtBP6AlmDGbJ9V9sE7bFA1DrHs7Kc9dcZACmSkg4YXNgSjjdgtsC2WT+QnnaEQ/R6cE IAKHdcOtjBTNDNh7xo8AD4JGB4an100vYI0GhZiT8OdvAbpkjDC1Y1KbTBnhlw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4SDnc12Wxlzvps; Mon, 23 Oct 2023 20:58:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39NKwvZK017994; Mon, 23 Oct 2023 20:58:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39NKwvs7017991; Mon, 23 Oct 2023 20:58:57 GMT (envelope-from git) Date: Mon, 23 Oct 2023 20:58:57 GMT Message-Id: <202310232058.39NKwvs7017991@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 934a24e55a78 - main - ndp: improve -c and -d handling in ndp_netlink List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 934a24e55a785e27faf96979602ae1954f384d67 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=934a24e55a785e27faf96979602ae1954f384d67 commit 934a24e55a785e27faf96979602ae1954f384d67 Author: R. Christian McDonald AuthorDate: 2023-10-23 19:43:44 +0000 Commit: Kristof Provost CommitDate: 2023-10-23 20:58:29 +0000 ndp: improve -c and -d handling in ndp_netlink This patch restores/fixes some of the behavior present in pre-netlink ndp(8). 1. Deleting a local address now correctly returns EPERM (instead of ENOENT) 2. ndp -c no longer dumps the entire table while complaining about local addresses 3. Return exit code when deleting entry (e.g. trying ndp -d on a local address is an error) Reviewed by: kp Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D42316 --- usr.sbin/ndp/ndp.c | 8 +++++--- usr.sbin/ndp/ndp.h | 2 +- usr.sbin/ndp/ndp_netlink.c | 13 ++++++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/usr.sbin/ndp/ndp.c b/usr.sbin/ndp/ndp.c index b7bc25dd7aa4..23643dd6c200 100644 --- a/usr.sbin/ndp/ndp.c +++ b/usr.sbin/ndp/ndp.c @@ -201,6 +201,7 @@ main(int argc, char **argv) { int ch, mode = 0; char *arg = NULL; + int ret = 0; pid = getpid(); thiszone = utc_offset(); @@ -280,7 +281,7 @@ main(int argc, char **argv) /*NOTREACHED*/ } xo_open_list("neighbor-cache"); - delete(arg); + ret = delete(arg); xo_close_list("neighbor-cache"); break; case 'I': @@ -353,7 +354,8 @@ main(int argc, char **argv) } xo_close_container("ndp"); xo_finish(); - exit(0); + + return (ret); } /* @@ -841,7 +843,7 @@ static int delete(char *host) { #ifndef WITHOUT_NETLINK - return (delete_nl(0, host)); + return (delete_nl(0, host, true)); /* do warn */ #else return (delete_rtsock(host)); #endif diff --git a/usr.sbin/ndp/ndp.h b/usr.sbin/ndp/ndp.h index 5b2558982e86..f89ab19a9d3f 100644 --- a/usr.sbin/ndp/ndp.h +++ b/usr.sbin/ndp/ndp.h @@ -20,7 +20,7 @@ char *ether_str(struct sockaddr_dl *sdl); char *sec2str(time_t total); int getaddr(char *host, struct sockaddr_in6 *sin6); int print_entries_nl(uint32_t ifindex, struct sockaddr_in6 *addr, bool cflag); -int delete_nl(uint32_t ifindex, char *host); +int delete_nl(uint32_t ifindex, char *host, bool warn); int set_nl(uint32_t ifindex, struct sockaddr_in6 *dst, struct sockaddr_dl *sdl, char *host); diff --git a/usr.sbin/ndp/ndp_netlink.c b/usr.sbin/ndp/ndp_netlink.c index 79bdec2356d0..e18d64175619 100644 --- a/usr.sbin/ndp/ndp_netlink.c +++ b/usr.sbin/ndp/ndp_netlink.c @@ -180,7 +180,7 @@ guess_ifindex(struct snl_state *ss, uint32_t fibnum, const struct sockaddr_in6 * int off = snl_add_msg_attr_nested(&nw, NHA_FREEBSD); snl_add_msg_attr_u32(&nw, NHAF_KID, r.rta_knh_id); - snl_add_msg_attr_u8(&nw, NHAF_FAMILY, AF_INET); + snl_add_msg_attr_u8(&nw, NHAF_FAMILY, AF_INET6); snl_add_msg_attr_u32(&nw, NHAF_TABLE, fibnum); snl_end_attr_nested(&nw, off); @@ -372,13 +372,14 @@ print_entries_nl(uint32_t ifindex, struct sockaddr_in6 *addr, bool cflag) continue; } - print_entry(&neigh, &link); if (cflag) { char dst_str[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, &dst->sin6_addr, dst_str, sizeof(dst_str)); - delete_nl(neigh.nda_ifindex, dst_str); - } + delete_nl(neigh.nda_ifindex, dst_str, false); /* no warn */ + } else + print_entry(&neigh, &link); + count++; snl_clear_lb(&ss_req); } @@ -391,8 +392,9 @@ print_entries_nl(uint32_t ifindex, struct sockaddr_in6 *addr, bool cflag) } int -delete_nl(uint32_t ifindex, char *host) +delete_nl(uint32_t ifindex, char *host, bool warn) { +#define xo_warnx(...) do { if (warn) { xo_warnx(__VA_ARGS__); } } while(0) struct snl_state ss = {}; struct snl_writer nw; struct sockaddr_in6 dst; @@ -458,6 +460,7 @@ delete_nl(uint32_t ifindex, char *host) snl_free(&ss); return (e.error != 0); +#undef xo_warnx /* see above */ } int