blob: e227164bc3e174a07f7badbb8c94e64d96a2b993 [file] [log] [blame]
Vlad Yasevich243a2e62013-02-13 12:00:09 +00001#include <linux/kernel.h>
2#include <linux/netdevice.h>
3#include <linux/rtnetlink.h>
4#include <linux/slab.h>
Scott Feldman7f109532015-06-12 17:39:50 -07005#include <net/switchdev.h>
Vlad Yasevich243a2e62013-02-13 12:00:09 +00006
7#include "br_private.h"
8
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +02009static inline int br_vlan_cmp(struct rhashtable_compare_arg *arg,
10 const void *ptr)
Vlad Yasevich552406c2013-02-13 12:00:15 +000011{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020012 const struct net_bridge_vlan *vle = ptr;
13 u16 vid = *(u16 *)arg->key;
14
15 return vle->vid != vid;
16}
17
18static const struct rhashtable_params br_vlan_rht_params = {
19 .head_offset = offsetof(struct net_bridge_vlan, vnode),
20 .key_offset = offsetof(struct net_bridge_vlan, vid),
21 .key_len = sizeof(u16),
22 .max_size = VLAN_N_VID,
23 .obj_cmpfn = br_vlan_cmp,
24 .automatic_shrinking = true,
25};
26
27static struct net_bridge_vlan *br_vlan_lookup(struct rhashtable *tbl, u16 vid)
28{
29 return rhashtable_lookup_fast(tbl, &vid, br_vlan_rht_params);
30}
31
32static void __vlan_add_pvid(u16 *pvid, u16 vid)
33{
34 if (*pvid == vid)
Vlad Yasevich552406c2013-02-13 12:00:15 +000035 return;
36
37 smp_wmb();
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020038 *pvid = vid;
Vlad Yasevich552406c2013-02-13 12:00:15 +000039}
40
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020041static void __vlan_delete_pvid(u16 *pvid, u16 vid)
Vlad Yasevich552406c2013-02-13 12:00:15 +000042{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020043 if (*pvid != vid)
Vlad Yasevich552406c2013-02-13 12:00:15 +000044 return;
45
46 smp_wmb();
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020047 *pvid = 0;
Vlad Yasevich552406c2013-02-13 12:00:15 +000048}
49
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020050static void __vlan_add_flags(struct net_bridge_vlan *v, u16 flags)
Vlad Yasevich35e03f32013-02-13 12:00:20 +000051{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020052 if (flags & BRIDGE_VLAN_INFO_PVID) {
53 if (br_vlan_is_master(v))
54 __vlan_add_pvid(&v->br->pvid, v->vid);
55 else
56 __vlan_add_pvid(&v->port->pvid, v->vid);
57 } else {
58 if (br_vlan_is_master(v))
59 __vlan_delete_pvid(&v->br->pvid, v->vid);
60 else
61 __vlan_delete_pvid(&v->port->pvid, v->vid);
62 }
Vlad Yasevich35e03f32013-02-13 12:00:20 +000063
64 if (flags & BRIDGE_VLAN_INFO_UNTAGGED)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020065 v->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
Vlad Yasevich635126b2014-09-12 16:26:17 -040066 else
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020067 v->flags &= ~BRIDGE_VLAN_INFO_UNTAGGED;
Vlad Yasevich35e03f32013-02-13 12:00:20 +000068}
69
Scott Feldman7f109532015-06-12 17:39:50 -070070static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br,
71 u16 vid, u16 flags)
72{
73 const struct net_device_ops *ops = dev->netdev_ops;
74 int err;
75
76 /* If driver uses VLAN ndo ops, use 8021q to install vid
77 * on device, otherwise try switchdev ops to install vid.
78 */
79
80 if (ops->ndo_vlan_rx_add_vid) {
81 err = vlan_vid_add(dev, br->vlan_proto, vid);
82 } else {
Vivien Didelotab069002015-09-29 12:07:17 -040083 struct switchdev_obj_vlan v = {
84 .flags = flags,
85 .vid_begin = vid,
86 .vid_end = vid,
Scott Feldman7f109532015-06-12 17:39:50 -070087 };
88
Vivien Didelotab069002015-09-29 12:07:17 -040089 err = switchdev_port_obj_add(dev, SWITCHDEV_OBJ_PORT_VLAN, &v);
Scott Feldman7f109532015-06-12 17:39:50 -070090 if (err == -EOPNOTSUPP)
91 err = 0;
92 }
93
94 return err;
95}
96
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020097static void __vlan_add_list(struct net_bridge_vlan *v)
Vlad Yasevich243a2e62013-02-13 12:00:09 +000098{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +020099 struct list_head *headp, *hpos;
100 struct net_bridge_vlan *vent;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000101
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200102 headp = br_vlan_is_master(v) ? &v->br->vlgrp->vlan_list :
103 &v->port->vlgrp->vlan_list;
104 list_for_each_prev(hpos, headp) {
105 vent = list_entry(hpos, struct net_bridge_vlan, vlist);
106 if (v->vid < vent->vid)
107 continue;
108 else
109 break;
Vlad Yasevich552406c2013-02-13 12:00:15 +0000110 }
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200111 list_add(&v->vlist, hpos);
112}
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000113
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200114static void __vlan_del_list(struct net_bridge_vlan *v)
115{
116 list_del(&v->vlist);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000117}
118
Vivien Didelotbf361ad2015-09-05 21:27:57 -0400119static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br,
120 u16 vid)
Scott Feldman7f109532015-06-12 17:39:50 -0700121{
122 const struct net_device_ops *ops = dev->netdev_ops;
Vivien Didelotbf361ad2015-09-05 21:27:57 -0400123 int err = 0;
Scott Feldman7f109532015-06-12 17:39:50 -0700124
125 /* If driver uses VLAN ndo ops, use 8021q to delete vid
126 * on device, otherwise try switchdev ops to delete vid.
127 */
128
129 if (ops->ndo_vlan_rx_kill_vid) {
130 vlan_vid_del(dev, br->vlan_proto, vid);
131 } else {
Vivien Didelotab069002015-09-29 12:07:17 -0400132 struct switchdev_obj_vlan v = {
133 .vid_begin = vid,
134 .vid_end = vid,
Scott Feldman7f109532015-06-12 17:39:50 -0700135 };
136
Vivien Didelotab069002015-09-29 12:07:17 -0400137 err = switchdev_port_obj_del(dev, SWITCHDEV_OBJ_PORT_VLAN, &v);
Vivien Didelotbf361ad2015-09-05 21:27:57 -0400138 if (err == -EOPNOTSUPP)
139 err = 0;
Scott Feldman7f109532015-06-12 17:39:50 -0700140 }
Vivien Didelotbf361ad2015-09-05 21:27:57 -0400141
142 return err;
Scott Feldman7f109532015-06-12 17:39:50 -0700143}
144
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200145/* This is the shared VLAN add function which works for both ports and bridge
146 * devices. There are four possible calls to this function in terms of the
147 * vlan entry type:
148 * 1. vlan is being added on a port (no master flags, global entry exists)
149 * 2. vlan is being added on a bridge (both master and brvlan flags)
150 * 3. vlan is being added on a port, but a global entry didn't exist which
151 * is being created right now (master flag set, brvlan flag unset), the
152 * global entry is used for global per-vlan features, but not for filtering
153 * 4. same as 3 but with both master and brvlan flags set so the entry
154 * will be used for filtering in both the port and the bridge
155 */
156static int __vlan_add(struct net_bridge_vlan *v, u16 flags)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000157{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200158 struct net_bridge_vlan *masterv = NULL;
159 struct net_bridge_port *p = NULL;
160 struct rhashtable *tbl;
161 struct net_device *dev;
162 struct net_bridge *br;
163 int err;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000164
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200165 if (br_vlan_is_master(v)) {
166 br = v->br;
167 dev = br->dev;
168 tbl = &br->vlgrp->vlan_hash;
169 } else {
170 p = v->port;
171 br = p->br;
172 dev = p->dev;
173 tbl = &p->vlgrp->vlan_hash;
174 }
Vlad Yasevich552406c2013-02-13 12:00:15 +0000175
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200176 if (p) {
177 u16 master_flags = flags;
Vivien Didelotbf361ad2015-09-05 21:27:57 -0400178
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200179 /* Add VLAN to the device filter if it is supported.
180 * This ensures tagged traffic enters the bridge when
181 * promiscuous mode is disabled by br_manage_promisc().
182 */
183 err = __vlan_vid_add(dev, br, v->vid, flags);
Vivien Didelotbf361ad2015-09-05 21:27:57 -0400184 if (err)
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200185 goto out;
186
187 /* need to work on the master vlan too */
188 if (flags & BRIDGE_VLAN_INFO_MASTER) {
189 master_flags |= BRIDGE_VLAN_INFO_BRENTRY;
190 err = br_vlan_add(br, v->vid, master_flags);
191 if (err)
192 goto out_filt;
193 }
194
195 masterv = br_vlan_find(br->vlgrp, v->vid);
196 if (!masterv) {
197 /* missing global ctx, create it now */
198 err = br_vlan_add(br, v->vid, master_flags);
199 if (err)
200 goto out_filt;
201 masterv = br_vlan_find(br->vlgrp, v->vid);
202 WARN_ON(!masterv);
203 }
204 atomic_inc(&masterv->refcnt);
205 v->brvlan = masterv;
Toshiaki Makita8580e212014-06-10 20:59:23 +0900206 }
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000207
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200208 /* Add the dev mac only if it's a usable vlan */
209 if (br_vlan_should_use(v)) {
210 err = br_fdb_insert(br, p, dev->dev_addr, v->vid);
211 if (err) {
212 br_err(br, "failed insert local address into bridge forwarding table\n");
213 goto out_filt;
214 }
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000215 }
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200216
217 err = rhashtable_lookup_insert_fast(tbl, &v->vnode, br_vlan_rht_params);
218 if (err)
219 goto out_fdb_insert;
220
221 __vlan_add_list(v);
222 __vlan_add_flags(v, flags);
223 if (br_vlan_is_master(v)) {
224 if (br_vlan_is_brentry(v))
225 br->vlgrp->num_vlans++;
226 } else {
227 p->vlgrp->num_vlans++;
228 }
229out:
230 return err;
231
232out_fdb_insert:
233 br_fdb_find_delete_local(br, p, br->dev->dev_addr, v->vid);
234
235out_filt:
236 if (p) {
237 __vlan_vid_del(dev, br, v->vid);
238 if (masterv) {
239 atomic_dec(&masterv->refcnt);
240 v->brvlan = NULL;
241 }
242 }
243
244 goto out;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000245}
246
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200247static int __vlan_del(struct net_bridge_vlan *v)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000248{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200249 struct net_bridge_vlan *masterv = v;
250 struct net_bridge_port *p = NULL;
251 struct net_bridge *br;
252 int err = 0;
253 struct rhashtable *tbl;
254 u16 *pvid;
255
256 if (br_vlan_is_master(v)) {
257 br = v->br;
258 tbl = &v->br->vlgrp->vlan_hash;
259 pvid = &v->br->pvid;
260 } else {
261 p = v->port;
262 br = p->br;
263 tbl = &p->vlgrp->vlan_hash;
264 masterv = v->brvlan;
265 pvid = &p->pvid;
266 }
267
268 __vlan_delete_pvid(pvid, v->vid);
269 if (p) {
270 err = __vlan_vid_del(p->dev, p->br, v->vid);
271 if (err)
272 goto out;
273 }
274
275 if (br_vlan_is_master(v)) {
276 if (br_vlan_is_brentry(v)) {
277 v->flags &= ~BRIDGE_VLAN_INFO_BRENTRY;
278 br->vlgrp->num_vlans--;
279 }
280 } else {
281 p->vlgrp->num_vlans--;
282 }
283
284 if (masterv != v) {
285 rhashtable_remove_fast(tbl, &v->vnode, br_vlan_rht_params);
286 __vlan_del_list(v);
287 kfree_rcu(v, rcu);
288 }
289
290 if (atomic_dec_and_test(&masterv->refcnt)) {
291 rhashtable_remove_fast(&masterv->br->vlgrp->vlan_hash,
292 &masterv->vnode, br_vlan_rht_params);
293 __vlan_del_list(masterv);
294 kfree_rcu(masterv, rcu);
295 }
296out:
297 return err;
298}
299
300static void __vlan_flush(struct net_bridge_vlan_group *vlgrp, u16 *pvid)
301{
302 struct net_bridge_vlan *vlan, *tmp;
303
304 __vlan_delete_pvid(pvid, *pvid);
305 list_for_each_entry_safe(vlan, tmp, &vlgrp->vlan_list, vlist)
306 __vlan_del(vlan);
307 rhashtable_destroy(&vlgrp->vlan_hash);
308 kfree(vlgrp);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000309}
310
Vlad Yasevich78851982013-02-13 12:00:14 +0000311struct sk_buff *br_handle_vlan(struct net_bridge *br,
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200312 struct net_bridge_vlan_group *vg,
Vlad Yasevich78851982013-02-13 12:00:14 +0000313 struct sk_buff *skb)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000314{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200315 struct net_bridge_vlan *v;
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000316 u16 vid;
317
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400318 /* If this packet was not filtered at input, let it pass */
319 if (!BR_INPUT_SKB_CB(skb)->vlan_filtered)
Vlad Yasevich78851982013-02-13 12:00:14 +0000320 goto out;
321
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200322 /* At this point, we know that the frame was filtered and contains
323 * a valid vlan id. If the vlan id has untagged flag set,
324 * send untagged; otherwise, send tagged.
325 */
326 br_vlan_get_tag(skb, &vid);
327 v = br_vlan_find(vg, vid);
328 /* Vlan entry must be configured at this point. The
Vlad Yasevichfc92f742014-03-27 21:51:18 -0400329 * only exception is the bridge is set in promisc mode and the
330 * packet is destined for the bridge device. In this case
331 * pass the packet as is.
332 */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200333 if (!v || !br_vlan_should_use(v)) {
Vlad Yasevichfc92f742014-03-27 21:51:18 -0400334 if ((br->dev->flags & IFF_PROMISC) && skb->dev == br->dev) {
335 goto out;
336 } else {
337 kfree_skb(skb);
338 return NULL;
339 }
340 }
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200341 if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED)
Toshiaki Makita99b192d2014-03-27 21:46:56 +0900342 skb->vlan_tci = 0;
Vlad Yasevich78851982013-02-13 12:00:14 +0000343
344out:
345 return skb;
346}
347
348/* Called under RCU */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200349static bool __allowed_ingress(struct rhashtable *tbl, u16 pvid, __be16 proto,
350 struct sk_buff *skb, u16 *vid)
Vlad Yasevich78851982013-02-13 12:00:14 +0000351{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200352 const struct net_bridge_vlan *v;
Toshiaki Makita8580e212014-06-10 20:59:23 +0900353 bool tagged;
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000354
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400355 BR_INPUT_SKB_CB(skb)->vlan_filtered = true;
Toshiaki Makita12464bb2014-03-27 21:46:55 +0900356 /* If vlan tx offload is disabled on bridge device and frame was
357 * sent from vlan device on the bridge device, it does not have
358 * HW accelerated vlan tag.
359 */
Jiri Pirkodf8a39d2015-01-13 17:13:44 +0100360 if (unlikely(!skb_vlan_tag_present(skb) &&
Toshiaki Makita8580e212014-06-10 20:59:23 +0900361 skb->protocol == proto)) {
Vlad Yasevich0d5501c2014-08-08 14:42:13 -0400362 skb = skb_vlan_untag(skb);
Toshiaki Makita12464bb2014-03-27 21:46:55 +0900363 if (unlikely(!skb))
364 return false;
365 }
366
Toshiaki Makita8580e212014-06-10 20:59:23 +0900367 if (!br_vlan_get_tag(skb, vid)) {
368 /* Tagged frame */
369 if (skb->vlan_proto != proto) {
370 /* Protocol-mismatch, empty out vlan_tci for new tag */
371 skb_push(skb, ETH_HLEN);
Jiri Pirko62749e22014-11-19 14:04:58 +0100372 skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
Jiri Pirkodf8a39d2015-01-13 17:13:44 +0100373 skb_vlan_tag_get(skb));
Toshiaki Makita8580e212014-06-10 20:59:23 +0900374 if (unlikely(!skb))
375 return false;
376
377 skb_pull(skb, ETH_HLEN);
378 skb_reset_mac_len(skb);
379 *vid = 0;
380 tagged = false;
381 } else {
382 tagged = true;
383 }
384 } else {
385 /* Untagged frame */
386 tagged = false;
387 }
388
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900389 if (!*vid) {
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900390 /* Frame had a tag with VID 0 or did not have a tag.
391 * See if pvid is set on this port. That tells us which
392 * vlan untagged or priority-tagged traffic belongs to.
Vlad Yasevich78851982013-02-13 12:00:14 +0000393 */
Vlad Yasevich3df6bf42014-10-03 11:29:17 -0400394 if (!pvid)
Toshiaki Makitaeb707612014-04-09 17:00:30 +0900395 goto drop;
Vlad Yasevich78851982013-02-13 12:00:14 +0000396
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900397 /* PVID is set on this port. Any untagged or priority-tagged
398 * ingress frame is considered to belong to this vlan.
Vlad Yasevich78851982013-02-13 12:00:14 +0000399 */
Toshiaki Makitadfb5fa32013-10-16 17:07:16 +0900400 *vid = pvid;
Toshiaki Makita8580e212014-06-10 20:59:23 +0900401 if (likely(!tagged))
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900402 /* Untagged Frame. */
Toshiaki Makita8580e212014-06-10 20:59:23 +0900403 __vlan_hwaccel_put_tag(skb, proto, pvid);
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900404 else
405 /* Priority-tagged Frame.
406 * At this point, We know that skb->vlan_tci had
407 * VLAN_TAG_PRESENT bit and its VID field was 0x000.
408 * We update only VID field and preserve PCP field.
409 */
410 skb->vlan_tci |= pvid;
411
Vlad Yasevich78851982013-02-13 12:00:14 +0000412 return true;
413 }
414
415 /* Frame had a valid vlan tag. See if vlan is allowed */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200416 v = br_vlan_lookup(tbl, *vid);
417 if (v && br_vlan_should_use(v))
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000418 return true;
Toshiaki Makitaeb707612014-04-09 17:00:30 +0900419drop:
420 kfree_skb(skb);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000421 return false;
422}
423
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200424bool br_allowed_ingress(struct net_bridge *br, struct sk_buff *skb, u16 *vid)
425{
426 /* If VLAN filtering is disabled on the bridge, all packets are
427 * permitted.
428 */
429 if (!br->vlan_enabled) {
430 BR_INPUT_SKB_CB(skb)->vlan_filtered = false;
431 return true;
432 }
433
434 return __allowed_ingress(&br->vlgrp->vlan_hash, br->pvid,
435 br->vlan_proto, skb, vid);
436}
437
438bool nbp_allowed_ingress(struct net_bridge_port *p, struct sk_buff *skb,
439 u16 *vid)
440{
441 struct net_bridge *br = p->br;
442
443 /* If VLAN filtering is disabled on the bridge, all packets are
444 * permitted.
445 */
446 if (!br->vlan_enabled) {
447 BR_INPUT_SKB_CB(skb)->vlan_filtered = false;
448 return true;
449 }
450
451 return __allowed_ingress(&p->vlgrp->vlan_hash, p->pvid, br->vlan_proto,
452 skb, vid);
453}
454
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000455/* Called under RCU. */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200456bool br_allowed_egress(struct net_bridge_vlan_group *vg,
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000457 const struct sk_buff *skb)
458{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200459 const struct net_bridge_vlan *v;
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000460 u16 vid;
461
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400462 /* If this packet was not filtered at input, let it pass */
463 if (!BR_INPUT_SKB_CB(skb)->vlan_filtered)
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000464 return true;
465
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000466 br_vlan_get_tag(skb, &vid);
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200467 v = br_vlan_find(vg, vid);
468 if (v && br_vlan_should_use(v))
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000469 return true;
470
471 return false;
472}
473
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900474/* Called under RCU */
475bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid)
476{
477 struct net_bridge *br = p->br;
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900478
Vlad Yasevich20adfa12014-09-12 16:26:16 -0400479 /* If filtering was disabled at input, let it pass. */
Vlad Yasevichc095f242014-09-15 15:24:26 -0400480 if (!br->vlan_enabled)
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900481 return true;
482
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200483 if (!p->vlgrp->num_vlans)
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900484 return false;
485
Toshiaki Makita8580e212014-06-10 20:59:23 +0900486 if (!br_vlan_get_tag(skb, vid) && skb->vlan_proto != br->vlan_proto)
487 *vid = 0;
488
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900489 if (!*vid) {
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200490 *vid = nbp_get_pvid(p);
Vlad Yasevich3df6bf42014-10-03 11:29:17 -0400491 if (!*vid)
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900492 return false;
493
494 return true;
495 }
496
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200497 if (br_vlan_find(p->vlgrp, *vid))
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900498 return true;
499
500 return false;
501}
502
Toshiaki Makita8adff412013-10-16 17:07:13 +0900503/* Must be protected by RTNL.
504 * Must be called with vid in range from 1 to 4094 inclusive.
505 */
Vlad Yasevich552406c2013-02-13 12:00:15 +0000506int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000507{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200508 struct net_bridge_vlan *vlan;
509 int ret;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000510
511 ASSERT_RTNL();
512
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200513 vlan = br_vlan_find(br->vlgrp, vid);
514 if (vlan) {
515 if (!br_vlan_is_brentry(vlan)) {
516 /* Trying to change flags of non-existent bridge vlan */
517 if (!(flags & BRIDGE_VLAN_INFO_BRENTRY))
518 return -EINVAL;
519 /* It was only kept for port vlans, now make it real */
520 ret = br_fdb_insert(br, NULL, br->dev->dev_addr,
521 vlan->vid);
522 if (ret) {
523 br_err(br, "failed insert local address into bridge forwarding table\n");
524 return ret;
525 }
526 atomic_inc(&vlan->refcnt);
527 vlan->flags |= BRIDGE_VLAN_INFO_BRENTRY;
528 br->vlgrp->num_vlans++;
529 }
530 __vlan_add_flags(vlan, flags);
531 return 0;
532 }
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000533
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200534 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
535 if (!vlan)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000536 return -ENOMEM;
537
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200538 vlan->vid = vid;
539 vlan->flags = flags | BRIDGE_VLAN_INFO_MASTER;
540 vlan->flags &= ~BRIDGE_VLAN_INFO_PVID;
541 vlan->br = br;
542 if (flags & BRIDGE_VLAN_INFO_BRENTRY)
543 atomic_set(&vlan->refcnt, 1);
544 ret = __vlan_add(vlan, flags);
545 if (ret)
546 kfree(vlan);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000547
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200548 return ret;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000549}
550
Toshiaki Makita8adff412013-10-16 17:07:13 +0900551/* Must be protected by RTNL.
552 * Must be called with vid in range from 1 to 4094 inclusive.
553 */
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000554int br_vlan_delete(struct net_bridge *br, u16 vid)
555{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200556 struct net_bridge_vlan *v;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000557
558 ASSERT_RTNL();
559
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200560 v = br_vlan_find(br->vlgrp, vid);
561 if (!v || !br_vlan_is_brentry(v))
562 return -ENOENT;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000563
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900564 br_fdb_find_delete_local(br, NULL, br->dev->dev_addr, vid);
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000565
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200566 return __vlan_del(v);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000567}
568
569void br_vlan_flush(struct net_bridge *br)
570{
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000571 ASSERT_RTNL();
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000572
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200573 __vlan_flush(br_vlan_group(br), &br->pvid);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000574}
575
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200576struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid)
Toshiaki Makita2b292fb2014-02-07 16:48:22 +0900577{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200578 if (!vg)
579 return NULL;
Toshiaki Makita2b292fb2014-02-07 16:48:22 +0900580
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200581 return br_vlan_lookup(&vg->vlan_hash, vid);
Toshiaki Makita2b292fb2014-02-07 16:48:22 +0900582}
583
Toshiaki Makita204177f2014-06-10 20:59:25 +0900584/* Must be protected by RTNL. */
585static void recalculate_group_addr(struct net_bridge *br)
586{
587 if (br->group_addr_set)
588 return;
589
590 spin_lock_bh(&br->lock);
591 if (!br->vlan_enabled || br->vlan_proto == htons(ETH_P_8021Q)) {
592 /* Bridge Group Address */
593 br->group_addr[5] = 0x00;
594 } else { /* vlan_enabled && ETH_P_8021AD */
595 /* Provider Bridge Group Address */
596 br->group_addr[5] = 0x08;
597 }
598 spin_unlock_bh(&br->lock);
599}
600
601/* Must be protected by RTNL. */
602void br_recalculate_fwd_mask(struct net_bridge *br)
603{
604 if (!br->vlan_enabled || br->vlan_proto == htons(ETH_P_8021Q))
605 br->group_fwd_mask_required = BR_GROUPFWD_DEFAULT;
606 else /* vlan_enabled && ETH_P_8021AD */
607 br->group_fwd_mask_required = BR_GROUPFWD_8021AD &
608 ~(1u << br->group_addr[5]);
609}
610
Nikolay Aleksandrova7854032015-08-07 19:40:45 +0300611int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000612{
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000613 if (br->vlan_enabled == val)
Nikolay Aleksandrova7854032015-08-07 19:40:45 +0300614 return 0;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000615
616 br->vlan_enabled = val;
Vlad Yasevich2796d0c2014-05-16 09:59:20 -0400617 br_manage_promisc(br);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900618 recalculate_group_addr(br);
619 br_recalculate_fwd_mask(br);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000620
Nikolay Aleksandrova7854032015-08-07 19:40:45 +0300621 return 0;
622}
623
624int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val)
625{
626 if (!rtnl_trylock())
627 return restart_syscall();
628
629 __br_vlan_filter_toggle(br, val);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000630 rtnl_unlock();
Nikolay Aleksandrova7854032015-08-07 19:40:45 +0300631
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000632 return 0;
633}
634
Toshiaki Makitad2d427b2015-08-27 15:32:26 +0900635int __br_vlan_set_proto(struct net_bridge *br, __be16 proto)
Toshiaki Makita204177f2014-06-10 20:59:25 +0900636{
637 int err = 0;
638 struct net_bridge_port *p;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200639 struct net_bridge_vlan *vlan;
Toshiaki Makitad2d427b2015-08-27 15:32:26 +0900640 __be16 oldproto;
Toshiaki Makita204177f2014-06-10 20:59:25 +0900641
Toshiaki Makita204177f2014-06-10 20:59:25 +0900642 if (br->vlan_proto == proto)
Toshiaki Makitad2d427b2015-08-27 15:32:26 +0900643 return 0;
Toshiaki Makita204177f2014-06-10 20:59:25 +0900644
645 /* Add VLANs for the new proto to the device filter. */
646 list_for_each_entry(p, &br->port_list, list) {
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200647 list_for_each_entry(vlan, &p->vlgrp->vlan_list, vlist) {
648 err = vlan_vid_add(p->dev, proto, vlan->vid);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900649 if (err)
650 goto err_filt;
651 }
652 }
653
654 oldproto = br->vlan_proto;
655 br->vlan_proto = proto;
656
657 recalculate_group_addr(br);
658 br_recalculate_fwd_mask(br);
659
660 /* Delete VLANs for the old proto from the device filter. */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200661 list_for_each_entry(p, &br->port_list, list)
662 list_for_each_entry(vlan, &p->vlgrp->vlan_list, vlist)
663 vlan_vid_del(p->dev, oldproto, vlan->vid);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900664
Toshiaki Makitad2d427b2015-08-27 15:32:26 +0900665 return 0;
Toshiaki Makita204177f2014-06-10 20:59:25 +0900666
667err_filt:
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200668 list_for_each_entry_continue_reverse(vlan, &p->vlgrp->vlan_list, vlist)
669 vlan_vid_del(p->dev, proto, vlan->vid);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900670
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200671 list_for_each_entry_continue_reverse(p, &br->port_list, list)
672 list_for_each_entry(vlan, &p->vlgrp->vlan_list, vlist)
673 vlan_vid_del(p->dev, proto, vlan->vid);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900674
Toshiaki Makitad2d427b2015-08-27 15:32:26 +0900675 return err;
676}
677
678int br_vlan_set_proto(struct net_bridge *br, unsigned long val)
679{
680 int err;
681
682 if (val != ETH_P_8021Q && val != ETH_P_8021AD)
683 return -EPROTONOSUPPORT;
684
685 if (!rtnl_trylock())
686 return restart_syscall();
687
688 err = __br_vlan_set_proto(br, htons(val));
689 rtnl_unlock();
690
691 return err;
Toshiaki Makita204177f2014-06-10 20:59:25 +0900692}
693
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200694static bool vlan_default_pvid(struct net_bridge_vlan_group *vg, u16 pvid,
695 u16 vid)
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400696{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200697 struct net_bridge_vlan *v;
698
699 if (vid != pvid)
700 return false;
701
702 v = br_vlan_lookup(&vg->vlan_hash, vid);
703 if (v && br_vlan_should_use(v) &&
704 (v->flags & BRIDGE_VLAN_INFO_UNTAGGED))
705 return true;
706
707 return false;
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400708}
709
710static void br_vlan_disable_default_pvid(struct net_bridge *br)
711{
712 struct net_bridge_port *p;
713 u16 pvid = br->default_pvid;
714
715 /* Disable default_pvid on all ports where it is still
716 * configured.
717 */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200718 if (vlan_default_pvid(br->vlgrp, br->pvid, pvid))
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400719 br_vlan_delete(br, pvid);
720
721 list_for_each_entry(p, &br->port_list, list) {
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200722 if (vlan_default_pvid(p->vlgrp, p->pvid, pvid))
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400723 nbp_vlan_delete(p, pvid);
724 }
725
726 br->default_pvid = 0;
727}
728
729static int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid)
730{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200731 const struct net_bridge_vlan *pvent;
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400732 struct net_bridge_port *p;
733 u16 old_pvid;
734 int err = 0;
735 unsigned long *changed;
736
737 changed = kcalloc(BITS_TO_LONGS(BR_MAX_PORTS), sizeof(unsigned long),
738 GFP_KERNEL);
739 if (!changed)
740 return -ENOMEM;
741
742 old_pvid = br->default_pvid;
743
744 /* Update default_pvid config only if we do not conflict with
745 * user configuration.
746 */
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200747 pvent = br_vlan_find(br->vlgrp, pvid);
748 if ((!old_pvid || vlan_default_pvid(br->vlgrp, br->pvid, old_pvid)) &&
749 (!pvent || !br_vlan_should_use(pvent))) {
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400750 err = br_vlan_add(br, pvid,
751 BRIDGE_VLAN_INFO_PVID |
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200752 BRIDGE_VLAN_INFO_UNTAGGED |
753 BRIDGE_VLAN_INFO_BRENTRY);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400754 if (err)
755 goto out;
756 br_vlan_delete(br, old_pvid);
757 set_bit(0, changed);
758 }
759
760 list_for_each_entry(p, &br->port_list, list) {
761 /* Update default_pvid config only if we do not conflict with
762 * user configuration.
763 */
764 if ((old_pvid &&
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200765 !vlan_default_pvid(p->vlgrp, p->pvid, old_pvid)) ||
766 br_vlan_find(p->vlgrp, pvid))
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400767 continue;
768
769 err = nbp_vlan_add(p, pvid,
770 BRIDGE_VLAN_INFO_PVID |
771 BRIDGE_VLAN_INFO_UNTAGGED);
772 if (err)
773 goto err_port;
774 nbp_vlan_delete(p, old_pvid);
775 set_bit(p->port_no, changed);
776 }
777
778 br->default_pvid = pvid;
779
780out:
781 kfree(changed);
782 return err;
783
784err_port:
785 list_for_each_entry_continue_reverse(p, &br->port_list, list) {
786 if (!test_bit(p->port_no, changed))
787 continue;
788
789 if (old_pvid)
790 nbp_vlan_add(p, old_pvid,
791 BRIDGE_VLAN_INFO_PVID |
792 BRIDGE_VLAN_INFO_UNTAGGED);
793 nbp_vlan_delete(p, pvid);
794 }
795
796 if (test_bit(0, changed)) {
797 if (old_pvid)
798 br_vlan_add(br, old_pvid,
799 BRIDGE_VLAN_INFO_PVID |
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200800 BRIDGE_VLAN_INFO_UNTAGGED |
801 BRIDGE_VLAN_INFO_BRENTRY);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400802 br_vlan_delete(br, pvid);
803 }
804 goto out;
805}
806
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400807int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val)
808{
809 u16 pvid = val;
810 int err = 0;
811
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400812 if (val >= VLAN_VID_MASK)
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400813 return -EINVAL;
814
815 if (!rtnl_trylock())
816 return restart_syscall();
817
818 if (pvid == br->default_pvid)
819 goto unlock;
820
821 /* Only allow default pvid change when filtering is disabled */
822 if (br->vlan_enabled) {
823 pr_info_once("Please disable vlan filtering to change default_pvid\n");
824 err = -EPERM;
825 goto unlock;
826 }
827
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400828 if (!pvid)
829 br_vlan_disable_default_pvid(br);
830 else
831 err = __br_vlan_set_default_pvid(br, pvid);
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400832
833unlock:
834 rtnl_unlock();
835 return err;
836}
837
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400838int br_vlan_init(struct net_bridge *br)
Toshiaki Makita8580e212014-06-10 20:59:23 +0900839{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200840 int ret = -ENOMEM;
841
842 br->vlgrp = kzalloc(sizeof(struct net_bridge_vlan_group), GFP_KERNEL);
843 if (!br->vlgrp)
844 goto out;
845 ret = rhashtable_init(&br->vlgrp->vlan_hash, &br_vlan_rht_params);
846 if (ret)
847 goto err_rhtbl;
848 INIT_LIST_HEAD(&br->vlgrp->vlan_list);
Toshiaki Makita8580e212014-06-10 20:59:23 +0900849 br->vlan_proto = htons(ETH_P_8021Q);
Vlad Yasevich96a20d92014-10-03 11:29:16 -0400850 br->default_pvid = 1;
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200851 ret = br_vlan_add(br, 1,
852 BRIDGE_VLAN_INFO_PVID | BRIDGE_VLAN_INFO_UNTAGGED |
853 BRIDGE_VLAN_INFO_BRENTRY);
854 if (ret)
855 goto err_vlan_add;
856
857out:
858 return ret;
859
860err_vlan_add:
861 rhashtable_destroy(&br->vlgrp->vlan_hash);
862err_rhtbl:
863 kfree(br->vlgrp);
864
865 goto out;
866}
867
868int nbp_vlan_init(struct net_bridge_port *p)
869{
870 int ret = -ENOMEM;
871
872 p->vlgrp = kzalloc(sizeof(struct net_bridge_vlan_group), GFP_KERNEL);
873 if (!p->vlgrp)
874 goto out;
875
876 ret = rhashtable_init(&p->vlgrp->vlan_hash, &br_vlan_rht_params);
877 if (ret)
878 goto err_rhtbl;
879 INIT_LIST_HEAD(&p->vlgrp->vlan_list);
880 if (p->br->default_pvid) {
881 ret = nbp_vlan_add(p, p->br->default_pvid,
882 BRIDGE_VLAN_INFO_PVID |
883 BRIDGE_VLAN_INFO_UNTAGGED);
884 if (ret)
885 goto err_vlan_add;
886 }
887out:
888 return ret;
889
890err_vlan_add:
891 rhashtable_destroy(&p->vlgrp->vlan_hash);
892err_rhtbl:
893 kfree(p->vlgrp);
894
895 goto out;
Toshiaki Makita8580e212014-06-10 20:59:23 +0900896}
897
Toshiaki Makita8adff412013-10-16 17:07:13 +0900898/* Must be protected by RTNL.
899 * Must be called with vid in range from 1 to 4094 inclusive.
900 */
Vlad Yasevich552406c2013-02-13 12:00:15 +0000901int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000902{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200903 struct net_bridge_vlan *vlan;
904 int ret;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000905
906 ASSERT_RTNL();
907
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200908 vlan = br_vlan_find(port->vlgrp, vid);
909 if (vlan) {
910 __vlan_add_flags(vlan, flags);
911 return 0;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000912 }
913
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200914 vlan = kzalloc(sizeof(*vlan), GFP_KERNEL);
915 if (!vlan)
916 return -ENOMEM;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000917
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200918 vlan->vid = vid;
919 vlan->port = port;
920 ret = __vlan_add(vlan, flags);
921 if (ret)
922 kfree(vlan);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000923
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200924 return ret;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000925}
926
Toshiaki Makita8adff412013-10-16 17:07:13 +0900927/* Must be protected by RTNL.
928 * Must be called with vid in range from 1 to 4094 inclusive.
929 */
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000930int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
931{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200932 struct net_bridge_vlan *v;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000933
934 ASSERT_RTNL();
935
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200936 v = br_vlan_find(port->vlgrp, vid);
937 if (!v)
938 return -ENOENT;
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900939 br_fdb_find_delete_local(port->br, port, port->dev->dev_addr, vid);
Nikolay Aleksandrov1ea2d022015-06-23 05:28:16 -0700940 br_fdb_delete_by_port(port->br, port, vid, 0);
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000941
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200942 return __vlan_del(v);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000943}
944
945void nbp_vlan_flush(struct net_bridge_port *port)
946{
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200947 struct net_bridge_vlan *vlan;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000948
949 ASSERT_RTNL();
950
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200951 list_for_each_entry(vlan, &port->vlgrp->vlan_list, vlist)
952 vlan_vid_del(port->dev, port->br->vlan_proto, vlan->vid);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000953
Nikolay Aleksandrov2594e9062015-09-25 19:00:11 +0200954 __vlan_flush(nbp_vlan_group(port), &port->pvid);
Vlad Yasevich5be5a2d2014-10-03 11:29:18 -0400955}