1 #include <linux/kernel.h>
2 #include <linux/netdevice.h>
3 #include <linux/rtnetlink.h>
4 #include <linux/slab.h>
5 #include <net/switchdev.h>
7 #include "br_private.h"
9 static inline int br_vlan_cmp(struct rhashtable_compare_arg
*arg
,
12 const struct net_bridge_vlan
*vle
= ptr
;
13 u16 vid
= *(u16
*)arg
->key
;
15 return vle
->vid
!= vid
;
18 static 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
),
24 .max_size
= VLAN_N_VID
,
25 .obj_cmpfn
= br_vlan_cmp
,
26 .automatic_shrinking
= true,
29 static struct net_bridge_vlan
*br_vlan_lookup(struct rhashtable
*tbl
, u16 vid
)
31 return rhashtable_lookup_fast(tbl
, &vid
, br_vlan_rht_params
);
34 static void __vlan_add_pvid(struct net_bridge_vlan_group
*vg
, u16 vid
)
43 static void __vlan_delete_pvid(struct net_bridge_vlan_group
*vg
, u16 vid
)
52 static void __vlan_add_flags(struct net_bridge_vlan
*v
, u16 flags
)
54 struct net_bridge_vlan_group
*vg
;
56 if (br_vlan_is_master(v
))
57 vg
= br_vlan_group(v
->br
);
59 vg
= nbp_vlan_group(v
->port
);
61 if (flags
& BRIDGE_VLAN_INFO_PVID
)
62 __vlan_add_pvid(vg
, v
->vid
);
64 __vlan_delete_pvid(vg
, v
->vid
);
66 if (flags
& BRIDGE_VLAN_INFO_UNTAGGED
)
67 v
->flags
|= BRIDGE_VLAN_INFO_UNTAGGED
;
69 v
->flags
&= ~BRIDGE_VLAN_INFO_UNTAGGED
;
72 static int __vlan_vid_add(struct net_device
*dev
, struct net_bridge
*br
,
75 struct switchdev_obj_port_vlan v
= {
77 .obj
.id
= SWITCHDEV_OBJ_ID_PORT_VLAN
,
84 /* Try switchdev op first. In case it is not supported, fallback to
87 err
= switchdev_port_obj_add(dev
, &v
.obj
);
88 if (err
== -EOPNOTSUPP
)
89 return vlan_vid_add(dev
, br
->vlan_proto
, vid
);
93 static void __vlan_add_list(struct net_bridge_vlan
*v
)
95 struct net_bridge_vlan_group
*vg
;
96 struct list_head
*headp
, *hpos
;
97 struct net_bridge_vlan
*vent
;
99 if (br_vlan_is_master(v
))
100 vg
= br_vlan_group(v
->br
);
102 vg
= nbp_vlan_group(v
->port
);
104 headp
= &vg
->vlan_list
;
105 list_for_each_prev(hpos
, headp
) {
106 vent
= list_entry(hpos
, struct net_bridge_vlan
, vlist
);
107 if (v
->vid
< vent
->vid
)
112 list_add_rcu(&v
->vlist
, hpos
);
115 static void __vlan_del_list(struct net_bridge_vlan
*v
)
117 list_del_rcu(&v
->vlist
);
120 static int __vlan_vid_del(struct net_device
*dev
, struct net_bridge
*br
,
123 struct switchdev_obj_port_vlan v
= {
125 .obj
.id
= SWITCHDEV_OBJ_ID_PORT_VLAN
,
131 /* Try switchdev op first. In case it is not supported, fallback to
134 err
= switchdev_port_obj_del(dev
, &v
.obj
);
135 if (err
== -EOPNOTSUPP
) {
136 vlan_vid_del(dev
, br
->vlan_proto
, vid
);
142 /* Returns a master vlan, if it didn't exist it gets created. In all cases a
143 * a reference is taken to the master vlan before returning.
145 static struct net_bridge_vlan
*br_vlan_get_master(struct net_bridge
*br
, u16 vid
)
147 struct net_bridge_vlan_group
*vg
;
148 struct net_bridge_vlan
*masterv
;
150 vg
= br_vlan_group(br
);
151 masterv
= br_vlan_find(vg
, vid
);
153 /* missing global ctx, create it now */
154 if (br_vlan_add(br
, vid
, 0))
156 masterv
= br_vlan_find(vg
, vid
);
157 if (WARN_ON(!masterv
))
160 atomic_inc(&masterv
->refcnt
);
165 static void br_vlan_put_master(struct net_bridge_vlan
*masterv
)
167 struct net_bridge_vlan_group
*vg
;
169 if (!br_vlan_is_master(masterv
))
172 vg
= br_vlan_group(masterv
->br
);
173 if (atomic_dec_and_test(&masterv
->refcnt
)) {
174 rhashtable_remove_fast(&vg
->vlan_hash
,
175 &masterv
->vnode
, br_vlan_rht_params
);
176 __vlan_del_list(masterv
);
177 kfree_rcu(masterv
, rcu
);
181 /* This is the shared VLAN add function which works for both ports and bridge
182 * devices. There are four possible calls to this function in terms of the
184 * 1. vlan is being added on a port (no master flags, global entry exists)
185 * 2. vlan is being added on a bridge (both master and brentry flags)
186 * 3. vlan is being added on a port, but a global entry didn't exist which
187 * is being created right now (master flag set, brentry flag unset), the
188 * global entry is used for global per-vlan features, but not for filtering
189 * 4. same as 3 but with both master and brentry flags set so the entry
190 * will be used for filtering in both the port and the bridge
192 static int __vlan_add(struct net_bridge_vlan
*v
, u16 flags
)
194 struct net_bridge_vlan
*masterv
= NULL
;
195 struct net_bridge_port
*p
= NULL
;
196 struct net_bridge_vlan_group
*vg
;
197 struct net_device
*dev
;
198 struct net_bridge
*br
;
201 if (br_vlan_is_master(v
)) {
204 vg
= br_vlan_group(br
);
209 vg
= nbp_vlan_group(p
);
213 /* Add VLAN to the device filter if it is supported.
214 * This ensures tagged traffic enters the bridge when
215 * promiscuous mode is disabled by br_manage_promisc().
217 err
= __vlan_vid_add(dev
, br
, v
->vid
, flags
);
221 /* need to work on the master vlan too */
222 if (flags
& BRIDGE_VLAN_INFO_MASTER
) {
223 err
= br_vlan_add(br
, v
->vid
, flags
|
224 BRIDGE_VLAN_INFO_BRENTRY
);
229 masterv
= br_vlan_get_master(br
, v
->vid
);
235 /* Add the dev mac and count the vlan only if it's usable */
236 if (br_vlan_should_use(v
)) {
237 err
= br_fdb_insert(br
, p
, dev
->dev_addr
, v
->vid
);
239 br_err(br
, "failed insert local address into bridge forwarding table\n");
245 err
= rhashtable_lookup_insert_fast(&vg
->vlan_hash
, &v
->vnode
,
251 __vlan_add_flags(v
, flags
);
256 if (br_vlan_should_use(v
)) {
257 br_fdb_find_delete_local(br
, p
, dev
->dev_addr
, v
->vid
);
263 __vlan_vid_del(dev
, br
, v
->vid
);
265 br_vlan_put_master(masterv
);
273 static int __vlan_del(struct net_bridge_vlan
*v
)
275 struct net_bridge_vlan
*masterv
= v
;
276 struct net_bridge_vlan_group
*vg
;
277 struct net_bridge_port
*p
= NULL
;
280 if (br_vlan_is_master(v
)) {
281 vg
= br_vlan_group(v
->br
);
284 vg
= nbp_vlan_group(v
->port
);
288 __vlan_delete_pvid(vg
, v
->vid
);
290 err
= __vlan_vid_del(p
->dev
, p
->br
, v
->vid
);
295 if (br_vlan_should_use(v
)) {
296 v
->flags
&= ~BRIDGE_VLAN_INFO_BRENTRY
;
301 rhashtable_remove_fast(&vg
->vlan_hash
, &v
->vnode
,
307 br_vlan_put_master(masterv
);
312 static void __vlan_group_free(struct net_bridge_vlan_group
*vg
)
314 WARN_ON(!list_empty(&vg
->vlan_list
));
315 rhashtable_destroy(&vg
->vlan_hash
);
319 static void __vlan_flush(struct net_bridge_vlan_group
*vg
)
321 struct net_bridge_vlan
*vlan
, *tmp
;
323 __vlan_delete_pvid(vg
, vg
->pvid
);
324 list_for_each_entry_safe(vlan
, tmp
, &vg
->vlan_list
, vlist
)
328 struct sk_buff
*br_handle_vlan(struct net_bridge
*br
,
329 struct net_bridge_vlan_group
*vg
,
332 struct net_bridge_vlan
*v
;
335 /* If this packet was not filtered at input, let it pass */
336 if (!BR_INPUT_SKB_CB(skb
)->vlan_filtered
)
339 /* At this point, we know that the frame was filtered and contains
340 * a valid vlan id. If the vlan id has untagged flag set,
341 * send untagged; otherwise, send tagged.
343 br_vlan_get_tag(skb
, &vid
);
344 v
= br_vlan_find(vg
, vid
);
345 /* Vlan entry must be configured at this point. The
346 * only exception is the bridge is set in promisc mode and the
347 * packet is destined for the bridge device. In this case
348 * pass the packet as is.
350 if (!v
|| !br_vlan_should_use(v
)) {
351 if ((br
->dev
->flags
& IFF_PROMISC
) && skb
->dev
== br
->dev
) {
358 if (v
->flags
& BRIDGE_VLAN_INFO_UNTAGGED
)
365 /* Called under RCU */
366 static bool __allowed_ingress(struct net_bridge_vlan_group
*vg
, __be16 proto
,
367 struct sk_buff
*skb
, u16
*vid
)
369 const struct net_bridge_vlan
*v
;
372 BR_INPUT_SKB_CB(skb
)->vlan_filtered
= true;
373 /* If vlan tx offload is disabled on bridge device and frame was
374 * sent from vlan device on the bridge device, it does not have
375 * HW accelerated vlan tag.
377 if (unlikely(!skb_vlan_tag_present(skb
) &&
378 skb
->protocol
== proto
)) {
379 skb
= skb_vlan_untag(skb
);
384 if (!br_vlan_get_tag(skb
, vid
)) {
386 if (skb
->vlan_proto
!= proto
) {
387 /* Protocol-mismatch, empty out vlan_tci for new tag */
388 skb_push(skb
, ETH_HLEN
);
389 skb
= vlan_insert_tag_set_proto(skb
, skb
->vlan_proto
,
390 skb_vlan_tag_get(skb
));
394 skb_pull(skb
, ETH_HLEN
);
395 skb_reset_mac_len(skb
);
407 u16 pvid
= br_get_pvid(vg
);
409 /* Frame had a tag with VID 0 or did not have a tag.
410 * See if pvid is set on this port. That tells us which
411 * vlan untagged or priority-tagged traffic belongs to.
416 /* PVID is set on this port. Any untagged or priority-tagged
417 * ingress frame is considered to belong to this vlan.
421 /* Untagged Frame. */
422 __vlan_hwaccel_put_tag(skb
, proto
, pvid
);
424 /* Priority-tagged Frame.
425 * At this point, We know that skb->vlan_tci had
426 * VLAN_TAG_PRESENT bit and its VID field was 0x000.
427 * We update only VID field and preserve PCP field.
429 skb
->vlan_tci
|= pvid
;
434 /* Frame had a valid vlan tag. See if vlan is allowed */
435 v
= br_vlan_find(vg
, *vid
);
436 if (v
&& br_vlan_should_use(v
))
443 bool br_allowed_ingress(const struct net_bridge
*br
,
444 struct net_bridge_vlan_group
*vg
, struct sk_buff
*skb
,
447 /* If VLAN filtering is disabled on the bridge, all packets are
450 if (!br
->vlan_enabled
) {
451 BR_INPUT_SKB_CB(skb
)->vlan_filtered
= false;
455 return __allowed_ingress(vg
, br
->vlan_proto
, skb
, vid
);
458 /* Called under RCU. */
459 bool br_allowed_egress(struct net_bridge_vlan_group
*vg
,
460 const struct sk_buff
*skb
)
462 const struct net_bridge_vlan
*v
;
465 /* If this packet was not filtered at input, let it pass */
466 if (!BR_INPUT_SKB_CB(skb
)->vlan_filtered
)
469 br_vlan_get_tag(skb
, &vid
);
470 v
= br_vlan_find(vg
, vid
);
471 if (v
&& br_vlan_should_use(v
))
477 /* Called under RCU */
478 bool br_should_learn(struct net_bridge_port
*p
, struct sk_buff
*skb
, u16
*vid
)
480 struct net_bridge_vlan_group
*vg
;
481 struct net_bridge
*br
= p
->br
;
483 /* If filtering was disabled at input, let it pass. */
484 if (!br
->vlan_enabled
)
487 vg
= nbp_vlan_group_rcu(p
);
488 if (!vg
|| !vg
->num_vlans
)
491 if (!br_vlan_get_tag(skb
, vid
) && skb
->vlan_proto
!= br
->vlan_proto
)
495 *vid
= br_get_pvid(vg
);
502 if (br_vlan_find(vg
, *vid
))
508 /* Must be protected by RTNL.
509 * Must be called with vid in range from 1 to 4094 inclusive.
511 int br_vlan_add(struct net_bridge
*br
, u16 vid
, u16 flags
)
513 struct net_bridge_vlan_group
*vg
;
514 struct net_bridge_vlan
*vlan
;
519 vg
= br_vlan_group(br
);
520 vlan
= br_vlan_find(vg
, vid
);
522 if (!br_vlan_is_brentry(vlan
)) {
523 /* Trying to change flags of non-existent bridge vlan */
524 if (!(flags
& BRIDGE_VLAN_INFO_BRENTRY
))
526 /* It was only kept for port vlans, now make it real */
527 ret
= br_fdb_insert(br
, NULL
, br
->dev
->dev_addr
,
530 br_err(br
, "failed insert local address into bridge forwarding table\n");
533 atomic_inc(&vlan
->refcnt
);
534 vlan
->flags
|= BRIDGE_VLAN_INFO_BRENTRY
;
537 __vlan_add_flags(vlan
, flags
);
541 vlan
= kzalloc(sizeof(*vlan
), GFP_KERNEL
);
546 vlan
->flags
= flags
| BRIDGE_VLAN_INFO_MASTER
;
547 vlan
->flags
&= ~BRIDGE_VLAN_INFO_PVID
;
549 if (flags
& BRIDGE_VLAN_INFO_BRENTRY
)
550 atomic_set(&vlan
->refcnt
, 1);
551 ret
= __vlan_add(vlan
, flags
);
558 /* Must be protected by RTNL.
559 * Must be called with vid in range from 1 to 4094 inclusive.
561 int br_vlan_delete(struct net_bridge
*br
, u16 vid
)
563 struct net_bridge_vlan_group
*vg
;
564 struct net_bridge_vlan
*v
;
568 vg
= br_vlan_group(br
);
569 v
= br_vlan_find(vg
, vid
);
570 if (!v
|| !br_vlan_is_brentry(v
))
573 br_fdb_find_delete_local(br
, NULL
, br
->dev
->dev_addr
, vid
);
574 br_fdb_delete_by_port(br
, NULL
, vid
, 0);
576 return __vlan_del(v
);
579 void br_vlan_flush(struct net_bridge
*br
)
581 struct net_bridge_vlan_group
*vg
;
585 vg
= br_vlan_group(br
);
587 RCU_INIT_POINTER(br
->vlgrp
, NULL
);
589 __vlan_group_free(vg
);
592 struct net_bridge_vlan
*br_vlan_find(struct net_bridge_vlan_group
*vg
, u16 vid
)
597 return br_vlan_lookup(&vg
->vlan_hash
, vid
);
600 /* Must be protected by RTNL. */
601 static void recalculate_group_addr(struct net_bridge
*br
)
603 if (br
->group_addr_set
)
606 spin_lock_bh(&br
->lock
);
607 if (!br
->vlan_enabled
|| br
->vlan_proto
== htons(ETH_P_8021Q
)) {
608 /* Bridge Group Address */
609 br
->group_addr
[5] = 0x00;
610 } else { /* vlan_enabled && ETH_P_8021AD */
611 /* Provider Bridge Group Address */
612 br
->group_addr
[5] = 0x08;
614 spin_unlock_bh(&br
->lock
);
617 /* Must be protected by RTNL. */
618 void br_recalculate_fwd_mask(struct net_bridge
*br
)
620 if (!br
->vlan_enabled
|| br
->vlan_proto
== htons(ETH_P_8021Q
))
621 br
->group_fwd_mask_required
= BR_GROUPFWD_DEFAULT
;
622 else /* vlan_enabled && ETH_P_8021AD */
623 br
->group_fwd_mask_required
= BR_GROUPFWD_8021AD
&
624 ~(1u << br
->group_addr
[5]);
627 int __br_vlan_filter_toggle(struct net_bridge
*br
, unsigned long val
)
629 struct switchdev_attr attr
= {
631 .id
= SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING
,
632 .flags
= SWITCHDEV_F_SKIP_EOPNOTSUPP
,
633 .u
.vlan_filtering
= val
,
637 if (br
->vlan_enabled
== val
)
640 err
= switchdev_port_attr_set(br
->dev
, &attr
);
641 if (err
&& err
!= -EOPNOTSUPP
)
644 br
->vlan_enabled
= val
;
645 br_manage_promisc(br
);
646 recalculate_group_addr(br
);
647 br_recalculate_fwd_mask(br
);
652 int br_vlan_filter_toggle(struct net_bridge
*br
, unsigned long val
)
657 return restart_syscall();
659 err
= __br_vlan_filter_toggle(br
, val
);
665 int __br_vlan_set_proto(struct net_bridge
*br
, __be16 proto
)
668 struct net_bridge_port
*p
;
669 struct net_bridge_vlan
*vlan
;
670 struct net_bridge_vlan_group
*vg
;
673 if (br
->vlan_proto
== proto
)
676 /* Add VLANs for the new proto to the device filter. */
677 list_for_each_entry(p
, &br
->port_list
, list
) {
678 vg
= nbp_vlan_group(p
);
679 list_for_each_entry(vlan
, &vg
->vlan_list
, vlist
) {
680 err
= vlan_vid_add(p
->dev
, proto
, vlan
->vid
);
686 oldproto
= br
->vlan_proto
;
687 br
->vlan_proto
= proto
;
689 recalculate_group_addr(br
);
690 br_recalculate_fwd_mask(br
);
692 /* Delete VLANs for the old proto from the device filter. */
693 list_for_each_entry(p
, &br
->port_list
, list
) {
694 vg
= nbp_vlan_group(p
);
695 list_for_each_entry(vlan
, &vg
->vlan_list
, vlist
)
696 vlan_vid_del(p
->dev
, oldproto
, vlan
->vid
);
702 list_for_each_entry_continue_reverse(vlan
, &vg
->vlan_list
, vlist
)
703 vlan_vid_del(p
->dev
, proto
, vlan
->vid
);
705 list_for_each_entry_continue_reverse(p
, &br
->port_list
, list
) {
706 vg
= nbp_vlan_group(p
);
707 list_for_each_entry(vlan
, &vg
->vlan_list
, vlist
)
708 vlan_vid_del(p
->dev
, proto
, vlan
->vid
);
714 int br_vlan_set_proto(struct net_bridge
*br
, unsigned long val
)
718 if (val
!= ETH_P_8021Q
&& val
!= ETH_P_8021AD
)
719 return -EPROTONOSUPPORT
;
722 return restart_syscall();
724 err
= __br_vlan_set_proto(br
, htons(val
));
730 static bool vlan_default_pvid(struct net_bridge_vlan_group
*vg
, u16 vid
)
732 struct net_bridge_vlan
*v
;
737 v
= br_vlan_lookup(&vg
->vlan_hash
, vid
);
738 if (v
&& br_vlan_should_use(v
) &&
739 (v
->flags
& BRIDGE_VLAN_INFO_UNTAGGED
))
745 static void br_vlan_disable_default_pvid(struct net_bridge
*br
)
747 struct net_bridge_port
*p
;
748 u16 pvid
= br
->default_pvid
;
750 /* Disable default_pvid on all ports where it is still
753 if (vlan_default_pvid(br_vlan_group(br
), pvid
))
754 br_vlan_delete(br
, pvid
);
756 list_for_each_entry(p
, &br
->port_list
, list
) {
757 if (vlan_default_pvid(nbp_vlan_group(p
), pvid
))
758 nbp_vlan_delete(p
, pvid
);
761 br
->default_pvid
= 0;
764 int __br_vlan_set_default_pvid(struct net_bridge
*br
, u16 pvid
)
766 const struct net_bridge_vlan
*pvent
;
767 struct net_bridge_vlan_group
*vg
;
768 struct net_bridge_port
*p
;
771 unsigned long *changed
;
774 br_vlan_disable_default_pvid(br
);
778 changed
= kcalloc(BITS_TO_LONGS(BR_MAX_PORTS
), sizeof(unsigned long),
783 old_pvid
= br
->default_pvid
;
785 /* Update default_pvid config only if we do not conflict with
786 * user configuration.
788 vg
= br_vlan_group(br
);
789 pvent
= br_vlan_find(vg
, pvid
);
790 if ((!old_pvid
|| vlan_default_pvid(vg
, old_pvid
)) &&
791 (!pvent
|| !br_vlan_should_use(pvent
))) {
792 err
= br_vlan_add(br
, pvid
,
793 BRIDGE_VLAN_INFO_PVID
|
794 BRIDGE_VLAN_INFO_UNTAGGED
|
795 BRIDGE_VLAN_INFO_BRENTRY
);
798 br_vlan_delete(br
, old_pvid
);
802 list_for_each_entry(p
, &br
->port_list
, list
) {
803 /* Update default_pvid config only if we do not conflict with
804 * user configuration.
806 vg
= nbp_vlan_group(p
);
808 !vlan_default_pvid(vg
, old_pvid
)) ||
809 br_vlan_find(vg
, pvid
))
812 err
= nbp_vlan_add(p
, pvid
,
813 BRIDGE_VLAN_INFO_PVID
|
814 BRIDGE_VLAN_INFO_UNTAGGED
);
817 nbp_vlan_delete(p
, old_pvid
);
818 set_bit(p
->port_no
, changed
);
821 br
->default_pvid
= pvid
;
828 list_for_each_entry_continue_reverse(p
, &br
->port_list
, list
) {
829 if (!test_bit(p
->port_no
, changed
))
833 nbp_vlan_add(p
, old_pvid
,
834 BRIDGE_VLAN_INFO_PVID
|
835 BRIDGE_VLAN_INFO_UNTAGGED
);
836 nbp_vlan_delete(p
, pvid
);
839 if (test_bit(0, changed
)) {
841 br_vlan_add(br
, old_pvid
,
842 BRIDGE_VLAN_INFO_PVID
|
843 BRIDGE_VLAN_INFO_UNTAGGED
|
844 BRIDGE_VLAN_INFO_BRENTRY
);
845 br_vlan_delete(br
, pvid
);
850 int br_vlan_set_default_pvid(struct net_bridge
*br
, unsigned long val
)
855 if (val
>= VLAN_VID_MASK
)
859 return restart_syscall();
861 if (pvid
== br
->default_pvid
)
864 /* Only allow default pvid change when filtering is disabled */
865 if (br
->vlan_enabled
) {
866 pr_info_once("Please disable vlan filtering to change default_pvid\n");
870 err
= __br_vlan_set_default_pvid(br
, pvid
);
876 int br_vlan_init(struct net_bridge
*br
)
878 struct net_bridge_vlan_group
*vg
;
881 vg
= kzalloc(sizeof(*vg
), GFP_KERNEL
);
884 ret
= rhashtable_init(&vg
->vlan_hash
, &br_vlan_rht_params
);
887 INIT_LIST_HEAD(&vg
->vlan_list
);
888 br
->vlan_proto
= htons(ETH_P_8021Q
);
889 br
->default_pvid
= 1;
890 rcu_assign_pointer(br
->vlgrp
, vg
);
891 ret
= br_vlan_add(br
, 1,
892 BRIDGE_VLAN_INFO_PVID
| BRIDGE_VLAN_INFO_UNTAGGED
|
893 BRIDGE_VLAN_INFO_BRENTRY
);
901 rhashtable_destroy(&vg
->vlan_hash
);
908 int nbp_vlan_init(struct net_bridge_port
*p
)
910 struct switchdev_attr attr
= {
911 .orig_dev
= p
->br
->dev
,
912 .id
= SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING
,
913 .flags
= SWITCHDEV_F_SKIP_EOPNOTSUPP
,
914 .u
.vlan_filtering
= p
->br
->vlan_enabled
,
916 struct net_bridge_vlan_group
*vg
;
919 vg
= kzalloc(sizeof(struct net_bridge_vlan_group
), GFP_KERNEL
);
923 ret
= switchdev_port_attr_set(p
->dev
, &attr
);
924 if (ret
&& ret
!= -EOPNOTSUPP
)
925 goto err_vlan_enabled
;
927 ret
= rhashtable_init(&vg
->vlan_hash
, &br_vlan_rht_params
);
930 INIT_LIST_HEAD(&vg
->vlan_list
);
931 rcu_assign_pointer(p
->vlgrp
, vg
);
932 if (p
->br
->default_pvid
) {
933 ret
= nbp_vlan_add(p
, p
->br
->default_pvid
,
934 BRIDGE_VLAN_INFO_PVID
|
935 BRIDGE_VLAN_INFO_UNTAGGED
);
943 RCU_INIT_POINTER(p
->vlgrp
, NULL
);
945 rhashtable_destroy(&vg
->vlan_hash
);
953 /* Must be protected by RTNL.
954 * Must be called with vid in range from 1 to 4094 inclusive.
956 int nbp_vlan_add(struct net_bridge_port
*port
, u16 vid
, u16 flags
)
958 struct switchdev_obj_port_vlan v
= {
959 .obj
.orig_dev
= port
->dev
,
960 .obj
.id
= SWITCHDEV_OBJ_ID_PORT_VLAN
,
965 struct net_bridge_vlan
*vlan
;
970 vlan
= br_vlan_find(nbp_vlan_group(port
), vid
);
972 /* Pass the flags to the hardware bridge */
973 ret
= switchdev_port_obj_add(port
->dev
, &v
.obj
);
974 if (ret
&& ret
!= -EOPNOTSUPP
)
976 __vlan_add_flags(vlan
, flags
);
980 vlan
= kzalloc(sizeof(*vlan
), GFP_KERNEL
);
986 ret
= __vlan_add(vlan
, flags
);
993 /* Must be protected by RTNL.
994 * Must be called with vid in range from 1 to 4094 inclusive.
996 int nbp_vlan_delete(struct net_bridge_port
*port
, u16 vid
)
998 struct net_bridge_vlan
*v
;
1002 v
= br_vlan_find(nbp_vlan_group(port
), vid
);
1005 br_fdb_find_delete_local(port
->br
, port
, port
->dev
->dev_addr
, vid
);
1006 br_fdb_delete_by_port(port
->br
, port
, vid
, 0);
1008 return __vlan_del(v
);
1011 void nbp_vlan_flush(struct net_bridge_port
*port
)
1013 struct net_bridge_vlan_group
*vg
;
1017 vg
= nbp_vlan_group(port
);
1019 RCU_INIT_POINTER(port
->vlgrp
, NULL
);
1021 __vlan_group_free(vg
);