Skip to contentSkip to conversation

iproute2: add 'ip monitor acaddress' support

PATCH RESEND In review Yuyang Huang 2 participants 4 messages Jan 17, 2025 – Jan 20, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover iproute2: add 'ip monitor acaddress' support

Patch: https://git.kernel.org/netdev/net-next/c/33d97a07b3ae adds support for netlink notifications for anycast address join and leave. This patch series updates the ip monitor command to support monitoring the address changes.

Patch 1/2: iproute2: expose anycast netlink constants in UAPI is added to make this patch series compile on top of main. Once Linux UAPI headers are synced back, we can discard this patch.

Yuyang Huang (2):
iproute2: expose anycast netlink constants in UAPI
iproute2: add 'ip monitor acaddress' support

 include/uapi/linux/rtnetlink.h |  8 +++++++-
 ip/ipaddress.c                 |  8 ++++++--
 ip/ipmonitor.c                 | 18 ++++++++++++++++--
 man/man8/ip-monitor.8          |  5 +++--
 4 files changed, 32 insertions(+), 7 deletions(-)
Signature · 1 line
2.48.0.rc2.279.g1de40edade-goog
#1 lore raw

PATCH RESEND 1/2 iproute2: expose anycast netlink constants in UAPI

This change adds the following anycast related netlink constants to the UAPI:

* RTNLGRP_IPV6_ACADDR: Netlink multicast groups for IPv6 anycast address changes.
* RTM_NEWANYCAST and RTM_DELANYCAST: Netlink message types for anycast address additions and deletions.

Cc Maciej Żenczykowski <[email protected]>
Cc Lorenzo Colitti <[email protected]>
---
 include/uapi/linux/rtnetlink.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
include/uapi/linux/rtnetlink.h +7 -1
index 478c9d83..6c652145 100644
@@ -100,7 +100,11 @@ enum {
 	RTM_GETMULTICAST,
 #define RTM_GETMULTICAST RTM_GETMULTICAST
 
-	RTM_GETANYCAST	= 62,
+	RTM_NEWANYCAST	= 60,
+#define RTM_NEWANYCAST RTM_NEWANYCAST
+	RTM_DELANYCAST,
+#define RTM_DELANYCAST RTM_DELANYCAST
+	RTM_GETANYCAST,
 #define RTM_GETANYCAST	RTM_GETANYCAST
 
 	RTM_NEWNEIGHTBL	= 64,
@@ -781,6 +785,8 @@ enum rtnetlink_groups {
 #define RTNLGRP_IPV4_MCADDR	RTNLGRP_IPV4_MCADDR
 	RTNLGRP_IPV6_MCADDR,
 #define RTNLGRP_IPV6_MCADDR	RTNLGRP_IPV6_MCADDR
+	RTNLGRP_IPV6_ACADDR,
+#define RTNLGRP_IPV6_ACADDR	RTNLGRP_IPV6_ACADDR
 	__RTNLGRP_MAX
 };
 #define RTNLGRP_MAX	(__RTNLGRP_MAX - 1)
Signature · 1 line
2.48.0.rc2.279.g1de40edade-goog
#2 lore raw

PATCH RESEND 2/2 iproute2: add 'ip monitor acaddress' support

In reply to Yuyang Huang

Enhanced the 'ip monitor' command to track changes in IPv6 anycast addresses. This update allows the command to listen for events related to anycast address additions and deletions by registering to the newly introduced RTNLGRP_IPV6_ACADDR netlink group.

This patch depends on the kernel patch that adds RTNLGRP_IPV6_ACADDR being merged first.

Here is an example usage:

root@uml-x86-64:/# ip monitor acaddress
2: if2    inet6 any 2001:db8:7b:0:528e:a53a:9224:c9c5 scope global
       valid_lft forever preferred_lft forever
Deleted 2: if2    inet6 any 2001:db8:7b:0:528e:a53a:9224:c9c5 scope global
       valid_lft forever preferred_lft forever
Cc Maciej Żenczykowski <[email protected]>
Cc Lorenzo Colitti <[email protected]>
---
 ip/ipaddress.c        |  8 ++++++--
 ip/ipmonitor.c        | 18 ++++++++++++++++--
 man/man8/ip-monitor.8 |  5 +++--
 3 files changed, 25 insertions(+), 6 deletions(-)
ip/ipaddress.c +6 -2
index 679b4c00..70b3d513 100644
@@ -1507,7 +1507,9 @@ int print_addrinfo(struct nlmsghdr *n, void *arg)
 	if (n->nlmsg_type != RTM_NEWADDR &&
 	    n->nlmsg_type != RTM_DELADDR &&
 	    n->nlmsg_type != RTM_NEWMULTICAST &&
-	    n->nlmsg_type != RTM_DELMULTICAST)
+	    n->nlmsg_type != RTM_DELMULTICAST &&
+	    n->nlmsg_type != RTM_NEWANYCAST &&
+	    n->nlmsg_type != RTM_DELANYCAST)
 		return 0;
 	len -= NLMSG_LENGTH(sizeof(*ifa));
 	if (len < 0) {
@@ -1567,7 +1569,9 @@ int print_addrinfo(struct nlmsghdr *n, void *arg)
 
 	print_headers(fp, "[ADDR]");
 
-	if (n->nlmsg_type == RTM_DELADDR || n->nlmsg_type == RTM_DELMULTICAST)
+	if (n->nlmsg_type == RTM_DELADDR ||
+	    n->nlmsg_type == RTM_DELMULTICAST ||
+	    n->nlmsg_type == RTM_DELANYCAST)
 		print_bool(PRINT_ANY, "deleted", "Deleted ", true);
 
 	if (!brief) {
ip/ipmonitor.c +16 -2
index b28faa20..eec48d83 100644
@@ -30,8 +30,8 @@ static void usage(void)
 	fprintf(stderr,
 		"Usage: ip monitor [ all | OBJECTS ] [ FILE ] [ label ] [ all-nsid ]\n"
 		"                  [ dev DEVICE ]\n"
-		"OBJECTS :=  address | link | mroute | maddress | neigh | netconf |\n"
-		"            nexthop | nsid | prefix | route | rule | stats\n"
+		"OBJECTS :=  address | link | mroute | maddress | acaddress | neigh |\n"
+		"            netconf | nexthop | nsid | prefix | route | rule | stats\n"
 		"FILE := file FILENAME\n");
 	exit(-1);
 }
@@ -154,6 +154,8 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,
 
 	case RTM_DELMULTICAST:
 	case RTM_NEWMULTICAST:
+	case RTM_DELANYCAST:
+	case RTM_NEWANYCAST:
 		print_addrinfo(n, arg);
 		return 0;
 
@@ -184,6 +186,7 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,
 #define IPMON_LNSID		BIT(9)
 #define IPMON_LNEXTHOP		BIT(10)
 #define IPMON_LMADDR		BIT(11)
+#define IPMON_LACADDR		BIT(12)
 
 #define IPMON_L_ALL		(~0)
 
@@ -210,6 +213,8 @@ int do_ipmonitor(int argc, char **argv)
 			lmask |= IPMON_LADDR;
 		} else if (matches(*argv, "maddress") == 0) {
 			lmask |= IPMON_LMADDR;
+		} else if (matches(*argv, "acaddress") == 0) {
+			lmask |= IPMON_LACADDR;
 		} else if (matches(*argv, "route") == 0) {
 			lmask |= IPMON_LROUTE;
 		} else if (matches(*argv, "mroute") == 0) {
@@ -349,6 +354,15 @@ int do_ipmonitor(int argc, char **argv)
 		}
 	}
 
