fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / net / wanrouter / wanmain.c
index fcdce75..769cdd6 100644 (file)
@@ -3,7 +3,7 @@
 *
 *              This module is completely hardware-independent and provides
 *              the following common services for the WAN Link Drivers:
-*               o WAN device managenment (registering, unregistering)
+*               o WAN device management (registering, unregistering)
 *               o Network interface management
 *               o Physical connection management (dial-up, incoming calls)
 *               o Logical connection management (switched virtual circuits)
 * Jun 02, 1999  Gideon Hack    Updates for Linux 2.0.X and 2.2.X kernels.
 *****************************************************************************/
 
-#include <linux/config.h>
 #include <linux/stddef.h>      /* offsetof(), etc. */
+#include <linux/capability.h>
 #include <linux/errno.h>       /* return codes */
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/module.h>      /* support for loadable modules */
-#include <linux/slab.h>        /* kmalloc(), kfree() */
-#include <linux/mm.h>          /* verify_area(), etc. */
+#include <linux/slab.h>                /* kmalloc(), kfree() */
+#include <linux/mm.h>
 #include <linux/string.h>      /* inline mem*, str* functions */
 
 #include <asm/byteorder.h>     /* htons(), etc. */
 
 #define KMEM_SAFETYZONE 8
 
-/***********FOR DEBUGGING PURPOSES*********************************************
-static void * dbg_kmalloc(unsigned int size, int prio, int line) {
-       int i = 0;
-       void * v = kmalloc(size+sizeof(unsigned int)+2*KMEM_SAFETYZONE*8,prio);
-       char * c1 = v;
-       c1 += sizeof(unsigned int);
-       *((unsigned int *)v) = size;
-
-       for (i = 0; i < KMEM_SAFETYZONE; i++) {
-               c1[0] = 'D'; c1[1] = 'E'; c1[2] = 'A'; c1[3] = 'D';
-               c1[4] = 'B'; c1[5] = 'E'; c1[6] = 'E'; c1[7] = 'F';
-               c1 += 8;
-       }
-       c1 += size;
-       for (i = 0; i < KMEM_SAFETYZONE; i++) {
-               c1[0] = 'M'; c1[1] = 'U'; c1[2] = 'N'; c1[3] = 'G';
-               c1[4] = 'W'; c1[5] = 'A'; c1[6] = 'L'; c1[7] = 'L';
-               c1 += 8;
-       }
-       v = ((char *)v) + sizeof(unsigned int) + KMEM_SAFETYZONE*8;
-       printk(KERN_INFO "line %d  kmalloc(%d,%d) = %p\n",line,size,prio,v);
-       return v;
-}
-static void dbg_kfree(void * v, int line) {
-       unsigned int * sp = (unsigned int *)(((char *)v) - (sizeof(unsigned int) + KMEM_SAFETYZONE*8));
-       unsigned int size = *sp;
-       char * c1 = ((char *)v) - KMEM_SAFETYZONE*8;
-       int i = 0;
-       for (i = 0; i < KMEM_SAFETYZONE; i++) {
-               if (   c1[0] != 'D' || c1[1] != 'E' || c1[2] != 'A' || c1[3] != 'D'
-                   || c1[4] != 'B' || c1[5] != 'E' || c1[6] != 'E' || c1[7] != 'F') {
-                       printk(KERN_INFO "kmalloced block at %p has been corrupted (underrun)!\n",v);
-                       printk(KERN_INFO " %4x: %2x %2x %2x %2x %2x %2x %2x %2x\n", i*8,
-                                       c1[0],c1[1],c1[2],c1[3],c1[4],c1[5],c1[6],c1[7] );
-               }
-               c1 += 8;
-       }
-       c1 += size;
-       for (i = 0; i < KMEM_SAFETYZONE; i++) {
-               if (   c1[0] != 'M' || c1[1] != 'U' || c1[2] != 'N' || c1[3] != 'G'
-                   || c1[4] != 'W' || c1[5] != 'A' || c1[6] != 'L' || c1[7] != 'L'
-                  ) {
-                       printk(KERN_INFO "kmalloced block at %p has been corrupted (overrun):\n",v);
-                       printk(KERN_INFO " %4x: %2x %2x %2x %2x %2x %2x %2x %2x\n", i*8,
-                                       c1[0],c1[1],c1[2],c1[3],c1[4],c1[5],c1[6],c1[7] );
-               }
-               c1 += 8;
-       }
-       printk(KERN_INFO "line %d  kfree(%p)\n",line,v);
-       v = ((char *)v) - (sizeof(unsigned int) + KMEM_SAFETYZONE*8);
-       kfree(v);
-}
-
-#define kmalloc(x,y) dbg_kmalloc(x,y,__LINE__)
-#define kfree(x) dbg_kfree(x,__LINE__)
-*****************************************************************************/
-
 /*
  *     Function Prototypes
  */
