Skip to content

Commit 9304035

Browse files
yangbolu1991kartben
authored andcommitted
net: bridge: support DSA port
DSA switch performs L2 switching on hardware on DSA user ports. The promisc mode requirement doesn't apply to DSA user ports. Signed-off-by: Yangbo Lu <[email protected]>
1 parent 98a20b2 commit 9304035

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

subsys/net/l2/ethernet/bridge.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,18 @@ int eth_bridge_iface_add(struct net_if *br, struct net_if *iface)
9494
int count = 0;
9595
int ret;
9696

97+
#if defined(CONFIG_NET_DSA) && !defined(CONFIG_NET_DSA_DEPRECATED)
98+
if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET) ||
99+
(eth_ctx->dsa_port != DSA_USER_PORT &&
100+
!(net_eth_get_hw_capabilities(iface) & ETHERNET_PROMISC_MODE))) {
101+
return -EINVAL;
102+
}
103+
#else
97104
if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET) ||
98105
!(net_eth_get_hw_capabilities(iface) & ETHERNET_PROMISC_MODE)) {
99106
return -EINVAL;
100107
}
101-
108+
#endif
102109
if (net_if_l2(br) != &NET_L2_GET_NAME(VIRTUAL) ||
103110
!(net_virtual_get_iface_capabilities(br) & VIRTUAL_INTERFACE_BRIDGE)) {
104111
return -EINVAL;
@@ -134,6 +141,17 @@ int eth_bridge_iface_add(struct net_if *br, struct net_if *iface)
134141
return -ENOMEM;
135142
}
136143

144+
#if defined(CONFIG_NET_DSA) && !defined(CONFIG_NET_DSA_DEPRECATED)
145+
if (eth_ctx->dsa_port != DSA_USER_PORT) {
146+
ret = net_eth_promisc_mode(iface, true);
147+
if (ret != 0 && ret != -EALREADY) {
148+
NET_DBG("iface %d promiscuous mode failed: %d",
149+
net_if_get_by_iface(iface), ret);
150+
eth_bridge_iface_remove(br, iface);
151+
return ret;
152+
}
153+
}
154+
#else
137155
ret = net_eth_promisc_mode(iface, true);
138156
if (ret != 0 && ret != -EALREADY) {
139157
/* Ignore any errors when using native-sim driver,
@@ -148,6 +166,7 @@ int eth_bridge_iface_add(struct net_if *br, struct net_if *iface)
148166
}
149167
}
150168

169+
#endif
151170
NET_DBG("iface %d added to bridge %d", net_if_get_by_iface(iface),
152171
net_if_get_by_iface(br));
153172

subsys/net/l2/ethernet/bridge_shell.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ static int get_idx(const struct shell *sh, char *index_str)
2727

2828
static int cmd_bridge_addif(const struct shell *sh, size_t argc, char *argv[])
2929
{
30+
#if defined(CONFIG_NET_DSA) && !defined(CONFIG_NET_DSA_DEPRECATED)
31+
struct ethernet_context *eth_ctx;
32+
#endif
3033
int ret = 0, br_idx, if_idx;
3134
struct net_if *iface;
3235
struct net_if *br;
@@ -59,10 +62,19 @@ static int cmd_bridge_addif(const struct shell *sh, size_t argc, char *argv[])
5962
continue;
6063
}
6164

65+
#if defined(CONFIG_NET_DSA) && !defined(CONFIG_NET_DSA_DEPRECATED)
66+
eth_ctx = net_if_l2_data(iface);
67+
if (eth_ctx->dsa_port != DSA_USER_PORT &&
68+
!(net_eth_get_hw_capabilities(iface) & ETHERNET_PROMISC_MODE)) {
69+
shell_warn(sh, "Interface %d cannot do promiscuous mode\n", if_idx);
70+
continue;
71+
}
72+
#else
6273
if (!(net_eth_get_hw_capabilities(iface) & ETHERNET_PROMISC_MODE)) {
6374
shell_warn(sh, "Interface %d cannot do promiscuous mode\n", if_idx);
6475
continue;
6576
}
77+
#endif
6678

6779
ret = eth_bridge_iface_add(br, iface);
6880
if (ret < 0) {

0 commit comments

Comments
 (0)