Skip to content

Commit 45e9d59

Browse files
KanjiMonsterkuba-moo
authored andcommitted
net: dsa: b53: do not allow to configure VLAN 0
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 <[email protected]> Tested-by: Florian Fainelli <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 13b152a commit 45e9d59

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
@@ -1544,6 +1544,9 @@ int b53_vlan_add(struct dsa_switch *ds, int port,
15441544
if (err)
15451545
return err;
15461546

1547+
if (vlan->vid == 0)
1548+
return 0;
1549+
15471550
b53_read16(dev, B53_VLAN_PAGE, B53_VLAN_PORT_DEF_TAG(port), &old_pvid);
15481551
if (pvid)
15491552
new_pvid = vlan->vid;
@@ -1556,10 +1559,7 @@ int b53_vlan_add(struct dsa_switch *ds, int port,
15561559

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

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

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

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

15941597
vl = &dev->vlans[vlan->vid];
@@ -1935,8 +1938,9 @@ int b53_br_join(struct dsa_switch *ds, int port, struct dsa_bridge bridge,
19351938
bool *tx_fwd_offload, struct netlink_ext_ack *extack)
19361939
{
19371940
struct b53_device *dev = ds->priv;
1941+
struct b53_vlan *vl;
19381942
s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index;
1939-
u16 pvlan, reg;
1943+
u16 pvlan, reg, pvid;
19401944
unsigned int i;
19411945

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

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

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

19611977
b53_for_each_port(dev, i) {
@@ -2023,10 +2039,12 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct dsa_bridge bridge)
20232039
b53_write16(dev, B53_VLAN_PAGE, B53_JOIN_ALL_VLAN_EN, reg);
20242040
}
20252041

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

0 commit comments

Comments
 (0)