From: Serhey Popovych <serhe.popovych@gmail.com>
To: netdev@vger.kernel.org
Cc: dsahern@gmail.com
Subject: [PATCH iproute2-next v5 1/9] ipaddress: Abstract IFA_LABEL matching code
Date: Thu, 15 Feb 2018 23:23:16 +0200 [thread overview]
Message-ID: <1518729804-19873-2-git-send-email-serhe.popovych@gmail.com> (raw)
In-Reply-To: <1518729804-19873-1-git-send-email-serhe.popovych@gmail.com>
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>
---
ip/ipaddress.c | 57 +++++++++++++++++++++++++++-----------------------------
1 file changed, 27 insertions(+), 30 deletions(-)
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 6990b81..ad69d09 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -1305,6 +1305,22 @@ static int get_filter(const char *arg)
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,
void *arg)
{
@@ -1343,21 +1359,13 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
return 0;
if ((filter.flags ^ ifa_flags) & filter.flagmask)
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)
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]))
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)
continue;
- if (filter.pfx.family || filter.label) {
- struct rtattr *rta =
- tb[IFA_LOCAL] ? : tb[IFA_ADDRESS];
-
- if (inet_addr_match_rta(&filter.pfx, rta))
- continue;
-
- if (filter.label) {
- SPRINT_BUF(b1);
- const char *label;
-
- 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;
- }
- }
+
+ if (ifa_label_match_rta(ifa->ifa_index, tb[IFA_LABEL]))
+ continue;
+
+ if (!tb[IFA_LOCAL])
+ tb[IFA_LOCAL] = tb[IFA_ADDRESS];
+ if (inet_addr_match_rta(&filter.pfx, tb[IFA_LOCAL]))
+ continue;
ok = 1;
break;
--
1.7.10.4
next prev parent reply other threads:[~2018-02-15 21:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-15 21:23 [PATCH iproute2-next v5 0/9] ipaddress: Make print_linkinfo_brief() static Serhey Popovych
2018-02-15 21:23 ` Serhey Popovych [this message]
2018-02-15 21:23 ` [PATCH iproute2-next v5 2/9] ipaddress: ll_map: Replace ll_idx_n2a() with ll_index_to_name() Serhey Popovych
2018-02-15 21:23 ` [PATCH iproute2-next v5 3/9] utils: Reimplement ll_idx_n2a() and introduce ll_idx_a2n() Serhey Popovych
2018-02-15 21:23 ` [PATCH iproute2-next v5 4/9] ipaddress: Improve print_linkinfo() Serhey Popovych
2018-02-15 21:23 ` [PATCH iproute2-next v5 5/9] ipaddress: Simplify print_linkinfo_brief() and it's usage Serhey Popovych
2018-02-15 21:23 ` [PATCH iproute2-next v5 6/9] lib: Correct object file dependencies Serhey Popovych
2018-02-15 21:23 ` [PATCH iproute2-next v5 7/9] utils: Introduce and use get_ifname_rta() Serhey Popovych
2018-02-15 21:23 ` [PATCH iproute2-next v5 8/9] utils: Introduce and use print_name_and_link() to print name@link Serhey Popovych
2018-02-15 21:23 ` [PATCH iproute2-next v5 9/9] ipaddress: Make print_linkinfo_brief() static Serhey Popovych
2018-02-16 16:17 ` [PATCH iproute2-next v5 0/9] " David Ahern
2018-02-16 16:56 ` Serhey Popovych
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1518729804-19873-2-git-send-email-serhe.popovych@gmail.com \
--to=serhe.popovych@gmail.com \
--cc=dsahern@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).