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
...@@ -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
...@@ -137,7 +119,6 @@ static void dbg_kfree(void * v, int line) { ...@@ -137,7 +119,6 @@ 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
*/ */
...@@ -218,13 +199,10 @@ int wanrouter_init(void) ...@@ -218,13 +199,10 @@ int wanrouter_init(void)
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
...@@ -368,15 +346,13 @@ int unregister_wan_device(char *name) ...@@ -368,15 +346,13 @@ int unregister_wan_device(char *name)
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);
...@@ -491,11 +467,8 @@ int wanrouter_ioctl(struct inode *inode, struct file *file, ...@@ -491,11 +467,8 @@ 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;
...@@ -560,19 +533,12 @@ static int device_setup (wan_device_t *wandev, wandev_conf_t *u_conf) ...@@ -560,19 +533,12 @@ 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",
...@@ -580,82 +546,48 @@ static int device_setup (wan_device_t *wandev, wandev_conf_t *u_conf) ...@@ -580,82 +546,48 @@ static int device_setup (wan_device_t *wandev, wandev_conf_t *u_conf)
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));
#endif
if (conf->magic != ROUTER_MAGIC){ 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)){
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 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 if (!copy_from_user(data, conf->data, conf->data_size)) {
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; 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 (!err){
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);
}
#endif
}else{
printk(KERN_INFO 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);
...@@ -676,17 +608,14 @@ static int device_shutdown (wan_device_t *wandev) ...@@ -676,17 +608,14 @@ 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
...@@ -694,9 +623,8 @@ static int device_shutdown (wan_device_t *wandev) ...@@ -694,9 +623,8 @@ static int device_shutdown (wan_device_t *wandev)
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);
...@@ -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;
} }
...@@ -761,74 +678,38 @@ static int device_new_if (wan_device_t *wandev, wanif_conf_t *u_conf) ...@@ -761,74 +678,38 @@ 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);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,16)
dev = pppdev->dev; 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()
...@@ -836,11 +717,11 @@ static int device_new_if (wan_device_t *wandev, wanif_conf_t *u_conf) ...@@ -836,11 +717,11 @@ static int device_new_if (wan_device_t *wandev, wanif_conf_t *u_conf)
* 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",
...@@ -854,9 +735,9 @@ static int device_new_if (wan_device_t *wandev, wanif_conf_t *u_conf) ...@@ -854,9 +735,9 @@ static int device_new_if (wan_device_t *wandev, wanif_conf_t *u_conf)
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));
...@@ -874,24 +755,22 @@ static int device_new_if (wan_device_t *wandev, wanif_conf_t *u_conf) ...@@ -874,24 +755,22 @@ 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;
} }
...@@ -911,24 +790,14 @@ static int device_del_if (wan_device_t *wandev, char *u_name) ...@@ -911,24 +790,14 @@ 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
...@@ -939,13 +808,12 @@ static int device_del_if (wan_device_t *wandev, char *u_name) ...@@ -939,13 +808,12 @@ static int device_del_if (wan_device_t *wandev, char *u_name)
* 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
*/ */
...@@ -996,17 +864,11 @@ static int delete_interface (wan_device_t *wandev, char *name) ...@@ -996,17 +864,11 @@ static int delete_interface (wan_device_t *wandev, char *name)
} }
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 */
}
#ifdef LINUX_2_4 if (netif_running(dev))
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);
...@@ -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); kfree(dev);
#else
if (dev->name){
kfree(dev->name);
}
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,23 +61,12 @@ typedef struct wan_stat_entry ...@@ -69,23 +61,12 @@ 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);
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. * Structures for interfacing with the /proc filesystem.
* Router creates its own directory /proc/net/router with the folowing * Router creates its own directory /proc/net/router with the folowing
* entries: * entries:
...@@ -94,937 +75,332 @@ typedef struct wan_stat_entry ...@@ -94,937 +75,332 @@ typedef struct wan_stat_entry
* <device> entry for each WAN device * <device> entry for each WAN device
*/ */
/* /*
* Generic /proc/net/router/<file> file and inode operations * 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 = static struct inode_operations router_inode =
{ {
permission: router_proc_perms, permission: router_proc_perms,
}; };
/*
* /proc/net/router/<device> file operations
*/
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 */
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";
/* Strings */
/* /*
* Interface functions * Interface functions
*/ */
/* /****** Proc filesystem entry points ****************************************/
* Initialize router proc interface.
*/
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 = &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;
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) /*
{ * Verify access rights.
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) static int router_proc_perms (struct inode* inode, int op)
{ {
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;
} }
/* /*
* Delete directory entry for WAN device. * 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();
}
int wanrouter_proc_delete(wan_device_t* wandev) static int config_show(struct seq_file *m, void *v)
{ {
if (wandev->magic != ROUTER_MAGIC) wan_device_t *p = v;
return -EINVAL; if (v == (void *)1) {
remove_proc_entry(wandev->name, proc_router); seq_puts(m, "Device name | port |IRQ|DMA| mem.addr |");
seq_puts(m, "mem.size|option1|option2|option3|option4\n");
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|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]);
* 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; return 0;
}
dent = PDE(inode); static int status_show(struct seq_file *m, void *v)
if ((dent == NULL) || (dent->get_info == NULL)) {
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; 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;
} }
if (!p->state)
/* return 0;
* Prepare data for reading 'Status' entry. seq_printf(m, "%-15s|%-8s|%-7s|%-9s|%-8s|%9u|%5u|%3u |",
* Return length of data. p->name,
*/ PROT_DECODE(p->config_id),
p->config_id == WANCONFIG_FR ?
static int status_get_info(char* buf, char** start, off_t offs, int len) (p->station ? " Node" : " CPE") :
{ (p->config_id == WANCONFIG_X25 ?
int cnt = 0; (p->station ? " DCE" : " DTE") :
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")), (" N/A")),
wandev->interface ? " V.35" : " RS-232", p->interface ? " V.35" : " RS-232",
wandev->clocking ? "internal" : "external", p->clocking ? "internal" : "external",
wandev->bps, p->bps,
wandev->mtu, p->mtu,
wandev->ndev); p->ndev);
switch (wandev->state) {
switch (p->state) {
case WAN_UNCONFIGURED: case WAN_UNCONFIGURED:
cnt += sprintf(&buf[cnt], "%-12s\n", "unconfigured"); seq_printf(m, "%-12s\n", "unconfigured");
break; break;
case WAN_DISCONNECTED: case WAN_DISCONNECTED:
cnt += sprintf(&buf[cnt], "%-12s\n", "disconnected"); seq_printf(m, "%-12s\n", "disconnected");
break; break;
case WAN_CONNECTING: case WAN_CONNECTING:
cnt += sprintf(&buf[cnt], "%-12s\n", "connecting"); seq_printf(m, "%-12s\n", "connecting");
break; break;
case WAN_CONNECTED: case WAN_CONNECTED:
cnt += sprintf(&buf[cnt], "%-12s\n", "connected"); seq_printf(m, "%-12s\n", "connected");
break; break;
default: default:
cnt += sprintf(&buf[cnt], "%-12s\n", "invalid"); seq_printf(m, "%-12s\n", "invalid");
break; break;
} }
} return 0;
return cnt; }
}
/* static struct seq_operations config_op = {
* Prepare data for reading <device> entry. start: r_start,
* Return length of data. next: r_next,
* stop: r_stop,
* On entry, the 'start' argument will contain a pointer to WAN device show: config_show
* data space. };
*/
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);
}
static int status_open(struct inode *inode, struct file *file)
{
return seq_open(file, &status_op);
}
static struct file_operations config_fops =
{
open: config_open,
read: seq_read,
llseek: seq_lseek,
release: seq_release,
};
static struct file_operations status_fops =
{
open: status_open,
read: seq_read,
llseek: seq_lseek,
release: seq_release,
};
static int wandev_get_info(char* buf, char** start, off_t offs, int len) static void *single_start(struct seq_file *p, loff_t *pos)
{ {
wan_device_t* wandev = (void*)start; return *pos == 0 ? p->private : NULL;
int cnt = 0; }
int rslt = 0; 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;
if ((wandev == NULL) || (wandev->magic != ROUTER_MAGIC)) if (wandev->magic != ROUTER_MAGIC)
return 0; return 0;
if (!wandev->state)
return sprintf(&buf[cnt], "device is not configured!\n"); if (!wandev->state) {
seq_puts(m, "device is not configured!\n");
return 0;
}
/* Update device statistics */ /* Update device statistics */
if (wandev->update) { if (wandev->update) {
int err = wandev->update(wandev);
rslt = wandev->update(wandev); if (err == -EAGAIN) {
if(rslt) { seq_printf(m, "Device is busy!\n");
switch (rslt) { return 0;
case -EAGAIN:
return sprintf(&buf[cnt], "Device is busy!\n");
default:
return sprintf(&buf[cnt],
"Device is not configured!\n");
} }
if (err) {
seq_printf(m, "Device is not configured!\n");
return 0;
} }
} }
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"total packets received", wandev->stats.rx_packets); "total packets received", wandev->stats.rx_packets);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"total packets transmitted", wandev->stats.tx_packets); "total packets transmitted", wandev->stats.tx_packets);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"total bytes received", wandev->stats.rx_bytes); "total bytes received", wandev->stats.rx_bytes);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"total bytes transmitted", wandev->stats.tx_bytes); "total bytes transmitted", wandev->stats.tx_bytes);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"bad packets received", wandev->stats.rx_errors); "bad packets received", wandev->stats.rx_errors);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"packet transmit problems", wandev->stats.tx_errors); "packet transmit problems", wandev->stats.tx_errors);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"received frames dropped", wandev->stats.rx_dropped); "received frames dropped", wandev->stats.rx_dropped);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"transmit frames dropped", wandev->stats.tx_dropped); "transmit frames dropped", wandev->stats.tx_dropped);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"multicast packets received", wandev->stats.multicast); "multicast packets received", wandev->stats.multicast);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"transmit collisions", wandev->stats.collisions); "transmit collisions", wandev->stats.collisions);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"receive length errors", wandev->stats.rx_length_errors); "receive length errors", wandev->stats.rx_length_errors);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"receiver overrun errors", wandev->stats.rx_over_errors); "receiver overrun errors", wandev->stats.rx_over_errors);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"CRC errors", wandev->stats.rx_crc_errors); "CRC errors", wandev->stats.rx_crc_errors);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"frame format errors (aborts)", wandev->stats.rx_frame_errors); "frame format errors (aborts)", wandev->stats.rx_frame_errors);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"receiver fifo overrun", wandev->stats.rx_fifo_errors); "receiver fifo overrun", wandev->stats.rx_fifo_errors);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"receiver missed packet", wandev->stats.rx_missed_errors); "receiver missed packet", wandev->stats.rx_missed_errors);
cnt += sprintf(&buf[cnt], PROC_STATS_FORMAT, seq_printf(m, PROC_STATS_FORMAT,
"aborted frames transmitted", wandev->stats.tx_aborted_errors); "aborted frames transmitted", wandev->stats.tx_aborted_errors);
return cnt; 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;
}
static struct file_operations wandev_fops =
{
open: wandev_open,
read: seq_read,
llseek: seq_lseek,
release: seq_release,
ioctl: wanrouter_ioctl,
};
#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. * Initialize router proc interface.
*/ */
#ifdef LINUX_2_1 int __init wanrouter_proc_init (void)
__initfunc(int wanrouter_proc_init (void)) {
{ struct proc_dir_entry *p;
int err = proc_register(proc_net, &proc_router); proc_router = proc_mkdir(ROUTER_NAME, proc_net);
if (!proc_router)
if (!err) { goto fail;
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) { p = create_proc_entry("config",0,proc_router);
proc_register_dynamic(&proc_router, &proc_router_conf); if (!p)
proc_register_dynamic(&proc_router, &proc_router_stat); goto fail_config;
} p->proc_fops = &config_fops;
return err; p->proc_iops = &router_inode;
} p = create_proc_entry("status",0,proc_router);
#endif 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;
}
/* /*
* Clean up router proc interface. * Clean up router proc interface.
*/ */
void wanrouter_proc_cleanup (void) void wanrouter_proc_cleanup (void)
{ {
proc_unregister(&proc_router, proc_router_conf.low_ino); remove_proc_entry("config", proc_router);
proc_unregister(&proc_router, proc_router_stat.low_ino); remove_proc_entry("status", proc_router);
#ifdef LINUX_2_1 remove_proc_entry(ROUTER_NAME,proc_net);
proc_unregister(proc_net, proc_router.low_ino); }
#else
proc_unregister(&proc_net, proc_router.low_ino);
#endif
}
/* /*
* Add directory entry for WAN device. * Add directory entry for WAN device.
*/ */
int wanrouter_proc_add (wan_device_t* wandev) int wanrouter_proc_add (wan_device_t* wandev)
{ {
if (wandev->magic != ROUTER_MAGIC) if (wandev->magic != ROUTER_MAGIC)
return -EINVAL; return -EINVAL;
memset(&wandev->dent, 0, sizeof(wandev->dent)); wandev->dent = create_proc_entry(wandev->name, 0, proc_router);
wandev->dent.namelen = strlen(wandev->name); if (!wandev->dent)
wandev->dent.name = wandev->name; return -ENOMEM;
wandev->dent.mode = 0444 | S_IFREG; wandev->dent->proc_fops = &wandev_fops;
wandev->dent.nlink = 1; wandev->dent->proc_iops = &router_inode;
wandev->dent.ops = &wandev_inode; wandev->dent->data = wandev;
wandev->dent.get_info = &wandev_get_info; return 0;
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
}
/* /*
* Delete directory entry for WAN device. * Delete directory entry for WAN device.
*/ */
int wanrouter_proc_delete(wan_device_t* wandev) int wanrouter_proc_delete(wan_device_t* wandev)
{ {
if (wandev->magic != ROUTER_MAGIC) if (wandev->magic != ROUTER_MAGIC)
return -EINVAL; return -EINVAL;
proc_unregister(&proc_router, wandev->dent.low_ino); remove_proc_entry(wandev->name, proc_router);
return 0;
}
/****** Proc filesystem entry points ****************************************/
/*
* Verify access rights.
*/
static int router_proc_perms (struct inode* inode, int op)
{
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)
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)
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;
}
/*
* 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; 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);
#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);
return cnt;
}
#endif /* End of ifdef LINUX_2_4 */
#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,33 +429,6 @@ int wanrouter_proc_delete(wan_device_t *wandev) ...@@ -1054,33 +429,6 @@ 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