Commit 093b7646 authored by vadimk's avatar vadimk Committed by Stephen Hemminger

ip monitor: Allow to filter events by dev

Added 'dev' option to allow filtering events by device.
Signed-off-by: default avatarVadim Kochan <vadim4j@gmail.com>
parent eef43b50
...@@ -13,14 +13,17 @@ extern int print_ntable(const struct sockaddr_nl *who, ...@@ -13,14 +13,17 @@ extern int print_ntable(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg); struct nlmsghdr *n, void *arg);
extern int ipaddr_list(int argc, char **argv); extern int ipaddr_list(int argc, char **argv);
extern int ipaddr_list_link(int argc, char **argv); extern int ipaddr_list_link(int argc, char **argv);
void ipaddr_get_vf_rate(int, int *, int *, int);
extern int iproute_monitor(int argc, char **argv); extern int iproute_monitor(int argc, char **argv);
extern void iplink_usage(void) __attribute__((noreturn)); extern void iplink_usage(void) __attribute__((noreturn));
extern void iproute_reset_filter(void);
extern void ipmroute_reset_filter(void); extern void iproute_reset_filter(int ifindex);
void ipaddr_get_vf_rate(int, int *, int *, int); extern void ipmroute_reset_filter(int ifindex);
extern void ipaddr_reset_filter(int); extern void ipaddr_reset_filter(int oneline, int ifindex);
extern void ipneigh_reset_filter(void); extern void ipneigh_reset_filter(int ifindex);
extern void ipntable_reset_filter(void); extern void ipntable_reset_filter(void);
extern void ipnetconf_reset_filter(int ifindex);
extern int print_route(const struct sockaddr_nl *who, extern int print_route(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg); struct nlmsghdr *n, void *arg);
extern int print_mroute(const struct sockaddr_nl *who, extern int print_mroute(const struct sockaddr_nl *who,
......
...@@ -1197,7 +1197,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action) ...@@ -1197,7 +1197,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
char *filter_dev = NULL; char *filter_dev = NULL;
int no_link = 0; int no_link = 0;
ipaddr_reset_filter(oneline); ipaddr_reset_filter(oneline, 0);
filter.showqueue = 1; filter.showqueue = 1;
if (filter.family == AF_UNSPEC) if (filter.family == AF_UNSPEC)
...@@ -1442,10 +1442,11 @@ int ipaddr_list_link(int argc, char **argv) ...@@ -1442,10 +1442,11 @@ int ipaddr_list_link(int argc, char **argv)
return ipaddr_list_flush_or_save(argc, argv, IPADD_LIST); return ipaddr_list_flush_or_save(argc, argv, IPADD_LIST);
} }
void ipaddr_reset_filter(int oneline) void ipaddr_reset_filter(int oneline, int ifindex)
{ {
memset(&filter, 0, sizeof(filter)); memset(&filter, 0, sizeof(filter));
filter.oneline = oneline; filter.oneline = oneline;
filter.ifindex = ifindex;
} }
static int default_scope(inet_prefix *lcl) static int default_scope(inet_prefix *lcl)
......
...@@ -29,7 +29,8 @@ int prefix_banner; ...@@ -29,7 +29,8 @@ int prefix_banner;
static void usage(void) static void usage(void)
{ {
fprintf(stderr, "Usage: ip monitor [ all | LISTofOBJECTS ] [ FILE ] [ label ]\n"); fprintf(stderr, "Usage: ip monitor [ all | LISTofOBJECTS ] [ FILE ]"
"[ label ] [dev DEVICE]\n");
fprintf(stderr, "LISTofOBJECTS := link | address | route | mroute | prefix |\n"); fprintf(stderr, "LISTofOBJECTS := link | address | route | mroute | prefix |\n");
fprintf(stderr, " neigh | netconf\n"); fprintf(stderr, " neigh | netconf\n");
fprintf(stderr, "FILE := file FILENAME\n"); fprintf(stderr, "FILE := file FILENAME\n");
...@@ -162,12 +163,9 @@ int do_ipmonitor(int argc, char **argv) ...@@ -162,12 +163,9 @@ int do_ipmonitor(int argc, char **argv)
int lprefix=0; int lprefix=0;
int lneigh=0; int lneigh=0;
int lnetconf=0; int lnetconf=0;
int ifindex=0;
rtnl_close(&rth); rtnl_close(&rth);
ipaddr_reset_filter(1);
iproute_reset_filter();
ipmroute_reset_filter();
ipneigh_reset_filter();
while (argc > 0) { while (argc > 0) {
if (matches(*argv, "file") == 0) { if (matches(*argv, "file") == 0) {
...@@ -201,6 +199,12 @@ int do_ipmonitor(int argc, char **argv) ...@@ -201,6 +199,12 @@ int do_ipmonitor(int argc, char **argv)
prefix_banner=1; prefix_banner=1;
} else if (matches(*argv, "help") == 0) { } else if (matches(*argv, "help") == 0) {
usage(); usage();
} else if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
ifindex = ll_name_to_index(*argv);
if (!ifindex)
invarg("Device does not exist\n", *argv);
} else { } else {
fprintf(stderr, "Argument \"%s\" is unknown, try \"ip monitor help\".\n", *argv); fprintf(stderr, "Argument \"%s\" is unknown, try \"ip monitor help\".\n", *argv);
exit(-1); exit(-1);
...@@ -208,6 +212,12 @@ int do_ipmonitor(int argc, char **argv) ...@@ -208,6 +212,12 @@ int do_ipmonitor(int argc, char **argv)
argc--; argv++; argc--; argv++;
} }
ipaddr_reset_filter(1, ifindex);
iproute_reset_filter(ifindex);
ipmroute_reset_filter(ifindex);
ipneigh_reset_filter(ifindex);
ipnetconf_reset_filter(ifindex);
if (llink) if (llink)
groups |= nl_mgrp(RTNLGRP_LINK); groups |= nl_mgrp(RTNLGRP_LINK);
if (laddr) { if (laddr) {
......
...@@ -174,11 +174,12 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -174,11 +174,12 @@ int print_mroute(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
return 0; return 0;
} }
void ipmroute_reset_filter(void) void ipmroute_reset_filter(int ifindex)
{ {
memset(&filter, 0, sizeof(filter)); memset(&filter, 0, sizeof(filter));
filter.mdst.bitlen = -1; filter.mdst.bitlen = -1;
filter.msrc.bitlen = -1; filter.msrc.bitlen = -1;
filter.iif = ifindex;
} }
static int mroute_list(int argc, char **argv) static int mroute_list(int argc, char **argv)
...@@ -186,7 +187,7 @@ static int mroute_list(int argc, char **argv) ...@@ -186,7 +187,7 @@ static int mroute_list(int argc, char **argv)
char *id = NULL; char *id = NULL;
int family; int family;
ipmroute_reset_filter(); ipmroute_reset_filter(0);
if (preferred_family == AF_UNSPEC) if (preferred_family == AF_UNSPEC)
family = AF_INET; family = AF_INET;
else else
......
...@@ -313,10 +313,11 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -313,10 +313,11 @@ int print_neigh(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
return 0; return 0;
} }
void ipneigh_reset_filter(void) void ipneigh_reset_filter(int ifindex)
{ {
memset(&filter, 0, sizeof(filter)); memset(&filter, 0, sizeof(filter));
filter.state = ~0; filter.state = ~0;
filter.index = ifindex;
} }
static int do_show_or_flush(int argc, char **argv, int flush) static int do_show_or_flush(int argc, char **argv, int flush)
...@@ -325,7 +326,7 @@ static int do_show_or_flush(int argc, char **argv, int flush) ...@@ -325,7 +326,7 @@ static int do_show_or_flush(int argc, char **argv, int flush)
int state_given = 0; int state_given = 0;
struct ndmsg ndm = { 0 }; struct ndmsg ndm = { 0 };
ipneigh_reset_filter(); ipneigh_reset_filter(0);
if (!filter.family) if (!filter.family)
filter.family = preferred_family; filter.family = preferred_family;
......
...@@ -123,9 +123,10 @@ int print_netconf(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) ...@@ -123,9 +123,10 @@ int print_netconf(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
return 0; return 0;
} }
static void ipnetconf_reset_filter(void) void ipnetconf_reset_filter(int ifindex)
{ {
memset(&filter, 0, sizeof(filter)); memset(&filter, 0, sizeof(filter));
filter.ifindex = ifindex;
} }
static int do_show(int argc, char **argv) static int do_show(int argc, char **argv)
...@@ -136,7 +137,7 @@ static int do_show(int argc, char **argv) ...@@ -136,7 +137,7 @@ static int do_show(int argc, char **argv)
char buf[1024]; char buf[1024];
} req; } req;
ipnetconf_reset_filter(); ipnetconf_reset_filter(0);
filter.family = preferred_family; filter.family = preferred_family;
if (filter.family == AF_UNSPEC) if (filter.family == AF_UNSPEC)
filter.family = AF_INET; filter.family = AF_INET;
......
...@@ -1137,7 +1137,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action) ...@@ -1137,7 +1137,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action)
} else } else
filter_fn = print_route; filter_fn = print_route;
iproute_reset_filter(); iproute_reset_filter(0);
filter.tb = RT_TABLE_MAIN; filter.tb = RT_TABLE_MAIN;
if ((action == IPROUTE_FLUSH) && argc <= 0) { if ((action == IPROUTE_FLUSH) && argc <= 0) {
...@@ -1385,7 +1385,7 @@ static int iproute_get(int argc, char **argv) ...@@ -1385,7 +1385,7 @@ static int iproute_get(int argc, char **argv)
memset(&req, 0, sizeof(req)); memset(&req, 0, sizeof(req));
iproute_reset_filter(); iproute_reset_filter(0);
filter.cloned = 2; filter.cloned = 2;
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
...@@ -1590,11 +1590,14 @@ static int iproute_showdump(void) ...@@ -1590,11 +1590,14 @@ static int iproute_showdump(void)
exit(rtnl_from_file(stdin, &show_handler, NULL)); exit(rtnl_from_file(stdin, &show_handler, NULL));
} }
void iproute_reset_filter(void) void iproute_reset_filter(int ifindex)
{ {
memset(&filter, 0, sizeof(filter)); memset(&filter, 0, sizeof(filter));
filter.mdst.bitlen = -1; filter.mdst.bitlen = -1;
filter.msrc.bitlen = -1; filter.msrc.bitlen = -1;
filter.oif = ifindex;
if (filter.oif > 0)
filter.oifmask = -1;
} }
int do_iproute(int argc, char **argv) int do_iproute(int argc, char **argv)
......
...@@ -11,6 +11,8 @@ ip-monitor, rtmon \- state monitoring ...@@ -11,6 +11,8 @@ ip-monitor, rtmon \- state monitoring
.BR "monitor" " [ " all " |" .BR "monitor" " [ " all " |"
.IR OBJECT-LIST " ] [" .IR OBJECT-LIST " ] ["
.BI file " FILENAME " .BI file " FILENAME "
] [
.BI dev " DEVICE "
] ]
.sp .sp
...@@ -26,6 +28,8 @@ command is the first in the command line and then the object list follows: ...@@ -26,6 +28,8 @@ command is the first in the command line and then the object list follows:
.BR "ip monitor" " [ " all " |" .BR "ip monitor" " [ " all " |"
.IR OBJECT-LIST " ] [" .IR OBJECT-LIST " ] ["
.BI file " FILENAME " .BI file " FILENAME "
] [
.BI dev " DEVICE "
] ]
.I OBJECT-LIST .I OBJECT-LIST
...@@ -69,6 +73,11 @@ at any time. ...@@ -69,6 +73,11 @@ at any time.
It prepends the history with the state snapshot dumped at the moment It prepends the history with the state snapshot dumped at the moment
of starting. of starting.
.P
If the
.BI dev
option is given, the program prints only events related to this device.
.SH SEE ALSO .SH SEE ALSO
.br .br
.BR ip (8) .BR ip (8)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment