Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Viro <viro@math.psu.edu>2002-02-24 20:19:57 -0800
committerLinus Torvalds <torvalds@penguin.transmeta.com>2002-02-24 20:19:57 -0800
commit61e828bae3991ae128cbef381fd61347bdc7f42b (patch)
treed80191c9e01bc836d861682a2f3eb343617a16dd
parent7c6fc5d0e9acae2214018c63ed8de2ff379940cd (diff)
[PATCH] net/wanrouter/wan{proc,main}.c crapectomy
Patch below does the following: * removes dead code from wanproc.c. When file looks like #ifdef LINUX_2_4 <800 lines> #else <900 lines> #endif there's no excuse for keeping all that junk around. * switches wanproc.c to use of seq_file * removes dead code from wanmain.c (again, dead == never seen by cc1). * fixes indentation in both * removes buttloads of trailing spaces in these files, while we are at it. See if it's OK with you...
-rw-r--r--net/wanrouter/wanmain.c406
-rw-r--r--net/wanrouter/wanproc.c1250
2 files changed, 423 insertions, 1233 deletions
diff --git a/net/wanrouter/wanmain.c b/net/wanrouter/wanmain.c
index 38838887c22d..e4b00d683981 100644
--- a/net/wanrouter/wanmain.c
+++ b/net/wanrouter/wanmain.c
@@ -9,7 +9,7 @@
* o Logical connection management (switched virtual circuits)
* o Protocol encapsulation/decapsulation
*
-* Author: Gideon Hack
+* Author: Gideon Hack
*
* Copyright: (c) 1995-1999 Sangoma Technologies Inc.
*
@@ -18,11 +18,11 @@
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
* ============================================================================
-* Nov 24, 2000 Nenad Corbic Updated for 2.4.X kernels
+* Nov 24, 2000 Nenad Corbic Updated for 2.4.X kernels
* Nov 07, 2000 Nenad Corbic Fixed the Mulit-Port PPP for kernels 2.2.16 and
* greater.
* Aug 2, 2000 Nenad Corbic Block the Multi-Port PPP from running on
-* kernels 2.2.16 or greater. The SyncPPP
+* kernels 2.2.16 or greater. The SyncPPP
* has changed.
* Jul 13, 2000 Nenad Corbic Added SyncPPP support
* Added extra debugging in device_setup().
@@ -39,7 +39,7 @@
* Dec 22, 1998 Arnaldo Melo vmalloc/vfree used in device_setup to allocate
* kernel memory and copy configuration data to
* kernel space (for big firmwares)
-* Jun 02, 1999 Gideon Hack Updates for Linux 2.0.X and 2.2.X kernels.
+* Jun 02, 1999 Gideon Hack Updates for Linux 2.0.X and 2.2.X kernels.
*****************************************************************************/
#include <linux/version.h>
@@ -55,28 +55,10 @@
#include <asm/byteorder.h> /* htons(), etc. */
#include <linux/wanrouter.h> /* WAN router API definitions */
-
-#if defined(LINUX_2_4)
- #include <linux/vmalloc.h> /* vmalloc, vfree */
- #include <asm/uaccess.h> /* copy_to/from_user */
- #include <linux/init.h> /* __initfunc et al. */
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,3)
- #include <net/syncppp.h>
-#else
- #include <../drivers/net/wan/syncppp.h>
-#endif
-
-#elif defined(LINUX_2_1)
- #define LINUX_2_1
- #include <linux/vmalloc.h> /* vmalloc, vfree */
- #include <asm/uaccess.h> /* copy_to/from_user */
- #include <linux/init.h> /* __initfunc et al. */
- #include <../drivers/net/syncppp.h>
-
-#else
- #include <asm/segment.h> /* kernel <-> user copy */
-#endif
+#include <linux/vmalloc.h> /* vmalloc, vfree */
+#include <asm/uaccess.h> /* copy_to/from_user */
+#include <linux/init.h> /* __initfunc et al. */
+#include <net/syncppp.h>
#define KMEM_SAFETYZONE 8
@@ -84,7 +66,7 @@
static void * dbg_kmalloc(unsigned int size, int prio, int line) {
int i = 0;
void * v = kmalloc(size+sizeof(unsigned int)+2*KMEM_SAFETYZONE*8,prio);
- char * c1 = v;
+ char * c1 = v;
c1 += sizeof(unsigned int);
*((unsigned int *)v) = size;
@@ -137,12 +119,11 @@ static void dbg_kfree(void * v, int line) {
#define kfree(x) dbg_kfree(x,__LINE__)
*****************************************************************************/
-
/*
- * Function Prototypes
+ * Function Prototypes
*/
-/*
+/*
* Kernel loadable module interface.
*/
#ifdef MODULE
@@ -150,8 +131,8 @@ int init_module (void);
void cleanup_module (void);
#endif
-/*
- * WAN device IOCTL handlers
+/*
+ * WAN device IOCTL handlers
*/
static int device_setup(wan_device_t *wandev, wandev_conf_t *u_conf);
@@ -159,9 +140,9 @@ static int device_stat(wan_device_t *wandev, wandev_stat_t *u_stat);
static int device_shutdown(wan_device_t *wandev);
static int device_new_if(wan_device_t *wandev, wanif_conf_t *u_conf);
static int device_del_if(wan_device_t *wandev, char *u_name);
-
-/*
- * Miscellaneous
+
+/*
+ * Miscellaneous
*/
static wan_device_t *find_device (char *name);
@@ -181,8 +162,8 @@ static char modname[] = ROUTER_NAME; /* short module name */
wan_device_t* router_devlist = NULL; /* list of registered devices */
static int devcnt = 0;
-/*
- * Organize Unique Identifiers for encapsulation/decapsulation
+/*
+ * Organize Unique Identifiers for encapsulation/decapsulation
*/
static unsigned char oui_ether[] = { 0x00, 0x00, 0x00 };
@@ -213,18 +194,15 @@ int wanrouter_init(void)
#ifdef CONFIG_VENDOR_SANGOMA
sdladrv_init();
wanpipe_init();
-#endif
-
+#endif
+
return err;
}
-
-#ifdef LINUX_2_4
static void __exit wanrouter_cleanup (void)
{
wanrouter_proc_cleanup();
}
-#endif
#else
@@ -249,10 +227,10 @@ int init_module (void)
printk(KERN_INFO "%s v%u.%u %s\n",
fullname, ROUTER_VERSION, ROUTER_RELEASE, copyright);
-
+
err = wanrouter_proc_init();
-
- if (err){
+
+ if (err){
printk(KERN_INFO
"%s: can't create entry in proc filesystem!\n", modname);
}
@@ -299,21 +277,21 @@ int register_wan_device(wan_device_t *wandev)
if ((wandev == NULL) || (wandev->magic != ROUTER_MAGIC) ||
(wandev->name == NULL))
return -EINVAL;
-
+
namelen = strlen(wandev->name);
if (!namelen || (namelen > WAN_DRVNAME_SZ))
return -EINVAL;
-
+
if (find_device(wandev->name) != NULL)
return -EEXIST;
-#ifdef WANDEBUG
+#ifdef WANDEBUG
printk(KERN_INFO "%s: registering WAN device %s\n",
modname, wandev->name);
#endif
/*
- * Register /proc directory entry
+ * Register /proc directory entry
*/
err = wanrouter_proc_add(wandev);
if (err) {
@@ -327,7 +305,7 @@ int register_wan_device(wan_device_t *wandev)
* Initialize fields of the wan_device structure maintained by the
* router and update local data.
*/
-
+
wandev->ndev = 0;
wandev->dev = NULL;
wandev->next = router_devlist;
@@ -364,20 +342,18 @@ int unregister_wan_device(char *name)
if (wandev == NULL)
return -ENODEV;
-#ifdef WANDEBUG
+#ifdef WANDEBUG
printk(KERN_INFO "%s: unregistering WAN device %s\n", modname, name);
#endif
- if (wandev->state != WAN_UNCONFIGURED) {
+ if (wandev->state != WAN_UNCONFIGURED)
device_shutdown(wandev);
- }
-
- if (prev){
+
+ if (prev)
prev->next = wandev->next;
- }else{
+ else
router_devlist = wandev->next;
- }
-
+
--devcnt;
wanrouter_proc_delete(wandev);
MOD_DEC_USE_COUNT;
@@ -457,7 +433,7 @@ unsigned short wanrouter_type_trans (struct sk_buff *skb, netdevice_t *dev)
skb->data[cnt+1], skb->data[cnt+2],
skb->data[cnt+3], dev->name);
return 0;
- }
+ }
ethertype = *((unsigned short*)&skb->data[cnt+4]);
cnt += 6;
break;
@@ -491,23 +467,20 @@ int wanrouter_ioctl(struct inode *inode, struct file *file,
struct proc_dir_entry *dent;
wan_device_t *wandev;
- #if defined (LINUX_2_1) || defined (LINUX_2_4)
- if (!capable(CAP_NET_ADMIN)){
+ if (!capable(CAP_NET_ADMIN))
return -EPERM;
- }
- #endif
-
+
if ((cmd >> 8) != ROUTER_IOCTL)
return -EINVAL;
-
+
dent = PDE(inode);
if ((dent == NULL) || (dent->data == NULL))
return -EINVAL;
-
+
wandev = dent->data;
if (wandev->magic != ROUTER_MAGIC)
return -EINVAL;
-
+
switch (cmd) {
case ROUTER_SETUP:
err = device_setup(wandev, (void*)arg);
@@ -560,103 +533,62 @@ static int device_setup (wan_device_t *wandev, wandev_conf_t *u_conf)
wandev_conf_t *conf;
int err = -EINVAL;
- if (wandev->setup == NULL){ /* Nothing to do ? */
+ if (wandev->setup == NULL) { /* Nothing to do ? */
printk(KERN_INFO "%s: ERROR, No setup script: wandev->setup()\n",
wandev->name);
return 0;
}
- #ifdef LINUX_2_0
- err = verify_area (VERIFY_READ, u_conf, sizeof(wandev_conf_t));
- if(err){
- return err;
- }
- #endif
-
conf = kmalloc(sizeof(wandev_conf_t), GFP_KERNEL);
if (conf == NULL){
printk(KERN_INFO "%s: ERROR, Failed to allocate kernel memory !\n",
wandev->name);
return -ENOBUFS;
}
-
- #if defined (LINUX_2_1) || defined (LINUX_2_4)
- if(copy_from_user(conf, u_conf, sizeof(wandev_conf_t))) {
+
+ if (copy_from_user(conf, u_conf, sizeof(wandev_conf_t))) {
printk(KERN_INFO "%s: Failed to copy user config data to kernel space!\n",
wandev->name);
kfree(conf);
return -EFAULT;
}
- #else
- memcpy_fromfs ((void *)conf, (void *)u_conf, sizeof(wandev_conf_t));
- #endif
-
- if (conf->magic != ROUTER_MAGIC){
+
+ if (conf->magic != ROUTER_MAGIC) {
kfree(conf);
printk(KERN_INFO "%s: ERROR, Invalid MAGIC Number\n",
wandev->name);
- return -EINVAL;
+ return -EINVAL;
}
- if (conf->data_size && conf->data){
- if(conf->data_size > 128000 || conf->data_size < 0) {
- printk(KERN_INFO
+ if (conf->data_size && conf->data) {
+ if (conf->data_size > 128000 || conf->data_size < 0) {
+ printk(KERN_INFO
"%s: ERROR, Invalid firmware data size %i !\n",
wandev->name, conf->data_size);
kfree(conf);
- return -EINVAL;;
+ return -EINVAL;
}
-#if defined (LINUX_2_1) || defined (LINUX_2_4)
data = vmalloc(conf->data_size);
- if (data) {
- if(!copy_from_user(data, conf->data, conf->data_size)){
- conf->data=data;
- err = wandev->setup(wandev,conf);
- }else{
- printk(KERN_INFO
- "%s: ERROR, Faild to copy from user data !\n",
- wandev->name);
- err = -EFAULT;
- }
- }else{
- printk(KERN_INFO
+ if (!data) {
+ printk(KERN_INFO
"%s: ERROR, Faild allocate kernel memory !\n",
wandev->name);
- err = -ENOBUFS;
- }
-
- if (data){
- vfree(data);
- }
-#else
- err = verify_area(VERIFY_READ, conf->data, conf->data_size);
- if (!err) {
- data = kmalloc(conf->data_size, GFP_KERNEL);
- if (data) {
- memcpy_fromfs(data, (void*)conf->data,
- conf->data_size);
- conf->data = data;
- }else{
- printk(KERN_INFO
- "%s: ERROR, Faild allocate kernel memory !\n",wandev->name);
- err = -ENOMEM;
- }
- }else{
- printk(KERN_INFO
- "%s: ERROR, Faild to copy from user data !\n",wandev->name);
+ kfree(conf);
+ return -ENOBUFS;
}
-
- if (!err){
+ if (!copy_from_user(data, conf->data, conf->data_size)) {
+ conf->data = data;
err = wandev->setup(wandev, conf);
+ } else {
+ printk(KERN_INFO
+ "%s: ERROR, Faild to copy from user data !\n",
+ wandev->name);
+ err = -EFAULT;
}
-
- if (data){
- kfree(data);
- }
-#endif
- }else{
- printk(KERN_INFO
+ vfree(data);
+ } else {
+ printk(KERN_INFO
"%s: ERROR, No firmware found ! Firmware size = %i !\n",
wandev->name, conf->data_size);
}
@@ -670,37 +602,33 @@ static int device_setup (wan_device_t *wandev, wandev_conf_t *u_conf)
* o delete all not opened logical channels for this device
* o call driver's shutdown() entry point
*/
-
+
static int device_shutdown (wan_device_t *wandev)
{
netdevice_t *dev;
int err=0;
-
- if (wandev->state == WAN_UNCONFIGURED){
+
+ if (wandev->state == WAN_UNCONFIGURED)
return 0;
- }
printk(KERN_INFO "\n%s: Shutting Down!\n",wandev->name);
-
+
for (dev = wandev->dev; dev;) {
- if ((err=delete_interface(wandev, dev->name)) != 0){
+ if ((err=delete_interface(wandev, dev->name)) != 0)
return err;
- }
-
/* The above function deallocates the current dev
* structure. Therefore, we cannot use dev->priv
* as the next element: wandev->dev points to the
* next element */
dev = wandev->dev;
}
-
- if (wandev->ndev){
+
+ if (wandev->ndev)
return -EBUSY; /* there are opened interfaces */
- }
-
+
if (wandev->shutdown)
err=wandev->shutdown(wandev);
-
+
return err;
}
@@ -712,13 +640,6 @@ static int device_stat (wan_device_t *wandev, wandev_stat_t *u_stat)
{
wandev_stat_t stat;
- #ifdef LINUX_2_0
- int err;
- err = verify_area(VERIFY_WRITE, u_stat, sizeof(wandev_stat_t));
- if (err)
- return err;
- #endif
-
memset(&stat, 0, sizeof(stat));
/* Ask device driver to update device statistics */
@@ -729,12 +650,8 @@ static int device_stat (wan_device_t *wandev, wandev_stat_t *u_stat)
stat.ndev = wandev->ndev;
stat.state = wandev->state;
- #if defined (LINUX_2_1) || defined (LINUX_2_4)
- if(copy_to_user(u_stat, &stat, sizeof(stat)))
+ if (copy_to_user(u_stat, &stat, sizeof(stat)))
return -EFAULT;
- #else
- memcpy_tofs((void*)u_stat, (void*)&stat, sizeof(stat));
- #endif
return 0;
}
@@ -760,103 +677,67 @@ static int device_new_if (wan_device_t *wandev, wanif_conf_t *u_conf)
if ((wandev->state == WAN_UNCONFIGURED) || (wandev->new_if == NULL))
return -ENODEV;
-
-#if defined (LINUX_2_1) || defined (LINUX_2_4)
- if(copy_from_user(&conf, u_conf, sizeof(wanif_conf_t)))
+
+ if (copy_from_user(&conf, u_conf, sizeof(wanif_conf_t)))
return -EFAULT;
-#else
- err = verify_area(VERIFY_READ, u_conf, sizeof(wanif_conf_t));
- if (err)
- return err;
- memcpy_fromfs((void*)&conf, (void*)u_conf, sizeof(wanif_conf_t));
-#endif
-
+
if (conf.magic != ROUTER_MAGIC)
return -EINVAL;
- err = -EPROTONOSUPPORT;
-
-
+ if (conf.config_id == WANCONFIG_MPPP) {
#ifdef CONFIG_WANPIPE_MULTPPP
- if (conf.config_id == WANCONFIG_MPPP){
-
pppdev = kmalloc(sizeof(struct ppp_device), GFP_KERNEL);
- if (pppdev == NULL){
+ if (pppdev == NULL)
return -ENOBUFS;
- }
memset(pppdev, 0, sizeof(struct ppp_device));
-
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,16)
pppdev->dev = kmalloc(sizeof(netdevice_t), GFP_KERNEL);
- if (pppdev->dev == NULL){
+ if (pppdev->dev == NULL) {
kfree(pppdev);
return -ENOBUFS;
}
memset(pppdev->dev, 0, sizeof(netdevice_t));
-#endif
-
err = wandev->new_if(wandev, (netdevice_t *)pppdev, &conf);
-
- #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,16)
- dev = pppdev->dev;
- #else
- dev = &pppdev->dev;
- #endif
-
- }else{
-
- dev = kmalloc(sizeof(netdevice_t), GFP_KERNEL);
- if (dev == NULL){
- return -ENOBUFS;
- }
- memset(dev, 0, sizeof(netdevice_t));
- err = wandev->new_if(wandev, dev, &conf);
- }
-
+ dev = pppdev->dev;
#else
- /* Sync PPP is disabled */
- if (conf.config_id != WANCONFIG_MPPP){
-
+ printk(KERN_INFO "%s: Wanpipe Mulit-Port PPP support has not been compiled in!\n",
+ wandev->name);
+ return -EPROTONOSUPPORT;
+#endif
+ } else {
dev = kmalloc(sizeof(netdevice_t), GFP_KERNEL);
- if (dev == NULL){
+ if (dev == NULL)
return -ENOBUFS;
- }
- memset(dev, 0, sizeof(netdevice_t));
+ memset(dev, 0, sizeof(netdevice_t));
err = wandev->new_if(wandev, dev, &conf);
- }else{
- printk(KERN_INFO "%s: Wanpipe Mulit-Port PPP support has not been compiled in!\n",
- wandev->name);
- return err;
}
-#endif
-
+
if (!err) {
/* Register network interface. This will invoke init()
* function supplied by the driver. If device registered
* successfully, add it to the interface list.
*/
- if (dev->name == NULL){
+ if (dev->name == NULL) {
err = -EINVAL;
- }else if (dev_get(dev->name)){
+ } else if (dev_get(dev->name)) {
err = -EEXIST; /* name already exists */
- }else{
-
- #ifdef WANDEBUG
+ } else {
+
+ #ifdef WANDEBUG
printk(KERN_INFO "%s: registering interface %s...\n",
modname, dev->name);
- #endif
-
+ #endif
+
err = register_netdev(dev);
if (!err) {
netdevice_t *slave=NULL;
unsigned long smp_flags=0;
-
+
lock_adapter_irq(&wandev->lock, &smp_flags);
-
- if (wandev->dev == NULL){
+
+ if (wandev->dev == NULL) {
wandev->dev = dev;
- }else{
+ } else {
for (slave=wandev->dev;
*((netdevice_t**)slave->priv);
slave=*((netdevice_t**)slave->priv));
@@ -864,7 +745,7 @@ static int device_new_if (wan_device_t *wandev, wanif_conf_t *u_conf)
*((netdevice_t**)slave->priv) = dev;
}
++wandev->ndev;
-
+
unlock_adapter_irq(&wandev->lock, &smp_flags);
return 0; /* done !!! */
}
@@ -874,25 +755,23 @@ static int device_new_if (wan_device_t *wandev, wanif_conf_t *u_conf)
}
/* This code has moved from del_if() function */
- if (dev->priv){
+ if (dev->priv) {
kfree(dev->priv);
- dev->priv=NULL;
+ dev->priv = NULL;
}
-
- #ifdef CONFIG_WANPIPE_MULTPPP
- if (conf.config_id == WANCONFIG_MPPP){
+
+#ifdef CONFIG_WANPIPE_MULTPPP
+ if (conf.config_id == WANCONFIG_MPPP)
kfree(pppdev);
- }else{
+ else
kfree(dev);
- }
- #else
+#else
/* Sync PPP is disabled */
- if (conf.config_id != WANCONFIG_MPPP){
+ if (conf.config_id != WANCONFIG_MPPP)
kfree(dev);
- }
- #endif
-
+#endif
+
return err;
}
@@ -910,42 +789,31 @@ static int device_del_if (wan_device_t *wandev, char *u_name)
if (wandev->state == WAN_UNCONFIGURED)
return -ENODEV;
-
- #ifdef LINUX_2_0
- err = verify_area(VERIFY_READ, u_name, WAN_IFNAME_SZ);
- if (err)
- return err;
- #endif
memset(name, 0, sizeof(name));
- #if defined (LINUX_2_1) || defined (LINUX_2_4)
- if(copy_from_user(name, u_name, WAN_IFNAME_SZ))
+ if (copy_from_user(name, u_name, WAN_IFNAME_SZ))
return -EFAULT;
- #else
- memcpy_fromfs((void*)name, (void*)u_name, WAN_IFNAME_SZ);
- #endif
err = delete_interface(wandev, name);
if (err)
- return(err);
+ return err;
/* If last interface being deleted, shutdown card
* This helps with administration at leaf nodes
- * (You can tell if the person at the other end of the phone
+ * (You can tell if the person at the other end of the phone
* has an interface configured) and avoids DoS vulnerabilities
* in binary driver files - this fixes a problem with the current
* Sangoma driver going into strange states when all the network
* interfaces are deleted and the link irrecoverably disconnected.
- */
+ */
- if (!wandev->ndev && wandev->shutdown){
+ if (!wandev->ndev && wandev->shutdown)
err = wandev->shutdown(wandev);
- }
+
return err;
}
-
/*
* Miscellaneous Functions
*/
@@ -995,18 +863,12 @@ static int delete_interface (wan_device_t *wandev, char *name)
dev = *slave;
}
unlock_adapter_irq(&wandev->lock, &smp_flags);
-
- if (dev == NULL){
+
+ if (dev == NULL)
return -ENODEV; /* interface not found */
- }
-
- #ifdef LINUX_2_4
- if (netif_running(dev)){
- #else
- if (dev->start) {
- #endif
+
+ if (netif_running(dev))
return -EBUSY; /* interface in use */
- }
if (wandev->del_if)
wandev->del_if(wandev, dev);
@@ -1023,9 +885,9 @@ static int delete_interface (wan_device_t *wandev, char *name)
}
--wandev->ndev;
unlock_adapter_irq(&wandev->lock, &smp_flags);
-
- printk(KERN_INFO "%s: unregistering '%s'\n", wandev->name, dev->name);
-
+
+ printk(KERN_INFO "%s: unregistering '%s'\n", wandev->name, dev->name);
+
/* Due to new interface linking method using dev->priv,
* this code has moved from del_if() function.*/
if (dev->priv){
@@ -1035,48 +897,28 @@ static int delete_interface (wan_device_t *wandev, char *name)
unregister_netdev(dev);
- #ifdef LINUX_2_4
- kfree(dev);
- #else
- if (dev->name){
- kfree(dev->name);
- }
kfree(dev);
- #endif
return 0;
}
void lock_adapter_irq(spinlock_t *lock, unsigned long *smp_flags)
{
- #ifdef LINUX_2_0
- save_flags(*smp_flags);
- cli();
- #else
spin_lock_irqsave(lock, *smp_flags);
- #endif
}
void unlock_adapter_irq(spinlock_t *lock, unsigned long *smp_flags)
{
- #ifdef LINUX_2_0
- restore_flags(*smp_flags);
- #else
spin_unlock_irqrestore(lock, *smp_flags);
- #endif
}
-
-
-#if defined (LINUX_2_1) || defined (LINUX_2_4)
EXPORT_SYMBOL(register_wan_device);
EXPORT_SYMBOL(unregister_wan_device);
EXPORT_SYMBOL(wanrouter_encapsulate);
EXPORT_SYMBOL(wanrouter_type_trans);
EXPORT_SYMBOL(lock_adapter_irq);
EXPORT_SYMBOL(unlock_adapter_irq);
-#endif
/*
* End
diff --git a/net/wanrouter/wanproc.c b/net/wanrouter/wanproc.c
index 51b0f8b18c9b..0fb5206ca8f6 100644
--- a/net/wanrouter/wanproc.c
+++ b/net/wanrouter/wanproc.c
@@ -31,23 +31,15 @@
#include <asm/byteorder.h> /* htons(), etc. */
#include <asm/io.h>
#include <linux/wanrouter.h> /* WAN router API definitions */
+#include <linux/seq_file.h>
+#include <linux/smp_lock.h>
+#include <linux/init.h> /* __initfunc et al. */
+#include <asm/uaccess.h> /* copy_to_user */
-
-
-#if defined(LINUX_2_1) || defined(LINUX_2_4)
- #include <linux/init.h> /* __initfunc et al. */
- #include <asm/uaccess.h> /* copy_to_user */
- #define PROC_STATS_FORMAT "%30s: %12lu\n"
-#else
- #define PROC_STATS_FORMAT "%30s: %12u\n"
- #include <asm/segment.h> /* kernel <-> user copy */
-#endif
-
+#define PROC_STATS_FORMAT "%30s: %12lu\n"
/****** Defines and Macros **************************************************/
-#define PROC_BUFSZ 4000 /* buffer size for printing proc info */
-
#define PROT_DECODE(prot) ((prot == WANCONFIG_FR) ? " FR" :\
(prot == WANCONFIG_X25) ? " X25" : \
(prot == WANCONFIG_PPP) ? " PPP" : \
@@ -69,962 +61,346 @@ typedef struct wan_stat_entry
#ifdef CONFIG_PROC_FS
+/* Proc filesystem interface */
+static int router_proc_perms(struct inode *, int);
-#ifdef LINUX_2_4 /* Start of LINUX 2.4.X code */
-
+/* Miscellaneous */
- /* Proc filesystem interface */
- static int router_proc_perms(struct inode *, int);
- static ssize_t router_proc_read(struct file* file, char* buf, size_t count, loff_t *ppos);
-
- /* Methods for preparing data for reading proc entries */
-
- static int config_get_info(char* buf, char** start, off_t offs, int len);
- static int status_get_info(char* buf, char** start, off_t offs, int len);
- static int wandev_get_info(char* buf, char** start, off_t offs, int len);
-
- /* Miscellaneous */
-
- /*
- * Structures for interfacing with the /proc filesystem.
- * Router creates its own directory /proc/net/router with the folowing
- * entries:
- * config device configuration
- * status global device statistics
- * <device> entry for each WAN device
- */
-
- /*
- * Generic /proc/net/router/<file> file and inode operations
- */
- static struct file_operations router_fops =
- {
- read: router_proc_read,
- };
+/*
+ * Structures for interfacing with the /proc filesystem.
+ * Router creates its own directory /proc/net/router with the folowing
+ * entries:
+ * config device configuration
+ * status global device statistics
+ * <device> entry for each WAN device
+ */
- static struct inode_operations router_inode =
- {
- permission: router_proc_perms,
- };
+/*
+ * Generic /proc/net/router/<file> file and inode operations
+ */
- /*
- * /proc/net/router/<device> file operations
- */
+static struct inode_operations router_inode =
+{
+ permission: router_proc_perms,
+};
- static struct file_operations wandev_fops =
- {
- read: router_proc_read,
- ioctl: wanrouter_ioctl,
- };
+/*
+ * /proc/net/router
+ */
- /*
- * /proc/net/router
- */
+static struct proc_dir_entry *proc_router;
- static struct proc_dir_entry *proc_router;
+/* Strings */
- /* Strings */
- static char conf_hdr[] =
- "Device name | port |IRQ|DMA| mem.addr |mem.size|"
- "option1|option2|option3|option4\n";
-
- static char stat_hdr[] =
- "Device name |protocol|station|interface|clocking|baud rate"
- "| MTU |ndev|link state\n";
+/*
+ * Interface functions
+ */
+/****** Proc filesystem entry points ****************************************/
- /*
- * Interface functions
- */
+/*
+ * Verify access rights.
+ */
- /*
- * Initialize router proc interface.
- */
+static int router_proc_perms (struct inode* inode, int op)
+{
+ return 0;
+}
- int __init wanrouter_proc_init (void)
- {
- struct proc_dir_entry *p;
- proc_router = proc_mkdir(ROUTER_NAME, proc_net);
- if (!proc_router)
- goto fail;
+/*
+ * Iterator
+ */
+static void *r_start(struct seq_file *m, loff_t *pos)
+{
+ wan_device_t *wandev;
+ loff_t l = *pos;
+
+ lock_kernel();
+ if (!l--)
+ return (void *)1;
+ for (wandev = router_devlist; l-- && wandev; wandev = wandev->next)
+ ;
+ return wandev;
+}
+static void *r_next(struct seq_file *m, void *v, loff_t *pos)
+{
+ wan_device_t *wandev = v;
+ (*pos)++;
+ return (v == (void *)1) ? router_devlist : wandev->next;
+}
+static void r_stop(struct seq_file *m, void *v)
+{
+ unlock_kernel();
+}
- p = create_proc_entry("config",0,proc_router);
- if (!p)
- goto fail_config;
- p->proc_fops = &router_fops;
- p->proc_iops = &router_inode;
- p->get_info = config_get_info;
- p = create_proc_entry("status",0,proc_router);
- if (!p)
- goto fail_stat;
- p->proc_fops = &router_fops;
- p->proc_iops = &router_inode;
- p->get_info = status_get_info;
+static int config_show(struct seq_file *m, void *v)
+{
+ wan_device_t *p = v;
+ if (v == (void *)1) {
+ seq_puts(m, "Device name | port |IRQ|DMA| mem.addr |");
+ seq_puts(m, "mem.size|option1|option2|option3|option4\n");
return 0;
- fail_stat:
- remove_proc_entry("config", proc_router);
- fail_config:
- remove_proc_entry(ROUTER_NAME, proc_net);
- fail:
- return -ENOMEM;
}
-
- /*
- * Clean up router proc interface.
- */
-
- void wanrouter_proc_cleanup (void)
- {
- remove_proc_entry("config", proc_router);
- remove_proc_entry("status", proc_router);
- remove_proc_entry(ROUTER_NAME,proc_net);
- }
-
- /*
- * Add directory entry for WAN device.
- */
-
- int wanrouter_proc_add (wan_device_t* wandev)
- {
- if (wandev->magic != ROUTER_MAGIC)
- return -EINVAL;
-
- wandev->dent = create_proc_entry(wandev->name, 0, proc_router);
- if (!wandev->dent)
- return -ENOMEM;
- wandev->dent->proc_fops = &wandev_fops;
- wandev->dent->proc_iops = &router_inode;
- wandev->dent->get_info = wandev_get_info;
- wandev->dent->data = wandev;
+ if (!p->state)
return 0;
- }
+ seq_printf(m, "%-15s|0x%-4X|%3u|%3u| 0x%-8lX |0x%-6X|%7u|%7u|%7u|%7u\n",
+ p->name, p->ioport, p->irq, p->dma, p->maddr, p->msize,
+ p->hw_opt[0], p->hw_opt[1], p->hw_opt[2], p->hw_opt[3]);
+ return 0;
+}
- /*
- * Delete directory entry for WAN device.
- */
-
- int wanrouter_proc_delete(wan_device_t* wandev)
- {
- if (wandev->magic != ROUTER_MAGIC)
- return -EINVAL;
- remove_proc_entry(wandev->name, proc_router);
+static int status_show(struct seq_file *m, void *v)
+{
+ wan_device_t *p = v;
+ if (v == (void *)1) {
+ seq_puts(m, "Device name |protocol|station|interface|");
+ seq_puts(m, "clocking|baud rate| MTU |ndev|link state\n");
return 0;
}
-
- /****** Proc filesystem entry points ****************************************/
-
- /*
- * Verify access rights.
- */
-
- static int router_proc_perms (struct inode* inode, int op)
- {
+ if (!p->state)
return 0;
+ seq_printf(m, "%-15s|%-8s|%-7s|%-9s|%-8s|%9u|%5u|%3u |",
+ p->name,
+ PROT_DECODE(p->config_id),
+ p->config_id == WANCONFIG_FR ?
+ (p->station ? " Node" : " CPE") :
+ (p->config_id == WANCONFIG_X25 ?
+ (p->station ? " DCE" : " DTE") :
+ (" N/A")),
+ p->interface ? " V.35" : " RS-232",
+ p->clocking ? "internal" : "external",
+ p->bps,
+ p->mtu,
+ p->ndev);
+
+ switch (p->state) {
+ case WAN_UNCONFIGURED:
+ seq_printf(m, "%-12s\n", "unconfigured");
+ break;
+ case WAN_DISCONNECTED:
+ seq_printf(m, "%-12s\n", "disconnected");
+ break;
+ case WAN_CONNECTING:
+ seq_printf(m, "%-12s\n", "connecting");
+ break;
+ case WAN_CONNECTED:
+ seq_printf(m, "%-12s\n", "connected");
+ break;
+ default:
+ seq_printf(m, "%-12s\n", "invalid");
+ break;
}
+ return 0;
+}
- /*
- * Read router proc directory entry.
- * This is universal routine for reading all entries in /proc/net/wanrouter
- * directory. Each directory entry contains a pointer to the 'method' for
- * preparing data for that entry.
- * o verify arguments
- * o allocate kernel buffer
- * o call get_info() to prepare data
- * o copy data to user space
- * o release kernel buffer
- *
- * Return: number of bytes copied to user space (0, if no data)
- * <0 error
- */
-
- static ssize_t router_proc_read(struct file* file, char* buf, size_t count,
- loff_t *ppos)
- {
- struct inode *inode = file->f_dentry->d_inode;
- struct proc_dir_entry* dent;
- char* page;
- int pos, offs, len;
-
- if (count <= 0)
- return 0;
-
- dent = PDE(inode);
- if ((dent == NULL) || (dent->get_info == NULL))
- return 0;
-
- page = kmalloc(PROC_BUFSZ, GFP_KERNEL);
- if (page == NULL)
- return -ENOBUFS;
-
- pos = dent->get_info(page, dent->data, 0, 0);
- offs = file->f_pos;
- if (offs < pos) {
- len = min_t(unsigned int, pos - offs, count);
- if (copy_to_user(buf, (page + offs), len)) {
- kfree(page);
- return -EFAULT;
- }
- file->f_pos += len;
- }
- else
- len = 0;
- kfree(page);
- return len;
- }
-
- /*
- * Prepare data for reading 'Config' entry.
- * Return length of data.
- */
-
- static int config_get_info(char* buf, char** start, off_t offs, int len)
- {
- int cnt = sizeof(conf_hdr) - 1;
- wan_device_t* wandev;
- strcpy(buf, conf_hdr);
- for (wandev = router_devlist;
- wandev && (cnt < (PROC_BUFSZ - 120));
- wandev = wandev->next) {
- if (wandev->state) cnt += sprintf(&buf[cnt],
- "%-15s|0x%-4X|%3u|%3u| 0x%-8lX |0x%-6X|%7u|%7u|%7u|%7u\n",
- wandev->name,
- wandev->ioport,
- wandev->irq,
- wandev->dma,
- wandev->maddr,
- wandev->msize,
- wandev->hw_opt[0],
- wandev->hw_opt[1],
- wandev->hw_opt[2],
- wandev->hw_opt[3]);
- }
-
- return cnt;
- }
-
- /*
- * Prepare data for reading 'Status' entry.
- * Return length of data.
- */
-
- static int status_get_info(char* buf, char** start, off_t offs, int len)
- {
- int cnt = 0;
- wan_device_t* wandev;
-
- //cnt += sprintf(&buf[cnt], "\nSTATUS:\n\n");
- strcpy(&buf[cnt], stat_hdr);
- cnt += sizeof(stat_hdr) - 1;
-
- for (wandev = router_devlist;
- wandev && (cnt < (PROC_BUFSZ - 80));
- wandev = wandev->next) {
- if (!wandev->state) continue;
- cnt += sprintf(&buf[cnt],
- "%-15s|%-8s|%-7s|%-9s|%-8s|%9u|%5u|%3u |",
- wandev->name,
- PROT_DECODE(wandev->config_id),
- wandev->config_id == WANCONFIG_FR ?
- (wandev->station ? " Node" : " CPE") :
- (wandev->config_id == WANCONFIG_X25 ?
- (wandev->station ? " DCE" : " DTE") :
- (" N/A")),
- wandev->interface ? " V.35" : " RS-232",
- wandev->clocking ? "internal" : "external",
- wandev->bps,
- wandev->mtu,
- wandev->ndev);
-
- switch (wandev->state) {
-
- case WAN_UNCONFIGURED:
- cnt += sprintf(&buf[cnt], "%-12s\n", "unconfigured");
- break;
-
- case WAN_DISCONNECTED:
- cnt += sprintf(&buf[cnt], "%-12s\n", "disconnected");
- break;
-
- case WAN_CONNECTING:
- cnt += sprintf(&buf[cnt], "%-12s\n", "connecting");
- break;
-
- case WAN_CONNECTED:
- cnt += sprintf(&buf[cnt], "%-12s\n", "connected");
- break;
-
- default:
- cnt += sprintf(&buf[cnt], "%-12s\n", "invalid");
- break;
- }
- }
- return cnt;
- }
-
- /*
- * Prepare data for reading <device> entry.
- * Return length of data.
- *
- * On entry, the 'start' argument will contain a pointer to WAN device
- * data space.
- */
-
- static int wandev_get_info(char* buf, char** start, off_t offs, int len)
- {
- wan_device_t* wandev = (void*)start;
- int cnt = 0;
- int rslt = 0;
-
- if ((wandev == NULL) || (wandev->magic != ROUTER_MAGIC))
- return 0;
- if (!wandev->state)
- return sprintf(&buf[cnt], "device is not configured!\n");
-
- /* Update device statistics */
- if (wandev->update) {
-
- rslt = wandev->update(wandev);
- if(rslt) {
- switch (rslt) {
- case -EAGAIN:
- return sprintf(&buf[cnt], "Device is busy!\n");
-
- default:
- return sprintf(&buf[cnt],
- "Device is not configured!\n");
- }
- }
- }
-
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "total packets received", wandev->stats.rx_packets);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "total packets transmitted", wandev->stats.tx_packets);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "total bytes received", wandev->stats.rx_bytes);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "total bytes transmitted", wandev->stats.tx_bytes);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "bad packets received", wandev->stats.rx_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "packet transmit problems", wandev->stats.tx_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "received frames dropped", wandev->stats.rx_dropped);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "transmit frames dropped", wandev->stats.tx_dropped);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "multicast packets received", wandev->stats.multicast);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "transmit collisions", wandev->stats.collisions);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "receive length errors", wandev->stats.rx_length_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "receiver overrun errors", wandev->stats.rx_over_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "CRC errors", wandev->stats.rx_crc_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "frame format errors (aborts)", wandev->stats.rx_frame_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "receiver fifo overrun", wandev->stats.rx_fifo_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "receiver missed packet", wandev->stats.rx_missed_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "aborted frames transmitted", wandev->stats.tx_aborted_errors);
- return cnt;
- }
-
-
-#else /* ------------------- END OF LINUX 2.4.X VERSION -------------*/
-
-
-
- /* Proc filesystem interface */
- static int router_proc_perms(struct inode *, int);
-#ifdef LINUX_2_1
- static ssize_t router_proc_read(struct file *file, char *buf, size_t count, loff_t *ppos);
-#else
- static int router_proc_read(
- struct inode* inode, struct file* file, char* buf, int count);
- static int device_write(
- struct inode* inode, struct file* file, const char* buf, int count);
-#endif
-
- /* Methods for preparing data for reading proc entries */
- static int config_get_info(char* buf, char** start, off_t offs, int len,
- int dummy);
- static int status_get_info(char* buf, char** start, off_t offs, int len,
- int dummy);
- static int wandev_get_info(char* buf, char** start, off_t offs, int len,
- int dummy);
-
- /* Miscellaneous */
-
- /*
- * Global Data
- */
-
- /*
- * Names of the proc directory entries
- */
-
- static char name_root[] = ROUTER_NAME;
- static char name_conf[] = "config";
- static char name_stat[] = "status";
-
- /*
- * Structures for interfacing with the /proc filesystem.
- * Router creates its own directory /proc/net/router with the folowing
- * entries:
- * config device configuration
- * status global device statistics
- * <device> entry for each WAN device
- */
-
- /*
- * Generic /proc/net/router/<file> file and inode operations
- */
-#ifdef LINUX_2_1
- static struct file_operations router_fops =
- {
- NULL, /* lseek */
- router_proc_read, /* read */
- NULL, /* write */
- NULL, /* readdir */
- NULL, /* select */
- NULL, /* ioctl */
- NULL, /* mmap */
- NULL, /* no special open code */
- NULL, /* flush */
- NULL, /* no special release code */
- NULL /* can't fsync */
- };
-#else
- static struct file_operations router_fops =
- {
- NULL, /* lseek */
- router_proc_read, /* read */
- NULL, /* write */
- NULL, /* readdir */
- NULL, /* select */
- NULL, /* ioctl */
- NULL, /* mmap */
- NULL, /* no special open code */
- NULL, /* no special release code */
- NULL /* can't fsync */
- };
-#endif
-
- static struct inode_operations router_inode =
- {
- &router_fops,
- NULL, /* create */
- NULL, /* lookup */
- NULL, /* link */
- NULL, /* unlink */
- NULL, /* symlink */
- NULL, /* mkdir */
- NULL, /* rmdir */
- NULL, /* mknod */
- NULL, /* rename */
- NULL, /* follow link */
- NULL, /* readlink */
- NULL, /* readpage */
- NULL, /* writepage */
- NULL, /* bmap */
- NULL, /* truncate */
- router_proc_perms
- };
-
- /*
- * /proc/net/router/<device> file and inode operations
- */
-
-#ifdef LINUX_2_1
- static struct file_operations wandev_fops =
- {
- NULL, /* lseek */
- router_proc_read, /* read */
- NULL, /* write */
- NULL, /* readdir */
- NULL, /* select */
- wanrouter_ioctl, /* ioctl */
- NULL, /* mmap */
- NULL, /* no special open code */
- NULL, /* flush */
- NULL, /* no special release code */
- NULL /* can't fsync */
- };
-#else
- static struct file_operations wandev_fops =
- {
- NULL, /* lseek */
- router_proc_read, /* read */
- device_write, /* write */
- NULL, /* readdir */
- NULL, /* select */
- wanrouter_ioctl, /* ioctl */
- NULL, /* mmap */
- NULL, /* no special open code */
- NULL, /* no special release code */
- NULL /* can't fsync */
- };
-#endif
-
- static struct inode_operations wandev_inode =
- {
- &wandev_fops,
- NULL, /* create */
- NULL, /* lookup */
- NULL, /* link */
- NULL, /* unlink */
- NULL, /* symlink */
- NULL, /* mkdir */
- NULL, /* rmdir */
- NULL, /* mknod */
- NULL, /* rename */
- NULL, /* readlink */
- NULL, /* follow_link */
- NULL, /* readpage */
- NULL, /* writepage */
- NULL, /* bmap */
- NULL, /* truncate */
- router_proc_perms
- };
-
- /*
- * Proc filesystem derectory entries.
- */
-
- /*
- * /proc/net/router
- */
-
- static struct proc_dir_entry proc_router =
- {
- 0, /* .low_ino */
- sizeof(name_root) - 1, /* .namelen */
- name_root, /* .name */
- 0555 | S_IFDIR, /* .mode */
- 2, /* .nlink */
- 0, /* .uid */
- 0, /* .gid */
- 0, /* .size */
- &proc_dir_inode_operations, /* .ops */
- NULL, /* .get_info */
- NULL, /* .fill_node */
- NULL, /* .next */
- NULL, /* .parent */
- NULL, /* .subdir */
- NULL, /* .data */
- };
-
- /*
- * /proc/net/router/config
- */
-
- static struct proc_dir_entry proc_router_conf =
- {
- 0, /* .low_ino */
- sizeof(name_conf) - 1, /* .namelen */
- name_conf, /* .name */
- 0444 | S_IFREG, /* .mode */
- 1, /* .nlink */
- 0, /* .uid */
- 0, /* .gid */
- 0, /* .size */
- &router_inode, /* .ops */
- &config_get_info, /* .get_info */
- NULL, /* .fill_node */
- NULL, /* .next */
- NULL, /* .parent */
- NULL, /* .subdir */
- NULL, /* .data */
- };
-
- /*
- * /proc/net/router/status
- */
-
- static struct proc_dir_entry proc_router_stat =
- {
- 0, /* .low_ino */
- sizeof(name_stat) - 1, /* .namelen */
- name_stat, /* .name */
- 0444 | S_IFREG, /* .mode */
- 1, /* .nlink */
- 0, /* .uid */
- 0, /* .gid */
- 0, /* .size */
- &router_inode, /* .ops */
- status_get_info, /* .get_info */
- NULL, /* .fill_node */
- NULL, /* .next */
- NULL, /* .parent */
- NULL, /* .subdir */
- NULL, /* .data */
- };
-
- /* Strings */
- static char conf_hdr[] =
- "Device name | port |IRQ|DMA| mem.addr |mem.size|"
- "option1|option2|option3|option4\n";
-
- static char stat_hdr[] =
- "Device name |protocol|station|interface|clocking|baud rate| MTU |ndev"
- "|link state\n";
-
-
- /*
- * Interface functions
- */
-
- /*
- * Initialize router proc interface.
- */
-
-#ifdef LINUX_2_1
- __initfunc(int wanrouter_proc_init (void))
- {
- int err = proc_register(proc_net, &proc_router);
-
- if (!err) {
- proc_register(&proc_router, &proc_router_conf);
- proc_register(&proc_router, &proc_router_stat);
- }
- return err;
- }
-#else
- int wanrouter_proc_init (void)
- {
- int err = proc_register_dynamic(&proc_net, &proc_router);
-
- if (!err) {
- proc_register_dynamic(&proc_router, &proc_router_conf);
- proc_register_dynamic(&proc_router, &proc_router_stat);
- }
- return err;
- }
-#endif
+static struct seq_operations config_op = {
+ start: r_start,
+ next: r_next,
+ stop: r_stop,
+ show: config_show
+};
+
+static struct seq_operations status_op = {
+ start: r_start,
+ next: r_next,
+ stop: r_stop,
+ show: status_show
+};
+
+static int config_open(struct inode *inode, struct file *file)
+{
+ return seq_open(file, &config_op);
+}
- /*
- * Clean up router proc interface.
- */
+static int status_open(struct inode *inode, struct file *file)
+{
+ return seq_open(file, &status_op);
+}
- void wanrouter_proc_cleanup (void)
- {
- proc_unregister(&proc_router, proc_router_conf.low_ino);
- proc_unregister(&proc_router, proc_router_stat.low_ino);
-#ifdef LINUX_2_1
- proc_unregister(proc_net, proc_router.low_ino);
-#else
- proc_unregister(&proc_net, proc_router.low_ino);
-#endif
- }
+static struct file_operations config_fops =
+{
+ open: config_open,
+ read: seq_read,
+ llseek: seq_lseek,
+ release: seq_release,
+};
- /*
- * Add directory entry for WAN device.
- */
+static struct file_operations status_fops =
+{
+ open: status_open,
+ read: seq_read,
+ llseek: seq_lseek,
+ release: seq_release,
+};
- int wanrouter_proc_add (wan_device_t* wandev)
- {
- if (wandev->magic != ROUTER_MAGIC)
- return -EINVAL;
-
- memset(&wandev->dent, 0, sizeof(wandev->dent));
- wandev->dent.namelen = strlen(wandev->name);
- wandev->dent.name = wandev->name;
- wandev->dent.mode = 0444 | S_IFREG;
- wandev->dent.nlink = 1;
- wandev->dent.ops = &wandev_inode;
- wandev->dent.get_info = &wandev_get_info;
- wandev->dent.data = wandev;
-#ifdef LINUX_2_1
- return proc_register(&proc_router, &wandev->dent);
-#else
- return proc_register_dynamic(&proc_router, &wandev->dent);
-#endif
- }
+static void *single_start(struct seq_file *p, loff_t *pos)
+{
+ return *pos == 0 ? p->private : NULL;
+}
+static void *single_next(struct seq_file *p, void *v, loff_t *pos)
+{
+ ++*pos;
+ return NULL;
+}
+static void single_stop(struct seq_file *p, void *v)
+{
+}
+static int wandev_show(struct seq_file *m, void *v)
+{
+ wan_device_t *wandev = v;
- /*
- * Delete directory entry for WAN device.
- */
-
- int wanrouter_proc_delete(wan_device_t* wandev)
- {
- if (wandev->magic != ROUTER_MAGIC)
- return -EINVAL;
- proc_unregister(&proc_router, wandev->dent.low_ino);
+ if (wandev->magic != ROUTER_MAGIC)
return 0;
- }
-
- /****** Proc filesystem entry points ****************************************/
- /*
- * Verify access rights.
- */
-
- static int router_proc_perms (struct inode* inode, int op)
- {
+ if (!wandev->state) {
+ seq_puts(m, "device is not configured!\n");
return 0;
}
- /*
- * Read router proc directory entry.
- * This is universal routine for reading all entries in /proc/net/wanrouter
- * directory. Each directory entry contains a pointer to the 'method' for
- * preparing data for that entry.
- * o verify arguments
- * o allocate kernel buffer
- * o call get_info() to prepare data
- * o copy data to user space
- * o release kernel buffer
- *
- * Return: number of bytes copied to user space (0, if no data)
- * <0 error
- */
-#ifdef LINUX_2_1
- static ssize_t router_proc_read(struct file* file, char* buf, size_t count,
- loff_t *ppos)
- {
- struct inode *inode = file->f_dentry->d_inode;
- struct proc_dir_entry* dent;
- char* page;
- int pos, offs, len;
-
- if (count <= 0)
+ /* Update device statistics */
+ if (wandev->update) {
+ int err = wandev->update(wandev);
+ if (err == -EAGAIN) {
+ seq_printf(m, "Device is busy!\n");
return 0;
-
- dent = PDE(inode);
- if ((dent == NULL) || (dent->get_info == NULL))
- return 0;
-
- page = kmalloc(PROC_BUFSZ, GFP_KERNEL);
- if (page == NULL)
- return -ENOBUFS;
-
- pos = dent->get_info(page, dent->data, 0, 0, 0);
- offs = file->f_pos;
- if (offs < pos) {
- len = min_t(unsigned int, pos - offs, count);
- if (copy_to_user(buf, (page + offs), len)) {
- kfree(page);
- return -EFAULT;
- }
- file->f_pos += len;
}
- else
- len = 0;
- kfree(page);
- return len;
- }
-
-#else
- static int router_proc_read(
- struct inode* inode, struct file* file, char* buf, int count)
- {
- struct proc_dir_entry* dent;
- char* page;
- int err, pos, offs, len;
-
- if (count <= 0)
+ if (err) {
+ seq_printf(m, "Device is not configured!\n");
return 0;
- dent = PDE(inode);
- if ((dent == NULL) || (dent->get_info == NULL))
- return -ENODATA;
- err = verify_area(VERIFY_WRITE, buf, count);
- if (err) return err;
-
- page = kmalloc(PROC_BUFSZ, GFP_KERNEL);
- if (page == NULL)
- return -ENOMEM;
-
- pos = dent->get_info(page, dent->data, 0, 0, 0);
- offs = file->f_pos;
- if (offs < pos) {
- len = min_t(unsigned int, pos - offs, count);
- memcpy_tofs((void*)buf, (void*)(page + offs), len);
- file->f_pos += len;
}
- else len = 0;
- kfree(page);
- return len;
}
-#endif
-
-
- /*
- * Prepare data for reading 'Config' entry.
- * Return length of data.
- */
-
- static int config_get_info(char* buf, char** start, off_t offs, int len,
- int dummy)
- {
- int cnt = sizeof(conf_hdr) - 1;
- wan_device_t* wandev;
- strcpy(buf, conf_hdr);
- for (wandev = router_devlist;
- wandev && (cnt < (PROC_BUFSZ - 120));
- wandev = wandev->next) {
- if (wandev->state) cnt += sprintf(&buf[cnt],
- "%-15s|0x%-4X|%3u|%3u| 0x%-8lX |0x%-6X|%7u|%7u|%7u|%7u\n",
- wandev->name,
- wandev->ioport,
- wandev->irq,
- wandev->dma,
- wandev->maddr,
- wandev->msize,
- wandev->hw_opt[0],
- wandev->hw_opt[1],
- wandev->hw_opt[2],
- wandev->hw_opt[3]);
- }
-
- return cnt;
- }
-
- /*
- * Prepare data for reading 'Status' entry.
- * Return length of data.
- */
-
- static int status_get_info(char* buf, char** start, off_t offs, int len,
- int dummy)
- {
- int cnt = 0;
- wan_device_t* wandev;
- //cnt += sprintf(&buf[cnt], "\nSTATUS:\n\n");
- strcpy(&buf[cnt], stat_hdr);
- cnt += sizeof(stat_hdr) - 1;
-
- for (wandev = router_devlist;
- wandev && (cnt < (PROC_BUFSZ - 80));
- wandev = wandev->next) {
- if (!wandev->state) continue;
- cnt += sprintf(&buf[cnt],
- "%-15s|%-8s|%-7s|%-9s|%-8s|%9u|%5u|%3u |",
- wandev->name,
- PROT_DECODE(wandev->config_id),
- wandev->config_id == WANCONFIG_FR ?
- (wandev->station ? " Node" : " CPE") :
- (wandev->config_id == WANCONFIG_X25 ?
- (wandev->station ? " DCE" : " DTE") :
- (" N/A")),
- wandev->interface ? " V.35" : " RS-232",
- wandev->clocking ? "internal" : "external",
- wandev->bps,
- wandev->mtu,
- wandev->ndev);
-
- switch (wandev->state) {
-
- case WAN_UNCONFIGURED:
- cnt += sprintf(&buf[cnt], "%-12s\n", "unconfigured");
- break;
-
- case WAN_DISCONNECTED:
- cnt += sprintf(&buf[cnt], "%-12s\n", "disconnected");
- break;
-
- case WAN_CONNECTING:
- cnt += sprintf(&buf[cnt], "%-12s\n", "connecting");
- break;
-
- case WAN_CONNECTED:
- cnt += sprintf(&buf[cnt], "%-12s\n", "connected");
- break;
-
- case WAN_FT1_READY:
- cnt += sprintf(&buf[cnt], "%-12s\n", "ft1 ready");
- break;
-
- default:
- cnt += sprintf(&buf[cnt], "%-12s\n", "invalid");
- break;
- }
- }
- return cnt;
+ seq_printf(m, PROC_STATS_FORMAT,
+ "total packets received", wandev->stats.rx_packets);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "total packets transmitted", wandev->stats.tx_packets);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "total bytes received", wandev->stats.rx_bytes);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "total bytes transmitted", wandev->stats.tx_bytes);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "bad packets received", wandev->stats.rx_errors);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "packet transmit problems", wandev->stats.tx_errors);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "received frames dropped", wandev->stats.rx_dropped);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "transmit frames dropped", wandev->stats.tx_dropped);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "multicast packets received", wandev->stats.multicast);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "transmit collisions", wandev->stats.collisions);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "receive length errors", wandev->stats.rx_length_errors);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "receiver overrun errors", wandev->stats.rx_over_errors);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "CRC errors", wandev->stats.rx_crc_errors);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "frame format errors (aborts)", wandev->stats.rx_frame_errors);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "receiver fifo overrun", wandev->stats.rx_fifo_errors);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "receiver missed packet", wandev->stats.rx_missed_errors);
+ seq_printf(m, PROC_STATS_FORMAT,
+ "aborted frames transmitted", wandev->stats.tx_aborted_errors);
+ return 0;
+}
+static struct seq_operations wandev_op = {
+ start: single_start,
+ next: single_next,
+ stop: single_stop,
+ show: wandev_show,
+};
+static int wandev_open(struct inode *inode, struct file *file)
+{
+ int ret = seq_open(file, &wandev_op);
+ if (!ret) {
+ struct seq_file *m = file->private_data;
+ m->private = PDE(inode)->data;
}
+ return ret;
+}
- /*
- * Prepare data for reading <device> entry.
- * Return length of data.
- *
- * On entry, the 'start' argument will contain a pointer to WAN device
- * data space.
- */
-
- static int wandev_get_info(char* buf, char** start, off_t offs, int len,
- int dummy)
- {
- wan_device_t* wandev = (void*)start;
- int cnt = 0;
- int rslt = 0;
-
- if ((wandev == NULL) || (wandev->magic != ROUTER_MAGIC))
- return 0;
- if (!wandev->state)
- return sprintf(&buf[cnt], "Device is not configured!\n");
+static struct file_operations wandev_fops =
+{
+ open: wandev_open,
+ read: seq_read,
+ llseek: seq_lseek,
+ release: seq_release,
+ ioctl: wanrouter_ioctl,
+};
- /* Update device statistics */
- if (wandev->update) {
+/*
+ * Initialize router proc interface.
+ */
- rslt = wandev->update(wandev);
- if(rslt) {
- switch (rslt) {
- case -EAGAIN:
- return sprintf(&buf[cnt], "Device is busy!\n");
+int __init wanrouter_proc_init (void)
+{
+ struct proc_dir_entry *p;
+ proc_router = proc_mkdir(ROUTER_NAME, proc_net);
+ if (!proc_router)
+ goto fail;
+
+ p = create_proc_entry("config",0,proc_router);
+ if (!p)
+ goto fail_config;
+ p->proc_fops = &config_fops;
+ p->proc_iops = &router_inode;
+ p = create_proc_entry("status",0,proc_router);
+ if (!p)
+ goto fail_stat;
+ p->proc_fops = &status_fops;
+ p->proc_iops = &router_inode;
+ return 0;
+fail_stat:
+ remove_proc_entry("config", proc_router);
+fail_config:
+ remove_proc_entry(ROUTER_NAME, proc_net);
+fail:
+ return -ENOMEM;
+}
- default:
- return sprintf(&buf[cnt],
- "Device is not configured!\n");
- }
- }
- }
+/*
+ * Clean up router proc interface.
+ */
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "total packets received", wandev->stats.rx_packets);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "total packets transmitted", wandev->stats.tx_packets);
-#ifdef LINUX_2_1
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "total bytes received", wandev->stats.rx_bytes);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "total bytes transmitted", wandev->stats.tx_bytes);
-#endif
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "bad packets received", wandev->stats.rx_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "packet transmit problems", wandev->stats.tx_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "received frames dropped", wandev->stats.rx_dropped);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "transmit frames dropped", wandev->stats.tx_dropped);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "multicast packets received", wandev->stats.multicast);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "transmit collisions", wandev->stats.collisions);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "receive length errors", wandev->stats.rx_length_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "receiver overrun errors", wandev->stats.rx_over_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "CRC errors", wandev->stats.rx_crc_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "frame format errors (aborts)", wandev->stats.rx_frame_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "receiver fifo overrun", wandev->stats.rx_fifo_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "receiver missed packet", wandev->stats.rx_missed_errors);
- cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT,
- "aborted frames transmitted", wandev->stats.tx_aborted_errors);
+void wanrouter_proc_cleanup (void)
+{
+ remove_proc_entry("config", proc_router);
+ remove_proc_entry("status", proc_router);
+ remove_proc_entry(ROUTER_NAME,proc_net);
+}
- return cnt;
- }
+/*
+ * Add directory entry for WAN device.
+ */
-#endif /* End of ifdef LINUX_2_4 */
+int wanrouter_proc_add (wan_device_t* wandev)
+{
+ if (wandev->magic != ROUTER_MAGIC)
+ return -EINVAL;
+
+ wandev->dent = create_proc_entry(wandev->name, 0, proc_router);
+ if (!wandev->dent)
+ return -ENOMEM;
+ wandev->dent->proc_fops = &wandev_fops;
+ wandev->dent->proc_iops = &router_inode;
+ wandev->dent->data = wandev;
+ return 0;
+}
+/*
+ * Delete directory entry for WAN device.
+ */
+
+int wanrouter_proc_delete(wan_device_t* wandev)
+{
+ if (wandev->magic != ROUTER_MAGIC)
+ return -EINVAL;
+ remove_proc_entry(wandev->name, proc_router);
+ return 0;
+}
#else
@@ -1039,7 +415,6 @@ int __init wanrouter_proc_init(void)
void wanrouter_proc_cleanup(void)
{
- return;
}
int wanrouter_proc_add(wan_device_t *wandev)
@@ -1054,34 +429,7 @@ int wanrouter_proc_delete(wan_device_t *wandev)
#endif
-/*============================================================================
- * Write WAN device ???.
- * o Find WAN device associated with this node
- */
-#ifdef LINUX_2_0
-static int device_write(
- struct inode* inode, struct file* file, const char* buf, int count)
-{
- int err = verify_area(VERIFY_READ, buf, count);
- struct proc_dir_entry* dent;
- wan_device_t* wandev;
-
- if (err) return err;
-
- dent = PDE(inode);
- if ((dent == NULL) || (dent->data == NULL))
- return -ENODATA;
-
- wandev = dent->data;
-
- printk(KERN_ERR "%s: writing %d bytes to %s...\n",
- name_root, count, dent->name);
-
- return 0;
-}
-#endif
-
/*
* End
*/
-
+