@@ -128,13 +71,14 @@ static void dbg_kfree(void * v, int line) {
  */
 
 static int wanrouter_device_setup(struct wan_device *wandev,
-                                 wandev_conf_t *u_conf);
+                                 wandev_conf_t __user *u_conf);
 static int wanrouter_device_stat(struct wan_device *wandev,
-                                wandev_stat_t *u_stat);
+                                wandev_stat_t __user *u_stat);
 static int wanrouter_device_shutdown(struct wan_device *wandev);
 static int wanrouter_device_new_if(struct wan_device *wandev,
-                                  wanif_conf_t *u_conf);
-static int wanrouter_device_del_if(struct wan_device *wandev, char *u_name);
+                                  wanif_conf_t __user *u_conf);
+static int wanrouter_device_del_if(struct wan_device *wandev,
+                                  char __user *u_name);
 
 /*
  *     Miscellaneous
@@ -357,10 +301,10 @@ int wanrouter_encapsulate(struct sk_buff *skb, struct net_device *dev,
  */
 
 
-unsigned short wanrouter_type_trans(struct sk_buff *skb, struct net_device *dev)
+__be16 wanrouter_type_trans(struct sk_buff *skb, struct net_device *dev)
 {
        int cnt = skb->data[0] ? 0 : 1; /* there may be a pad present */
-       unsigned short ethertype;
+       __be16 ethertype;
 
        switch (skb->data[cnt]) {
        case NLPID_IP:          /* IP datagramm */
@@ -378,7 +322,7 @@ unsigned short wanrouter_type_trans(struct sk_buff *skb, struct net_device *dev)
                                skb->data[cnt+3], dev->name);
                        return 0;
                }
-               ethertype = *((unsigned short*)&skb->data[cnt+4]);
+               ethertype = *((__be16*)&skb->data[cnt+4]);
                cnt += 6;
                break;
 
@@ -410,6 +354,7 @@ int wanrouter_ioctl(struct inode *inode, struct file *file,
        int err = 0;
        struct proc_dir_entry *dent;
        struct wan_device *wandev;
+       void __user *data = (void __user *)arg;
 
        if (!capable(CAP_NET_ADMIN))
                return -EPERM;
@@ -427,7 +372,7 @@ int wanrouter_ioctl(struct inode *inode, struct file *file,
 
        switch (cmd) {
        case ROUTER_SETUP:
-               err = wanrouter_device_setup(wandev, (void*)arg);
+               err = wanrouter_device_setup(wandev, data);
                break;
 
        case ROUTER_DOWN:
@@ -435,15 +380,15 @@ int wanrouter_ioctl(struct inode *inode, struct file *file,
                break;
 
        case ROUTER_STAT:
-               err = wanrouter_device_stat(wandev, (void*)arg);
+               err = wanrouter_device_stat(wandev, data);
                break;
 
        case ROUTER_IFNEW:
-               err = wanrouter_device_new_if(wandev, (void*)arg);
+               err = wanrouter_device_new_if(wandev, data);
                break;
 
        case ROUTER_IFDEL:
-               err = wanrouter_device_del_if(wandev, (void*)arg);
+               err = wanrouter_device_del_if(wandev, data);
                break;
 
        case ROUTER_IFSTAT:
@@ -472,7 +417,7 @@ int wanrouter_ioctl(struct inode *inode, struct file *file,
  */
 
 static int wanrouter_device_setup(struct wan_device *wandev,
-                                 wandev_conf_t *u_conf)
+                                 wandev_conf_t __user *u_conf)
 {
        void *data = NULL;
        wandev_conf_t *conf;
@@ -583,7 +528,7 @@ static int wanrouter_device_shutdown(struct wan_device *wandev)
  */
 
 static int wanrouter_device_stat(struct wan_device *wandev,
-                                wandev_stat_t *u_stat)
+                                wandev_stat_t __user *u_stat)
 {
        wandev_stat_t stat;
 
@@ -614,7 +559,7 @@ static int wanrouter_device_stat(struct wan_device *wandev,
  */
 
 static int wanrouter_device_new_if(struct wan_device *wandev,
-                                  wanif_conf_t *u_conf)
+                                  wanif_conf_t __user *u_conf)
 {
        wanif_conf_t *cnf;
        struct net_device *dev = NULL;
@@ -640,18 +585,16 @@ static int wanrouter_device_new_if(struct wan_device *wandev,
 
        if (cnf->config_id == WANCONFIG_MPPP) {
 #ifdef CONFIG_WANPIPE_MULTPPP
-               pppdev = kmalloc(sizeof(struct ppp_device), GFP_KERNEL);
+               pppdev = kzalloc(sizeof(struct ppp_device), GFP_KERNEL);
                err = -ENOBUFS;
                if (pppdev == NULL)
                        goto out;
-               memset(pppdev, 0, sizeof(struct ppp_device));
-               pppdev->dev = kmalloc(sizeof(struct net_device), GFP_KERNEL);
+               pppdev->dev = kzalloc(sizeof(struct net_device), GFP_KERNEL);
                if (pppdev->dev == NULL) {
                        kfree(pppdev);
                        err = -ENOBUFS;
                        goto out;
                }
-               memset(pppdev->dev, 0, sizeof(struct net_device));
                err = wandev->new_if(wandev, (struct net_device *)pppdev, cnf);
                dev = pppdev->dev;
 #else
@@ -661,11 +604,10 @@ static int wanrouter_device_new_if(struct wan_device *wandev,
                goto out;
 #endif
        } else {
-               dev = kmalloc(sizeof(struct net_device), GFP_KERNEL);
+               dev = kzalloc(sizeof(struct net_device), GFP_KERNEL);
                err = -ENOBUFS;
                if (dev == NULL)
                        goto out;
-               memset(dev, 0, sizeof(struct net_device));
                err = wandev->new_if(wandev, dev, cnf);
        }
 
@@ -712,10 +654,8 @@ static int wanrouter_device_new_if(struct wan_device *wandev,
        }
 
        /* This code has moved from del_if() function */
-       if (dev->priv) {
-               kfree(dev->priv);
-               dev->priv = NULL;
-       }
+       kfree(dev->priv);
+       dev->priv = NULL;
 
 #ifdef CONFIG_WANPIPE_MULTPPP
        if (cnf->config_id == WANCONFIG_MPPP)
@@ -740,7 +680,7 @@ out:
  *      o copy configuration data to kernel address space
  */
 
-static int wanrouter_device_del_if(struct wan_device *wandev, char *u_name)
+static int wanrouter_device_del_if(struct wan_device *wandev, char __user *u_name)
 {
        char name[WAN_IFNAME_SZ + 1];
         int err = 0;
@@ -849,10 +789,8 @@ static int wanrouter_delete_interface(struct wan_device *wandev, char *name)
 
        /* Due to new interface linking method using dev->priv,
         * this code has moved from del_if() function.*/
-       if (dev->priv){
-               kfree(dev->priv);
-               dev->priv=NULL;
-       }
+       kfree(dev->priv);
+       dev->priv=NULL;
 
        unregister_netdev(dev);