Revert "ip address: Change print_linkinfo_brief to take filter as an input"

This reverts commit 63891c7013.

It seems print_linkinfo_brief() never accepts filter different than
default one and David Ahern suggests to revert it instead of making
new change that actually do revert.

Conflicts:
	ip/ipaddress.c
	ip/iplink.c

These are caused by JSON support addition after commit we reverting.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
Serhey Popovych 2018-02-01 13:25:52 +02:00 committed by David Ahern
parent 1e24e773f1
commit 2cd0578fcb
3 changed files with 17 additions and 22 deletions

View File

@ -30,8 +30,7 @@ int get_operstate(const char *name);
int print_linkinfo(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg);
int print_linkinfo_brief(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg,
struct link_filter *filter);
struct nlmsghdr *n, void *arg);
int print_addrinfo(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg);
int print_addrlabel(const struct sockaddr_nl *who,

View File

@ -919,8 +919,7 @@ static void print_link_stats(FILE *fp, struct nlmsghdr *n)
}
int print_linkinfo_brief(const struct sockaddr_nl *who,
struct nlmsghdr *n, void *arg,
struct link_filter *pfilter)
struct nlmsghdr *n, void *arg)
{
FILE *fp = (FILE *)arg;
struct ifinfomsg *ifi = NLMSG_DATA(n);
@ -937,12 +936,9 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
if (len < 0)
return -1;
if (!pfilter)
pfilter = &filter;
if (pfilter->ifindex && ifi->ifi_index != pfilter->ifindex)
if (filter.ifindex && ifi->ifi_index != filter.ifindex)
return -1;
if (pfilter->up && !(ifi->ifi_flags&IFF_UP))
if (filter.up && !(ifi->ifi_flags&IFF_UP))
return -1;
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
@ -953,30 +949,30 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
name = rta_getattr_str(tb[IFLA_IFNAME]);
}
if (pfilter->label &&
(!pfilter->family || pfilter->family == AF_PACKET) &&
fnmatch(pfilter->label, RTA_DATA(tb[IFLA_IFNAME]), 0))
if (filter.label &&
(!filter.family || filter.family == AF_PACKET) &&
fnmatch(filter.label, RTA_DATA(tb[IFLA_IFNAME]), 0))
return -1;
if (tb[IFLA_GROUP]) {
int group = rta_getattr_u32(tb[IFLA_GROUP]);
if (pfilter->group != -1 && group != pfilter->group)
if (filter.group != -1 && group != filter.group)
return -1;
}
if (tb[IFLA_MASTER]) {
int master = rta_getattr_u32(tb[IFLA_MASTER]);
if (pfilter->master > 0 && master != pfilter->master)
if (filter.master > 0 && master != filter.master)
return -1;
} else if (pfilter->master > 0)
} else if (filter.master > 0)
return -1;
if (pfilter->kind && match_link_kind(tb, pfilter->kind, 0))
if (filter.kind && match_link_kind(tb, filter.kind, 0))
return -1;
if (pfilter->slave_kind && match_link_kind(tb, pfilter->slave_kind, 1))
if (filter.slave_kind && match_link_kind(tb, filter.slave_kind, 1))
return -1;
if (n->nlmsg_type == RTM_DELLINK)
@ -1006,7 +1002,7 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
if (tb[IFLA_OPERSTATE])
print_operstate(fp, rta_getattr_u8(tb[IFLA_OPERSTATE]));
if (pfilter->family == AF_PACKET) {
if (filter.family == AF_PACKET) {
SPRINT_BUF(b1);
if (tb[IFLA_ADDRESS]) {
@ -1020,10 +1016,11 @@ int print_linkinfo_brief(const struct sockaddr_nl *who,
}
}
if (pfilter->family == AF_PACKET) {
if (filter.family == AF_PACKET) {
print_link_flags(fp, ifi->ifi_flags, m_flag);
print_string(PRINT_FP, NULL, "%s", "\n");
}
fflush(fp);
return 0;
}
@ -2197,8 +2194,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
open_json_object(NULL);
if (brief) {
if (print_linkinfo_brief(NULL, &l->h,
stdout, NULL) == 0)
if (print_linkinfo_brief(NULL, &l->h, stdout) == 0)
if (filter.family != AF_PACKET)
print_selected_addrinfo(ifi,
ainfo->head,

View File

@ -1077,7 +1077,7 @@ int iplink_get(unsigned int flags, char *name, __u32 filt_mask)
open_json_object(NULL);
if (brief)
print_linkinfo_brief(NULL, answer, stdout, NULL);
print_linkinfo_brief(NULL, answer, stdout);
else
print_linkinfo(NULL, answer, stdout);
close_json_object();