blob: 2b2774fe0703871e7e4e65ee1d5816375c398e11 [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>
5
6#include "br_private.h"
7
Vlad Yasevich552406c2013-02-13 12:00:15 +00008static void __vlan_add_pvid(struct net_port_vlans *v, u16 vid)
9{
10 if (v->pvid == vid)
11 return;
12
13 smp_wmb();
14 v->pvid = vid;
15}
16
17static void __vlan_delete_pvid(struct net_port_vlans *v, u16 vid)
18{
19 if (v->pvid != vid)
20 return;
21
22 smp_wmb();
23 v->pvid = 0;
24}
25
Vlad Yasevich35e03f32013-02-13 12:00:20 +000026static void __vlan_add_flags(struct net_port_vlans *v, u16 vid, u16 flags)
27{
28 if (flags & BRIDGE_VLAN_INFO_PVID)
29 __vlan_add_pvid(v, vid);
30
31 if (flags & BRIDGE_VLAN_INFO_UNTAGGED)
32 set_bit(vid, v->untagged_bitmap);
33}
34
Vlad Yasevich552406c2013-02-13 12:00:15 +000035static int __vlan_add(struct net_port_vlans *v, u16 vid, u16 flags)
Vlad Yasevich243a2e62013-02-13 12:00:09 +000036{
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +000037 struct net_bridge_port *p = NULL;
38 struct net_bridge *br;
39 struct net_device *dev;
Vlad Yasevich243a2e62013-02-13 12:00:09 +000040 int err;
41
Vlad Yasevich552406c2013-02-13 12:00:15 +000042 if (test_bit(vid, v->vlan_bitmap)) {
Vlad Yasevich35e03f32013-02-13 12:00:20 +000043 __vlan_add_flags(v, vid, flags);
Vlad Yasevich552406c2013-02-13 12:00:15 +000044 return 0;
45 }
Vlad Yasevich243a2e62013-02-13 12:00:09 +000046
Toshiaki Makita8adff412013-10-16 17:07:13 +090047 if (v->port_idx) {
48 p = v->parent.port;
49 br = p->br;
50 dev = p->dev;
51 } else {
52 br = v->parent.br;
53 dev = br->dev;
54 }
Vlad Yasevich243a2e62013-02-13 12:00:09 +000055
Toshiaki Makita19236832013-11-13 17:26:12 +090056 if (p) {
Toshiaki Makita8adff412013-10-16 17:07:13 +090057 /* Add VLAN to the device filter if it is supported.
58 * Stricly speaking, this is not necessary now, since
59 * devices are made promiscuous by the bridge, but if
60 * that ever changes this code will allow tagged
61 * traffic to enter the bridge.
62 */
Toshiaki Makita8580e212014-06-10 20:59:23 +090063 err = vlan_vid_add(dev, br->vlan_proto, vid);
Toshiaki Makita8adff412013-10-16 17:07:13 +090064 if (err)
65 return err;
66 }
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +000067
Toshiaki Makita8adff412013-10-16 17:07:13 +090068 err = br_fdb_insert(br, p, dev->dev_addr, vid);
69 if (err) {
70 br_err(br, "failed insert local address into bridge "
71 "forwarding table\n");
72 goto out_filt;
Vlad Yasevich243a2e62013-02-13 12:00:09 +000073 }
74
75 set_bit(vid, v->vlan_bitmap);
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +000076 v->num_vlans++;
Vlad Yasevich35e03f32013-02-13 12:00:20 +000077 __vlan_add_flags(v, vid, flags);
Vlad Yasevich552406c2013-02-13 12:00:15 +000078
Vlad Yasevich243a2e62013-02-13 12:00:09 +000079 return 0;
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +000080
81out_filt:
Toshiaki Makita19236832013-11-13 17:26:12 +090082 if (p)
Toshiaki Makita8580e212014-06-10 20:59:23 +090083 vlan_vid_del(dev, br->vlan_proto, vid);
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +000084 return err;
Vlad Yasevich243a2e62013-02-13 12:00:09 +000085}
86
87static int __vlan_del(struct net_port_vlans *v, u16 vid)
88{
89 if (!test_bit(vid, v->vlan_bitmap))
90 return -EINVAL;
91
Vlad Yasevich552406c2013-02-13 12:00:15 +000092 __vlan_delete_pvid(v, vid);
Vlad Yasevich35e03f32013-02-13 12:00:20 +000093 clear_bit(vid, v->untagged_bitmap);
Vlad Yasevich552406c2013-02-13 12:00:15 +000094
Toshiaki Makita8580e212014-06-10 20:59:23 +090095 if (v->port_idx) {
96 struct net_bridge_port *p = v->parent.port;
97 vlan_vid_del(p->dev, p->br->vlan_proto, vid);
98 }
Vlad Yasevich243a2e62013-02-13 12:00:09 +000099
100 clear_bit(vid, v->vlan_bitmap);
Vlad Yasevich6cbdcee2013-02-13 12:00:13 +0000101 v->num_vlans--;
Toshiaki Makitaef40b7e2013-08-20 17:10:18 +0900102 if (bitmap_empty(v->vlan_bitmap, VLAN_N_VID)) {
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000103 if (v->port_idx)
Monam Agarwalcd187212014-03-24 00:41:13 +0530104 RCU_INIT_POINTER(v->parent.port->vlan_info, NULL);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000105 else
Monam Agarwalcd187212014-03-24 00:41:13 +0530106 RCU_INIT_POINTER(v->parent.br->vlan_info, NULL);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000107 kfree_rcu(v, rcu);
108 }
109 return 0;
110}
111
112static void __vlan_flush(struct net_port_vlans *v)
113{
Vlad Yasevich552406c2013-02-13 12:00:15 +0000114 smp_wmb();
115 v->pvid = 0;
Toshiaki Makitaef40b7e2013-08-20 17:10:18 +0900116 bitmap_zero(v->vlan_bitmap, VLAN_N_VID);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000117 if (v->port_idx)
Monam Agarwalcd187212014-03-24 00:41:13 +0530118 RCU_INIT_POINTER(v->parent.port->vlan_info, NULL);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000119 else
Monam Agarwalcd187212014-03-24 00:41:13 +0530120 RCU_INIT_POINTER(v->parent.br->vlan_info, NULL);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000121 kfree_rcu(v, rcu);
122}
123
Vlad Yasevich78851982013-02-13 12:00:14 +0000124struct sk_buff *br_handle_vlan(struct net_bridge *br,
125 const struct net_port_vlans *pv,
126 struct sk_buff *skb)
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000127{
128 u16 vid;
129
Vlad Yasevich78851982013-02-13 12:00:14 +0000130 if (!br->vlan_enabled)
131 goto out;
132
Vlad Yasevichfc92f742014-03-27 21:51:18 -0400133 /* Vlan filter table must be configured at this point. The
134 * only exception is the bridge is set in promisc mode and the
135 * packet is destined for the bridge device. In this case
136 * pass the packet as is.
137 */
138 if (!pv) {
139 if ((br->dev->flags & IFF_PROMISC) && skb->dev == br->dev) {
140 goto out;
141 } else {
142 kfree_skb(skb);
143 return NULL;
144 }
145 }
146
Vlad Yasevich78851982013-02-13 12:00:14 +0000147 /* At this point, we know that the frame was filtered and contains
Vlad Yasevich35e03f32013-02-13 12:00:20 +0000148 * a valid vlan id. If the vlan id is set in the untagged bitmap,
tanxiaojun1a81a2e2013-12-16 21:32:46 +0800149 * send untagged; otherwise, send tagged.
Vlad Yasevich78851982013-02-13 12:00:14 +0000150 */
151 br_vlan_get_tag(skb, &vid);
Vlad Yasevich35e03f32013-02-13 12:00:20 +0000152 if (test_bit(vid, pv->untagged_bitmap))
Toshiaki Makita99b192d2014-03-27 21:46:56 +0900153 skb->vlan_tci = 0;
Vlad Yasevich78851982013-02-13 12:00:14 +0000154
155out:
156 return skb;
157}
158
159/* Called under RCU */
160bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
161 struct sk_buff *skb, u16 *vid)
162{
Toshiaki Makita8580e212014-06-10 20:59:23 +0900163 bool tagged;
164 __be16 proto;
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900165
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000166 /* If VLAN filtering is disabled on the bridge, all packets are
167 * permitted.
168 */
169 if (!br->vlan_enabled)
170 return true;
171
172 /* If there are no vlan in the permitted list, all packets are
173 * rejected.
174 */
175 if (!v)
Toshiaki Makitaeb707612014-04-09 17:00:30 +0900176 goto drop;
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000177
Toshiaki Makita8580e212014-06-10 20:59:23 +0900178 proto = br->vlan_proto;
179
Toshiaki Makita12464bb2014-03-27 21:46:55 +0900180 /* If vlan tx offload is disabled on bridge device and frame was
181 * sent from vlan device on the bridge device, it does not have
182 * HW accelerated vlan tag.
183 */
184 if (unlikely(!vlan_tx_tag_present(skb) &&
Toshiaki Makita8580e212014-06-10 20:59:23 +0900185 skb->protocol == proto)) {
Toshiaki Makita12464bb2014-03-27 21:46:55 +0900186 skb = vlan_untag(skb);
187 if (unlikely(!skb))
188 return false;
189 }
190
Toshiaki Makita8580e212014-06-10 20:59:23 +0900191 if (!br_vlan_get_tag(skb, vid)) {
192 /* Tagged frame */
193 if (skb->vlan_proto != proto) {
194 /* Protocol-mismatch, empty out vlan_tci for new tag */
195 skb_push(skb, ETH_HLEN);
196 skb = __vlan_put_tag(skb, skb->vlan_proto,
197 vlan_tx_tag_get(skb));
198 if (unlikely(!skb))
199 return false;
200
201 skb_pull(skb, ETH_HLEN);
202 skb_reset_mac_len(skb);
203 *vid = 0;
204 tagged = false;
205 } else {
206 tagged = true;
207 }
208 } else {
209 /* Untagged frame */
210 tagged = false;
211 }
212
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900213 if (!*vid) {
Vlad Yasevich78851982013-02-13 12:00:14 +0000214 u16 pvid = br_get_pvid(v);
215
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900216 /* Frame had a tag with VID 0 or did not have a tag.
217 * See if pvid is set on this port. That tells us which
218 * vlan untagged or priority-tagged traffic belongs to.
Vlad Yasevich78851982013-02-13 12:00:14 +0000219 */
220 if (pvid == VLAN_N_VID)
Toshiaki Makitaeb707612014-04-09 17:00:30 +0900221 goto drop;
Vlad Yasevich78851982013-02-13 12:00:14 +0000222
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900223 /* PVID is set on this port. Any untagged or priority-tagged
224 * ingress frame is considered to belong to this vlan.
Vlad Yasevich78851982013-02-13 12:00:14 +0000225 */
Toshiaki Makitadfb5fa32013-10-16 17:07:16 +0900226 *vid = pvid;
Toshiaki Makita8580e212014-06-10 20:59:23 +0900227 if (likely(!tagged))
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900228 /* Untagged Frame. */
Toshiaki Makita8580e212014-06-10 20:59:23 +0900229 __vlan_hwaccel_put_tag(skb, proto, pvid);
Toshiaki Makitab90356ce2013-10-16 17:07:14 +0900230 else
231 /* Priority-tagged Frame.
232 * At this point, We know that skb->vlan_tci had
233 * VLAN_TAG_PRESENT bit and its VID field was 0x000.
234 * We update only VID field and preserve PCP field.
235 */
236 skb->vlan_tci |= pvid;
237
Vlad Yasevich78851982013-02-13 12:00:14 +0000238 return true;
239 }
240
241 /* Frame had a valid vlan tag. See if vlan is allowed */
242 if (test_bit(*vid, v->vlan_bitmap))
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000243 return true;
Toshiaki Makitaeb707612014-04-09 17:00:30 +0900244drop:
245 kfree_skb(skb);
Vlad Yasevicha37b85c2013-02-13 12:00:10 +0000246 return false;
247}
248
Vlad Yasevich85f46c62013-02-13 12:00:11 +0000249/* Called under RCU. */
250bool br_allowed_egress(struct net_bridge *br,
251 const struct net_port_vlans *v,
252 const struct sk_buff *skb)
253{
254 u16 vid;
255
256 if (!br->vlan_enabled)
257 return true;
258
259 if (!v)
260 return false;
261
262 br_vlan_get_tag(skb, &vid);
263 if (test_bit(vid, v->vlan_bitmap))
264 return true;
265
266 return false;
267}
268
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900269/* Called under RCU */
270bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid)
271{
272 struct net_bridge *br = p->br;
273 struct net_port_vlans *v;
274
275 if (!br->vlan_enabled)
276 return true;
277
278 v = rcu_dereference(p->vlan_info);
279 if (!v)
280 return false;
281
Toshiaki Makita8580e212014-06-10 20:59:23 +0900282 if (!br_vlan_get_tag(skb, vid) && skb->vlan_proto != br->vlan_proto)
283 *vid = 0;
284
Toshiaki Makitae0d79682014-05-26 15:15:53 +0900285 if (!*vid) {
286 *vid = br_get_pvid(v);
287 if (*vid == VLAN_N_VID)
288 return false;
289
290 return true;
291 }
292
293 if (test_bit(*vid, v->vlan_bitmap))
294 return true;
295
296 return false;
297}
298
Toshiaki Makita8adff412013-10-16 17:07:13 +0900299/* Must be protected by RTNL.
300 * Must be called with vid in range from 1 to 4094 inclusive.
301 */
Vlad Yasevich552406c2013-02-13 12:00:15 +0000302int br_vlan_add(struct net_bridge *br, u16 vid, u16 flags)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000303{
304 struct net_port_vlans *pv = NULL;
305 int err;
306
307 ASSERT_RTNL();
308
309 pv = rtnl_dereference(br->vlan_info);
310 if (pv)
Vlad Yasevich552406c2013-02-13 12:00:15 +0000311 return __vlan_add(pv, vid, flags);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000312
313 /* Create port vlan infomration
314 */
315 pv = kzalloc(sizeof(*pv), GFP_KERNEL);
316 if (!pv)
317 return -ENOMEM;
318
319 pv->parent.br = br;
Vlad Yasevich552406c2013-02-13 12:00:15 +0000320 err = __vlan_add(pv, vid, flags);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000321 if (err)
322 goto out;
323
324 rcu_assign_pointer(br->vlan_info, pv);
325 return 0;
326out:
327 kfree(pv);
328 return err;
329}
330
Toshiaki Makita8adff412013-10-16 17:07:13 +0900331/* Must be protected by RTNL.
332 * Must be called with vid in range from 1 to 4094 inclusive.
333 */
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000334int br_vlan_delete(struct net_bridge *br, u16 vid)
335{
336 struct net_port_vlans *pv;
337
338 ASSERT_RTNL();
339
340 pv = rtnl_dereference(br->vlan_info);
341 if (!pv)
342 return -EINVAL;
343
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900344 br_fdb_find_delete_local(br, NULL, br->dev->dev_addr, vid);
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000345
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000346 __vlan_del(pv, vid);
347 return 0;
348}
349
350void br_vlan_flush(struct net_bridge *br)
351{
352 struct net_port_vlans *pv;
353
354 ASSERT_RTNL();
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000355 pv = rtnl_dereference(br->vlan_info);
356 if (!pv)
357 return;
358
359 __vlan_flush(pv);
360}
361
Toshiaki Makita2b292fb2014-02-07 16:48:22 +0900362bool br_vlan_find(struct net_bridge *br, u16 vid)
363{
364 struct net_port_vlans *pv;
365 bool found = false;
366
367 rcu_read_lock();
368 pv = rcu_dereference(br->vlan_info);
369
370 if (!pv)
371 goto out;
372
373 if (test_bit(vid, pv->vlan_bitmap))
374 found = true;
375
376out:
377 rcu_read_unlock();
378 return found;
379}
380
Toshiaki Makita204177f2014-06-10 20:59:25 +0900381/* Must be protected by RTNL. */
382static void recalculate_group_addr(struct net_bridge *br)
383{
384 if (br->group_addr_set)
385 return;
386
387 spin_lock_bh(&br->lock);
388 if (!br->vlan_enabled || br->vlan_proto == htons(ETH_P_8021Q)) {
389 /* Bridge Group Address */
390 br->group_addr[5] = 0x00;
391 } else { /* vlan_enabled && ETH_P_8021AD */
392 /* Provider Bridge Group Address */
393 br->group_addr[5] = 0x08;
394 }
395 spin_unlock_bh(&br->lock);
396}
397
398/* Must be protected by RTNL. */
399void br_recalculate_fwd_mask(struct net_bridge *br)
400{
401 if (!br->vlan_enabled || br->vlan_proto == htons(ETH_P_8021Q))
402 br->group_fwd_mask_required = BR_GROUPFWD_DEFAULT;
403 else /* vlan_enabled && ETH_P_8021AD */
404 br->group_fwd_mask_required = BR_GROUPFWD_8021AD &
405 ~(1u << br->group_addr[5]);
406}
407
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000408int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val)
409{
410 if (!rtnl_trylock())
411 return restart_syscall();
412
413 if (br->vlan_enabled == val)
414 goto unlock;
415
416 br->vlan_enabled = val;
Vlad Yasevich2796d0c2014-05-16 09:59:20 -0400417 br_manage_promisc(br);
Toshiaki Makita204177f2014-06-10 20:59:25 +0900418 recalculate_group_addr(br);
419 br_recalculate_fwd_mask(br);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000420
421unlock:
422 rtnl_unlock();
423 return 0;
424}
425
Toshiaki Makita204177f2014-06-10 20:59:25 +0900426int br_vlan_set_proto(struct net_bridge *br, unsigned long val)
427{
428 int err = 0;
429 struct net_bridge_port *p;
430 struct net_port_vlans *pv;
431 __be16 proto, oldproto;
432 u16 vid, errvid;
433
434 if (val != ETH_P_8021Q && val != ETH_P_8021AD)
435 return -EPROTONOSUPPORT;
436
437 if (!rtnl_trylock())
438 return restart_syscall();
439
440 proto = htons(val);
441 if (br->vlan_proto == proto)
442 goto unlock;
443
444 /* Add VLANs for the new proto to the device filter. */
445 list_for_each_entry(p, &br->port_list, list) {
446 pv = rtnl_dereference(p->vlan_info);
447 if (!pv)
448 continue;
449
450 for_each_set_bit(vid, pv->vlan_bitmap, VLAN_N_VID) {
451 err = vlan_vid_add(p->dev, proto, vid);
452 if (err)
453 goto err_filt;
454 }
455 }
456
457 oldproto = br->vlan_proto;
458 br->vlan_proto = proto;
459
460 recalculate_group_addr(br);
461 br_recalculate_fwd_mask(br);
462
463 /* Delete VLANs for the old proto from the device filter. */
464 list_for_each_entry(p, &br->port_list, list) {
465 pv = rtnl_dereference(p->vlan_info);
466 if (!pv)
467 continue;
468
469 for_each_set_bit(vid, pv->vlan_bitmap, VLAN_N_VID)
470 vlan_vid_del(p->dev, oldproto, vid);
471 }
472
473unlock:
474 rtnl_unlock();
475 return err;
476
477err_filt:
478 errvid = vid;
479 for_each_set_bit(vid, pv->vlan_bitmap, errvid)
480 vlan_vid_del(p->dev, proto, vid);
481
482 list_for_each_entry_continue_reverse(p, &br->port_list, list) {
483 pv = rtnl_dereference(p->vlan_info);
484 if (!pv)
485 continue;
486
487 for_each_set_bit(vid, pv->vlan_bitmap, VLAN_N_VID)
488 vlan_vid_del(p->dev, proto, vid);
489 }
490
491 goto unlock;
492}
493
Toshiaki Makita8580e212014-06-10 20:59:23 +0900494void br_vlan_init(struct net_bridge *br)
495{
496 br->vlan_proto = htons(ETH_P_8021Q);
497}
498
Toshiaki Makita8adff412013-10-16 17:07:13 +0900499/* Must be protected by RTNL.
500 * Must be called with vid in range from 1 to 4094 inclusive.
501 */
Vlad Yasevich552406c2013-02-13 12:00:15 +0000502int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags)
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000503{
504 struct net_port_vlans *pv = NULL;
505 int err;
506
507 ASSERT_RTNL();
508
509 pv = rtnl_dereference(port->vlan_info);
510 if (pv)
Vlad Yasevich552406c2013-02-13 12:00:15 +0000511 return __vlan_add(pv, vid, flags);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000512
513 /* Create port vlan infomration
514 */
515 pv = kzalloc(sizeof(*pv), GFP_KERNEL);
516 if (!pv) {
517 err = -ENOMEM;
518 goto clean_up;
519 }
520
521 pv->port_idx = port->port_no;
522 pv->parent.port = port;
Vlad Yasevich552406c2013-02-13 12:00:15 +0000523 err = __vlan_add(pv, vid, flags);
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000524 if (err)
525 goto clean_up;
526
527 rcu_assign_pointer(port->vlan_info, pv);
528 return 0;
529
530clean_up:
531 kfree(pv);
532 return err;
533}
534
Toshiaki Makita8adff412013-10-16 17:07:13 +0900535/* Must be protected by RTNL.
536 * Must be called with vid in range from 1 to 4094 inclusive.
537 */
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000538int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
539{
540 struct net_port_vlans *pv;
541
542 ASSERT_RTNL();
543
544 pv = rtnl_dereference(port->vlan_info);
545 if (!pv)
546 return -EINVAL;
547
Toshiaki Makita424bb9c2014-02-07 16:48:25 +0900548 br_fdb_find_delete_local(port->br, port, port->dev->dev_addr, vid);
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000549
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000550 return __vlan_del(pv, vid);
551}
552
553void nbp_vlan_flush(struct net_bridge_port *port)
554{
555 struct net_port_vlans *pv;
Toshiaki Makitadbbaf942013-11-13 17:26:13 +0900556 u16 vid;
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000557
558 ASSERT_RTNL();
559
560 pv = rtnl_dereference(port->vlan_info);
561 if (!pv)
562 return;
563
Toshiaki Makitadbbaf942013-11-13 17:26:13 +0900564 for_each_set_bit(vid, pv->vlan_bitmap, VLAN_N_VID)
Toshiaki Makita8580e212014-06-10 20:59:23 +0900565 vlan_vid_del(port->dev, port->br->vlan_proto, vid);
Toshiaki Makitadbbaf942013-11-13 17:26:13 +0900566
Vlad Yasevich243a2e62013-02-13 12:00:09 +0000567 __vlan_flush(pv);
568}
Vlad Yasevichbc9a25d2013-02-13 12:00:19 +0000569
570bool nbp_vlan_find(struct net_bridge_port *port, u16 vid)
571{
572 struct net_port_vlans *pv;
573 bool found = false;
574
575 rcu_read_lock();
576 pv = rcu_dereference(port->vlan_info);
577
578 if (!pv)
579 goto out;
580
581 if (test_bit(vid, pv->vlan_bitmap))
582 found = true;
583
584out:
585 rcu_read_unlock();
586 return found;
587}