Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3805835rwb; Sun, 9 Oct 2022 11:21:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5S96+g3BPjEwElCGGRg+yL99TAyTR5cTDMUW5c/L4KioCYyQtlKqhks5YvD3nhYfQMemp6 X-Received: by 2002:a17:90b:384a:b0:20a:dbe3:25d7 with SMTP id nl10-20020a17090b384a00b0020adbe325d7mr27949607pjb.85.1665339694393; Sun, 09 Oct 2022 11:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665339694; cv=none; d=google.com; s=arc-20160816; b=TL9TIeLEoLgCW9nZ4ML8LfvI+BBL4ZmGndkd8FRt450kiRIAeQ349+jRA3ebhqaimq 1TTl6axiW+1LkxAnSGa8d5gDOJsU7moWbELkAKWSFIjiRavzMSzInRemkDnMem8uXacM 1EGjH/NLW7WeB28T+5R/2cvNxWVhuSL5VoHOMMFX8lyigpwXjIVxx0WXNhHpz5A2nWX/ kLyARqNojKSKHqFcfikF8kCmABl797ZN/Ifxd6k8PUE8ogbtmrZhpLG5RNSLBWS1sIPX QeETLLoOWWc3ERlyFbLTiaqZ5lKw7c3Eqt7gDuVb5MXsUP63Hr/EKsQuMkVPNEf2P21r A99Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:organization :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=nDV0bNjvJPDT2NveirZvObH4eoZNGdoGV6kSQAzE/ic=; b=y82N6gCFKdRU/ipybU93iAc2XdBedvUPimJqk1qmSbE8+ltShtYktDTo+KkeKcgQ3G MIe5xgATFYWVgpCmC26qWWA03LtRoCvmC4g9ydydD5IY48wJZ4zY/Z9b+QQpidkAjRXm 2GftR0yX1bgGYJ92WswFC+61NmxNEcRLZ1UgOkHrGudLGzJqdkr2Ysha9ENzSJRRsq1J tKxB2hquPsmOhrLLzlCaRiiYby2HHMxz4Oq3PDEuEpYLqFTS70lnZGdQ/2Voj7wPYKQ8 4WeXUWtblcOVr1TIuaQ0X6wlhaDXd20EQTkq7ujL2UApB1uLy7aVgDMw40Ebbmiw3f8k FCZQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u2-20020a17090282c200b0017f8723b451si8557957plz.427.2022.10.09.11.21.22; Sun, 09 Oct 2022 11:21:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230184AbiJIRlq (ORCPT + 99 others); Sun, 9 Oct 2022 13:41:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbiJIRld (ORCPT ); Sun, 9 Oct 2022 13:41:33 -0400 Received: from mailout-taastrup.gigahost.dk (mailout-taastrup.gigahost.dk [46.183.139.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A75E66305; Sun, 9 Oct 2022 10:41:31 -0700 (PDT) Received: from mailout.gigahost.dk (mailout.gigahost.dk [89.186.169.112]) by mailout-taastrup.gigahost.dk (Postfix) with ESMTP id 5A36D18843FC; Sun, 9 Oct 2022 17:41:30 +0000 (UTC) Received: from smtp.gigahost.dk (smtp.gigahost.dk [89.186.169.109]) by mailout.gigahost.dk (Postfix) with ESMTP id 51E6F25052CE; Sun, 9 Oct 2022 17:41:30 +0000 (UTC) Received: by smtp.gigahost.dk (Postfix, from userid 1000) id 3E6D19EC0005; Sun, 9 Oct 2022 17:41:30 +0000 (UTC) X-Screener-Id: 413d8c6ce5bf6eab4824d0abaab02863e8e3f662 Received: from fujitsu.vestervang (2-104-116-184-cable.dk.customer.tdc.net [2.104.116.184]) by smtp.gigahost.dk (Postfix) with ESMTPSA id 5905F9EC0002; Sun, 9 Oct 2022 17:41:29 +0000 (UTC) From: "Hans J. Schultz" To: davem@davemloft.net, kuba@kernel.org Cc: netdev@vger.kernel.org, "Hans J. Schultz" , Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean , Eric Dumazet , Paolo Abeni , Kurt Kanzenbach , Hauke Mehrtens , Woojung Huh , UNGLinuxDriver@microchip.com, Sean Wang , Landen Chao , DENG Qingfang , Matthias Brugger , Claudiu Manoil , Alexandre Belloni , Jiri Pirko , Ivan Vecera , Roopa Prabhu , Nikolay Aleksandrov , Shuah Khan , Russell King , Christian Marangi , Daniel Borkmann , Yuwei Wang , Petr Machata , Ido Schimmel , Florent Fourcot , Hans Schultz , Joachim Wiberg , Amit Cohen , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, bridge@lists.linux-foundation.org, linux-kselftest@vger.kernel.org Subject: [PATCH v7 net-next 4/9] net: switchdev: support offloading of the FDB blackhole flag Date: Sun, 9 Oct 2022 19:40:47 +0200 Message-Id: <20221009174052.1927483-5-netdev@kapio-technology.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221009174052.1927483-1-netdev@kapio-technology.com> References: <20221009174052.1927483-1-netdev@kapio-technology.com> MIME-Version: 1.0 Organization: Westermo Network Technologies AB Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support for offloading of the FDB blackhole flag. Signed-off-by: Hans J. Schultz --- include/net/dsa.h | 1 + include/net/switchdev.h | 1 + net/bridge/br.c | 3 ++- net/bridge/br_fdb.c | 19 ++++++++++++++++--- net/bridge/br_private.h | 3 ++- net/bridge/br_switchdev.c | 1 + net/dsa/dsa_priv.h | 4 ++-- net/dsa/port.c | 22 ++++++++++++---------- net/dsa/slave.c | 6 ++++-- 9 files changed, 41 insertions(+), 19 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index e4b641b20713..d5b2aef52d93 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -822,6 +822,7 @@ static inline bool dsa_port_tree_same(const struct dsa_port *a, } #define DSA_FDB_FLAG_LOCKED (1 << 0) +#define DSA_FDB_FLAG_BLACKHOLE (1 << 1) typedef int dsa_fdb_dump_cb_t(const unsigned char *addr, u16 vid, bool is_static, void *data); diff --git a/include/net/switchdev.h b/include/net/switchdev.h index ca0312b78294..39727902354e 100644 --- a/include/net/switchdev.h +++ b/include/net/switchdev.h @@ -249,6 +249,7 @@ struct switchdev_notifier_fdb_info { u8 added_by_user:1, is_local:1, locked:1, + blackhole:1, offloaded:1; }; diff --git a/net/bridge/br.c b/net/bridge/br.c index e0e2df2fa278..85fc529b6a9f 100644 --- a/net/bridge/br.c +++ b/net/bridge/br.c @@ -166,7 +166,8 @@ static int br_switchdev_event(struct notifier_block *unused, case SWITCHDEV_FDB_ADD_TO_BRIDGE: fdb_info = ptr; err = br_fdb_external_learn_add(br, p, fdb_info->addr, fdb_info->vid, - fdb_info->locked, false); + fdb_info->locked, fdb_info->is_local, + fdb_info->blackhole, false); if (err) { err = notifier_from_errno(err); break; diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index 86fa60cbc26c..d6f22e2e018a 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -1148,7 +1148,7 @@ static int __br_fdb_add(struct ndmsg *ndm, struct net_bridge *br, "FDB entry towards bridge must be permanent"); return -EINVAL; } - err = br_fdb_external_learn_add(br, p, addr, vid, false, true); + err = br_fdb_external_learn_add(br, p, addr, vid, false, false, false, true); } else if ((ext_flags & NTF_EXT_BLACKHOLE) && p) { NL_SET_ERR_MSG_MOD(extack, "Blackhole FDB entry cannot be applied on a port"); return -EINVAL; @@ -1390,7 +1390,7 @@ void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p) int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, const unsigned char *addr, u16 vid, bool locked, - bool swdev_notify) + bool local, bool blackhole, bool swdev_notify) { struct net_bridge_fdb_entry *fdb; bool modified = false; @@ -1407,12 +1407,15 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, if (swdev_notify) flags |= BIT(BR_FDB_ADDED_BY_USER); - if (!p) + if (!p || local) flags |= BIT(BR_FDB_LOCAL); if (locked) flags |= BIT(BR_FDB_LOCKED); + if (blackhole) + flags |= BIT(BR_FDB_BLACKHOLE); + fdb = fdb_create(br, p, addr, vid, flags); if (!fdb) { err = -ENOMEM; @@ -1436,11 +1439,21 @@ int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, modified = true; } + if (local != test_bit(BR_FDB_LOCAL, &fdb->flags)) { + change_bit(BR_FDB_LOCAL, &fdb->flags); + modified = true; + } + if (locked != test_bit(BR_FDB_LOCKED, &fdb->flags)) { change_bit(BR_FDB_LOCKED, &fdb->flags); modified = true; } + if (blackhole != test_bit(BR_FDB_BLACKHOLE, &fdb->flags)) { + change_bit(BR_FDB_BLACKHOLE, &fdb->flags); + modified = true; + } + if (swdev_notify) set_bit(BR_FDB_ADDED_BY_USER, &fdb->flags); diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 3e9f4d1fbd60..4202c80e465e 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -812,7 +812,8 @@ int br_fdb_sync_static(struct net_bridge *br, struct net_bridge_port *p); void br_fdb_unsync_static(struct net_bridge *br, struct net_bridge_port *p); int br_fdb_external_learn_add(struct net_bridge *br, struct net_bridge_port *p, const unsigned char *addr, u16 vid, - bool locked, bool swdev_notify); + bool locked, bool local, bool blackhole, + bool swdev_notify); int br_fdb_external_learn_del(struct net_bridge *br, struct net_bridge_port *p, const unsigned char *addr, u16 vid, bool swdev_notify); diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c index ccf1b4cffdd0..ce7b80c782ec 100644 --- a/net/bridge/br_switchdev.c +++ b/net/bridge/br_switchdev.c @@ -137,6 +137,7 @@ static void br_switchdev_fdb_populate(struct net_bridge *br, item->offloaded = test_bit(BR_FDB_OFFLOADED, &fdb->flags); item->is_local = test_bit(BR_FDB_LOCAL, &fdb->flags); item->locked = test_bit(BR_FDB_LOCKED, &fdb->flags); + item->blackhole = test_bit(BR_FDB_BLACKHOLE, &fdb->flags); item->info.dev = (!p || item->is_local) ? br->dev : p->dev; item->info.ctx = ctx; } diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index c943e8934063..611833f162d1 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -251,9 +251,9 @@ int dsa_port_standalone_host_fdb_add(struct dsa_port *dp, int dsa_port_standalone_host_fdb_del(struct dsa_port *dp, const unsigned char *addr, u16 vid); int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, const unsigned char *addr, - u16 vid); + u16 vid, u16 fdb_flags); int dsa_port_bridge_host_fdb_del(struct dsa_port *dp, const unsigned char *addr, - u16 vid); + u16 vid, u16 fdb_flags); int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr, u16 vid); int dsa_port_lag_fdb_del(struct dsa_port *dp, const unsigned char *addr, diff --git a/net/dsa/port.c b/net/dsa/port.c index eab32b7a945a..e4a79fd4a99e 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -1001,12 +1001,13 @@ int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr, static int dsa_port_host_fdb_add(struct dsa_port *dp, const unsigned char *addr, u16 vid, - struct dsa_db db) + u16 fdb_flags, struct dsa_db db) { struct dsa_notifier_fdb_info info = { .dp = dp, .addr = addr, .vid = vid, + .fdb_flags = fdb_flags, .db = db, }; @@ -1024,11 +1025,11 @@ int dsa_port_standalone_host_fdb_add(struct dsa_port *dp, .dp = dp, }; - return dsa_port_host_fdb_add(dp, addr, vid, db); + return dsa_port_host_fdb_add(dp, addr, vid, 0, db); } -int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, - const unsigned char *addr, u16 vid) +int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, const unsigned char *addr, + u16 vid, u16 fdb_flags) { struct net_device *master = dsa_port_to_master(dp); struct dsa_db db = { @@ -1047,17 +1048,18 @@ int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, return err; } - return dsa_port_host_fdb_add(dp, addr, vid, db); + return dsa_port_host_fdb_add(dp, addr, vid, fdb_flags, db); } static int dsa_port_host_fdb_del(struct dsa_port *dp, const unsigned char *addr, u16 vid, - struct dsa_db db) + u16 fdb_flags, struct dsa_db db) { struct dsa_notifier_fdb_info info = { .dp = dp, .addr = addr, .vid = vid, + .fdb_flags = fdb_flags, .db = db, }; @@ -1075,11 +1077,11 @@ int dsa_port_standalone_host_fdb_del(struct dsa_port *dp, .dp = dp, }; - return dsa_port_host_fdb_del(dp, addr, vid, db); + return dsa_port_host_fdb_del(dp, addr, vid, 0, db); } -int dsa_port_bridge_host_fdb_del(struct dsa_port *dp, - const unsigned char *addr, u16 vid) +int dsa_port_bridge_host_fdb_del(struct dsa_port *dp, const unsigned char *addr, + u16 vid, u16 fdb_flags) { struct net_device *master = dsa_port_to_master(dp); struct dsa_db db = { @@ -1094,7 +1096,7 @@ int dsa_port_bridge_host_fdb_del(struct dsa_port *dp, return err; } - return dsa_port_host_fdb_del(dp, addr, vid, db); + return dsa_port_host_fdb_del(dp, addr, vid, fdb_flags, db); } int dsa_port_lag_fdb_add(struct dsa_port *dp, const unsigned char *addr, diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 65f0c578ef44..4e22014ec469 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -3258,7 +3258,7 @@ static void dsa_slave_switchdev_event_work(struct work_struct *work) switch (switchdev_work->event) { case SWITCHDEV_FDB_ADD_TO_DEVICE: if (switchdev_work->host_addr) - err = dsa_port_bridge_host_fdb_add(dp, addr, vid); + err = dsa_port_bridge_host_fdb_add(dp, addr, vid, fdb_flags); else if (dp->lag) err = dsa_port_lag_fdb_add(dp, addr, vid); else @@ -3274,7 +3274,7 @@ static void dsa_slave_switchdev_event_work(struct work_struct *work) case SWITCHDEV_FDB_DEL_TO_DEVICE: if (switchdev_work->host_addr) - err = dsa_port_bridge_host_fdb_del(dp, addr, vid); + err = dsa_port_bridge_host_fdb_del(dp, addr, vid, fdb_flags); else if (dp->lag) err = dsa_port_lag_fdb_del(dp, addr, vid); else @@ -3365,6 +3365,8 @@ static int dsa_slave_fdb_event(struct net_device *dev, if (fdb_info->locked) fdb_flags |= DSA_FDB_FLAG_LOCKED; + if (fdb_info->blackhole) + fdb_flags |= DSA_FDB_FLAG_BLACKHOLE; INIT_WORK(&switchdev_work->work, dsa_slave_switchdev_event_work); switchdev_work->event = event; -- 2.34.1