From patchwork Thu Aug 2 13:29:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linhaifeng X-Patchwork-Id: 952734 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41h9yy1p90z9ryt for ; Thu, 2 Aug 2018 23:30:17 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id F06A3E27; Thu, 2 Aug 2018 13:30:14 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 2D887E1B for ; Thu, 2 Aug 2018 13:30:14 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from huawei.com (szxga04-in.huawei.com [45.249.212.190]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 498F3701 for ; Thu, 2 Aug 2018 13:30:13 +0000 (UTC) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 6C1B53B191110; Thu, 2 Aug 2018 21:30:07 +0800 (CST) Received: from localhost (10.177.20.223) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.399.0; Thu, 2 Aug 2018 21:30:02 +0800 From: Haifeng Lin To: , Date: Thu, 2 Aug 2018 21:29:52 +0800 Message-ID: <1533216592-12612-1-git-send-email-haifeng.lin@huawei.com> X-Mailer: git-send-email 1.8.5.2.msysgit.0 MIME-Version: 1.0 X-Originating-IP: [10.177.20.223] X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] netlink-notifier: support blacklist X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org in dpdk ovs mode some ether not need rtnetlink notifier so we can use blacklist remove ethernet from rtnetlink notifier Change-Id: I34121a4c44bfb2fcfe8799130762474bbfe5c015 Signed-off-by: Haifeng Lin --- lib/netdev-dpdk.c | 3 ++ lib/netlink-notifier.c | 5 ++- lib/rtnetlink.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/rtnetlink.h | 22 ++++++++++ 4 files changed, 138 insertions(+), 1 deletion(-) diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index 9bf2185..2cfe5c8 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; 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..c2e12e9 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,94 @@ 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; +} + +int +rtnetlink_blacklist_add(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, sizeof(*name))) { + return 0; + } + } + + entry = xmalloc(sizeof *entry); + entry->name = strdup(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; + + CMAP_FOR_EACH_WITH_HASH (entry, cmap_node, hash_string(name, 0), + &if_blacklist) { + if (!strncmp(name, entry->name, sizeof(*name))) { + break; + } + } + + 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, sizeof(*change->ifname))) { + return true; + } + } + } + + return false; +} + diff --git a/lib/rtnetlink.h b/lib/rtnetlink.h index 422d1db..0fe7c5b 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 if name to blacklist + * @name if name + */ +int +rtnetlink_blacklist_add(const char* name); + +/** + * rtnetlink_blacklist_del - del if name in blacklist + * @name if name + */ +int +rtnetlink_blacklist_del(const char* name); + +/** + * rtnetlink_is_in_blacklist - check if name whether in blacklist + * @c pointer to struct rtnetlink_change + */ +bool +rtnetlink_is_in_blacklist(void *c); + #endif /* rtnetlink.h */