+	if (lmask & IPMON_LACADDR) {
+		if ((!preferred_family || preferred_family == AF_INET6) &&
+		    rtnl_add_nl_group(&rth, RTNLGRP_IPV6_ACADDR) < 0) {
+			fprintf(stderr,
+				"Failed to add ipv6 acaddr group to list\n");
+			exit(1);
+		}
+	}
+
 	if (listen_all_nsid && rtnl_listen_all_nsid(&rth) < 0)
 		exit(1);
 
man/man8/ip-monitor.8 +3 -2
index a3c099ae..6cb585ba 100644
@@ -54,8 +54,9 @@ command is the first in the command line and then the object list follows:
 .I OBJECT-LIST
 is the list of object types that we want to monitor.
 It may contain
-.BR link ", " address ", " route ", " mroute ", " maddress ", " prefix ", "
-.BR neigh ", " netconf ", "  rule ", " stats ", " nsid " and " nexthop "."
+.BR link ", " address ", " route ", " mroute ", " maddress ", " acaddress ", "
+.BR prefix ", "neigh ", " netconf ", "  rule ", " stats ", " nsid " and "
+.BR nexthop "."
 If no
 .B file
 argument is given,
Signature · 1 line
2.48.0.rc2.279.g1de40edade-goog
#3 lore raw

ip/ipmonitor.c int do_ipmonitor(int argc, char **argv) · line 216

Quoted 5 lines · Yuyang Huang
ip/ipmonitor.c +1 -0
@@ -210,6 +213,8 @@ int do_ipmonitor(int argc, char **argv)
 			lmask |= IPMON_LADDR;
 		} else if (matches(*argv, "maddress") == 0) {
 			lmask |= IPMON_LMADDR;
+		} else if (matches(*argv, "acaddress") == 0) {

changed that to strcmp (not taking any more matches) and applied to iproute2-next.