Skip to content

Commit ea749a8

Browse files
KanjiMonsterSasha Levin
authored andcommitted
net: dsa: b53: do not allow to configure VLAN 0
[ Upstream commit 45e9d59 ] Since we cannot set forwarding destinations per VLAN, we should not have a VLAN 0 configured, as it would allow untagged traffic to work across ports on VLAN aware bridges regardless if a PVID untagged VLAN exists. So remove the VLAN 0 on join, an re-add it on leave. But only do so if we have a VLAN aware bridge, as without it, untagged traffic would become tagged with VID 0 on a VLAN unaware bridge. Fixes: a2482d2 ("net: dsa: b53: Plug in VLAN support") Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com> Tested-by: Florian Fainelli <florian.fainelli@broadcom.com> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> Link: https://patch.msgid.link/20250429201710.330937-8-jonas.gorski@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ccd3811 commit ea749a8

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

drivers/net/dsa/b53/b53_common.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,9 @@ int b53_vlan_add(struct dsa_switch *ds, int port,
15451545
if (err)
15461546
return err;
15471547

1548+
if (vlan->vid == 0)
1549+
return 0;
1550+
15481551
b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &old_pvid);
15491552
if (pvid)
15501553
new_pvid = vlan->vid;
@@ -1557,10 +1560,7 @@ int b53_vlan_add(struct dsa_switch *ds, int port,
15571560

15581561
b53_get_vlan_entry(dev, vlan->vid, vl);
15591562

1560-
if (vlan->vid == 0 && vlan->vid == b53_default_pvid(dev))
1561-
untagged = true;
1562-
1563-
if (vlan->vid > 0 && dsa_is_cpu_port(ds, port))
1563+
if (dsa_is_cpu_port(ds, port))
15641564
untagged = false;
15651565

15661566
vl->members |= BIT(port);
@@ -1590,6 +1590,9 @@ int b53_vlan_del(struct dsa_switch *ds, int port,
15901590
struct b53_vlan *vl;
15911591
u16 pvid;
15921592

1593+
if (vlan->vid == 0)
1594+
return 0;
1595+
15931596
b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &pvid);
15941597

15951598
vl = &dev->vlans[vlan->vid];
@@ -1936,8 +1939,9 @@ int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
19361939
bool *tx_fwd_offload, struct netlink_ext_ack *extack)
19371940
{
19381941
struct b53_device *dev = ds->priv;
1942+
struct b53_vlan *vl;
19391943
s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
1940-
u16 pvlan, reg;
1944+
u16 pvlan, reg, pvid;
19411945
unsigned int i;
19421946

19431947
/* On 7278, port 7 which connects to the ASP should only receive
@@ -1946,6 +1950,9 @@ int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
19461950
if (dev->chip_id == BCM7278_DEVICE_ID && port == 7)
19471951
return -EINVAL;
19481952

1953+
pvid = b53_default_pvid(dev);
1954+
vl = &dev->vlans[pvid];
1955+
19491956
/* Make this port leave the all VLANs join since we will have proper
19501957
* VLAN entries from now on
19511958
*/
@@ -1957,6 +1964,15 @@ int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
19571964
b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg);
19581965
}
19591966

1967+
if (ds->vlan_filtering) {
1968+
b53_get_vlan_entry(dev, pvid, vl);
1969+
vl->members &= ~BIT(port);
1970+
if (vl->members == BIT(cpu_port))
1971+
vl->members &= ~BIT(cpu_port);
1972+
vl->untag = vl->members;
1973+
b53_set_vlan_entry(dev, pvid, vl);
1974+
}
1975+
19601976
b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan);
19611977

19621978
b53_for_each_port(dev, i) {
@@ -2024,10 +2040,12 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge)
20242040
b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg);
20252041
}
20262042

2027-
b53_get_vlan_entry(dev, pvid, vl);
2028-
vl->members |= BIT(port) | BIT(cpu_port);
2029-
vl->untag |= BIT(port) | BIT(cpu_port);
2030-
b53_set_vlan_entry(dev, pvid, vl);
2043+
if (ds->vlan_filtering) {
2044+
b53_get_vlan_entry(dev, pvid, vl);
2045+
vl->members |= BIT(port) | BIT(cpu_port);
2046+
vl->untag |= BIT(port) | BIT(cpu_port);
2047+
b53_set_vlan_entry(dev, pvid, vl);
2048+
}
20312049
}
20322050
EXPORT_SYMBOL(b53_br_leave);
20332051

0 commit comments

Comments
 (0)