1 /******************************************************************************
2 * vlanproc.c VLAN Module. /proc filesystem interface.
4 * This module is completely hardware-independent and provides
5 * access to the router using Linux /proc filesystem.
7 * Author: Ben Greear, <greearb@candelatech.com> coppied from wanproc.c
8 * by: Gene Kozin <genek@compuserve.com>
10 * Copyright: (c) 1998 Ben Greear
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 *****************************************************************************/
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 */
32 #include <linux/proc_fs.h>
33 #include <linux/seq_file.h>
35 #include <linux/netdevice.h>
36 #include <linux/if_vlan.h>
40 /****** Function Prototypes *************************************************/
42 /* Methods for preparing data for reading proc entries */
43 static int vlan_seq_show(struct seq_file *seq, void *v);
44 static void *vlan_seq_start(struct seq_file *seq, loff_t *pos);
45 static void *vlan_seq_next(struct seq_file *seq, void *v, loff_t *pos);
46 static void vlan_seq_stop(struct seq_file *seq, void *);
47 static int vlandev_seq_show(struct seq_file *seq, void *v);
50 #define SEQ_START_TOKEN ((void *) 1)
59 * Names of the proc directory entries
62 static const char name_root[] = "vlan";
63 static const char name_conf[] = "config";
66 * Structures for interfacing with the /proc filesystem.
67 * VLAN creates its own directory /proc/net/vlan with the folowing
69 * config device status/configuration
70 * <device> entry for each device
74 * Generic /proc/net/vlan/<file> file and inode operations
77 static struct seq_operations vlan_seq_ops = {
78 .start = vlan_seq_start,
79 .next = vlan_seq_next,
80 .stop = vlan_seq_stop,
81 .show = vlan_seq_show,
84 static int vlan_seq_open(struct inode *inode, struct file *file)
86 return seq_open(file, &vlan_seq_ops);
89 static struct file_operations vlan_fops = {
91 .open = vlan_seq_open,
94 .release = seq_release,
98 * /proc/net/vlan/<device> file and inode operations
101 static int vlandev_seq_open(struct inode *inode, struct file *file)
103 return single_open(file, vlandev_seq_show, PDE(inode)->data);
106 static struct file_operations vlandev_fops = {
107 .owner = THIS_MODULE,
108 .open = vlandev_seq_open,
111 .release = single_release,
115 * Proc filesystem derectory entries.
122 static struct proc_dir_entry *proc_vlan_dir;
125 * /proc/net/vlan/config
128 static struct proc_dir_entry *proc_vlan_conf;
131 static const char *vlan_name_type_str[VLAN_NAME_TYPE_HIGHEST] = {
132 [VLAN_NAME_TYPE_RAW_PLUS_VID] = "VLAN_NAME_TYPE_RAW_PLUS_VID",
133 [VLAN_NAME_TYPE_PLUS_VID_NO_PAD] = "VLAN_NAME_TYPE_PLUS_VID_NO_PAD",
134 [VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD]= "VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD",
135 [VLAN_NAME_TYPE_PLUS_VID] = "VLAN_NAME_TYPE_PLUS_VID",
138 * Interface functions
142 * Clean up /proc/net/vlan entries
145 void vlan_proc_cleanup(void)
148 remove_proc_entry(name_conf, proc_vlan_dir);
151 proc_net_remove(name_root);
153 /* Dynamically added entries should be cleaned up as their vlan_device
154 * is removed, so we should not have to take care of it here...
159 * Create /proc/net/vlan entries
162 int __init vlan_proc_init(void)
164 proc_vlan_dir = proc_mkdir(name_root, proc_net);
166 proc_vlan_conf = create_proc_entry(name_conf,
167 S_IFREG|S_IRUSR|S_IWUSR,
169 if (proc_vlan_conf) {
170 proc_vlan_conf->proc_fops = &vlan_fops;
179 * Add directory entry for VLAN device.
182 int vlan_proc_add_dev (struct net_device *vlandev)
184 struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev);
186 if (!(vlandev->priv_flags & IFF_802_1Q_VLAN)) {
188 "ERROR: vlan_proc_add, device -:%s:- is NOT a VLAN\n",
193 dev_info->dent = create_proc_entry(vlandev->name,
194 S_IFREG|S_IRUSR|S_IWUSR,
199 dev_info->dent->proc_fops = &vlandev_fops;
200 dev_info->dent->data = vlandev;
203 printk(KERN_ERR "vlan_proc_add, device -:%s:- being added.\n",
210 * Delete directory entry for VLAN device.
212 int vlan_proc_rem_dev(struct net_device *vlandev)
215 printk(VLAN_ERR "%s: invalid argument: %p\n",
216 __FUNCTION__, vlandev);
220 if (!(vlandev->priv_flags & IFF_802_1Q_VLAN)) {
221 printk(VLAN_DBG "%s: invalid argument, device: %s is not a VLAN device, priv_flags: 0x%4hX.\n",
222 __FUNCTION__, vlandev->name, vlandev->priv_flags);
227 printk(VLAN_DBG __FUNCTION__ ": dev: %p\n", vlandev);
230 /** NOTE: This will consume the memory pointed to by dent, it seems. */
231 remove_proc_entry(VLAN_DEV_INFO(vlandev)->dent->name, proc_vlan_dir);
232 VLAN_DEV_INFO(vlandev)->dent = NULL;
237 /****** Proc filesystem entry points ****************************************/
240 * The following few functions build the content of /proc/net/vlan/config
243 /* starting at dev, find a VLAN device */
244 struct net_device *vlan_skip(struct net_device *dev)
246 while (dev && !(dev->priv_flags & IFF_802_1Q_VLAN))
252 /* start read of /proc/net/vlan/config */
253 static void *vlan_seq_start(struct seq_file *seq, loff_t *pos)
255 struct net_device *dev;
258 read_lock(&dev_base_lock);
261 return SEQ_START_TOKEN;
263 for (dev = vlan_skip(dev_base); dev && i < *pos;
264 dev = vlan_skip(dev->next), ++i);
266 return (i == *pos) ? dev : NULL;
269 static void *vlan_seq_next(struct seq_file *seq, void *v, loff_t *pos)
273 return vlan_skip((v == SEQ_START_TOKEN)
275 : ((struct net_device *)v)->next);
278 static void vlan_seq_stop(struct seq_file *seq, void *v)
280 read_unlock(&dev_base_lock);
283 static int vlan_seq_show(struct seq_file *seq, void *v)
285 if (v == SEQ_START_TOKEN) {
286 const char *nmtype = NULL;
288 seq_puts(seq, "VLAN Dev name | VLAN ID\n");
290 if (vlan_name_type < ARRAY_SIZE(vlan_name_type_str))
291 nmtype = vlan_name_type_str[vlan_name_type];
293 seq_printf(seq, "Name-Type: %s\n",
294 nmtype ? nmtype : "UNKNOWN" );
296 const struct net_device *vlandev = v;
297 const struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev);
299 seq_printf(seq, "%-15s| %d | %s\n", vlandev->name,
300 dev_info->vlan_id, dev_info->real_dev->name);
305 static int vlandev_seq_show(struct seq_file *seq, void *offset)
307 struct net_device *vlandev = (struct net_device *) seq->private;
308 const struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev);
309 struct net_device_stats *stats;
310 static const char *fmt = "%30s %12lu\n";
313 if ((vlandev == NULL) || (!(vlandev->priv_flags & IFF_802_1Q_VLAN)))
316 seq_printf(seq, "%s VID: %d REORDER_HDR: %i dev->priv_flags: %hx\n",
317 vlandev->name, dev_info->vlan_id,
318 (int)(dev_info->flags & 1), vlandev->priv_flags);
321 stats = vlan_dev_get_stats(vlandev);
323 seq_printf(seq, fmt, "total frames received", stats->rx_packets);
324 seq_printf(seq, fmt, "total bytes received", stats->rx_bytes);
325 seq_printf(seq, fmt, "Broadcast/Multicast Rcvd", stats->multicast);
327 seq_printf(seq, fmt, "total frames transmitted", stats->tx_packets);
328 seq_printf(seq, fmt, "total bytes transmitted", stats->tx_bytes);
329 seq_printf(seq, fmt, "total headroom inc",
330 dev_info->cnt_inc_headroom_on_tx);
331 seq_printf(seq, fmt, "total encap on xmit",
332 dev_info->cnt_encap_on_xmit);
333 seq_printf(seq, "Device: %s", dev_info->real_dev->name);
334 /* now show all PRIORITY mappings relating to this VLAN */
336 "\nINGRESS priority mappings: 0:%lu 1:%lu 2:%lu 3:%lu 4:%lu 5:%lu 6:%lu 7:%lu\n",
337 dev_info->ingress_priority_map[0],
338 dev_info->ingress_priority_map[1],
339 dev_info->ingress_priority_map[2],
340 dev_info->ingress_priority_map[3],
341 dev_info->ingress_priority_map[4],
342 dev_info->ingress_priority_map[5],
343 dev_info->ingress_priority_map[6],
344 dev_info->ingress_priority_map[7]);
346 seq_printf(seq, "EGRESSS priority Mappings: ");
347 for (i = 0; i < 16; i++) {
348 const struct vlan_priority_tci_mapping *mp
349 = dev_info->egress_priority_map[i];
351 seq_printf(seq, "%lu:%hu ",
352 mp->priority, ((mp->vlan_qos >> 13) & 0x7));