Commit 61e828ba authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[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...
parent 7c6fc5d0
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* o Logical connection management (switched virtual circuits) * o Logical connection management (switched virtual circuits)
* o Protocol encapsulation/decapsulation * o Protocol encapsulation/decapsulation
* *
* Author: Gideon Hack * Author: Gideon Hack
* *
* Copyright: (c) 1995-1999 Sangoma Technologies Inc. * Copyright: (c) 1995-1999 Sangoma Technologies Inc.
* *
...@@ -18,11 +18,11 @@ ...@@ -18,11 +18,11 @@
* as published by the Free Software Foundation; either version * as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later 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 * Nov 07, 2000 Nenad Corbic Fixed the Mulit-Port PPP for kernels 2.2.16 and
* greater. * greater.
* Aug 2, 2000 Nenad Corbic Block the Multi-Port PPP from running on * 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. * has changed.
* Jul 13, 2000 Nenad Corbic Added SyncPPP support * Jul 13, 2000 Nenad Corbic Added SyncPPP support
* Added extra debugging in device_setup(). * Added extra debugging in device_setup().
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
* Dec 22, 1998 Arnaldo Melo vmalloc/vfree used in device_setup to allocate * Dec 22, 1998 Arnaldo Melo vmalloc/vfree used in device_setup to allocate
* kernel memory and copy configuration data to * kernel memory and copy configuration data to
* kernel space (for big firmwares) * 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> #include <linux/version.h>
...@@ -55,28 +55,10 @@ ...@@ -55,28 +55,10 @@
#include <asm/byteorder.h> /* htons(), etc. */ #include <asm/byteorder.h> /* htons(), etc. */
#include <linux/wanrouter.h> /* WAN router API definitions */ #include <linux/wanrouter.h> /* WAN router API definitions */
#include <linux/vmalloc.h> /* vmalloc, vfree */
#if defined(LINUX_2_4) #include <asm/uaccess.h> /* copy_to/from_user */
#include <linux/vmalloc.h> /* vmalloc, vfree */ #include <linux/init.h> /* __initfunc et al. */
#include <asm/uaccess.h> /* copy_to/from_user */ #include <net/syncppp.h>
#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
#define KMEM_SAFETYZONE 8 #define KMEM_SAFETYZONE 8
...@@ -84,7 +66,7 @@ ...@@ -84,7 +66,7 @@
static void * dbg_kmalloc(unsigned int size, int prio, int line) { static void * dbg_kmalloc(unsigned int size, int prio, int line) {
int i = 0; int i = 0;
void * v = kmalloc(size+sizeof(unsigned int)+2*KMEM_SAFETYZONE*8,prio); void * v = kmalloc(size+sizeof(unsigned int)+2*KMEM_SAFETYZONE*8,prio);
char * c1 = v; char * c1 = v;
c1 += sizeof(unsigned int); c1 += sizeof(unsigned int);
*((unsigned int *)v) = size; *((unsigned int *)v) = size;
...@@ -137,12 +119,11 @@ static void dbg_kfree(void * v, int line) { ...@@ -137,12 +119,11 @@ static void dbg_kfree(void * v, int line) {
#define kfree(x) dbg_kfree(x,__LINE__) #define kfree(x) dbg_kfree(x,__LINE__)
*****************************************************************************/ *****************************************************************************/
/* /*
* Function Prototypes * Function Prototypes
*/ */
/* /*
* Kernel loadable module interface. * Kernel loadable module interface.
*/ */
#ifdef MODULE #ifdef MODULE
...@@ -150,8 +131,8 @@ int init_module (void); ...@@ -150,8 +131,8 @@ int init_module (void);
void cleanup_module (void); void cleanup_module (void);
#endif #endif
/* /*
* WAN device IOCTL handlers * WAN device IOCTL handlers
*/ */
static int device_setup(wan_device_t *wandev, wandev_conf_t *u_conf); 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); ...@@ -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_shutdown(wan_device_t *wandev);
static int device_new_if(wan_device_t *wandev, wanif_conf_t *u_conf); 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); static int device_del_if(wan_device_t *wandev, char *u_name);
/* /*
* Miscellaneous * Miscellaneous
*/ */
static wan_device_t *find_device (char *name); static wan_device_t *find_device (char *name);
...@@ -181,8 +162,8 @@ static char modname[] = ROUTER_NAME; /* short module name */ ...@@ -181,8 +162,8 @@ static char modname[] = ROUTER_NAME; /* short module name */
wan_device_t* router_devlist = NULL; /* list of registered devices */ wan_device_t* router_devlist = NULL; /* list of registered devices */
static int devcnt = 0; static int devcnt = 0;
/* /*
* Organize Unique Identifiers for encapsulation/decapsulation * Organize Unique Identifiers for encapsulation/decapsulation
*/ */
static unsigned char oui_ether[] = { 0x00, 0x00, 0x00 }; static unsigned char oui_ether[] = { 0x00, 0x00, 0x00 };
...@@ -213,18 +194,15 @@ int wanrouter_init(void) ...@@ -213,18 +194,15 @@ int wanrouter_init(void)
#ifdef CONFIG_VENDOR_SANGOMA #ifdef CONFIG_VENDOR_SANGOMA
sdladrv_init(); sdladrv_init();
wanpipe_init(); wanpipe_init();
#endif #endif
return err; return err;
} }
#ifdef LINUX_2_4
static void __exit wanrouter_cleanup (void) static void __exit wanrouter_cleanup (void)
{ {
wanrouter_proc_cleanup(); wanrouter_proc_cleanup();
} }
#endif
#else #else
...@@ -249,10 +227,10 @@ int init_module (void) ...@@ -249,10 +227,10 @@ int init_module (void)
printk(KERN_INFO "%s v%u.%u %s\n", printk(KERN_INFO "%s v%u.%u %s\n",
fullname, ROUTER_VERSION, ROUTER_RELEASE, copyright); fullname, ROUTER_VERSION, ROUTER_RELEASE, copyright);
err = wanrouter_proc_init(); err = wanrouter_proc_init();
if (err){ if (err){
printk(KERN_INFO printk(KERN_INFO
"%s: can't create entry in proc filesystem!\n", modname); "%s: can't create entry in proc filesystem!\n", modname);
} }
...@@ -299,21 +277,21 @@ int register_wan_device(wan_device_t *wandev) ...@@ -299,21 +277,21 @@ int register_wan_device(wan_device_t *wandev)
if ((wandev == NULL) || (wandev->magic != ROUTER_MAGIC) || if ((wandev == NULL) || (wandev->magic != ROUTER_MAGIC) ||
(wandev->name == NULL)) (wandev->name == NULL))
return -EINVAL; return -EINVAL;
namelen = strlen(wandev->name); namelen = strlen(wandev->name);
if (!namelen || (namelen > WAN_DRVNAME_SZ)) if (!namelen || (namelen > WAN_DRVNAME_SZ))
return -EINVAL; return -EINVAL;
if (find_device(wandev->name) != NULL) if (find_device(wandev->name) != NULL)
return -EEXIST; return -EEXIST;
#ifdef WANDEBUG #ifdef WANDEBUG
printk(KERN_INFO "%s: registering WAN device %s\n", printk(KERN_INFO "%s: registering WAN device %s\n",
modname, wandev->name); modname, wandev->name);
#endif #endif
/* /*
* Register /proc directory entry * Register /proc directory entry
*/ */
err = wanrouter_proc_add(wandev); err = wanrouter_proc_add(wandev);
if (err) { if (err) {
...@@ -327,7 +305,7 @@ int register_wan_device(wan_device_t *wandev) ...@@ -327,7 +305,7 @@ int register_wan_device(wan_device_t *wandev)
* Initialize fields of the wan_device structure maintained by the * Initialize fields of the wan_device structure maintained by the
* router and update local data. * router and update local data.
*/ */
wandev->ndev = 0; wandev->ndev = 0;
wandev->dev = NULL; wandev->dev = NULL;
wandev->next = router_devlist; wandev->next = router_devlist;
...@@ -364,20 +342,18 @@ int unregister_wan_device(char *name) ...@@ -364,20 +342,18 @@ int unregister_wan_device(char *name)
if (wandev == NULL) if (wandev == NULL)
return -ENODEV; return -ENODEV;
#ifdef WANDEBUG #ifdef WANDEBUG
printk(KERN_INFO "%s: unregistering WAN device %s\n", modname, name); printk(KERN_INFO "%s: unregistering WAN device %s\n", modname, name);
#endif #endif
if (wandev->state != WAN_UNCONFIGURED) { if (wandev->state != WAN_UNCONFIGURED)
device_shutdown(wandev); device_shutdown(wandev);
}
if (prev)
if (prev){
prev->next = wandev->next; prev->next = wandev->next;
}else{ else
router_devlist = wandev->next; router_devlist = wandev->next;
}
--devcnt; --devcnt;
wanrouter_proc_delete(wandev); wanrouter_proc_delete(wandev);
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
...@@ -457,7 +433,7 @@ unsigned short wanrouter_type_trans (struct sk_buff *skb, netdevice_t *dev) ...@@ -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+1], skb->data[cnt+2],
skb->data[cnt+3], dev->name); skb->data[cnt+3], dev->name);
return 0; return 0;
} }
ethertype = *((unsigned short*)&skb->data[cnt+4]); ethertype = *((unsigned short*)&skb->data[cnt+4]);
cnt += 6; cnt += 6;
break; break;
...@@ -491,23 +467,20 @@ int wanrouter_ioctl(struct inode *inode, struct file *file, ...@@ -491,23 +467,20 @@ int wanrouter_ioctl(struct inode *inode, struct file *file,
struct proc_dir_entry *dent; struct proc_dir_entry *dent;
wan_device_t *wandev; 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; return -EPERM;
}
#endif
if ((cmd >> 8) != ROUTER_IOCTL) if ((cmd >> 8) != ROUTER_IOCTL)
return -EINVAL; return -EINVAL;
dent = PDE(inode); dent = PDE(inode);
if ((dent == NULL) || (dent->data == NULL)) if ((dent == NULL) || (dent->data == NULL))
return -EINVAL; return -EINVAL;
wandev = dent->data; wandev = dent->data;
if (wandev->magic != ROUTER_MAGIC) if (wandev->magic != ROUTER_MAGIC)
return -EINVAL; return -EINVAL;
switch (cmd) { switch (cmd) {
case ROUTER_SETUP: case ROUTER_SETUP:
err = device_setup(wandev, (void*)arg); err = device_setup(wandev, (void*)arg);
...@@ -560,103 +533,62 @@ static int device_setup (wan_device_t *wandev, wandev_conf_t *u_conf) ...@@ -560,103 +533,62 @@ static int device_setup (wan_device_t *wandev, wandev_conf_t *u_conf)
wandev_conf_t *conf; wandev_conf_t *conf;
int err = -EINVAL; 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", printk(KERN_INFO "%s: ERROR, No setup script: wandev->setup()\n",
wandev->name); wandev->name);
return 0; 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); conf = kmalloc(sizeof(wandev_conf_t), GFP_KERNEL);
if (conf == NULL){ if (conf == NULL){
printk(KERN_INFO "%s: ERROR, Failed to allocate kernel memory !\n", printk(KERN_INFO "%s: ERROR, Failed to allocate kernel memory !\n",
wandev->name); wandev->name);
return -ENOBUFS; 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", printk(KERN_INFO "%s: Failed to copy user config data to kernel space!\n",
wandev->name); wandev->name);
kfree(conf); kfree(conf);
return -EFAULT; return -EFAULT;
} }
#else
memcpy_fromfs ((void *)conf, (void *)u_conf, sizeof(wandev_conf_t)); if (conf->magic != ROUTER_MAGIC) {
#endif
if (conf->magic != ROUTER_MAGIC){
kfree(conf); kfree(conf);
printk(KERN_INFO "%s: ERROR, Invalid MAGIC Number\n", printk(KERN_INFO "%s: ERROR, Invalid MAGIC Number\n",
wandev->name); wandev->name);
return -EINVAL; return -EINVAL;
} }
if (conf->data_size && conf->data){ if (conf->data_size && conf->data) {
if(conf->data_size > 128000 || conf->data_size < 0) { if (conf->data_size > 128000 || conf->data_size < 0) {
printk(KERN_INFO printk(KERN_INFO
"%s: ERROR, Invalid firmware data size %i !\n", "%s: ERROR, Invalid firmware data size %i !\n",
wandev->name, conf->data_size); wandev->name, conf->data_size);
kfree(conf); kfree(conf);
return -EINVAL;; return -EINVAL;
} }
#if defined (LINUX_2_1) || defined (LINUX_2_4)
data = vmalloc(conf->data_size); data = vmalloc(conf->data_size);
if (data) { if (!data) {
if(!copy_from_user(data, conf->data, conf->data_size)){ printk(KERN_INFO
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
"%s: ERROR, Faild allocate kernel memory !\n", "%s: ERROR, Faild allocate kernel memory !\n",
wandev->name); wandev->name);
err = -ENOBUFS; kfree(conf);
} return -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);
} }
if (!copy_from_user(data, conf->data, conf->data_size)) {
if (!err){ conf->data = data;
err = wandev->setup(wandev, conf); err = wandev->setup(wandev, conf);
} else {
printk(KERN_INFO
"%s: ERROR, Faild to copy from user data !\n",
wandev->name);
err = -EFAULT;
} }
vfree(data);
if (data){ } else {
kfree(data); printk(KERN_INFO
}
#endif
}else{
printk(KERN_INFO
"%s: ERROR, No firmware found ! Firmware size = %i !\n", "%s: ERROR, No firmware found ! Firmware size = %i !\n",
wandev->name, conf->data_size); wandev->name, conf->data_size);
} }
...@@ -670,37 +602,33 @@ static int device_setup (wan_device_t *wandev, wandev_conf_t *u_conf) ...@@ -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 delete all not opened logical channels for this device
* o call driver's shutdown() entry point * o call driver's shutdown() entry point
*/ */
static int device_shutdown (wan_device_t *wandev) static int device_shutdown (wan_device_t *wandev)
{ {
netdevice_t *dev; netdevice_t *dev;
int err=0; int err=0;
if (wandev->state == WAN_UNCONFIGURED){ if (wandev->state == WAN_UNCONFIGURED)
return 0; return 0;
}
printk(KERN_INFO "\n%s: Shutting Down!\n",wandev->name); printk(KERN_INFO "\n%s: Shutting Down!\n",wandev->name);
for (dev = wandev->dev; dev;) { for (dev = wandev->dev; dev;) {
if ((err=delete_interface(wandev, dev->name)) != 0){ if ((err=delete_interface(wandev, dev->name)) != 0)
return err; return err;
}
/* The above function deallocates the current dev /* The above function deallocates the current dev
* structure. Therefore, we cannot use dev->priv * structure. Therefore, we cannot use dev->priv
* as the next element: wandev->dev points to the * as the next element: wandev->dev points to the
* next element */ * next element */
dev = wandev->dev; dev = wandev->dev;
} }
if (wandev->ndev){ if (wandev->ndev)
return -EBUSY; /* there are opened interfaces */ return -EBUSY; /* there are opened interfaces */
}
if (wandev->shutdown) if (wandev->shutdown)
err=wandev->shutdown(wandev); err=wandev->shutdown(wandev);
return err; return err;
} }
...@@ -712,13 +640,6 @@ static int device_stat (wan_device_t *wandev, wandev_stat_t *u_stat) ...@@ -712,13 +640,6 @@ static int device_stat (wan_device_t *wandev, wandev_stat_t *u_stat)
{ {
wandev_stat_t 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)); memset(&stat, 0, sizeof(stat));
/* Ask device driver to update device statistics */ /* Ask device driver to update device statistics */
...@@ -729,12 +650,8 @@ static int device_stat (wan_device_t *wandev, wandev_stat_t *u_stat) ...@@ -729,12 +650,8 @@ static int device_stat (wan_device_t *wandev, wandev_stat_t *u_stat)
stat.ndev = wandev->ndev; stat.ndev = wandev->ndev;
stat.state = wandev->state; 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; return -EFAULT;
#else
memcpy_tofs((void*)u_stat, (void*)&stat, sizeof(stat));
#endif
return 0; return 0;
} }
...@@ -760,103 +677,67 @@ static int device_new_if (wan_device_t *wandev, wanif_conf_t *u_conf) ...@@ -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)) if ((wandev->state == WAN_UNCONFIGURED) || (wandev->new_if == NULL))
return -ENODEV; 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; 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) if (conf.magic != ROUTER_MAGIC)
return -EINVAL; return -EINVAL;
err = -EPROTONOSUPPORT; if (conf.config_id == WANCONFIG_MPPP) {
#ifdef CONFIG_WANPIPE_MULTPPP #ifdef CONFIG_WANPIPE_MULTPPP
if (conf.config_id == WANCONFIG_MPPP){
pppdev = kmalloc(sizeof(struct ppp_device), GFP_KERNEL); pppdev = kmalloc(sizeof(struct ppp_device), GFP_KERNEL);
if (pppdev == NULL){ if (pppdev == NULL)
return -ENOBUFS; return -ENOBUFS;
}
memset(pppdev, 0, sizeof(struct ppp_device)); memset(pppdev, 0, sizeof(struct ppp_device));
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,16)
pppdev->dev = kmalloc(sizeof(netdevice_t), GFP_KERNEL); pppdev->dev = kmalloc(sizeof(netdevice_t), GFP_KERNEL);
if (pppdev->dev == NULL){ if (pppdev->dev == NULL) {
kfree(pppdev); kfree(pppdev);
return -ENOBUFS; return -ENOBUFS;
} }
memset(pppdev->dev, 0, sizeof(netdevice_t)); memset(pppdev->dev, 0, sizeof(netdevice_t));
#endif
err = wandev->new_if(wandev, (netdevice_t *)pppdev, &conf); err = wandev->new_if(wandev, (netdevice_t *)pppdev, &conf);
dev = pppdev->dev;
#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);
}
#else #else
/* Sync PPP is disabled */ printk(KERN_INFO "%s: Wanpipe Mulit-Port PPP support has not been compiled in!\n",
if (conf.config_id != WANCONFIG_MPPP){ wandev->name);
return -EPROTONOSUPPORT;
#endif
} else {
dev = kmalloc(sizeof(netdevice_t), GFP_KERNEL); dev = kmalloc(sizeof(netdevice_t), GFP_KERNEL);
if (dev == NULL){ if (dev == NULL)
return -ENOBUFS; return -ENOBUFS;
} memset(dev, 0, sizeof(netdevice_t));
memset(dev, 0, sizeof(netdevice_t));
err = wandev->new_if(wandev, dev, &conf); 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) { if (!err) {
/* Register network interface. This will invoke init() /* Register network interface. This will invoke init()
* function supplied by the driver. If device registered * function supplied by the driver. If device registered
* successfully, add it to the interface list. * successfully, add it to the interface list.
*/ */
if (dev->name == NULL){ if (dev->name == NULL) {
err = -EINVAL; err = -EINVAL;
}else if (dev_get(dev->name)){ } else if (dev_get(dev->name)) {
err = -EEXIST; /* name already exists */ err = -EEXIST; /* name already exists */
}else{ } else {
#ifdef WANDEBUG #ifdef WANDEBUG
printk(KERN_INFO "%s: registering interface %s...\n", printk(KERN_INFO "%s: registering interface %s...\n",
modname, dev->name); modname, dev->name);
#endif #endif
err = register_netdev(dev); err = register_netdev(dev);
if (!err) { if (!err) {
netdevice_t *slave=NULL; netdevice_t *slave=NULL;
unsigned long smp_flags=0; unsigned long smp_flags=0;
lock_adapter_irq(&wandev->lock, &smp_flags); lock_adapter_irq(&wandev->lock, &smp_flags);
if (wandev->dev == NULL){ if (wandev->dev == NULL) {
wandev->dev = dev; wandev->dev = dev;
}else{ } else {
for (slave=wandev->dev; for (slave=wandev->dev;
*((netdevice_t**)slave->priv); *((netdevice_t**)slave->priv);
slave=*((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) ...@@ -864,7 +745,7 @@ static int device_new_if (wan_device_t *wandev, wanif_conf_t *u_conf)
*((netdevice_t**)slave->priv) = dev; *((netdevice_t**)slave->priv) = dev;
} }
++wandev->ndev; ++wandev->ndev;
unlock_adapter_irq(&wandev->lock, &smp_flags); unlock_adapter_irq(&wandev->lock, &smp_flags);
return 0; /* done !!! */ return 0; /* done !!! */
} }
...@@ -874,25 +755,23 @@ static int device_new_if (wan_device_t *wandev, wanif_conf_t *u_conf) ...@@ -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 */ /* This code has moved from del_if() function */
if (dev->priv){ if (dev->priv) {
kfree(dev->priv); kfree(dev->priv);
dev->priv=NULL; dev->priv = NULL;
} }
#ifdef CONFIG_WANPIPE_MULTPPP #ifdef CONFIG_WANPIPE_MULTPPP
if (conf.config_id == WANCONFIG_MPPP){ if (conf.config_id == WANCONFIG_MPPP)
kfree(pppdev); kfree(pppdev);
}else{ else
kfree(dev); kfree(dev);
} #else
#else
/* Sync PPP is disabled */ /* Sync PPP is disabled */
if (conf.config_id != WANCONFIG_MPPP){ if (conf.config_id != WANCONFIG_MPPP)
kfree(dev); kfree(dev);
} #endif
#endif
return err; return err;
} }
...@@ -910,42 +789,31 @@ static int device_del_if (wan_device_t *wandev, char *u_name) ...@@ -910,42 +789,31 @@ static int device_del_if (wan_device_t *wandev, char *u_name)
if (wandev->state == WAN_UNCONFIGURED) if (wandev->state == WAN_UNCONFIGURED)
return -ENODEV; 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)); 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; return -EFAULT;
#else
memcpy_fromfs((void*)name, (void*)u_name, WAN_IFNAME_SZ);
#endif
err = delete_interface(wandev, name); err = delete_interface(wandev, name);
if (err) if (err)
return(err); return err;
/* If last interface being deleted, shutdown card /* If last interface being deleted, shutdown card
* This helps with administration at leaf nodes * 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 * has an interface configured) and avoids DoS vulnerabilities
* in binary driver files - this fixes a problem with the current * in binary driver files - this fixes a problem with the current
* Sangoma driver going into strange states when all the network * Sangoma driver going into strange states when all the network
* interfaces are deleted and the link irrecoverably disconnected. * interfaces are deleted and the link irrecoverably disconnected.
*/ */
if (!wandev->ndev && wandev->shutdown){ if (!wandev->ndev && wandev->shutdown)
err = wandev->shutdown(wandev); err = wandev->shutdown(wandev);
}
return err; return err;
} }
/* /*
* Miscellaneous Functions * Miscellaneous Functions
*/ */
...@@ -995,18 +863,12 @@ static int delete_interface (wan_device_t *wandev, char *name) ...@@ -995,18 +863,12 @@ static int delete_interface (wan_device_t *wandev, char *name)
dev = *slave; dev = *slave;
} }
unlock_adapter_irq(&wandev->lock, &smp_flags); unlock_adapter_irq(&wandev->lock, &smp_flags);
if (dev == NULL){ if (dev == NULL)
return -ENODEV; /* interface not found */ return -ENODEV; /* interface not found */
}
if (netif_running(dev))
#ifdef LINUX_2_4
if (netif_running(dev)){
#else
if (dev->start) {
#endif
return -EBUSY; /* interface in use */ return -EBUSY; /* interface in use */
}
if (wandev->del_if) if (wandev->del_if)
wandev->del_if(wandev, dev); wandev->del_if(wandev, dev);
...@@ -1023,9 +885,9 @@ static int delete_interface (wan_device_t *wandev, char *name) ...@@ -1023,9 +885,9 @@ static int delete_interface (wan_device_t *wandev, char *name)
} }
--wandev->ndev; --wandev->ndev;
unlock_adapter_irq(&wandev->lock, &smp_flags); 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, /* Due to new interface linking method using dev->priv,
* this code has moved from del_if() function.*/ * this code has moved from del_if() function.*/
if (dev->priv){ if (dev->priv){
...@@ -1035,48 +897,28 @@ static int delete_interface (wan_device_t *wandev, char *name) ...@@ -1035,48 +897,28 @@ static int delete_interface (wan_device_t *wandev, char *name)
unregister_netdev(dev); unregister_netdev(dev);
#ifdef LINUX_2_4
kfree(dev);
#else
if (dev->name){
kfree(dev->name);
}
kfree(dev); kfree(dev);
#endif
return 0; return 0;
} }
void lock_adapter_irq(spinlock_t *lock, unsigned long *smp_flags) 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); spin_lock_irqsave(lock, *smp_flags);
#endif
} }
void unlock_adapter_irq(spinlock_t *lock, unsigned long *smp_flags) 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); spin_unlock_irqrestore(lock, *smp_flags);
#endif
} }
#if defined (LINUX_2_1) || defined (LINUX_2_4)
EXPORT_SYMBOL(register_wan_device); EXPORT_SYMBOL(register_wan_device);
EXPORT_SYMBOL(unregister_wan_device); EXPORT_SYMBOL(unregister_wan_device);
EXPORT_SYMBOL(wanrouter_encapsulate); EXPORT_SYMBOL(wanrouter_encapsulate);
EXPORT_SYMBOL(wanrouter_type_trans); EXPORT_SYMBOL(wanrouter_type_trans);
EXPORT_SYMBOL(lock_adapter_irq); EXPORT_SYMBOL(lock_adapter_irq);
EXPORT_SYMBOL(unlock_adapter_irq); EXPORT_SYMBOL(unlock_adapter_irq);
#endif
/* /*
* End * End
......
...@@ -31,23 +31,15 @@ ...@@ -31,23 +31,15 @@
#include <asm/byteorder.h> /* htons(), etc. */ #include <asm/byteorder.h> /* htons(), etc. */
#include <asm/io.h> #include <asm/io.h>
#include <linux/wanrouter.h> /* WAN router API definitions */ #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 */
#define PROC_STATS_FORMAT "%30s: %12lu\n"
#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
/****** Defines and Macros **************************************************/ /****** Defines and Macros **************************************************/
#define PROC_BUFSZ 4000 /* buffer size for printing proc info */
#define PROT_DECODE(prot) ((prot == WANCONFIG_FR) ? " FR" :\ #define PROT_DECODE(prot) ((prot == WANCONFIG_FR) ? " FR" :\
(prot == WANCONFIG_X25) ? " X25" : \ (prot == WANCONFIG_X25) ? " X25" : \
(prot == WANCONFIG_PPP) ? " PPP" : \ (prot == WANCONFIG_PPP) ? " PPP" : \
...@@ -69,962 +61,346 @@ typedef struct wan_stat_entry ...@@ -69,962 +61,346 @@ typedef struct wan_stat_entry
#ifdef CONFIG_PROC_FS #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); * Structures for interfacing with the /proc filesystem.
static ssize_t router_proc_read(struct file* file, char* buf, size_t count, loff_t *ppos); * Router creates its own directory /proc/net/router with the folowing
* entries:
/* Methods for preparing data for reading proc entries */ * config device configuration
* status global device statistics
static int config_get_info(char* buf, char** start, off_t offs, int len); * <device> entry for each WAN device
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,
};
static struct inode_operations router_inode = /*
{ * Generic /proc/net/router/<file> file and inode operations
permission: router_proc_perms, */
};
/* static struct inode_operations router_inode =
* /proc/net/router/<device> file operations {
*/ permission: router_proc_perms,
};
static struct file_operations wandev_fops = /*
{ * /proc/net/router
read: router_proc_read, */
ioctl: wanrouter_ioctl,
};
/* static struct proc_dir_entry *proc_router;
* /proc/net/router
*/
static struct proc_dir_entry *proc_router; /* Strings */
/* Strings */ /*
static char conf_hdr[] = * Interface functions
"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";
/****** Proc filesystem entry points ****************************************/
/* /*
* Interface functions * Verify access rights.
*/ */
/* static int router_proc_perms (struct inode* inode, int op)
* Initialize router proc interface. {
*/ return 0;
}
int __init wanrouter_proc_init (void) /*
{ * Iterator
struct proc_dir_entry *p; */
proc_router = proc_mkdir(ROUTER_NAME, proc_net); static void *r_start(struct seq_file *m, loff_t *pos)
if (!proc_router) {
goto fail; 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); static int config_show(struct seq_file *m, void *v)
if (!p) {
goto fail_config; wan_device_t *p = v;
p->proc_fops = &router_fops; if (v == (void *)1) {
p->proc_iops = &router_inode; seq_puts(m, "Device name | port |IRQ|DMA| mem.addr |");
p->get_info = config_get_info; seq_puts(m, "mem.size|option1|option2|option3|option4\n");
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;
return 0; return 0;
fail_stat:
remove_proc_entry("config", proc_router);
fail_config:
remove_proc_entry(ROUTER_NAME, proc_net);
fail:
return -ENOMEM;
} }
if (!p->state)
/*
* 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;
return 0; 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;
}
/* static int status_show(struct seq_file *m, void *v)
* Delete directory entry for WAN device. {
*/ wan_device_t *p = v;
if (v == (void *)1) {
int wanrouter_proc_delete(wan_device_t* wandev) seq_puts(m, "Device name |protocol|station|interface|");
{ seq_puts(m, "clocking|baud rate| MTU |ndev|link state\n");
if (wandev->magic != ROUTER_MAGIC)
return -EINVAL;
remove_proc_entry(wandev->name, proc_router);
return 0; return 0;
} }
if (!p->state)
/****** Proc filesystem entry points ****************************************/
/*
* Verify access rights.
*/
static int router_proc_perms (struct inode* inode, int op)
{
return 0; 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;
}
/* static struct seq_operations config_op = {
* Read router proc directory entry. start: r_start,
* This is universal routine for reading all entries in /proc/net/wanrouter next: r_next,
* directory. Each directory entry contains a pointer to the 'method' for stop: r_stop,
* preparing data for that entry. show: config_show
* o verify arguments };
* o allocate kernel buffer
* o call get_info() to prepare data static struct seq_operations status_op = {
* o copy data to user space start: r_start,
* o release kernel buffer next: r_next,
* stop: r_stop,
* Return: number of bytes copied to user space (0, if no data) show: status_show
* <0 error };
*/
static int config_open(struct inode *inode, struct file *file)
static ssize_t router_proc_read(struct file* file, char* buf, size_t count, {
loff_t *ppos) return seq_open(file, &config_op);
{ }
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 int status_open(struct inode *inode, struct file *file)
* Clean up router proc interface. {
*/ return seq_open(file, &status_op);
}
void wanrouter_proc_cleanup (void) static struct file_operations config_fops =
{ {
proc_unregister(&proc_router, proc_router_conf.low_ino); open: config_open,
proc_unregister(&proc_router, proc_router_stat.low_ino); read: seq_read,
#ifdef LINUX_2_1 llseek: seq_lseek,
proc_unregister(proc_net, proc_router.low_ino); release: seq_release,
#else };
proc_unregister(&proc_net, proc_router.low_ino);
#endif
}
/* static struct file_operations status_fops =
* Add directory entry for WAN device. {
*/ open: status_open,
read: seq_read,
llseek: seq_lseek,
release: seq_release,
};
int wanrouter_proc_add (wan_device_t* wandev) static void *single_start(struct seq_file *p, loff_t *pos)
{ {
if (wandev->magic != ROUTER_MAGIC) return *pos == 0 ? p->private : NULL;
return -EINVAL; }
static void *single_next(struct seq_file *p, void *v, loff_t *pos)
memset(&wandev->dent, 0, sizeof(wandev->dent)); {
wandev->dent.namelen = strlen(wandev->name); ++*pos;
wandev->dent.name = wandev->name; return NULL;
wandev->dent.mode = 0444 | S_IFREG; }
wandev->dent.nlink = 1; static void single_stop(struct seq_file *p, void *v)
wandev->dent.ops = &wandev_inode; {
wandev->dent.get_info = &wandev_get_info; }
wandev->dent.data = wandev; static int wandev_show(struct seq_file *m, void *v)
#ifdef LINUX_2_1 {
return proc_register(&proc_router, &wandev->dent); wan_device_t *wandev = v;
#else
return proc_register_dynamic(&proc_router, &wandev->dent);
#endif
}
/* if (wandev->magic != ROUTER_MAGIC)
* 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);
return 0; return 0;
}
/****** Proc filesystem entry points ****************************************/
/* if (!wandev->state) {
* Verify access rights. seq_puts(m, "device is not configured!\n");
*/
static int router_proc_perms (struct inode* inode, int op)
{
return 0; return 0;
} }
/* /* Update device statistics */
* Read router proc directory entry. if (wandev->update) {
* This is universal routine for reading all entries in /proc/net/wanrouter int err = wandev->update(wandev);
* directory. Each directory entry contains a pointer to the 'method' for if (err == -EAGAIN) {
* preparing data for that entry. seq_printf(m, "Device is busy!\n");
* 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)
return 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, 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 if (err) {
len = 0; seq_printf(m, "Device is not configured!\n");
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)
return 0; 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"); seq_printf(m, PROC_STATS_FORMAT,
strcpy(&buf[cnt], stat_hdr); "total packets received", wandev->stats.rx_packets);
cnt += sizeof(stat_hdr) - 1; seq_printf(m, PROC_STATS_FORMAT,
"total packets transmitted", wandev->stats.tx_packets);
for (wandev = router_devlist; seq_printf(m, PROC_STATS_FORMAT,
wandev && (cnt < (PROC_BUFSZ - 80)); "total bytes received", wandev->stats.rx_bytes);
wandev = wandev->next) { seq_printf(m, PROC_STATS_FORMAT,
if (!wandev->state) continue; "total bytes transmitted", wandev->stats.tx_bytes);
cnt += sprintf(&buf[cnt], seq_printf(m, PROC_STATS_FORMAT,
"%-15s|%-8s|%-7s|%-9s|%-8s|%9u|%5u|%3u |", "bad packets received", wandev->stats.rx_errors);
wandev->name, seq_printf(m, PROC_STATS_FORMAT,
PROT_DECODE(wandev->config_id), "packet transmit problems", wandev->stats.tx_errors);
wandev->config_id == WANCONFIG_FR ? seq_printf(m, PROC_STATS_FORMAT,
(wandev->station ? " Node" : " CPE") : "received frames dropped", wandev->stats.rx_dropped);
(wandev->config_id == WANCONFIG_X25 ? seq_printf(m, PROC_STATS_FORMAT,
(wandev->station ? " DCE" : " DTE") : "transmit frames dropped", wandev->stats.tx_dropped);
(" N/A")), seq_printf(m, PROC_STATS_FORMAT,
wandev->interface ? " V.35" : " RS-232", "multicast packets received", wandev->stats.multicast);
wandev->clocking ? "internal" : "external", seq_printf(m, PROC_STATS_FORMAT,
wandev->bps, "transmit collisions", wandev->stats.collisions);
wandev->mtu, seq_printf(m, PROC_STATS_FORMAT,
wandev->ndev); "receive length errors", wandev->stats.rx_length_errors);
seq_printf(m, PROC_STATS_FORMAT,
switch (wandev->state) { "receiver overrun errors", wandev->stats.rx_over_errors);
seq_printf(m, PROC_STATS_FORMAT,
case WAN_UNCONFIGURED: "CRC errors", wandev->stats.rx_crc_errors);
cnt += sprintf(&buf[cnt], "%-12s\n", "unconfigured"); seq_printf(m, PROC_STATS_FORMAT,
break; "frame format errors (aborts)", wandev->stats.rx_frame_errors);
seq_printf(m, PROC_STATS_FORMAT,
case WAN_DISCONNECTED: "receiver fifo overrun", wandev->stats.rx_fifo_errors);
cnt += sprintf(&buf[cnt], "%-12s\n", "disconnected"); seq_printf(m, PROC_STATS_FORMAT,
break; "receiver missed packet", wandev->stats.rx_missed_errors);
seq_printf(m, PROC_STATS_FORMAT,
case WAN_CONNECTING: "aborted frames transmitted", wandev->stats.tx_aborted_errors);
cnt += sprintf(&buf[cnt], "%-12s\n", "connecting"); return 0;
break; }
static struct seq_operations wandev_op = {
case WAN_CONNECTED: start: single_start,
cnt += sprintf(&buf[cnt], "%-12s\n", "connected"); next: single_next,
break; stop: single_stop,
show: wandev_show,
case WAN_FT1_READY: };
cnt += sprintf(&buf[cnt], "%-12s\n", "ft1 ready"); static int wandev_open(struct inode *inode, struct file *file)
break; {
int ret = seq_open(file, &wandev_op);
default: if (!ret) {
cnt += sprintf(&buf[cnt], "%-12s\n", "invalid"); struct seq_file *m = file->private_data;
break; m->private = PDE(inode)->data;
}
}
return cnt;
} }
return ret;
}
/* static struct file_operations wandev_fops =
* Prepare data for reading <device> entry. {
* Return length of data. open: wandev_open,
* read: seq_read,
* On entry, the 'start' argument will contain a pointer to WAN device llseek: seq_lseek,
* data space. release: seq_release,
*/ ioctl: wanrouter_ioctl,
};
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");
/* Update device statistics */ /*
if (wandev->update) { * Initialize router proc interface.
*/
rslt = wandev->update(wandev); int __init wanrouter_proc_init (void)
if(rslt) { {
switch (rslt) { struct proc_dir_entry *p;
case -EAGAIN: proc_router = proc_mkdir(ROUTER_NAME, proc_net);
return sprintf(&buf[cnt], "Device is busy!\n"); 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], * Clean up router proc interface.
"Device is not configured!\n"); */
}
}
}
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, void wanrouter_proc_cleanup (void)
"total packets received", wandev->stats.rx_packets); {
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, remove_proc_entry("config", proc_router);
"total packets transmitted", wandev->stats.tx_packets); remove_proc_entry("status", proc_router);
#ifdef LINUX_2_1 remove_proc_entry(ROUTER_NAME,proc_net);
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);
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 #else
...@@ -1039,7 +415,6 @@ int __init wanrouter_proc_init(void) ...@@ -1039,7 +415,6 @@ int __init wanrouter_proc_init(void)
void wanrouter_proc_cleanup(void) void wanrouter_proc_cleanup(void)
{ {
return;
} }
int wanrouter_proc_add(wan_device_t *wandev) int wanrouter_proc_add(wan_device_t *wandev)
...@@ -1054,34 +429,7 @@ int wanrouter_proc_delete(wan_device_t *wandev) ...@@ -1054,34 +429,7 @@ int wanrouter_proc_delete(wan_device_t *wandev)
#endif #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 * End
*/ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment