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/stddef.h> /* offsetof(), etc. */
22 #include <linux/errno.h> /* return codes */
23 #include <linux/kernel.h>
24 #include <linux/slab.h> /* kmalloc(), kfree() */
25 #include <linux/mm.h> /* verify_area(), etc. */
26 #include <linux/string.h> /* inline mem*, str* functions */
27 #include <linux/init.h> /* __initfunc et al. */
28 #include <asm/segment.h> /* kernel <-> user copy */
29 #include <asm/byteorder.h> /* htons(), etc. */
30 #include <asm/uaccess.h> /* copy_to_user */
32 #include <linux/proc_fs.h>
34 #include <linux/netdevice.h>
35 #include <linux/if_vlan.h>
39 /****** Function Prototypes *************************************************/
43 /* Proc filesystem interface */
44 static ssize_t vlan_proc_read(struct file *file, char *buf, size_t count,
47 /* Methods for preparing data for reading proc entries */
49 static int vlan_config_get_info(char *buf, char **start, off_t offs, int len);
50 static int vlandev_get_info(char *buf, char **start, off_t offs, int len);
59 * Names of the proc directory entries
62 static char name_root[] = "vlan";
63 static char name_conf[] = "config";
64 static char term_msg[] = "***KERNEL: Out of buffer space!***\n";
67 * Structures for interfacing with the /proc filesystem.
68 * VLAN creates its own directory /proc/net/vlan with the folowing
70 * config device status/configuration
71 * <device> entry for each device
75 * Generic /proc/net/vlan/<file> file and inode operations
78 static struct file_operations vlan_fops = {
80 ioctl: NULL, /* vlan_proc_ioctl */
84 * /proc/net/vlan/<device> file and inode operations
87 static struct file_operations vlandev_fops = {
89 ioctl: NULL, /* vlan_proc_ioctl */
93 * Proc filesystem derectory entries.
100 static struct proc_dir_entry *proc_vlan_dir;
103 * /proc/net/vlan/config
106 static struct proc_dir_entry *proc_vlan_conf;
109 static char conf_hdr[] = "VLAN Dev name | VLAN ID\n";
112 * Interface functions
116 * Clean up /proc/net/vlan entries
119 void vlan_proc_cleanup(void)
122 remove_proc_entry(name_conf, proc_vlan_dir);
125 proc_net_remove(name_root);
127 /* Dynamically added entries should be cleaned up as their vlan_device
128 * is removed, so we should not have to take care of it here...
133 * Create /proc/net/vlan entries
136 int __init vlan_proc_init(void)
138 proc_vlan_dir = proc_mkdir(name_root, proc_net);
140 proc_vlan_conf = create_proc_entry(name_conf,
141 S_IFREG|S_IRUSR|S_IWUSR,
143 if (proc_vlan_conf) {
144 proc_vlan_conf->proc_fops = &vlan_fops;
145 proc_vlan_conf->get_info = vlan_config_get_info;
154 * Add directory entry for VLAN device.
157 int vlan_proc_add_dev (struct net_device *vlandev)
159 struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev);
161 if (!(vlandev->priv_flags & IFF_802_1Q_VLAN)) {
163 "ERROR: vlan_proc_add, device -:%s:- is NOT a VLAN\n",
168 dev_info->dent = create_proc_entry(vlandev->name,
169 S_IFREG|S_IRUSR|S_IWUSR,
174 dev_info->dent->proc_fops = &vlandev_fops;
175 dev_info->dent->get_info = &vlandev_get_info;
176 dev_info->dent->data = vlandev;
179 printk(KERN_ERR "vlan_proc_add, device -:%s:- being added.\n",
186 * Delete directory entry for VLAN device.
188 int vlan_proc_rem_dev(struct net_device *vlandev)
191 printk(VLAN_ERR "%s: invalid argument: %p\n",
192 __FUNCTION__, vlandev);
196 if (!(vlandev->priv_flags & IFF_802_1Q_VLAN)) {
197 printk(VLAN_DBG "%s: invalid argument, device: %s is not a VLAN device, priv_flags: 0x%4hX.\n",
198 __FUNCTION__, vlandev->name, vlandev->priv_flags);
203 printk(VLAN_DBG __FUNCTION__ ": dev: %p\n", vlandev);
206 /** NOTE: This will consume the memory pointed to by dent, it seems. */
207 if (VLAN_DEV_INFO(vlandev)->dent) {
208 remove_proc_entry(VLAN_DEV_INFO(vlandev)->dent->name, proc_vlan_dir);
209 VLAN_DEV_INFO(vlandev)->dent = NULL;
215 /****** Proc filesystem entry points ****************************************/
218 * Read VLAN proc directory entry.
219 * This is universal routine for reading all entries in /proc/net/vlan
220 * directory. Each directory entry contains a pointer to the 'method' for
221 * preparing data for that entry.
223 * o allocate kernel buffer
224 * o call get_info() to prepare data
225 * o copy data to user space
226 * o release kernel buffer
228 * Return: number of bytes copied to user space (0, if no data)
231 static ssize_t vlan_proc_read(struct file *file, char *buf,
232 size_t count, loff_t *ppos)
234 struct inode *inode = file->f_dentry->d_inode;
235 struct proc_dir_entry *dent;
244 dent = inode->u.generic_ip;
245 if ((dent == NULL) || (dent->get_info == NULL))
248 page = kmalloc(VLAN_PROC_BUFSZ, GFP_KERNEL);
249 VLAN_MEM_DBG("page malloc, addr: %p size: %i\n",
250 page, VLAN_PROC_BUFSZ);
255 pos = dent->get_info(page, dent->data, 0, 0);
256 if (offs == n && offs < pos) {
257 len = min_t(int, pos - offs, count);
258 if (copy_to_user(buf, (page + offs), len)) {
269 VLAN_FMEM_DBG("page free, addr: %p\n", page);
274 * The following few functions build the content of /proc/net/vlan/config
277 static int vlan_proc_get_vlan_info(char* buf, unsigned int cnt)
279 struct net_device *vlandev = NULL;
280 struct vlan_group *grp = NULL;
282 char *nm_type = NULL;
283 struct vlan_dev_info *dev_info = NULL;
286 printk(VLAN_DBG __FUNCTION__ ": cnt == %i\n", cnt);
289 if (vlan_name_type == VLAN_NAME_TYPE_RAW_PLUS_VID) {
290 nm_type = "VLAN_NAME_TYPE_RAW_PLUS_VID";
291 } else if (vlan_name_type == VLAN_NAME_TYPE_PLUS_VID_NO_PAD) {
292 nm_type = "VLAN_NAME_TYPE_PLUS_VID_NO_PAD";
293 } else if (vlan_name_type == VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD) {
294 nm_type = "VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD";
295 } else if (vlan_name_type == VLAN_NAME_TYPE_PLUS_VID) {
296 nm_type = "VLAN_NAME_TYPE_PLUS_VID";
301 cnt += sprintf(buf + cnt, "Name-Type: %s\n", nm_type);
303 spin_lock_bh(&vlan_group_lock);
304 for (h = 0; h < VLAN_GRP_HASH_SIZE; h++) {
305 for (grp = vlan_group_hash[h]; grp != NULL; grp = grp->next) {
306 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
307 vlandev = grp->vlan_devices[i];
311 if ((cnt + 100) > VLAN_PROC_BUFSZ) {
312 if ((cnt+strlen(term_msg)) < VLAN_PROC_BUFSZ)
313 cnt += sprintf(buf+cnt, "%s", term_msg);
318 dev_info = VLAN_DEV_INFO(vlandev);
319 cnt += sprintf(buf + cnt, "%-15s| %d | %s\n",
322 dev_info->real_dev->name);
327 spin_unlock_bh(&vlan_group_lock);
333 * Prepare data for reading 'Config' entry.
334 * Return length of data.
337 static int vlan_config_get_info(char *buf, char **start,
340 strcpy(buf, conf_hdr);
341 return vlan_proc_get_vlan_info(buf, (unsigned int)(strlen(conf_hdr)));
345 * Prepare data for reading <device> entry.
346 * Return length of data.
348 * On entry, the 'start' argument will contain a pointer to VLAN device
352 static int vlandev_get_info(char *buf, char **start,
355 struct net_device *vlandev = (void *) start;
356 struct net_device_stats *stats = NULL;
357 struct vlan_dev_info *dev_info = NULL;
358 struct vlan_priority_tci_mapping *mp;
362 if ((vlandev == NULL) || (!(vlandev->priv_flags & IFF_802_1Q_VLAN)))
365 dev_info = VLAN_DEV_INFO(vlandev);
367 cnt += sprintf(buf + cnt, "%s VID: %d REORDER_HDR: %i dev->priv_flags: %hx\n",
368 vlandev->name, dev_info->vlan_id,
369 (int)(dev_info->flags & 1), vlandev->priv_flags);
371 stats = vlan_dev_get_stats(vlandev);
373 cnt += sprintf(buf + cnt, "%30s: %12lu\n",
374 "total frames received", stats->rx_packets);
376 cnt += sprintf(buf + cnt, "%30s: %12lu\n",
377 "total bytes received", stats->rx_bytes);
379 cnt += sprintf(buf + cnt, "%30s: %12lu\n",
380 "Broadcast/Multicast Rcvd", stats->multicast);
382 cnt += sprintf(buf + cnt, "\n%30s: %12lu\n",
383 "total frames transmitted", stats->tx_packets);
385 cnt += sprintf(buf + cnt, "%30s: %12lu\n",
386 "total bytes transmitted", stats->tx_bytes);
388 cnt += sprintf(buf + cnt, "%30s: %12lu\n",
389 "total headroom inc", dev_info->cnt_inc_headroom_on_tx);
391 cnt += sprintf(buf + cnt, "%30s: %12lu\n",
392 "total encap on xmit", dev_info->cnt_encap_on_xmit);
394 cnt += sprintf(buf + cnt, "Device: %s", dev_info->real_dev->name);
396 /* now show all PRIORITY mappings relating to this VLAN */
397 cnt += sprintf(buf + cnt, "\nINGRESS priority mappings: 0:%lu 1:%lu 2:%lu 3:%lu 4:%lu 5:%lu 6:%lu 7:%lu\n",
398 dev_info->ingress_priority_map[0],
399 dev_info->ingress_priority_map[1],
400 dev_info->ingress_priority_map[2],
401 dev_info->ingress_priority_map[3],
402 dev_info->ingress_priority_map[4],
403 dev_info->ingress_priority_map[5],
404 dev_info->ingress_priority_map[6],
405 dev_info->ingress_priority_map[7]);
407 if ((cnt + 100) > VLAN_PROC_BUFSZ) {
408 if ((cnt + strlen(term_msg)) >= VLAN_PROC_BUFSZ) {
409 /* should never get here */
412 cnt += sprintf(buf + cnt, "%s", term_msg);
417 cnt += sprintf(buf + cnt, "EGRESSS priority Mappings: ");
419 for (i = 0; i < 16; i++) {
420 mp = dev_info->egress_priority_map[i];
422 cnt += sprintf(buf + cnt, "%lu:%hu ",
423 mp->priority, ((mp->vlan_qos >> 13) & 0x7));
425 if ((cnt + 100) > VLAN_PROC_BUFSZ) {
426 if ((cnt + strlen(term_msg)) >= VLAN_PROC_BUFSZ) {
427 /* should never get here */
430 cnt += sprintf(buf + cnt, "%s", term_msg);
438 cnt += sprintf(buf + cnt, "\n");
443 #else /* No CONFIG_PROC_FS */
446 * No /proc - output stubs
449 int __init vlan_proc_init (void)
454 void vlan_proc_cleanup(void)
460 int vlan_proc_add_dev(struct net_device *vlandev)
465 int vlan_proc_rem_dev(struct net_device *vlandev)
470 #endif /* No CONFIG_PROC_FS */