Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp973561pxp; Wed, 16 Mar 2022 23:07:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwxIxVCFResqIMRxN8RIMX3W7hICPhOEL16ElTek+XY/jTQ+71XmtM2WzDWilhbRH1Dz9nA X-Received: by 2002:a17:90b:1e43:b0:1bf:920:8a26 with SMTP id pi3-20020a17090b1e4300b001bf09208a26mr13809718pjb.52.1647497268322; Wed, 16 Mar 2022 23:07:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647497268; cv=none; d=google.com; s=arc-20160816; b=ivMWtFIJWdVzqJjwvZOkTO/zsf2gTLyPfw8wOf4lWdLbpu4DqjLSkewyKT1mKDB7G7 fgJWv/+dwtzdYA+jIMlV50VrdlQ4/4KqZ9RPXTAkvdO/qvry6eNIhs6lR3xGmLQMpZ7z DxXlCvl6pHxUHMyEUVaUYxjnmtKngVEKAm63JC3T3KLcb29tY9cjY9/43ms3KiNCPVqm VtD/1tgp55dxpfvY78CqQttW7CRe1i58pLHShvqepFve2zO28673i26b+8+wLCKTwemP nJghJjwpCpP0DaM2YddC2C1gkjP7IkG4VPfnfYnpmzxAX9DB4TvAsiTm7Au3iubKU5sY /cOQ== 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:dkim-signature; bh=qEjq+JluqrX19JTya9E5BaOdRZi0yTBXOGGVayL2yG8=; b=ELSuFhiPDVhh1lKooaAnJdaGlBAbgtry0QFalj1O+eRrYYP9s+apcqDRqCINWO8tBp wCVvqol06XoJebvVWmOOofE0GeEB0+xkv+qMEDV/qy+l39X0Ek8t91ctf4gIFemNGV8k YRxiKi9uAEHRMZij3qgrD69T9S+1z7JvmnUck+Trb/G2GehxVyqtTKgcm3vDIhNIQ9s8 Nz3tEGzfJBNnujXlqwSu7Cfk9W+SPOkfzYqpgFGdD+To9Qky/UXOCNtjZDWBb86ErqsN oqHepNhkwb3WwkHs1N+ttzUH6ENSJN+I9WFBlXV8/I2oeTrD1nb819HXh9xCmJX+1fsA PYGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@waldekranz-com.20210112.gappssmtp.com header.s=20210112 header.b=E2yBmQ0o; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id cp17-20020a170902e79100b00151b8f2fb41si3465039plb.461.2022.03.16.23.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 23:07:48 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@waldekranz-com.20210112.gappssmtp.com header.s=20210112 header.b=E2yBmQ0o; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7FCEA1F0C88; Wed, 16 Mar 2022 22:16:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357018AbiCPPLE (ORCPT + 99 others); Wed, 16 Mar 2022 11:11:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346968AbiCPPKk (ORCPT ); Wed, 16 Mar 2022 11:10:40 -0400 Received: from mail-lj1-x22e.google.com (mail-lj1-x22e.google.com [IPv6:2a00:1450:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62F715C644 for ; Wed, 16 Mar 2022 08:09:12 -0700 (PDT) Received: by mail-lj1-x22e.google.com with SMTP id g24so2318453lja.7 for ; Wed, 16 Mar 2022 08:09:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:organization:content-transfer-encoding; bh=qEjq+JluqrX19JTya9E5BaOdRZi0yTBXOGGVayL2yG8=; b=E2yBmQ0oQWbZj+OJQ/GtTbkTinQMJwVEMzGVWSNnH0Kb84FX+zg3/y8Xju8B2bQwyW tLeVYacb4MTPPNq2SZPOnk77IcFp0lehuuh2ho1A30bSnkG3im6TlA8jMt1zVAmxI0ZM 0TQKLyrvWxv8duC0gRHF6O/tzSI4KRV1KXlWc8vOQGN5a3LEOWuMt2l3wqhizrCu5Dhg /JthNozYLxn6W/kwLW3JKwfLM1vM7AkJ7C0ebaXQV55TuqspiALUUQQ9FQkCAl/5EYpF DpknQeD8T/noWlT6QM5ZQsW239R6s5c8QWTKBTq/Tq36F4UUD8hCisgqt+k9IN3+6wEw VAwA== 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=qEjq+JluqrX19JTya9E5BaOdRZi0yTBXOGGVayL2yG8=; b=U48a5BTkL2MbabgvKo5ljA5j1UAJkOufwwUB6/8IKAuj2BaW3fi/4nemTCVV8XbnOH 53zIK9UHe3+t31d6kjXndmNIsJiKIQ91oHdJLMRWupziHEy7TtudI5ls9wWUmetMsoa2 YcS+u5gU5YeZHPvZEowygW+PpAWMZLadRYTpE5vF0tQ7cHvVAr6206FTDCFAcvfJoDm9 D7GObTZ9OjqBpwOxQ/HV9PglX6F+1vaJclD1ZrukLQbAkEsJAoiwF8oJEMlKwDV2zawg YRCQIn/e+fML3FIhATwOacXAawda+5E/wN7QzUayCLTvpdg5X9ApE7SSOu8ejNAjH3iE 670w== X-Gm-Message-State: AOAM532jFN8VtJCvt7ahGMv4gzLl4cShLRXtCTALErFY5yqRQRId0KuQ 93pyPHU3y87iSORmXCZAXpYKBQ== X-Received: by 2002:a2e:b058:0:b0:244:d39a:3549 with SMTP id d24-20020a2eb058000000b00244d39a3549mr56652ljl.199.1647443348777; Wed, 16 Mar 2022 08:09:08 -0700 (PDT) Received: from veiron.westermo.com (static-193-12-47-89.cust.tele2.se. [193.12.47.89]) by smtp.gmail.com with ESMTPSA id d2-20020a194f02000000b00448b915e2d3sm176048lfb.99.2022.03.16.08.09.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 08:09:08 -0700 (PDT) From: Tobias Waldekranz To: davem@davemloft.net, kuba@kernel.org Cc: Nikolay Aleksandrov , Andrew Lunn , Vivien Didelot , Florian Fainelli , Vladimir Oltean , Jiri Pirko , Ivan Vecera , Roopa Prabhu , Russell King , Petr Machata , Ido Schimmel , Matt Johnston , Cooper Lees , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bridge@lists.linux-foundation.org Subject: [PATCH v5 net-next 02/15] net: bridge: mst: Allow changing a VLAN's MSTI Date: Wed, 16 Mar 2022 16:08:44 +0100 Message-Id: <20220316150857.2442916-3-tobias@waldekranz.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220316150857.2442916-1-tobias@waldekranz.com> References: <20220316150857.2442916-1-tobias@waldekranz.com> MIME-Version: 1.0 Organization: Westermo Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Allow a VLAN to move out of the CST (MSTI 0), to an independent tree. The user manages the VID to MSTI mappings via a global VLAN setting. The proposed iproute2 interface would be: bridge vlan global set dev br0 vid msti Changing the state in non-zero MSTIs is still not supported, but will be addressed in upcoming changes. Signed-off-by: Tobias Waldekranz Acked-by: Nikolay Aleksandrov --- include/uapi/linux/if_bridge.h | 1 + net/bridge/br_mst.c | 42 ++++++++++++++++++++++++++++++++++ net/bridge/br_private.h | 1 + net/bridge/br_vlan_options.c | 15 ++++++++++++ 4 files changed, 59 insertions(+) diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h index 30a242195ced..f60244b747ae 100644 --- a/include/uapi/linux/if_bridge.h +++ b/include/uapi/linux/if_bridge.h @@ -564,6 +564,7 @@ enum { BRIDGE_VLANDB_GOPTS_MCAST_QUERIER, BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS, BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_STATE, + BRIDGE_VLANDB_GOPTS_MSTI, __BRIDGE_VLANDB_GOPTS_MAX }; #define BRIDGE_VLANDB_GOPTS_MAX (__BRIDGE_VLANDB_GOPTS_MAX - 1) diff --git a/net/bridge/br_mst.c b/net/bridge/br_mst.c index 0f9f596f86bc..d7a7b5d7ddb3 100644 --- a/net/bridge/br_mst.c +++ b/net/bridge/br_mst.c @@ -46,6 +46,48 @@ int br_mst_set_state(struct net_bridge_port *p, u16 msti, u8 state, return 0; } +static void br_mst_vlan_sync_state(struct net_bridge_vlan *pv, u16 msti) +{ + struct net_bridge_vlan_group *vg = nbp_vlan_group(pv->port); + struct net_bridge_vlan *v; + + list_for_each_entry(v, &vg->vlan_list, vlist) { + /* If this port already has a defined state in this + * MSTI (through some other VLAN membership), inherit + * it. + */ + if (v != pv && v->brvlan->msti == msti) { + br_mst_vlan_set_state(pv->port, pv, v->state); + return; + } + } + + /* Otherwise, start out in a new MSTI with all ports disabled. */ + return br_mst_vlan_set_state(pv->port, pv, BR_STATE_DISABLED); +} + +int br_mst_vlan_set_msti(struct net_bridge_vlan *mv, u16 msti) +{ + struct net_bridge_vlan_group *vg; + struct net_bridge_vlan *pv; + struct net_bridge_port *p; + + if (mv->msti == msti) + return 0; + + mv->msti = msti; + + list_for_each_entry(p, &mv->br->port_list, list) { + vg = nbp_vlan_group(p); + + pv = br_vlan_find(vg, mv->vid); + if (pv) + br_mst_vlan_sync_state(pv, msti); + } + + return 0; +} + void br_mst_vlan_init_state(struct net_bridge_vlan *v) { /* VLANs always start out in MSTI 0 (CST) */ diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index c2190c8841fb..3978e1d9ffb5 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -1780,6 +1780,7 @@ static inline bool br_mst_is_enabled(struct net_bridge *br) int br_mst_set_state(struct net_bridge_port *p, u16 msti, u8 state, struct netlink_ext_ack *extack); +int br_mst_vlan_set_msti(struct net_bridge_vlan *v, u16 msti); void br_mst_vlan_init_state(struct net_bridge_vlan *v); int br_mst_set_enabled(struct net_bridge *br, bool on, struct netlink_ext_ack *extack); diff --git a/net/bridge/br_vlan_options.c b/net/bridge/br_vlan_options.c index 09112b56e79c..a2724d03278c 100644 --- a/net/bridge/br_vlan_options.c +++ b/net/bridge/br_vlan_options.c @@ -296,6 +296,7 @@ bool br_vlan_global_opts_can_enter_range(const struct net_bridge_vlan *v_curr, const struct net_bridge_vlan *r_end) { return v_curr->vid - r_end->vid == 1 && + v_curr->msti == r_end->msti && ((v_curr->priv_flags ^ r_end->priv_flags) & BR_VLFLAG_GLOBAL_MCAST_ENABLED) == 0 && br_multicast_ctx_options_equal(&v_curr->br_mcast_ctx, @@ -384,6 +385,9 @@ bool br_vlan_global_opts_fill(struct sk_buff *skb, u16 vid, u16 vid_range, #endif #endif + if (nla_put_u16(skb, BRIDGE_VLANDB_GOPTS_MSTI, v_opts->msti)) + goto out_err; + nla_nest_end(skb, nest); return true; @@ -415,6 +419,7 @@ static size_t rtnl_vlan_global_opts_nlmsg_size(const struct net_bridge_vlan *v) + nla_total_size(0) /* BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS */ + br_rports_size(&v->br_mcast_ctx) /* BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS */ #endif + + nla_total_size(sizeof(u16)) /* BRIDGE_VLANDB_GOPTS_MSTI */ + nla_total_size(sizeof(u16)); /* BRIDGE_VLANDB_GOPTS_RANGE */ } @@ -564,6 +569,15 @@ static int br_vlan_process_global_one_opts(const struct net_bridge *br, } #endif #endif + if (tb[BRIDGE_VLANDB_GOPTS_MSTI]) { + u16 msti; + + msti = nla_get_u16(tb[BRIDGE_VLANDB_GOPTS_MSTI]); + err = br_mst_vlan_set_msti(v, msti); + if (err) + return err; + *changed = true; + } return 0; } @@ -583,6 +597,7 @@ static const struct nla_policy br_vlan_db_gpol[BRIDGE_VLANDB_GOPTS_MAX + 1] = { [BRIDGE_VLANDB_GOPTS_MCAST_QUERIER_INTVL] = { .type = NLA_U64 }, [BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_INTVL] = { .type = NLA_U64 }, [BRIDGE_VLANDB_GOPTS_MCAST_QUERY_RESPONSE_INTVL] = { .type = NLA_U64 }, + [BRIDGE_VLANDB_GOPTS_MSTI] = NLA_POLICY_MAX(NLA_U16, VLAN_N_VID - 1), }; int br_vlan_rtm_process_global_options(struct net_device *dev, -- 2.25.1