iproute2: add 'ip monitor acaddress' support
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>
This commit is contained in:
committed by
David Ahern
parent
d009b68ffc
commit
fe4100df83
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user