ipmonitor: Add nexthop option to monitor

Add capability to ip-monitor to listen and dump nexthop messages.
Since the nexthop group = 32 which exceeds the max groups bit
field, 2 separate flags are needed - one that defaults on to indicate
nexthop group is joined by default and a second that indicates a
specific selection by the user (e.g, ip mon nexthop route).

Signed-off-by: David Ahern <dsahern@gmail.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
David Ahern 2019-06-07 15:38:16 -07:00
parent 12387e2c14
commit e7cd93e7af

View File

@ -84,6 +84,12 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,
} }
} }
case RTM_NEWNEXTHOP:
case RTM_DELNEXTHOP:
print_headers(fp, "[NEXTHOP]", ctrl);
print_nexthop(n, arg);
return 0;
case RTM_NEWLINK: case RTM_NEWLINK:
case RTM_DELLINK: case RTM_DELLINK:
ll_remember_index(n, NULL); ll_remember_index(n, NULL);
@ -161,6 +167,7 @@ static int accept_msg(struct rtnl_ctrl_data *ctrl,
int do_ipmonitor(int argc, char **argv) int do_ipmonitor(int argc, char **argv)
{ {
int lnexthop = 0, nh_set = 1;
char *file = NULL; char *file = NULL;
unsigned int groups = 0; unsigned int groups = 0;
int llink = 0; int llink = 0;
@ -202,30 +209,42 @@ int do_ipmonitor(int argc, char **argv)
} else if (matches(*argv, "link") == 0) { } else if (matches(*argv, "link") == 0) {
llink = 1; llink = 1;
groups = 0; groups = 0;
nh_set = 0;
} else if (matches(*argv, "address") == 0) { } else if (matches(*argv, "address") == 0) {
laddr = 1; laddr = 1;
groups = 0; groups = 0;
nh_set = 0;
} else if (matches(*argv, "route") == 0) { } else if (matches(*argv, "route") == 0) {
lroute = 1; lroute = 1;
groups = 0; groups = 0;
nh_set = 0;
} else if (matches(*argv, "mroute") == 0) { } else if (matches(*argv, "mroute") == 0) {
lmroute = 1; lmroute = 1;
groups = 0; groups = 0;
nh_set = 0;
} else if (matches(*argv, "prefix") == 0) { } else if (matches(*argv, "prefix") == 0) {
lprefix = 1; lprefix = 1;
groups = 0; groups = 0;
nh_set = 0;
} else if (matches(*argv, "neigh") == 0) { } else if (matches(*argv, "neigh") == 0) {
lneigh = 1; lneigh = 1;
groups = 0; groups = 0;
nh_set = 0;
} else if (matches(*argv, "netconf") == 0) { } else if (matches(*argv, "netconf") == 0) {
lnetconf = 1; lnetconf = 1;
groups = 0; groups = 0;
nh_set = 0;
} else if (matches(*argv, "rule") == 0) { } else if (matches(*argv, "rule") == 0) {
lrule = 1; lrule = 1;
groups = 0; groups = 0;
nh_set = 0;
} else if (matches(*argv, "nsid") == 0) { } else if (matches(*argv, "nsid") == 0) {
lnsid = 1; lnsid = 1;
groups = 0; groups = 0;
nh_set = 0;
} else if (matches(*argv, "nexthop") == 0) {
lnexthop = 1;
groups = 0;
} else if (strcmp(*argv, "all") == 0) { } else if (strcmp(*argv, "all") == 0) {
prefix_banner = 1; prefix_banner = 1;
} else if (matches(*argv, "all-nsid") == 0) { } else if (matches(*argv, "all-nsid") == 0) {
@ -297,6 +316,9 @@ int do_ipmonitor(int argc, char **argv)
if (lnsid) { if (lnsid) {
groups |= nl_mgrp(RTNLGRP_NSID); groups |= nl_mgrp(RTNLGRP_NSID);
} }
if (nh_set)
lnexthop = 1;
if (file) { if (file) {
FILE *fp; FILE *fp;
int err; int err;
@ -313,6 +335,12 @@ int do_ipmonitor(int argc, char **argv)
if (rtnl_open(&rth, groups) < 0) if (rtnl_open(&rth, groups) < 0)
exit(1); exit(1);
if (lnexthop && rtnl_add_nl_group(&rth, RTNLGRP_NEXTHOP) < 0) {
fprintf(stderr, "Failed to add nexthop group to list\n");
exit(1);
}
if (listen_all_nsid && rtnl_listen_all_nsid(&rth) < 0) if (listen_all_nsid && rtnl_listen_all_nsid(&rth) < 0)
exit(1); exit(1);