From patchwork Mon Apr 11 08:40:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joachim Wiberg X-Patchwork-Id: 12808700 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 F2B7DC433FE for ; Mon, 11 Apr 2022 08:41:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343921AbiDKInd (ORCPT ); Mon, 11 Apr 2022 04:43:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343917AbiDKInb (ORCPT ); Mon, 11 Apr 2022 04:43:31 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD5733EAA5 for ; Mon, 11 Apr 2022 01:41:17 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id r18so3516008ljp.0 for ; Mon, 11 Apr 2022 01:41:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:organization:content-transfer-encoding; bh=wVQ0HARhc+FxCf/O5hQemDc31KPNUzAFgjRud4EVmj0=; b=IiYlIzzw6xSpVMIsEs9TF4kFV5ijoit+JbuIYRGVRHxl40fbt6p6r5Trxu6a5OYBWy a+6Phbq3A0pk0VkfqfpE4xJ943Z3EGR7sjRuAxznHf1wdsRFaVJ+gCAb/SCDtsxK0ERt aUgZ1sIjquH45Y0I5NONMMRHNSIuikRZN6GcOezI/K1BsYGwVffvhxQCDJdq5PZ0KRMz 9B2TANhwKr5y1Fh5kD7s8VhKVoXD1fOQYIdXbcVycBAZd9Az29dhTeDdyx7jk5jIHuFj Vf1Mq00iKP2sWsmh4W2mPJut+jKflmjfhkthOMEoaBAi+wzu7kJGpNi53sQXT1qbSQ4k IBCw== 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:organization:content-transfer-encoding; bh=wVQ0HARhc+FxCf/O5hQemDc31KPNUzAFgjRud4EVmj0=; b=2PnUMbz/l85ltCinHN06lFpYZYcM7TAXjphXNm/I4LBuvjwuZMgsk+1m0ca/Ointop bS/bE45THnmP+YDA9V8j8BPn3H6a/CnihFybgHipF83F0QXn8sLMIbgK0wQz+5KBoaPJ 4FExVBzXvES2h2Yf6xmgQ+W0CmFVhQkJLInOaFDIsem5b94puBtIvS1rGdka91dQiRWi iD7Rslg6W/ArYqDQ1Z3/+d0djkbjFPieyMIsPS3g2xR39Ern0B055PX+7C+kWbIBHgXj tTZW639hPBXsSWcnmTsePktjL4r5MYFv+T7O+jH5q9q6NlcGMsAQJDc3owrz51Cj7v+L Tw/A== X-Gm-Message-State: AOAM532uQ0kg8o5dWRRhvlh8IeILmf8crwql/f+PEIObfChIvcqWRhRg VsUkIdOLsP87ZYPwS6mNWig= X-Google-Smtp-Source: ABdhPJxM9YmQOWvSk+ddKlvNVI1IhjkzfoUxCeNXbLrRJnzRjCTfLe7xe5IKjjeB7JJdnlvTnIWyKg== X-Received: by 2002:a2e:91d7:0:b0:24b:6981:15a6 with SMTP id u23-20020a2e91d7000000b0024b698115a6mr271533ljg.141.1649666476040; Mon, 11 Apr 2022 01:41:16 -0700 (PDT) Received: from wbg.labs.westermo.se (h-158-174-22-128.NA.cust.bahnhof.se. [158.174.22.128]) by smtp.gmail.com with ESMTPSA id x24-20020a056512047800b0046b9dafd55bsm549080lfd.164.2022.04.11.01.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 01:41:15 -0700 (PDT) From: Joachim Wiberg To: Jakub Kicinski Cc: Nikolay Aleksandrov , Roopa Prabhu , netdev@vger.kernel.org, bridge@lists.linux-foundation.org, "David S . Miller" , Joachim Wiberg Subject: [PATCH v2 net-next 1/2] net: bridge: add support for host l2 mdb entries Date: Mon, 11 Apr 2022 10:40:53 +0200 Message-Id: <20220411084054.298807-2-troglobit@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220411084054.298807-1-troglobit@gmail.com> References: <20220223172407.175865-1-troglobit@gmail.com> <20220411084054.298807-1-troglobit@gmail.com> MIME-Version: 1.0 Organization: Westermo Network Technologies AB Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This patch expands on the earlier work on layer-2 mdb entries by adding support for host entries. Due to the fact that host joined entries do not have any flag field, we infer the permanent flag when reporting the entries to userspace, which otherwise would be listed as 'temp'. Before patch: ~# bridge mdb add dev br0 port br0 grp 01:00:00:c0:ff:ee permanent Error: bridge: Flags are not allowed for host groups. ~# bridge mdb add dev br0 port br0 grp 01:00:00:c0:ff:ee Error: bridge: Only permanent L2 entries allowed. After patch: ~# bridge mdb add dev br0 port br0 grp 01:00:00:c0:ff:ee permanent ~# bridge mdb show dev br0 port br0 grp 01:00:00:c0:ff:ee permanent vid 1 Signed-off-by: Joachim Wiberg Acked-by: Nikolay Aleksandrov --- net/bridge/br_mdb.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c index 4556d913955b..fdcc641fc89a 100644 --- a/net/bridge/br_mdb.c +++ b/net/bridge/br_mdb.c @@ -251,14 +251,16 @@ static int __mdb_fill_info(struct sk_buff *skb, __mdb_entry_fill_flags(&e, flags); e.ifindex = ifindex; e.vid = mp->addr.vid; - if (mp->addr.proto == htons(ETH_P_IP)) + if (mp->addr.proto == htons(ETH_P_IP)) { e.addr.u.ip4 = mp->addr.dst.ip4; #if IS_ENABLED(CONFIG_IPV6) - else if (mp->addr.proto == htons(ETH_P_IPV6)) + } else if (mp->addr.proto == htons(ETH_P_IPV6)) { e.addr.u.ip6 = mp->addr.dst.ip6; #endif - else + } else { ether_addr_copy(e.addr.u.mac_addr, mp->addr.dst.mac_addr); + e.state = MDB_PG_FLAGS_PERMANENT; + } e.addr.proto = mp->addr.proto; nest_ent = nla_nest_start_noflag(skb, MDBA_MDB_ENTRY_INFO); @@ -873,8 +875,8 @@ static int br_mdb_add_group(struct net_bridge *br, struct net_bridge_port *port, return -EINVAL; /* host join errors which can happen before creating the group */ - if (!port) { - /* don't allow any flags for host-joined groups */ + if (!port && !br_group_is_l2(&group)) { + /* don't allow any flags for host-joined IP groups */ if (entry->state) { NL_SET_ERR_MSG_MOD(extack, "Flags are not allowed for host groups"); return -EINVAL; From patchwork Mon Apr 11 08:40:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joachim Wiberg X-Patchwork-Id: 12808701 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 79AFEC433EF for ; Mon, 11 Apr 2022 08:41:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343922AbiDKInk (ORCPT ); Mon, 11 Apr 2022 04:43:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343923AbiDKInf (ORCPT ); Mon, 11 Apr 2022 04:43:35 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46EC63D4A1 for ; Mon, 11 Apr 2022 01:41:20 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id u7so8208947lfs.8 for ; Mon, 11 Apr 2022 01:41:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:organization:content-transfer-encoding; bh=e7IjdhPKEVh1ILxXP0o9ofaJvPijy5TyOaJH5gWrzSo=; b=CG69gl74fRXhya4eLFC2KbyTlkiTOQUfJ0CqTKGenEhzBRLHESehB2tnCquvSwHp9V 8SMqS50EaoIbfSPADm86/PKfHoBBmVzE39VIBPdpxhkJkPilkH3vztEfv3WkKvglG1Os PuqTSsqBr2RuqS/OZiqe3QORivaD67vSahID8wyRBvrivLtQyvh2pnHU8lvqiKi42tPP +A7yJMKoDapprK+zyFWrnq4HlejGJ+SqUcy1CbfwUqjY2GjGeP6jaqbQtqz54pBM65s6 d1V6NoauDuqLA/hv7/CkSd40hEmp5yCDGBhxITP3i+zGdGFdAa9sslFpeEpk7k4WH1YP HVlw== 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:organization:content-transfer-encoding; bh=e7IjdhPKEVh1ILxXP0o9ofaJvPijy5TyOaJH5gWrzSo=; b=2BacB8ZcpHrJqTEFlc44zUC8MaGO4GD2h4VmIi5UipOAzBnT/VULh7qZvCETrKKLeM YDup+DreBzAeIMEXh5x2mzLRp9P2JSi0roV2SkXUjgrzX6KuKyWGlJgIt6YoXOJSxTMP vD+S3PpnCnlgI+Cjzk3QBn5lL6KVT823+L9X8TUURGDSqBAKeekG2ikMuG4HXonmvbY0 6mFUxQ44CICqCFaBMa4XWFUZut758kj1+qi/RlFiEF88DYg44xgjRxm/8UwuCh84TcNj efweYhbRZ7io6x92T3Hl1TJmxlKVHOb/wmncoO2qf6R42EQMZ3YUN8v3BVtWv9nhTW48 I6fg== X-Gm-Message-State: AOAM533EORQ95mZvf332L2bwbX97+LXI1Fhjuv8tDDvLquQ334Nxv5kK CIBytQ3U7c0jTYaSFcDZHyfEteqVRhxzVaMa X-Google-Smtp-Source: ABdhPJwdM/7oBZs5n1xaB3RwYAFSEvoTFzMB0BeIbziN9YE1pQQ3sgHq8emQrtip5/Es8R74XrPYeA== X-Received: by 2002:a05:6512:1681:b0:464:fa16:393d with SMTP id bu1-20020a056512168100b00464fa16393dmr11996924lfb.672.1649666477820; Mon, 11 Apr 2022 01:41:17 -0700 (PDT) Received: from wbg.labs.westermo.se (h-158-174-22-128.NA.cust.bahnhof.se. [158.174.22.128]) by smtp.gmail.com with ESMTPSA id x24-20020a056512047800b0046b9dafd55bsm549080lfd.164.2022.04.11.01.41.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 01:41:16 -0700 (PDT) From: Joachim Wiberg To: Jakub Kicinski Cc: Nikolay Aleksandrov , Roopa Prabhu , netdev@vger.kernel.org, bridge@lists.linux-foundation.org, "David S . Miller" , Joachim Wiberg Subject: [PATCH v2 net-next 2/2] selftests: forwarding: new test, verify host mdb entries Date: Mon, 11 Apr 2022 10:40:54 +0200 Message-Id: <20220411084054.298807-3-troglobit@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220411084054.298807-1-troglobit@gmail.com> References: <20220223172407.175865-1-troglobit@gmail.com> <20220411084054.298807-1-troglobit@gmail.com> MIME-Version: 1.0 Organization: Westermo Network Technologies AB Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Boiler plate for testing static mdb entries. This first test verifies adding and removing host mdb entries for all supported types: IPv4, IPv6, and MAC multicast. Signed-off-by: Joachim Wiberg --- .../testing/selftests/net/forwarding/Makefile | 1 + .../selftests/net/forwarding/bridge_mdb.sh | 103 ++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100755 tools/testing/selftests/net/forwarding/bridge_mdb.sh diff --git a/tools/testing/selftests/net/forwarding/Makefile b/tools/testing/selftests/net/forwarding/Makefile index 8fa97ae9af9e..ae80c2aef577 100644 --- a/tools/testing/selftests/net/forwarding/Makefile +++ b/tools/testing/selftests/net/forwarding/Makefile @@ -2,6 +2,7 @@ TEST_PROGS = bridge_igmp.sh \ bridge_locked_port.sh \ + bridge_mdb.sh \ bridge_port_isolation.sh \ bridge_sticky_fdb.sh \ bridge_vlan_aware.sh \ diff --git a/tools/testing/selftests/net/forwarding/bridge_mdb.sh b/tools/testing/selftests/net/forwarding/bridge_mdb.sh new file mode 100755 index 000000000000..b1ba6876dd86 --- /dev/null +++ b/tools/testing/selftests/net/forwarding/bridge_mdb.sh @@ -0,0 +1,103 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Verify that adding host mdb entries work as intended for all types of +# multicast filters: ipv4, ipv6, and mac + +ALL_TESTS="mdb_add_del_test" +NUM_NETIFS=2 + +TEST_GROUP_IP4="225.1.2.3" +TEST_GROUP_IP6="ff02::42" +TEST_GROUP_MAC="01:00:01:c0:ff:ee" + +source lib.sh + +h1_create() +{ + simple_if_init $h1 192.0.2.1/24 2001:db8:1::1/64 +} + +h1_destroy() +{ + simple_if_fini $h1 192.0.2.1/24 2001:db8:1::1/64 +} + +switch_create() +{ + # Enable multicast filtering + ip link add dev br0 type bridge mcast_snooping 1 + + ip link set dev $swp1 master br0 + + ip link set dev br0 up + ip link set dev $swp1 up +} + +switch_destroy() +{ + ip link set dev $swp1 down + ip link del dev br0 +} + +setup_prepare() +{ + h1=${NETIFS[p1]} + swp1=${NETIFS[p2]} + + vrf_prepare + + h1_create + switch_create +} + +cleanup() +{ + pre_cleanup + + switch_destroy + h1_destroy + + vrf_cleanup +} + +do_mdb_add_del() +{ + local group=$1 + local flag=$2 + + RET=0 + bridge mdb add dev br0 port br0 grp $group $flag 2>/dev/null + check_err $? "Failed adding $group to br0, port br0" + + if [ -z "$flag" ]; then + flag="temp" + fi + + bridge mdb show dev br0 | grep $group | grep -q $flag 2>/dev/null + check_err $? "$group not added with $flag flag" + + bridge mdb del dev br0 port br0 grp $group 2>/dev/null + check_err $? "Failed deleting $group from br0, port br0" + + bridge mdb show dev br0 | grep -q $group >/dev/null + check_err_fail 1 $? "$group still in mdb after delete" + + log_test "MDB add/del group $group to bridge port br0" +} + +mdb_add_del_test() +{ + do_mdb_add_del $TEST_GROUP_MAC permanent + do_mdb_add_del $TEST_GROUP_IP4 + do_mdb_add_del $TEST_GROUP_IP6 +} + +trap cleanup EXIT + +setup_prepare +setup_wait + +tests_run + +exit $EXIT_STATUS