1 #include <linux/kernel.h>
2 #include <linux/netdevice.h>
3 #include <linux/rtnetlink.h>
4 #include <linux/slab.h>
6 #include "br_private.h"
8 static int __vlan_add(struct net_port_vlans *v, u16 vid)
12 if (test_bit(vid, v->vlan_bitmap))
15 if (v->port_idx && vid) {
16 struct net_device *dev = v->parent.port->dev;
18 /* Add VLAN to the device filter if it is supported.
19 * Stricly speaking, this is not necessary now, since devices
20 * are made promiscuous by the bridge, but if that ever changes
21 * this code will allow tagged traffic to enter the bridge.
23 if (dev->features & NETIF_F_HW_VLAN_FILTER) {
24 err = dev->netdev_ops->ndo_vlan_rx_add_vid(dev, vid);
30 set_bit(vid, v->vlan_bitmap);
34 static int __vlan_del(struct net_port_vlans *v, u16 vid)
36 if (!test_bit(vid, v->vlan_bitmap))
39 if (v->port_idx && vid) {
40 struct net_device *dev = v->parent.port->dev;
42 if (dev->features & NETIF_F_HW_VLAN_FILTER)
43 dev->netdev_ops->ndo_vlan_rx_kill_vid(dev, vid);
46 clear_bit(vid, v->vlan_bitmap);
47 if (bitmap_empty(v->vlan_bitmap, BR_VLAN_BITMAP_LEN)) {
49 rcu_assign_pointer(v->parent.port->vlan_info, NULL);
51 rcu_assign_pointer(v->parent.br->vlan_info, NULL);
57 static void __vlan_flush(struct net_port_vlans *v)
59 bitmap_zero(v->vlan_bitmap, BR_VLAN_BITMAP_LEN);
61 rcu_assign_pointer(v->parent.port->vlan_info, NULL);
63 rcu_assign_pointer(v->parent.br->vlan_info, NULL);
67 /* Called under RCU */
68 bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
73 /* If VLAN filtering is disabled on the bridge, all packets are
76 if (!br->vlan_enabled)
79 /* If there are no vlan in the permitted list, all packets are
85 br_vlan_get_tag(skb, &vid);
86 if (test_bit(vid, v->vlan_bitmap))
92 /* Called under RCU. */
93 bool br_allowed_egress(struct net_bridge *br,
94 const struct net_port_vlans *v,
95 const struct sk_buff *skb)
99 if (!br->vlan_enabled)
105 br_vlan_get_tag(skb, &vid);
106 if (test_bit(vid, v->vlan_bitmap))
112 /* Must be protected by RTNL */
113 int br_vlan_add(struct net_bridge *br, u16 vid)
115 struct net_port_vlans *pv = NULL;
120 pv = rtnl_dereference(br->vlan_info);
122 return __vlan_add(pv, vid);
124 /* Create port vlan infomration
126 pv = kzalloc(sizeof(*pv), GFP_KERNEL);
131 err = __vlan_add(pv, vid);
135 rcu_assign_pointer(br->vlan_info, pv);
142 /* Must be protected by RTNL */
143 int br_vlan_delete(struct net_bridge *br, u16 vid)
145 struct net_port_vlans *pv;
149 pv = rtnl_dereference(br->vlan_info);
157 void br_vlan_flush(struct net_bridge *br)
159 struct net_port_vlans *pv;
163 pv = rtnl_dereference(br->vlan_info);
170 int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val)
173 return restart_syscall();
175 if (br->vlan_enabled == val)
178 br->vlan_enabled = val;
185 /* Must be protected by RTNL */
186 int nbp_vlan_add(struct net_bridge_port *port, u16 vid)
188 struct net_port_vlans *pv = NULL;
193 pv = rtnl_dereference(port->vlan_info);
195 return __vlan_add(pv, vid);
197 /* Create port vlan infomration
199 pv = kzalloc(sizeof(*pv), GFP_KERNEL);
205 pv->port_idx = port->port_no;
206 pv->parent.port = port;
207 err = __vlan_add(pv, vid);
211 rcu_assign_pointer(port->vlan_info, pv);
219 /* Must be protected by RTNL */
220 int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
222 struct net_port_vlans *pv;
226 pv = rtnl_dereference(port->vlan_info);
230 return __vlan_del(pv, vid);
233 void nbp_vlan_flush(struct net_bridge_port *port)
235 struct net_port_vlans *pv;
239 pv = rtnl_dereference(port->vlan_info);