From mboxrd@z Thu Jan 1 00:00:00 1970 From: Serhey Popovych Subject: [PATCH iproute2-next v2 2/8] ipaddress: Use inet_addr_match_rta() Date: Tue, 23 Jan 2018 21:19:24 +0200 Message-ID: <1516735170-20921-3-git-send-email-serhe.popovych@gmail.com> References: <1516735170-20921-1-git-send-email-serhe.popovych@gmail.com> To: netdev@vger.kernel.org Return-path: Received: from mail-lf0-f67.google.com ([209.85.215.67]:35700 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751928AbeAWTTj (ORCPT ); Tue, 23 Jan 2018 14:19:39 -0500 Received: by mail-lf0-f67.google.com with SMTP id a204so2024232lfa.2 for ; Tue, 23 Jan 2018 11:19:38 -0800 (PST) Received: from tuxracer.localdomain ([2a01:6d80::195:20:96:53]) by smtp.gmail.com with ESMTPSA id u87sm162394lfk.8.2018.01.23.11.19.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 23 Jan 2018 11:19:37 -0800 (PST) In-Reply-To: <1516735170-20921-1-git-send-email-serhe.popovych@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: While there check return from get_prefix() for filter address. Signed-off-by: Serhey Popovych --- ip/ipaddress.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index ba60125..44894e6 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -1523,19 +1523,13 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n, if (fnmatch(filter.label, label, 0) != 0) return 0; } - if (filter.pfx.family) { - if (rta_tb[IFA_LOCAL]) { - inet_prefix dst = { .family = ifa->ifa_family }; - - memcpy(&dst.data, RTA_DATA(rta_tb[IFA_LOCAL]), RTA_PAYLOAD(rta_tb[IFA_LOCAL])); - if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen)) - return 0; - } - } if (filter.family && filter.family != ifa->ifa_family) return 0; + if (inet_addr_match_rta(&filter.pfx, rta_tb[IFA_LOCAL])) + return 0; + if (filter.flushb) { struct nlmsghdr *fn; @@ -1889,18 +1883,12 @@ 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) { - if (!tb[IFA_LOCAL]) - tb[IFA_LOCAL] = tb[IFA_ADDRESS]; + struct rtattr *rta = + tb[IFA_LOCAL] ? : tb[IFA_ADDRESS]; - if (filter.pfx.family && tb[IFA_LOCAL]) { - inet_prefix dst = { - .family = ifa->ifa_family - }; + if (inet_addr_match_rta(&filter.pfx, rta)) + continue; - memcpy(&dst.data, RTA_DATA(tb[IFA_LOCAL]), RTA_PAYLOAD(tb[IFA_LOCAL])); - if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bitlen)) - continue; - } if (filter.label) { SPRINT_BUF(b1); const char *label; @@ -2072,7 +2060,8 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action) while (argc > 0) { if (strcmp(*argv, "to") == 0) { NEXT_ARG(); - get_prefix(&filter.pfx, *argv, filter.family); + if (get_prefix(&filter.pfx, *argv, filter.family)) + invarg("invalid \"to\"\n", *argv); if (filter.family == AF_UNSPEC) filter.family = filter.pfx.family; } else if (strcmp(*argv, "scope") == 0) { -- 1.7.10.4