[ovs-dev,v3] netlink-notifier: support blacklist

Message ID 1533358256-11020-1-git-send-email-haifeng.lin@huawei.com
State New
Headers show
Series
  • [ovs-dev,v3] netlink-notifier: support blacklist
Related show

Commit Message

Haifeng Lin Aug. 4, 2018, 4:50 a.m.
in dpdk ovs mode some ethernet which have linux interface
not need rtnetlink notifier so we can add them to blacklist.

Signed-off-by: Haifeng Lin <haifeng.lin@huawei.com>
---
 lib/netdev-dpdk.c      |   5 +++
 lib/netlink-notifier.c |   5 ++-
 lib/rtnetlink.c        | 118 +++++++++++++++++++++++++++++++++++++++++++++++++
 lib/rtnetlink.h        |  22 +++++++++
 4 files changed, 149 insertions(+), 1 deletion(-)

Patch

diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index 9bf2185..2b756bd 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -65,6 +65,7 @@ 
 #include "timeval.h"
 #include "uuid.h"
 #include "unixctl.h"
+#include "rtnetlink.h"
 
 enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM};
 
@@ -1015,6 +1016,8 @@  dpdk_eth_dev_init(struct netdev_dpdk *dev)
 
     rte_eth_dev_info_get(dev->port_id, &info);
 
+    rtnetlink_blacklist_add(dev->up.name);
+
     if (strstr(info.driver_name, "vf") != NULL) {
         VLOG_INFO("Virtual function detected, HW_CRC_STRIP will be enabled");
         dev->hw_ol_features |= NETDEV_RX_HW_CRC_STRIP;
@@ -1349,6 +1352,8 @@  netdev_dpdk_destruct(struct netdev *netdev)
     free(dev->devargs);
     common_destruct(dev);
 
+    rtnetlink_blacklist_del(netdev_get_name(netdev));
+
     ovs_mutex_unlock(&dpdk_mutex);
 }
 
diff --git a/lib/netlink-notifier.c b/lib/netlink-notifier.c
index dfecb97..430412d 100644
--- a/lib/netlink-notifier.c
+++ b/lib/netlink-notifier.c
@@ -27,6 +27,7 @@ 
 #include "netlink-socket.h"
 #include "openvswitch/ofpbuf.h"
 #include "openvswitch/vlog.h"
+#include "rtnetlink.h"
 
 VLOG_DEFINE_THIS_MODULE(netlink_notifier);
 
@@ -234,7 +235,9 @@  nln_report(const struct nln *nln, void *change, int group)
 
     LIST_FOR_EACH (notifier, node, &nln->all_notifiers) {
         if (!change || group == notifier->multicast_group) {
-            notifier->cb(change, notifier->aux);
+            if (!rtnetlink_is_in_blacklist(change)) {
+                notifier->cb(change, notifier->aux);
+            }
         }
     }
 }
diff --git a/lib/rtnetlink.c b/lib/rtnetlink.c
index f822dff..65e70f1 100644
--- a/lib/rtnetlink.c
+++ b/lib/rtnetlink.c
@@ -26,6 +26,20 @@ 
 #include "netlink-notifier.h"
 #include "openvswitch/ofpbuf.h"
 #include "packets.h"
+#include "rtnetlink.h"
+#include "cmap.h"
+
+struct if_entry{
+    char *name;
+    struct cmap_node cmap_node;
+};
+
+static struct cmap if_blacklist;
+
+static int
+rtnetlink_blacklist_init(void);
+static int
+rtnetlink_blacklist_uninit(void);
 
 #if IFLA_INFO_MAX < 5
 #define IFLA_INFO_SLAVE_KIND 4
@@ -193,6 +207,8 @@  rtnetlink_notifier_create(rtnetlink_notify_func *cb, void *aux)
         nln = nln_create(NETLINK_ROUTE, rtnetlink_parse_cb, &rtn_change);
     }
 
