aboutsummaryrefslogtreecommitdiffstats
path: root/net/8021q
diff options
context:
space:
mode:
Diffstat (limited to 'net/8021q')
-rw-r--r--net/8021q/Kconfig10
-rw-r--r--net/8021q/Makefile12
-rw-r--r--net/8021q/vlan.c80
-rw-r--r--net/8021q/vlan.h86
-rw-r--r--net/8021q/vlan_core.c64
-rw-r--r--net/8021q/vlan_dev.c298
-rw-r--r--net/8021q/vlan_gvrp.c66
-rw-r--r--net/8021q/vlan_netlink.c7
-rw-r--r--net/8021q/vlanproc.c13
9 files changed, 406 insertions, 230 deletions
diff --git a/net/8021q/Kconfig b/net/8021q/Kconfig
index c4a382e450e2..fa073a54963e 100644
--- a/net/8021q/Kconfig
+++ b/net/8021q/Kconfig
@@ -17,3 +17,13 @@ config VLAN_8021Q
17 will be called 8021q. 17 will be called 8021q.
18 18
19 If unsure, say N. 19 If unsure, say N.
20
21config VLAN_8021Q_GVRP
22 bool "GVRP (GARP VLAN Registration Protocol) support"
23 depends on VLAN_8021Q
24 select GARP
25 help
26 Select this to enable GVRP end-system support. GVRP is used for
27 automatic propagation of registered VLANs to switches.
28
29 If unsure, say N.
diff --git a/net/8021q/Makefile b/net/8021q/Makefile
index 10ca7f486c3a..9f4f174ead1c 100644
--- a/net/8021q/Makefile
+++ b/net/8021q/Makefile
@@ -1,12 +1,10 @@
1# 1#
2# Makefile for the Linux VLAN layer. 2# Makefile for the Linux VLAN layer.
3# 3#
4obj-$(subst m,y,$(CONFIG_VLAN_8021Q)) += vlan_core.o
5obj-$(CONFIG_VLAN_8021Q) += 8021q.o
4 6
5obj-$(CONFIG_VLAN_8021Q) += 8021q.o 78021q-y := vlan.o vlan_dev.o vlan_netlink.o
6 88021q-$(CONFIG_VLAN_8021Q_GVRP) += vlan_gvrp.o
78021q-objs := vlan.o vlan_dev.o vlan_netlink.o 98021q-$(CONFIG_PROC_FS) += vlanproc.o
8
9ifeq ($(CONFIG_PROC_FS),y)
108021q-objs += vlanproc.o
11endif
12 10
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 08f14f6c5fd6..b661f47bf10a 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -18,22 +18,20 @@
18 * 2 of the License, or (at your option) any later version. 18 * 2 of the License, or (at your option) any later version.
19 */ 19 */
20 20
21#include <asm/uaccess.h> /* for copy_from_user */
22#include <linux/capability.h> 21#include <linux/capability.h>
23#include <linux/module.h> 22#include <linux/module.h>
24#include <linux/netdevice.h> 23#include <linux/netdevice.h>
25#include <linux/skbuff.h> 24#include <linux/skbuff.h>
26#include <net/datalink.h>
27#include <linux/mm.h>
28#include <linux/in.h>
29#include <linux/init.h> 25#include <linux/init.h>
30#include <linux/rculist.h> 26#include <linux/rculist.h>
31#include <net/p8022.h> 27#include <net/p8022.h>
32#include <net/arp.h> 28#include <net/arp.h>
33#include <linux/rtnetlink.h> 29#include <linux/rtnetlink.h>
34#include <linux/notifier.h> 30#include <linux/notifier.h>
31#include <net/rtnetlink.h>
35#include <net/net_namespace.h> 32#include <net/net_namespace.h>
36#include <net/netns/generic.h> 33#include <net/netns/generic.h>
34#include <asm/uaccess.h>
37 35
38#include <linux/if_vlan.h> 36#include <linux/if_vlan.h>
39#include "vlan.h" 37#include "vlan.h"
@@ -84,13 +82,12 @@ static struct vlan_group *__vlan_find_group(struct net_device *real_dev)
84 * 82 *
85 * Must be invoked with RCU read lock (no preempt) 83 * Must be invoked with RCU read lock (no preempt)
86 */ 84 */
87struct net_device *__find_vlan_dev(struct net_device *real_dev, 85struct net_device *__find_vlan_dev(struct net_device *real_dev, u16 vlan_id)
88 unsigned short VID)
89{ 86{
90 struct vlan_group *grp = __vlan_find_group(real_dev); 87 struct vlan_group *grp = __vlan_find_group(real_dev);
91 88
92 if (grp) 89 if (grp)
93 return vlan_group_get_device(grp, VID); 90 return vlan_group_get_device(grp, vlan_id);
94 91
95 return NULL; 92 return NULL;
96} 93}
@@ -118,14 +115,14 @@ static struct vlan_group *vlan_group_alloc(struct net_device *real_dev)
118 return grp; 115 return grp;
119} 116}
120 117
121static int vlan_group_prealloc_vid(struct vlan_group *vg, int vid) 118static int vlan_group_prealloc_vid(struct vlan_group *vg, u16 vlan_id)
122{ 119{
123 struct net_device **array; 120 struct net_device **array;
124 unsigned int size; 121 unsigned int size;
125 122
126 ASSERT_RTNL(); 123 ASSERT_RTNL();
127 124
128 array = vg->vlan_devices_arrays[vid / VLAN_GROUP_ARRAY_PART_LEN]; 125 array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
129 if (array != NULL) 126 if (array != NULL)
130 return 0; 127 return 0;
131 128
@@ -134,7 +131,7 @@ static int vlan_group_prealloc_vid(struct vlan_group *vg, int vid)
134 if (array == NULL) 131 if (array == NULL)
135 return -ENOBUFS; 132 return -ENOBUFS;
136 133
137 vg->vlan_devices_arrays[vid / VLAN_GROUP_ARRAY_PART_LEN] = array; 134 vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN] = array;
138 return 0; 135 return 0;
139} 136}
140 137
@@ -148,7 +145,7 @@ void unregister_vlan_dev(struct net_device *dev)
148 struct vlan_dev_info *vlan = vlan_dev_info(dev); 145 struct vlan_dev_info *vlan = vlan_dev_info(dev);
149 struct net_device *real_dev = vlan->real_dev; 146 struct net_device *real_dev = vlan->real_dev;
150 struct vlan_group *grp; 147 struct vlan_group *grp;
151 unsigned short vlan_id = vlan->vlan_id; 148 u16 vlan_id = vlan->vlan_id;
152 149
153 ASSERT_RTNL(); 150 ASSERT_RTNL();
154 151
@@ -166,8 +163,12 @@ void unregister_vlan_dev(struct net_device *dev)
166 163
167 synchronize_net(); 164 synchronize_net();
168 165
166 unregister_netdevice(dev);
167
169 /* If the group is now empty, kill off the group. */ 168 /* If the group is now empty, kill off the group. */
170 if (grp->nr_vlans == 0) { 169 if (grp->nr_vlans == 0) {
170 vlan_gvrp_uninit_applicant(real_dev);
171
171 if (real_dev->features & NETIF_F_HW_VLAN_RX) 172 if (real_dev->features & NETIF_F_HW_VLAN_RX)
172 real_dev->vlan_rx_register(real_dev, NULL); 173 real_dev->vlan_rx_register(real_dev, NULL);
173 174
@@ -179,8 +180,6 @@ void unregister_vlan_dev(struct net_device *dev)
179 180
180 /* Get rid of the vlan's reference to real_dev */ 181 /* Get rid of the vlan's reference to real_dev */
181 dev_put(real_dev); 182 dev_put(real_dev);
182
183 unregister_netdevice(dev);
184} 183}
185 184
186static void vlan_transfer_operstate(const struct net_device *dev, 185static void vlan_transfer_operstate(const struct net_device *dev,
@@ -204,7 +203,7 @@ static void vlan_transfer_operstate(const struct net_device *dev,
204 } 203 }
205} 204}
206 205
207int vlan_check_real_dev(struct net_device *real_dev, unsigned short vlan_id) 206int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id)
208{ 207{
209 char *name = real_dev->name; 208 char *name = real_dev->name;
210 209
@@ -241,7 +240,7 @@ int register_vlan_dev(struct net_device *dev)
241{ 240{
242 struct vlan_dev_info *vlan = vlan_dev_info(dev); 241 struct vlan_dev_info *vlan = vlan_dev_info(dev);
243 struct net_device *real_dev = vlan->real_dev; 242 struct net_device *real_dev = vlan->real_dev;
244 unsigned short vlan_id = vlan->vlan_id; 243 u16 vlan_id = vlan->vlan_id;
245 struct vlan_group *grp, *ngrp = NULL; 244 struct vlan_group *grp, *ngrp = NULL;
246 int err; 245 int err;
247 246
@@ -250,15 +249,18 @@ int register_vlan_dev(struct net_device *dev)
250 ngrp = grp = vlan_group_alloc(real_dev); 249 ngrp = grp = vlan_group_alloc(real_dev);
251 if (!grp) 250 if (!grp)
252 return -ENOBUFS; 251 return -ENOBUFS;
252 err = vlan_gvrp_init_applicant(real_dev);
253 if (err < 0)
254 goto out_free_group;
253 } 255 }
254 256
255 err = vlan_group_prealloc_vid(grp, vlan_id); 257 err = vlan_group_prealloc_vid(grp, vlan_id);
256 if (err < 0) 258 if (err < 0)
257 goto out_free_group; 259 goto out_uninit_applicant;
258 260
259 err = register_netdevice(dev); 261 err = register_netdevice(dev);
260 if (err < 0) 262 if (err < 0)
261 goto out_free_group; 263 goto out_uninit_applicant;
262 264
263 /* Account for reference in struct vlan_dev_info */ 265 /* Account for reference in struct vlan_dev_info */
264 dev_hold(real_dev); 266 dev_hold(real_dev);
@@ -279,6 +281,9 @@ int register_vlan_dev(struct net_device *dev)
279 281
280 return 0; 282 return 0;
281 283
284out_uninit_applicant:
285 if (ngrp)
286 vlan_gvrp_uninit_applicant(real_dev);
282out_free_group: 287out_free_group:
283 if (ngrp) 288 if (ngrp)
284 vlan_group_free(ngrp); 289 vlan_group_free(ngrp);
@@ -288,8 +293,7 @@ out_free_group:
288/* Attach a VLAN device to a mac address (ie Ethernet Card). 293/* Attach a VLAN device to a mac address (ie Ethernet Card).
289 * Returns 0 if the device was created or a negative error code otherwise. 294 * Returns 0 if the device was created or a negative error code otherwise.
290 */ 295 */
291static int register_vlan_device(struct net_device *real_dev, 296static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)
292 unsigned short VLAN_ID)
293{ 297{
294 struct net_device *new_dev; 298 struct net_device *new_dev;
295 struct net *net = dev_net(real_dev); 299 struct net *net = dev_net(real_dev);
@@ -297,10 +301,10 @@ static int register_vlan_device(struct net_device *real_dev,
297 char name[IFNAMSIZ]; 301 char name[IFNAMSIZ];
298 int err; 302 int err;
299 303
300 if (VLAN_ID >= VLAN_VID_MASK) 304 if (vlan_id >= VLAN_VID_MASK)
301 return -ERANGE; 305 return -ERANGE;
302 306
303 err = vlan_check_real_dev(real_dev, VLAN_ID); 307 err = vlan_check_real_dev(real_dev, vlan_id);
304 if (err < 0) 308 if (err < 0)
305 return err; 309 return err;
306 310
@@ -308,26 +312,26 @@ static int register_vlan_device(struct net_device *real_dev,
308 switch (vn->name_type) { 312 switch (vn->name_type) {
309 case VLAN_NAME_TYPE_RAW_PLUS_VID: 313 case VLAN_NAME_TYPE_RAW_PLUS_VID:
310 /* name will look like: eth1.0005 */ 314 /* name will look like: eth1.0005 */
311 snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, VLAN_ID); 315 snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, vlan_id);
312 break; 316 break;
313 case VLAN_NAME_TYPE_PLUS_VID_NO_PAD: 317 case VLAN_NAME_TYPE_PLUS_VID_NO_PAD:
314 /* Put our vlan.VID in the name. 318 /* Put our vlan.VID in the name.
315 * Name will look like: vlan5 319 * Name will look like: vlan5
316 */ 320 */
317 snprintf(name, IFNAMSIZ, "vlan%i", VLAN_ID); 321 snprintf(name, IFNAMSIZ, "vlan%i", vlan_id);
318 break; 322 break;
319 case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD: 323 case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD:
320 /* Put our vlan.VID in the name. 324 /* Put our vlan.VID in the name.
321 * Name will look like: eth0.5 325 * Name will look like: eth0.5
322 */ 326 */
323 snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, VLAN_ID); 327 snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, vlan_id);
324 break; 328 break;
325 case VLAN_NAME_TYPE_PLUS_VID: 329 case VLAN_NAME_TYPE_PLUS_VID:
326 /* Put our vlan.VID in the name. 330 /* Put our vlan.VID in the name.
327 * Name will look like: vlan0005 331 * Name will look like: vlan0005
328 */ 332 */
329 default: 333 default:
330 snprintf(name, IFNAMSIZ, "vlan%.4i", VLAN_ID); 334 snprintf(name, IFNAMSIZ, "vlan%.4i", vlan_id);
331 } 335 }
332 336
333 new_dev = alloc_netdev(sizeof(struct vlan_dev_info), name, 337 new_dev = alloc_netdev(sizeof(struct vlan_dev_info), name,
@@ -342,7 +346,7 @@ static int register_vlan_device(struct net_device *real_dev,
342 */ 346 */
343 new_dev->mtu = real_dev->mtu; 347 new_dev->mtu = real_dev->mtu;
344 348
345 vlan_dev_info(new_dev)->vlan_id = VLAN_ID; /* 1 through VLAN_VID_MASK */ 349 vlan_dev_info(new_dev)->vlan_id = vlan_id;
346 vlan_dev_info(new_dev)->real_dev = real_dev; 350 vlan_dev_info(new_dev)->real_dev = real_dev;
347 vlan_dev_info(new_dev)->dent = NULL; 351 vlan_dev_info(new_dev)->dent = NULL;
348 vlan_dev_info(new_dev)->flags = VLAN_FLAG_REORDER_HDR; 352 vlan_dev_info(new_dev)->flags = VLAN_FLAG_REORDER_HDR;
@@ -536,7 +540,6 @@ static struct notifier_block vlan_notifier_block __read_mostly = {
536static int vlan_ioctl_handler(struct net *net, void __user *arg) 540static int vlan_ioctl_handler(struct net *net, void __user *arg)
537{ 541{
538 int err; 542 int err;
539 unsigned short vid = 0;
540 struct vlan_ioctl_args args; 543 struct vlan_ioctl_args args;
541 struct net_device *dev = NULL; 544 struct net_device *dev = NULL;
542 545
@@ -563,8 +566,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
563 goto out; 566 goto out;
564 567
565 err = -EINVAL; 568 err = -EINVAL;
566 if (args.cmd != ADD_VLAN_CMD && 569 if (args.cmd != ADD_VLAN_CMD && !is_vlan_dev(dev))
567 !(dev->priv_flags & IFF_802_1Q_VLAN))
568 goto out; 570 goto out;
569 } 571 }
570 572
@@ -592,9 +594,9 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
592 err = -EPERM; 594 err = -EPERM;
593 if (!capable(CAP_NET_ADMIN)) 595 if (!capable(CAP_NET_ADMIN))
594 break; 596 break;
595 err = vlan_dev_set_vlan_flag(dev, 597 err = vlan_dev_change_flags(dev,
596 args.u.flag, 598 args.vlan_qos ? args.u.flag : 0,
597 args.vlan_qos); 599 args.u.flag);
598 break; 600 break;
599 601
600 case SET_VLAN_NAME_TYPE_CMD: 602 case SET_VLAN_NAME_TYPE_CMD:
@@ -638,8 +640,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
638 640
639 case GET_VLAN_VID_CMD: 641 case GET_VLAN_VID_CMD:
640 err = 0; 642 err = 0;
641 vlan_dev_get_vid(dev, &vid); 643 args.u.VID = vlan_dev_vlan_id(dev);
642 args.u.VID = vid;
643 if (copy_to_user(arg, &args, 644 if (copy_to_user(arg, &args,
644 sizeof(struct vlan_ioctl_args))) 645 sizeof(struct vlan_ioctl_args)))
645 err = -EFAULT; 646 err = -EFAULT;
@@ -714,14 +715,20 @@ static int __init vlan_proto_init(void)
714 if (err < 0) 715 if (err < 0)
715 goto err2; 716 goto err2;
716 717
717 err = vlan_netlink_init(); 718 err = vlan_gvrp_init();
718 if (err < 0) 719 if (err < 0)
719 goto err3; 720 goto err3;
720 721
722 err = vlan_netlink_init();
723 if (err < 0)
724 goto err4;
725
721 dev_add_pack(&vlan_packet_type); 726 dev_add_pack(&vlan_packet_type);
722 vlan_ioctl_set(vlan_ioctl_handler); 727 vlan_ioctl_set(vlan_ioctl_handler);
723 return 0; 728 return 0;
724 729
730err4:
731 vlan_gvrp_uninit();
725err3: 732err3:
726 unregister_netdevice_notifier(&vlan_notifier_block); 733 unregister_netdevice_notifier(&vlan_notifier_block);
727err2: 734err2:
@@ -746,8 +753,9 @@ static void __exit vlan_cleanup_module(void)
746 BUG_ON(!hlist_empty(&vlan_group_hash[i])); 753 BUG_ON(!hlist_empty(&vlan_group_hash[i]));
747 754
748 unregister_pernet_gen_device(vlan_net_id, &vlan_net_ops); 755 unregister_pernet_gen_device(vlan_net_id, &vlan_net_ops);
749
750 synchronize_net(); 756 synchronize_net();
757
758 vlan_gvrp_uninit();
751} 759}
752 760
753module_init(vlan_proto_init); 761module_init(vlan_proto_init);
diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h
index 5229a72c7ea1..a6603a4d917f 100644
--- a/net/8021q/vlan.h
+++ b/net/8021q/vlan.h
@@ -3,6 +3,55 @@
3 3
4#include <linux/if_vlan.h> 4#include <linux/if_vlan.h>
5 5
6
7/**
8 * struct vlan_priority_tci_mapping - vlan egress priority mappings
9 * @priority: skb priority
10 * @vlan_qos: vlan priority: (skb->priority << 13) & 0xE000
11 * @next: pointer to next struct
12 */
13struct vlan_priority_tci_mapping {
14 u32 priority;
15 u16 vlan_qos;
16 struct vlan_priority_tci_mapping *next;
17};
18
19/**
20 * struct vlan_dev_info - VLAN private device data
21 * @nr_ingress_mappings: number of ingress priority mappings
22 * @ingress_priority_map: ingress priority mappings
23 * @nr_egress_mappings: number of egress priority mappings
24 * @egress_priority_map: hash of egress priority mappings
25 * @vlan_id: VLAN identifier
26 * @flags: device flags
27 * @real_dev: underlying netdevice
28 * @real_dev_addr: address of underlying netdevice
29 * @dent: proc dir entry
30 * @cnt_inc_headroom_on_tx: statistic - number of skb expansions on TX
31 * @cnt_encap_on_xmit: statistic - number of skb encapsulations on TX
32 */
33struct vlan_dev_info {
34 unsigned int nr_ingress_mappings;
35 u32 ingress_priority_map[8];
36 unsigned int nr_egress_mappings;
37 struct vlan_priority_tci_mapping *egress_priority_map[16];
38
39 u16 vlan_id;
40 u16 flags;
41
42 struct net_device *real_dev;
43 unsigned char real_dev_addr[ETH_ALEN];
44
45 struct proc_dir_entry *dent;
46 unsigned long cnt_inc_headroom_on_tx;
47 unsigned long cnt_encap_on_xmit;
48};
49
50static inline struct vlan_dev_info *vlan_dev_info(const struct net_device *dev)
51{
52 return netdev_priv(dev);
53}
54
6#define VLAN_GRP_HASH_SHIFT 5 55#define VLAN_GRP_HASH_SHIFT 5
7#define VLAN_GRP_HASH_SIZE (1 << VLAN_GRP_HASH_SHIFT) 56#define VLAN_GRP_HASH_SIZE (1 << VLAN_GRP_HASH_SHIFT)
8#define VLAN_GRP_HASH_MASK (VLAN_GRP_HASH_SIZE - 1) 57#define VLAN_GRP_HASH_MASK (VLAN_GRP_HASH_SIZE - 1)
@@ -18,26 +67,47 @@
18 * Must be invoked with rcu_read_lock (ie preempt disabled) 67 * Must be invoked with rcu_read_lock (ie preempt disabled)
19 * or with RTNL. 68 * or with RTNL.
20 */ 69 */
21struct net_device *__find_vlan_dev(struct net_device *real_dev, 70struct net_device *__find_vlan_dev(struct net_device *real_dev, u16 vlan_id);
22 unsigned short VID); /* vlan.c */
23 71
24/* found in vlan_dev.c */ 72/* found in vlan_dev.c */
25int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev, 73int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
26 struct packet_type *ptype, struct net_device *orig_dev); 74 struct packet_type *ptype, struct net_device *orig_dev);
27void vlan_dev_set_ingress_priority(const struct net_device *dev, 75void vlan_dev_set_ingress_priority(const struct net_device *dev,
28 u32 skb_prio, short vlan_prio); 76 u32 skb_prio, u16 vlan_prio);
29int vlan_dev_set_egress_priority(const struct net_device *dev, 77int vlan_dev_set_egress_priority(const struct net_device *dev,
30 u32 skb_prio, short vlan_prio); 78 u32 skb_prio, u16 vlan_prio);
31int vlan_dev_set_vlan_flag(const struct net_device *dev, 79int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
32 u32 flag, short flag_val);
33void vlan_dev_get_realdev_name(const struct net_device *dev, char *result); 80void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
34void vlan_dev_get_vid(const struct net_device *dev, unsigned short *result);
35 81
36int vlan_check_real_dev(struct net_device *real_dev, unsigned short vlan_id); 82int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id);
37void vlan_setup(struct net_device *dev); 83void vlan_setup(struct net_device *dev);
38int register_vlan_dev(struct net_device *dev); 84int register_vlan_dev(struct net_device *dev);
39void unregister_vlan_dev(struct net_device *dev); 85void unregister_vlan_dev(struct net_device *dev);
40 86
87static inline u32 vlan_get_ingress_priority(struct net_device *dev,
88 u16 vlan_tci)
89{
90 struct vlan_dev_info *vip = vlan_dev_info(dev);
91
92 return vip->ingress_priority_map[(vlan_tci >> 13) & 0x7];
93}
94
95#ifdef CONFIG_VLAN_8021Q_GVRP
96extern int vlan_gvrp_request_join(const struct net_device *dev);
97extern void vlan_gvrp_request_leave(const struct net_device *dev);
98extern int vlan_gvrp_init_applicant(struct net_device *dev);
99extern void vlan_gvrp_uninit_applicant(struct net_device *dev);
100extern int vlan_gvrp_init(void);
101extern void vlan_gvrp_uninit(void);
102#else
103static inline int vlan_gvrp_request_join(const struct net_device *dev) { return 0; }
104static inline void vlan_gvrp_request_leave(const struct net_device *dev) {}
105static inline int vlan_gvrp_init_applicant(struct net_device *dev) { return 0; }
106static inline void vlan_gvrp_uninit_applicant(struct net_device *dev) {}
107static inline int vlan_gvrp_init(void) { return 0; }
108static inline void vlan_gvrp_uninit(void) {}
109#endif
110
41int vlan_netlink_init(void); 111int vlan_netlink_init(void);
42void vlan_netlink_fini(void); 112void vlan_netlink_fini(void);
43 113
diff --git a/net/8021q/vlan_core.c b/net/8021q/vlan_core.c
new file mode 100644
index 000000000000..916061f681b6
--- /dev/null
+++ b/net/8021q/vlan_core.c
@@ -0,0 +1,64 @@
1#include <linux/skbuff.h>
2#include <linux/netdevice.h>
3#include <linux/if_vlan.h>
4#include "vlan.h"
5
6/* VLAN rx hw acceleration helper. This acts like netif_{rx,receive_skb}(). */
7int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
8 u16 vlan_tci, int polling)
9{
10 struct net_device_stats *stats;
11
12 if (skb_bond_should_drop(skb)) {
13 dev_kfree_skb_any(skb);
14 return NET_RX_DROP;
15 }
16
17 skb->vlan_tci = vlan_tci;
18 netif_nit_deliver(skb);
19
20 skb->dev = vlan_group_get_device(grp, vlan_tci & VLAN_VID_MASK);
21 if (skb->dev == NULL) {
22 dev_kfree_skb_any(skb);
23 /* Not NET_RX_DROP, this is not being dropped
24 * due to congestion. */
25 return NET_RX_SUCCESS;
26 }
27 skb->dev->last_rx = jiffies;
28 skb->vlan_tci = 0;
29
30 stats = &skb->dev->stats;
31 stats->rx_packets++;
32 stats->rx_bytes += skb->len;
33
34 skb->priority = vlan_get_ingress_priority(skb->dev, vlan_tci);
35 switch (skb->pkt_type) {
36 case PACKET_BROADCAST:
37 break;
38 case PACKET_MULTICAST:
39 stats->multicast++;
40 break;
41 case PACKET_OTHERHOST:
42 /* Our lower layer thinks this is not local, let's make sure.
43 * This allows the VLAN to have a different MAC than the
44 * underlying device, and still route correctly. */
45 if (!compare_ether_addr(eth_hdr(skb)->h_dest,
46 skb->dev->dev_addr))
47 skb->pkt_type = PACKET_HOST;
48 break;
49 };
50 return (polling ? netif_receive_skb(skb) : netif_rx(skb));
51}
52EXPORT_SYMBOL(__vlan_hwaccel_rx);
53
54struct net_device *vlan_dev_real_dev(const struct net_device *dev)
55{
56 return vlan_dev_info(dev)->real_dev;
57}
58EXPORT_SYMBOL_GPL(vlan_dev_real_dev);
59
60u16 vlan_dev_vlan_id(const struct net_device *dev)
61{
62 return vlan_dev_info(dev)->vlan_id;
63}
64EXPORT_SYMBOL_GPL(vlan_dev_vlan_id);
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
index 5d055c242ed8..f42bc2b26b85 100644
--- a/net/8021q/vlan_dev.c
+++ b/net/8021q/vlan_dev.c
@@ -21,21 +21,15 @@
21 */ 21 */
22 22
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/mm.h>
25#include <linux/in.h>
26#include <linux/init.h>
27#include <asm/uaccess.h> /* for copy_from_user */
28#include <linux/skbuff.h> 24#include <linux/skbuff.h>
29#include <linux/netdevice.h> 25#include <linux/netdevice.h>
30#include <linux/etherdevice.h> 26#include <linux/etherdevice.h>
31#include <net/datalink.h> 27#include <linux/ethtool.h>
32#include <net/p8022.h>
33#include <net/arp.h> 28#include <net/arp.h>
34 29
35#include "vlan.h" 30#include "vlan.h"
36#include "vlanproc.h" 31#include "vlanproc.h"
37#include <linux/if_vlan.h> 32#include <linux/if_vlan.h>
38#include <net/ip.h>
39 33
40/* 34/*
41 * Rebuild the Ethernet MAC header. This is called after an ARP 35 * Rebuild the Ethernet MAC header. This is called after an ARP
@@ -73,11 +67,8 @@ static int vlan_dev_rebuild_header(struct sk_buff *skb)
73static inline struct sk_buff *vlan_check_reorder_header(struct sk_buff *skb) 67static inline struct sk_buff *vlan_check_reorder_header(struct sk_buff *skb)
74{ 68{
75 if (vlan_dev_info(skb->dev)->flags & VLAN_FLAG_REORDER_HDR) { 69 if (vlan_dev_info(skb->dev)->flags & VLAN_FLAG_REORDER_HDR) {
76 if (skb_shared(skb) || skb_cloned(skb)) { 70 if (skb_cow(skb, skb_headroom(skb)) < 0)
77 struct sk_buff *nskb = skb_copy(skb, GFP_ATOMIC); 71 skb = NULL;
78 kfree_skb(skb);
79 skb = nskb;
80 }
81 if (skb) { 72 if (skb) {
82 /* Lifted from Gleb's VLAN code... */ 73 /* Lifted from Gleb's VLAN code... */
83 memmove(skb->data - ETH_HLEN, 74 memmove(skb->data - ETH_HLEN,
@@ -149,9 +140,9 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
149 struct packet_type *ptype, struct net_device *orig_dev) 140 struct packet_type *ptype, struct net_device *orig_dev)
150{ 141{
151 struct vlan_hdr *vhdr; 142 struct vlan_hdr *vhdr;
152 unsigned short vid;
153 struct net_device_stats *stats; 143 struct net_device_stats *stats;
154 unsigned short vlan_TCI; 144 u16 vlan_id;
145 u16 vlan_tci;
155 146
156 skb = skb_share_check(skb, GFP_ATOMIC); 147 skb = skb_share_check(skb, GFP_ATOMIC);
157 if (skb == NULL) 148 if (skb == NULL)
@@ -161,14 +152,14 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
161 goto err_free; 152 goto err_free;
162 153
163 vhdr = (struct vlan_hdr *)skb->data; 154 vhdr = (struct vlan_hdr *)skb->data;
164 vlan_TCI = ntohs(vhdr->h_vlan_TCI); 155 vlan_tci = ntohs(vhdr->h_vlan_TCI);
165 vid = (vlan_TCI & VLAN_VID_MASK); 156 vlan_id = vlan_tci & VLAN_VID_MASK;
166 157
167 rcu_read_lock(); 158 rcu_read_lock();
168 skb->dev = __find_vlan_dev(dev, vid); 159 skb->dev = __find_vlan_dev(dev, vlan_id);
169 if (!skb->dev) { 160 if (!skb->dev) {
170 pr_debug("%s: ERROR: No net_device for VID: %u on dev: %s\n", 161 pr_debug("%s: ERROR: No net_device for VID: %u on dev: %s\n",
171 __func__, (unsigned int)vid, dev->name); 162 __func__, vlan_id, dev->name);
172 goto err_unlock; 163 goto err_unlock;
173 } 164 }
174 165
@@ -180,11 +171,10 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
180 171
181 skb_pull_rcsum(skb, VLAN_HLEN); 172 skb_pull_rcsum(skb, VLAN_HLEN);
182 173
183 skb->priority = vlan_get_ingress_priority(skb->dev, 174 skb->priority = vlan_get_ingress_priority(skb->dev, vlan_tci);
184 ntohs(vhdr->h_vlan_TCI));
185 175
186 pr_debug("%s: priority: %u for TCI: %hu\n", 176 pr_debug("%s: priority: %u for TCI: %hu\n",
187 __func__, skb->priority, ntohs(vhdr->h_vlan_TCI)); 177 __func__, skb->priority, vlan_tci);
188 178
189 switch (skb->pkt_type) { 179 switch (skb->pkt_type) {
190 case PACKET_BROADCAST: /* Yeah, stats collect these together.. */ 180 case PACKET_BROADCAST: /* Yeah, stats collect these together.. */
@@ -227,7 +217,7 @@ err_free:
227 return NET_RX_DROP; 217 return NET_RX_DROP;
228} 218}
229 219
230static inline unsigned short 220static inline u16
231vlan_dev_get_egress_qos_mask(struct net_device *dev, struct sk_buff *skb) 221vlan_dev_get_egress_qos_mask(struct net_device *dev, struct sk_buff *skb)
232{ 222{
233 struct vlan_priority_tci_mapping *mp; 223 struct vlan_priority_tci_mapping *mp;
@@ -259,103 +249,44 @@ static int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,
259 unsigned int len) 249 unsigned int len)
260{ 250{
261 struct vlan_hdr *vhdr; 251 struct vlan_hdr *vhdr;
262 unsigned short veth_TCI = 0; 252 unsigned int vhdrlen = 0;
263 int rc = 0; 253 u16 vlan_tci = 0;
264 int build_vlan_header = 0; 254 int rc;
265 struct net_device *vdev = dev;
266
267 pr_debug("%s: skb: %p type: %hx len: %u vlan_id: %hx, daddr: %p\n",
268 __func__, skb, type, len, vlan_dev_info(dev)->vlan_id,
269 daddr);
270
271 /* build vlan header only if re_order_header flag is NOT set. This
272 * fixes some programs that get confused when they see a VLAN device
273 * sending a frame that is VLAN encoded (the consensus is that the VLAN
274 * device should look completely like an Ethernet device when the
275 * REORDER_HEADER flag is set) The drawback to this is some extra
276 * header shuffling in the hard_start_xmit. Users can turn off this
277 * REORDER behaviour with the vconfig tool.
278 */
279 if (!(vlan_dev_info(dev)->flags & VLAN_FLAG_REORDER_HDR))
280 build_vlan_header = 1;
281 255
282 if (build_vlan_header) { 256 if (WARN_ON(skb_headroom(skb) < dev->hard_header_len))
283 vhdr = (struct vlan_hdr *) skb_push(skb, VLAN_HLEN); 257 return -ENOSPC;
284 258
285 /* build the four bytes that make this a VLAN header. */ 259 if (!(vlan_dev_info(dev)->flags & VLAN_FLAG_REORDER_HDR)) {
286 260 vhdr = (struct vlan_hdr *) skb_push(skb, VLAN_HLEN);
287 /* Now, construct the second two bytes. This field looks
288 * something like:
289 * usr_priority: 3 bits (high bits)
290 * CFI 1 bit
291 * VLAN ID 12 bits (low bits)
292 *
293 */
294 veth_TCI = vlan_dev_info(dev)->vlan_id;
295 veth_TCI |= vlan_dev_get_egress_qos_mask(dev, skb);
296 261
297 vhdr->h_vlan_TCI = htons(veth_TCI); 262 vlan_tci = vlan_dev_info(dev)->vlan_id;
263 vlan_tci |= vlan_dev_get_egress_qos_mask(dev, skb);
264 vhdr->h_vlan_TCI = htons(vlan_tci);
298 265
299 /* 266 /*
300 * Set the protocol type. For a packet of type ETH_P_802_3 we 267 * Set the protocol type. For a packet of type ETH_P_802_3 we
301 * put the length in here instead. It is up to the 802.2 268 * put the length in here instead. It is up to the 802.2
302 * layer to carry protocol information. 269 * layer to carry protocol information.
303 */ 270 */
304
305 if (type != ETH_P_802_3) 271 if (type != ETH_P_802_3)
306 vhdr->h_vlan_encapsulated_proto = htons(type); 272 vhdr->h_vlan_encapsulated_proto = htons(type);
307 else 273 else
308 vhdr->h_vlan_encapsulated_proto = htons(len); 274 vhdr->h_vlan_encapsulated_proto = htons(len);
309 275
310 skb->protocol = htons(ETH_P_8021Q); 276 skb->protocol = htons(ETH_P_8021Q);
311 skb_reset_network_header(skb); 277 type = ETH_P_8021Q;
278 vhdrlen = VLAN_HLEN;
312 } 279 }
313 280
314 /* Before delegating work to the lower layer, enter our MAC-address */ 281 /* Before delegating work to the lower layer, enter our MAC-address */
315 if (saddr == NULL) 282 if (saddr == NULL)
316 saddr = dev->dev_addr; 283 saddr = dev->dev_addr;
317 284
285 /* Now make the underlying real hard header */
318 dev = vlan_dev_info(dev)->real_dev; 286 dev = vlan_dev_info(dev)->real_dev;
319 287 rc = dev_hard_header(skb, dev, type, daddr, saddr, len + vhdrlen);
320 /* MPLS can send us skbuffs w/out enough space. This check will grow 288 if (rc > 0)
321 * the skb if it doesn't have enough headroom. Not a beautiful solution, 289 rc += vhdrlen;
322 * so I'll tick a counter so that users can know it's happening...
323 * If they care...
324 */
325
326 /* NOTE: This may still break if the underlying device is not the final
327 * device (and thus there are more headers to add...) It should work for
328 * good-ole-ethernet though.
329 */
330 if (skb_headroom(skb) < dev->hard_header_len) {
331 struct sk_buff *sk_tmp = skb;
332 skb = skb_realloc_headroom(sk_tmp, dev->hard_header_len);
333 kfree_skb(sk_tmp);
334 if (skb == NULL) {
335 struct net_device_stats *stats = &vdev->stats;
336 stats->tx_dropped++;
337 return -ENOMEM;
338 }
339 vlan_dev_info(vdev)->cnt_inc_headroom_on_tx++;
340 pr_debug("%s: %s: had to grow skb\n", __func__, vdev->name);
341 }
342
343 if (build_vlan_header) {
344 /* Now make the underlying real hard header */
345 rc = dev_hard_header(skb, dev, ETH_P_8021Q, daddr, saddr,
346 len + VLAN_HLEN);
347 if (rc > 0)
348 rc += VLAN_HLEN;
349 else if (rc < 0)
350 rc -= VLAN_HLEN;
351 } else
352 /* If here, then we'll just make a normal looking ethernet
353 * frame, but, the hard_start_xmit method will insert the tag
354 * (it has to be able to do this for bridged and other skbs
355 * that don't come down the protocol stack in an orderly manner.
356 */
357 rc = dev_hard_header(skb, dev, type, daddr, saddr, len);
358
359 return rc; 290 return rc;
360} 291}
361 292
@@ -369,78 +300,49 @@ static int vlan_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
369 * NOTE: THIS ASSUMES DIX ETHERNET, SPECIFICALLY NOT SUPPORTING 300 * NOTE: THIS ASSUMES DIX ETHERNET, SPECIFICALLY NOT SUPPORTING
370 * OTHER THINGS LIKE FDDI/TokenRing/802.3 SNAPs... 301 * OTHER THINGS LIKE FDDI/TokenRing/802.3 SNAPs...
371 */ 302 */
372
373 if (veth->h_vlan_proto != htons(ETH_P_8021Q) || 303 if (veth->h_vlan_proto != htons(ETH_P_8021Q) ||
374 vlan_dev_info(dev)->flags & VLAN_FLAG_REORDER_HDR) { 304 vlan_dev_info(dev)->flags & VLAN_FLAG_REORDER_HDR) {
375 int orig_headroom = skb_headroom(skb); 305 unsigned int orig_headroom = skb_headroom(skb);
376 unsigned short veth_TCI; 306 u16 vlan_tci;
377 307
378 /* This is not a VLAN frame...but we can fix that! */
379 vlan_dev_info(dev)->cnt_encap_on_xmit++; 308 vlan_dev_info(dev)->cnt_encap_on_xmit++;
380 309
381 pr_debug("%s: proto to encap: 0x%hx\n", 310 vlan_tci = vlan_dev_info(dev)->vlan_id;
382 __func__, ntohs(veth->h_vlan_proto)); 311 vlan_tci |= vlan_dev_get_egress_qos_mask(dev, skb);
383 /* Construct the second two bytes. This field looks something 312 skb = __vlan_put_tag(skb, vlan_tci);
384 * like:
385 * usr_priority: 3 bits (high bits)
386 * CFI 1 bit
387 * VLAN ID 12 bits (low bits)
388 */
389 veth_TCI = vlan_dev_info(dev)->vlan_id;
390 veth_TCI |= vlan_dev_get_egress_qos_mask(dev, skb);
391
392 skb = __vlan_put_tag(skb, veth_TCI);
393 if (!skb) { 313 if (!skb) {
394 stats->tx_dropped++; 314 stats->tx_dropped++;
395 return 0; 315 return NETDEV_TX_OK;
396 } 316 }
397 317
398 if (orig_headroom < VLAN_HLEN) 318 if (orig_headroom < VLAN_HLEN)
399 vlan_dev_info(dev)->cnt_inc_headroom_on_tx++; 319 vlan_dev_info(dev)->cnt_inc_headroom_on_tx++;
400 } 320 }
401 321
402 pr_debug("%s: about to send skb: %p to dev: %s\n", 322 stats->tx_packets++;
403 __func__, skb, skb->dev->name);
404 pr_debug(" " MAC_FMT " " MAC_FMT " %4hx %4hx %4hx\n",
405 veth->h_dest[0], veth->h_dest[1], veth->h_dest[2],
406 veth->h_dest[3], veth->h_dest[4], veth->h_dest[5],
407 veth->h_source[0], veth->h_source[1], veth->h_source[2],
408 veth->h_source[3], veth->h_source[4], veth->h_source[5],
409 veth->h_vlan_proto, veth->h_vlan_TCI,
410 veth->h_vlan_encapsulated_proto);
411
412 stats->tx_packets++; /* for statics only */
413 stats->tx_bytes += skb->len; 323 stats->tx_bytes += skb->len;
414 324
415 skb->dev = vlan_dev_info(dev)->real_dev; 325 skb->dev = vlan_dev_info(dev)->real_dev;
416 dev_queue_xmit(skb); 326 dev_queue_xmit(skb);
417 327 return NETDEV_TX_OK;
418 return 0;
419} 328}
420 329
421static int vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb, 330static int vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb,
422 struct net_device *dev) 331 struct net_device *dev)
423{ 332{
424 struct net_device_stats *stats = &dev->stats; 333 struct net_device_stats *stats = &dev->stats;
425 unsigned short veth_TCI; 334 u16 vlan_tci;
426 335
427 /* Construct the second two bytes. This field looks something 336 vlan_tci = vlan_dev_info(dev)->vlan_id;
428 * like: 337 vlan_tci |= vlan_dev_get_egress_qos_mask(dev, skb);
429 * usr_priority: 3 bits (high bits) 338 skb = __vlan_hwaccel_put_tag(skb, vlan_tci);
430 * CFI 1 bit
431 * VLAN ID 12 bits (low bits)
432 */
433 veth_TCI = vlan_dev_info(dev)->vlan_id;
434 veth_TCI |= vlan_dev_get_egress_qos_mask(dev, skb);
435 skb = __vlan_hwaccel_put_tag(skb, veth_TCI);
436 339
437 stats->tx_packets++; 340 stats->tx_packets++;
438 stats->tx_bytes += skb->len; 341 stats->tx_bytes += skb->len;
439 342
440 skb->dev = vlan_dev_info(dev)->real_dev; 343 skb->dev = vlan_dev_info(dev)->real_dev;
441 dev_queue_xmit(skb); 344 dev_queue_xmit(skb);
442 345 return NETDEV_TX_OK;
443 return 0;
444} 346}
445 347
446static int vlan_dev_change_mtu(struct net_device *dev, int new_mtu) 348static int vlan_dev_change_mtu(struct net_device *dev, int new_mtu)
@@ -457,7 +359,7 @@ static int vlan_dev_change_mtu(struct net_device *dev, int new_mtu)
457} 359}
458 360
459void vlan_dev_set_ingress_priority(const struct net_device *dev, 361void vlan_dev_set_ingress_priority(const struct net_device *dev,
460 u32 skb_prio, short vlan_prio) 362 u32 skb_prio, u16 vlan_prio)
461{ 363{
462 struct vlan_dev_info *vlan = vlan_dev_info(dev); 364 struct vlan_dev_info *vlan = vlan_dev_info(dev);
463 365
@@ -470,7 +372,7 @@ void vlan_dev_set_ingress_priority(const struct net_device *dev,
470} 372}
471 373
472int vlan_dev_set_egress_priority(const struct net_device *dev, 374int vlan_dev_set_egress_priority(const struct net_device *dev,
473 u32 skb_prio, short vlan_prio) 375 u32 skb_prio, u16 vlan_prio)
474{ 376{
475 struct vlan_dev_info *vlan = vlan_dev_info(dev); 377 struct vlan_dev_info *vlan = vlan_dev_info(dev);
476 struct vlan_priority_tci_mapping *mp = NULL; 378 struct vlan_priority_tci_mapping *mp = NULL;
@@ -507,18 +409,23 @@ int vlan_dev_set_egress_priority(const struct net_device *dev,
507} 409}
508 410
509/* Flags are defined in the vlan_flags enum in include/linux/if_vlan.h file. */ 411/* Flags are defined in the vlan_flags enum in include/linux/if_vlan.h file. */
510int vlan_dev_set_vlan_flag(const struct net_device *dev, 412int vlan_dev_change_flags(const struct net_device *dev, u32 flags, u32 mask)
511 u32 flag, short flag_val)
512{ 413{
513 /* verify flag is supported */ 414 struct vlan_dev_info *vlan = vlan_dev_info(dev);
514 if (flag == VLAN_FLAG_REORDER_HDR) { 415 u32 old_flags = vlan->flags;
515 if (flag_val) 416
516 vlan_dev_info(dev)->flags |= VLAN_FLAG_REORDER_HDR; 417 if (mask & ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP))
418 return -EINVAL;
419
420 vlan->flags = (old_flags & ~mask) | (flags & mask);
421
422 if (netif_running(dev) && (vlan->flags ^ old_flags) & VLAN_FLAG_GVRP) {
423 if (vlan->flags & VLAN_FLAG_GVRP)
424 vlan_gvrp_request_join(dev);
517 else 425 else
518 vlan_dev_info(dev)->flags &= ~VLAN_FLAG_REORDER_HDR; 426 vlan_gvrp_request_leave(dev);
519 return 0;
520 } 427 }
521 return -EINVAL; 428 return 0;
522} 429}
523 430
524void vlan_dev_get_realdev_name(const struct net_device *dev, char *result) 431void vlan_dev_get_realdev_name(const struct net_device *dev, char *result)
@@ -526,11 +433,6 @@ void vlan_dev_get_realdev_name(const struct net_device *dev, char *result)
526 strncpy(result, vlan_dev_info(dev)->real_dev->name, 23); 433 strncpy(result, vlan_dev_info(dev)->real_dev->name, 23);
527} 434}
528 435
529void vlan_dev_get_vid(const struct net_device *dev, unsigned short *result)
530{
531 *result = vlan_dev_info(dev)->vlan_id;
532}
533
534static int vlan_dev_open(struct net_device *dev) 436static int vlan_dev_open(struct net_device *dev)
535{ 437{
536 struct vlan_dev_info *vlan = vlan_dev_info(dev); 438 struct vlan_dev_info *vlan = vlan_dev_info(dev);
@@ -543,21 +445,44 @@ static int vlan_dev_open(struct net_device *dev)
543 if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) { 445 if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) {
544 err = dev_unicast_add(real_dev, dev->dev_addr, ETH_ALEN); 446 err = dev_unicast_add(real_dev, dev->dev_addr, ETH_ALEN);
545 if (err < 0) 447 if (err < 0)
546 return err; 448 goto out;
449 }
450
451 if (dev->flags & IFF_ALLMULTI) {
452 err = dev_set_allmulti(real_dev, 1);
453 if (err < 0)
454 goto del_unicast;
547 } 455 }
456 if (dev->flags & IFF_PROMISC) {
457 err = dev_set_promiscuity(real_dev, 1);
458 if (err < 0)
459 goto clear_allmulti;
460 }
461
548 memcpy(vlan->real_dev_addr, real_dev->dev_addr, ETH_ALEN); 462 memcpy(vlan->real_dev_addr, real_dev->dev_addr, ETH_ALEN);
549 463
550 if (dev->flags & IFF_ALLMULTI) 464 if (vlan->flags & VLAN_FLAG_GVRP)
551 dev_set_allmulti(real_dev, 1); 465 vlan_gvrp_request_join(dev);
552 if (dev->flags & IFF_PROMISC)
553 dev_set_promiscuity(real_dev, 1);
554 466
555 return 0; 467 return 0;
468
469clear_allmulti:
470 if (dev->flags & IFF_ALLMULTI)
471 dev_set_allmulti(real_dev, -1);
472del_unicast:
473 if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr))
474 dev_unicast_delete(real_dev, dev->dev_addr, ETH_ALEN);
475out:
476 return err;
556} 477}
557 478
558static int vlan_dev_stop(struct net_device *dev) 479static int vlan_dev_stop(struct net_device *dev)
559{ 480{
560 struct net_device *real_dev = vlan_dev_info(dev)->real_dev; 481 struct vlan_dev_info *vlan = vlan_dev_info(dev);
482 struct net_device *real_dev = vlan->real_dev;
483
484 if (vlan->flags & VLAN_FLAG_GVRP)
485 vlan_gvrp_request_leave(dev);
561 486
562 dev_mc_unsync(real_dev, dev); 487 dev_mc_unsync(real_dev, dev);
563 dev_unicast_unsync(real_dev, dev); 488 dev_unicast_unsync(real_dev, dev);
@@ -645,6 +570,20 @@ static void vlan_dev_set_rx_mode(struct net_device *vlan_dev)
645 */ 570 */
646static struct lock_class_key vlan_netdev_xmit_lock_key; 571static struct lock_class_key vlan_netdev_xmit_lock_key;
647 572
573static void vlan_dev_set_lockdep_one(struct net_device *dev,
574 struct netdev_queue *txq,
575 void *_subclass)
576{
577 lockdep_set_class_and_subclass(&txq->_xmit_lock,
578 &vlan_netdev_xmit_lock_key,
579 *(int *)_subclass);
580}
581
582static void vlan_dev_set_lockdep_class(struct net_device *dev, int subclass)
583{
584 netdev_for_each_tx_queue(dev, vlan_dev_set_lockdep_one, &subclass);
585}
586
648static const struct header_ops vlan_header_ops = { 587static const struct header_ops vlan_header_ops = {
649 .create = vlan_dev_hard_header, 588 .create = vlan_dev_hard_header,
650 .rebuild = vlan_dev_rebuild_header, 589 .rebuild = vlan_dev_rebuild_header,
@@ -683,11 +622,10 @@ static int vlan_dev_init(struct net_device *dev)
683 dev->hard_start_xmit = vlan_dev_hard_start_xmit; 622 dev->hard_start_xmit = vlan_dev_hard_start_xmit;
684 } 623 }
685 624
686 if (real_dev->priv_flags & IFF_802_1Q_VLAN) 625 if (is_vlan_dev(real_dev))
687 subclass = 1; 626 subclass = 1;
688 627
689 lockdep_set_class_and_subclass(&dev->_xmit_lock, 628 vlan_dev_set_lockdep_class(dev, subclass);
690 &vlan_netdev_xmit_lock_key, subclass);
691 return 0; 629 return 0;
692} 630}
693 631
@@ -705,6 +643,35 @@ static void vlan_dev_uninit(struct net_device *dev)
705 } 643 }
706} 644}
707 645
646static u32 vlan_ethtool_get_rx_csum(struct net_device *dev)
647{
648 const struct vlan_dev_info *vlan = vlan_dev_info(dev);
649 struct net_device *real_dev = vlan->real_dev;
650
651 if (real_dev->ethtool_ops == NULL ||
652 real_dev->ethtool_ops->get_rx_csum == NULL)
653 return 0;
654 return real_dev->ethtool_ops->get_rx_csum(real_dev);
655}
656
657static u32 vlan_ethtool_get_flags(struct net_device *dev)
658{
659 const struct vlan_dev_info *vlan = vlan_dev_info(dev);
660 struct net_device *real_dev = vlan->real_dev;
661
662 if (!(real_dev->features & NETIF_F_HW_VLAN_RX) ||
663 real_dev->ethtool_ops == NULL ||
664 real_dev->ethtool_ops->get_flags == NULL)
665 return 0;
666 return real_dev->ethtool_ops->get_flags(real_dev);
667}
668
669static const struct ethtool_ops vlan_ethtool_ops = {
670 .get_link = ethtool_op_get_link,
671 .get_rx_csum = vlan_ethtool_get_rx_csum,
672 .get_flags = vlan_ethtool_get_flags,
673};
674
708void vlan_setup(struct net_device *dev) 675void vlan_setup(struct net_device *dev)
709{ 676{
710 ether_setup(dev); 677 ether_setup(dev);
@@ -723,6 +690,7 @@ void vlan_setup(struct net_device *dev)
723 dev->change_rx_flags = vlan_dev_change_rx_flags; 690 dev->change_rx_flags = vlan_dev_change_rx_flags;
724 dev->do_ioctl = vlan_dev_ioctl; 691 dev->do_ioctl = vlan_dev_ioctl;
725 dev->destructor = free_netdev; 692 dev->destructor = free_netdev;
693 dev->ethtool_ops = &vlan_ethtool_ops;
726 694
727 memset(dev->broadcast, 0, ETH_ALEN); 695 memset(dev->broadcast, 0, ETH_ALEN);
728} 696}
diff --git a/net/8021q/vlan_gvrp.c b/net/8021q/vlan_gvrp.c
new file mode 100644
index 000000000000..061ceceeef12
--- /dev/null
+++ b/net/8021q/vlan_gvrp.c
@@ -0,0 +1,66 @@
1/*
2 * IEEE 802.1Q GARP VLAN Registration Protocol (GVRP)
3 *
4 * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
9 */
10#include <linux/types.h>
11#include <linux/if_vlan.h>
12#include <net/garp.h>
13#include "vlan.h"
14
15#define GARP_GVRP_ADDRESS { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x21 }
16
17enum gvrp_attributes {
18 GVRP_ATTR_INVALID,
19 GVRP_ATTR_VID,
20 __GVRP_ATTR_MAX
21};
22#define GVRP_ATTR_MAX (__GVRP_ATTR_MAX - 1)
23
24static struct garp_application vlan_gvrp_app __read_mostly = {
25 .proto.group_address = GARP_GVRP_ADDRESS,
26 .maxattr = GVRP_ATTR_MAX,
27 .type = GARP_APPLICATION_GVRP,
28};
29
30int vlan_gvrp_request_join(const struct net_device *dev)
31{
32 const struct vlan_dev_info *vlan = vlan_dev_info(dev);
33 __be16 vlan_id = htons(vlan->vlan_id);
34
35 return garp_request_join(vlan->real_dev, &vlan_gvrp_app,
36 &vlan_id, sizeof(vlan_id), GVRP_ATTR_VID);
37}
38
39void vlan_gvrp_request_leave(const struct net_device *dev)
40{
41 const struct vlan_dev_info *vlan = vlan_dev_info(dev);
42 __be16 vlan_id = htons(vlan->vlan_id);
43
44 garp_request_leave(vlan->real_dev, &vlan_gvrp_app,
45 &vlan_id, sizeof(vlan_id), GVRP_ATTR_VID);
46}
47
48int vlan_gvrp_init_applicant(struct net_device *dev)
49{
50 return garp_init_applicant(dev, &vlan_gvrp_app);
51}
52
53void vlan_gvrp_uninit_applicant(struct net_device *dev)
54{
55 garp_uninit_applicant(dev, &vlan_gvrp_app);
56}
57
58int __init vlan_gvrp_init(void)
59{
60 return garp_register_application(&vlan_gvrp_app);
61}
62
63void vlan_gvrp_uninit(void)
64{
65 garp_unregister_application(&vlan_gvrp_app);
66}
diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
index c93e69ec28ed..e9c91dcecc9b 100644
--- a/net/8021q/vlan_netlink.c
+++ b/net/8021q/vlan_netlink.c
@@ -59,7 +59,8 @@ static int vlan_validate(struct nlattr *tb[], struct nlattr *data[])
59 } 59 }
60 if (data[IFLA_VLAN_FLAGS]) { 60 if (data[IFLA_VLAN_FLAGS]) {
61 flags = nla_data(data[IFLA_VLAN_FLAGS]); 61 flags = nla_data(data[IFLA_VLAN_FLAGS]);
62 if ((flags->flags & flags->mask) & ~VLAN_FLAG_REORDER_HDR) 62 if ((flags->flags & flags->mask) &
63 ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP))
63 return -EINVAL; 64 return -EINVAL;
64 } 65 }
65 66
@@ -75,7 +76,6 @@ static int vlan_validate(struct nlattr *tb[], struct nlattr *data[])
75static int vlan_changelink(struct net_device *dev, 76static int vlan_changelink(struct net_device *dev,
76 struct nlattr *tb[], struct nlattr *data[]) 77 struct nlattr *tb[], struct nlattr *data[])
77{ 78{
78 struct vlan_dev_info *vlan = vlan_dev_info(dev);
79 struct ifla_vlan_flags *flags; 79 struct ifla_vlan_flags *flags;
80 struct ifla_vlan_qos_mapping *m; 80 struct ifla_vlan_qos_mapping *m;
81 struct nlattr *attr; 81 struct nlattr *attr;
@@ -83,8 +83,7 @@ static int vlan_changelink(struct net_device *dev,
83 83
84 if (data[IFLA_VLAN_FLAGS]) { 84 if (data[IFLA_VLAN_FLAGS]) {
85 flags = nla_data(data[IFLA_VLAN_FLAGS]); 85 flags = nla_data(data[IFLA_VLAN_FLAGS]);
86 vlan->flags = (vlan->flags & ~flags->mask) | 86 vlan_dev_change_flags(dev, flags->flags, flags->mask);
87 (flags->flags & flags->mask);
88 } 87 }
89 if (data[IFLA_VLAN_INGRESS_QOS]) { 88 if (data[IFLA_VLAN_INGRESS_QOS]) {
90 nla_for_each_nested(attr, data[IFLA_VLAN_INGRESS_QOS], rem) { 89 nla_for_each_nested(attr, data[IFLA_VLAN_INGRESS_QOS], rem) {
diff --git a/net/8021q/vlanproc.c b/net/8021q/vlanproc.c
index 08b54b593d56..0feefa4e1a4b 100644
--- a/net/8021q/vlanproc.c
+++ b/net/8021q/vlanproc.c
@@ -18,16 +18,9 @@
18 *****************************************************************************/ 18 *****************************************************************************/
19 19
20#include <linux/module.h> 20#include <linux/module.h>
21#include <linux/stddef.h> /* offsetof(), etc. */ 21#include <linux/errno.h>
22#include <linux/errno.h> /* return codes */
23#include <linux/kernel.h> 22#include <linux/kernel.h>
24#include <linux/slab.h> /* kmalloc(), kfree() */ 23#include <linux/string.h>
25#include <linux/mm.h>
26#include <linux/string.h> /* inline mem*, str* functions */
27#include <linux/init.h> /* __initfunc et al. */
28#include <asm/byteorder.h> /* htons(), etc. */
29#include <asm/uaccess.h> /* copy_to_user */
30#include <asm/io.h>
31#include <linux/proc_fs.h> 24#include <linux/proc_fs.h>
32#include <linux/seq_file.h> 25#include <linux/seq_file.h>
33#include <linux/fs.h> 26#include <linux/fs.h>
@@ -290,7 +283,7 @@ static int vlandev_seq_show(struct seq_file *seq, void *offset)
290 static const char fmt[] = "%30s %12lu\n"; 283 static const char fmt[] = "%30s %12lu\n";
291 int i; 284 int i;
292 285
293 if (!(vlandev->priv_flags & IFF_802_1Q_VLAN)) 286 if (!is_vlan_dev(vlandev))
294 return 0; 287 return 0;
295 288
296 seq_printf(seq, 289 seq_printf(seq,