diff options
Diffstat (limited to 'net/dsa/switch.c')
-rw-r--r-- | net/dsa/switch.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/net/dsa/switch.c b/net/dsa/switch.c index 142b294d3446..e1fae969aa73 100644 --- a/net/dsa/switch.c +++ b/net/dsa/switch.c | |||
@@ -12,6 +12,7 @@ | |||
12 | 12 | ||
13 | #include <linux/netdevice.h> | 13 | #include <linux/netdevice.h> |
14 | #include <linux/notifier.h> | 14 | #include <linux/notifier.h> |
15 | #include <linux/if_vlan.h> | ||
15 | #include <net/switchdev.h> | 16 | #include <net/switchdev.h> |
16 | 17 | ||
17 | #include "dsa_priv.h" | 18 | #include "dsa_priv.h" |
@@ -168,6 +169,43 @@ static int dsa_switch_mdb_del(struct dsa_switch *ds, | |||
168 | return 0; | 169 | return 0; |
169 | } | 170 | } |
170 | 171 | ||
172 | static int dsa_port_vlan_device_check(struct net_device *vlan_dev, | ||
173 | int vlan_dev_vid, | ||
174 | void *arg) | ||
175 | { | ||
176 | struct switchdev_obj_port_vlan *vlan = arg; | ||
177 | u16 vid; | ||
178 | |||
179 | for (vid = vlan->vid_begin; vid <= vlan->vid_end; ++vid) { | ||
180 | if (vid == vlan_dev_vid) | ||
181 | return -EBUSY; | ||
182 | } | ||
183 | |||
184 | return 0; | ||
185 | } | ||
186 | |||
187 | static int dsa_port_vlan_check(struct dsa_switch *ds, int port, | ||
188 | const struct switchdev_obj_port_vlan *vlan) | ||
189 | { | ||
190 | const struct dsa_port *dp = dsa_to_port(ds, port); | ||
191 | int err = 0; | ||
192 | |||
193 | /* Device is not bridged, let it proceed with the VLAN device | ||
194 | * creation. | ||
195 | */ | ||
196 | if (!dp->bridge_dev) | ||
197 | return err; | ||
198 | |||
199 | /* dsa_slave_vlan_rx_{add,kill}_vid() cannot use the prepare pharse and | ||
200 | * already checks whether there is an overlapping bridge VLAN entry | ||
201 | * with the same VID, so here we only need to check that if we are | ||
202 | * adding a bridge VLAN entry there is not an overlapping VLAN device | ||
203 | * claiming that VID. | ||
204 | */ | ||
205 | return vlan_for_each(dp->slave, dsa_port_vlan_device_check, | ||
206 | (void *)vlan); | ||
207 | } | ||
208 | |||
171 | static int | 209 | static int |
172 | dsa_switch_vlan_prepare_bitmap(struct dsa_switch *ds, | 210 | dsa_switch_vlan_prepare_bitmap(struct dsa_switch *ds, |
173 | const struct switchdev_obj_port_vlan *vlan, | 211 | const struct switchdev_obj_port_vlan *vlan, |
@@ -179,6 +217,10 @@ dsa_switch_vlan_prepare_bitmap(struct dsa_switch *ds, | |||
179 | return -EOPNOTSUPP; | 217 | return -EOPNOTSUPP; |
180 | 218 | ||
181 | for_each_set_bit(port, bitmap, ds->num_ports) { | 219 | for_each_set_bit(port, bitmap, ds->num_ports) { |
220 | err = dsa_port_vlan_check(ds, port, vlan); | ||
221 | if (err) | ||
222 | return err; | ||
223 | |||
182 | err = ds->ops->port_vlan_prepare(ds, port, vlan); | 224 | err = ds->ops->port_vlan_prepare(ds, port, vlan); |
183 | if (err) | 225 | if (err) |
184 | return err; | 226 | return err; |