1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/config.h>
21#include <linux/stddef.h>
22#include <linux/errno.h>
23#include <linux/kernel.h>
24#include <linux/slab.h>
25#include <linux/mm.h>
26#include <linux/string.h>
27#include <linux/init.h>
28#include <asm/segment.h>
29#include <asm/byteorder.h>
30#include <asm/uaccess.h>
31#include <asm/io.h>
32#include <linux/proc_fs.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
40
41#ifdef CONFIG_PROC_FS
42
43
44static ssize_t vlan_proc_read(struct file *file, char *buf, size_t count,
45 loff_t *ppos);
46
47
48
49static int vlan_config_get_info(char *buf, char **start, off_t offs, int len);
50static int vlandev_get_info(char *buf, char **start, off_t offs, int len);
51
52
53
54
55
56
57
58
59
60
61
62static char name_root[] = "vlan";
63static char name_conf[] = "config";
64static char term_msg[] = "***KERNEL: Out of buffer space!***\n";
65
66
67
68
69
70
71
72
73
74
75
76
77
78static struct file_operations vlan_fops = {
79 read: vlan_proc_read,
80 ioctl: NULL,
81};
82
83
84
85
86
87static struct file_operations vlandev_fops = {
88 read: vlan_proc_read,
89 ioctl: NULL,
90};
91
92
93
94
95
96
97
98
99
100static struct proc_dir_entry *proc_vlan_dir;
101
102
103
104
105
106static struct proc_dir_entry *proc_vlan_conf;
107
108
109static char conf_hdr[] = "VLAN Dev name | VLAN ID\n";
110
111
112
113
114
115
116
117
118
119void vlan_proc_cleanup(void)
120{
121 if (proc_vlan_conf)
122 remove_proc_entry(name_conf, proc_vlan_dir);
123
124 if (proc_vlan_dir)
125 proc_net_remove(name_root);
126
127
128
129
130}
131
132
133
134
135
136int __init vlan_proc_init(void)
137{
138 proc_vlan_dir = proc_mkdir(name_root, proc_net);
139 if (proc_vlan_dir) {
140 proc_vlan_conf = create_proc_entry(name_conf,
141 S_IFREG|S_IRUSR|S_IWUSR,
142 proc_vlan_dir);
143 if (proc_vlan_conf) {
144 proc_vlan_conf->proc_fops = &vlan_fops;
145 proc_vlan_conf->get_info = vlan_config_get_info;
146 return 0;
147 }
148 }
149 vlan_proc_cleanup();
150 return -ENOBUFS;
151}
152
153
154
155
156
157int vlan_proc_add_dev (struct net_device *vlandev)
158{
159 struct vlan_dev_info *dev_info = VLAN_DEV_INFO(vlandev);
160
161 if (!(vlandev->priv_flags & IFF_802_1Q_VLAN)) {
162 printk(KERN_ERR
163 "ERROR: vlan_proc_add, device -:%s:- is NOT a VLAN\n",
164 vlandev->name);
165 return -EINVAL;
166 }
167
168 dev_info->dent = create_proc_entry(vlandev->name,
169 S_IFREG|S_IRUSR|S_IWUSR,
170 proc_vlan_dir);
171 if (!dev_info->dent)
172 return -ENOBUFS;
173
174 dev_info->dent->proc_fops = &vlandev_fops;
175 dev_info->dent->get_info = &vlandev_get_info;
176 dev_info->dent->data = vlandev;
177
178#ifdef VLAN_DEBUG
179 printk(KERN_ERR "vlan_proc_add, device -:%s:- being added.\n",
180 vlandev->name);
181#endif
182 return 0;
183}
184
185
186
187
188int vlan_proc_rem_dev(struct net_device *vlandev)
189{
190 if (!vlandev) {
191 printk(VLAN_ERR "%s: invalid argument: %p\n",
192 __FUNCTION__, vlandev);
193 return -EINVAL;
194 }
195
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);
199 return -EINVAL;
200 }
201
202#ifdef VLAN_DEBUG
203 printk(VLAN_DBG __FUNCTION__ ": dev: %p\n", vlandev);
204#endif
205
206
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;
210 }
211
212 return 0;
213}
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231static ssize_t vlan_proc_read(struct file *file, char *buf,
232 size_t count, loff_t *ppos)
233{
234 struct inode *inode = file->f_dentry->d_inode;
235 struct proc_dir_entry *dent;
236 char *page;
237 int pos, len;
238 loff_t n = *ppos;
239 unsigned offs = n;
240
241 if (count <= 0)
242 return 0;
243
244 dent = inode->u.generic_ip;
245 if ((dent == NULL) || (dent->get_info == NULL))
246 return 0;
247
248 page = kmalloc(VLAN_PROC_BUFSZ, GFP_KERNEL);
249 VLAN_MEM_DBG("page malloc, addr: %p size: %i\n",
250 page, VLAN_PROC_BUFSZ);
251
252 if (page == NULL)
253 return -ENOBUFS;
254
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)) {
259 kfree(page);
260 return -EFAULT;
261 }
262
263 *ppos = offs + len;
264 } else {
265 len = 0;
266 }
267
268 kfree(page);
269 VLAN_FMEM_DBG("page free, addr: %p\n", page);
270 return len;
271}
272
273
274
275
276
277static int vlan_proc_get_vlan_info(char* buf, unsigned int cnt)
278{
279 struct net_device *vlandev = NULL;
280 struct vlan_group *grp = NULL;
281 int h, i;
282 char *nm_type = NULL;
283 struct vlan_dev_info *dev_info = NULL;
284
285#ifdef VLAN_DEBUG
286 printk(VLAN_DBG __FUNCTION__ ": cnt == %i\n", cnt);
287#endif
288
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";
297 } else {
298 nm_type = "UNKNOWN";
299 }
300
301 cnt += sprintf(buf + cnt, "Name-Type: %s\n", nm_type);
302
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];
308 if (!vlandev)
309 continue;
310
311 if ((cnt + 100) > VLAN_PROC_BUFSZ) {
312 if ((cnt+strlen(term_msg)) < VLAN_PROC_BUFSZ)
313 cnt += sprintf(buf+cnt, "%s", term_msg);
314
315 goto out;
316 }
317
318 dev_info = VLAN_DEV_INFO(vlandev);
319 cnt += sprintf(buf + cnt, "%-15s| %d | %s\n",
320 vlandev->name,
321 dev_info->vlan_id,
322 dev_info->real_dev->name);
323 }
324 }
325 }
326out:
327 spin_unlock_bh(&vlan_group_lock);
328
329 return cnt;
330}
331
332
333
334
335
336
337static int vlan_config_get_info(char *buf, char **start,
338 off_t offs, int len)
339{
340 strcpy(buf, conf_hdr);
341 return vlan_proc_get_vlan_info(buf, (unsigned int)(strlen(conf_hdr)));
342}
343
344
345
346
347
348
349
350
351
352static int vlandev_get_info(char *buf, char **start,
353 off_t offs, int len)
354{
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;
359 int cnt = 0;
360 int i;
361
362 if ((vlandev == NULL) || (!(vlandev->priv_flags & IFF_802_1Q_VLAN)))
363 return 0;
364
365 dev_info = VLAN_DEV_INFO(vlandev);
366
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);
370
371 stats = vlan_dev_get_stats(vlandev);
372
373 cnt += sprintf(buf + cnt, "%30s: %12lu\n",
374 "total frames received", stats->rx_packets);
375
376 cnt += sprintf(buf + cnt, "%30s: %12lu\n",
377 "total bytes received", stats->rx_bytes);
378
379 cnt += sprintf(buf + cnt, "%30s: %12lu\n",
380 "Broadcast/Multicast Rcvd", stats->multicast);
381
382 cnt += sprintf(buf + cnt, "\n%30s: %12lu\n",
383 "total frames transmitted", stats->tx_packets);
384
385 cnt += sprintf(buf + cnt, "%30s: %12lu\n",
386 "total bytes transmitted", stats->tx_bytes);
387
388 cnt += sprintf(buf + cnt, "%30s: %12lu\n",
389 "total headroom inc", dev_info->cnt_inc_headroom_on_tx);
390
391 cnt += sprintf(buf + cnt, "%30s: %12lu\n",
392 "total encap on xmit", dev_info->cnt_encap_on_xmit);
393
394 cnt += sprintf(buf + cnt, "Device: %s", dev_info->real_dev->name);
395
396
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]);
406
407 if ((cnt + 100) > VLAN_PROC_BUFSZ) {
408 if ((cnt + strlen(term_msg)) >= VLAN_PROC_BUFSZ) {
409
410 return cnt;
411 } else {
412 cnt += sprintf(buf + cnt, "%s", term_msg);
413 return cnt;
414 }
415 }
416
417 cnt += sprintf(buf + cnt, "EGRESSS priority Mappings: ");
418
419 for (i = 0; i < 16; i++) {
420 mp = dev_info->egress_priority_map[i];
421 while (mp) {
422 cnt += sprintf(buf + cnt, "%lu:%hu ",
423 mp->priority, ((mp->vlan_qos >> 13) & 0x7));
424
425 if ((cnt + 100) > VLAN_PROC_BUFSZ) {
426 if ((cnt + strlen(term_msg)) >= VLAN_PROC_BUFSZ) {
427
428 return cnt;
429 } else {
430 cnt += sprintf(buf + cnt, "%s", term_msg);
431 return cnt;
432 }
433 }
434 mp = mp->next;
435 }
436 }
437
438 cnt += sprintf(buf + cnt, "\n");
439
440 return cnt;
441}
442
443#else
444
445
446
447
448
449int __init vlan_proc_init (void)
450{
451 return 0;
452}
453
454void vlan_proc_cleanup(void)
455{
456 return;
457}
458
459
460int vlan_proc_add_dev(struct net_device *vlandev)
461{
462 return 0;
463}
464
465int vlan_proc_rem_dev(struct net_device *vlandev)
466{
467 return 0;
468}
469
470#endif
471