]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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, <[email protected]> coppied from wanproc.c | |
8 | * by: Gene Kozin <[email protected]> | |
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 | ||
1da177e4 LT |
20 | #include <linux/module.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() */ | |
e49332bd | 25 | #include <linux/mm.h> |
1da177e4 LT |
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> | |
32 | #include <linux/seq_file.h> | |
33 | #include <linux/fs.h> | |
34 | #include <linux/netdevice.h> | |
35 | #include <linux/if_vlan.h> | |
36 | #include "vlanproc.h" | |
37 | #include "vlan.h" | |
38 | ||
39 | /****** Function Prototypes *************************************************/ | |
40 | ||
41 | /* Methods for preparing data for reading proc entries */ | |
42 | static int vlan_seq_show(struct seq_file *seq, void *v); | |
43 | static void *vlan_seq_start(struct seq_file *seq, loff_t *pos); | |
44 | static void *vlan_seq_next(struct seq_file *seq, void *v, loff_t *pos); | |
45 | static void vlan_seq_stop(struct seq_file *seq, void *); | |
46 | static int vlandev_seq_show(struct seq_file *seq, void *v); | |
47 | ||
48 | /* | |
49 | * Global Data | |
50 | */ | |
51 | ||
52 | ||
53 | /* | |
122952fc | 54 | * Names of the proc directory entries |
1da177e4 LT |
55 | */ |
56 | ||
57 | static const char name_root[] = "vlan"; | |
58 | static const char name_conf[] = "config"; | |
59 | ||
60 | /* | |
61 | * Structures for interfacing with the /proc filesystem. | |
62 | * VLAN creates its own directory /proc/net/vlan with the folowing | |
63 | * entries: | |
64 | * config device status/configuration | |
65 | * <device> entry for each device | |
66 | */ | |
67 | ||
68 | /* | |
122952fc | 69 | * Generic /proc/net/vlan/<file> file and inode operations |
1da177e4 LT |
70 | */ |
71 | ||
56b3d975 | 72 | static const struct seq_operations vlan_seq_ops = { |
1da177e4 LT |
73 | .start = vlan_seq_start, |
74 | .next = vlan_seq_next, | |
75 | .stop = vlan_seq_stop, | |
76 | .show = vlan_seq_show, | |
77 | }; | |
78 | ||
79 | static int vlan_seq_open(struct inode *inode, struct file *file) | |
80 | { | |
81 | return seq_open(file, &vlan_seq_ops); | |
82 | } | |
83 | ||
9a32144e | 84 | static const struct file_operations vlan_fops = { |
1da177e4 LT |
85 | .owner = THIS_MODULE, |
86 | .open = vlan_seq_open, | |
87 | .read = seq_read, | |
88 | .llseek = seq_lseek, | |
89 | .release = seq_release, | |
90 | }; | |
91 | ||
92 | /* | |
93 | * /proc/net/vlan/<device> file and inode operations | |
94 | */ | |
95 | ||
96 | static int vlandev_seq_open(struct inode *inode, struct file *file) | |
97 | { | |
98 | return single_open(file, vlandev_seq_show, PDE(inode)->data); | |
99 | } | |
100 | ||
9a32144e | 101 | static const struct file_operations vlandev_fops = { |
1da177e4 LT |
102 | .owner = THIS_MODULE, |
103 | .open = vlandev_seq_open, | |
104 | .read = seq_read, | |
105 | .llseek = seq_lseek, | |
106 | .release = single_release, | |
107 | }; | |
108 | ||
109 | /* | |
110 | * Proc filesystem derectory entries. | |
111 | */ | |
112 | ||
113 | /* | |
122952fc | 114 | * /proc/net/vlan |
1da177e4 LT |
115 | */ |
116 | ||
117 | static struct proc_dir_entry *proc_vlan_dir; | |
118 | ||
119 | /* | |
122952fc | 120 | * /proc/net/vlan/config |
1da177e4 LT |
121 | */ |
122 | ||
123 | static struct proc_dir_entry *proc_vlan_conf; | |
124 | ||
125 | /* Strings */ | |
126 | static const char *vlan_name_type_str[VLAN_NAME_TYPE_HIGHEST] = { | |
127 | [VLAN_NAME_TYPE_RAW_PLUS_VID] = "VLAN_NAME_TYPE_RAW_PLUS_VID", | |
128 | [VLAN_NAME_TYPE_PLUS_VID_NO_PAD] = "VLAN_NAME_TYPE_PLUS_VID_NO_PAD", | |
129 | [VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD]= "VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD", | |
130 | [VLAN_NAME_TYPE_PLUS_VID] = "VLAN_NAME_TYPE_PLUS_VID", | |
131 | }; | |
132 | /* | |
133 | * Interface functions | |
134 | */ | |
135 | ||
136 | /* | |
137 | * Clean up /proc/net/vlan entries | |
138 | */ | |
139 | ||
140 | void vlan_proc_cleanup(void) | |
141 | { | |
142 | if (proc_vlan_conf) | |
143 | remove_proc_entry(name_conf, proc_vlan_dir); | |
144 | ||
145 | if (proc_vlan_dir) | |
146 | proc_net_remove(name_root); | |
147 | ||
148 | /* Dynamically added entries should be cleaned up as their vlan_device | |
149 | * is removed, so we should not have to take care of it here... | |
150 | */ | |
151 | } | |
152 | ||
153 | /* | |
154 | * Create /proc/net/vlan entries | |
155 | */ | |
156 | ||
157 | int __init vlan_proc_init(void) | |
158 | { | |
159 | proc_vlan_dir = proc_mkdir(name_root, proc_net); | |
160 | if (proc_vlan_dir) { | |
161 | proc_vlan_conf = create_proc_entry(name_conf, | |
162 | S_IFREG|S_IRUSR|S_IWUSR, | |
163 | proc_vlan_dir); | |
164 | if (proc_vlan_conf) { | |
165 | proc_vlan_conf->proc_fops = &vlan_fops; | |
166 | return 0; | |
167 | } | |
168 | } | |
169 | vlan_proc_cleanup(); | |
170 | return -ENOBUFS; | |
171 | } | |
172 | ||
173 | /* | |
174 | * Add directory entry for VLAN device. | |
175 | */ | |
176 | ||
177 | int vlan_proc_add_dev (struct net_device *vlandev) | |
178 | { | |
179 | struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev); | |
180 | ||
181 | if (!(vlandev->priv_flags & IFF_802_1Q_VLAN)) { | |
182 | printk(KERN_ERR | |
183 | "ERROR: vlan_proc_add, device -:%s:- is NOT a VLAN\n", | |
184 | vlandev->name); | |
185 | return -EINVAL; | |
186 | } | |
187 | ||
188 | dev_info->dent = create_proc_entry(vlandev->name, | |
189 | S_IFREG|S_IRUSR|S_IWUSR, | |
190 | proc_vlan_dir); | |
191 | if (!dev_info->dent) | |
192 | return -ENOBUFS; | |
193 | ||
194 | dev_info->dent->proc_fops = &vlandev_fops; | |
195 | dev_info->dent->data = vlandev; | |
196 | ||
197 | #ifdef VLAN_DEBUG | |
198 | printk(KERN_ERR "vlan_proc_add, device -:%s:- being added.\n", | |
199 | vlandev->name); | |
200 | #endif | |
201 | return 0; | |
202 | } | |
203 | ||
204 | /* | |
205 | * Delete directory entry for VLAN device. | |
206 | */ | |
207 | int vlan_proc_rem_dev(struct net_device *vlandev) | |
208 | { | |
209 | if (!vlandev) { | |
210 | printk(VLAN_ERR "%s: invalid argument: %p\n", | |
211 | __FUNCTION__, vlandev); | |
212 | return -EINVAL; | |
213 | } | |
214 | ||
215 | if (!(vlandev->priv_flags & IFF_802_1Q_VLAN)) { | |
216 | printk(VLAN_DBG "%s: invalid argument, device: %s is not a VLAN device, priv_flags: 0x%4hX.\n", | |
217 | __FUNCTION__, vlandev->name, vlandev->priv_flags); | |
218 | return -EINVAL; | |
219 | } | |
220 | ||
221 | #ifdef VLAN_DEBUG | |
222 | printk(VLAN_DBG "%s: dev: %p\n", __FUNCTION__, vlandev); | |
223 | #endif | |
224 | ||
225 | /** NOTE: This will consume the memory pointed to by dent, it seems. */ | |
226 | if (VLAN_DEV_INFO(vlandev)->dent) { | |
227 | remove_proc_entry(VLAN_DEV_INFO(vlandev)->dent->name, proc_vlan_dir); | |
228 | VLAN_DEV_INFO(vlandev)->dent = NULL; | |
229 | } | |
230 | ||
231 | return 0; | |
232 | } | |
233 | ||
234 | /****** Proc filesystem entry points ****************************************/ | |
235 | ||
236 | /* | |
237 | * The following few functions build the content of /proc/net/vlan/config | |
238 | */ | |
239 | ||
7562f876 | 240 | static inline int is_vlan_dev(struct net_device *dev) |
1da177e4 | 241 | { |
7562f876 | 242 | return dev->priv_flags & IFF_802_1Q_VLAN; |
1da177e4 LT |
243 | } |
244 | ||
122952fc | 245 | /* start read of /proc/net/vlan/config */ |
1da177e4 LT |
246 | static void *vlan_seq_start(struct seq_file *seq, loff_t *pos) |
247 | { | |
248 | struct net_device *dev; | |
249 | loff_t i = 1; | |
250 | ||
251 | read_lock(&dev_base_lock); | |
252 | ||
253 | if (*pos == 0) | |
254 | return SEQ_START_TOKEN; | |
122952fc | 255 | |
7562f876 PE |
256 | for_each_netdev(dev) { |
257 | if (!is_vlan_dev(dev)) | |
258 | continue; | |
259 | ||
260 | if (i++ == *pos) | |
261 | return dev; | |
262 | } | |
122952fc | 263 | |
7562f876 | 264 | return NULL; |
122952fc | 265 | } |
1da177e4 LT |
266 | |
267 | static void *vlan_seq_next(struct seq_file *seq, void *v, loff_t *pos) | |
268 | { | |
7562f876 PE |
269 | struct net_device *dev; |
270 | ||
1da177e4 LT |
271 | ++*pos; |
272 | ||
7562f876 PE |
273 | dev = (struct net_device *)v; |
274 | if (v == SEQ_START_TOKEN) | |
275 | dev = net_device_entry(&dev_base_head); | |
276 | ||
277 | for_each_netdev_continue(dev) { | |
278 | if (!is_vlan_dev(dev)) | |
279 | continue; | |
280 | ||
281 | return dev; | |
282 | } | |
283 | ||
284 | return NULL; | |
1da177e4 LT |
285 | } |
286 | ||
287 | static void vlan_seq_stop(struct seq_file *seq, void *v) | |
288 | { | |
289 | read_unlock(&dev_base_lock); | |
290 | } | |
291 | ||
292 | static int vlan_seq_show(struct seq_file *seq, void *v) | |
293 | { | |
294 | if (v == SEQ_START_TOKEN) { | |
295 | const char *nmtype = NULL; | |
296 | ||
297 | seq_puts(seq, "VLAN Dev name | VLAN ID\n"); | |
298 | ||
299 | if (vlan_name_type < ARRAY_SIZE(vlan_name_type_str)) | |
300 | nmtype = vlan_name_type_str[vlan_name_type]; | |
301 | ||
122952fc | 302 | seq_printf(seq, "Name-Type: %s\n", |
1da177e4 LT |
303 | nmtype ? nmtype : "UNKNOWN" ); |
304 | } else { | |
305 | const struct net_device *vlandev = v; | |
306 | const struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev); | |
307 | ||
122952fc | 308 | seq_printf(seq, "%-15s| %d | %s\n", vlandev->name, |
1da177e4 LT |
309 | dev_info->vlan_id, dev_info->real_dev->name); |
310 | } | |
311 | return 0; | |
312 | } | |
313 | ||
314 | static int vlandev_seq_show(struct seq_file *seq, void *offset) | |
315 | { | |
316 | struct net_device *vlandev = (struct net_device *) seq->private; | |
317 | const struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev); | |
318 | struct net_device_stats *stats; | |
319 | static const char fmt[] = "%30s %12lu\n"; | |
320 | int i; | |
321 | ||
322 | if ((vlandev == NULL) || (!(vlandev->priv_flags & IFF_802_1Q_VLAN))) | |
323 | return 0; | |
324 | ||
325 | seq_printf(seq, "%s VID: %d REORDER_HDR: %i dev->priv_flags: %hx\n", | |
326 | vlandev->name, dev_info->vlan_id, | |
327 | (int)(dev_info->flags & 1), vlandev->priv_flags); | |
328 | ||
329 | ||
330 | stats = vlan_dev_get_stats(vlandev); | |
331 | ||
332 | seq_printf(seq, fmt, "total frames received", stats->rx_packets); | |
333 | seq_printf(seq, fmt, "total bytes received", stats->rx_bytes); | |
334 | seq_printf(seq, fmt, "Broadcast/Multicast Rcvd", stats->multicast); | |
335 | seq_puts(seq, "\n"); | |
336 | seq_printf(seq, fmt, "total frames transmitted", stats->tx_packets); | |
337 | seq_printf(seq, fmt, "total bytes transmitted", stats->tx_bytes); | |
122952fc | 338 | seq_printf(seq, fmt, "total headroom inc", |
1da177e4 | 339 | dev_info->cnt_inc_headroom_on_tx); |
122952fc | 340 | seq_printf(seq, fmt, "total encap on xmit", |
1da177e4 LT |
341 | dev_info->cnt_encap_on_xmit); |
342 | seq_printf(seq, "Device: %s", dev_info->real_dev->name); | |
343 | /* now show all PRIORITY mappings relating to this VLAN */ | |
122952fc | 344 | seq_printf(seq, |
734423cf | 345 | "\nINGRESS priority mappings: 0:%u 1:%u 2:%u 3:%u 4:%u 5:%u 6:%u 7:%u\n", |
1da177e4 LT |
346 | dev_info->ingress_priority_map[0], |
347 | dev_info->ingress_priority_map[1], | |
348 | dev_info->ingress_priority_map[2], | |
349 | dev_info->ingress_priority_map[3], | |
350 | dev_info->ingress_priority_map[4], | |
351 | dev_info->ingress_priority_map[5], | |
352 | dev_info->ingress_priority_map[6], | |
353 | dev_info->ingress_priority_map[7]); | |
354 | ||
355 | seq_printf(seq, "EGRESSS priority Mappings: "); | |
356 | for (i = 0; i < 16; i++) { | |
357 | const struct vlan_priority_tci_mapping *mp | |
358 | = dev_info->egress_priority_map[i]; | |
359 | while (mp) { | |
734423cf | 360 | seq_printf(seq, "%u:%hu ", |
1da177e4 LT |
361 | mp->priority, ((mp->vlan_qos >> 13) & 0x7)); |
362 | mp = mp->next; | |
363 | } | |
364 | } | |
365 | seq_puts(seq, "\n"); | |
366 | ||
367 | return 0; | |
368 | } |