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);
35 static int __vlan_del(struct net_port_vlans *v, u16 vid)
37 if (!test_bit(vid, v->vlan_bitmap))
40 if (v->port_idx && vid) {
41 struct net_device *dev = v->parent.port->dev;
43 if (dev->features & NETIF_F_HW_VLAN_FILTER)
44 dev->netdev_ops->ndo_vlan_rx_kill_vid(dev, vid);
47 clear_bit(vid, v->vlan_bitmap);
49 if (bitmap_empty(v->vlan_bitmap, BR_VLAN_BITMAP_LEN)) {
51 rcu_assign_pointer(v->parent.port->vlan_info, NULL);
53 rcu_assign_pointer(v->parent.br->vlan_info, NULL);
59 static void __vlan_flush(struct net_port_vlans *v)
61 bitmap_zero(v->vlan_bitmap, BR_VLAN_BITMAP_LEN);
63 rcu_assign_pointer(v->parent.port->vlan_info, NULL);
65 rcu_assign_pointer(v->parent.br->vlan_info, NULL);
69 /* Called under RCU */
70 bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
75 /* If VLAN filtering is disabled on the bridge, all packets are
78 if (!br->vlan_enabled)
81 /* If there are no vlan in the permitted list, all packets are
87 br_vlan_get_tag(skb, &vid);
88 if (test_bit(vid, v->vlan_bitmap))
94 /* Called under RCU. */
95 bool br_allowed_egress(struct net_bridge *br,
96 const struct net_port_vlans *v,
97 const struct sk_buff *skb)
101 if (!br->vlan_enabled)
107 br_vlan_get_tag(skb, &vid);
108 if (test_bit(vid, v->vlan_bitmap))
114 /* Must be protected by RTNL */
115 int br_vlan_add(struct net_bridge *br, u16 vid)
117 struct net_port_vlans *pv = NULL;
122 pv = rtnl_dereference(br->vlan_info);
124 return __vlan_add(pv, vid);
126 /* Create port vlan infomration
128 pv = kzalloc(sizeof(*pv), GFP_KERNEL);
133 err = __vlan_add(pv, vid);
137 rcu_assign_pointer(br->vlan_info, pv);
144 /* Must be protected by RTNL */
145 int br_vlan_delete(struct net_bridge *br, u16 vid)
147 struct net_port_vlans *pv;
151 pv = rtnl_dereference(br->vlan_info);
159 void br_vlan_flush(struct net_bridge *br)
161 struct net_port_vlans *pv;
165 pv = rtnl_dereference(br->vlan_info);
172 int br_vlan_filter_toggle(struct net_bridge *br, unsigned long val)
175 return restart_syscall();
177 if (br->vlan_enabled == val)
180 br->vlan_enabled = val;
187 /* Must be protected by RTNL */
188 int nbp_vlan_add(struct net_bridge_port *port, u16 vid)
190 struct net_port_vlans *pv = NULL;
195 pv = rtnl_dereference(port->vlan_info);
197 return __vlan_add(pv, vid);
199 /* Create port vlan infomration
201 pv = kzalloc(sizeof(*pv), GFP_KERNEL);
207 pv->port_idx = port->port_no;
208 pv->parent.port = port;
209 err = __vlan_add(pv, vid);
213 rcu_assign_pointer(port->vlan_info, pv);
221 /* Must be protected by RTNL */
222 int nbp_vlan_delete(struct net_bridge_port *port, u16 vid)
224 struct net_port_vlans *pv;
228 pv = rtnl_dereference(port->vlan_info);
232 return __vlan_del(pv, vid);
235 void nbp_vlan_flush(struct net_bridge_port *port)
237 struct net_port_vlans *pv;
241 pv = rtnl_dereference(port->vlan_info);