]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Linux: Validate RTM_DELADDR/RTM_NEWADDR messages for IPv6
authorRoy Marples <roy@marples.name>
Tue, 22 Oct 2019 11:39:56 +0000 (12:39 +0100)
committerRoy Marples <roy@marples.name>
Tue, 22 Oct 2019 11:39:56 +0000 (12:39 +0100)
To ensure that if messages lag, they can be ignored.
How to do similar without a heavy getifaddrs call for IPv4?

src/if-linux.c

index 3ee6c5c9d642f9e186f2751c67e69be5246c9f3d..4fd5d265a68ab19a423fcfc707b09028f1955583 100644 (file)
@@ -634,6 +634,7 @@ link_addr(struct dhcpcd_ctx *ctx, struct interface *ifp, struct nlmsghdr *nlm)
 #endif
 #ifdef INET6
        struct in6_addr addr6;
+       int flags;
 #endif
 
        if (nlm->nlmsg_type != RTM_DELADDR && nlm->nlmsg_type != RTM_NEWADDR)
@@ -682,6 +683,8 @@ link_addr(struct dhcpcd_ctx *ctx, struct interface *ifp, struct nlmsghdr *nlm)
                        }
                        rta = RTA_NEXT(rta, len);
                }
+
+               /* XXX how to validate command for address? */
                ipv4_handleifa(ctx, nlm->nlmsg_type, NULL, ifp->name,
                    &addr, &net, &brd, ifa->ifa_flags, (pid_t)nlm->nlmsg_pid);
                break;
@@ -698,6 +701,18 @@ link_addr(struct dhcpcd_ctx *ctx, struct interface *ifp, struct nlmsghdr *nlm)
                        }
                        rta = RTA_NEXT(rta, len);
                }
+
+               /* Validate RTM_DELADDR really means address deleted
+                * and anything else really means address exists. */
+               flags = if_addrflags6(ifp, &addr6, NULL);
+               if (nlm->nlmsg_type == RTM_DELADDR) {
+                       if (flags != -1)
+                               break;
+               } else {
+                       if (flags == -1)
+                               break;
+               }
+
                ipv6_handleifa(ctx, nlm->nlmsg_type, NULL, ifp->name,
                    &addr6, ifa->ifa_prefixlen, ifa->ifa_flags,
                    (pid_t)nlm->nlmsg_pid);