Commit 60b33aeb authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

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: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7f14937f
...@@ -198,6 +198,7 @@ struct sja1105_private { ...@@ -198,6 +198,7 @@ struct sja1105_private {
* the switch doesn't confuse them with one another. * the switch doesn't confuse them with one another.
*/ */
struct mutex mgmt_lock; struct mutex mgmt_lock;
bool expect_dsa_8021q;
enum sja1105_vlan_state vlan_state; enum sja1105_vlan_state vlan_state;
struct sja1105_tagger_data tagger_data; struct sja1105_tagger_data tagger_data;
struct sja1105_ptp_data ptp_data; struct sja1105_ptp_data ptp_data;
......
...@@ -1811,15 +1811,19 @@ static int sja1105_crosschip_bridge_join(struct dsa_switch *ds, ...@@ -1811,15 +1811,19 @@ static int sja1105_crosschip_bridge_join(struct dsa_switch *ds,
if (dsa_to_port(ds, port)->bridge_dev != br) if (dsa_to_port(ds, port)->bridge_dev != br)
continue; continue;
other_priv->expect_dsa_8021q = true;
rc = dsa_8021q_crosschip_bridge_join(ds, port, other_ds, rc = dsa_8021q_crosschip_bridge_join(ds, port, other_ds,
other_port, br, other_port, br,
&priv->crosschip_links); &priv->crosschip_links);
other_priv->expect_dsa_8021q = false;
if (rc) if (rc)
return rc; return rc;
priv->expect_dsa_8021q = true;
rc = dsa_8021q_crosschip_bridge_join(other_ds, other_port, ds, rc = dsa_8021q_crosschip_bridge_join(other_ds, other_port, ds,
port, br, port, br,
&other_priv->crosschip_links); &other_priv->crosschip_links);
priv->expect_dsa_8021q = false;
if (rc) if (rc)
return rc; return rc;
} }
...@@ -1846,12 +1850,16 @@ static void sja1105_crosschip_bridge_leave(struct dsa_switch *ds, ...@@ -1846,12 +1850,16 @@ static void sja1105_crosschip_bridge_leave(struct dsa_switch *ds,
if (dsa_to_port(ds, port)->bridge_dev != br) if (dsa_to_port(ds, port)->bridge_dev != br)
continue; continue;
other_priv->expect_dsa_8021q = true;
dsa_8021q_crosschip_bridge_leave(ds, port, other_ds, other_port, dsa_8021q_crosschip_bridge_leave(ds, port, other_ds, other_port,
br, &priv->crosschip_links); br, &priv->crosschip_links);
other_priv->expect_dsa_8021q = false;
priv->expect_dsa_8021q = true;
dsa_8021q_crosschip_bridge_leave(other_ds, other_port, ds, dsa_8021q_crosschip_bridge_leave(other_ds, other_port, ds,
port, br, port, br,
&other_priv->crosschip_links); &other_priv->crosschip_links);
priv->expect_dsa_8021q = false;
} }
} }
...@@ -1862,8 +1870,10 @@ static int sja1105_replay_crosschip_vlans(struct dsa_switch *ds, bool enabled) ...@@ -1862,8 +1870,10 @@ static int sja1105_replay_crosschip_vlans(struct dsa_switch *ds, bool enabled)
int rc; int rc;
list_for_each_entry(c, &priv->crosschip_links, list) { list_for_each_entry(c, &priv->crosschip_links, list) {
priv->expect_dsa_8021q = true;
rc = dsa_8021q_crosschip_link_apply(ds, c->port, c->other_ds, rc = dsa_8021q_crosschip_link_apply(ds, c->port, c->other_ds,
c->other_port, enabled); c->other_port, enabled);
priv->expect_dsa_8021q = false;
if (rc) if (rc)
break; break;
} }
...@@ -1873,10 +1883,13 @@ static int sja1105_replay_crosschip_vlans(struct dsa_switch *ds, bool enabled) ...@@ -1873,10 +1883,13 @@ static int sja1105_replay_crosschip_vlans(struct dsa_switch *ds, bool enabled)
static int sja1105_setup_8021q_tagging(struct dsa_switch *ds, bool enabled) static int sja1105_setup_8021q_tagging(struct dsa_switch *ds, bool enabled)
{ {
struct sja1105_private *priv = ds->priv;
int rc, i; int rc, i;
for (i = 0; i < SJA1105_NUM_PORTS; i++) { for (i = 0; i < SJA1105_NUM_PORTS; i++) {
priv->expect_dsa_8021q = true;
rc = dsa_port_setup_8021q_tagging(ds, i, enabled); rc = dsa_port_setup_8021q_tagging(ds, i, enabled);
priv->expect_dsa_8021q = false;
if (rc < 0) { if (rc < 0) {
dev_err(ds->dev, "Failed to setup VLAN tagging for port %d: %d\n", dev_err(ds->dev, "Failed to setup VLAN tagging for port %d: %d\n",
i, rc); i, rc);
...@@ -1901,10 +1914,26 @@ sja1105_get_tag_protocol(struct dsa_switch *ds, int port, ...@@ -1901,10 +1914,26 @@ sja1105_get_tag_protocol(struct dsa_switch *ds, int port,
return DSA_TAG_PROTO_SJA1105; return DSA_TAG_PROTO_SJA1105;
} }
/* This callback needs to be present */
static int sja1105_vlan_prepare(struct dsa_switch *ds, int port, static int sja1105_vlan_prepare(struct dsa_switch *ds, int port,
const struct switchdev_obj_port_vlan *vlan) const struct switchdev_obj_port_vlan *vlan)
{ {
struct sja1105_private *priv = ds->priv;
u16 vid;
if (priv->vlan_state == SJA1105_VLAN_FILTERING_FULL)
return 0;
/* If the user wants best-effort VLAN filtering (aka vlan_filtering
* bridge plus tagging), be sure to at least deny alterations to the
* configuration done by dsa_8021q.
*/
for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) {
if (!priv->expect_dsa_8021q && vid_is_dsa_8021q(vid)) {
dev_err(ds->dev, "Range 1024-3071 reserved for dsa_8021q operation\n");
return -EBUSY;
}
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment