lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 22 Jul 2021 18:55:39 +0300
From:   Vladimir Oltean <>
To:, Jakub Kicinski <>,
        "David S. Miller" <>
Cc:     Andrew Lunn <>,
        Florian Fainelli <>,
        Vivien Didelot <>,
        Jiri Pirko <>,
        Ido Schimmel <>,
        Tobias Waldekranz <>,
        Roopa Prabhu <>,
        Nikolay Aleksandrov <>,
        Stephen Hemminger <>,,
        Grygorii Strashko <>,
        Marek Behun <>,
        DENG Qingfang <>
Subject: [PATCH v5 net-next 2/5] net: dsa: track the number of switches in a tree

In preparation of supporting data plane forwarding on behalf of a
software bridge, some drivers might need to view bridges as virtual
switches behind the CPU port in a cross-chip topology.

Give them some help and let them know how many physical switches there
are in the tree, so that they can count the virtual switches starting
from that number on.

Note that the first dsa_switch_ops method where this information is
reliably available is .setup(). This is because of how DSA works:
in a tree with 3 switches, each calling dsa_register_switch(), the first
2 will advance until dsa_tree_setup() -> dsa_tree_setup_routing_table()
and exit with error code 0 because the topology is not complete. Since
probing is parallel at this point, one switch does not know about the
existence of the other. Then the third switch comes, and for it,
dsa_tree_setup_routing_table() returns complete = true. This switch goes
ahead and calls dsa_tree_setup_switches() for everybody else, calling
their .setup() methods too. This acts as the synchronization point.

Signed-off-by: Vladimir Oltean <>
Reviewed-by: Florian Fainelli <>
v2->v3: patch is new
v3->v5: none

 include/net/dsa.h | 3 +++
 net/dsa/dsa2.c    | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/include/net/dsa.h b/include/net/dsa.h
index 9e5593885357..929bcaec4d41 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -159,6 +159,9 @@ struct dsa_switch_tree {
 	struct net_device **lags;
 	unsigned int lags_len;
+	/* Track the largest switch index within a tree */
+	unsigned int last_switch;
 #define dsa_lags_foreach_id(_id, _dst)				\
diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c
index 185629f27f80..de5e93ba2a9d 100644
--- a/net/dsa/dsa2.c
+++ b/net/dsa/dsa2.c
@@ -1265,6 +1265,9 @@ static int dsa_switch_parse_member_of(struct dsa_switch *ds,
 		return -EEXIST;
+	if (ds->dst->last_switch < ds->index)
+		ds->dst->last_switch = ds->index;
 	return 0;

Powered by blists - more mailing lists