]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
iproute2: add 'ip monitor acaddress' support
authorYuyang Huang <yuyanghuang@google.com>
Fri, 17 Jan 2025 03:20:41 +0000 (12:20 +0900)
committerDavid Ahern <dsahern@kernel.org>
Mon, 20 Jan 2025 00:20:56 +0000 (00:20 +0000)
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 <maze@google.com>
Cc: Lorenzo Colitti <lorenzo@google.com>
Signed-off-by: Yuyang Huang <yuyanghuang@google.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
ip/ipaddress.c
ip/ipmonitor.c
man/man8/ip-monitor.8

index 679b4c002e127d4a4404cc8021c6c2d2c547295f..70b3d513e510e6939e7799530236d1b0c9f5e6cc 100644 (file)
@@ -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) {
index b28faa208dcb96a80f18727999706aa12b62ba15..b890b4d06ed15a3535648a25a969c54c4e6c51dc 100644 (file)
@@ -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 (strcmp(*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);
 
index a3c099aeb2fad6a6b7ca1538648717e37598a736..6cb585baf72b19e1483ff0c96ea72f5139d5d901 100644 (file)
@@ -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,