From patchwork Mon Jun 24 13:00:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13709445 X-Patchwork-Delegate: stephen@networkplumber.org Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1883B135414 for ; Mon, 24 Jun 2024 13:00:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234062; cv=none; b=dTy8Y+1dIwq4VnsyV98vjL3VUw8bJ8xNKwKdAMlJAqzsKLfeZpuURATyXvJhcJYlMrMIGt6nB0bkYPZRmLulEPNOfQcfLeDG8KUafAwfKfAwZTHcuFJNYrRjOwCYn/LZLVubjMBdulSMSv+MhYZ+F3QNrENP0CH4bggYHE7uW14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234062; c=relaxed/simple; bh=RyokshU+WclVGMh//XugxXFLsaY29TtbRP0vMmVrUK8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ToNJ/r/cDixqLc8HxLZJ7zup2wJmINCpqG7LUgQz+hyMU9eelSSZFJrzi/xlo5MFy0y0WCHxMaEtAgAWVb9mpWL3q1j5vyqVIcxUl8mzrcD+laMvQg7RY6zs9UB9E1PULb2a9kmiKO3AiSaadQYOuBnEbFHmBG24usMxXTO0jwA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com; spf=pass smtp.mailfrom=waldekranz.com; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b=X2OJq00z; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="X2OJq00z" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-52ce674da85so986732e87.2 for ; Mon, 24 Jun 2024 06:00:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1719234058; x=1719838858; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=ooLfCMYPlwAcfVO+ZEfEnAjNUYPYAXAlFcQUJX0gVv0=; b=X2OJq00zPYsgKa8OrfmC3deid4SBWuLQ0cZ9DBDaGEosZUCrSEhEwE+OYxvVYJGua9 n5f5OGOI3Hji8S7W7m8WjDKBXmQVRgrTbyVn3DcnVEEqUV0aoQO3Dizzsh50jKPZNaFn 2BS+kt+ogISvpKwa1FRWNjOwn9GsI9gZbublysilfs706UzGi+lTGPyqhWxYkP66xuBW Shk4tEnnEn6L9D8khuyjLd0S9a1BAsB4tCkb/Uv+LgqIpwhi4Oi/o8CEjQYEtn9eycpj wHDmNajImNa+Z8+NdgR1lIDb7iHkyLJ9kToGqgRv2127o8IQpbtdNyUfWNFdhVwFhg7H R64A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234058; x=1719838858; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ooLfCMYPlwAcfVO+ZEfEnAjNUYPYAXAlFcQUJX0gVv0=; b=b20gRiV8HUyqdLuPkCIfaXUkElBidQSpTi0tviT//6vUFfQkBG7bJWE17Tp+RkCRaO 0W6SliC1wQ9BdX1DowjfTOd3Rly+s9fRty511ru61ZSZYjpEa3IkXPvyaK063LNW4Hza 9jY01kLtxDebILIBL+FE8hUCiqnnGweFevGqnjkFegQF23xFNXAwbmQ0lZ3jzlzswo/i 0zYieQOepomSZiHAi9PksaFQg9MnAbRCR0wIngt9m44hw0vNVLU2aA+KbJmcLv63ZqJu bHfBoIQV6RQOe5FYu9YES7adlQf4ubcZ9qXnW46xVZhcogpgE64+Gl1GnjwzaSSg73af 8dcg== X-Forwarded-Encrypted: i=1; AJvYcCUlJu9Qy+LtgAcndneCFO9KAe7ntaG9BkoFH/QYJQeUwtJtHzutKMj/9tbQeVHgZIHQ4O5YZSgs6DFScFYjFAAP0YamRp0P X-Gm-Message-State: AOJu0YxQ03pjXhvz9kJuFCm0+MphMDsMmluyOnLUtWKVG/fAdNideuWm 4Ea3pVuTcOxRCXqRWGJ6aqGDpx5UeRzTpe8e3qmW460s5U3qYG5Gwiff/m6st7s= X-Google-Smtp-Source: AGHT+IEdtfYDa2BYtDClsU1EEcYZf0TgT2roI37WmsTsZB4ACxffu6xs6RVbl6YANlEC5AqXIbEHyw== X-Received: by 2002:a05:6512:3090:b0:52b:bd50:baed with SMTP id 2adb3069b0e04-52ce1861711mr4448941e87.61.1719234058161; Mon, 24 Jun 2024 06:00:58 -0700 (PDT) Received: from wkz-x13.addiva.ad (h-176-10-146-181.NA.cust.bahnhof.se. [176.10.146.181]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cd6432bd9sm981827e87.227.2024.06.24.06.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 06:00:57 -0700 (PDT) From: Tobias Waldekranz To: stephen@networkplumber.org, dsahern@kernel.org Cc: liuhangbin@gmail.com, netdev@vger.kernel.org Subject: [PATCH v2 iproute2 1/3] ip: bridge: add support for mst_enabled Date: Mon, 24 Jun 2024 15:00:33 +0200 Message-Id: <20240624130035.3689606-2-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240624130035.3689606-1-tobias@waldekranz.com> References: <20240624130035.3689606-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: dsahern@gmail.com When enabled, the bridge's legacy per-VLAN STP facility is replaced with the Multiple Spanning Tree Protocol (MSTP) compatible version. Signed-off-by: Tobias Waldekranz Reviewed-by: Hangbin Liu Acked-by: Nikolay Aleksandrov --- ip/iplink_bridge.c | 19 +++++++++++++++++++ man/man8/ip-link.8.in | 14 ++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c index 6b70ffbb..f01ffe15 100644 --- a/ip/iplink_bridge.c +++ b/ip/iplink_bridge.c @@ -30,6 +30,7 @@ static void print_explain(FILE *f) " [ max_age MAX_AGE ]\n" " [ ageing_time AGEING_TIME ]\n" " [ stp_state STP_STATE ]\n" + " [ mst_enabled MST_ENABLED ]\n" " [ priority PRIORITY ]\n" " [ group_fwd_mask MASK ]\n" " [ group_address ADDRESS ]\n" @@ -169,6 +170,18 @@ static int bridge_parse_opt(struct link_util *lu, int argc, char **argv, bm.optval |= no_ll_learn_bit; else bm.optval &= ~no_ll_learn_bit; + } else if (strcmp(*argv, "mst_enabled") == 0) { + __u32 mst_bit = 1 << BR_BOOLOPT_MST_ENABLE; + __u8 mst_enabled; + + NEXT_ARG(); + if (get_u8(&mst_enabled, *argv, 0)) + invarg("invalid mst_enabled", *argv); + bm.optmask |= mst_bit; + if (mst_enabled) + bm.optval |= mst_bit; + else + bm.optval &= ~mst_bit; } else if (strcmp(*argv, "fdb_max_learned") == 0) { __u32 fdb_max_learned; @@ -609,6 +622,7 @@ static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) if (tb[IFLA_BR_MULTI_BOOLOPT]) { __u32 mcvl_bit = 1 << BR_BOOLOPT_MCAST_VLAN_SNOOPING; __u32 no_ll_learn_bit = 1 << BR_BOOLOPT_NO_LL_LEARN; + __u32 mst_bit = 1 << BR_BOOLOPT_MST_ENABLE; struct br_boolopt_multi *bm; bm = RTA_DATA(tb[IFLA_BR_MULTI_BOOLOPT]); @@ -622,6 +636,11 @@ static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) "mcast_vlan_snooping", "mcast_vlan_snooping %u ", !!(bm->optval & mcvl_bit)); + if (bm->optmask & mst_bit) + print_uint(PRINT_ANY, + "mst_enabled", + "mst_enabled %u ", + !!(bm->optval & mst_bit)); } if (tb[IFLA_BR_MCAST_ROUTER]) diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in index c1984158..eabca490 100644 --- a/man/man8/ip-link.8.in +++ b/man/man8/ip-link.8.in @@ -1685,6 +1685,8 @@ the following additional arguments are supported: ] [ .BI stp_state " STP_STATE " ] [ +.BI mst_enabled " MST_ENABLED " +] [ .BI priority " PRIORITY " ] [ .BI no_linklocal_learn " NO_LINKLOCAL_LEARN " @@ -1788,6 +1790,18 @@ or off .RI ( STP_STATE " == 0). " for this bridge. +.BI mst_enabled " MST_ENABLED " +- turn multiple spanning tree (MST) support on +.RI ( MST_ENABLED " > 0) " +or off +.RI ( MST_ENABLED " == 0). " +When enabled, sets of VLANs can be associated with multiple spanning +tree instances (MSTIs), and STP states for each port can be controlled +on a per-MSTI basis. Note: no implementation of the MSTP protocol is +provided, only the primitives needed to implement it. To avoid +interfering with the legacy per-VLAN STP states, this setting can only +be changed when no bridge VLANs are configured. + .BI priority " PRIORITY " - set this bridge's spanning tree priority, used during STP root bridge election. From patchwork Mon Jun 24 13:00:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13709446 X-Patchwork-Delegate: stephen@networkplumber.org Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E913A13699A for ; Mon, 24 Jun 2024 13:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234062; cv=none; b=ua4AX2ErcyKUVbcsU6iL7hhCYgDzxd6AeX+ZulHKNDw4n76IYsAFUGMl9isWJSi2LVClmhbes7upcD609x2aFHYYmni/JzYItqL3IeX69HKF06P/Z38D44paSR/Ik+K19u9GmuvvHrDd178/DUKl5mwj3WTgDIZLi8T03aHTWZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234062; c=relaxed/simple; bh=xnE3v2fU7NxIpzyZJ2ceEC+dccvprNag/D4piqTJLCQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lkV7AW5wiHv73yRIGL4Fno0vAXnJsdu4v6bcg6jVoof5tvHz78/e5weA1+3E1DTLn6atxy1aZ7+18FvMgo93cIY07uveCe/kzLoUy3jLksdUCsWfkLCasPZAkI+UAmQVVcsy3QcGqx/pPpqzYUVjc+2qzTLhU2VX3UDwwkWhdRk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com; spf=pass smtp.mailfrom=waldekranz.com; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b=xaJOzwfL; arc=none smtp.client-ip=209.85.167.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="xaJOzwfL" Received: by mail-lf1-f41.google.com with SMTP id 2adb3069b0e04-52cdea1387eso1995044e87.0 for ; Mon, 24 Jun 2024 06:01:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1719234059; x=1719838859; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=u0S+LRarOvOVQhRVeLVj58mXdHnF8qmLz8b6eobZUBs=; b=xaJOzwfLnQRfC20j+USWNgWOqotJV0Yw6M+FK7g3Oc4roQA4va2X43F6Dx48ra+Pn+ tbnKN8DEW5B51tRxoU8FbuSHun21uMNq6HIx+LSuQFXkEwrVDAkM3fpQYipgtskLUvUa 0574fynYXxOK9Crn0su5uWJSC1vbeMfcWc5K7OCVoRvBOPb9NAvxPSCFvT0u74l0kWDq VJsuFLOcwfJRlNFQIxrJHAXDcBJQ0aWKm48YAzFwkfh2PPHLph3oCyWoxmb4afLsyb8P LakhFlXWmv9x5MrE0DlXO53h05Z7SYaw+uyqx+5agrx9/mecLfofmsMSSfFRrIvTHuTq OBcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234059; x=1719838859; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=u0S+LRarOvOVQhRVeLVj58mXdHnF8qmLz8b6eobZUBs=; b=jF/Ns+s7KWz4h0V0UqDwoRf1poNE29nZhfO/iG6YX2SSOin2HpPivsftmKzHMrD9q8 5e3F0f4Gk6N5A1Q1esxIwvXGgVG+7OCoxeYX2R3fmelRldYr/VZyGTNI/6HqKWU+NkIB PA2UfPToNO/2GwjW3JfOLcUMBIc6SqGjJgIuhLLakJaRttvo+O6YJnmSYMOevSGlo5XH vX9p3piFiCfzjZJKpEuROOjTIqA/DhXvEMHIKPBpJzpySkU44GkvK7CY37Kz9hrgRb3/ uSVxK2QaD6y+a/sqWFg24G2G+ufVNoF9ua811qyQSWvp4TKZB2afqUBwQue+Pw9Hm2TZ sSeg== X-Forwarded-Encrypted: i=1; AJvYcCXVruwTbJelh822A6kIvgglDcwxYyKLPTnnyXXjzhJPWVt0GcDSub19N9n4gP1EHW3s5mUlC1EXAGMxe5RQ2Rsnjozg/Kdx X-Gm-Message-State: AOJu0YzPvCEWnNNvvYIJQ2qkOvUfs+dwY6WUW3CFxIkQm6ikDxLGSBPM KMp2Y9LBlEQKbsNMz/VCKHB24ebKeHPqbSivnC+LofdbS6Z7fve0Ne0QGW4EMeg= X-Google-Smtp-Source: AGHT+IGyvI4gZnxJKRtt5b+1pabodPynS1nmb/JHqR1uMChQmrVzErXxCsV5ayfG2l8wX3sJ3F89lA== X-Received: by 2002:a19:7407:0:b0:52c:cca8:db45 with SMTP id 2adb3069b0e04-52ce185fa61mr2464084e87.46.1719234059291; Mon, 24 Jun 2024 06:00:59 -0700 (PDT) Received: from wkz-x13.addiva.ad (h-176-10-146-181.NA.cust.bahnhof.se. [176.10.146.181]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cd6432bd9sm981827e87.227.2024.06.24.06.00.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 06:00:58 -0700 (PDT) From: Tobias Waldekranz To: stephen@networkplumber.org, dsahern@kernel.org Cc: liuhangbin@gmail.com, netdev@vger.kernel.org Subject: [PATCH v2 iproute2 2/3] bridge: vlan: Add support for setting a VLANs MSTI Date: Mon, 24 Jun 2024 15:00:34 +0200 Message-Id: <20240624130035.3689606-3-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240624130035.3689606-1-tobias@waldekranz.com> References: <20240624130035.3689606-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: dsahern@gmail.com Allow the user to associate one or more VLANs with a multiple spanning tree instance (MSTI), when MST is enabled on the bridge. Signed-off-by: Tobias Waldekranz Reviewed-by: Hangbin Liu Acked-by: Nikolay Aleksandrov --- bridge/vlan.c | 13 +++++++++++++ man/man8/bridge.8 | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 0a7e6c45..34d7f767 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -56,6 +56,7 @@ static void usage(void) " [ mcast_querier_interval QUERIER_INTERVAL ]\n" " [ mcast_query_interval QUERY_INTERVAL ]\n" " [ mcast_query_response_interval QUERY_RESPONSE_INTERVAL ]\n" + " [ msti MSTI ]\n" " bridge vlan global { show } [ dev DEV ] [ vid VLAN_ID ]\n"); exit(-1); } @@ -406,6 +407,7 @@ static int vlan_global_option_set(int argc, char **argv) short vid = -1; __u64 val64; __u32 val32; + __u16 val16; __u8 val8; afspec = addattr_nest(&req.n, sizeof(req), @@ -536,6 +538,12 @@ static int vlan_global_option_set(int argc, char **argv) addattr64(&req.n, 1024, BRIDGE_VLANDB_GOPTS_MCAST_STARTUP_QUERY_INTVL, val64); + } else if (strcmp(*argv, "msti") == 0) { + NEXT_ARG(); + if (get_u16(&val16, *argv, 0)) + invarg("invalid msti", *argv); + addattr16(&req.n, 1024, + BRIDGE_VLANDB_GOPTS_MSTI, val16); } else { if (strcmp(*argv, "help") == 0) NEXT_ARG(); @@ -945,6 +953,11 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) "mcast_query_response_interval %llu ", rta_getattr_u64(vattr)); } + if (vtb[BRIDGE_VLANDB_GOPTS_MSTI]) { + vattr = vtb[BRIDGE_VLANDB_GOPTS_MSTI]; + print_uint(PRINT_ANY, "msti", "msti %u ", + rta_getattr_u16(vattr)); + } print_nl(); if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS]) { vattr = RTA_DATA(vtb[BRIDGE_VLANDB_GOPTS_MCAST_ROUTER_PORTS]); diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index bb02bd27..b4699801 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -266,7 +266,9 @@ bridge \- show / manipulate bridge addresses and devices .B mcast_query_interval .IR QUERY_INTERVAL " ] [ " .B mcast_query_response_interval -.IR QUERY_RESPONSE_INTERVAL " ]" +.IR QUERY_RESPONSE_INTERVAL " ] [ " +.B msti +.IR MSTI " ]" .ti -8 .BR "bridge vlan global" " [ " show " ] [ " @@ -1493,6 +1495,11 @@ startup phase. set the Max Response Time/Maximum Response Delay for IGMP/MLD queries sent by the bridge. +.TP +.BI msti " MSTI " +associate the VLAN with the specified multiple spanning tree instance +(MSTI). + .SS bridge vlan global show - list global vlan options. This command displays the global VLAN options for each VLAN entry. From patchwork Mon Jun 24 13:00:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13709447 X-Patchwork-Delegate: stephen@networkplumber.org Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E17E13D53E for ; Mon, 24 Jun 2024 13:01:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234064; cv=none; b=GtxBKwdKnkSm8fgqKiwxgQjM5/rZNulBtu61YWAsaSfzDJ+sTYcGkV7SlWxkMaAWA+QNQrUOj2rAM7UsulYdt5dEj7ftEric6I9M9IBbKnckOaQdh2pd3x2GegvjFu2rh4bpC5UK8SS+iBKbDH3EcDFpDuxJwdA5A+w65EAmuXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234064; c=relaxed/simple; bh=NfOvLuh5WOf8Hdo6LN2wpjDQm8QakCsGfnpHQRRdAt8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S4GH1+2gG/zxIEIGBX1jQsI1RJs4mEI4/2KJp26Ssx5MjPYo+emo8SJVJRHGOc+kpWeoBIYomHRTLdTVX/MLFTP5TOgXUi6HcfrN5S8WtQ1+YrccLm8Qcl1q9n81vYeNgXhRqW4gfWqS+rVG8Zp1A+Dj6RWg6J43UZeYFS7gehM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com; spf=pass smtp.mailfrom=waldekranz.com; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b=qA/NU6wk; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=waldekranz.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=waldekranz-com.20230601.gappssmtp.com header.i=@waldekranz-com.20230601.gappssmtp.com header.b="qA/NU6wk" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-52ce6c8db7bso1127434e87.1 for ; Mon, 24 Jun 2024 06:01:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1719234061; x=1719838861; darn=vger.kernel.org; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=oMzaptHEUYgcsJloL3vT7lSkVXfNwAQtqAjb6Kh7Tk4=; b=qA/NU6wkJHZKN0EywSO7tbqRkJVt+VU0bxedNFie30jpb8ARhW8DXzNFUqAwUrhd8A Dm+tMS1L0ku73b4WnB0hQne2oh9jwSYp1EBr+8BKY5pHJ+QB17BepxkdhaaMjZ2oVuFb O5hsA7cB5pDo/z4dsnMahXcYPII3hUNKjEzlxqOPlh1R6hL7kQIdgEaE/rmzxrHyQTI8 76Nq3lRiMw++ZKyWBc86uf0nKuQ1cDjvTtRRy8vLicGYCKY9OhBHHW6oO0ryT9xNlKaY p9IfbXTgkGq1hl/SCuHnisScvAeSE/guwJzDeL6TKMt5PJcCCsM0sPVOFzz7qTdYQlTR eumQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234061; x=1719838861; h=content-transfer-encoding:organization:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=oMzaptHEUYgcsJloL3vT7lSkVXfNwAQtqAjb6Kh7Tk4=; b=bIdBzTLlehE6JSNtcgkk+fIsRVzjmA73oVcU/gYHQCahLd386v1hbRXQiTpk2ez1o3 Dx2d/wRmBb188OwyN8d5wg80fuMOgtbglxuZmMzNTzldeaQ6FLrydJzIXQNBZyOtBqu1 xk//XqHQeVvPMCtLLcgsHKdX8bw8vU7MkLH1BWXeSX9hynHBASJuw+Du5f2d1JlbR4Ox Q/5wC+/3dK1mH0IxUmHOxCrxDW+dVQbuBGY16h9EBQEmqdzeQT0eVfx/VyRGXWUaeLsK qbzE6UcxsjJsqUdmeZjwqzAmRIOaVCmFbx/sCykpGO+PjwPKZTltWf8yIgeQFQ3M3gaO yDaQ== X-Forwarded-Encrypted: i=1; AJvYcCXLE86BJCepKnSYKs29HT0RK5WAcaE4kKL1550aOof3+0o4RisW+iZKQOiS/r7cDIddAnDe/sLslFBOJU3Wpq4zvlWH76J6 X-Gm-Message-State: AOJu0Yy2aG+mCR1RCIlZzO+9Ap22P1ZGEAVjMD5W+4V5XE5g2TdCt2+S 2UzpRoxAkU2AXhbTN4+jAshdkie1TAwWZl+OtD+n/C2bJVEYzmtZW297QMuEvFo= X-Google-Smtp-Source: AGHT+IEw89UxfDB3laGOJJT6WdJ8uTvlReMnoRL8VJEn4QNJeyvqesdBSYemT58LN+tqU1F79BSqXw== X-Received: by 2002:a05:6512:247:b0:52c:d84b:eee6 with SMTP id 2adb3069b0e04-52ce183b2b3mr2354812e87.38.1719234060654; Mon, 24 Jun 2024 06:01:00 -0700 (PDT) Received: from wkz-x13.addiva.ad (h-176-10-146-181.NA.cust.bahnhof.se. [176.10.146.181]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-52cd6432bd9sm981827e87.227.2024.06.24.06.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jun 2024 06:00:59 -0700 (PDT) From: Tobias Waldekranz To: stephen@networkplumber.org, dsahern@kernel.org Cc: liuhangbin@gmail.com, netdev@vger.kernel.org Subject: [PATCH v2 iproute2 3/3] bridge: mst: Add get/set support for MST states Date: Mon, 24 Jun 2024 15:00:35 +0200 Message-Id: <20240624130035.3689606-4-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240624130035.3689606-1-tobias@waldekranz.com> References: <20240624130035.3689606-1-tobias@waldekranz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Addiva Elektronik X-Patchwork-Delegate: dsahern@gmail.com Allow a port's spanning tree state to be modified on a per-MSTI basis, and support dumping the current MST states for every port and MSTI. Signed-off-by: Tobias Waldekranz --- bridge/Makefile | 2 +- bridge/br_common.h | 1 + bridge/bridge.c | 3 +- bridge/mst.c | 262 +++++++++++++++++++++++++++++++++++++++++++++ man/man8/bridge.8 | 57 ++++++++++ 5 files changed, 323 insertions(+), 2 deletions(-) create mode 100644 bridge/mst.c diff --git a/bridge/Makefile b/bridge/Makefile index 01f8a455..4c57df43 100644 --- a/bridge/Makefile +++ b/bridge/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -BROBJ = bridge.o fdb.o monitor.o link.o mdb.o vlan.o vni.o +BROBJ = bridge.o fdb.o monitor.o link.o mdb.o mst.o vlan.o vni.o include ../config.mk diff --git a/bridge/br_common.h b/bridge/br_common.h index 704e76b0..3a0cf882 100644 --- a/bridge/br_common.h +++ b/bridge/br_common.h @@ -20,6 +20,7 @@ void print_headers(FILE *fp, const char *label); int do_fdb(int argc, char **argv); int do_mdb(int argc, char **argv); int do_monitor(int argc, char **argv); +int do_mst(int argc, char **argv); int do_vlan(int argc, char **argv); int do_link(int argc, char **argv); int do_vni(int argc, char **argv); diff --git a/bridge/bridge.c b/bridge/bridge.c index ef592815..f8b5646a 100644 --- a/bridge/bridge.c +++ b/bridge/bridge.c @@ -36,7 +36,7 @@ static void usage(void) fprintf(stderr, "Usage: bridge [ OPTIONS ] OBJECT { COMMAND | help }\n" " bridge [ -force ] -batch filename\n" -"where OBJECT := { link | fdb | mdb | vlan | vni | monitor }\n" +"where OBJECT := { link | fdb | mdb | mst | vlan | vni | monitor }\n" " OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] |\n" " -o[neline] | -t[imestamp] | -n[etns] name |\n" " -com[pressvlans] -c[olor] -p[retty] -j[son] }\n"); @@ -56,6 +56,7 @@ static const struct cmd { { "link", do_link }, { "fdb", do_fdb }, { "mdb", do_mdb }, + { "mst", do_mst }, { "vlan", do_vlan }, { "vni", do_vni }, { "monitor", do_monitor }, diff --git a/bridge/mst.c b/bridge/mst.c new file mode 100644 index 00000000..873ca536 --- /dev/null +++ b/bridge/mst.c @@ -0,0 +1,262 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Get/set Multiple Spanning Tree (MST) states + */ + +#include +#include +#include + +#include "libnetlink.h" +#include "json_print.h" +#include "utils.h" + +#include "br_common.h" + +#define MST_ID_LEN 9 + +#define __stringify_1(x...) #x +#define __stringify(x...) __stringify_1(x) + +static unsigned int filter_index; + +static void usage(void) +{ + fprintf(stderr, + "Usage: bridge mst set dev DEV msti MSTI state STATE\n" + " bridge mst {show} [ dev DEV ]\n"); + exit(-1); +} + +static void print_mst_entry(struct rtattr *a, FILE *fp) +{ + struct rtattr *tb[IFLA_BRIDGE_MST_ENTRY_MAX + 1]; + __u16 msti = 0; + __u8 state = 0; + + parse_rtattr_flags(tb, IFLA_BRIDGE_MST_ENTRY_MAX, RTA_DATA(a), + RTA_PAYLOAD(a), NLA_F_NESTED); + + + if (!(tb[IFLA_BRIDGE_MST_ENTRY_MSTI] && + tb[IFLA_BRIDGE_MST_ENTRY_STATE])) { + fprintf(stderr, "BUG: broken MST entry"); + return; + } + + msti = rta_getattr_u16(tb[IFLA_BRIDGE_MST_ENTRY_MSTI]); + state = rta_getattr_u8(tb[IFLA_BRIDGE_MST_ENTRY_STATE]); + + open_json_object(NULL); + print_uint(PRINT_ANY, "msti", "%u", msti); + print_nl(); + print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + print_stp_state(state); + print_nl(); + close_json_object(); +} + +static int print_msts(struct nlmsghdr *n, void *arg) +{ + struct ifinfomsg *ifi = NLMSG_DATA(n); + struct rtattr *af_spec, *mst, *a; + int rem = n->nlmsg_len; + bool opened = false; + + rem -= NLMSG_LENGTH(sizeof(*ifi)); + if (rem < 0) { + fprintf(stderr, "BUG: wrong nlmsg len %d\n", rem); + return -1; + } + + af_spec = parse_rtattr_one(IFLA_AF_SPEC, IFLA_RTA(ifi), rem); + if (!af_spec) + return -1; + + if (filter_index && filter_index != ifi->ifi_index) + return 0; + + mst = parse_rtattr_one_nested(NLA_F_NESTED | IFLA_BRIDGE_MST, af_spec); + if (!mst) + return 0; + + rem = RTA_PAYLOAD(mst); + for (a = RTA_DATA(mst); RTA_OK(a, rem); a = RTA_NEXT(a, rem)) { + unsigned short rta_type = a->rta_type & NLA_TYPE_MASK; + + if (rta_type > IFLA_BRIDGE_MST_MAX) + continue; + + switch (rta_type) { + case IFLA_BRIDGE_MST_ENTRY: + if (!opened) { + open_json_object(NULL); + print_color_string(PRINT_ANY, COLOR_IFNAME, + "ifname", + "%-" __stringify(IFNAMSIZ) "s ", + ll_index_to_name(ifi->ifi_index)); + open_json_array(PRINT_JSON, "mst"); + opened = true; + } else { + print_string(PRINT_FP, NULL, "%-" + __stringify(IFNAMSIZ) "s ", ""); + } + + print_mst_entry(a, arg); + break; + } + } + + if (opened) { + close_json_array(PRINT_JSON, NULL); + close_json_object(); + } + + return 0; +} + +static int mst_show(int argc, char **argv) +{ + char *filter_dev = NULL; + + while (argc > 0) { + if (strcmp(*argv, "dev") == 0) { + NEXT_ARG(); + if (filter_dev) + duparg("dev", *argv); + filter_dev = *argv; + } + argc--; argv++; + } + + if (filter_dev) { + filter_index = ll_name_to_index(filter_dev); + if (!filter_index) + return nodev(filter_dev); + } + + if (rtnl_linkdump_req_filter(&rth, PF_BRIDGE, RTEXT_FILTER_MST) < 0) { + perror("Cannon send dump request"); + exit(1); + } + + new_json_obj(json); + + if (!is_json_context()) { + printf("%-" __stringify(IFNAMSIZ) "s " + "%-" __stringify(MST_ID_LEN) "s", + "port", "msti"); + printf("\n"); + } + + if (rtnl_dump_filter(&rth, print_msts, stdout) < 0) { + fprintf(stderr, "Dump terminated\n"); + return -1; + } + + delete_json_obj(); + fflush(stdout); + return 0; +} + +static int mst_set(int argc, char **argv) +{ + struct { + struct nlmsghdr n; + struct ifinfomsg ifi; + char buf[512]; + } req = { + .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)), + .n.nlmsg_flags = NLM_F_REQUEST, + .n.nlmsg_type = RTM_SETLINK, + .ifi.ifi_family = PF_BRIDGE, + }; + char *d = NULL, *m = NULL, *s = NULL, *endptr; + struct rtattr *af_spec, *mst, *entry; + __u16 msti; + __u8 state; + + while (argc > 0) { + if (strcmp(*argv, "dev") == 0) { + NEXT_ARG(); + d = *argv; + } else if (strcmp(*argv, "msti") == 0) { + NEXT_ARG(); + m = *argv; + } else if (strcmp(*argv, "state") == 0) { + NEXT_ARG(); + s = *argv; + } else { + if (matches(*argv, "help") == 0) + usage(); + } + argc--; argv++; + } + + if (d == NULL || m == NULL || s == NULL) { + fprintf(stderr, "Device, MSTI and state are required arguments.\n"); + return -1; + } + + req.ifi.ifi_index = ll_name_to_index(d); + if (!req.ifi.ifi_index) + return nodev(d); + + msti = strtol(m, &endptr, 10); + if (!(*s != '\0' && *endptr == '\0')) { + fprintf(stderr, + "Error: invalid MSTI\n"); + return -1; + } + + state = strtol(s, &endptr, 10); + if (!(*s != '\0' && *endptr == '\0')) { + state = parse_stp_state(s); + if (state == -1) { + fprintf(stderr, + "Error: invalid STP port state\n"); + return -1; + } + } + + af_spec = addattr_nest(&req.n, sizeof(req), IFLA_AF_SPEC); + mst = addattr_nest(&req.n, sizeof(req), IFLA_BRIDGE_MST); + + entry = addattr_nest(&req.n, sizeof(req), IFLA_BRIDGE_MST_ENTRY); + entry->rta_type |= NLA_F_NESTED; + + addattr16(&req.n, sizeof(req), IFLA_BRIDGE_MST_ENTRY_MSTI, msti); + addattr8(&req.n, sizeof(req), IFLA_BRIDGE_MST_ENTRY_STATE, state); + + addattr_nest_end(&req.n, entry); + + addattr_nest_end(&req.n, mst); + addattr_nest_end(&req.n, af_spec); + + + if (rtnl_talk(&rth, &req.n, NULL) < 0) + return -1; + + return 0; +} + +int do_mst(int argc, char **argv) +{ + ll_init_map(&rth); + + if (argc > 0) { + if (matches(*argv, "set") == 0) + return mst_set(argc-1, argv+1); + + if (matches(*argv, "show") == 0 || + matches(*argv, "lst") == 0 || + matches(*argv, "list") == 0) + return mst_show(argc-1, argv+1); + if (matches(*argv, "help") == 0) + usage(); + } else + return mst_show(0, NULL); + + fprintf(stderr, "Command \"%s\" is unknown, try \"bridge mst help\".\n", *argv); + exit(-1); +} diff --git a/man/man8/bridge.8 b/man/man8/bridge.8 index b4699801..08f329c6 100644 --- a/man/man8/bridge.8 +++ b/man/man8/bridge.8 @@ -207,6 +207,15 @@ bridge \- show / manipulate bridge addresses and devices .RB "[ " vni .IR VNI " ]" +.ti -8 +.B "bridge mst set" +.IR dev " DEV " msti " MSTI " state " STP_STATE " + +.ti -8 +.BR "bridge mst" " [ [ " show " ] [ " +.B dev +.IR DEV " ] ]" + .ti -8 .BR "bridge vlan" " { " add " | " del " } " .B dev @@ -1247,6 +1256,54 @@ endpoint. Match entries only with the specified destination port number. the VXLAN VNI Network Identifier to use to connect to the remote VXLAN tunnel endpoint. Match entries only with the specified destination VNI. +.SH bridge mst - multiple spanning tree port states + +In the multiple spanning tree (MST) model, the active paths through a +network can be different for different VLANs. In other words, a +bridge port can simultaneously forward one subset of VLANs, while +blocking another. + +Provided that the +.B mst_enable +bridge option is enabled, a group of VLANs can be forwarded along the +same spanning tree by associating them with the same instance (MSTI) +using +.BR "bridge vlan global set" . + +.SS bridge mst set - set multiple spanning tree state + +Set the spanning tree state for +.IR DEV , +in the multiple spanning tree instance +.IR MSTI , +to +.IR STP_STATE . + +.TP +.BI dev " DEV" +Interface name of the bridge port. + +.TP +.BI msti " MSTI" +The multiple spanning tree instance. + +.TP +.BI state " STP_STATE" +The spanning tree state, see the +.B state +option of +.B "bridge link set" +for supported states. + +.SS bridge mst show - list MST states + +List current MST port states in every MSTI. + +.TP +.BI dev " DEV" +If specified, only display states of the bridge port with this +interface name. + .SH bridge vlan - VLAN filter list .B vlan