ipaddress: Simplify print_linkinfo_brief() and it's usage
Simplify calling code in ipaddr_list_flush_or_save() by introducing intermediate variable of @struct nlmsghdr, drop duplicated code: print_linkinfo_brief() never returns values other than <= 0 so we can move print_selected_addrinfo() outside of each block. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
parent
9516823051
commit
1bccd1e43b
|
|
@ -753,7 +753,7 @@ static void print_link_stats(FILE *fp, struct nlmsghdr *n)
|
||||||
}
|
}
|
||||||
|
|
||||||
int print_linkinfo_brief(const struct sockaddr_nl *who,
|
int print_linkinfo_brief(const struct sockaddr_nl *who,
|
||||||
struct nlmsghdr *n, void *arg)
|
struct nlmsghdr *n, void *arg)
|
||||||
{
|
{
|
||||||
FILE *fp = (FILE *)arg;
|
FILE *fp = (FILE *)arg;
|
||||||
struct ifinfomsg *ifi = NLMSG_DATA(n);
|
struct ifinfomsg *ifi = NLMSG_DATA(n);
|
||||||
|
|
@ -2013,24 +2013,21 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
|
||||||
ipaddr_filter(&linfo, ainfo);
|
ipaddr_filter(&linfo, ainfo);
|
||||||
|
|
||||||
for (l = linfo.head; l; l = l->next) {
|
for (l = linfo.head; l; l = l->next) {
|
||||||
int res = 0;
|
struct nlmsghdr *n = &l->h;
|
||||||
struct ifinfomsg *ifi = NLMSG_DATA(&l->h);
|
struct ifinfomsg *ifi = NLMSG_DATA(n);
|
||||||
|
int res;
|
||||||
|
|
||||||
open_json_object(NULL);
|
open_json_object(NULL);
|
||||||
if (brief) {
|
if (brief)
|
||||||
if (print_linkinfo_brief(NULL, &l->h, stdout) == 0)
|
res = print_linkinfo_brief(NULL, n, stdout);
|
||||||
if (filter.family != AF_PACKET)
|
else if (no_link)
|
||||||
print_selected_addrinfo(ifi,
|
res = 0;
|
||||||
ainfo->head,
|
else
|
||||||
stdout);
|
res = print_linkinfo(NULL, n, stdout);
|
||||||
} else if (no_link ||
|
if (res >= 0 && filter.family != AF_PACKET)
|
||||||
(res = print_linkinfo(NULL, &l->h, stdout)) >= 0) {
|
print_selected_addrinfo(ifi, ainfo->head, stdout);
|
||||||
if (filter.family != AF_PACKET)
|
if (res > 0 && !do_link && show_stats)
|
||||||
print_selected_addrinfo(ifi,
|
print_link_stats(stdout, n);
|
||||||
ainfo->head, stdout);
|
|
||||||
if (res > 0 && !do_link && show_stats)
|
|
||||||
print_link_stats(stdout, &l->h);
|
|
||||||
}
|
|
||||||
close_json_object();
|
close_json_object();
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue