ip: convert monitor to switch
The decoding of netlink message types is natural for a C switch statement. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
parent
d67eb4fbf8
commit
40443f49b3
|
|
@ -58,7 +58,9 @@ static int accept_msg(const struct sockaddr_nl *who,
|
||||||
{
|
{
|
||||||
FILE *fp = (FILE *)arg;
|
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);
|
struct rtmsg *r = NLMSG_DATA(n);
|
||||||
int len = n->nlmsg_len - NLMSG_LENGTH(sizeof(*r));
|
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);
|
ll_remember_index(who, n, NULL);
|
||||||
print_headers(fp, "[LINK]", ctrl);
|
print_headers(fp, "[LINK]", ctrl);
|
||||||
print_linkinfo(who, n, arg);
|
print_linkinfo(who, n, arg);
|
||||||
return 0;
|
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_headers(fp, "[ADDR]", ctrl);
|
||||||
print_addrinfo(who, n, arg);
|
print_addrinfo(who, n, arg);
|
||||||
return 0;
|
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_headers(fp, "[ADDRLABEL]", ctrl);
|
||||||
print_addrlabel(who, n, arg);
|
print_addrlabel(who, n, arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
if (n->nlmsg_type == RTM_NEWNEIGH || n->nlmsg_type == RTM_DELNEIGH ||
|
case RTM_NEWNEIGH:
|
||||||
n->nlmsg_type == RTM_GETNEIGH) {
|
case RTM_DELNEIGH:
|
||||||
|
case RTM_GETNEIGH:
|
||||||
if (preferred_family) {
|
if (preferred_family) {
|
||||||
struct ndmsg *r = NLMSG_DATA(n);
|
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_headers(fp, "[NEIGH]", ctrl);
|
||||||
print_neigh(who, n, arg);
|
print_neigh(who, n, arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
if (n->nlmsg_type == RTM_NEWPREFIX) {
|
case RTM_NEWPREFIX:
|
||||||
print_headers(fp, "[PREFIX]", ctrl);
|
print_headers(fp, "[PREFIX]", ctrl);
|
||||||
print_prefix(who, n, arg);
|
print_prefix(who, n, arg);
|
||||||
return 0;
|
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_headers(fp, "[RULE]", ctrl);
|
||||||
print_rule(who, n, arg);
|
print_rule(who, n, arg);
|
||||||
return 0;
|
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_headers(fp, "[NETCONF]", ctrl);
|
||||||
print_netconf(who, ctrl, n, arg);
|
print_netconf(who, ctrl, n, arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
if (n->nlmsg_type == NLMSG_TSTAMP) {
|
case RTM_DELNSID:
|
||||||
print_nlmsg_timestamp(fp, n);
|
case RTM_NEWNSID:
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (n->nlmsg_type == RTM_NEWNSID || n->nlmsg_type == RTM_DELNSID) {
|
|
||||||
print_headers(fp, "[NSID]", ctrl);
|
print_headers(fp, "[NSID]", ctrl);
|
||||||
print_nsid(who, n, arg);
|
print_nsid(who, n, arg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP &&
|
case NLMSG_ERROR:
|
||||||
n->nlmsg_type != NLMSG_DONE) {
|
case NLMSG_NOOP:
|
||||||
fprintf(fp, "Unknown message: type=0x%08x(%d) flags=0x%08x(%d)len=0x%08x(%d)\n",
|
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_type, n->nlmsg_type,
|
||||||
n->nlmsg_flags, n->nlmsg_flags, n->nlmsg_len,
|
n->nlmsg_flags, n->nlmsg_flags, n->nlmsg_len,
|
||||||
n->nlmsg_len);
|
n->nlmsg_len);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue