Skip to content

Commit d371b7c

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: Unset vlan_filtering when ports leave the bridge
When ports are standalone (after they left the bridge), they should have no VLAN filtering semantics (they should pass all traffic to the CPU). Currently this is not true for switchdev drivers, because the bridge "forgets" to unset that. Normally one would think that doing this at the bridge layer would be a better idea, i.e. call br_vlan_filter_toggle() from br_del_if(), similar to how nbp_vlan_init() is called from br_add_if(). However what complicates that approach, and makes this one preferable, is the fact that for the bridge core, vlan_filtering is a per-bridge setting, whereas for switchdev/DSA it is per-port. Also there are switches where the setting is per the entire device, and unsetting vlan_filtering one by one, for each leaving port, would not be possible from the bridge core without a certain level of awareness. So do this in DSA and let drivers be unaware of it. Signed-off-by: Vladimir Oltean <olteanv@gmail.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7228b23 commit d371b7c

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

‎net/dsa/switch.c‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* (at your option) any later version.
1111
*/
1212

13+
#include <linux/if_bridge.h>
1314
#include <linux/netdevice.h>
1415
#include <linux/notifier.h>
1516
#include <linux/if_vlan.h>
@@ -71,13 +72,41 @@ static int dsa_switch_bridge_join(struct dsa_switch *ds,
7172
static int dsa_switch_bridge_leave(struct dsa_switch *ds,
7273
struct dsa_notifier_bridge_info *info)
7374
{
75+
bool unset_vlan_filtering = br_vlan_enabled(info->br);
76+
int err, i;
77+
7478
if (ds->index == info->sw_index && ds->ops->port_bridge_leave)
7579
ds->ops->port_bridge_leave(ds, info->port, info->br);
7680

7781
if (ds->index != info->sw_index && ds->ops->crosschip_bridge_leave)
7882
ds->ops->crosschip_bridge_leave(ds, info->sw_index, info->port,
7983
info->br);
8084

85+
/* If the bridge was vlan_filtering, the bridge core doesn't trigger an
86+
* event for changing vlan_filtering setting upon slave ports leaving
87+
* it. That is a good thing, because that lets us handle it and also
88+
* handle the case where the switch's vlan_filtering setting is global
89+
* (not per port). When that happens, the correct moment to trigger the
90+
* vlan_filtering callback is only when the last port left this bridge.
91+
*/
92+
if (unset_vlan_filtering && ds->vlan_filtering_is_global) {
93+
for (i = 0; i < ds->num_ports; i++) {
94+
if (i == info->port)
95+
continue;
96+
if (dsa_to_port(ds, i)->bridge_dev == info->br) {
97+
unset_vlan_filtering = false;
98+
break;
99+
}
100+
}
101+
}
102+
if (unset_vlan_filtering) {
103+
struct switchdev_trans trans = {0};
104+
105+
err = dsa_port_vlan_filtering(&ds->ports[info->port],
106+
false, &trans);
107+
if (err && err != EOPNOTSUPP)
108+
return err;
109+
}
81110
return 0;
82111
}
83112

0 commit comments

Comments
 (0)