Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp685918rwb; Tue, 4 Oct 2022 09:14:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4/E0VI8EMsnxipJmZaQNQ6S5UlHmoLJZu4yA7uRn9LcohyfENUnkWpug6f/I6D8iR097Fd X-Received: by 2002:a17:906:8a64:b0:78c:725f:610b with SMTP id hy4-20020a1709068a6400b0078c725f610bmr6686511ejc.347.1664900062411; Tue, 04 Oct 2022 09:14:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664900062; cv=none; d=google.com; s=arc-20160816; b=LWzcujHT5WpBYLzldxdZhf1Z+7W2P4LF4WdyTOANYkEdNhkvemm7TIyr7/1uUVreY0 IB2ZQlqjkaC6/cjyLJdBovpz80oSdVbMXHUG1C1CoCOV3QCn3qSwOewLxWWxfWWsROq2 fCR733AT73jrEPZ5noCX5qHfw/BgFjWeAKBRw+J7WhzZIGS/kOkTgULa+jc0imTBkHyp Miwte6Gp7X4Q7H60tKNEx7Xj0mHNeXyd2NZnm2M/fR/BstNOaIL76/HDvZ5s988c9MbA A7boZYbOVoPTAuyaCIBchs8mcJD0q3vHpepoZMxwXlLfYt8e6AbVqY1hiO5WyEzgGuBZ El7w== 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=aDDYNPmPIO8lF82QnYDHqknyAJoGYuOkiVjkdrkRog0=; b=RrqQxIHmnG+OQvrpzw6oEXae5dHXerdePk7Pysrbf//e/23yD45gu/w0+aCPA6ldGa Ii6WmzxNF02fIFMsdC3hbWY+vewS6xoz/7PCRE7LykpVWUXauGV+L4F6LpHrDWZ6DAO/ f72Yku0Pv63zKODapmUP3guGxcmMArJRGMRqZnlMDKYyBoCuKCdTJpZLLBCZ6f+Iy9gn CkJI9vkqz+VrqNW7pMBBYwiU3IgqN9J35nEQjHvzltjNhdWOwfonyiHJgQTHsTdTgjFm MDcPHFQQ3qhCpGdPTZ7uKPckDVOY5yRQDJUo489ZkPqaFGjRnIy8Xftf7OUD1RSdrXvg 5zXQ== 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 jz2-20020a170906bb0200b0073d9ea386d4si9937418ejb.983.2022.10.04.09.13.52; Tue, 04 Oct 2022 09:14:22 -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 S229720AbiJDPVJ (ORCPT + 99 others); Tue, 4 Oct 2022 11:21:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229710AbiJDPUz (ORCPT ); Tue, 4 Oct 2022 11:20:55 -0400 Received: from mailout-taastrup.gigahost.dk (mailout-taastrup.gigahost.dk [46.183.139.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61B575FAD0; Tue, 4 Oct 2022 08:20:54 -0700 (PDT) Received: from mailout.gigahost.dk (mailout.gigahost.dk [89.186.169.112]) by mailout-taastrup.gigahost.dk (Postfix) with ESMTP id C91BD1884BAC; Tue, 4 Oct 2022 15:20:52 +0000 (UTC) Received: from smtp.gigahost.dk (smtp.gigahost.dk [89.186.169.109]) by mailout.gigahost.dk (Postfix) with ESMTP id AC91125001FA; Tue, 4 Oct 2022 15:20:52 +0000 (UTC) Received: by smtp.gigahost.dk (Postfix, from userid 1000) id 8B1649EC000E; Tue, 4 Oct 2022 15:20:52 +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 B5CFB9EC000A; Tue, 4 Oct 2022 15:20:51 +0000 (UTC) From: Hans Schultz To: davem@davemloft.net, kuba@kernel.org Cc: netdev@vger.kernel.org, Hans 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 v2 iproute2-next 4/4] bridge: fdb: enable FDB blackhole feature Date: Tue, 4 Oct 2022 17:20:36 +0200 Message-Id: <20221004152036.7848-4-netdev@kapio-technology.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004152036.7848-1-netdev@kapio-technology.com> References: <20221004152036.7848-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 Block traffic to a specific host with the command: bridge fdb add vlan dev br0 blackhole Blackhole FDB entries can be added, deleted and replaced with ordinary FDB entries. Example with output: $ bridge fdb add 10:10:10:10:10:10 dev br0 blackhole $ bridge -d fdb show dev br0 10:10:10:10:10:10 vlan 1 blackhole master br0 permanent 10:10:10:10:10:10 blackhole master br0 permanent $ bridge -d -j -p fdb show dev br0 [ { "mac": "10:10:10:10:10:10", "vlan": 1, "flags": [ "blackhole" ], "master": "br0", "state": "permanent" },{ "mac": "10:10:10:10:10:10", "flags": [ "blackhole" ], "master": "br0", "state": "permanent" } ] Signed-off-by: Hans Schultz --- bridge/fdb.c | 13 ++++++++++++- man/man8/bridge.8 | 12 ++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/bridge/fdb.c b/bridge/fdb.c index f1f0a5bb..1c8c50a8 100644 --- a/bridge/fdb.c +++ b/bridge/fdb.c @@ -38,7 +38,7 @@ static void usage(void) fprintf(stderr, "Usage: bridge fdb { add | append | del | replace } ADDR dev DEV\n" " [ self ] [ master ] [ use ] [ router ] [ extern_learn ]\n" - " [ sticky ] [ local | static | dynamic ] [ vlan VID ]\n" + " [ sticky ] [ local | static | dynamic ] [ blackhole ] [ vlan VID ]\n" " { [ dst IPADDR ] [ port PORT] [ vni VNI ] | [ nhid NHID ] }\n" " [ via DEV ] [ src_vni VNI ]\n" " bridge fdb [ show [ br BRDEV ] [ brport DEV ] [ vlan VID ]\n" @@ -116,6 +116,9 @@ static void fdb_print_flags(FILE *fp, unsigned int flags, __u8 ext_flags) if (flags & NTF_STICKY) print_string(PRINT_ANY, NULL, "%s ", "sticky"); + if (ext_flags & NTF_EXT_BLACKHOLE) + print_string(PRINT_ANY, NULL, "%s ", "blackhole"); + if (ext_flags & NTF_EXT_LOCKED) print_string(PRINT_ANY, NULL, "%s ", "locked"); @@ -421,6 +424,7 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv) char *endptr; short vid = -1; __u32 nhid = 0; + __u32 ext_flags = 0; while (argc > 0) { if (strcmp(*argv, "dev") == 0) { @@ -492,6 +496,8 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv) req.ndm.ndm_flags |= NTF_EXT_LEARNED; } else if (matches(*argv, "sticky") == 0) { req.ndm.ndm_flags |= NTF_STICKY; + } else if (matches(*argv, "blackhole") == 0) { + ext_flags |= NTF_EXT_BLACKHOLE; } else { if (strcmp(*argv, "to") == 0) NEXT_ARG(); @@ -534,6 +540,11 @@ static int fdb_modify(int cmd, int flags, int argc, char **argv) if (dst_ok) addattr_l(&req.n, sizeof(req), NDA_DST, &dst.data, dst.bytelen); + if (ext_flags && + addattr_l(&req.n, sizeof(req), NDA_FLAGS_EXT, &ext_flags, + sizeof(ext_flags)) < 0) + return -1; + if (vid >= 0) addattr16(&req.n, sizeof(req), NDA_VLAN, vid); if (nhid > 0) diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index f4f1d807..0119a2a9 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -85,6 +85,13 @@ bridge \- show / manipulate bridge addresses and devices .B nhid .IR NHID " } " +.ti -8 +.BR "bridge fdb" " { " add " | " del " } " +.I LLADR +.B dev +.IR BRDEV " [ " +.BR self " ] [ " local " ] [ " blackhole " ] " + .ti -8 .BR "bridge fdb" " [ [ " show " ] [ " .B br @@ -701,6 +708,11 @@ controller learnt dynamic entry. Kernel will not age such an entry. - this entry will not change its port due to learning. .sp +.B blackhole +- this entry will silently discard all matching packets. The entry must +be added as a local permanent entry. +.sp + .in -8 The next command line parameters apply only when the specified device -- 2.34.1