1 /*****************************************************************************
2 * wanproc.c WAN Router Module. /proc filesystem interface.
4 * This module is completely hardware-independent and provides
5 * access to the router using Linux /proc filesystem.
9 * Copyright: (c) 1995-1999 Sangoma Technologies Inc.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 * ============================================================================
16 * Jun 02, 1999 Gideon Hack Updates for Linux 2.2.X kernels.
17 * Jun 29, 1997 Alan Cox Merged with 1.0.3 vendor code
18 * Jan 29, 1997 Gene Kozin v1.0.1. Implemented /proc read routines
19 * Jan 30, 1997 Alan Cox Hacked around for 2.1
20 * Dec 13, 1996 Gene Kozin Initial version (based on Sangoma's WANPIPE)
21 *****************************************************************************/
23 #include <linux/init.h> /* __initfunc et al. */
24 #include <linux/stddef.h> /* offsetof(), etc. */
25 #include <linux/errno.h> /* return codes */
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/wanrouter.h> /* WAN router API definitions */
29 #include <linux/seq_file.h>
30 #include <linux/smp_lock.h>
32 #include <net/net_namespace.h>
35 #define PROC_STATS_FORMAT "%30s: %12lu\n"
37 /****** Defines and Macros **************************************************/
39 #define PROT_DECODE(prot) ((prot == WANCONFIG_FR) ? " FR" :\
40 (prot == WANCONFIG_X25) ? " X25" : \
41 (prot == WANCONFIG_PPP) ? " PPP" : \
42 (prot == WANCONFIG_CHDLC) ? " CHDLC": \
43 (prot == WANCONFIG_MPPP) ? " MPPP" : \
46 /****** Function Prototypes *************************************************/
53 * Structures for interfacing with the /proc filesystem.
54 * Router creates its own directory /proc/net/router with the folowing
56 * config device configuration
57 * status global device statistics
58 * <device> entry for each WAN device
62 * Generic /proc/net/router/<file> file and inode operations
69 static struct proc_dir_entry
*proc_router
;
77 /****** Proc filesystem entry points ****************************************/
82 static void *r_start(struct seq_file
*m
, loff_t
*pos
)
84 struct wan_device
*wandev
;
89 return SEQ_START_TOKEN
;
90 for (wandev
= wanrouter_router_devlist
; l
-- && wandev
;
91 wandev
= wandev
->next
)
96 static void *r_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
98 struct wan_device
*wandev
= v
;
100 return (v
== SEQ_START_TOKEN
) ? wanrouter_router_devlist
: wandev
->next
;
103 static void r_stop(struct seq_file
*m
, void *v
)
108 static int config_show(struct seq_file
*m
, void *v
)
110 struct wan_device
*p
= v
;
111 if (v
== SEQ_START_TOKEN
) {
112 seq_puts(m
, "Device name | port |IRQ|DMA| mem.addr |"
113 "mem.size|option1|option2|option3|option4\n");
118 seq_printf(m
, "%-15s|0x%-4X|%3u|%3u| 0x%-8lX |0x%-6X|%7u|%7u|%7u|%7u\n",
119 p
->name
, p
->ioport
, p
->irq
, p
->dma
, p
->maddr
, p
->msize
,
120 p
->hw_opt
[0], p
->hw_opt
[1], p
->hw_opt
[2], p
->hw_opt
[3]);
124 static int status_show(struct seq_file
*m
, void *v
)
126 struct wan_device
*p
= v
;
127 if (v
== SEQ_START_TOKEN
) {
128 seq_puts(m
, "Device name |protocol|station|interface|"
129 "clocking|baud rate| MTU |ndev|link state\n");
134 seq_printf(m
, "%-15s|%-8s| %-7s| %-9s|%-8s|%9u|%5u|%3u |",
136 PROT_DECODE(p
->config_id
),
137 p
->config_id
== WANCONFIG_FR
?
138 (p
->station
? "Node" : "CPE") :
139 (p
->config_id
== WANCONFIG_X25
?
140 (p
->station
? "DCE" : "DTE") :
142 p
->interface
? "V.35" : "RS-232",
143 p
->clocking
? "internal" : "external",
149 case WAN_UNCONFIGURED
:
150 seq_printf(m
, "%-12s\n", "unconfigured");
152 case WAN_DISCONNECTED
:
153 seq_printf(m
, "%-12s\n", "disconnected");
156 seq_printf(m
, "%-12s\n", "connecting");
159 seq_printf(m
, "%-12s\n", "connected");
162 seq_printf(m
, "%-12s\n", "invalid");
168 static const struct seq_operations config_op
= {
175 static const struct seq_operations status_op
= {
182 static int config_open(struct inode
*inode
, struct file
*file
)
184 return seq_open(file
, &config_op
);
187 static int status_open(struct inode
*inode
, struct file
*file
)
189 return seq_open(file
, &status_op
);
192 static const struct file_operations config_fops
= {
193 .owner
= THIS_MODULE
,
197 .release
= seq_release
,
200 static const struct file_operations status_fops
= {
201 .owner
= THIS_MODULE
,
205 .release
= seq_release
,
208 static int wandev_show(struct seq_file
*m
, void *v
)
210 struct wan_device
*wandev
= m
->private;
212 if (wandev
->magic
!= ROUTER_MAGIC
)
215 if (!wandev
->state
) {
216 seq_puts(m
, "device is not configured!\n");
220 /* Update device statistics */
221 if (wandev
->update
) {
222 int err
= wandev
->update(wandev
);
223 if (err
== -EAGAIN
) {
224 seq_puts(m
, "Device is busy!\n");
228 seq_puts(m
, "Device is not configured!\n");
233 seq_printf(m
, PROC_STATS_FORMAT
,
234 "total packets received", wandev
->stats
.rx_packets
);
235 seq_printf(m
, PROC_STATS_FORMAT
,
236 "total packets transmitted", wandev
->stats
.tx_packets
);
237 seq_printf(m
, PROC_STATS_FORMAT
,
238 "total bytes received", wandev
->stats
.rx_bytes
);
239 seq_printf(m
, PROC_STATS_FORMAT
,
240 "total bytes transmitted", wandev
->stats
.tx_bytes
);
241 seq_printf(m
, PROC_STATS_FORMAT
,
242 "bad packets received", wandev
->stats
.rx_errors
);
243 seq_printf(m
, PROC_STATS_FORMAT
,
244 "packet transmit problems", wandev
->stats
.tx_errors
);
245 seq_printf(m
, PROC_STATS_FORMAT
,
246 "received frames dropped", wandev
->stats
.rx_dropped
);
247 seq_printf(m
, PROC_STATS_FORMAT
,
248 "transmit frames dropped", wandev
->stats
.tx_dropped
);
249 seq_printf(m
, PROC_STATS_FORMAT
,
250 "multicast packets received", wandev
->stats
.multicast
);
251 seq_printf(m
, PROC_STATS_FORMAT
,
252 "transmit collisions", wandev
->stats
.collisions
);
253 seq_printf(m
, PROC_STATS_FORMAT
,
254 "receive length errors", wandev
->stats
.rx_length_errors
);
255 seq_printf(m
, PROC_STATS_FORMAT
,
256 "receiver overrun errors", wandev
->stats
.rx_over_errors
);
257 seq_printf(m
, PROC_STATS_FORMAT
,
258 "CRC errors", wandev
->stats
.rx_crc_errors
);
259 seq_printf(m
, PROC_STATS_FORMAT
,
260 "frame format errors (aborts)", wandev
->stats
.rx_frame_errors
);
261 seq_printf(m
, PROC_STATS_FORMAT
,
262 "receiver fifo overrun", wandev
->stats
.rx_fifo_errors
);
263 seq_printf(m
, PROC_STATS_FORMAT
,
264 "receiver missed packet", wandev
->stats
.rx_missed_errors
);
265 seq_printf(m
, PROC_STATS_FORMAT
,
266 "aborted frames transmitted", wandev
->stats
.tx_aborted_errors
);
270 static int wandev_open(struct inode
*inode
, struct file
*file
)
272 return single_open(file
, wandev_show
, PDE(inode
)->data
);
275 static const struct file_operations wandev_fops
= {
276 .owner
= THIS_MODULE
,
280 .release
= single_release
,
281 .ioctl
= wanrouter_ioctl
,
285 * Initialize router proc interface.
288 int __init
wanrouter_proc_init(void)
290 struct proc_dir_entry
*p
;
291 proc_router
= proc_mkdir(ROUTER_NAME
, init_net
.proc_net
);
295 <<<<<<< HEAD
:net
/wanrouter
/wanproc
.c
296 p
= create_proc_entry("config", S_IRUGO
, proc_router
);
298 p
= proc_create("config", S_IRUGO
, proc_router
, &config_fops
);
299 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:net
/wanrouter
/wanproc
.c
302 <<<<<<< HEAD
:net
/wanrouter
/wanproc
.c
303 p
->proc_fops
= &config_fops
;
304 p
= create_proc_entry("status", S_IRUGO
, proc_router
);
306 p
= proc_create("status", S_IRUGO
, proc_router
, &status_fops
);
307 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:net
/wanrouter
/wanproc
.c
310 <<<<<<< HEAD
:net
/wanrouter
/wanproc
.c
311 p
->proc_fops
= &status_fops
;
313 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:net
/wanrouter
/wanproc
.c
316 remove_proc_entry("config", proc_router
);
318 remove_proc_entry(ROUTER_NAME
, init_net
.proc_net
);
324 * Clean up router proc interface.
327 void wanrouter_proc_cleanup(void)
329 remove_proc_entry("config", proc_router
);
330 remove_proc_entry("status", proc_router
);
331 remove_proc_entry(ROUTER_NAME
, init_net
.proc_net
);
335 * Add directory entry for WAN device.
338 int wanrouter_proc_add(struct wan_device
* wandev
)
340 if (wandev
->magic
!= ROUTER_MAGIC
)
343 <<<<<<< HEAD
:net
/wanrouter
/wanproc
.c
344 wandev
->dent
= create_proc_entry(wandev
->name
, S_IRUGO
, proc_router
);
346 wandev
->dent
= proc_create(wandev
->name
, S_IRUGO
,
347 proc_router
, &wandev_fops
);
348 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:net
/wanrouter
/wanproc
.c
351 <<<<<<< HEAD
:net
/wanrouter
/wanproc
.c
352 wandev
->dent
->proc_fops
= &wandev_fops
;
354 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:net
/wanrouter
/wanproc
.c
355 wandev
->dent
->data
= wandev
;
360 * Delete directory entry for WAN device.
362 int wanrouter_proc_delete(struct wan_device
* wandev
)
364 if (wandev
->magic
!= ROUTER_MAGIC
)
366 remove_proc_entry(wandev
->name
, proc_router
);
373 * No /proc - output stubs
376 int __init
wanrouter_proc_init(void)
381 void wanrouter_proc_cleanup(void)
385 int wanrouter_proc_add(struct wan_device
*wandev
)
390 int wanrouter_proc_delete(struct wan_device
*wandev
)