Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 Oct 2024 16:34:03 GMT
From:      Zhenlei Huang <zlei@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: b6d4e3bee350 - main - ndp: Bring back the -A option for the netlink implementation
Message-ID:  <202410311634.49VGY3O0032190@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=b6d4e3bee350b881b5efea03068c1247985b12fe

commit b6d4e3bee350b881b5efea03068c1247985b12fe
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2024-10-31 16:32:14 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2024-10-31 16:32:14 +0000

    ndp: Bring back the -A option for the netlink implementation
    
    This was lost during the conversion to netlink.
    
    Reviewed by:    kp
    Fixes:          91fbe0819bb9 ndp: convert ndp(8) to netlink
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D47234
---
 usr.sbin/ndp/ndp_netlink.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/usr.sbin/ndp/ndp_netlink.c b/usr.sbin/ndp/ndp_netlink.c
index 546057e5e552..7bd3252f0943 100644
--- a/usr.sbin/ndp/ndp_netlink.c
+++ b/usr.sbin/ndp/ndp_netlink.c
@@ -314,12 +314,24 @@ print_entries_nl(uint32_t ifindex, struct sockaddr_in6 *addr, bool cflag)
 	struct snl_state ss_req = {}, ss_cmd = {};
 	struct snl_parsed_link_simple link = {};
 	struct snl_writer nw;
+	struct nlmsghdr *hdr;
+	struct ndmsg *ndmsg;
 
 	nl_init_socket(&ss_req);
 	snl_init_writer(&ss_req, &nw);
 
-	struct nlmsghdr *hdr = snl_create_msg_request(&nw, RTM_GETNEIGH);
-	struct ndmsg *ndmsg = snl_reserve_msg_object(&nw, struct ndmsg);
+	/* Print header */
+	if (!opts.tflag && !cflag) {
+		char xobuf[200];
+		snprintf(xobuf, sizeof(xobuf),
+		    "{T:/%%-%d.%ds} {T:/%%-%d.%ds} {T:/%%%d.%ds} {T:/%%-9.9s} {T:/%%1s} {T:/%%5s}\n",
+		    W_ADDR, W_ADDR, W_LL, W_LL, W_IF, W_IF);
+		xo_emit(xobuf, "Neighbor", "Linklayer Address", "Netif", "Expire", "S", "Flags");
+	}
+
+again:
+	hdr = snl_create_msg_request(&nw, RTM_GETNEIGH);
+	ndmsg = snl_reserve_msg_object(&nw, struct ndmsg);
 	if (ndmsg != NULL) {
 		ndmsg->ndm_family = AF_INET6;
 		ndmsg->ndm_ifindex = ifindex;
@@ -335,14 +347,6 @@ print_entries_nl(uint32_t ifindex, struct sockaddr_in6 *addr, bool cflag)
 	int count = 0;
 	nl_init_socket(&ss_cmd);
 
-	/* Print header */
-	if (!opts.tflag && !cflag) {
-		char xobuf[200];
-		snprintf(xobuf, sizeof(xobuf),
-		    "{T:/%%-%d.%ds} {T:/%%-%d.%ds} {T:/%%%d.%ds} {T:/%%-9.9s} {T:/%%1s} {T:/%%5s}\n",
-		    W_ADDR, W_ADDR, W_LL, W_LL, W_IF, W_IF);
-		xo_emit(xobuf, "Neighbor", "Linklayer Address", "Netif", "Expire", "S", "Flags");
-	}
 	xo_open_list("neighbor-cache");
 
 	while ((hdr = snl_read_reply_multi(&ss_req, nlmsg_seq, &e)) != NULL) {
@@ -381,6 +385,12 @@ print_entries_nl(uint32_t ifindex, struct sockaddr_in6 *addr, bool cflag)
 		count++;
 		snl_clear_lb(&ss_req);
 	}
+	if (opts.repeat) {
+		xo_emit("\n");
+		xo_flush();
+		sleep(opts.repeat);
+		goto again;
+	}
 	xo_close_list("neighbor-cache");
 
 	snl_free(&ss_req);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202410311634.49VGY3O0032190>