aboutsummaryrefslogtreecommitdiffstats
path: root/net/8021q
diff options
context:
space:
mode:
Diffstat (limited to 'net/8021q')
-rw-r--r--net/8021q/Makefile12
-rw-r--r--net/8021q/vlan.c774
-rw-r--r--net/8021q/vlan.h72
-rw-r--r--net/8021q/vlan_dev.c890
-rw-r--r--net/8021q/vlanproc.c357
-rw-r--r--net/8021q/vlanproc.h19
6 files changed, 2124 insertions, 0 deletions
diff --git a/net/8021q/Makefile b/net/8021q/Makefile
new file mode 100644
index 000000000000..97feb44dbdce
--- /dev/null
+++ b/net/8021q/Makefile
@@ -0,0 +1,12 @@
1#
2# Makefile for the Linux VLAN layer.
3#
4
5obj-$(CONFIG_VLAN_8021Q) += 8021q.o
6
78021q-objs := vlan.o vlan_dev.o
8
9ifeq ($(CONFIG_PROC_FS),y)
108021q-objs += vlanproc.o
11endif
12
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
new file mode 100644
index 000000000000..1f6d31670bc7
--- /dev/null
+++ b/net/8021q/vlan.c
@@ -0,0 +1,774 @@
1/*
2 * INET 802.1Q VLAN
3 * Ethernet-type device handling.
4 *
5 * Authors: Ben Greear <greearb@candelatech.com>
6 * Please send support related email to: vlan@scry.wanfear.com
7 * VLAN Home Page: http://www.candelatech.com/~greear/vlan.html
8 *
9 * Fixes:
10 * Fix for packet capture - Nick Eggleston <nick@dccinc.com>;
11 * Add HW acceleration hooks - David S. Miller <davem@redhat.com>;
12 * Correct all the locking - David S. Miller <davem@redhat.com>;
13 * Use hash table for VLAN groups - David S. Miller <davem@redhat.com>
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
19 */
20
21#include <asm/uaccess.h> /* for copy_from_user */
22#include <linux/module.h>
23#include <linux/netdevice.h>
24#include <linux/skbuff.h>
25#include <net/datalink.h>
26#include <linux/mm.h>
27#include <linux/in.h>
28#include <linux/init.h>
29#include <net/p8022.h>
30#include <net/arp.h>
31#include <linux/rtnetlink.h>
32#include <linux/notifier.h>
33
34#include <linux/if_vlan.h>
35#include "vlan.h"
36#include "vlanproc.h"
37
38#define DRV_VERSION "1.8"
39
40/* Global VLAN variables */
41
42/* Our listing of VLAN group(s) */
43static struct hlist_head vlan_group_hash[VLAN_GRP_HASH_SIZE];
44#define vlan_grp_hashfn(IDX) ((((IDX) >> VLAN_GRP_HASH_SHIFT) ^ (IDX)) & VLAN_GRP_HASH_MASK)
45
46static char vlan_fullname[] = "802.1Q VLAN Support";
47static char vlan_version[] = DRV_VERSION;
48static char vlan_copyright[] = "Ben Greear <greearb@candelatech.com>";
49static char vlan_buggyright[] = "David S. Miller <davem@redhat.com>";
50
51static int vlan_device_event(struct notifier_block *, unsigned long, void *);
52static int vlan_ioctl_handler(void __user *);
53static int unregister_vlan_dev(struct net_device *, unsigned short );
54
55static struct notifier_block vlan_notifier_block = {
56 .notifier_call = vlan_device_event,
57};
58
59/* These may be changed at run-time through IOCTLs */
60
61/* Determines interface naming scheme. */
62unsigned short vlan_name_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD;
63
64static struct packet_type vlan_packet_type = {
65 .type = __constant_htons(ETH_P_8021Q),
66 .func = vlan_skb_recv, /* VLAN receive method */
67};
68
69/* Bits of netdev state that are propagated from real device to virtual */
70#define VLAN_LINK_STATE_MASK \
71 ((1<<__LINK_STATE_PRESENT)|(1<<__LINK_STATE_NOCARRIER))
72
73/* End of global variables definitions. */
74
75/*
76 * Function vlan_proto_init (pro)
77 *
78 * Initialize VLAN protocol layer,
79 *
80 */
81static int __init vlan_proto_init(void)
82{
83 int err;
84
85 printk(VLAN_INF "%s v%s %s\n",
86 vlan_fullname, vlan_version, vlan_copyright);
87 printk(VLAN_INF "All bugs added by %s\n",
88 vlan_buggyright);
89
90 /* proc file system initialization */
91 err = vlan_proc_init();
92 if (err < 0) {
93 printk(KERN_ERR
94 "%s %s: can't create entry in proc filesystem!\n",
95 __FUNCTION__, VLAN_NAME);
96 return err;
97 }
98
99 dev_add_pack(&vlan_packet_type);
100
101 /* Register us to receive netdevice events */
102 err = register_netdevice_notifier(&vlan_notifier_block);
103 if (err < 0) {
104 dev_remove_pack(&vlan_packet_type);
105 vlan_proc_cleanup();
106 return err;
107 }
108
109 vlan_ioctl_set(vlan_ioctl_handler);
110
111 return 0;
112}
113
114/* Cleanup all vlan devices
115 * Note: devices that have been registered that but not
116 * brought up will exist but have no module ref count.
117 */
118static void __exit vlan_cleanup_devices(void)
119{
120 struct net_device *dev, *nxt;
121
122 rtnl_lock();
123 for (dev = dev_base; dev; dev = nxt) {
124 nxt = dev->next;
125 if (dev->priv_flags & IFF_802_1Q_VLAN) {
126 unregister_vlan_dev(VLAN_DEV_INFO(dev)->real_dev,
127 VLAN_DEV_INFO(dev)->vlan_id);
128
129 unregister_netdevice(dev);
130 }
131 }
132 rtnl_unlock();
133}
134
135/*
136 * Module 'remove' entry point.
137 * o delete /proc/net/router directory and static entries.
138 */
139static void __exit vlan_cleanup_module(void)
140{
141 int i;
142
143 vlan_ioctl_set(NULL);
144
145 /* Un-register us from receiving netdevice events */
146 unregister_netdevice_notifier(&vlan_notifier_block);
147
148 dev_remove_pack(&vlan_packet_type);
149 vlan_cleanup_devices();
150
151 /* This table must be empty if there are no module
152 * references left.
153 */
154 for (i = 0; i < VLAN_GRP_HASH_SIZE; i++) {
155 BUG_ON(!hlist_empty(&vlan_group_hash[i]));
156 }
157 vlan_proc_cleanup();
158
159 synchronize_net();
160}
161
162module_init(vlan_proto_init);
163module_exit(vlan_cleanup_module);
164
165/* Must be invoked with RCU read lock (no preempt) */
166static struct vlan_group *__vlan_find_group(int real_dev_ifindex)
167{
168 struct vlan_group *grp;
169 struct hlist_node *n;
170 int hash = vlan_grp_hashfn(real_dev_ifindex);
171
172 hlist_for_each_entry_rcu(grp, n, &vlan_group_hash[hash], hlist) {
173 if (grp->real_dev_ifindex == real_dev_ifindex)
174 return grp;
175 }
176
177 return NULL;
178}
179
180/* Find the protocol handler. Assumes VID < VLAN_VID_MASK.
181 *
182 * Must be invoked with RCU read lock (no preempt)
183 */
184struct net_device *__find_vlan_dev(struct net_device *real_dev,
185 unsigned short VID)
186{
187 struct vlan_group *grp = __vlan_find_group(real_dev->ifindex);
188
189 if (grp)
190 return grp->vlan_devices[VID];
191
192 return NULL;
193}
194
195static void vlan_rcu_free(struct rcu_head *rcu)
196{
197 kfree(container_of(rcu, struct vlan_group, rcu));
198}
199
200
201/* This returns 0 if everything went fine.
202 * It will return 1 if the group was killed as a result.
203 * A negative return indicates failure.
204 *
205 * The RTNL lock must be held.
206 */
207static int unregister_vlan_dev(struct net_device *real_dev,
208 unsigned short vlan_id)
209{
210 struct net_device *dev = NULL;
211 int real_dev_ifindex = real_dev->ifindex;
212 struct vlan_group *grp;
213 int i, ret;
214
215#ifdef VLAN_DEBUG
216 printk(VLAN_DBG "%s: VID: %i\n", __FUNCTION__, vlan_id);
217#endif
218
219 /* sanity check */
220 if (vlan_id >= VLAN_VID_MASK)
221 return -EINVAL;
222
223 ASSERT_RTNL();
224 grp = __vlan_find_group(real_dev_ifindex);
225
226 ret = 0;
227
228 if (grp) {
229 dev = grp->vlan_devices[vlan_id];
230 if (dev) {
231 /* Remove proc entry */
232 vlan_proc_rem_dev(dev);
233
234 /* Take it out of our own structures, but be sure to
235 * interlock with HW accelerating devices or SW vlan
236 * input packet processing.
237 */
238 if (real_dev->features &
239 (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER)) {
240 real_dev->vlan_rx_kill_vid(real_dev, vlan_id);
241 }
242
243 grp->vlan_devices[vlan_id] = NULL;
244 synchronize_net();
245
246
247 /* Caller unregisters (and if necessary, puts)
248 * VLAN device, but we get rid of the reference to
249 * real_dev here.
250 */
251 dev_put(real_dev);
252
253 /* If the group is now empty, kill off the
254 * group.
255 */
256 for (i = 0; i < VLAN_VID_MASK; i++)
257 if (grp->vlan_devices[i])
258 break;
259
260 if (i == VLAN_VID_MASK) {
261 if (real_dev->features & NETIF_F_HW_VLAN_RX)
262 real_dev->vlan_rx_register(real_dev, NULL);
263
264 hlist_del_rcu(&grp->hlist);
265
266 /* Free the group, after all cpu's are done. */
267 call_rcu(&grp->rcu, vlan_rcu_free);
268
269 grp = NULL;
270 ret = 1;
271 }
272 }
273 }
274
275 return ret;
276}
277
278static int unregister_vlan_device(const char *vlan_IF_name)
279{
280 struct net_device *dev = NULL;
281 int ret;
282
283
284 dev = dev_get_by_name(vlan_IF_name);
285 ret = -EINVAL;
286 if (dev) {
287 if (dev->priv_flags & IFF_802_1Q_VLAN) {
288 rtnl_lock();
289
290 ret = unregister_vlan_dev(VLAN_DEV_INFO(dev)->real_dev,
291 VLAN_DEV_INFO(dev)->vlan_id);
292
293 dev_put(dev);
294 unregister_netdevice(dev);
295
296 rtnl_unlock();
297
298 if (ret == 1)
299 ret = 0;
300 } else {
301 printk(VLAN_ERR
302 "%s: ERROR: Tried to remove a non-vlan device "
303 "with VLAN code, name: %s priv_flags: %hX\n",
304 __FUNCTION__, dev->name, dev->priv_flags);
305 dev_put(dev);
306 ret = -EPERM;
307 }
308 } else {
309#ifdef VLAN_DEBUG
310 printk(VLAN_DBG "%s: WARNING: Could not find dev.\n", __FUNCTION__);
311#endif
312 ret = -EINVAL;
313 }
314
315 return ret;
316}
317
318static void vlan_setup(struct net_device *new_dev)
319{
320 SET_MODULE_OWNER(new_dev);
321
322 /* new_dev->ifindex = 0; it will be set when added to
323 * the global list.
324 * iflink is set as well.
325 */
326 new_dev->get_stats = vlan_dev_get_stats;
327
328 /* Make this thing known as a VLAN device */
329 new_dev->priv_flags |= IFF_802_1Q_VLAN;
330
331 /* Set us up to have no queue, as the underlying Hardware device
332 * can do all the queueing we could want.
333 */
334 new_dev->tx_queue_len = 0;
335
336 /* set up method calls */
337 new_dev->change_mtu = vlan_dev_change_mtu;
338 new_dev->open = vlan_dev_open;
339 new_dev->stop = vlan_dev_stop;
340 new_dev->set_mac_address = vlan_dev_set_mac_address;
341 new_dev->set_multicast_list = vlan_dev_set_multicast_list;
342 new_dev->destructor = free_netdev;
343 new_dev->do_ioctl = vlan_dev_ioctl;
344}
345
346/* Attach a VLAN device to a mac address (ie Ethernet Card).
347 * Returns the device that was created, or NULL if there was
348 * an error of some kind.
349 */
350static struct net_device *register_vlan_device(const char *eth_IF_name,
351 unsigned short VLAN_ID)
352{
353 struct vlan_group *grp;
354 struct net_device *new_dev;
355 struct net_device *real_dev; /* the ethernet device */
356 char name[IFNAMSIZ];
357
358#ifdef VLAN_DEBUG
359 printk(VLAN_DBG "%s: if_name -:%s:- vid: %i\n",
360 __FUNCTION__, eth_IF_name, VLAN_ID);
361#endif
362
363 if (VLAN_ID >= VLAN_VID_MASK)
364 goto out_ret_null;
365
366 /* find the device relating to eth_IF_name. */
367 real_dev = dev_get_by_name(eth_IF_name);
368 if (!real_dev)
369 goto out_ret_null;
370
371 if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
372 printk(VLAN_DBG "%s: VLANs not supported on %s.\n",
373 __FUNCTION__, real_dev->name);
374 goto out_put_dev;
375 }
376
377 if ((real_dev->features & NETIF_F_HW_VLAN_RX) &&
378 (real_dev->vlan_rx_register == NULL ||
379 real_dev->vlan_rx_kill_vid == NULL)) {
380 printk(VLAN_DBG "%s: Device %s has buggy VLAN hw accel.\n",
381 __FUNCTION__, real_dev->name);
382 goto out_put_dev;
383 }
384
385 if ((real_dev->features & NETIF_F_HW_VLAN_FILTER) &&
386 (real_dev->vlan_rx_add_vid == NULL ||
387 real_dev->vlan_rx_kill_vid == NULL)) {
388 printk(VLAN_DBG "%s: Device %s has buggy VLAN hw accel.\n",
389 __FUNCTION__, real_dev->name);
390 goto out_put_dev;
391 }
392
393 /* From this point on, all the data structures must remain
394 * consistent.
395 */
396 rtnl_lock();
397
398 /* The real device must be up and operating in order to
399 * assosciate a VLAN device with it.
400 */
401 if (!(real_dev->flags & IFF_UP))
402 goto out_unlock;
403
404 if (__find_vlan_dev(real_dev, VLAN_ID) != NULL) {
405 /* was already registered. */
406 printk(VLAN_DBG "%s: ALREADY had VLAN registered\n", __FUNCTION__);
407 goto out_unlock;
408 }
409
410 /* Gotta set up the fields for the device. */
411#ifdef VLAN_DEBUG
412 printk(VLAN_DBG "About to allocate name, vlan_name_type: %i\n",
413 vlan_name_type);
414#endif
415 switch (vlan_name_type) {
416 case VLAN_NAME_TYPE_RAW_PLUS_VID:
417 /* name will look like: eth1.0005 */
418 snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, VLAN_ID);
419 break;
420 case VLAN_NAME_TYPE_PLUS_VID_NO_PAD:
421 /* Put our vlan.VID in the name.
422 * Name will look like: vlan5
423 */
424 snprintf(name, IFNAMSIZ, "vlan%i", VLAN_ID);
425 break;
426 case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD:
427 /* Put our vlan.VID in the name.
428 * Name will look like: eth0.5
429 */
430 snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, VLAN_ID);
431 break;
432 case VLAN_NAME_TYPE_PLUS_VID:
433 /* Put our vlan.VID in the name.
434 * Name will look like: vlan0005
435 */
436 default:
437 snprintf(name, IFNAMSIZ, "vlan%.4i", VLAN_ID);
438 };
439
440 new_dev = alloc_netdev(sizeof(struct vlan_dev_info), name,
441 vlan_setup);
442 if (new_dev == NULL)
443 goto out_unlock;
444
445#ifdef VLAN_DEBUG
446 printk(VLAN_DBG "Allocated new name -:%s:-\n", new_dev->name);
447#endif
448 /* IFF_BROADCAST|IFF_MULTICAST; ??? */
449 new_dev->flags = real_dev->flags;
450 new_dev->flags &= ~IFF_UP;
451
452 new_dev->state = real_dev->state & VLAN_LINK_STATE_MASK;
453
454 /* need 4 bytes for extra VLAN header info,
455 * hope the underlying device can handle it.
456 */
457 new_dev->mtu = real_dev->mtu;
458
459 /* TODO: maybe just assign it to be ETHERNET? */
460 new_dev->type = real_dev->type;
461
462 new_dev->hard_header_len = real_dev->hard_header_len;
463 if (!(real_dev->features & NETIF_F_HW_VLAN_TX)) {
464 /* Regular ethernet + 4 bytes (18 total). */
465 new_dev->hard_header_len += VLAN_HLEN;
466 }
467
468 VLAN_MEM_DBG("new_dev->priv malloc, addr: %p size: %i\n",
469 new_dev->priv,
470 sizeof(struct vlan_dev_info));
471
472 memcpy(new_dev->broadcast, real_dev->broadcast, real_dev->addr_len);
473 memcpy(new_dev->dev_addr, real_dev->dev_addr, real_dev->addr_len);
474 new_dev->addr_len = real_dev->addr_len;
475
476 if (real_dev->features & NETIF_F_HW_VLAN_TX) {
477 new_dev->hard_header = real_dev->hard_header;
478 new_dev->hard_start_xmit = vlan_dev_hwaccel_hard_start_xmit;
479 new_dev->rebuild_header = real_dev->rebuild_header;
480 } else {
481 new_dev->hard_header = vlan_dev_hard_header;
482 new_dev->hard_start_xmit = vlan_dev_hard_start_xmit;
483 new_dev->rebuild_header = vlan_dev_rebuild_header;
484 }
485 new_dev->hard_header_parse = real_dev->hard_header_parse;
486
487 VLAN_DEV_INFO(new_dev)->vlan_id = VLAN_ID; /* 1 through VLAN_VID_MASK */
488 VLAN_DEV_INFO(new_dev)->real_dev = real_dev;
489 VLAN_DEV_INFO(new_dev)->dent = NULL;
490 VLAN_DEV_INFO(new_dev)->flags = 1;
491
492#ifdef VLAN_DEBUG
493 printk(VLAN_DBG "About to go find the group for idx: %i\n",
494 real_dev->ifindex);
495#endif
496
497 if (register_netdevice(new_dev))
498 goto out_free_newdev;
499
500 /* So, got the sucker initialized, now lets place
501 * it into our local structure.
502 */
503 grp = __vlan_find_group(real_dev->ifindex);
504
505 /* Note, we are running under the RTNL semaphore
506 * so it cannot "appear" on us.
507 */
508 if (!grp) { /* need to add a new group */
509 grp = kmalloc(sizeof(struct vlan_group), GFP_KERNEL);
510 if (!grp)
511 goto out_free_unregister;
512
513 /* printk(KERN_ALERT "VLAN REGISTER: Allocated new group.\n"); */
514 memset(grp, 0, sizeof(struct vlan_group));
515 grp->real_dev_ifindex = real_dev->ifindex;
516
517 hlist_add_head_rcu(&grp->hlist,
518 &vlan_group_hash[vlan_grp_hashfn(real_dev->ifindex)]);
519
520 if (real_dev->features & NETIF_F_HW_VLAN_RX)
521 real_dev->vlan_rx_register(real_dev, grp);
522 }
523
524 grp->vlan_devices[VLAN_ID] = new_dev;
525
526 if (vlan_proc_add_dev(new_dev)<0)/* create it's proc entry */
527 printk(KERN_WARNING "VLAN: failed to add proc entry for %s\n",
528 new_dev->name);
529
530 if (real_dev->features & NETIF_F_HW_VLAN_FILTER)
531 real_dev->vlan_rx_add_vid(real_dev, VLAN_ID);
532
533 rtnl_unlock();
534
535
536#ifdef VLAN_DEBUG
537 printk(VLAN_DBG "Allocated new device successfully, returning.\n");
538#endif
539 return new_dev;
540
541out_free_unregister:
542 unregister_netdev(new_dev);
543 goto out_unlock;
544
545out_free_newdev:
546 free_netdev(new_dev);
547
548out_unlock:
549 rtnl_unlock();
550
551out_put_dev:
552 dev_put(real_dev);
553
554out_ret_null:
555 return NULL;
556}
557
558static int vlan_device_event(struct notifier_block *unused, unsigned long event, void *ptr)
559{
560 struct net_device *dev = ptr;
561 struct vlan_group *grp = __vlan_find_group(dev->ifindex);
562 int i, flgs;
563 struct net_device *vlandev;
564
565 if (!grp)
566 goto out;
567
568 /* It is OK that we do not hold the group lock right now,
569 * as we run under the RTNL lock.
570 */
571
572 switch (event) {
573 case NETDEV_CHANGE:
574 /* Propagate real device state to vlan devices */
575 flgs = dev->state & VLAN_LINK_STATE_MASK;
576 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
577 vlandev = grp->vlan_devices[i];
578 if (!vlandev)
579 continue;
580
581 if ((vlandev->state & VLAN_LINK_STATE_MASK) != flgs) {
582 vlandev->state = (vlandev->state &~ VLAN_LINK_STATE_MASK)
583 | flgs;
584 netdev_state_change(vlandev);
585 }
586 }
587 break;
588
589 case NETDEV_DOWN:
590 /* Put all VLANs for this dev in the down state too. */
591 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
592 vlandev = grp->vlan_devices[i];
593 if (!vlandev)
594 continue;
595
596 flgs = vlandev->flags;
597 if (!(flgs & IFF_UP))
598 continue;
599
600 dev_change_flags(vlandev, flgs & ~IFF_UP);
601 }
602 break;
603
604 case NETDEV_UP:
605 /* Put all VLANs for this dev in the up state too. */
606 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
607 vlandev = grp->vlan_devices[i];
608 if (!vlandev)
609 continue;
610
611 flgs = vlandev->flags;
612 if (flgs & IFF_UP)
613 continue;
614
615 dev_change_flags(vlandev, flgs | IFF_UP);
616 }
617 break;
618
619 case NETDEV_UNREGISTER:
620 /* Delete all VLANs for this dev. */
621 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
622 int ret;
623
624 vlandev = grp->vlan_devices[i];
625 if (!vlandev)
626 continue;
627
628 ret = unregister_vlan_dev(dev,
629 VLAN_DEV_INFO(vlandev)->vlan_id);
630
631 unregister_netdevice(vlandev);
632
633 /* Group was destroyed? */
634 if (ret == 1)
635 break;
636 }
637 break;
638 };
639
640out:
641 return NOTIFY_DONE;
642}
643
644/*
645 * VLAN IOCTL handler.
646 * o execute requested action or pass command to the device driver
647 * arg is really a struct vlan_ioctl_args __user *.
648 */
649static int vlan_ioctl_handler(void __user *arg)
650{
651 int err = 0;
652 unsigned short vid = 0;
653 struct vlan_ioctl_args args;
654
655 if (copy_from_user(&args, arg, sizeof(struct vlan_ioctl_args)))
656 return -EFAULT;
657
658 /* Null terminate this sucker, just in case. */
659 args.device1[23] = 0;
660 args.u.device2[23] = 0;
661
662#ifdef VLAN_DEBUG
663 printk(VLAN_DBG "%s: args.cmd: %x\n", __FUNCTION__, args.cmd);
664#endif
665
666 switch (args.cmd) {
667 case SET_VLAN_INGRESS_PRIORITY_CMD:
668 if (!capable(CAP_NET_ADMIN))
669 return -EPERM;
670 err = vlan_dev_set_ingress_priority(args.device1,
671 args.u.skb_priority,
672 args.vlan_qos);
673 break;
674
675 case SET_VLAN_EGRESS_PRIORITY_CMD:
676 if (!capable(CAP_NET_ADMIN))
677 return -EPERM;
678 err = vlan_dev_set_egress_priority(args.device1,
679 args.u.skb_priority,
680 args.vlan_qos);
681 break;
682
683 case SET_VLAN_FLAG_CMD:
684 if (!capable(CAP_NET_ADMIN))
685 return -EPERM;
686 err = vlan_dev_set_vlan_flag(args.device1,
687 args.u.flag,
688 args.vlan_qos);
689 break;
690
691 case SET_VLAN_NAME_TYPE_CMD:
692 if (!capable(CAP_NET_ADMIN))
693 return -EPERM;
694 if ((args.u.name_type >= 0) &&
695 (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
696 vlan_name_type = args.u.name_type;
697 err = 0;
698 } else {
699 err = -EINVAL;
700 }
701 break;
702
703 case ADD_VLAN_CMD:
704 if (!capable(CAP_NET_ADMIN))
705 return -EPERM;
706 /* we have been given the name of the Ethernet Device we want to
707 * talk to: args.dev1 We also have the
708 * VLAN ID: args.u.VID
709 */
710 if (register_vlan_device(args.device1, args.u.VID)) {
711 err = 0;
712 } else {
713 err = -EINVAL;
714 }
715 break;
716
717 case DEL_VLAN_CMD:
718 if (!capable(CAP_NET_ADMIN))
719 return -EPERM;
720 /* Here, the args.dev1 is the actual VLAN we want
721 * to get rid of.
722 */
723 err = unregister_vlan_device(args.device1);
724 break;
725
726 case GET_VLAN_INGRESS_PRIORITY_CMD:
727 /* TODO: Implement
728 err = vlan_dev_get_ingress_priority(args);
729 if (copy_to_user((void*)arg, &args,
730 sizeof(struct vlan_ioctl_args))) {
731 err = -EFAULT;
732 }
733 */
734 err = -EINVAL;
735 break;
736 case GET_VLAN_EGRESS_PRIORITY_CMD:
737 /* TODO: Implement
738 err = vlan_dev_get_egress_priority(args.device1, &(args.args);
739 if (copy_to_user((void*)arg, &args,
740 sizeof(struct vlan_ioctl_args))) {
741 err = -EFAULT;
742 }
743 */
744 err = -EINVAL;
745 break;
746 case GET_VLAN_REALDEV_NAME_CMD:
747 err = vlan_dev_get_realdev_name(args.device1, args.u.device2);
748 if (copy_to_user(arg, &args,
749 sizeof(struct vlan_ioctl_args))) {
750 err = -EFAULT;
751 }
752 break;
753
754 case GET_VLAN_VID_CMD:
755 err = vlan_dev_get_vid(args.device1, &vid);
756 args.u.VID = vid;
757 if (copy_to_user(arg, &args,
758 sizeof(struct vlan_ioctl_args))) {
759 err = -EFAULT;
760 }
761 break;
762
763 default:
764 /* pass on to underlying device instead?? */
765 printk(VLAN_DBG "%s: Unknown VLAN CMD: %x \n",
766 __FUNCTION__, args.cmd);
767 return -EINVAL;
768 };
769
770 return err;
771}
772
773MODULE_LICENSE("GPL");
774MODULE_VERSION(DRV_VERSION);
diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h
new file mode 100644
index 000000000000..508b1fa14546
--- /dev/null
+++ b/net/8021q/vlan.h
@@ -0,0 +1,72 @@
1#ifndef __BEN_VLAN_802_1Q_INC__
2#define __BEN_VLAN_802_1Q_INC__
3
4#include <linux/if_vlan.h>
5
6/* Uncomment this if you want debug traces to be shown. */
7/* #define VLAN_DEBUG */
8
9#define VLAN_ERR KERN_ERR
10#define VLAN_INF KERN_INFO
11#define VLAN_DBG KERN_ALERT /* change these... to debug, having a hard time
12 * changing the log level at run-time..for some reason.
13 */
14
15/*
16
17These I use for memory debugging. I feared a leak at one time, but
18I never found it..and the problem seems to have dissappeared. Still,
19I'll bet they might prove useful again... --Ben
20
21
22#define VLAN_MEM_DBG(x, y, z) printk(VLAN_DBG "%s: " x, __FUNCTION__, y, z);
23#define VLAN_FMEM_DBG(x, y) printk(VLAN_DBG "%s: " x, __FUNCTION__, y);
24*/
25
26/* This way they don't do anything! */
27#define VLAN_MEM_DBG(x, y, z)
28#define VLAN_FMEM_DBG(x, y)
29
30
31extern unsigned short vlan_name_type;
32
33#define VLAN_GRP_HASH_SHIFT 5
34#define VLAN_GRP_HASH_SIZE (1 << VLAN_GRP_HASH_SHIFT)
35#define VLAN_GRP_HASH_MASK (VLAN_GRP_HASH_SIZE - 1)
36
37/* Find a VLAN device by the MAC address of its Ethernet device, and
38 * it's VLAN ID. The default configuration is to have VLAN's scope
39 * to be box-wide, so the MAC will be ignored. The mac will only be
40 * looked at if we are configured to have a separate set of VLANs per
41 * each MAC addressable interface. Note that this latter option does
42 * NOT follow the spec for VLANs, but may be useful for doing very
43 * large quantities of VLAN MUX/DEMUX onto FrameRelay or ATM PVCs.
44 *
45 * Must be invoked with rcu_read_lock (ie preempt disabled)
46 * or with RTNL.
47 */
48struct net_device *__find_vlan_dev(struct net_device* real_dev,
49 unsigned short VID); /* vlan.c */
50
51/* found in vlan_dev.c */
52int vlan_dev_rebuild_header(struct sk_buff *skb);
53int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
54 struct packet_type* ptype);
55int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,
56 unsigned short type, void *daddr, void *saddr,
57 unsigned len);
58int vlan_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev);
59int vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb, struct net_device *dev);
60int vlan_dev_change_mtu(struct net_device *dev, int new_mtu);
61int vlan_dev_set_mac_address(struct net_device *dev, void* addr);
62int vlan_dev_open(struct net_device* dev);
63int vlan_dev_stop(struct net_device* dev);
64int vlan_dev_ioctl(struct net_device* dev, struct ifreq *ifr, int cmd);
65int vlan_dev_set_ingress_priority(char* dev_name, __u32 skb_prio, short vlan_prio);
66int vlan_dev_set_egress_priority(char* dev_name, __u32 skb_prio, short vlan_prio);
67int vlan_dev_set_vlan_flag(char* dev_name, __u32 flag, short flag_val);
68int vlan_dev_get_realdev_name(const char* dev_name, char* result);
69int vlan_dev_get_vid(const char* dev_name, unsigned short* result);
70void vlan_dev_set_multicast_list(struct net_device *vlan_dev);
71
72#endif /* !(__BEN_VLAN_802_1Q_INC__) */
diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
new file mode 100644
index 000000000000..49c487413518
--- /dev/null
+++ b/net/8021q/vlan_dev.c
@@ -0,0 +1,890 @@
1/* -*- linux-c -*-
2 * INET 802.1Q VLAN
3 * Ethernet-type device handling.
4 *
5 * Authors: Ben Greear <greearb@candelatech.com>
6 * Please send support related email to: vlan@scry.wanfear.com
7 * VLAN Home Page: http://www.candelatech.com/~greear/vlan.html
8 *
9 * Fixes: Mar 22 2001: Martin Bokaemper <mbokaemper@unispherenetworks.com>
10 * - reset skb->pkt_type on incoming packets when MAC was changed
11 * - see that changed MAC is saddr for outgoing packets
12 * Oct 20, 2001: Ard van Breeman:
13 * - Fix MC-list, finally.
14 * - Flush MC-list on VLAN destroy.
15 *
16 *
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version
20 * 2 of the License, or (at your option) any later version.
21 */
22
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>
29#include <linux/netdevice.h>
30#include <linux/etherdevice.h>
31#include <net/datalink.h>
32#include <net/p8022.h>
33#include <net/arp.h>
34
35#include "vlan.h"
36#include "vlanproc.h"
37#include <linux/if_vlan.h>
38#include <net/ip.h>
39
40/*
41 * Rebuild the Ethernet MAC header. This is called after an ARP
42 * (or in future other address resolution) has completed on this
43 * sk_buff. We now let ARP fill in the other fields.
44 *
45 * This routine CANNOT use cached dst->neigh!
46 * Really, it is used only when dst->neigh is wrong.
47 *
48 * TODO: This needs a checkup, I'm ignorant here. --BLG
49 */
50int vlan_dev_rebuild_header(struct sk_buff *skb)
51{
52 struct net_device *dev = skb->dev;
53 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)(skb->data);
54
55 switch (veth->h_vlan_encapsulated_proto) {
56#ifdef CONFIG_INET
57 case __constant_htons(ETH_P_IP):
58
59 /* TODO: Confirm this will work with VLAN headers... */
60 return arp_find(veth->h_dest, skb);
61#endif
62 default:
63 printk(VLAN_DBG
64 "%s: unable to resolve type %X addresses.\n",
65 dev->name, (int)veth->h_vlan_encapsulated_proto);
66
67 memcpy(veth->h_source, dev->dev_addr, ETH_ALEN);
68 break;
69 };
70
71 return 0;
72}
73
74static inline struct sk_buff *vlan_check_reorder_header(struct sk_buff *skb)
75{
76 if (VLAN_DEV_INFO(skb->dev)->flags & 1) {
77 if (skb_shared(skb) || skb_cloned(skb)) {
78 struct sk_buff *nskb = skb_copy(skb, GFP_ATOMIC);
79 kfree_skb(skb);
80 skb = nskb;
81 }
82 if (skb) {
83 /* Lifted from Gleb's VLAN code... */
84 memmove(skb->data - ETH_HLEN,
85 skb->data - VLAN_ETH_HLEN, 12);
86 skb->mac.raw += VLAN_HLEN;
87 }
88 }
89
90 return skb;
91}
92
93/*
94 * Determine the packet's protocol ID. The rule here is that we
95 * assume 802.3 if the type field is short enough to be a length.
96 * This is normal practice and works for any 'now in use' protocol.
97 *
98 * Also, at this point we assume that we ARE dealing exclusively with
99 * VLAN packets, or packets that should be made into VLAN packets based
100 * on a default VLAN ID.
101 *
102 * NOTE: Should be similar to ethernet/eth.c.
103 *
104 * SANITY NOTE: This method is called when a packet is moving up the stack
105 * towards userland. To get here, it would have already passed
106 * through the ethernet/eth.c eth_type_trans() method.
107 * SANITY NOTE 2: We are referencing to the VLAN_HDR frields, which MAY be
108 * stored UNALIGNED in the memory. RISC systems don't like
109 * such cases very much...
110 * SANITY NOTE 2a: According to Dave Miller & Alexey, it will always be aligned,
111 * so there doesn't need to be any of the unaligned stuff. It has
112 * been commented out now... --Ben
113 *
114 */
115int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
116 struct packet_type* ptype)
117{
118 unsigned char *rawp = NULL;
119 struct vlan_hdr *vhdr = (struct vlan_hdr *)(skb->data);
120 unsigned short vid;
121 struct net_device_stats *stats;
122 unsigned short vlan_TCI;
123 unsigned short proto;
124
125 /* vlan_TCI = ntohs(get_unaligned(&vhdr->h_vlan_TCI)); */
126 vlan_TCI = ntohs(vhdr->h_vlan_TCI);
127
128 vid = (vlan_TCI & VLAN_VID_MASK);
129
130#ifdef VLAN_DEBUG
131 printk(VLAN_DBG "%s: skb: %p vlan_id: %hx\n",
132 __FUNCTION__, skb, vid);
133#endif
134
135 /* Ok, we will find the correct VLAN device, strip the header,
136 * and then go on as usual.
137 */
138
139 /* We have 12 bits of vlan ID.
140 *
141 * We must not drop allow preempt until we hold a
142 * reference to the device (netif_rx does that) or we
143 * fail.
144 */
145
146 rcu_read_lock();
147 skb->dev = __find_vlan_dev(dev, vid);
148 if (!skb->dev) {
149 rcu_read_unlock();
150
151#ifdef VLAN_DEBUG
152 printk(VLAN_DBG "%s: ERROR: No net_device for VID: %i on dev: %s [%i]\n",
153 __FUNCTION__, (unsigned int)(vid), dev->name, dev->ifindex);
154#endif
155 kfree_skb(skb);
156 return -1;
157 }
158
159 skb->dev->last_rx = jiffies;
160
161 /* Bump the rx counters for the VLAN device. */
162 stats = vlan_dev_get_stats(skb->dev);
163 stats->rx_packets++;
164 stats->rx_bytes += skb->len;
165
166 skb_pull(skb, VLAN_HLEN); /* take off the VLAN header (4 bytes currently) */
167
168 /* Ok, lets check to make sure the device (dev) we
169 * came in on is what this VLAN is attached to.
170 */
171
172 if (dev != VLAN_DEV_INFO(skb->dev)->real_dev) {
173 rcu_read_unlock();
174
175#ifdef VLAN_DEBUG
176 printk(VLAN_DBG "%s: dropping skb: %p because came in on wrong device, dev: %s real_dev: %s, skb_dev: %s\n",
177 __FUNCTION__, skb, dev->name,
178 VLAN_DEV_INFO(skb->dev)->real_dev->name,
179 skb->dev->name);
180#endif
181 kfree_skb(skb);
182 stats->rx_errors++;
183 return -1;
184 }
185
186 /*
187 * Deal with ingress priority mapping.
188 */
189 skb->priority = vlan_get_ingress_priority(skb->dev, ntohs(vhdr->h_vlan_TCI));
190
191#ifdef VLAN_DEBUG
192 printk(VLAN_DBG "%s: priority: %lu for TCI: %hu (hbo)\n",
193 __FUNCTION__, (unsigned long)(skb->priority),
194 ntohs(vhdr->h_vlan_TCI));
195#endif
196
197 /* The ethernet driver already did the pkt_type calculations
198 * for us...
199 */
200 switch (skb->pkt_type) {
201 case PACKET_BROADCAST: /* Yeah, stats collect these together.. */
202 // stats->broadcast ++; // no such counter :-(
203 break;
204
205 case PACKET_MULTICAST:
206 stats->multicast++;
207 break;
208
209 case PACKET_OTHERHOST:
210 /* Our lower layer thinks this is not local, let's make sure.
211 * This allows the VLAN to have a different MAC than the underlying
212 * device, and still route correctly.
213 */
214 if (memcmp(eth_hdr(skb)->h_dest, skb->dev->dev_addr, ETH_ALEN) == 0) {
215 /* It is for our (changed) MAC-address! */
216 skb->pkt_type = PACKET_HOST;
217 }
218 break;
219 default:
220 break;
221 };
222
223 /* Was a VLAN packet, grab the encapsulated protocol, which the layer
224 * three protocols care about.
225 */
226 /* proto = get_unaligned(&vhdr->h_vlan_encapsulated_proto); */
227 proto = vhdr->h_vlan_encapsulated_proto;
228
229 skb->protocol = proto;
230 if (ntohs(proto) >= 1536) {
231 /* place it back on the queue to be handled by
232 * true layer 3 protocols.
233 */
234
235 /* See if we are configured to re-write the VLAN header
236 * to make it look like ethernet...
237 */
238 skb = vlan_check_reorder_header(skb);
239
240 /* Can be null if skb-clone fails when re-ordering */
241 if (skb) {
242 netif_rx(skb);
243 } else {
244 /* TODO: Add a more specific counter here. */
245 stats->rx_errors++;
246 }
247 rcu_read_unlock();
248 return 0;
249 }
250
251 rawp = skb->data;
252
253 /*
254 * This is a magic hack to spot IPX packets. Older Novell breaks
255 * the protocol design and runs IPX over 802.3 without an 802.2 LLC
256 * layer. We look for FFFF which isn't a used 802.2 SSAP/DSAP. This
257 * won't work for fault tolerant netware but does for the rest.
258 */
259 if (*(unsigned short *)rawp == 0xFFFF) {
260 skb->protocol = __constant_htons(ETH_P_802_3);
261 /* place it back on the queue to be handled by true layer 3 protocols.
262 */
263
264 /* See if we are configured to re-write the VLAN header
265 * to make it look like ethernet...
266 */
267 skb = vlan_check_reorder_header(skb);
268
269 /* Can be null if skb-clone fails when re-ordering */
270 if (skb) {
271 netif_rx(skb);
272 } else {
273 /* TODO: Add a more specific counter here. */
274 stats->rx_errors++;
275 }
276 rcu_read_unlock();
277 return 0;
278 }
279
280 /*
281 * Real 802.2 LLC
282 */
283 skb->protocol = __constant_htons(ETH_P_802_2);
284 /* place it back on the queue to be handled by upper layer protocols.
285 */
286
287 /* See if we are configured to re-write the VLAN header
288 * to make it look like ethernet...
289 */
290 skb = vlan_check_reorder_header(skb);
291
292 /* Can be null if skb-clone fails when re-ordering */
293 if (skb) {
294 netif_rx(skb);
295 } else {
296 /* TODO: Add a more specific counter here. */
297 stats->rx_errors++;
298 }
299 rcu_read_unlock();
300 return 0;
301}
302
303static inline unsigned short vlan_dev_get_egress_qos_mask(struct net_device* dev,
304 struct sk_buff* skb)
305{
306 struct vlan_priority_tci_mapping *mp =
307 VLAN_DEV_INFO(dev)->egress_priority_map[(skb->priority & 0xF)];
308
309 while (mp) {
310 if (mp->priority == skb->priority) {
311 return mp->vlan_qos; /* This should already be shifted to mask
312 * correctly with the VLAN's TCI
313 */
314 }
315 mp = mp->next;
316 }
317 return 0;
318}
319
320/*
321 * Create the VLAN header for an arbitrary protocol layer
322 *
323 * saddr=NULL means use device source address
324 * daddr=NULL means leave destination address (eg unresolved arp)
325 *
326 * This is called when the SKB is moving down the stack towards the
327 * physical devices.
328 */
329int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,
330 unsigned short type, void *daddr, void *saddr,
331 unsigned len)
332{
333 struct vlan_hdr *vhdr;
334 unsigned short veth_TCI = 0;
335 int rc = 0;
336 int build_vlan_header = 0;
337 struct net_device *vdev = dev; /* save this for the bottom of the method */
338
339#ifdef VLAN_DEBUG
340 printk(VLAN_DBG "%s: skb: %p type: %hx len: %x vlan_id: %hx, daddr: %p\n",
341 __FUNCTION__, skb, type, len, VLAN_DEV_INFO(dev)->vlan_id, daddr);
342#endif
343
344 /* build vlan header only if re_order_header flag is NOT set. This
345 * fixes some programs that get confused when they see a VLAN device
346 * sending a frame that is VLAN encoded (the consensus is that the VLAN
347 * device should look completely like an Ethernet device when the
348 * REORDER_HEADER flag is set) The drawback to this is some extra
349 * header shuffling in the hard_start_xmit. Users can turn off this
350 * REORDER behaviour with the vconfig tool.
351 */
352 build_vlan_header = ((VLAN_DEV_INFO(dev)->flags & 1) == 0);
353
354 if (build_vlan_header) {
355 vhdr = (struct vlan_hdr *) skb_push(skb, VLAN_HLEN);
356
357 /* build the four bytes that make this a VLAN header. */
358
359 /* Now, construct the second two bytes. This field looks something
360 * like:
361 * usr_priority: 3 bits (high bits)
362 * CFI 1 bit
363 * VLAN ID 12 bits (low bits)
364 *
365 */
366 veth_TCI = VLAN_DEV_INFO(dev)->vlan_id;
367 veth_TCI |= vlan_dev_get_egress_qos_mask(dev, skb);
368
369 vhdr->h_vlan_TCI = htons(veth_TCI);
370
371 /*
372 * Set the protocol type.
373 * For a packet of type ETH_P_802_3 we put the length in here instead.
374 * It is up to the 802.2 layer to carry protocol information.
375 */
376
377 if (type != ETH_P_802_3) {
378 vhdr->h_vlan_encapsulated_proto = htons(type);
379 } else {
380 vhdr->h_vlan_encapsulated_proto = htons(len);
381 }
382 }
383
384 /* Before delegating work to the lower layer, enter our MAC-address */
385 if (saddr == NULL)
386 saddr = dev->dev_addr;
387
388 dev = VLAN_DEV_INFO(dev)->real_dev;
389
390 /* MPLS can send us skbuffs w/out enough space. This check will grow the
391 * skb if it doesn't have enough headroom. Not a beautiful solution, so
392 * I'll tick a counter so that users can know it's happening... If they
393 * care...
394 */
395
396 /* NOTE: This may still break if the underlying device is not the final
397 * device (and thus there are more headers to add...) It should work for
398 * good-ole-ethernet though.
399 */
400 if (skb_headroom(skb) < dev->hard_header_len) {
401 struct sk_buff *sk_tmp = skb;
402 skb = skb_realloc_headroom(sk_tmp, dev->hard_header_len);
403 kfree_skb(sk_tmp);
404 if (skb == NULL) {
405 struct net_device_stats *stats = vlan_dev_get_stats(vdev);
406 stats->tx_dropped++;
407 return -ENOMEM;
408 }
409 VLAN_DEV_INFO(vdev)->cnt_inc_headroom_on_tx++;
410#ifdef VLAN_DEBUG
411 printk(VLAN_DBG "%s: %s: had to grow skb.\n", __FUNCTION__, vdev->name);
412#endif
413 }
414
415 if (build_vlan_header) {
416 /* Now make the underlying real hard header */
417 rc = dev->hard_header(skb, dev, ETH_P_8021Q, daddr, saddr, len + VLAN_HLEN);
418
419 if (rc > 0) {
420 rc += VLAN_HLEN;
421 } else if (rc < 0) {
422 rc -= VLAN_HLEN;
423 }
424 } else {
425 /* If here, then we'll just make a normal looking ethernet frame,
426 * but, the hard_start_xmit method will insert the tag (it has to
427 * be able to do this for bridged and other skbs that don't come
428 * down the protocol stack in an orderly manner.
429 */
430 rc = dev->hard_header(skb, dev, type, daddr, saddr, len);
431 }
432
433 return rc;
434}
435
436int vlan_dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
437{
438 struct net_device_stats *stats = vlan_dev_get_stats(dev);
439 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)(skb->data);
440
441 /* Handle non-VLAN frames if they are sent to us, for example by DHCP.
442 *
443 * NOTE: THIS ASSUMES DIX ETHERNET, SPECIFICALLY NOT SUPPORTING
444 * OTHER THINGS LIKE FDDI/TokenRing/802.3 SNAPs...
445 */
446
447 if (veth->h_vlan_proto != __constant_htons(ETH_P_8021Q)) {
448 int orig_headroom = skb_headroom(skb);
449 unsigned short veth_TCI;
450
451 /* This is not a VLAN frame...but we can fix that! */
452 VLAN_DEV_INFO(dev)->cnt_encap_on_xmit++;
453
454#ifdef VLAN_DEBUG
455 printk(VLAN_DBG "%s: proto to encap: 0x%hx (hbo)\n",
456 __FUNCTION__, htons(veth->h_vlan_proto));
457#endif
458 /* Construct the second two bytes. This field looks something
459 * like:
460 * usr_priority: 3 bits (high bits)
461 * CFI 1 bit
462 * VLAN ID 12 bits (low bits)
463 */
464 veth_TCI = VLAN_DEV_INFO(dev)->vlan_id;
465 veth_TCI |= vlan_dev_get_egress_qos_mask(dev, skb);
466
467 skb = __vlan_put_tag(skb, veth_TCI);
468 if (!skb) {
469 stats->tx_dropped++;
470 return 0;
471 }
472
473 if (orig_headroom < VLAN_HLEN) {
474 VLAN_DEV_INFO(dev)->cnt_inc_headroom_on_tx++;
475 }
476 }
477
478#ifdef VLAN_DEBUG
479 printk(VLAN_DBG "%s: about to send skb: %p to dev: %s\n",
480 __FUNCTION__, skb, skb->dev->name);
481 printk(VLAN_DBG " %2hx.%2hx.%2hx.%2xh.%2hx.%2hx %2hx.%2hx.%2hx.%2hx.%2hx.%2hx %4hx %4hx %4hx\n",
482 veth->h_dest[0], veth->h_dest[1], veth->h_dest[2], veth->h_dest[3], veth->h_dest[4], veth->h_dest[5],
483 veth->h_source[0], veth->h_source[1], veth->h_source[2], veth->h_source[3], veth->h_source[4], veth->h_source[5],
484 veth->h_vlan_proto, veth->h_vlan_TCI, veth->h_vlan_encapsulated_proto);
485#endif
486
487 stats->tx_packets++; /* for statics only */
488 stats->tx_bytes += skb->len;
489
490 skb->dev = VLAN_DEV_INFO(dev)->real_dev;
491 dev_queue_xmit(skb);
492
493 return 0;
494}
495
496int vlan_dev_hwaccel_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
497{
498 struct net_device_stats *stats = vlan_dev_get_stats(dev);
499 unsigned short veth_TCI;
500
501 /* Construct the second two bytes. This field looks something
502 * like:
503 * usr_priority: 3 bits (high bits)
504 * CFI 1 bit
505 * VLAN ID 12 bits (low bits)
506 */
507 veth_TCI = VLAN_DEV_INFO(dev)->vlan_id;
508 veth_TCI |= vlan_dev_get_egress_qos_mask(dev, skb);
509 skb = __vlan_hwaccel_put_tag(skb, veth_TCI);
510
511 stats->tx_packets++;
512 stats->tx_bytes += skb->len;
513
514 skb->dev = VLAN_DEV_INFO(dev)->real_dev;
515 dev_queue_xmit(skb);
516
517 return 0;
518}
519
520int vlan_dev_change_mtu(struct net_device *dev, int new_mtu)
521{
522 /* TODO: gotta make sure the underlying layer can handle it,
523 * maybe an IFF_VLAN_CAPABLE flag for devices?
524 */
525 if (VLAN_DEV_INFO(dev)->real_dev->mtu < new_mtu)
526 return -ERANGE;
527
528 dev->mtu = new_mtu;
529
530 return 0;
531}
532
533int vlan_dev_set_ingress_priority(char *dev_name, __u32 skb_prio, short vlan_prio)
534{
535 struct net_device *dev = dev_get_by_name(dev_name);
536
537 if (dev) {
538 if (dev->priv_flags & IFF_802_1Q_VLAN) {
539 /* see if a priority mapping exists.. */
540 VLAN_DEV_INFO(dev)->ingress_priority_map[vlan_prio & 0x7] = skb_prio;
541 dev_put(dev);
542 return 0;
543 }
544
545 dev_put(dev);
546 }
547 return -EINVAL;
548}
549
550int vlan_dev_set_egress_priority(char *dev_name, __u32 skb_prio, short vlan_prio)
551{
552 struct net_device *dev = dev_get_by_name(dev_name);
553 struct vlan_priority_tci_mapping *mp = NULL;
554 struct vlan_priority_tci_mapping *np;
555
556 if (dev) {
557 if (dev->priv_flags & IFF_802_1Q_VLAN) {
558 /* See if a priority mapping exists.. */
559 mp = VLAN_DEV_INFO(dev)->egress_priority_map[skb_prio & 0xF];
560 while (mp) {
561 if (mp->priority == skb_prio) {
562 mp->vlan_qos = ((vlan_prio << 13) & 0xE000);
563 dev_put(dev);
564 return 0;
565 }
566 mp = mp->next;
567 }
568
569 /* Create a new mapping then. */
570 mp = VLAN_DEV_INFO(dev)->egress_priority_map[skb_prio & 0xF];
571 np = kmalloc(sizeof(struct vlan_priority_tci_mapping), GFP_KERNEL);
572 if (np) {
573 np->next = mp;
574 np->priority = skb_prio;
575 np->vlan_qos = ((vlan_prio << 13) & 0xE000);
576 VLAN_DEV_INFO(dev)->egress_priority_map[skb_prio & 0xF] = np;
577 dev_put(dev);
578 return 0;
579 } else {
580 dev_put(dev);
581 return -ENOBUFS;
582 }
583 }
584 dev_put(dev);
585 }
586 return -EINVAL;
587}
588
589/* Flags are defined in the vlan_dev_info class in include/linux/if_vlan.h file. */
590int vlan_dev_set_vlan_flag(char *dev_name, __u32 flag, short flag_val)
591{
592 struct net_device *dev = dev_get_by_name(dev_name);
593
594 if (dev) {
595 if (dev->priv_flags & IFF_802_1Q_VLAN) {
596 /* verify flag is supported */
597 if (flag == 1) {
598 if (flag_val) {
599 VLAN_DEV_INFO(dev)->flags |= 1;
600 } else {
601 VLAN_DEV_INFO(dev)->flags &= ~1;
602 }
603 dev_put(dev);
604 return 0;
605 } else {
606 printk(KERN_ERR "%s: flag %i is not valid.\n",
607 __FUNCTION__, (int)(flag));
608 dev_put(dev);
609 return -EINVAL;
610 }
611 } else {
612 printk(KERN_ERR
613 "%s: %s is not a vlan device, priv_flags: %hX.\n",
614 __FUNCTION__, dev->name, dev->priv_flags);
615 dev_put(dev);
616 }
617 } else {
618 printk(KERN_ERR "%s: Could not find device: %s\n",
619 __FUNCTION__, dev_name);
620 }
621
622 return -EINVAL;
623}
624
625
626int vlan_dev_get_realdev_name(const char *dev_name, char* result)
627{
628 struct net_device *dev = dev_get_by_name(dev_name);
629 int rv = 0;
630 if (dev) {
631 if (dev->priv_flags & IFF_802_1Q_VLAN) {
632 strncpy(result, VLAN_DEV_INFO(dev)->real_dev->name, 23);
633 rv = 0;
634 } else {
635 rv = -EINVAL;
636 }
637 dev_put(dev);
638 } else {
639 rv = -ENODEV;
640 }
641 return rv;
642}
643
644int vlan_dev_get_vid(const char *dev_name, unsigned short* result)
645{
646 struct net_device *dev = dev_get_by_name(dev_name);
647 int rv = 0;
648 if (dev) {
649 if (dev->priv_flags & IFF_802_1Q_VLAN) {
650 *result = VLAN_DEV_INFO(dev)->vlan_id;
651 rv = 0;
652 } else {
653 rv = -EINVAL;
654 }
655 dev_put(dev);
656 } else {
657 rv = -ENODEV;
658 }
659 return rv;
660}
661
662
663int vlan_dev_set_mac_address(struct net_device *dev, void *addr_struct_p)
664{
665 struct sockaddr *addr = (struct sockaddr *)(addr_struct_p);
666 int i;
667
668 if (netif_running(dev))
669 return -EBUSY;
670
671 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
672
673 printk("%s: Setting MAC address to ", dev->name);
674 for (i = 0; i < 6; i++)
675 printk(" %2.2x", dev->dev_addr[i]);
676 printk(".\n");
677
678 if (memcmp(VLAN_DEV_INFO(dev)->real_dev->dev_addr,
679 dev->dev_addr,
680 dev->addr_len) != 0) {
681 if (!(VLAN_DEV_INFO(dev)->real_dev->flags & IFF_PROMISC)) {
682 int flgs = VLAN_DEV_INFO(dev)->real_dev->flags;
683
684 /* Increment our in-use promiscuity counter */
685 dev_set_promiscuity(VLAN_DEV_INFO(dev)->real_dev, 1);
686
687 /* Make PROMISC visible to the user. */
688 flgs |= IFF_PROMISC;
689 printk("VLAN (%s): Setting underlying device (%s) to promiscious mode.\n",
690 dev->name, VLAN_DEV_INFO(dev)->real_dev->name);
691 dev_change_flags(VLAN_DEV_INFO(dev)->real_dev, flgs);
692 }
693 } else {
694 printk("VLAN (%s): Underlying device (%s) has same MAC, not checking promiscious mode.\n",
695 dev->name, VLAN_DEV_INFO(dev)->real_dev->name);
696 }
697
698 return 0;
699}
700
701static inline int vlan_dmi_equals(struct dev_mc_list *dmi1,
702 struct dev_mc_list *dmi2)
703{
704 return ((dmi1->dmi_addrlen == dmi2->dmi_addrlen) &&
705 (memcmp(dmi1->dmi_addr, dmi2->dmi_addr, dmi1->dmi_addrlen) == 0));
706}
707
708/** dmi is a single entry into a dev_mc_list, a single node. mc_list is
709 * an entire list, and we'll iterate through it.
710 */
711static int vlan_should_add_mc(struct dev_mc_list *dmi, struct dev_mc_list *mc_list)
712{
713 struct dev_mc_list *idmi;
714
715 for (idmi = mc_list; idmi != NULL; ) {
716 if (vlan_dmi_equals(dmi, idmi)) {
717 if (dmi->dmi_users > idmi->dmi_users)
718 return 1;
719 else
720 return 0;
721 } else {
722 idmi = idmi->next;
723 }
724 }
725
726 return 1;
727}
728
729static inline void vlan_destroy_mc_list(struct dev_mc_list *mc_list)
730{
731 struct dev_mc_list *dmi = mc_list;
732 struct dev_mc_list *next;
733
734 while(dmi) {
735 next = dmi->next;
736 kfree(dmi);
737 dmi = next;
738 }
739}
740
741static void vlan_copy_mc_list(struct dev_mc_list *mc_list, struct vlan_dev_info *vlan_info)
742{
743 struct dev_mc_list *dmi, *new_dmi;
744
745 vlan_destroy_mc_list(vlan_info->old_mc_list);
746 vlan_info->old_mc_list = NULL;
747
748 for (dmi = mc_list; dmi != NULL; dmi = dmi->next) {
749 new_dmi = kmalloc(sizeof(*new_dmi), GFP_ATOMIC);
750 if (new_dmi == NULL) {
751 printk(KERN_ERR "vlan: cannot allocate memory. "
752 "Multicast may not work properly from now.\n");
753 return;
754 }
755
756 /* Copy whole structure, then make new 'next' pointer */
757 *new_dmi = *dmi;
758 new_dmi->next = vlan_info->old_mc_list;
759 vlan_info->old_mc_list = new_dmi;
760 }
761}
762
763static void vlan_flush_mc_list(struct net_device *dev)
764{
765 struct dev_mc_list *dmi = dev->mc_list;
766
767 while (dmi) {
768 printk(KERN_DEBUG "%s: del %.2x:%.2x:%.2x:%.2x:%.2x:%.2x mcast address from vlan interface\n",
769 dev->name,
770 dmi->dmi_addr[0],
771 dmi->dmi_addr[1],
772 dmi->dmi_addr[2],
773 dmi->dmi_addr[3],
774 dmi->dmi_addr[4],
775 dmi->dmi_addr[5]);
776 dev_mc_delete(dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
777 dmi = dev->mc_list;
778 }
779
780 /* dev->mc_list is NULL by the time we get here. */
781 vlan_destroy_mc_list(VLAN_DEV_INFO(dev)->old_mc_list);
782 VLAN_DEV_INFO(dev)->old_mc_list = NULL;
783}
784
785int vlan_dev_open(struct net_device *dev)
786{
787 if (!(VLAN_DEV_INFO(dev)->real_dev->flags & IFF_UP))
788 return -ENETDOWN;
789
790 return 0;
791}
792
793int vlan_dev_stop(struct net_device *dev)
794{
795 vlan_flush_mc_list(dev);
796 return 0;
797}
798
799int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
800{
801 struct net_device *real_dev = VLAN_DEV_INFO(dev)->real_dev;
802 struct ifreq ifrr;
803 int err = -EOPNOTSUPP;
804
805 strncpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
806 ifrr.ifr_ifru = ifr->ifr_ifru;
807
808 switch(cmd) {
809 case SIOCGMIIPHY:
810 case SIOCGMIIREG:
811 case SIOCSMIIREG:
812 if (real_dev->do_ioctl && netif_device_present(real_dev))
813 err = real_dev->do_ioctl(real_dev, &ifrr, cmd);
814 break;
815
816 case SIOCETHTOOL:
817 err = dev_ethtool(&ifrr);
818 }
819
820 if (!err)
821 ifr->ifr_ifru = ifrr.ifr_ifru;
822
823 return err;
824}
825
826/** Taken from Gleb + Lennert's VLAN code, and modified... */
827void vlan_dev_set_multicast_list(struct net_device *vlan_dev)
828{
829 struct dev_mc_list *dmi;
830 struct net_device *real_dev;
831 int inc;
832
833 if (vlan_dev && (vlan_dev->priv_flags & IFF_802_1Q_VLAN)) {
834 /* Then it's a real vlan device, as far as we can tell.. */
835 real_dev = VLAN_DEV_INFO(vlan_dev)->real_dev;
836
837 /* compare the current promiscuity to the last promisc we had.. */
838 inc = vlan_dev->promiscuity - VLAN_DEV_INFO(vlan_dev)->old_promiscuity;
839 if (inc) {
840 printk(KERN_INFO "%s: dev_set_promiscuity(master, %d)\n",
841 vlan_dev->name, inc);
842 dev_set_promiscuity(real_dev, inc); /* found in dev.c */
843 VLAN_DEV_INFO(vlan_dev)->old_promiscuity = vlan_dev->promiscuity;
844 }
845
846 inc = vlan_dev->allmulti - VLAN_DEV_INFO(vlan_dev)->old_allmulti;
847 if (inc) {
848 printk(KERN_INFO "%s: dev_set_allmulti(master, %d)\n",
849 vlan_dev->name, inc);
850 dev_set_allmulti(real_dev, inc); /* dev.c */
851 VLAN_DEV_INFO(vlan_dev)->old_allmulti = vlan_dev->allmulti;
852 }
853
854 /* looking for addresses to add to master's list */
855 for (dmi = vlan_dev->mc_list; dmi != NULL; dmi = dmi->next) {
856 if (vlan_should_add_mc(dmi, VLAN_DEV_INFO(vlan_dev)->old_mc_list)) {
857 dev_mc_add(real_dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
858 printk(KERN_DEBUG "%s: add %.2x:%.2x:%.2x:%.2x:%.2x:%.2x mcast address to master interface\n",
859 vlan_dev->name,
860 dmi->dmi_addr[0],
861 dmi->dmi_addr[1],
862 dmi->dmi_addr[2],
863 dmi->dmi_addr[3],
864 dmi->dmi_addr[4],
865 dmi->dmi_addr[5]);
866 }
867 }
868
869 /* looking for addresses to delete from master's list */
870 for (dmi = VLAN_DEV_INFO(vlan_dev)->old_mc_list; dmi != NULL; dmi = dmi->next) {
871 if (vlan_should_add_mc(dmi, vlan_dev->mc_list)) {
872 /* if we think we should add it to the new list, then we should really
873 * delete it from the real list on the underlying device.
874 */
875 dev_mc_delete(real_dev, dmi->dmi_addr, dmi->dmi_addrlen, 0);
876 printk(KERN_DEBUG "%s: del %.2x:%.2x:%.2x:%.2x:%.2x:%.2x mcast address from master interface\n",
877 vlan_dev->name,
878 dmi->dmi_addr[0],
879 dmi->dmi_addr[1],
880 dmi->dmi_addr[2],
881 dmi->dmi_addr[3],
882 dmi->dmi_addr[4],
883 dmi->dmi_addr[5]);
884 }
885 }
886
887 /* save multicast list */
888 vlan_copy_mc_list(vlan_dev->mc_list, VLAN_DEV_INFO(vlan_dev));
889 }
890}
diff --git a/net/8021q/vlanproc.c b/net/8021q/vlanproc.c
new file mode 100644
index 000000000000..c32d27af0a3f
--- /dev/null
+++ b/net/8021q/vlanproc.c
@@ -0,0 +1,357 @@
1/******************************************************************************
2 * vlanproc.c VLAN Module. /proc filesystem interface.
3 *
4 * This module is completely hardware-independent and provides
5 * access to the router using Linux /proc filesystem.
6 *
7 * Author: Ben Greear, <greearb@candelatech.com> coppied from wanproc.c
8 * by: Gene Kozin <genek@compuserve.com>
9 *
10 * Copyright: (c) 1998 Ben Greear
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
16 * ============================================================================
17 * Jan 20, 1998 Ben Greear Initial Version
18 *****************************************************************************/
19
20#include <linux/config.h>
21#include <linux/module.h>
22#include <linux/stddef.h> /* offsetof(), etc. */
23#include <linux/errno.h> /* return codes */
24#include <linux/kernel.h>
25#include <linux/slab.h> /* kmalloc(), kfree() */
26#include <linux/mm.h> /* verify_area(), etc. */
27#include <linux/string.h> /* inline mem*, str* functions */
28#include <linux/init.h> /* __initfunc et al. */
29#include <asm/byteorder.h> /* htons(), etc. */
30#include <asm/uaccess.h> /* copy_to_user */
31#include <asm/io.h>
32#include <linux/proc_fs.h>
33#include <linux/seq_file.h>
34#include <linux/fs.h>
35#include <linux/netdevice.h>
36#include <linux/if_vlan.h>
37#include "vlanproc.h"
38#include "vlan.h"
39
40/****** Function Prototypes *************************************************/
41
42/* Methods for preparing data for reading proc entries */
43static int vlan_seq_show(struct seq_file *seq, void *v);
44static void *vlan_seq_start(struct seq_file *seq, loff_t *pos);
45static void *vlan_seq_next(struct seq_file *seq, void *v, loff_t *pos);
46static void vlan_seq_stop(struct seq_file *seq, void *);
47static int vlandev_seq_show(struct seq_file *seq, void *v);
48
49/*
50 * Global Data
51 */
52
53
54/*
55 * Names of the proc directory entries
56 */
57
58static const char name_root[] = "vlan";
59static const char name_conf[] = "config";
60
61/*
62 * Structures for interfacing with the /proc filesystem.
63 * VLAN creates its own directory /proc/net/vlan with the folowing
64 * entries:
65 * config device status/configuration
66 * <device> entry for each device
67 */
68
69/*
70 * Generic /proc/net/vlan/<file> file and inode operations
71 */
72
73static struct seq_operations vlan_seq_ops = {
74 .start = vlan_seq_start,
75 .next = vlan_seq_next,
76 .stop = vlan_seq_stop,
77 .show = vlan_seq_show,
78};
79
80static int vlan_seq_open(struct inode *inode, struct file *file)
81{
82 return seq_open(file, &vlan_seq_ops);
83}
84
85static struct file_operations vlan_fops = {
86 .owner = THIS_MODULE,
87 .open = vlan_seq_open,
88 .read = seq_read,
89 .llseek = seq_lseek,
90 .release = seq_release,
91};
92
93/*
94 * /proc/net/vlan/<device> file and inode operations
95 */
96
97static int vlandev_seq_open(struct inode *inode, struct file *file)
98{
99 return single_open(file, vlandev_seq_show, PDE(inode)->data);
100}
101
102static struct file_operations vlandev_fops = {
103 .owner = THIS_MODULE,
104 .open = vlandev_seq_open,
105 .read = seq_read,
106 .llseek = seq_lseek,
107 .release = single_release,
108};
109
110/*
111 * Proc filesystem derectory entries.
112 */
113
114/*
115 * /proc/net/vlan
116 */
117
118static struct proc_dir_entry *proc_vlan_dir;
119
120/*
121 * /proc/net/vlan/config
122 */
123
124static struct proc_dir_entry *proc_vlan_conf;
125
126/* Strings */
127static const char *vlan_name_type_str[VLAN_NAME_TYPE_HIGHEST] = {
128 [VLAN_NAME_TYPE_RAW_PLUS_VID] = "VLAN_NAME_TYPE_RAW_PLUS_VID",
129 [VLAN_NAME_TYPE_PLUS_VID_NO_PAD] = "VLAN_NAME_TYPE_PLUS_VID_NO_PAD",
130 [VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD]= "VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD",
131 [VLAN_NAME_TYPE_PLUS_VID] = "VLAN_NAME_TYPE_PLUS_VID",
132};
133/*
134 * Interface functions
135 */
136
137/*
138 * Clean up /proc/net/vlan entries
139 */
140
141void vlan_proc_cleanup(void)
142{
143 if (proc_vlan_conf)
144 remove_proc_entry(name_conf, proc_vlan_dir);
145
146 if (proc_vlan_dir)
147 proc_net_remove(name_root);
148
149 /* Dynamically added entries should be cleaned up as their vlan_device
150 * is removed, so we should not have to take care of it here...
151 */
152}
153
154/*
155 * Create /proc/net/vlan entries
156 */
157
158int __init vlan_proc_init(void)
159{
160 proc_vlan_dir = proc_mkdir(name_root, proc_net);
161 if (proc_vlan_dir) {
162 proc_vlan_conf = create_proc_entry(name_conf,
163 S_IFREG|S_IRUSR|S_IWUSR,
164 proc_vlan_dir);
165 if (proc_vlan_conf) {
166 proc_vlan_conf->proc_fops = &vlan_fops;
167 return 0;
168 }
169 }
170 vlan_proc_cleanup();
171 return -ENOBUFS;
172}
173
174/*
175 * Add directory entry for VLAN device.
176 */
177
178int vlan_proc_add_dev (struct net_device *vlandev)
179{
180 struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev);
181
182 if (!(vlandev->priv_flags & IFF_802_1Q_VLAN)) {
183 printk(KERN_ERR
184 "ERROR: vlan_proc_add, device -:%s:- is NOT a VLAN\n",
185 vlandev->name);
186 return -EINVAL;
187 }
188
189 dev_info->dent = create_proc_entry(vlandev->name,
190 S_IFREG|S_IRUSR|S_IWUSR,
191 proc_vlan_dir);
192 if (!dev_info->dent)
193 return -ENOBUFS;
194
195 dev_info->dent->proc_fops = &vlandev_fops;
196 dev_info->dent->data = vlandev;
197
198#ifdef VLAN_DEBUG
199 printk(KERN_ERR "vlan_proc_add, device -:%s:- being added.\n",
200 vlandev->name);
201#endif
202 return 0;
203}
204
205/*
206 * Delete directory entry for VLAN device.
207 */
208int vlan_proc_rem_dev(struct net_device *vlandev)
209{
210 if (!vlandev) {
211 printk(VLAN_ERR "%s: invalid argument: %p\n",
212 __FUNCTION__, vlandev);
213 return -EINVAL;
214 }
215
216 if (!(vlandev->priv_flags & IFF_802_1Q_VLAN)) {
217 printk(VLAN_DBG "%s: invalid argument, device: %s is not a VLAN device, priv_flags: 0x%4hX.\n",
218 __FUNCTION__, vlandev->name, vlandev->priv_flags);
219 return -EINVAL;
220 }
221
222#ifdef VLAN_DEBUG
223 printk(VLAN_DBG "%s: dev: %p\n", __FUNCTION__, vlandev);
224#endif
225
226 /** NOTE: This will consume the memory pointed to by dent, it seems. */
227 if (VLAN_DEV_INFO(vlandev)->dent) {
228 remove_proc_entry(VLAN_DEV_INFO(vlandev)->dent->name, proc_vlan_dir);
229 VLAN_DEV_INFO(vlandev)->dent = NULL;
230 }
231
232 return 0;
233}
234
235/****** Proc filesystem entry points ****************************************/
236
237/*
238 * The following few functions build the content of /proc/net/vlan/config
239 */
240
241/* starting at dev, find a VLAN device */
242static struct net_device *vlan_skip(struct net_device *dev)
243{
244 while (dev && !(dev->priv_flags & IFF_802_1Q_VLAN))
245 dev = dev->next;
246
247 return dev;
248}
249
250/* start read of /proc/net/vlan/config */
251static void *vlan_seq_start(struct seq_file *seq, loff_t *pos)
252{
253 struct net_device *dev;
254 loff_t i = 1;
255
256 read_lock(&dev_base_lock);
257
258 if (*pos == 0)
259 return SEQ_START_TOKEN;
260
261 for (dev = vlan_skip(dev_base); dev && i < *pos;
262 dev = vlan_skip(dev->next), ++i);
263
264 return (i == *pos) ? dev : NULL;
265}
266
267static void *vlan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
268{
269 ++*pos;
270
271 return vlan_skip((v == SEQ_START_TOKEN)
272 ? dev_base
273 : ((struct net_device *)v)->next);
274}
275
276static void vlan_seq_stop(struct seq_file *seq, void *v)
277{
278 read_unlock(&dev_base_lock);
279}
280
281static int vlan_seq_show(struct seq_file *seq, void *v)
282{
283 if (v == SEQ_START_TOKEN) {
284 const char *nmtype = NULL;
285
286 seq_puts(seq, "VLAN Dev name | VLAN ID\n");
287
288 if (vlan_name_type < ARRAY_SIZE(vlan_name_type_str))
289 nmtype = vlan_name_type_str[vlan_name_type];
290
291 seq_printf(seq, "Name-Type: %s\n",
292 nmtype ? nmtype : "UNKNOWN" );
293 } else {
294 const struct net_device *vlandev = v;
295 const struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev);
296
297 seq_printf(seq, "%-15s| %d | %s\n", vlandev->name,
298 dev_info->vlan_id, dev_info->real_dev->name);
299 }
300 return 0;
301}
302
303static int vlandev_seq_show(struct seq_file *seq, void *offset)
304{
305 struct net_device *vlandev = (struct net_device *) seq->private;
306 const struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev);
307 struct net_device_stats *stats;
308 static const char fmt[] = "%30s %12lu\n";
309 int i;
310
311 if ((vlandev == NULL) || (!(vlandev->priv_flags & IFF_802_1Q_VLAN)))
312 return 0;
313
314 seq_printf(seq, "%s VID: %d REORDER_HDR: %i dev->priv_flags: %hx\n",
315 vlandev->name, dev_info->vlan_id,
316 (int)(dev_info->flags & 1), vlandev->priv_flags);
317
318
319 stats = vlan_dev_get_stats(vlandev);
320
321 seq_printf(seq, fmt, "total frames received", stats->rx_packets);
322 seq_printf(seq, fmt, "total bytes received", stats->rx_bytes);
323 seq_printf(seq, fmt, "Broadcast/Multicast Rcvd", stats->multicast);
324 seq_puts(seq, "\n");
325 seq_printf(seq, fmt, "total frames transmitted", stats->tx_packets);
326 seq_printf(seq, fmt, "total bytes transmitted", stats->tx_bytes);
327 seq_printf(seq, fmt, "total headroom inc",
328 dev_info->cnt_inc_headroom_on_tx);
329 seq_printf(seq, fmt, "total encap on xmit",
330 dev_info->cnt_encap_on_xmit);
331 seq_printf(seq, "Device: %s", dev_info->real_dev->name);
332 /* now show all PRIORITY mappings relating to this VLAN */
333 seq_printf(seq,
334 "\nINGRESS priority mappings: 0:%lu 1:%lu 2:%lu 3:%lu 4:%lu 5:%lu 6:%lu 7:%lu\n",
335 dev_info->ingress_priority_map[0],
336 dev_info->ingress_priority_map[1],
337 dev_info->ingress_priority_map[2],
338 dev_info->ingress_priority_map[3],
339 dev_info->ingress_priority_map[4],
340 dev_info->ingress_priority_map[5],
341 dev_info->ingress_priority_map[6],
342 dev_info->ingress_priority_map[7]);
343
344 seq_printf(seq, "EGRESSS priority Mappings: ");
345 for (i = 0; i < 16; i++) {
346 const struct vlan_priority_tci_mapping *mp
347 = dev_info->egress_priority_map[i];
348 while (mp) {
349 seq_printf(seq, "%lu:%hu ",
350 mp->priority, ((mp->vlan_qos >> 13) & 0x7));
351 mp = mp->next;
352 }
353 }
354 seq_puts(seq, "\n");
355
356 return 0;
357}
diff --git a/net/8021q/vlanproc.h b/net/8021q/vlanproc.h
new file mode 100644
index 000000000000..f908ee332fd8
--- /dev/null
+++ b/net/8021q/vlanproc.h
@@ -0,0 +1,19 @@
1#ifndef __BEN_VLAN_PROC_INC__
2#define __BEN_VLAN_PROC_INC__
3
4#ifdef CONFIG_PROC_FS
5int vlan_proc_init(void);
6int vlan_proc_rem_dev(struct net_device *vlandev);
7int vlan_proc_add_dev (struct net_device *vlandev);
8void vlan_proc_cleanup (void);
9
10#else /* No CONFIG_PROC_FS */
11
12#define vlan_proc_init() (0)
13#define vlan_proc_cleanup() do {} while(0)
14#define vlan_proc_add_dev(dev) ({(void)(dev), 0;})
15#define vlan_proc_rem_dev(dev) ({(void)(dev), 0;})
16
17#endif
18
19#endif /* !(__BEN_VLAN_PROC_INC__) */