* [PATCH 1/2] ip: convert monitor to switch
2018-08-15 21:29 [PATCH iproute2 0/2] ip monitor fixes Stephen Hemminger
@ 2018-08-15 21:29 ` Stephen Hemminger
2018-08-15 21:29 ` [PATCH 2/2] ipmonitor: decode DELNETCONF message Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2018-08-15 21:29 UTC (permalink / raw)
To: netdev; +Cc: Stephen Hemminger, Stephen Hemminger
From: Stephen Hemminger <sthemmin@microsoft.com>
The decoding of netlink message types is natural for a C
switch statement.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
ip/ipmonitor.c | 63 ++++++++++++++++++++++++++++++--------------------
1 file changed, 38 insertions(+), 25 deletions(-)
diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c
index 8b017341da6b..5552d98ee9e5 100644
--- a/ip/ipmonitor.c
+++ b/ip/ipmonitor.c
@@ -58,7 +58,9 @@ static int accept_msg(const struct sockaddr_nl *who,
{
FILE *fp = (FILE *)arg;
- if (n->nlmsg_type == RTM_NEWROUTE || n->nlmsg_type == RTM_DELROUTE) {
+ switch (n->nlmsg_type) {
+ case RTM_NEWROUTE:
+ case RTM_DELROUTE: {
struct rtmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len - NLMSG_LENGTH(sizeof(*r));
@@ -82,24 +84,28 @@ static int accept_msg(const struct sockaddr_nl *who,
}
}
- if (n->nlmsg_type == RTM_NEWLINK || n->nlmsg_type == RTM_DELLINK) {
+ case RTM_NEWLINK:
+ case RTM_DELLINK:
ll_remember_index(who, n, NULL);
print_headers(fp, "[LINK]", ctrl);
print_linkinfo(who, n, arg);
return 0;
- }
- if (n->nlmsg_type == RTM_NEWADDR || n->nlmsg_type == RTM_DELADDR) {
+
+ case RTM_NEWADDR:
+ case RTM_DELADDR:
print_headers(fp, "[ADDR]", ctrl);
print_addrinfo(who, n, arg);
return 0;
- }
- if (n->nlmsg_type == RTM_NEWADDRLABEL || n->nlmsg_type == RTM_DELADDRLABEL) {
+
+ case RTM_NEWADDRLABEL:
+ case RTM_DELADDRLABEL:
print_headers(fp, "[ADDRLABEL]", ctrl);
print_addrlabel(who, n, arg);
return 0;
- }
- if (n->nlmsg_type == RTM_NEWNEIGH || n->nlmsg_type == RTM_DELNEIGH ||
- n->nlmsg_type == RTM_GETNEIGH) {
+
+ case RTM_NEWNEIGH:
+ case RTM_DELNEIGH:
+ case RTM_GETNEIGH:
if (preferred_family) {
struct ndmsg *r = NLMSG_DATA(n);
@@ -110,34 +116,41 @@ static int accept_msg(const struct sockaddr_nl *who,
print_headers(fp, "[NEIGH]", ctrl);
print_neigh(who, n, arg);
return 0;
- }
- if (n->nlmsg_type == RTM_NEWPREFIX) {
+
+ case RTM_NEWPREFIX:
print_headers(fp, "[PREFIX]", ctrl);
print_prefix(who, n, arg);
return 0;
- }
- if (n->nlmsg_type == RTM_NEWRULE || n->nlmsg_type == RTM_DELRULE) {
+
+ case RTM_NEWRULE:
+ case RTM_DELRULE:
print_headers(fp, "[RULE]", ctrl);
print_rule(who, n, arg);
return 0;
- }
- if (n->nlmsg_type == RTM_NEWNETCONF) {
+
+ case NLMSG_TSTAMP:
+ print_nlmsg_timestamp(fp, n);
+ return 0;
+
+ case RTM_NEWNETCONF:
print_headers(fp, "[NETCONF]", ctrl);
print_netconf(who, ctrl, n, arg);
return 0;
- }
- if (n->nlmsg_type == NLMSG_TSTAMP) {
- print_nlmsg_timestamp(fp, n);
- return 0;
- }
- if (n->nlmsg_type == RTM_NEWNSID || n->nlmsg_type == RTM_DELNSID) {
+
+ case RTM_DELNSID:
+ case RTM_NEWNSID:
print_headers(fp, "[NSID]", ctrl);
print_nsid(who, n, arg);
return 0;
- }
- if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP &&
- n->nlmsg_type != NLMSG_DONE) {
- fprintf(fp, "Unknown message: type=0x%08x(%d) flags=0x%08x(%d)len=0x%08x(%d)\n",
+
+ case NLMSG_ERROR:
+ case NLMSG_NOOP:
+ case NLMSG_DONE:
+ break; /* ignore */
+
+ default:
+ fprintf(stderr,
+ "Unknown message: type=0x%08x(%d) flags=0x%08x(%d) len=0x%08x(%d)\n",
n->nlmsg_type, n->nlmsg_type,
n->nlmsg_flags, n->nlmsg_flags, n->nlmsg_len,
n->nlmsg_len);
--
2.18.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/2] ipmonitor: decode DELNETCONF message
2018-08-15 21:29 [PATCH iproute2 0/2] ip monitor fixes Stephen Hemminger
2018-08-15 21:29 ` [PATCH 1/2] ip: convert monitor to switch Stephen Hemminger
@ 2018-08-15 21:29 ` Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2018-08-15 21:29 UTC (permalink / raw)
To: netdev; +Cc: Stephen Hemminger, Stephen Hemminger
From: Stephen Hemminger <sthemmin@microsoft.com>
When device is deleted DELNETCONF is sent, but ipmonitor
was unable to decode it.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
ip/ipmonitor.c | 1 +
ip/ipnetconf.c | 6 +++++-
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/ip/ipmonitor.c b/ip/ipmonitor.c
index 5552d98ee9e5..a93b62cd6624 100644
--- a/ip/ipmonitor.c
+++ b/ip/ipmonitor.c
@@ -133,6 +133,7 @@ static int accept_msg(const struct sockaddr_nl *who,
return 0;
case RTM_NEWNETCONF:
+ case RTM_DELNETCONF:
print_headers(fp, "[NETCONF]", ctrl);
print_netconf(who, ctrl, n, arg);
return 0;
diff --git a/ip/ipnetconf.c b/ip/ipnetconf.c
index 03f98ace9145..afce982ced37 100644
--- a/ip/ipnetconf.c
+++ b/ip/ipnetconf.c
@@ -66,7 +66,8 @@ int print_netconf(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl,
if (n->nlmsg_type == NLMSG_ERROR)
return -1;
- if (n->nlmsg_type != RTM_NEWNETCONF) {
+
+ if (n->nlmsg_type != RTM_NEWNETCONF && n->nlmsg_type != RTM_DELNETCONF) {
fprintf(stderr, "Not RTM_NEWNETCONF: %08x %08x %08x\n",
n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
@@ -91,6 +92,9 @@ int print_netconf(const struct sockaddr_nl *who, struct rtnl_ctrl_data *ctrl,
return 0;
open_json_object(NULL);
+ if (n->nlmsg_type == RTM_DELNETCONF)
+ print_bool(PRINT_ANY, "deleted", "Deleted ", true);
+
print_string(PRINT_ANY, "family",
"%s ", family_name(ncm->ncm_family));
--
2.18.0
^ permalink raw reply related [flat|nested] 3+ messages in thread