Add rule notification support to ip monitor
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
diff --git a/ip/ip_common.h b/ip/ip_common.h
index 8b286b0..bc6a7cd 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -20,6 +20,8 @@
struct nlmsghdr *n, void *arg);
extern int print_prefix(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg);
+extern int print_rule(const struct sockaddr_nl *who,
+ struct nlmsghdr *n, void *arg);
extern int do_ipaddr(int argc, char **argv);
extern int do_iproute(int argc, char **argv);
extern int do_iprule(int argc, char **argv);
diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c
index 50b6327..704ada7 100644
--- a/ip/ipmonitor.c
+++ b/ip/ipmonitor.c
@@ -62,6 +62,10 @@
print_prefix(who, n, arg);
return 0;
}
+ if (n->nlmsg_type == RTM_NEWRULE || n->nlmsg_type == RTM_DELRULE) {
+ print_rule(who, n, arg);
+ return 0;
+ }
if (n->nlmsg_type == 15) {
char *tstr;
time_t secs = ((__u32*)NLMSG_DATA(n))[0];
diff --git a/ip/iprule.c b/ip/iprule.c
index af014ba..c584b18 100644
--- a/ip/iprule.c
+++ b/ip/iprule.c
@@ -46,8 +46,7 @@
exit(-1);
}
-static int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n,
- void *arg)
+int print_rule(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{
FILE *fp = (FILE*)arg;
struct rtmsg *r = NLMSG_DATA(n);
@@ -58,7 +57,7 @@
char abuf[256];
SPRINT_BUF(b1);
- if (n->nlmsg_type != RTM_NEWRULE)
+ if (n->nlmsg_type != RTM_NEWRULE && n->nlmsg_type != RTM_DELRULE)
return 0;
len -= NLMSG_LENGTH(sizeof(*r));
@@ -76,6 +75,9 @@
else if (r->rtm_family == AF_IPX)
host_len = 80;
+ if (n->nlmsg_type == RTM_DELRULE)
+ fprintf(fp, "Deleted ");
+
if (tb[RTA_PRIORITY])
fprintf(fp, "%u:\t", *(unsigned*)RTA_DATA(tb[RTA_PRIORITY]));
else