ipaddress: Abstract IFA_LABEL matching code
There at least two places in ip/ipaddress.c where we match IFA_LABEL against filter.label if that is given. Get rid of "common" if () statement for inet_addr_match_rta() and ifa_label_match_rta(): it is not common because first will check for filter.pfx.family != AF_UNSPEC inside and second for filter.label being non NULL. This allows us to further simplify down code and prepare for ll_idx_n2a() replacement with ll_index_to_name() without 80 columns checkpatch notice. Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com> Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
parent
5433656705
commit
17df3d607d
|
|
@ -1305,6 +1305,22 @@ static int get_filter(const char *arg)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ifa_label_match_rta(int ifindex, const struct rtattr *rta)
|
||||||
|
{
|
||||||
|
const char *label;
|
||||||
|
SPRINT_BUF(b1);
|
||||||
|
|
||||||
|
if (!filter.label)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (rta)
|
||||||
|
label = RTA_DATA(rta);
|
||||||
|
else
|
||||||
|
label = ll_idx_n2a(ifindex, b1);
|
||||||
|
|
||||||
|
return fnmatch(filter.label, label, 0);
|
||||||
|
}
|
||||||
|
|
||||||
int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
|
int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
|
||||||
void *arg)
|
void *arg)
|
||||||
{
|
{
|
||||||
|
|
@ -1343,21 +1359,13 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
|
||||||
return 0;
|
return 0;
|
||||||
if ((filter.flags ^ ifa_flags) & filter.flagmask)
|
if ((filter.flags ^ ifa_flags) & filter.flagmask)
|
||||||
return 0;
|
return 0;
|
||||||
if (filter.label) {
|
|
||||||
SPRINT_BUF(b1);
|
|
||||||
const char *label;
|
|
||||||
|
|
||||||
if (rta_tb[IFA_LABEL])
|
|
||||||
label = RTA_DATA(rta_tb[IFA_LABEL]);
|
|
||||||
else
|
|
||||||
label = ll_idx_n2a(ifa->ifa_index, b1);
|
|
||||||
if (fnmatch(filter.label, label, 0) != 0)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter.family && filter.family != ifa->ifa_family)
|
if (filter.family && filter.family != ifa->ifa_family)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
if (ifa_label_match_rta(ifa->ifa_index, rta_tb[IFA_LABEL]))
|
||||||
|
return 0;
|
||||||
|
|
||||||
if (inet_addr_match_rta(&filter.pfx, rta_tb[IFA_LOCAL]))
|
if (inet_addr_match_rta(&filter.pfx, rta_tb[IFA_LOCAL]))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
@ -1713,25 +1721,14 @@ static void ipaddr_filter(struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo)
|
||||||
|
|
||||||
if ((filter.flags ^ ifa_flags) & filter.flagmask)
|
if ((filter.flags ^ ifa_flags) & filter.flagmask)
|
||||||
continue;
|
continue;
|
||||||
if (filter.pfx.family || filter.label) {
|
|
||||||
struct rtattr *rta =
|
|
||||||
tb[IFA_LOCAL] ? : tb[IFA_ADDRESS];
|
|
||||||
|
|
||||||
if (inet_addr_match_rta(&filter.pfx, rta))
|
if (ifa_label_match_rta(ifa->ifa_index, tb[IFA_LABEL]))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (filter.label) {
|
if (!tb[IFA_LOCAL])
|
||||||
SPRINT_BUF(b1);
|
tb[IFA_LOCAL] = tb[IFA_ADDRESS];
|
||||||
const char *label;
|
if (inet_addr_match_rta(&filter.pfx, tb[IFA_LOCAL]))
|
||||||
|
continue;
|
||||||
if (tb[IFA_LABEL])
|
|
||||||
label = RTA_DATA(tb[IFA_LABEL]);
|
|
||||||
else
|
|
||||||
label = ll_idx_n2a(ifa->ifa_index, b1);
|
|
||||||
if (fnmatch(filter.label, label, 0) != 0)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ok = 1;
|
ok = 1;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue