From patchwork Tue Jul 2 12:08:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13719528 X-Patchwork-Delegate: dsahern@gmail.com Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 ED83615CD7C for ; Tue, 2 Jul 2024 12:08:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719922115; cv=none; b=sdDoo5oqYQQafQoUyANPz57WoZVKoJYFsPqmZZ/XsmDXFP3G//Ob7EWu4BWSqaqNJ7hyIlhK1FnqWRkIfVf1vJtOw4PZrSXuTzJJkJSF+iXbc3viy9uzz6S00Gxepi3OUY9NMPwNEH4EiFuFgzAKd1DO00xOlOMSUhrDHB4EUW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719922115; c=relaxed/simple; bh=9eIa7E2SX1m1tEX0xIgUzdbIr1Wl1VNa5TpYucuVwRc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VR67rADX54c9Hmsb9h4bwDT+tOSWyUdWNVR1ExUtIOpFrNa5giGI8LXz12IHTfZT9I1r01EfyIo11EFGsVyElcxv7xwEO7kvVn3pvpSYbn9KcwC56w0jOSQ6Iexdx/zvEU7N7RfUCUkpdAUUfAV4gdBSGeDFYVzTR/0VMHMM1hE= 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=s/gmOcGW; arc=none smtp.client-ip=209.85.167.47 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="s/gmOcGW" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-52caebc6137so3564986e87.0 for ; Tue, 02 Jul 2024 05:08:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1719922111; x=1720526911; 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=xgQdQMdjhR92R38qSZNVEOOBIPnKqiUX7hdimYEwX3o=; b=s/gmOcGWGsGYz+JfI0GdTJYhkjre0wIOxcLmBtPg7nsxDXRS15duinNypSjd0wyQQT yMzsW3Jh/gWsZwnnphQWQ7sjJRlKGfhgBWs/4dsOiAsJ2dTLRZXDQzggS9rirNUosyBp PYOwX+cKD9ctezT71WXAbddet8XNgBXEIIJLoMispIBQXo3NoqUO6D8+uOXHc/fnomgY efQ67q+/Id3rbQfLXn7VgLtCVjmDf5rmCEaP2d3W80yT+kQA/rA3eoDdo1ZqIDE2PPd9 eBda68NKmUUoPKvsJvrT1azakr3VflFpL7IaZ+tiduO7TiqTy2+UO8zZvjDI1KploJaa EQSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719922111; x=1720526911; 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=xgQdQMdjhR92R38qSZNVEOOBIPnKqiUX7hdimYEwX3o=; b=AQsG+9rPZtdPFy9tMdXyVxW/3ed6OFdRGdUZ4FzC97+NaJPE4jSm7RuJlV5t5Cthzi se38EuKj2fC7fhKJyMg6b0O/VwrRee6Ak7rrmAHXUWjTuItUcaUz9njJCuGFZQlQbhUJ wP+2T4tqwk9vLYxG9hddUp6rDsFX2njyJqSVtmNcV4DCWr4NBo7gH3KfjHIzu0v0zELI Gg/2DrdwvsFekYc6WuPs0dmQpJnOB1ShHWHbVrgCHOogDdQ2NwlcicSZZHYMSJYTYsZA aII7mZlBpX0cSbYv2R/VfMkDwrYT+lTQ7RqnFOZ9T5LffDouHtK1X7PlSqNqiUrXfOYX nqwQ== X-Forwarded-Encrypted: i=1; AJvYcCXOfQEJONNbujcBZFz2ksSi6R+5zpeEkYClOLiGv3mfKgnfNRINcF4nFsxelQATuWAbN78+xo65M2lwFv/uDVWHzBQdJ3JR X-Gm-Message-State: AOJu0YzcpdAZnteZiMBcxkLSQifDltCHy3GR3XleKxQMhbuMo5epJCkg sw0gSEprJzjfcRULGsFsvxOxu2L1mXD1EzBG5DLffqGWsnDDmV1WgEjlHOpBdIY= X-Google-Smtp-Source: AGHT+IF9a7ftKNDrAOgX8w4585WgK8NDzBb6lJXOWfgSlcymGaTYJe9zpCyUWmrbLNn+2S9C05uAVg== X-Received: by 2002:a05:6512:3e1c:b0:52c:dfa7:53a2 with SMTP id 2adb3069b0e04-52e826f7609mr5987406e87.50.1719922110452; Tue, 02 Jul 2024 05:08:30 -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-52e7ab1064asm1799414e87.103.2024.07.02.05.08.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 05:08:29 -0700 (PDT) From: Tobias Waldekranz To: stephen@networkplumber.org, dsahern@kernel.org, roopa@nvidia.com, razor@blackwall.org, bridge@lists.linux.dev, netdev@vger.kernel.org Cc: liuhangbin@gmail.com Subject: [PATCH v3 iproute2 1/4] ip: bridge: add support for mst_enabled Date: Tue, 2 Jul 2024 14:08:02 +0200 Message-Id: <20240702120805.2391594-2-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240702120805.2391594-1-tobias@waldekranz.com> References: <20240702120805.2391594-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. Reviewed-by: Hangbin Liu Acked-by: Nikolay Aleksandrov Signed-off-by: Tobias Waldekranz --- 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 Tue Jul 2 12:08:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13719529 X-Patchwork-Delegate: dsahern@gmail.com Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 4C66C15D5B3 for ; Tue, 2 Jul 2024 12:08:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719922116; cv=none; b=figIMdNiWyglc9lAj18Ie+yFjAxBTGZlgh7d64FZ+0KfzaB5Fqym3DPeSZZJOD+IAGEF6YeiKoETrJeTe55o/8Chtb6ta6Bgh5VInhhl52ekAr3VxfFffQb0DgGL/UxPtGdYqlaSvMohChvTgSirP9JfX+fwkinYyyk9qqv+w/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719922116; c=relaxed/simple; bh=hsftkSP2BDiz9TglzlG9ee1wDJWfkHJpC75tpg0xtkg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AOJIbBHl+FpmGB/ZYojtZKvTs3EiPugXxK1HqkXx0AoOm8DJm/hcgoEawRlHFQlkGeqLq47mO//4BF6JkM5YGkI5+4MF7mKleTlCT4+ZzT2VVMO8e11ZRucF8shb2yWxQ+Xw8d05jUhDjBoSfmdK52bgqi9C/2wb7hjrVAbz7Vk= 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=ykJKPOqu; arc=none smtp.client-ip=209.85.167.49 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="ykJKPOqu" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-52cdb0d816bso4050658e87.1 for ; Tue, 02 Jul 2024 05:08:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1719922112; x=1720526912; 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=8j4YJnckxoKym+ZcM9ZDthFzWyUhM2Uf5fbtBbrDdx4=; b=ykJKPOqu7DueqzQ2GrhFUbFJ+wGCpY9ihKUoGAOsenKmD8ZGEvFBmq9Jqo1LNqO0tj iIq/emaFr914xAr7OvllebgeiK45MZatc+7aaIs1c5TsjDchRm/61M93EhsXjJp+4jLV M3boSQWKHT8g45XTWbO3fAB1p9Y1wxcdtmS2OK2VnrLfHJc9fAUwumggQMr1lDJCesE1 rKq3Xr2Dq3gOCcSf71szUz3iGDzGsktRuxXBqkIw7A0erW7tTT5x55Q5KgYe7xY5o8la F1EigN0MQsgTqnUjQEK4mlKD9TFqBhaQ35u2Uasrvs0/uYDaTQF92ZXwPYBC6Y7qXuip gy6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719922112; x=1720526912; 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=8j4YJnckxoKym+ZcM9ZDthFzWyUhM2Uf5fbtBbrDdx4=; b=fwOD1D6azn1/7QMFde17iOZ4RYD/cqfUwfBYXZCQrHB+77KUs1bcxZDLj27IQCOzve OJ2wjxd7cJ/NanpaWcL2Bs9JE2rWlf5njc5KPGjjCxg8wwtv3BEfYesye2Bfndx+eNq0 gr7tLdx6JIT0owYyK7eYjQUcJ7wnZsfmYsHRei3lFwrbiatlEyaE3m86jt13CB9bDyjy t3xYwG9dIlJNjrNz21RknJu3hIDj3DVHFRghjrRc+FeJeOklU7M/C1lZpXE8DwWDJCtQ 4hEBSaA/bLvxpV3UdDpLmuMd6fFu8CGOvlJO63c8ej1xXGGM+1iLoJBCYzzoWiupm9Z0 LSSA== X-Forwarded-Encrypted: i=1; AJvYcCXfFg9AF2jkrEjNEdlw+jQW3dpU0aMQruHbIwAwEaOQ1SD4f1knvSH1hTlhXiOOqDuOOeEc7yXfRxisRTV2xRTQReOo0lTY X-Gm-Message-State: AOJu0Yz8asPDNwtx9pgpOiAmetqTHjym89Db2bXHiPyZ8mTClL56+ex/ 5ySm3ELPlsiDIqLm9BwHjs0G8eedMgiVK7kS9OnrcLV9QHXSL8Je0LJ7hyH1ktg= X-Google-Smtp-Source: AGHT+IGr4wQPv5afUFDcinzrJ0DCOrcAewoDqVAFuxi9J7/AILw78OE4VOEWMCvm39t77WUoK8ZTEA== X-Received: by 2002:a05:6512:3e0c:b0:52c:ca8d:d1c with SMTP id 2adb3069b0e04-52e825976ecmr2619228e87.2.1719922112246; Tue, 02 Jul 2024 05:08:32 -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-52e7ab1064asm1799414e87.103.2024.07.02.05.08.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 05:08:31 -0700 (PDT) From: Tobias Waldekranz To: stephen@networkplumber.org, dsahern@kernel.org, roopa@nvidia.com, razor@blackwall.org, bridge@lists.linux.dev, netdev@vger.kernel.org Cc: liuhangbin@gmail.com Subject: [PATCH v3 iproute2 2/4] bridge: Remove duplicated textification macros Date: Tue, 2 Jul 2024 14:08:03 +0200 Message-Id: <20240702120805.2391594-3-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240702120805.2391594-1-tobias@waldekranz.com> References: <20240702120805.2391594-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 include/utils.h already provides textify(), which is functionally equivalent to __stringify(). Signed-off-by: Tobias Waldekranz --- bridge/vlan.c | 41 +++++++++++++++++++---------------------- bridge/vni.c | 15 ++++++--------- 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 0a7e6c45..70f01aff 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -28,9 +28,6 @@ enum vlan_show_subject { #define VLAN_ID_LEN 9 -#define __stringify_1(x...) #x -#define __stringify(x...) __stringify_1(x) - static void usage(void) { fprintf(stderr, @@ -579,7 +576,7 @@ static void open_vlan_port(int ifi_index, enum vlan_show_subject subject) { open_json_object(NULL); print_color_string(PRINT_ANY, COLOR_IFNAME, "ifname", - "%-" __stringify(IFNAMSIZ) "s ", + "%-" textify(IFNAMSIZ) "s ", ll_index_to_name(ifi_index)); open_json_array(PRINT_JSON, subject == VLAN_SHOW_VLAN ? "vlans": "tunnels"); @@ -643,7 +640,7 @@ static void print_vlan_tunnel_info(struct rtattr *tb, int ifindex) opened = true; } else { print_string(PRINT_FP, NULL, - "%-" __stringify(IFNAMSIZ) "s ", ""); + "%-" textify(IFNAMSIZ) "s ", ""); } open_json_object(NULL); @@ -716,13 +713,13 @@ static void print_vlan_flags(__u16 flags) static void __print_one_vlan_stats(const struct bridge_vlan_xstats *vstats) { - print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + print_string(PRINT_FP, NULL, "%-" textify(IFNAMSIZ) "s ", ""); print_lluint(PRINT_ANY, "rx_bytes", "RX: %llu bytes", vstats->rx_bytes); print_lluint(PRINT_ANY, "rx_packets", " %llu packets\n", vstats->rx_packets); - print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + print_string(PRINT_FP, NULL, "%-" textify(IFNAMSIZ) "s ", ""); print_lluint(PRINT_ANY, "tx_bytes", "TX: %llu bytes", vstats->tx_bytes); print_lluint(PRINT_ANY, "tx_packets", " %llu packets\n", @@ -776,7 +773,7 @@ static void print_vlan_stats_attr(struct rtattr *attr, int ifindex) found_vlan = true; } else { print_string(PRINT_FP, NULL, - "%-" __stringify(IFNAMSIZ) "s ", ""); + "%-" textify(IFNAMSIZ) "s ", ""); } print_one_vlan_stats(vstats); } @@ -822,7 +819,7 @@ static void print_vlan_router_ports(struct rtattr *rattr) int rem = RTA_PAYLOAD(rattr); struct rtattr *i; - print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + print_string(PRINT_FP, NULL, "%-" textify(IFNAMSIZ) "s ", ""); open_json_array(PRINT_ANY, is_json_context() ? "router_ports" : "router ports: "); for (i = RTA_DATA(rattr); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { @@ -834,7 +831,7 @@ static void print_vlan_router_ports(struct rtattr *rattr) print_nl(); /* start: IFNAMSIZ + 4 + strlen("router ports: ") */ print_string(PRINT_FP, NULL, - "%-" __stringify(IFNAMSIZ) "s " + "%-" textify(IFNAMSIZ) "s " " ", ""); } @@ -872,11 +869,11 @@ static void print_vlan_global_opts(struct rtattr *a, int ifindex) vlan_rtm_cur_ifidx = ifindex; } else { open_json_object(NULL); - print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + print_string(PRINT_FP, NULL, "%-" textify(IFNAMSIZ) "s ", ""); } print_range("vlan", vid, vrange); print_nl(); - print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + print_string(PRINT_FP, NULL, "%-" textify(IFNAMSIZ) "s ", ""); if (vtb[BRIDGE_VLANDB_GOPTS_MCAST_SNOOPING]) { vattr = vtb[BRIDGE_VLANDB_GOPTS_MCAST_SNOOPING]; print_uint(PRINT_ANY, "mcast_snooping", "mcast_snooping %u ", @@ -1012,12 +1009,12 @@ static void print_vlan_opts(struct rtattr *a, int ifindex) vlan_rtm_cur_ifidx = ifindex; } else { open_json_object(NULL); - print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + print_string(PRINT_FP, NULL, "%-" textify(IFNAMSIZ) "s ", ""); } print_range("vlan", vinfo->vid, vrange); print_vlan_flags(vinfo->flags); print_nl(); - print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + print_string(PRINT_FP, NULL, "%-" textify(IFNAMSIZ) "s ", ""); print_stp_state(state); if (vtb[BRIDGE_VLANDB_ENTRY_MCAST_ROUTER]) { vattr = vtb[BRIDGE_VLANDB_ENTRY_MCAST_ROUTER]; @@ -1155,8 +1152,8 @@ static int vlan_show(int argc, char **argv, int subject) } if (!is_json_context()) { - printf("%-" __stringify(IFNAMSIZ) "s %-" - __stringify(VLAN_ID_LEN) "s", "port", + printf("%-" textify(IFNAMSIZ) "s %-" + textify(VLAN_ID_LEN) "s", "port", "vlan-id"); printf("\n"); } @@ -1183,8 +1180,8 @@ static int vlan_show(int argc, char **argv, int subject) } if (!is_json_context()) { - printf("%-" __stringify(IFNAMSIZ) "s %-" - __stringify(VLAN_ID_LEN) "s", "port", + printf("%-" textify(IFNAMSIZ) "s %-" + textify(VLAN_ID_LEN) "s", "port", "vlan-id"); if (subject == VLAN_SHOW_TUNNELINFO) printf(" tunnel-id"); @@ -1207,7 +1204,7 @@ static int vlan_show(int argc, char **argv, int subject) } if (!is_json_context()) - printf("%-" __stringify(IFNAMSIZ) "s vlan-id\n", + printf("%-" textify(IFNAMSIZ) "s vlan-id\n", "port"); if (rtnl_dump_filter(&rth, print_vlan_stats, stdout) < 0) { @@ -1269,8 +1266,8 @@ static int vlan_global_show(int argc, char **argv) } if (!is_json_context()) { - printf("%-" __stringify(IFNAMSIZ) "s %-" - __stringify(VLAN_ID_LEN) "s", "port", + printf("%-" textify(IFNAMSIZ) "s %-" + textify(VLAN_ID_LEN) "s", "port", "vlan-id"); printf("\n"); } @@ -1318,7 +1315,7 @@ static void print_vlan_info(struct rtattr *tb, int ifindex) opened = true; } else { print_string(PRINT_FP, NULL, "%-" - __stringify(IFNAMSIZ) "s ", ""); + textify(IFNAMSIZ) "s ", ""); } open_json_object(NULL); diff --git a/bridge/vni.c b/bridge/vni.c index e1f981fc..57b04c8c 100644 --- a/bridge/vni.c +++ b/bridge/vni.c @@ -27,9 +27,6 @@ static unsigned int filter_index; /* max len of "-" */ #define VXLAN_ID_LEN 17 -#define __stringify_1(x...) #x -#define __stringify(x...) __stringify_1(x) - static void usage(void) { fprintf(stderr, @@ -153,7 +150,7 @@ static void open_vni_port(int ifi_index) { open_json_object(NULL); print_color_string(PRINT_ANY, COLOR_IFNAME, "ifname", - "%-" __stringify(IFNAMSIZ) "s ", + "%-" textify(IFNAMSIZ) "s ", ll_index_to_name(ifi_index)); open_json_array(PRINT_JSON, "vnis"); } @@ -174,7 +171,7 @@ static void print_vnifilter_entry_stats(struct rtattr *stats_attr) RTA_PAYLOAD(stats_attr), NLA_F_NESTED); print_nl(); - print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s RX: ", + print_string(PRINT_FP, NULL, "%-" textify(IFNAMSIZ) "s RX: ", ""); if (stb[VNIFILTER_ENTRY_STATS_RX_BYTES]) { @@ -195,7 +192,7 @@ static void print_vnifilter_entry_stats(struct rtattr *stats_attr) } print_nl(); - print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s TX: ", + print_string(PRINT_FP, NULL, "%-" textify(IFNAMSIZ) "s TX: ", ""); if (stb[VNIFILTER_ENTRY_STATS_TX_BYTES]) { @@ -327,7 +324,7 @@ int print_vnifilter_rtm(struct nlmsghdr *n, void *arg) open_vni_port(tmsg->ifindex); opened = true; } else { - print_string(PRINT_FP, NULL, "%-" __stringify(IFNAMSIZ) "s ", ""); + print_string(PRINT_FP, NULL, "%-" textify(IFNAMSIZ) "s ", ""); } print_vni(t, tmsg->ifindex); @@ -373,8 +370,8 @@ static int vni_show(int argc, char **argv) } if (!is_json_context()) - printf("%-" __stringify(IFNAMSIZ) "s %-" - __stringify(VXLAN_ID_LEN) "s group/remote\n", "dev", + printf("%-" textify(IFNAMSIZ) "s %-" + textify(VXLAN_ID_LEN) "s group/remote\n", "dev", "vni"); ret = rtnl_dump_filter(&rth, print_vnifilter_rtm, NULL); From patchwork Tue Jul 2 12:08:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13719530 X-Patchwork-Delegate: dsahern@gmail.com Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 625D11662F4 for ; Tue, 2 Jul 2024 12:08:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719922117; cv=none; b=Kor0Les+KMQtbkKMHB3Czm6yC12Z3k43IMPl1tlBlFBfHSPVFbpw7tUtnsBUvYnEZUTi5wD2PEqJWavG1rPbmo//qflbJTCYLcXtxnPxZY5oZ4eQYDpghj2zk0UJo1Pb4yDj7TSJcyTaDSlFNo3vfmXZgV69Y4hKjhx533qAITw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719922117; c=relaxed/simple; bh=L4iknHWv24LRJnoIT3fvpcqfrurIP2YwW3xU1mKpwnA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S4Qa+KVpXITmcrv2w1WOeEp0v87zcnJDneRvruAAPoAejTFbyNCW4/kWEaxCFj6DyjYj4rB8hzUY+TGVLdL9MGGmWDL2vaUzmYiqTeTvpqQMakGJRDmvnxh0yKVFqMgsgYRceLNs6443uE/8ZeOaUknLRHm9CoxDmTkeMGeGMWI= 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=i+RnPTbq; arc=none smtp.client-ip=209.85.167.47 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="i+RnPTbq" Received: by mail-lf1-f47.google.com with SMTP id 2adb3069b0e04-5295eb47b48so4975328e87.1 for ; Tue, 02 Jul 2024 05:08:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1719922114; x=1720526914; 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=FCahmSEYU6tX9FqLb0Uk9Z14eoHvtjROOSdSw1YJQpE=; b=i+RnPTbqW9Wud0G6Bnk2/LZeFidNEwfAnlcDCj3sddtWNmo96DBcDwPN36CJ4gkWWZ T86aCNjs4le8Pw7Fsy5XHdjPlqTJwlErnc8KJS/PGaM85dFYnoDNA6umpaRnVNEY20CT ICloCOIb51nSxK46M4sZ3jnRsbrs83KXxKDyNQCrVBA3jM7wOt1Hwn2CtAZI4roSwC4F oskcNhyBZePZBlLAJ6516gSZm4l+MPUDlDCK0wWKw+7ZoEaz7GtnmzW5aiNKfHfZkohf AqL7LT4nERe5vtEK7+Achf0sHsb6J913C8RMQiSwytGCW4f6p58YWB3wWdvGL2lrbTnB 3I+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719922114; x=1720526914; 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=FCahmSEYU6tX9FqLb0Uk9Z14eoHvtjROOSdSw1YJQpE=; b=kog49iI6/yUFsVuzZ5lrb8r90gOPi2h3BK5NFo95nLeyYIRIxuwmvSkCk34LU7Mq0N Y0efQylP96J69qjKZ+7wDpUlvgo5DEPfN3R5mud6GjU+MflxsUX/XslCZ0AN/isAIeQM nXVDV1sqsQIII8TFu7LVlTRxlkxMjwgvD07faGzZNlEGM1DKYzkS2dYck5VzHCBZeMEv pJVWbKE/nMIguBRx4F9odNqBMv66iS4ItC1/dkUsSr4SeA4jMLm5jji+7ngGzFdHjodB E0zKaltGiNDAnMHi7Mroh2atB7cYq0UPV7qJIh+iYU65J3wDHl9QHbtwUKCG61WMWsGA MQPQ== X-Forwarded-Encrypted: i=1; AJvYcCVsPzEJrr9oY2luNu2uERw5rkrDvwX83tumeBoVdrtCH/D0uurfZEaRj83F4HNlmVs0WE24aTx6POlhzE8TDOkH8M56kTro X-Gm-Message-State: AOJu0YxAMK8sLf+EGilSaO9JRC1P/Esro0svt80Smt6kL0Fp40o3Ib6o A8slAB7R7bicoO60m7eu0p1V7Jzfdo8KmMUXlGmWPDHh/yoBWA0jbc0LJKBKm78= X-Google-Smtp-Source: AGHT+IHa8FAMkx5Vj/lheTFRq2vnO8kcgH30G8QkbdtT9a7fNLM9xq68XDWCaFIdq1JAVFRY9tlAWw== X-Received: by 2002:a05:6512:3e28:b0:52c:a5cb:69e4 with SMTP id 2adb3069b0e04-52e826f12d1mr5949124e87.54.1719922113775; Tue, 02 Jul 2024 05:08:33 -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-52e7ab1064asm1799414e87.103.2024.07.02.05.08.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 05:08:32 -0700 (PDT) From: Tobias Waldekranz To: stephen@networkplumber.org, dsahern@kernel.org, roopa@nvidia.com, razor@blackwall.org, bridge@lists.linux.dev, netdev@vger.kernel.org Cc: liuhangbin@gmail.com Subject: [PATCH v3 iproute2 3/4] bridge: vlan: Add support for setting a VLANs MSTI Date: Tue, 2 Jul 2024 14:08:04 +0200 Message-Id: <20240702120805.2391594-4-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240702120805.2391594-1-tobias@waldekranz.com> References: <20240702120805.2391594-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. Reviewed-by: Hangbin Liu Acked-by: Nikolay Aleksandrov Signed-off-by: Tobias Waldekranz --- 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 70f01aff..ea4aff93 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -53,6 +53,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); } @@ -403,6 +404,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), @@ -533,6 +535,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(); @@ -942,6 +950,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 Tue Jul 2 12:08:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Waldekranz X-Patchwork-Id: 13719531 X-Patchwork-Delegate: dsahern@gmail.com 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 D7C4C16B3A1 for ; Tue, 2 Jul 2024 12:08:36 +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=1719922119; cv=none; b=etZgZXklyr9PvVNXJHms2lTun19y6CmzfaXxkBxjLJqJjrSErgfe7TbOWKFElgivz+BGhzpa1470joAEkxHtFwl7GX9GTFicLL6n+6CufPx/F7yklX7MfidbDha/JWDzZY1kSbAQtDHoDixIfP+aBCM84pVwu+jzTxDB3Tj6W8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719922119; c=relaxed/simple; bh=/5nuBLnx57EsEH5Fp51r8N+mP4r0+26G8FY2XbSSlHw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gbOAHH/eBNtyqbIPoZaLHQuNY/FjOzC/UNPAaFO1sSpaA1InSEa+bOWhCHGr6XrCXjzymCOV2Sf4SRYyW92013G/THM5wxsBXBMx9THM23KTKPIykn3DHE81nvydn4+zMEIgyXtCXCAEq1mvmXiEEKFpWVy7K1d8h5TtlJ8uvk8= 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=onsOz5Q/; 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="onsOz5Q/" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-52e743307a2so4635784e87.0 for ; Tue, 02 Jul 2024 05:08:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=waldekranz-com.20230601.gappssmtp.com; s=20230601; t=1719922115; x=1720526915; 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=yFzCccGikLAGCgY4ieBgdKYyFg/aj/68UUIXY9SMuzs=; b=onsOz5Q/jrZv2GAfomtJb32sqLEnmHbflrwW2TzwQAQW4fgkWtbXWwItwfd7M/EW6g Zw+DkWdDBGTkl1cs0JunHZprEi+KDMNL4AcMLHOVaYVrPg7qS3hi1DY43IYMu2Kw5SVM OZJJRRGtJgvWzH9eoVmxuxa6GPVdv4LCNrfhPU7ZPSMgnxlFrSGv27dnFeWvp8SA38o/ tarR9LJOpxVAL7iO2KLwfCFj9CuUrmIzRb3qi5bQErPreYQatBD4dhyazTdIHtm/lMO+ lj8h5mK7CiwSV3hTJHrwJUHq374lty80rSLtSoYDr0EKdi5wKppHJrwsVvl+OKZvlNbi 3Jmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719922115; x=1720526915; 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=yFzCccGikLAGCgY4ieBgdKYyFg/aj/68UUIXY9SMuzs=; b=lJUyrj8QB925jlzk7HUM3WyOtsfog4OWz7dYvPw25cvaTZdf9XrktXD6Yy6BY+LF16 7nhILUtt3E5mAqgSa11eaW3xurvPDXGkbdPfta9Rs7VWDS78dXXtt1FysM8TjBc64KL8 5Du/B7ibj8ocgv/FGtk7i6L+KW+wL7e5++jT8H0Ziw/bBMVt0cGKMMrpoRnwp86zix+k Q/5ii6eDofkq1hKMJsy+PJ6oE7fECA8+2ZM/qJ41uLAmHcN7rKjZIOP/wSNPhSKOuN9m XpBfgsbsZ0UA3vW9VSQ7lIM4mQ8VIUnzdFHvBWh6+UuZFLC2uWmtansHliRnAypodJG8 bZkw== X-Forwarded-Encrypted: i=1; AJvYcCUxn/Cr4CgPhquVhk5G2iE8JHLtcZuT6NqBbAVo+JrjbM+kYMvzqQBZe5PmqObxu53nKUZQMxeZZc43lKaxpBqx86SLHL8b X-Gm-Message-State: AOJu0YwNx/HUn/PmDhhHUDU63ExjcSnxuJ21OLj2dtTKMbQETd4GFoOy /T0G2XI0YVBGm1syHuZD1O2Rhwws/MrcrWPuEwBzQZ1XutP48a9ARxEfEycuRz4= X-Google-Smtp-Source: AGHT+IH6NGdGFub5TNV2QR9171sllrmPpz4CWI4PH7V1ab+QjIstt5mBJdBeJ827KcuTOdcGJcE2Iw== X-Received: by 2002:a05:6512:2355:b0:52c:b09e:136d with SMTP id 2adb3069b0e04-52e8268b415mr7290375e87.32.1719922115072; Tue, 02 Jul 2024 05:08:35 -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-52e7ab1064asm1799414e87.103.2024.07.02.05.08.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jul 2024 05:08:34 -0700 (PDT) From: Tobias Waldekranz To: stephen@networkplumber.org, dsahern@kernel.org, roopa@nvidia.com, razor@blackwall.org, bridge@lists.linux.dev, netdev@vger.kernel.org Cc: liuhangbin@gmail.com Subject: [PATCH v3 iproute2 4/4] bridge: mst: Add get/set support for MST states Date: Tue, 2 Jul 2024 14:08:05 +0200 Message-Id: <20240702120805.2391594-5-tobias@waldekranz.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240702120805.2391594-1-tobias@waldekranz.com> References: <20240702120805.2391594-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 | 258 +++++++++++++++++++++++++++++++++++++++++++++ man/man8/bridge.8 | 57 ++++++++++ 5 files changed, 319 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..f8447284 --- /dev/null +++ b/bridge/mst.c @@ -0,0 +1,258 @@ +/* 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 + +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, "%-" textify(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; + + switch (rta_type) { + case IFLA_BRIDGE_MST_ENTRY: + if (!opened) { + open_json_object(NULL); + print_color_string(PRINT_ANY, COLOR_IFNAME, + "ifname", + "%-" textify(IFNAMSIZ) "s ", + ll_index_to_name(ifi->ifi_index)); + open_json_array(PRINT_JSON, "mst"); + opened = true; + } else { + print_string(PRINT_FP, NULL, "%-" + textify(IFNAMSIZ) "s ", ""); + } + + print_mst_entry(a, arg); + break; + default: + continue; + } + } + + 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("%-" textify(IFNAMSIZ) "s " + "%-" textify(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; + __s8 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..08032e2f 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 dev DEV vid VID msti MSTI" . + +.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