[ovs-dev] [PATCH 2/6] netdev-linux: Fix netdev ipv6 notification

Pravin B Shelar pshelar at ovn.org
Thu Mar 10 00:40:41 UTC 2016


Listen to RTNLGRP_IPV6_IFINFO to get IPv6 address change
notification.

Signed-off-by: Pravin B Shelar <pshelar at ovn.org>
---
 lib/netdev-linux.c | 15 ++++++++++++---
 lib/rtnetlink.c    |  6 ++++--
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index d58c1b1..570677e 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -595,8 +595,8 @@ netdev_linux_notify_sock(void)
 {
     static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
     static struct nl_sock *sock;
-    unsigned int mcgroups[3] = {RTNLGRP_LINK, RTNLGRP_IPV4_IFADDR,
-                                RTNLGRP_IPV6_IFADDR};
+    unsigned int mcgroups[] = {RTNLGRP_LINK, RTNLGRP_IPV4_IFADDR,
+                                RTNLGRP_IPV6_IFADDR, RTNLGRP_IPV6_IFINFO};
 
     if (ovsthread_once_start(&once)) {
         int error;
@@ -652,7 +652,16 @@ netdev_linux_run(void)
             struct rtnetlink_change change;
 
             if (rtnetlink_parse(&buf, &change)) {
-                struct netdev *netdev_ = netdev_from_name(change.ifname);
+                struct netdev *netdev_ = NULL;
+                char dev_name[IFNAMSIZ];
+
+                if (!change.ifname) {
+                     change.ifname = if_indextoname(change.if_index, dev_name);
+                }
+
+                if (change.ifname) {
+                    netdev_ = netdev_from_name(change.ifname);
+                }
                 if (netdev_ && is_netdev_linux_class(netdev_->netdev_class)) {
                     struct netdev_linux *netdev = netdev_linux_cast(netdev_);
 
diff --git a/lib/rtnetlink.c b/lib/rtnetlink.c
index d0c1ee7..d12467e 100644
--- a/lib/rtnetlink.c
+++ b/lib/rtnetlink.c
@@ -100,7 +100,7 @@ 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 },
+            [IFA_LABEL] = { .type = NL_A_STRING, .optional = true },
         };
 
         struct nlattr *attrs[ARRAY_SIZE(policy)];
@@ -115,7 +115,9 @@ rtnetlink_parse(struct ofpbuf *buf, struct rtnetlink_change *change)
 
             change->nlmsg_type     = nlmsg->nlmsg_type;
             change->if_index       = ifaddr->ifa_index;
-            change->ifname         = nl_attr_get_string(attrs[IFA_LABEL]);
+            change->ifname         = (attrs[IFA_LABEL]
+                                      ? nl_attr_get_string(attrs[IFA_LABEL])
+                                      : NULL);
         }
     }
 
-- 
2.5.0




More information about the dev mailing list