rtnetlink: do not use address labels for device name
authorThadeu Lima de Souza Cascardo <cascardo@redhat.com>
Thu, 18 Feb 2016 12:54:28 +0000 (10:54 -0200)
committerThadeu Lima de Souza Cascardo <cascardo@redhat.com>
Thu, 10 Mar 2016 17:03:57 +0000 (14:03 -0300)
Address labels are not the name of the device they belong to, and are not
present in IPv6 notifications. Just use the interface index and get the name
from that.

lib/rtnetlink.c
lib/rtnetlink.h

index d0c1ee7..ef13b18 100644 (file)
@@ -77,7 +77,8 @@ rtnetlink_parse(struct ofpbuf *buf, struct rtnetlink_change *change)
 
             change->nlmsg_type     = nlmsg->nlmsg_type;
             change->if_index       = ifinfo->ifi_index;
-            change->ifname         = nl_attr_get_string(attrs[IFLA_IFNAME]);
+            strncpy(change->ifname, nl_attr_get_string(attrs[IFLA_IFNAME]),
+                    IFNAMSIZ);
             change->ifi_flags      = ifinfo->ifi_flags;
             change->master_ifindex = (attrs[IFLA_MASTER]
                                       ? nl_attr_get_u32(attrs[IFLA_MASTER])
@@ -99,24 +100,14 @@ rtnetlink_parse(struct ofpbuf *buf, struct rtnetlink_change *change)
          *
          * There are *many* more fields in these messages, but currently we
          * only care about these fields. */
-        static const struct nl_policy policy[] = {
-            [IFA_LABEL] = { .type = NL_A_STRING, .optional = false },
-        };
-
-        struct nlattr *attrs[ARRAY_SIZE(policy)];
-
-        parsed = nl_policy_parse(buf, NLMSG_HDRLEN + sizeof(struct ifaddrmsg),
-                                 policy, attrs, ARRAY_SIZE(policy));
-
-        if (parsed) {
-            const struct ifaddrmsg *ifaddr;
+        const struct ifaddrmsg *ifaddr;
 
-            ifaddr = ofpbuf_at(buf, NLMSG_HDRLEN, sizeof *ifaddr);
+        ifaddr = ofpbuf_at(buf, NLMSG_HDRLEN, sizeof *ifaddr);
 
-            change->nlmsg_type     = nlmsg->nlmsg_type;
-            change->if_index       = ifaddr->ifa_index;
-            change->ifname         = nl_attr_get_string(attrs[IFA_LABEL]);
-        }
+        change->nlmsg_type     = nlmsg->nlmsg_type;
+        change->if_index       = ifaddr->ifa_index;
+        if_indextoname(ifaddr->ifa_index, change->ifname);
+        parsed = true;
     }
 
     return parsed;
index 91ed486..55b61be 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdbool.h>
 #include <stdint.h>
 #include <linux/if_ether.h>
+#include <net/if.h>
 
 #include "openvswitch/types.h"
 
@@ -38,7 +39,7 @@ struct rtnetlink_change {
 
     /* Common attributes. */
     int if_index;               /* Index of network device. */
-    const char *ifname;         /* Name of network device. */
+    char ifname[IFNAMSIZ];      /* Name of network device. */
 
     /* Network device link status. */
     int master_ifindex;         /* Ifindex of datapath master (0 if none). */