Skip to content

Commit 60b33ae

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: sja1105: deny alterations of dsa_8021q VLANs from the bridge
At the moment, this can never happen. The 2 modes that we operate in do not permit that: - SJA1105_VLAN_UNAWARE: we are guarded from bridge VLANs added by the user by the DSA core. We will later lift this restriction by setting ds->vlan_bridge_vtu = true, and that is where we'll need it. - SJA1105_VLAN_FILTERING_FULL: in this mode, dsa_8021q configuration is disabled. So the user is free to add these VLANs in the 1024-3071 range. The reason for the patch is that we'll introduce a third VLAN awareness state, where both dsa_8021q as well as the bridge are going to call our .port_vlan_add and .port_vlan_del methods. For that, we need a good way to discriminate between the 2. The easiest (and less intrusive way for upper layers) is to recognize the fact that dsa_8021q configurations are always driven by our driver - we _know_ when a .port_vlan_add method will be called from dsa_8021q because _we_ initiated it. So introduce an expect_dsa_8021q boolean which is only used, at the moment, for blacklisting VLANs in range 1024-3071 in the modes when dsa_8021q is active. Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7f14937 commit 60b33ae

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

drivers/net/dsa/sja1105/sja1105.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ struct sja1105_private {
198198
* the switch doesn't confuse them with one another.
199199
*/
200200
struct mutex mgmt_lock;
201+
bool expect_dsa_8021q;
201202
enum sja1105_vlan_state vlan_state;
202203
struct sja1105_tagger_data tagger_data;
203204
struct sja1105_ptp_data ptp_data;

drivers/net/dsa/sja1105/sja1105_main.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1811,15 +1811,19 @@ static int sja1105_crosschip_bridge_join(struct dsa_switch *ds,
18111811
if (dsa_to_port(ds, port)->bridge_dev != br)
18121812
continue;
18131813

1814+
other_priv->expect_dsa_8021q = true;
18141815
rc = dsa_8021q_crosschip_bridge_join(ds, port, other_ds,
18151816
other_port, br,
18161817
&priv->crosschip_links);
1818+
other_priv->expect_dsa_8021q = false;
18171819
if (rc)
18181820
return rc;
18191821

1822+
priv->expect_dsa_8021q = true;
18201823
rc = dsa_8021q_crosschip_bridge_join(other_ds, other_port, ds,
18211824
port, br,
18221825
&other_priv->crosschip_links);
1826+
priv->expect_dsa_8021q = false;
18231827
if (rc)
18241828
return rc;
18251829
}
@@ -1846,12 +1850,16 @@ static void sja1105_crosschip_bridge_leave(struct dsa_switch *ds,
18461850
if (dsa_to_port(ds, port)->bridge_dev != br)
18471851
continue;
18481852

1853+
other_priv->expect_dsa_8021q = true;
18491854
dsa_8021q_crosschip_bridge_leave(ds, port, other_ds, other_port,
18501855
br, &priv->crosschip_links);
1856+
other_priv->expect_dsa_8021q = false;
18511857

1858+
priv->expect_dsa_8021q = true;
18521859
dsa_8021q_crosschip_bridge_leave(other_ds, other_port, ds,
18531860
port, br,
18541861
&other_priv->crosschip_links);
1862+
priv->expect_dsa_8021q = false;
18551863
}
18561864
}
18571865

@@ -1862,8 +1870,10 @@ static int sja1105_replay_crosschip_vlans(struct dsa_switch *ds, bool enabled)
18621870
int rc;
18631871

18641872
list_for_each_entry(c, &priv->crosschip_links, list) {
1873+
priv->expect_dsa_8021q = true;
18651874
rc = dsa_8021q_crosschip_link_apply(ds, c->port, c->other_ds,
18661875
c->other_port, enabled);
1876+
priv->expect_dsa_8021q = false;
18671877
if (rc)
18681878
break;
18691879
}
@@ -1873,10 +1883,13 @@ static int sja1105_replay_crosschip_vlans(struct dsa_switch *ds, bool enabled)
18731883

18741884
static int sja1105_setup_8021q_tagging(struct dsa_switch *ds, bool enabled)
18751885
{
1886+
struct sja1105_private *priv = ds->priv;
18761887
int rc, i;
18771888

18781889
for (i = 0; i < SJA1105_NUM_PORTS; i++) {
1890+
priv->expect_dsa_8021q = true;
18791891
rc = dsa_port_setup_8021q_tagging(ds, i, enabled);
1892+
priv->expect_dsa_8021q = false;
18801893
if (rc < 0) {
18811894
dev_err(ds->dev, "Failed to setup VLAN tagging for port %d: %d\n",
18821895
i, rc);
@@ -1901,10 +1914,26 @@ sja1105_get_tag_protocol(struct dsa_switch *ds, int port,
19011914
return DSA_TAG_PROTO_SJA1105;
19021915
}
19031916

1904-
/* This callback needs to be present */
19051917
static int sja1105_vlan_prepare(struct dsa_switch *ds, int port,
19061918
const struct switchdev_obj_port_vlan *vlan)
19071919
{
1920+
struct sja1105_private *priv = ds->priv;
1921+
u16 vid;
1922+
1923+
if (priv->vlan_state == SJA1105_VLAN_FILTERING_FULL)
1924+
return 0;
1925+
1926+
/* If the user wants best-effort VLAN filtering (aka vlan_filtering
1927+
* bridge plus tagging), be sure to at least deny alterations to the
1928+
* configuration done by dsa_8021q.
1929+
*/
1930+
for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
1931+
if (!priv->expect_dsa_8021q && vid_is_dsa_8021q(vid)) {
1932+
dev_err(ds->dev, "Range 1024-3071 reserved for dsa_8021q operation\n");
1933+
return -EBUSY;
1934+
}
1935+
}
1936+
19081937
return 0;
19091938
}
19101939

0 commit comments

Comments
 (0)