1 /* Modified by Broadcom Corp. Portions Copyright (c) Broadcom Corp, 2012. */
2 /******************************************************************************
3 * vlanproc.c VLAN Module. /proc filesystem interface.
5 * This module is completely hardware-independent and provides
6 * access to the router using Linux /proc filesystem.
8 * Author: Ben Greear, <greearb@candelatech.com> coppied from wanproc.c
9 * by: Gene Kozin <genek@compuserve.com>
11 * Copyright: (c) 1998 Ben Greear
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
17 * ============================================================================
18 * Jan 20, 1998 Ben Greear Initial Version
19 *****************************************************************************/
21 #include <linux/module.h>
22 #include <linux/errno.h>
23 #include <linux/kernel.h>
24 #include <linux/string.h>
25 #include <linux/proc_fs.h>
26 #include <linux/seq_file.h>
28 #include <linux/netdevice.h>
29 #include <linux/if_vlan.h>
30 #include <net/net_namespace.h>
31 #include <net/netns/generic.h>
35 /****** Function Prototypes *************************************************/
37 /* Methods for preparing data for reading proc entries */
38 static int vlan_seq_show(struct seq_file
*seq
, void *v
);
39 static void *vlan_seq_start(struct seq_file
*seq
, loff_t
*pos
);
40 static void *vlan_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
);
41 static void vlan_seq_stop(struct seq_file
*seq
, void *);
42 static int vlandev_seq_show(struct seq_file
*seq
, void *v
);
43 #ifdef CONFIG_INET_GRO
44 static int gro_write(struct file
*file
, const char __user
*buf
, size_t size
, loff_t
*ppos
);
45 #endif /* CONFIG_INET_GRO */
53 * Names of the proc directory entries
56 static const char name_root
[] = "vlan";
57 static const char name_conf
[] = "config";
60 * Structures for interfacing with the /proc filesystem.
61 * VLAN creates its own directory /proc/net/vlan with the folowing
63 * config device status/configuration
64 * <device> entry for each device
68 * Generic /proc/net/vlan/<file> file and inode operations
71 static const struct seq_operations vlan_seq_ops
= {
72 .start
= vlan_seq_start
,
73 .next
= vlan_seq_next
,
74 .stop
= vlan_seq_stop
,
75 .show
= vlan_seq_show
,
78 static int vlan_seq_open(struct inode
*inode
, struct file
*file
)
80 return seq_open_net(inode
, file
, &vlan_seq_ops
,
81 sizeof(struct seq_net_private
));
84 static const struct file_operations vlan_fops
= {
86 .open
= vlan_seq_open
,
89 .release
= seq_release_net
,
93 * /proc/net/vlan/<device> file and inode operations
96 static int vlandev_seq_open(struct inode
*inode
, struct file
*file
)
98 return single_open(file
, vlandev_seq_show
, PDE(inode
)->data
);
101 #ifdef CONFIG_INET_GRO
102 extern atomic_t gro_timer_init
;
103 static struct timer_list gro_timer
;
105 static int gro_timer_interval
;
106 extern struct napi_struct gro_napi
;
108 static void gro_watchdog(ulong data
)
110 struct net_device
*gro_dev
= (struct net_device
*)data
;
112 if (gro_dev
->features
& NETIF_F_GRO
) {
113 gro_timer
.expires
= jiffies
+ gro_timer_interval
;
114 add_timer(&gro_timer
);
117 spin_lock_bh(&gro_lock
);
118 generic_napi_gro_flush(&gro_napi
);
119 spin_unlock_bh(&gro_lock
);
122 static int gro_write(struct file
*file
, const char __user
*buf
, size_t size
, loff_t
*ppos
)
124 struct seq_file
*seq
= (struct seq_file
*)file
->private_data
;
125 struct net_device
*gro_dev
= seq
->private;
127 if (!atomic_read(&gro_timer_init
)) {
128 spin_lock_init(&gro_lock
);
130 init_timer(&gro_timer
);
131 gro_timer
.function
= gro_watchdog
;
132 atomic_set(&gro_timer_init
, 1);
135 if (size
< 5 || size
> 8)
138 if (strncmp(buf
, "-gro", 4))
141 sscanf(buf
, "-gro %d", &gro_timer_interval
);
143 if (gro_timer_interval
> 0) {
144 gro_dev
->features
|= NETIF_F_GRO
;
145 gro_timer
.data
= (ulong
)gro_dev
;
146 gro_timer
.expires
= jiffies
+ gro_timer_interval
;
147 mod_timer(&gro_timer
, jiffies
+ gro_timer_interval
);
148 printk("\ngro enabled with interval %d\n", gro_timer_interval
);
151 gro_dev
->features
&= ~NETIF_F_GRO
;
152 del_timer(&gro_timer
);
155 gro_watchdog((ulong
)gro_dev
);
156 printk("\ngro disabled\n");
161 #endif /* CONFIG_INET_GRO */
163 static const struct file_operations vlandev_fops
= {
164 .owner
= THIS_MODULE
,
165 .open
= vlandev_seq_open
,
167 #ifdef CONFIG_INET_GRO
169 #endif /* CONFIG_INET_GRO */
171 .release
= single_release
,
175 * Proc filesystem derectory entries.
179 static const char *const vlan_name_type_str
[VLAN_NAME_TYPE_HIGHEST
] = {
180 [VLAN_NAME_TYPE_RAW_PLUS_VID
] = "VLAN_NAME_TYPE_RAW_PLUS_VID",
181 [VLAN_NAME_TYPE_PLUS_VID_NO_PAD
] = "VLAN_NAME_TYPE_PLUS_VID_NO_PAD",
182 [VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD
] = "VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD",
183 [VLAN_NAME_TYPE_PLUS_VID
] = "VLAN_NAME_TYPE_PLUS_VID",
186 * Interface functions
190 * Clean up /proc/net/vlan entries
193 void vlan_proc_cleanup(struct net
*net
)
195 struct vlan_net
*vn
= net_generic(net
, vlan_net_id
);
197 if (vn
->proc_vlan_conf
)
198 remove_proc_entry(name_conf
, vn
->proc_vlan_dir
);
200 if (vn
->proc_vlan_dir
)
201 proc_net_remove(net
, name_root
);
203 /* Dynamically added entries should be cleaned up as their vlan_device
204 * is removed, so we should not have to take care of it here...
209 * Create /proc/net/vlan entries
212 int __net_init
vlan_proc_init(struct net
*net
)
214 struct vlan_net
*vn
= net_generic(net
, vlan_net_id
);
216 vn
->proc_vlan_dir
= proc_net_mkdir(net
, name_root
, net
->proc_net
);
217 if (!vn
->proc_vlan_dir
)
220 vn
->proc_vlan_conf
= proc_create(name_conf
, S_IFREG
|S_IRUSR
|S_IWUSR
,
221 vn
->proc_vlan_dir
, &vlan_fops
);
222 if (!vn
->proc_vlan_conf
)
227 pr_err("%s: can't create entry in proc filesystem!\n", __func__
);
228 vlan_proc_cleanup(net
);
233 * Add directory entry for VLAN device.
236 int vlan_proc_add_dev(struct net_device
*vlandev
)
238 struct vlan_dev_info
*dev_info
= vlan_dev_info(vlandev
);
239 struct vlan_net
*vn
= net_generic(dev_net(vlandev
), vlan_net_id
);
242 proc_create_data(vlandev
->name
, S_IFREG
|S_IRUSR
|S_IWUSR
,
243 vn
->proc_vlan_dir
, &vlandev_fops
, vlandev
);
250 * Delete directory entry for VLAN device.
252 int vlan_proc_rem_dev(struct net_device
*vlandev
)
254 struct vlan_net
*vn
= net_generic(dev_net(vlandev
), vlan_net_id
);
256 /** NOTE: This will consume the memory pointed to by dent, it seems. */
257 if (vlan_dev_info(vlandev
)->dent
) {
258 remove_proc_entry(vlan_dev_info(vlandev
)->dent
->name
,
260 vlan_dev_info(vlandev
)->dent
= NULL
;
265 /****** Proc filesystem entry points ****************************************/
268 * The following few functions build the content of /proc/net/vlan/config
271 /* start read of /proc/net/vlan/config */
272 static void *vlan_seq_start(struct seq_file
*seq
, loff_t
*pos
)
275 struct net_device
*dev
;
276 struct net
*net
= seq_file_net(seq
);
281 return SEQ_START_TOKEN
;
283 for_each_netdev_rcu(net
, dev
) {
284 if (!is_vlan_dev(dev
))
294 static void *vlan_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
296 struct net_device
*dev
;
297 struct net
*net
= seq_file_net(seq
);
301 dev
= (struct net_device
*)v
;
302 if (v
== SEQ_START_TOKEN
)
303 dev
= net_device_entry(&net
->dev_base_head
);
305 for_each_netdev_continue_rcu(net
, dev
) {
306 if (!is_vlan_dev(dev
))
315 static void vlan_seq_stop(struct seq_file
*seq
, void *v
)
321 static int vlan_seq_show(struct seq_file
*seq
, void *v
)
323 struct net
*net
= seq_file_net(seq
);
324 struct vlan_net
*vn
= net_generic(net
, vlan_net_id
);
326 if (v
== SEQ_START_TOKEN
) {
327 const char *nmtype
= NULL
;
329 seq_puts(seq
, "VLAN Dev name | VLAN ID\n");
331 if (vn
->name_type
< ARRAY_SIZE(vlan_name_type_str
))
332 nmtype
= vlan_name_type_str
[vn
->name_type
];
334 seq_printf(seq
, "Name-Type: %s\n",
335 nmtype
? nmtype
: "UNKNOWN");
337 const struct net_device
*vlandev
= v
;
338 const struct vlan_dev_info
*dev_info
= vlan_dev_info(vlandev
);
340 seq_printf(seq
, "%-15s| %d | %s\n", vlandev
->name
,
341 dev_info
->vlan_id
, dev_info
->real_dev
->name
);
346 static int vlandev_seq_show(struct seq_file
*seq
, void *offset
)
348 struct net_device
*vlandev
= (struct net_device
*) seq
->private;
349 const struct vlan_dev_info
*dev_info
= vlan_dev_info(vlandev
);
350 struct rtnl_link_stats64 temp
;
351 const struct rtnl_link_stats64
*stats
;
352 static const char fmt
[] = "%30s %12lu\n";
353 static const char fmt64
[] = "%30s %12llu\n";
356 if (!is_vlan_dev(vlandev
))
359 stats
= dev_get_stats(vlandev
, &temp
);
361 "%s VID: %d REORDER_HDR: %i dev->priv_flags: %hx\n",
362 vlandev
->name
, dev_info
->vlan_id
,
363 (int)(dev_info
->flags
& 1), vlandev
->priv_flags
);
365 seq_printf(seq
, fmt64
, "total frames received", stats
->rx_packets
);
366 seq_printf(seq
, fmt64
, "total bytes received", stats
->rx_bytes
);
367 seq_printf(seq
, fmt64
, "Broadcast/Multicast Rcvd", stats
->multicast
);
369 seq_printf(seq
, fmt64
, "total frames transmitted", stats
->tx_packets
);
370 seq_printf(seq
, fmt64
, "total bytes transmitted", stats
->tx_bytes
);
371 seq_printf(seq
, fmt
, "total headroom inc",
372 dev_info
->cnt_inc_headroom_on_tx
);
373 seq_printf(seq
, fmt
, "total encap on xmit",
374 dev_info
->cnt_encap_on_xmit
);
375 seq_printf(seq
, "Device: %s", dev_info
->real_dev
->name
);
376 /* now show all PRIORITY mappings relating to this VLAN */
377 seq_printf(seq
, "\nINGRESS priority mappings: "
378 "0:%u 1:%u 2:%u 3:%u 4:%u 5:%u 6:%u 7:%u\n",
379 dev_info
->ingress_priority_map
[0],
380 dev_info
->ingress_priority_map
[1],
381 dev_info
->ingress_priority_map
[2],
382 dev_info
->ingress_priority_map
[3],
383 dev_info
->ingress_priority_map
[4],
384 dev_info
->ingress_priority_map
[5],
385 dev_info
->ingress_priority_map
[6],
386 dev_info
->ingress_priority_map
[7]);
388 seq_printf(seq
, " EGRESS priority mappings: ");
389 for (i
= 0; i
< 16; i
++) {
390 const struct vlan_priority_tci_mapping
*mp
391 = dev_info
->egress_priority_map
[i
];
393 seq_printf(seq
, "%u:%hu ",
394 mp
->priority
, ((mp
->vlan_qos
>> 13) & 0x7));