+    rtnetlink_blacklist_init();
+
     return nln_notifier_create(nln, RTNLGRP_LINK, (nln_notify_func *) cb, aux);
 }
 
@@ -201,6 +217,8 @@  rtnetlink_notifier_create(rtnetlink_notify_func *cb, void *aux)
 void
 rtnetlink_notifier_destroy(struct nln_notifier *notifier)
 {
+    rtnetlink_blacklist_uninit();
+
     nln_notifier_destroy(notifier);
 }
 
@@ -232,3 +250,103 @@  rtnetlink_report_link(void)
         nln_report(nln, NULL, RTNLGRP_LINK);
     }
 }
+
+static int
+rtnetlink_blacklist_init(void)
+{
+    cmap_init(&if_blacklist);
+
+    return 0;
+}
+
+static int
+rtnetlink_blacklist_uninit(void)
+{
+    struct if_entry *entry;
+
+    CMAP_FOR_EACH (entry, cmap_node, &if_blacklist) {
+        if (entry) {
+            free(entry->name);
+            free(entry);
+        }
+    }
+
+    cmap_destroy(&if_blacklist);
+    return 0;
+}
+
+static struct if_entry *
+rtnetlink_blacklist_find(const char *name)
+{
+    struct if_entry *entry;
+
+    CMAP_FOR_EACH_WITH_HASH (entry, cmap_node, hash_string(name, 0),
+                             &if_blacklist) {
+        if (!strncmp(name, entry->name, strlen(name) + 1)) {
+            return entry;
+        }
+    }
+
+    return NULL;
+}
+
+int
+rtnetlink_blacklist_add(const char *name)
+{
+    struct if_entry *entry;
+
+    entry = rtnetlink_blacklist_find(name);
+    if (!entry) {
+        entry = xmalloc(sizeof *entry);
+        entry->name = xstrdup(name);
+        cmap_insert(&if_blacklist, &entry->cmap_node,
+                    hash_string(entry->name, 0));
+    }
+
+    return 0;
+}
+
+static void
+free_if_entry(struct if_entry *entry)
+{
+    free(entry->name);
+    free(entry);
+}
+
+int
+rtnetlink_blacklist_del(const char *name)
+{
+    struct if_entry *entry;
+
+    entry = rtnetlink_blacklist_find(name);
+    if (entry) {
+        cmap_remove(&if_blacklist, &entry->cmap_node,
+                    hash_string(name, 0));
+        ovsrcu_postpone(free_if_entry, entry);
+
+    }
+
+    return 0;
+}
+
+bool
+rtnetlink_is_in_blacklist(void *c)
+{
+    struct rtnetlink_change *change = c;
+    struct if_entry *entry;
+
+    if (!change) {
+        return false;
+    }
+
+    CMAP_FOR_EACH (entry, cmap_node, &if_blacklist) {
+        if (entry) {
+            if (!strncmp(entry->name, change->ifname,
+                strlen(change->ifname) + 1)) {
+                return true;
+            }
+        }
+    }
+
+    return false;
+}
diff --git a/lib/rtnetlink.h b/lib/rtnetlink.h
index 422d1db..0b821e6 100755
--- a/lib/rtnetlink.h
+++ b/lib/rtnetlink.h
@@ -72,4 +72,26 @@  void rtnetlink_notifier_destroy(struct nln_notifier *);
 void rtnetlink_run(void);
 void rtnetlink_wait(void);
 void rtnetlink_report_link(void);
+
+/**
+ * rtnetlink_blacklist_add - add name to blacklist
+ * @name if name
+ */
+int
+rtnetlink_blacklist_add(const char *name);
+
+/**
+ * rtnetlink_blacklist_del - del name in blacklist
+ * @name if name
+ */
+int
+rtnetlink_blacklist_del(const char *name);
+
+/**
+ * rtnetlink_is_in_blacklist - check name whether in blacklist
+ * @c pointer to struct rtnetlink_change
+ */
+bool
+rtnetlink_is_in_blacklist(void *c);
+
 #endif /* rtnetlink.h */