ip monitor fixes
Subsystems (2)
cover ip monitor fixes
While debugging another problem noticed that ip monitor does not decode all the netconf messages.
Stephen Hemminger (2):
ip: convert monitor to switch
ipmonitor: decode DELNETCONF message
ip/ipmonitor.c | 64 ++++++++++++++++++++++++++++++-------------------- ip/ipnetconf.c | 6 ++++- 2 files changed, 44 insertions(+), 26 deletions(-)
Signature · 1 line
2.18.0
PATCH 1/2 ip: convert monitor to switch
From: Stephen Hemminger <[email protected]>
The decoding of netlink message types is natural for a C switch statement.
Signed-off-by Stephen Hemminger <[email protected]>
--- ip/ipmonitor.c | 63 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 25 deletions(-)
ip/ipmonitor.c +38 -25
@@ -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);
Signature · 1 line
2.18.0
PATCH 2/2 ipmonitor: decode DELNETCONF message
In reply to Stephen HemmingerFrom: Stephen Hemminger <[email protected]>
When device is deleted DELNETCONF is sent, but ipmonitor was unable to decode it.
Signed-off-by Stephen Hemminger <[email protected]>
--- ip/ipmonitor.c | 1 + ip/ipnetconf.c | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-)
ip/ipmonitor.c +1 -0
@@ -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 ;
ip/ipnetconf.c +5 -1
@@ -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));
Signature · 1 line
2.18.0