]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Ignore netlink messages with an our of range pid.
authorRoy Marples <roy@marples.name>
Fri, 7 Feb 2014 14:57:19 +0000 (14:57 +0000)
committerRoy Marples <roy@marples.name>
Fri, 7 Feb 2014 14:57:19 +0000 (14:57 +0000)
if-linux.c

index 11c6874085d7b0aa6fe435c8ad0a39c3306f9897..fe69fc956acd07551f57102cb2676e62cc4d8ce2 100644 (file)
@@ -243,6 +243,18 @@ err_netlink(struct nlmsghdr *nlm)
        return -1;
 }
 
+/* Work out the maximum pid size */
+static inline long long
+get_max_pid_t()
+{
+
+    if (sizeof(pid_t) == sizeof(short))                return SHRT_MAX;
+    if (sizeof(pid_t) == sizeof(int))          return INT_MAX;
+    if (sizeof(pid_t) == sizeof(long))         return LONG_MAX;
+    if (sizeof(pid_t) == sizeof(long long))    return LLONG_MAX;
+    abort();
+}
+
 static int
 link_route(struct nlmsghdr *nlm)
 {
@@ -263,9 +275,15 @@ link_route(struct nlmsghdr *nlm)
        rtm = NLMSG_DATA(nlm);
        if (rtm->rtm_type != RTN_UNICAST ||
            rtm->rtm_table != RT_TABLE_MAIN ||
-           rtm->rtm_family != AF_INET ||
-           nlm->nlmsg_pid == (uint32_t)getpid())
+           rtm->rtm_family != AF_INET)
                return 1;
+       /* Ignore messages generated by us.
+        * For some reason we get messages generated by us
+        * with a very large value in nlmsg_pid that seems to be
+        * sequentially changing. Is there a better test for this? */
+       if (nlm->nlmsg_pid > get_max_pid_t())
+               return 1;
+
        rta = (struct rtattr *)(void *)((char *)rtm +NLMSG_ALIGN(sizeof(*rtm)));
        len = NLMSG_PAYLOAD(nlm, sizeof(*rtm));
        memset(&rt, 0, sizeof(rt));
@@ -328,8 +346,6 @@ link_addr(struct nlmsghdr *nlm)
                errno = EBADMSG;
                return -1;
        }
-//     if (nlm->nlmsg_pid == (uint32_t)getpid())
-//             return 1;
        ifa = NLMSG_DATA(nlm);
        if (if_indextoname(ifa->ifa_index, ifn) == NULL)
                return -1;
@@ -508,6 +524,7 @@ link_netlink(struct nlmsghdr *nlm)
 int
 manage_link(int fd)
 {
+
        return get_netlink(fd, MSG_DONTWAIT, &link_netlink);
 }