Skip to content

Commit ed040ab

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: sja1105: use 4095 as the private VLAN for untagged traffic
One thing became visible when writing the blamed commit, and that was that STP and PTP frames injected by net/dsa/tag_sja1105.c using the deferred xmit mechanism are always classified to the pvid of the CPU port, regardless of whatever VLAN there might be in these packets. So a decision needed to be taken regarding the mechanism through which we should ensure that delivery of STP and PTP traffic is possible when we are in a VLAN awareness mode that involves tag_8021q. This is because tag_8021q is not concerned with managing the pvid of the CPU port, since as far as tag_8021q is concerned, no traffic should be sent as untagged from the CPU port. So we end up not actually having a pvid on the CPU port if we only listen to tag_8021q, and unless we do something about it. The decision taken at the time was to keep VLAN 1 in the list of priv->dsa_8021q_vlans, and make it a pvid of the CPU port. This ensures that STP and PTP frames can always be sent to the outside world. However there is a problem. If we do the following while we are in the best_effort_vlan_filtering=true mode: ip link add br0 type bridge vlan_filtering 1 ip link set swp2 master br0 bridge vlan del dev swp2 vid 1 Then untagged and pvid-tagged frames should be dropped. But we observe that they aren't, and this is because of the precaution we took that VID 1 is always installed on all ports. So clearly VLAN 1 is not good for this purpose. What about VLAN 0? Well, VLAN 0 is managed by the 8021q module, and that module wants to ensure that 802.1p tagged frames are always received by a port, and are always transmitted as VLAN-tagged (with VLAN ID 0). Whereas we want our STP and PTP frames to be untagged if the stack sent them as untagged - we don't want the driver to just decide out of the blue that it adds VID 0 to some packets. So what to do? Well, there is one other VLAN that is reserved, and that is 4095: $ ip link add link swp2 name swp2.4095 type vlan id 4095 Error: 8021q: Invalid VLAN id. $ bridge vlan add dev swp2 vid 4095 Error: bridge: Vlan id is invalid. After we made this change, VLAN 1 is indeed forwarded and/or dropped according to the bridge VLAN table, there are no further alterations done by the sja1105 driver. Fixes: ec5ae61 ("net: dsa: sja1105: save/restore VLANs using a delta commit method") Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6729188 commit ed040ab

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

drivers/net/dsa/sja1105/sja1105_main.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "sja1105_tas.h"
2727

2828
#define SJA1105_UNKNOWN_MULTICAST 0x010000000000ull
29+
#define SJA1105_DEFAULT_VLAN (VLAN_N_VID - 1)
2930

3031
static const struct dsa_switch_ops sja1105_switch_ops;
3132

@@ -322,6 +323,13 @@ static int sja1105_init_l2_lookup_params(struct sja1105_private *priv)
322323
return 0;
323324
}
324325

326+
/* Set up a default VLAN for untagged traffic injected from the CPU
327+
* using management routes (e.g. STP, PTP) as opposed to tag_8021q.
328+
* All DT-defined ports are members of this VLAN, and there are no
329+
* restrictions on forwarding (since the CPU selects the destination).
330+
* Frames from this VLAN will always be transmitted as untagged, and
331+
* neither the bridge nor the 8021q module cannot create this VLAN ID.
332+
*/
325333
static int sja1105_init_static_vlan(struct sja1105_private *priv)
326334
{
327335
struct sja1105_table *table;
@@ -331,17 +339,13 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv)
331339
.vmemb_port = 0,
332340
.vlan_bc = 0,
333341
.tag_port = 0,
334-
.vlanid = 1,
342+
.vlanid = SJA1105_DEFAULT_VLAN,
335343
};
336344
struct dsa_switch *ds = priv->ds;
337345
int port;
338346

339347
table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP];
340348

341-
/* The static VLAN table will only contain the initial pvid of 1.
342-
* All other VLANs are to be configured through dynamic entries,
343-
* and kept in the static configuration table as backing memory.
344-
*/
345349
if (table->entry_count) {
346350
kfree(table->entries);
347351
table->entry_count = 0;
@@ -354,9 +358,6 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv)
354358

355359
table->entry_count = 1;
356360

357-
/* VLAN 1: all DT-defined ports are members; no restrictions on
358-
* forwarding; always transmit as untagged.
359-
*/
360361
for (port = 0; port < ds->num_ports; port++) {
361362
struct sja1105_bridge_vlan *v;
362363

@@ -367,15 +368,12 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv)
367368
pvid.vlan_bc |= BIT(port);
368369
pvid.tag_port &= ~BIT(port);
369370

370-
/* Let traffic that don't need dsa_8021q (e.g. STP, PTP) be
371-
* transmitted as untagged.
372-
*/
373371
v = kzalloc(sizeof(*v), GFP_KERNEL);
374372
if (!v)
375373
return -ENOMEM;
376374

377375
v->port = port;
378-
v->vid = 1;
376+
v->vid = SJA1105_DEFAULT_VLAN;
379377
v->untagged = true;
380378
if (dsa_is_cpu_port(ds, port))
381379
v->pvid = true;

0 commit comments

Comments
 (0)