Commit 3b0006f8 authored by Nicolas Dichtel's avatar Nicolas Dichtel Committed by Stephen Hemminger

ipmonitor: introduce print_headers

The goal of this patch is to avoid code duplication.
Signed-off-by: default avatarNicolas Dichtel <nicolas.dichtel@6wind.com>
parent 0628cddd
...@@ -37,6 +37,15 @@ static void usage(void) ...@@ -37,6 +37,15 @@ static void usage(void)
exit(-1); exit(-1);
} }
static void print_headers(FILE *fp, char *label)
{
if (timestamp)
print_timestamp(fp);
if (prefix_banner)
fprintf(fp, "%s", label);
}
static int accept_msg(const struct sockaddr_nl *who, static int accept_msg(const struct sockaddr_nl *who,
struct rtnl_ctrl_data *ctrl, struct rtnl_ctrl_data *ctrl,
struct nlmsghdr *n, void *arg) struct nlmsghdr *n, void *arg)
...@@ -55,42 +64,31 @@ static int accept_msg(const struct sockaddr_nl *who, ...@@ -55,42 +64,31 @@ static int accept_msg(const struct sockaddr_nl *who,
if (r->rtm_flags & RTM_F_CLONED) if (r->rtm_flags & RTM_F_CLONED)
return 0; return 0;
if (timestamp)
print_timestamp(fp);
if (r->rtm_family == RTNL_FAMILY_IPMR || if (r->rtm_family == RTNL_FAMILY_IPMR ||
r->rtm_family == RTNL_FAMILY_IP6MR) { r->rtm_family == RTNL_FAMILY_IP6MR) {
if (prefix_banner) print_headers(fp, "[MROUTE]");
fprintf(fp, "[MROUTE]");
print_mroute(who, n, arg); print_mroute(who, n, arg);
return 0; return 0;
} else { } else {
if (prefix_banner) print_headers(fp, "[ROUTE]");
fprintf(fp, "[ROUTE]");
print_route(who, n, arg); print_route(who, n, arg);
return 0; return 0;
} }
} }
if (timestamp)
print_timestamp(fp);
if (n->nlmsg_type == RTM_NEWLINK || n->nlmsg_type == RTM_DELLINK) { if (n->nlmsg_type == RTM_NEWLINK || n->nlmsg_type == RTM_DELLINK) {
ll_remember_index(who, n, NULL); ll_remember_index(who, n, NULL);
if (prefix_banner) print_headers(fp, "[LINK]");
fprintf(fp, "[LINK]");
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) { if (n->nlmsg_type == RTM_NEWADDR || n->nlmsg_type == RTM_DELADDR) {
if (prefix_banner) print_headers(fp, "[ADDR]");
fprintf(fp, "[ADDR]");
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) { if (n->nlmsg_type == RTM_NEWADDRLABEL || n->nlmsg_type == RTM_DELADDRLABEL) {
if (prefix_banner) print_headers(fp, "[ADDRLABEL]");
fprintf(fp, "[ADDRLABEL]");
print_addrlabel(who, n, arg); print_addrlabel(who, n, arg);
return 0; return 0;
} }
...@@ -103,26 +101,22 @@ static int accept_msg(const struct sockaddr_nl *who, ...@@ -103,26 +101,22 @@ static int accept_msg(const struct sockaddr_nl *who,
return 0; return 0;
} }
if (prefix_banner) print_headers(fp, "[NEIGH]");
fprintf(fp, "[NEIGH]");
print_neigh(who, n, arg); print_neigh(who, n, arg);
return 0; return 0;
} }
if (n->nlmsg_type == RTM_NEWPREFIX) { if (n->nlmsg_type == RTM_NEWPREFIX) {
if (prefix_banner) print_headers(fp, "[PREFIX]");
fprintf(fp, "[PREFIX]");
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) { if (n->nlmsg_type == RTM_NEWRULE || n->nlmsg_type == RTM_DELRULE) {
if (prefix_banner) print_headers(fp, "[RULE]");
fprintf(fp, "[RULE]");
print_rule(who, n, arg); print_rule(who, n, arg);
return 0; return 0;
} }
if (n->nlmsg_type == RTM_NEWNETCONF) { if (n->nlmsg_type == RTM_NEWNETCONF) {
if (prefix_banner) print_headers(fp, "[NETCONF]");
fprintf(fp, "[NETCONF]");
print_netconf(who, ctrl, n, arg); print_netconf(who, ctrl, n, arg);
return 0; return 0;
} }
...@@ -131,8 +125,7 @@ static int accept_msg(const struct sockaddr_nl *who, ...@@ -131,8 +125,7 @@ static int accept_msg(const struct sockaddr_nl *who,
return 0; return 0;
} }
if (n->nlmsg_type == RTM_NEWNSID || n->nlmsg_type == RTM_DELNSID) { if (n->nlmsg_type == RTM_NEWNSID || n->nlmsg_type == RTM_DELNSID) {
if (prefix_banner) print_headers(fp, "[NSID]");
fprintf(fp, "[NSID]");
print_nsid(who, n, arg); print_nsid(who, n, arg);
return 0; return 0;
} }
......
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