From patchwork Sat Apr 9 10:58:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12807834 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2986BC433F5 for ; Sat, 9 Apr 2022 11:05:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241480AbiDILHL (ORCPT ); Sat, 9 Apr 2022 07:07:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236232AbiDILG7 (ORCPT ); Sat, 9 Apr 2022 07:06:59 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2681F23EC7A for ; Sat, 9 Apr 2022 04:04:52 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id dr20so21785800ejc.6 for ; Sat, 09 Apr 2022 04:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OJhM912bfhb7uMFugRwaEA6kDWsFt0tEfGy7vW0mS0I=; b=SIbGuIOlNQM2gXLI6wvPq/OiqaZuZlgUzTQ45QFtUYdm6NIIc3GSxL6kYcVzdawb6b YtW8i9z7gmBXEx64ydeD1JW3GTPA4jfmSs7UXYvcry4+LO+XfgoAZ2BAUkhM0BN7fDC3 ZVTQ4/fosfRQ50fAeOZTNrrhPjvb74jIQ7eojyRiEQaDd2e2lr7ydHrYgHH7DOHESflO HIbFJgGZ35WPNj4QMOx+/QVLiwJryGWgzxyc3n8Xgfg/V4MSz/LE8o7IH8YKJgvSwDxO qtA4SE/Kn94ydc9pgbR4fj45t3HbfndToPy2YfOehBYZodIAiWm53alkq0FjLLV2UwIn vURw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OJhM912bfhb7uMFugRwaEA6kDWsFt0tEfGy7vW0mS0I=; b=djUsH2lK5jECSKzBNgqfqXX4kAwqynLZIl0GiNThI42BtZg6gU1tJouIbKlncxc0/J lG5p22EOIPyvSdfc1Ix011xt1Pt7TkTotXsjnZwhiPrYzD5QBb2Ryvc7Ds4PJqo7Sxzg txBAi6gcnptkSfLv76+0koRsRyYaVQgqRBYVB0E3wtIrJ9LZMNn3ODoS8YP/SVwPWMwv WLtf5kCVQohk1guHPkPvpCKPwcO2SGXBTEjhTQ92JGelRpE1uAaIkns1RNApRA3xMIxn T+C+ZhBfLF4gt1IKkWyUhlEWJRQ2joPjiq4K6O84u47YtAp39DK7Sin0MP/fyf14Yc6X 6sdw== X-Gm-Message-State: AOAM5320XuyTsjmXoT4Gqq2wnWzxoc+PC+5s6YgPwBCHfDxVTP3I8nbu r7udMCH7rXSKtE1OvL4QpJskdC6fTKpbHN+LwKk= X-Google-Smtp-Source: ABdhPJwYEMDPohwDYUiufv/XqoQdYice2/kWKxabF4RdtB+3ZoftUjO0iq+5NsvsIs/XnS0PYmWXGQ== X-Received: by 2002:a17:907:72cc:b0:6e0:2d3:bcba with SMTP id du12-20020a17090772cc00b006e002d3bcbamr22158460ejc.642.1649502290289; Sat, 09 Apr 2022 04:04:50 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id r11-20020a1709064d0b00b006e87938318dsm179574eju.39.2022.04.09.04.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Apr 2022 04:04:49 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: roopa@nvidia.com, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next 1/6] net: bridge: add a generic flush operation Date: Sat, 9 Apr 2022 13:58:52 +0300 Message-Id: <20220409105857.803667-2-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220409105857.803667-1-razor@blackwall.org> References: <20220409105857.803667-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add a new bridge attribute (IFLA_BRIDGE_FLUSH) which will have embedded attributes describing the object types that will be flushed. It will allow fine-grained object flushing. Only a single flush attribute is allowed per call since it can be a very load heavy operation. Also it is allowed only with setlink command (similar to changelink flush). A nice side-effect of using an af spec attribute is that it avoids making the bridge link attribute options list longer. An example structure for fdbs: [ IFLA_BRIDGE_FLUSH ] `[ BRIDGE_FDB_FLUSH ] `[ FDB_FLUSH_NDM_STATE ] `[ FDB_FLUSH_NDM_FLAGS ] Signed-off-by: Nikolay Aleksandrov --- include/uapi/linux/if_bridge.h | 8 +++++++ net/bridge/br_netlink.c | 42 +++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h index a86a7e7b811f..221a4256808f 100644 --- a/include/uapi/linux/if_bridge.h +++ b/include/uapi/linux/if_bridge.h @@ -123,6 +123,7 @@ enum { IFLA_BRIDGE_MRP, IFLA_BRIDGE_CFM, IFLA_BRIDGE_MST, + IFLA_BRIDGE_FLUSH, __IFLA_BRIDGE_MAX, }; #define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1) @@ -802,4 +803,11 @@ enum { __BRIDGE_QUERIER_MAX }; #define BRIDGE_QUERIER_MAX (__BRIDGE_QUERIER_MAX - 1) + +/* embedded in IFLA_BRIDGE_FLUSH */ +enum { + BRIDGE_FLUSH_UNSPEC, + __BRIDGE_FLUSH_MAX +}; +#define BRIDGE_FLUSH_MAX (__BRIDGE_FLUSH_MAX - 1) #endif /* _UAPI_LINUX_IF_BRIDGE_H */ diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index 200ad05b296f..fe2211d4c0c7 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -779,6 +779,34 @@ int br_process_vlan_info(struct net_bridge *br, return err; } +static const struct nla_policy br_flush_policy[BRIDGE_FLUSH_MAX + 1] = { + [BRIDGE_FLUSH_UNSPEC] = { .type = NLA_REJECT }, +}; + +static int br_flush(struct net_bridge *br, int cmd, + struct nlattr *flush_attr, + struct netlink_ext_ack *extack) +{ + struct nlattr *flush_tb[BRIDGE_FLUSH_MAX + 1]; + int err; + + switch (cmd) { + case RTM_SETLINK: + break; + default: + NL_SET_ERR_MSG_MOD(extack, + "Bridge flush attribute is allowed only with RTM_SETLINK"); + return -EINVAL; + } + + err = nla_parse_nested(flush_tb, BRIDGE_FLUSH_MAX, flush_attr, + br_flush_policy, extack); + if (err) + return err; + + return 0; +} + static int br_afspec(struct net_bridge *br, struct net_bridge_port *p, struct nlattr *af_spec, @@ -787,9 +815,10 @@ static int br_afspec(struct net_bridge *br, { struct bridge_vlan_info *vinfo_curr = NULL; struct bridge_vlan_info *vinfo_last = NULL; - struct nlattr *attr; struct vtunnel_info tinfo_last = {}; struct vtunnel_info tinfo_curr = {}; + bool flushed = false; + struct nlattr *attr; int err = 0, rem; nla_for_each_nested(attr, af_spec, rem) { @@ -845,6 +874,17 @@ static int br_afspec(struct net_bridge *br, if (err) return err; break; + case IFLA_BRIDGE_FLUSH: + if (flushed) { + NL_SET_ERR_MSG_MOD(extack, + "Multiple bridge flush attributes are not allowed"); + return -EINVAL; + } + err = br_flush(br, cmd, attr, extack); + if (err) + return err; + flushed = true; + break; } } From patchwork Sat Apr 9 10:58:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12807835 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AB48C433FE for ; Sat, 9 Apr 2022 11:05:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241502AbiDILHM (ORCPT ); Sat, 9 Apr 2022 07:07:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241316AbiDILHB (ORCPT ); Sat, 9 Apr 2022 07:07:01 -0400 Received: from mail-ed1-x52e.google.com (mail-ed1-x52e.google.com [IPv6:2a00:1450:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04EC823F3AC for ; Sat, 9 Apr 2022 04:04:53 -0700 (PDT) Received: by mail-ed1-x52e.google.com with SMTP id t25so23177edt.9 for ; Sat, 09 Apr 2022 04:04:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Fbnlf8kTog0ziFAwrjyK4x7U8wwDsSsFVdwcSgNLjgs=; b=AfKOr2kRuukfU0wH1SNJb1vCUdfKMEfMlLVYZ4RpMMTaZvfg1fcnr5POTI06kAX56X EDVKZfXiA9nSiuda7IvHYk3ETzZI718onZohFDGcImrrYLAsW42V/QcMeprq8MfCc5el eU+QrkJOthZINMcjUc1PPwugEQ0+vCUdBrs5XZRxhNQW7YKCulRfJ/D0mF0Pz7lVDpYS UWc4jpBTaPFSM4HO4A++p5x1Z1Cwt9yL/Q1gFJ5OGGvwWe42ZEkzDvZLv1lzyWpf58Hg 5L0MplmZ75bJzL5OxHaOUdIt+UCiZMJegFUwJsSvG3VvChKSuffgG6p5e75eA4XPT8ys VDHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Fbnlf8kTog0ziFAwrjyK4x7U8wwDsSsFVdwcSgNLjgs=; b=u+us0UP0JJoDr0BtfqG/TFr4Gypcd2fpIDuTmwLc+VBxaL/p2zawYDTOv0H9QiyI/7 P2W5R2h2ERC9gmLZd0GmGBHwT4XfJqGvYsQrwaHyQybvtmizkuMlbKdv9bvHSIEVvHdO Mngr556IO61C/Y00b5Pe3x+QJqnZFxjf9KBUgO+1RwHLnEeUgmJ/JHGJ5tOMTHlO21Am sw1nfLIPFPNJSycut/wS03WJALGGwKybVn/VON6ThHU3MDYMhNsEU8tWW68xSf6HMk/s sOG/zXuXYfCTwb0jwltnqCipayX9T8zvKWjGPCkYQCR5NJITnEQM5cQZH7b7LGZhG0Vw 8ufQ== X-Gm-Message-State: AOAM5323l89wYQDDk/zVTEub8+Z6YRPXJ1I8rnJfxZH8HNIPbseZh0ey CIpqkmbJQG68c4pU52gbU12FzX+5NlViVYlZDsM= X-Google-Smtp-Source: ABdhPJxO6m0ucbuZJevVTCM5WUCN24OtKQMo/EiL3Yxax5yCp/D6tdsYWHiwxzAthVaqE1vt+ZfDxQ== X-Received: by 2002:a05:6402:449:b0:41c:9096:44f7 with SMTP id p9-20020a056402044900b0041c909644f7mr23739906edw.43.1649502291288; Sat, 09 Apr 2022 04:04:51 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id r11-20020a1709064d0b00b006e87938318dsm179574eju.39.2022.04.09.04.04.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Apr 2022 04:04:50 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: roopa@nvidia.com, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next 2/6] net: bridge: fdb: add support for fine-grained flushing Date: Sat, 9 Apr 2022 13:58:53 +0300 Message-Id: <20220409105857.803667-3-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220409105857.803667-1-razor@blackwall.org> References: <20220409105857.803667-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add the ability to specify exactly which fdbs to be flushed. They are described by a new structure - net_bridge_fdb_flush_desc. Currently it can match on port/bridge ifindex, vlan id and fdb flags. It is used to describe the existing dynamic fdb flush operation. Signed-off-by: Nikolay Aleksandrov --- net/bridge/br_fdb.c | 36 +++++++++++++++++++++++++++++------- net/bridge/br_netlink.c | 9 +++++++-- net/bridge/br_private.h | 10 +++++++++- net/bridge/br_sysfs_br.c | 6 +++++- 4 files changed, 50 insertions(+), 11 deletions(-) diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 6ccda68bd473..4b0bf88c4121 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -558,18 +558,40 @@ void br_fdb_cleanup(struct work_struct *work) mod_delayed_work(system_long_wq, &br->gc_work, work_delay); } -/* Completely flush all dynamic entries in forwarding database.*/ -void br_fdb_flush(struct net_bridge *br) +static bool __fdb_flush_matches(const struct net_bridge *br, + const struct net_bridge_fdb_entry *f, + const struct net_bridge_fdb_flush_desc *desc) +{ + const struct net_bridge_port *dst = READ_ONCE(f->dst); + int port_ifidx, br_ifidx = br->dev->ifindex; + + port_ifidx = dst ? dst->dev->ifindex : 0; + + return (!desc->vlan_id || desc->vlan_id == f->key.vlan_id) && + (!desc->port_ifindex || + (desc->port_ifindex == port_ifidx || + (!dst && desc->port_ifindex == br_ifidx))) && + (!desc->flags_mask || + ((f->flags & desc->flags_mask) == desc->flags)); +} + +/* Flush forwarding database entries matching the description */ +void br_fdb_flush(struct net_bridge *br, + const struct net_bridge_fdb_flush_desc *desc) { struct net_bridge_fdb_entry *f; - struct hlist_node *tmp; - spin_lock_bh(&br->hash_lock); - hlist_for_each_entry_safe(f, tmp, &br->fdb_list, fdb_node) { - if (!test_bit(BR_FDB_STATIC, &f->flags)) + rcu_read_lock(); + hlist_for_each_entry_rcu(f, &br->fdb_list, fdb_node) { + if (!__fdb_flush_matches(br, f, desc)) + continue; + + spin_lock_bh(&br->hash_lock); + if (!hlist_unhashed(&f->fdb_node)) fdb_delete(br, f, true); + spin_unlock_bh(&br->hash_lock); } - spin_unlock_bh(&br->hash_lock); + rcu_read_unlock(); } /* Flush all entries referring to a specific port. diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index fe2211d4c0c7..6e6dce6880c9 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -1366,8 +1366,13 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[], br_recalculate_fwd_mask(br); } - if (data[IFLA_BR_FDB_FLUSH]) - br_fdb_flush(br); + if (data[IFLA_BR_FDB_FLUSH]) { + struct net_bridge_fdb_flush_desc desc = { + .flags_mask = BR_FDB_STATIC + }; + + br_fdb_flush(br, &desc); + } #ifdef CONFIG_BRIDGE_IGMP_SNOOPING if (data[IFLA_BR_MCAST_ROUTER]) { diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 6e62af2e07e9..e6930e9ee69d 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -274,6 +274,13 @@ struct net_bridge_fdb_entry { struct rcu_head rcu; }; +struct net_bridge_fdb_flush_desc { + unsigned long flags; + unsigned long flags_mask; + int port_ifindex; + u16 vlan_id; +}; + #define MDB_PG_FLAGS_PERMANENT BIT(0) #define MDB_PG_FLAGS_OFFLOAD BIT(1) #define MDB_PG_FLAGS_FAST_LEAVE BIT(2) @@ -759,7 +766,8 @@ int br_fdb_init(void); void br_fdb_fini(void); int br_fdb_hash_init(struct net_bridge *br); void br_fdb_hash_fini(struct net_bridge *br); -void br_fdb_flush(struct net_bridge *br); +void br_fdb_flush(struct net_bridge *br, + const struct net_bridge_fdb_flush_desc *desc); void br_fdb_find_delete_local(struct net_bridge *br, const struct net_bridge_port *p, const unsigned char *addr, u16 vid); diff --git a/net/bridge/br_sysfs_br.c b/net/bridge/br_sysfs_br.c index 3f7ca88c2aa3..612e367fff20 100644 --- a/net/bridge/br_sysfs_br.c +++ b/net/bridge/br_sysfs_br.c @@ -344,7 +344,11 @@ static DEVICE_ATTR_RW(group_addr); static int set_flush(struct net_bridge *br, unsigned long val, struct netlink_ext_ack *extack) { - br_fdb_flush(br); + struct net_bridge_fdb_flush_desc desc = { + .flags_mask = BR_FDB_STATIC + }; + + br_fdb_flush(br, &desc); return 0; } From patchwork Sat Apr 9 10:58:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12807837 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81996C433F5 for ; Sat, 9 Apr 2022 11:05:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241495AbiDILHP (ORCPT ); Sat, 9 Apr 2022 07:07:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241476AbiDILHK (ORCPT ); Sat, 9 Apr 2022 07:07:10 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3B3123F3FF for ; Sat, 9 Apr 2022 04:04:53 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id l7so16450701ejn.2 for ; Sat, 09 Apr 2022 04:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ByfL8z/R6BuRgwZqTxWQ31zr/BQkKOOXCLKFqhleuTY=; b=ilhuW9/NCRq4MTKKfWSDcWFxlWcnsF2ZZozvoMJG02Aiw6o1FZiMM93nJSKtnNfLWI OPN7XWVHpxnl+tP18PkJud6MfyjAWUorgmDYQdfVl3dbUTvMK0fIqxcInmuOFSQFmq6l ypvTJJ1pGUzjZJaaBaB3X+FDpSB3ALFjZzuALMG9ZKj4OFleKGGrtWhL5CIvdJZQyp8j +pg1P7f5FQAxjdPVVbyPotaNcXjxy1ieOy/Bq5U1b0xpt32co5tOSnijoKHmL1gODEjq hJmrlLC8K21YWB5fRAiYJbPb/wEWDPafq8z0g1N9MBDvt4jzGzwPQvg/A9QN8L3wNSx7 FZMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ByfL8z/R6BuRgwZqTxWQ31zr/BQkKOOXCLKFqhleuTY=; b=5Y1BtP57j31n1Ff2cgdGdCFafETdSAeVy+8DvRM4CpW5BGao2jXf7Ga55EClk7zCtI UjH+WtROYUKHSeIZHgKDXE/p1aa76Km1Tp5sWTttePV+AkaezdmyJ4lv1p0997qOPyhv CgZJznAUeNdTZjw7JdjcFdpF6rzALTLPONzvfHNTaU3wgm7q1WdLOn41oQTE4K0vOgwM JIF61YBx6poqaFMQDmV6uqwScd3dNz1rdtW0vuuId94RvoQeM2mLw4AKyhOq4dHaePu5 tSjZjkf1JHBpUKJVjXcFog0Z5e7a6Z1DvH0rqZyYl+NmBfa3F4LWuU82/XBGiTNoajR7 du8w== X-Gm-Message-State: AOAM5326LGKP/0jrSGo89IdbZiW56TUKj405kuhy2Nhr9yKb0PfaSpwr LQ6FmY3FLLqyV1maksujsw5GgFx9OPqkT2nNHE0= X-Google-Smtp-Source: ABdhPJxtyzsUMBx+lnq/Dwpwi4sb6B14tB2bpLSu2+2TcHoBKiJLynE/mrdnudx7dnKRecCCrqd6bg== X-Received: by 2002:a17:906:d10c:b0:6cd:4aa2:cd62 with SMTP id b12-20020a170906d10c00b006cd4aa2cd62mr22117209ejz.229.1649502292179; Sat, 09 Apr 2022 04:04:52 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id r11-20020a1709064d0b00b006e87938318dsm179574eju.39.2022.04.09.04.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Apr 2022 04:04:51 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: roopa@nvidia.com, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next 3/6] net: bridge: fdb: add new nl attribute-based flush call Date: Sat, 9 Apr 2022 13:58:54 +0300 Message-Id: <20220409105857.803667-4-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220409105857.803667-1-razor@blackwall.org> References: <20220409105857.803667-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add a new fdb flush call which parses the embedded attributes in BRIDGE_FLUSH_FDB and fills in the fdb flush descriptor to delete only matching entries. Currently it's a complete flush, support for more fine-grained filtering will be added in the following patches. Signed-off-by: Nikolay Aleksandrov --- include/uapi/linux/if_bridge.h | 8 ++++++++ net/bridge/br_fdb.c | 24 ++++++++++++++++++++++++ net/bridge/br_netlink.c | 8 ++++++++ net/bridge/br_private.h | 2 ++ 4 files changed, 42 insertions(+) diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h index 221a4256808f..2f3799cf14b2 100644 --- a/include/uapi/linux/if_bridge.h +++ b/include/uapi/linux/if_bridge.h @@ -807,7 +807,15 @@ enum { /* embedded in IFLA_BRIDGE_FLUSH */ enum { BRIDGE_FLUSH_UNSPEC, + BRIDGE_FLUSH_FDB, __BRIDGE_FLUSH_MAX }; #define BRIDGE_FLUSH_MAX (__BRIDGE_FLUSH_MAX - 1) + +/* embedded in BRIDGE_FLUSH_FDB */ +enum { + FDB_FLUSH_UNSPEC, + __FDB_FLUSH_MAX +}; +#define FDB_FLUSH_MAX (__FDB_FLUSH_MAX - 1) #endif /* _UAPI_LINUX_IF_BRIDGE_H */ diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 4b0bf88c4121..62f694a739e1 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -594,6 +594,30 @@ void br_fdb_flush(struct net_bridge *br, rcu_read_unlock(); } +static const struct nla_policy br_fdb_flush_policy[FDB_FLUSH_MAX + 1] = { + [FDB_FLUSH_UNSPEC] = { .type = NLA_REJECT }, +}; + +int br_fdb_flush_nlattr(struct net_bridge *br, struct nlattr *fdb_flush_attr, + struct netlink_ext_ack *extack) +{ + struct nlattr *fdb_flush_tb[FDB_FLUSH_MAX + 1]; + struct net_bridge_fdb_flush_desc desc = {}; + int err; + + err = nla_parse_nested(fdb_flush_tb, FDB_FLUSH_MAX, fdb_flush_attr, + br_fdb_flush_policy, extack); + if (err) + return err; + + br_debug(br, "flushing port ifindex: %d vlan id: %u flags: 0x%lx flags mask: 0x%lx\n", + desc.port_ifindex, desc.vlan_id, desc.flags, desc.flags_mask); + + br_fdb_flush(br, &desc); + + return 0; +} + /* Flush all entries referring to a specific port. * if do_all is set also flush static entries * if vid is set delete all entries that match the vlan_id diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c index 6e6dce6880c9..bd2c91e5723d 100644 --- a/net/bridge/br_netlink.c +++ b/net/bridge/br_netlink.c @@ -781,6 +781,7 @@ int br_process_vlan_info(struct net_bridge *br, static const struct nla_policy br_flush_policy[BRIDGE_FLUSH_MAX + 1] = { [BRIDGE_FLUSH_UNSPEC] = { .type = NLA_REJECT }, + [BRIDGE_FLUSH_FDB] = { .type = NLA_NESTED }, }; static int br_flush(struct net_bridge *br, int cmd, @@ -804,6 +805,13 @@ static int br_flush(struct net_bridge *br, int cmd, if (err) return err; + if (flush_tb[BRIDGE_FLUSH_FDB]) { + err = br_fdb_flush_nlattr(br, flush_tb[BRIDGE_FLUSH_FDB], + extack); + if (err) + return err; + } + return 0; } diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index e6930e9ee69d..c7ea531d30ef 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -768,6 +768,8 @@ int br_fdb_hash_init(struct net_bridge *br); void br_fdb_hash_fini(struct net_bridge *br); void br_fdb_flush(struct net_bridge *br, const struct net_bridge_fdb_flush_desc *desc); +int br_fdb_flush_nlattr(struct net_bridge *br, struct nlattr *fdb_flush_attr, + struct netlink_ext_ack *extack); void br_fdb_find_delete_local(struct net_bridge *br, const struct net_bridge_port *p, const unsigned char *addr, u16 vid); From patchwork Sat Apr 9 10:58:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12807838 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 29328C433FE for ; Sat, 9 Apr 2022 11:05:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241483AbiDILHR (ORCPT ); Sat, 9 Apr 2022 07:07:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241473AbiDILHC (ORCPT ); Sat, 9 Apr 2022 07:07:02 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D96B523FF17 for ; Sat, 9 Apr 2022 04:04:54 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id dr20so21785923ejc.6 for ; Sat, 09 Apr 2022 04:04:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=guCQtZJSW+6tAwRjn+xEzfBeefFkGekLuh0Y+O3VkjU=; b=bbLtwEAsjB9MTLVpVYrxb3AsIdDdsAXY/PaSdP03vlHL8c/dcfd+Et0gbMMg0K6fR/ eDjuxvcHs8D/c0Usg9KTbOCYM9jDquU/oVvK/okxHcSF+121z2zgMf1rR0JU6n1cD2U3 sMSbMW4pQu+USvN+a/xOlLxQR3h+KH3q3Oc4XdI7bEdEq4PRobUoXPDsYMvej1mHljdY DxNb8Kfw3DBLUwvrKztbdw2m4qBAauU8M/v1ap3yHlT0ZkZfU0W4scTbVMJregvx3PqO tuVR8vRzq0hkxLTBoP7IlBOXp+tuv2ZtAEm+5HlUZSkH1nQORIdvMue809+Qe4wxCQG5 wQ8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=guCQtZJSW+6tAwRjn+xEzfBeefFkGekLuh0Y+O3VkjU=; b=hkh4mTQVf0z97MszI+st0l/zDC81a7AHwl9b+7XcN3qm5f4MNdGx41PgRBpJcLzdBS PKn0PC60Pvdcs+sVTXB3QAHBdFoY+ljRFwWnK969ltxRW2dfwBakC//sXvURBuZGaGeA SP9XB+4Nx9j2HDhpu7WTRJjK1TSH/jQ7iRPCIue3+CZ/gWEZVte9fc7n6LVaaU6XVzNO 3cwG0NPbJ+lUaEObmAlq9K0K9gJdpf9m9T+IkeCjTL5L/3mvBw27WVra1EN350rEz8o1 /zARxWJtFuDJm7OInGXD3/qoqXrLFe8Zw9/ob4urySILIG2P/FwI3PrN4YsRIZMWcS/f Olgw== X-Gm-Message-State: AOAM531W/KQcZBfehpIZqP0Z2sKwjyKnZGQLMomo958LeWP1rZK97oYh 9EJtLatxf8b+ihLprjaK1b7FfXi6Gp5vLTc1QJY= X-Google-Smtp-Source: ABdhPJxTsykKKSk5FioE0+8GII9stuEihStRh+ExC+z5gJiPkOO8jGnT8FIQsbsGcvIlfrklLNqPzQ== X-Received: by 2002:a17:907:9868:b0:6e8:7ae3:7f42 with SMTP id ko8-20020a170907986800b006e87ae37f42mr266476ejc.224.1649502293056; Sat, 09 Apr 2022 04:04:53 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id r11-20020a1709064d0b00b006e87938318dsm179574eju.39.2022.04.09.04.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Apr 2022 04:04:52 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: roopa@nvidia.com, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next 4/6] net: bridge: fdb: add support for flush filtering based on ndm flags and state Date: Sat, 9 Apr 2022 13:58:55 +0300 Message-Id: <20220409105857.803667-5-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220409105857.803667-1-razor@blackwall.org> References: <20220409105857.803667-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add support for fdb flush filtering based on ndm flags and state. The new attributes allow users to specify a mask and value which are mapped to bridge-specific flags. NTF_USE is used to represent added_by_user flag since it sets it on fdb add and we don't have a 1:1 mapping for it. Signed-off-by: Nikolay Aleksandrov --- include/uapi/linux/if_bridge.h | 4 +++ net/bridge/br_fdb.c | 55 ++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h index 2f3799cf14b2..4638d7e39f2a 100644 --- a/include/uapi/linux/if_bridge.h +++ b/include/uapi/linux/if_bridge.h @@ -815,6 +815,10 @@ enum { /* embedded in BRIDGE_FLUSH_FDB */ enum { FDB_FLUSH_UNSPEC, + FDB_FLUSH_NDM_STATE, + FDB_FLUSH_NDM_STATE_MASK, + FDB_FLUSH_NDM_FLAGS, + FDB_FLUSH_NDM_FLAGS_MASK, __FDB_FLUSH_MAX }; #define FDB_FLUSH_MAX (__FDB_FLUSH_MAX - 1) diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 62f694a739e1..340a2ace1d5e 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -594,8 +594,40 @@ void br_fdb_flush(struct net_bridge *br, rcu_read_unlock(); } +static unsigned long __ndm_state_to_fdb_flags(u16 ndm_state) +{ + unsigned long flags = 0; + + if (ndm_state & NUD_PERMANENT) + __set_bit(BR_FDB_LOCAL, &flags); + if (ndm_state & NUD_NOARP) + __set_bit(BR_FDB_STATIC, &flags); + + return flags; +} + +static unsigned long __ndm_flags_to_fdb_flags(u16 ndm_flags) +{ + unsigned long flags = 0; + + if (ndm_flags & NTF_USE) + __set_bit(BR_FDB_ADDED_BY_USER, &flags); + if (ndm_flags & NTF_EXT_LEARNED) + __set_bit(BR_FDB_ADDED_BY_EXT_LEARN, &flags); + if (ndm_flags & NTF_OFFLOADED) + __set_bit(BR_FDB_OFFLOADED, &flags); + if (ndm_flags & NTF_STICKY) + __set_bit(BR_FDB_STICKY, &flags); + + return flags; +} + static const struct nla_policy br_fdb_flush_policy[FDB_FLUSH_MAX + 1] = { [FDB_FLUSH_UNSPEC] = { .type = NLA_REJECT }, + [FDB_FLUSH_NDM_STATE] = { .type = NLA_U16 }, + [FDB_FLUSH_NDM_FLAGS] = { .type = NLA_U16 }, + [FDB_FLUSH_NDM_STATE_MASK] = { .type = NLA_U16 }, + [FDB_FLUSH_NDM_FLAGS_MASK] = { .type = NLA_U16 }, }; int br_fdb_flush_nlattr(struct net_bridge *br, struct nlattr *fdb_flush_attr, @@ -610,6 +642,29 @@ int br_fdb_flush_nlattr(struct net_bridge *br, struct nlattr *fdb_flush_attr, if (err) return err; + if (fdb_flush_tb[FDB_FLUSH_NDM_STATE]) { + u16 ndm_state = nla_get_u16(fdb_flush_tb[FDB_FLUSH_NDM_STATE]); + + desc.flags |= __ndm_state_to_fdb_flags(ndm_state); + } + if (fdb_flush_tb[FDB_FLUSH_NDM_STATE_MASK]) { + u16 ndm_state_mask; + + ndm_state_mask = nla_get_u16(fdb_flush_tb[FDB_FLUSH_NDM_STATE_MASK]); + desc.flags_mask |= __ndm_state_to_fdb_flags(ndm_state_mask); + } + if (fdb_flush_tb[FDB_FLUSH_NDM_FLAGS]) { + u16 ndm_flags = nla_get_u16(fdb_flush_tb[FDB_FLUSH_NDM_FLAGS]); + + desc.flags |= __ndm_flags_to_fdb_flags(ndm_flags); + } + if (fdb_flush_tb[FDB_FLUSH_NDM_FLAGS_MASK]) { + u16 ndm_flags_mask; + + ndm_flags_mask = nla_get_u16(fdb_flush_tb[FDB_FLUSH_NDM_FLAGS_MASK]); + desc.flags_mask |= __ndm_flags_to_fdb_flags(ndm_flags_mask); + } + br_debug(br, "flushing port ifindex: %d vlan id: %u flags: 0x%lx flags mask: 0x%lx\n", desc.port_ifindex, desc.vlan_id, desc.flags, desc.flags_mask); From patchwork Sat Apr 9 10:58:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12807836 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCB54C433EF for ; Sat, 9 Apr 2022 11:05:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241487AbiDILHN (ORCPT ); Sat, 9 Apr 2022 07:07:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241475AbiDILHK (ORCPT ); Sat, 9 Apr 2022 07:07:10 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0449024058C for ; Sat, 9 Apr 2022 04:04:56 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id g20so12687003edw.6 for ; Sat, 09 Apr 2022 04:04:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ruKthvyRBdKBojJ9cI3HF+YHEwKh0vpzBB/A3CTMky8=; b=6Lxea4KtEreyzkvQXC0nXxpr8fx0jK/b9OrGY4V/fWEGgtpTyMivpumpy3aP/IakOl tqVLSodTNTYTpQ7nOYxeY3DWoUkI9LM4YNnXNIig8zMAbaaZ8LFKcq6lVH4Hg9WbSkwU jTRbFngE6hu3Xu3J2kVRxEMKESXUSZW3ey55pOVgGeAsnL8nsATeU2BIyhIJfSJ8A3aO Em6+F2H38vxyVEYmwaXQmrYtUnZ1AZrDD/rwvwLZfTCGD2vkgvjKhTrffJLfn4krZwcy pCIyS4zrwr7HuYVY2dX1o81fiyK0PS3A//+MMjEsSS4E+eOtJmNuC6vHi9ZM4oQVFR6V 5cyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ruKthvyRBdKBojJ9cI3HF+YHEwKh0vpzBB/A3CTMky8=; b=GNXlNybzbkNa0My/61LFNH1gnQnxRuRHxiSt9BfR7+T2t/Hal+dQ2LBL12N3WErXja FuZ6qAseo1EdWMTgfZ4Zr7kpS0IGDVNhqX86COho5pD1BpCoWGemIpqEKKLo8PnhWihX fRJ9GFWww1yLWOvhp2qSeMaYhsT2lfzoNNL+rR+jqfc9We8jhg+JiEsSNjxxPaWjUdll xc0PLzHb1o08LoOdOtDkGCgMm6EhvHnnNgZabTAOifHOl2bH9zZivR9EypgpziTjfEkS Ei9vGpiB70np8Ak76wwJRtJsLxcd0SdJvFXTxo4cD5yBZbQ7gFJhtaRKtUEffuJ20UTd Tdiw== X-Gm-Message-State: AOAM531EQr51ymx4ihDAS/6SFK4+VEjwuGyUPLCL50xKMDj7X22mKGhh rLZH/TgUq+ypAerr5X+FJut7HlzAVIBha403DdM= X-Google-Smtp-Source: ABdhPJwcaCWCNll8VthWgjCMOUW/rW1g9RgnU8vk5G+v2JLm8Bb+cuJ3ez96x+uRgXD37ZMt8TsErA== X-Received: by 2002:a05:6402:1e92:b0:41d:219:d936 with SMTP id f18-20020a0564021e9200b0041d0219d936mr13400331edf.383.1649502294074; Sat, 09 Apr 2022 04:04:54 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id r11-20020a1709064d0b00b006e87938318dsm179574eju.39.2022.04.09.04.04.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Apr 2022 04:04:53 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: roopa@nvidia.com, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next 5/6] net: bridge: fdb: add support for flush filtering based on ifindex Date: Sat, 9 Apr 2022 13:58:56 +0300 Message-Id: <20220409105857.803667-6-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220409105857.803667-1-razor@blackwall.org> References: <20220409105857.803667-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add support for fdb flush filtering based on destination ifindex. The ifindex must either match a port's device ifindex or the bridge's. Signed-off-by: Nikolay Aleksandrov --- include/uapi/linux/if_bridge.h | 1 + net/bridge/br_fdb.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h index 4638d7e39f2a..67ee12586844 100644 --- a/include/uapi/linux/if_bridge.h +++ b/include/uapi/linux/if_bridge.h @@ -819,6 +819,7 @@ enum { FDB_FLUSH_NDM_STATE_MASK, FDB_FLUSH_NDM_FLAGS, FDB_FLUSH_NDM_FLAGS_MASK, + FDB_FLUSH_PORT_IFINDEX, __FDB_FLUSH_MAX }; #define FDB_FLUSH_MAX (__FDB_FLUSH_MAX - 1) diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 340a2ace1d5e..53208adf7474 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -628,6 +628,7 @@ static const struct nla_policy br_fdb_flush_policy[FDB_FLUSH_MAX + 1] = { [FDB_FLUSH_NDM_FLAGS] = { .type = NLA_U16 }, [FDB_FLUSH_NDM_STATE_MASK] = { .type = NLA_U16 }, [FDB_FLUSH_NDM_FLAGS_MASK] = { .type = NLA_U16 }, + [FDB_FLUSH_PORT_IFINDEX] = { .type = NLA_S32 }, }; int br_fdb_flush_nlattr(struct net_bridge *br, struct nlattr *fdb_flush_attr, @@ -664,6 +665,12 @@ int br_fdb_flush_nlattr(struct net_bridge *br, struct nlattr *fdb_flush_attr, ndm_flags_mask = nla_get_u16(fdb_flush_tb[FDB_FLUSH_NDM_FLAGS_MASK]); desc.flags_mask |= __ndm_flags_to_fdb_flags(ndm_flags_mask); } + if (fdb_flush_tb[FDB_FLUSH_PORT_IFINDEX]) { + int port_ifidx; + + port_ifidx = nla_get_u32(fdb_flush_tb[FDB_FLUSH_PORT_IFINDEX]); + desc.port_ifindex = port_ifidx; + } br_debug(br, "flushing port ifindex: %d vlan id: %u flags: 0x%lx flags mask: 0x%lx\n", desc.port_ifindex, desc.vlan_id, desc.flags, desc.flags_mask); From patchwork Sat Apr 9 10:58:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Aleksandrov X-Patchwork-Id: 12807839 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF070C433EF for ; Sat, 9 Apr 2022 11:05:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241476AbiDILHS (ORCPT ); Sat, 9 Apr 2022 07:07:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241482AbiDILHL (ORCPT ); Sat, 9 Apr 2022 07:07:11 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 646A8241A10 for ; Sat, 9 Apr 2022 04:04:56 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id w18so12632681edi.13 for ; Sat, 09 Apr 2022 04:04:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pI4juhDXvvHTh0rGKGfMfLE6PZX77VF+PfLCGPPEVPU=; b=7Xj6XrbUXlfjlBFZqVNm3ajjO3GpKvG9FGv29kYvmyM0tZ/j7ilBb7io1qOU53kWbb yr4jlrpYDe7dIV7kbQk282i9NwC2uFaWTAwGux3wcAoxVpIUddc1LVr6cnmHxOQjFDg6 2F+mew77iqtO4+3ht4Rg+43B0GcBiFyMyrPW48qVeHUcd9HilQp0FDei3LEkYybW7O5J DvEPuEddTG1Drn3hMrsH005CeJXzgYaJVV2Hj6HDEHi/oWo3/wtq2EXzirUHJY9gXFXg +tiwAyrWhoZLoa+lCuh2d4yTc+zkPlGPKWTRSE7hbtm4R2MuL9Wev4RwFd/GpTMEpdgi c91A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pI4juhDXvvHTh0rGKGfMfLE6PZX77VF+PfLCGPPEVPU=; b=LMGfGZEzwN6xumt5MQQoqCzxEJaUjKVnAYp0gnSwCi6/9TddFKNDgrp8iTqIqwX/Tv eeQwXpaF5BGX6lDYCopcA5TUSutWAFy5l6uZkEL6Jv28YbklLkiqxyM6u1s0BC1vbnhm GKikCKsVbQ4OLpoKHwZAqnjCxi4jSl9Owd1nbFrJmq6efPgpkOWIqVOCm1n4b86B2dzH W2kg86Uwy2kpZaedgqyIh5Tgw6PrBq4bVxudG2HHu1M0YmT2yCychIjOaleasqwICBZT yJWOTFIR/P1DUPVzJ9IwbqW2JEQ/qgNRrxNGKNFCY3vCe7LQ8ENQsoQIhLb3T10AlglY oong== X-Gm-Message-State: AOAM533nyrkbeBEIWZi74LZny2dDmkKLO6jslJ477Bgn8NnejJd+VqK3 ZM/mSRi8P36YOMpYGKPkOzEBxxvsCXiZ244zatQ= X-Google-Smtp-Source: ABdhPJx4bak1GlJt3DvLQ7SnZM7ZLqBj3nF8XgcBSJrJRibsIUXwPLesQXqb4zLYtnsmq8p0vs8xqg== X-Received: by 2002:a50:cd19:0:b0:41d:709f:5c57 with SMTP id z25-20020a50cd19000000b0041d709f5c57mr689523edi.227.1649502295159; Sat, 09 Apr 2022 04:04:55 -0700 (PDT) Received: from debil.. (87-243-81-1.ip.btc-net.bg. [87.243.81.1]) by smtp.gmail.com with ESMTPSA id r11-20020a1709064d0b00b006e87938318dsm179574eju.39.2022.04.09.04.04.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Apr 2022 04:04:54 -0700 (PDT) From: Nikolay Aleksandrov To: netdev@vger.kernel.org Cc: roopa@nvidia.com, kuba@kernel.org, davem@davemloft.net, bridge@lists.linux-foundation.org, Nikolay Aleksandrov Subject: [PATCH net-next 6/6] net: bridge: fdb: add support for flush filtering based on vlan id Date: Sat, 9 Apr 2022 13:58:57 +0300 Message-Id: <20220409105857.803667-7-razor@blackwall.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220409105857.803667-1-razor@blackwall.org> References: <20220409105857.803667-1-razor@blackwall.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add support for fdb flush filtering based on vlan id. Signed-off-by: Nikolay Aleksandrov --- include/uapi/linux/if_bridge.h | 1 + net/bridge/br_fdb.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h index 67ee12586844..7f6730812916 100644 --- a/include/uapi/linux/if_bridge.h +++ b/include/uapi/linux/if_bridge.h @@ -820,6 +820,7 @@ enum { FDB_FLUSH_NDM_FLAGS, FDB_FLUSH_NDM_FLAGS_MASK, FDB_FLUSH_PORT_IFINDEX, + FDB_FLUSH_VLAN_ID, __FDB_FLUSH_MAX }; #define FDB_FLUSH_MAX (__FDB_FLUSH_MAX - 1) diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 53208adf7474..bc8b5cbde8ed 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -626,6 +626,7 @@ static const struct nla_policy br_fdb_flush_policy[FDB_FLUSH_MAX + 1] = { [FDB_FLUSH_UNSPEC] = { .type = NLA_REJECT }, [FDB_FLUSH_NDM_STATE] = { .type = NLA_U16 }, [FDB_FLUSH_NDM_FLAGS] = { .type = NLA_U16 }, + [FDB_FLUSH_VLAN_ID] = { .type = NLA_U16 }, [FDB_FLUSH_NDM_STATE_MASK] = { .type = NLA_U16 }, [FDB_FLUSH_NDM_FLAGS_MASK] = { .type = NLA_U16 }, [FDB_FLUSH_PORT_IFINDEX] = { .type = NLA_S32 }, @@ -671,6 +672,11 @@ int br_fdb_flush_nlattr(struct net_bridge *br, struct nlattr *fdb_flush_attr, port_ifidx = nla_get_u32(fdb_flush_tb[FDB_FLUSH_PORT_IFINDEX]); desc.port_ifindex = port_ifidx; } + if (fdb_flush_tb[FDB_FLUSH_VLAN_ID]) { + desc.vlan_id = nla_get_u16(fdb_flush_tb[FDB_FLUSH_VLAN_ID]); + if (!br_vlan_valid_id(desc.vlan_id, extack)) + return -EINVAL; + } br_debug(br, "flushing port ifindex: %d vlan id: %u flags: 0x%lx flags mask: 0x%lx\n", desc.port_ifindex, desc.vlan_id, desc.flags, desc.flags_mask);