]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ipaddress: Use inet_addr_match_rta()
authorSerhey Popovych <serhe.popovych@gmail.com>
Wed, 24 Jan 2018 18:56:34 +0000 (20:56 +0200)
committerDavid Ahern <dsahern@gmail.com>
Thu, 25 Jan 2018 17:31:19 +0000 (09:31 -0800)
While there check return from get_prefix() for filter address.

Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
ip/ipaddress.c

index ba60125c1b78dd31eee342f5bd2f2fdb719f4ebd..44894e606ae84855f72cbdfc8cab4043131fbda4 100644 (file)
@@ -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) {