]> git.ozlabs.org Git - ppp.git/blobdiff - linux/ppp.c
updated to zlib-1.0.4
[ppp.git] / linux / ppp.c
index 98a74979faabf58328e25343dae01a2b9b90bcd2..38472f90e2de50e2dd4c904ae9caf7b4494c2bd7 100644 (file)
@@ -6,7 +6,7 @@
  *  Dynamic PPP devices by Jim Freeman <jfree@caldera.com>.
  *  ppp_tty_receive ``noisy-raise-bug'' fixed by Ove Ewerlid <ewerlid@syscon.uu.se>
  *
- *  ==FILEVERSION 960926==
+ *  ==FILEVERSION 970626==
  *
  *  NOTE TO MAINTAINERS:
  *     If you modify this file at all, please set the number above to the
@@ -51,7 +51,7 @@
 #define PPP_MAX_DEV    256
 #endif
 
-/* $Id: ppp.c,v 1.9 1996/09/26 06:26:01 paulus Exp $
+/* $Id: ppp.c,v 1.13 1997/07/14 03:50:50 paulus Exp $
  * Added dynamic allocation of channels to eliminate
  *   compiled-in limits on the number of channels.
  *
@@ -59,6 +59,7 @@
  *   released under the GNU General Public License Version 2.
  */
 
+#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/fcntl.h>
 #include <linux/interrupt.h>
 #include <linux/ptrace.h>
+
+#undef VERSION
+/* a nice define to generate linux version numbers */
+#define VERSION(major,minor,patch) (((((major)<<8)+(minor))<<8)+(patch))
+
+#if LINUX_VERSION_CODE < VERSION(2,1,14)
 #include <linux/ioport.h>
+#endif
+
+#if LINUX_VERSION_CODE >= VERSION(2,1,23)
+#include <linux/poll.h>
+#endif
+
 #include <linux/in.h>
 #include <linux/malloc.h>
 #include <linux/tty.h>
@@ -76,7 +89,6 @@
 #include <linux/signal.h>      /* used in new tty drivers */
 #include <asm/system.h>
 #include <asm/bitops.h>
-#include <asm/segment.h>
 #include <linux/if.h>
 #include <linux/if_ether.h>
 #include <linux/netdevice.h>
@@ -108,6 +120,53 @@ typedef struct sk_buff          sk_buff;
 #define PPP_LQR 0xc025 /* Link Quality Reporting Protocol */
 #endif
 
+#if LINUX_VERSION_CODE >= VERSION(2,1,4)
+#include <asm/segment.h>
+#define GET_USER(error,value,addr) error = get_user(value,addr)
+#define COPY_FROM_USER(error,dest,src,size) error = copy_from_user(dest,src,size) ? -EFAULT : 0
+#define PUT_USER(error,value,addr) error = put_user(value,addr)
+#define COPY_TO_USER(error,dest,src,size) error = copy_to_user(dest,src,size) ? -EFAULT : 0
+
+#if LINUX_VERSION_CODE >= VERSION(2,1,5)
+#include <asm/uaccess.h>
+#endif
+
+#else  /* 2.0.x and 2.1.x before 2.1.4 */
+
+#define GET_USER(error,value,addr)                                       \
+do {                                                                     \
+       error = verify_area (VERIFY_READ, (void *) addr, sizeof (value)); \
+       if (error == 0)                                                   \
+               value = get_user(addr);                                   \
+} while (0)
+
+#define COPY_FROM_USER(error,dest,src,size)                              \
+do {                                                                     \
+       error = verify_area (VERIFY_READ, (void *) src, size);            \
+       if (error == 0)                                                   \
+               memcpy_fromfs (dest, src, size);                          \
+} while (0)
+
+#define PUT_USER(error,value,addr)                                        \
+do {                                                                      \
+       error = verify_area (VERIFY_WRITE, (void *) addr, sizeof (value)); \
+       if (error == 0)                                                    \
+               put_user (value, addr);                                    \
+} while (0)
+
+#define COPY_TO_USER(error,dest,src,size)                                \
+do {                                                                     \
+       error = verify_area (VERIFY_WRITE, (void *) dest, size);                  \
+       if (error == 0)                                                   \
+               memcpy_tofs (dest, src, size);                            \
+} while (0)
+
+#endif
+
+#if LINUX_VERSION_CODE < VERSION(2,1,37)
+#define test_and_set_bit(nr, addr)     set_bit(nr, addr)
+#endif
+
 static int ppp_register_compressor (struct compressor *cp);
 static void ppp_unregister_compressor (struct compressor *cp);
 
@@ -118,7 +177,6 @@ static void ppp_unregister_compressor (struct compressor *cp);
 static struct compressor *find_compressor (int type);
 static void ppp_init_ctrl_blk (register struct ppp *);
 static void ppp_kick_tty (struct ppp *, struct ppp_buffer *bfr);
-static int ppp_doframe (struct ppp *);
 static struct ppp *ppp_alloc (void);
 static struct ppp *ppp_find (int pid_value);
 static void ppp_print_buffer (const __u8 *, const __u8 *, int);
@@ -126,6 +184,8 @@ extern inline void ppp_stuff_char (struct ppp *ppp,
                                   register struct ppp_buffer *buf,
                                   register __u8 chr);
 extern inline int lock_buffer (register struct ppp_buffer *buf);
+static int ppp_dev_xmit_ip (struct ppp *ppp, struct ppp_buffer *buf,
+                           __u8 *data, int len);
 
 static int rcv_proto_ip                (struct ppp *, __u16, __u8 *, int);
 static int rcv_proto_ipx       (struct ppp *, __u16, __u8 *, int);
@@ -156,6 +216,11 @@ static int  rcv_proto_ccp (struct ppp *, __u16, __u8 *, int);
 static int  flag_time = OPTIMIZE_FLAG_TIME;
 static int  max_dev   = PPP_MAX_DEV;
 
+#if LINUX_VERSION_CODE >= VERSION(2,1,19) 
+MODULE_PARM(flag_time, "i");
+MODULE_PARM(max_dev, "i");
+#endif
+
 /*
  * The "main" procedure to the ppp device
  */
@@ -171,10 +236,14 @@ static int ppp_dev_ioctl (struct device *dev, struct ifreq *ifr, int cmd);
 static int ppp_dev_close (struct device *);
 static int ppp_dev_xmit (sk_buff *, struct device *);
 static struct enet_statistics *ppp_dev_stats (struct device *);
+
+#if LINUX_VERSION_CODE < VERSION(2,1,15)
 static int ppp_dev_header (sk_buff *, struct device *, __u16,
                           void *, void *, unsigned int);
 static int ppp_dev_rebuild (void *eth, struct device *dev,
-                            unsigned long raddr, struct sk_buff *skb);
+                           unsigned long raddr, struct sk_buff *skb);
+#endif
+
 /*
  * TTY callbacks
  */
@@ -184,9 +253,13 @@ static int ppp_tty_read (struct tty_struct *, struct file *, __u8 *,
 static int ppp_tty_write (struct tty_struct *, struct file *, const __u8 *,
                          unsigned int);
 static int ppp_tty_ioctl (struct tty_struct *, struct file *, unsigned int,
-                          unsigned long);
+                         unsigned long);
+#if LINUX_VERSION_CODE < VERSION(2,1,23)
 static int ppp_tty_select (struct tty_struct *tty, struct inode *inode,
                      struct file *filp, int sel_type, select_table * wait);
+#else
+static unsigned int ppp_tty_poll (struct tty_struct *tty, struct file *filp, poll_table * wait);
+#endif
 static int ppp_tty_open (struct tty_struct *);
 static void ppp_tty_close (struct tty_struct *);
 static int ppp_tty_room (struct tty_struct *tty);
@@ -194,8 +267,25 @@ static void ppp_tty_receive (struct tty_struct *tty, const __u8 * cp,
                             char *fp, int count);
 static void ppp_tty_wakeup (struct tty_struct *tty);
 
-#define CHECK_PPP(a)  if (!ppp->inuse) { printk (ppp_warning, __LINE__); return a;}
-#define CHECK_PPP_VOID()  if (!ppp->inuse) { printk (ppp_warning, __LINE__); return;}
+#define CHECK_PPP_MAGIC(ppp)   do { \
+       if (ppp->magic != PPP_MAGIC) { \
+               printk(KERN_WARNING "bad magic for ppp %p at %s:%d\n", \
+                      ppp, __FILE__, __LINE__); \
+       } \
+} while (0)
+#define CHECK_PPP(a)   do { \
+       CHECK_PPP_MAGIC(ppp); \
+       if (!ppp->inuse) { \
+               printk (ppp_warning, __LINE__); \
+               return a; \
+       } \
+} while (0)
+#define CHECK_PPP_VOID() do { \
+       CHECK_PPP_MAGIC(ppp); \
+       if (!ppp->inuse) { \
+               printk (ppp_warning, __LINE__); \
+       } \
+} while (0)
 
 #define in_xmap(ppp,c) (ppp->xmit_async_map[(c) >> 5] & (1 << ((c) & 0x1f)))
 #define in_rmap(ppp,c) ((((unsigned int) (__u8) (c)) < 0x20) && \
@@ -203,31 +293,13 @@ static void ppp_tty_wakeup (struct tty_struct *tty);
 
 #define bset(p,b)      ((p)[(b) >> 5] |= (1 << ((b) & 0x1f)))
 
-#define tty2ppp(tty)   ((struct ppp *) (tty->disc_data))
-#define dev2ppp(dev)   ((struct ppp *) (dev->priv))
-#define ppp2tty(ppp)   ((struct tty_struct *) ppp->tty)
-#define ppp2dev(ppp)   ((struct device *) ppp->dev)
-
-struct ppp_hdr {
-       __u8 address;
-       __u8 control;
-       __u8 protocol[2];
-};
-
-#define PPP_HARD_HDR_LEN       (sizeof (struct ppp_hdr))
-
-typedef struct ppp_ctrl {
-       struct ppp_ctrl *next;          /* Next structure in the list   */
-       char            name [8];       /* Name of the device           */
-       struct ppp      ppp;            /* PPP control table            */
-       struct device   dev;            /* Device information table     */
-} ppp_ctrl_t;
+#define tty2ppp(tty)   ((struct ppp *) ((tty)->disc_data))
+#define dev2ppp(dev)   ((struct ppp *) ((dev)->priv))
+#define ppp2tty(ppp)   ((ppp)->tty)
+#define ppp2dev(ppp)   (&(ppp)->dev)
 
-static ppp_ctrl_t *ppp_list = NULL;
-
-#define ctl2ppp(ctl) (struct ppp *)    &ctl->ppp
-#define ctl2dev(ctl) (struct device *) &ctl->dev
-#undef PPP_NRUNIT
+static struct ppp *ppp_list = NULL;
+static struct ppp *ppp_last = NULL;
 
 /* Buffer types */
 #define BUFFER_TYPE_DEV_RD     0  /* ppp read buffer       */
@@ -240,7 +312,7 @@ static ppp_ctrl_t *ppp_list = NULL;
 static char ppp_warning[] = KERN_WARNING "PPP: ALERT! not INUSE! %d\n";
 
 static char szVersion[]                = PPP_VERSION;
+
 /*
  * Information for the protocol decoder
  */
@@ -340,13 +412,10 @@ ppp_first_time (void)
                "TCP compression code copyright 1989 Regents of the "
                "University of California\n");
 #endif
-       
-       printk (KERN_INFO
-               "PPP Dynamic channel allocation code copyright 1995 "
-               "Caldera, Inc.\n");
+
 /*
  * Register the tty discipline
- */    
+ */
        (void) memset (&ppp_ldisc, 0, sizeof (ppp_ldisc));
        ppp_ldisc.magic         = TTY_LDISC_MAGIC;
        ppp_ldisc.open          = ppp_tty_open;
@@ -354,11 +423,15 @@ ppp_first_time (void)
        ppp_ldisc.read          = ppp_tty_read;
        ppp_ldisc.write         = ppp_tty_write;
        ppp_ldisc.ioctl         = ppp_tty_ioctl;
+#if LINUX_VERSION_CODE < VERSION(2,1,23)
        ppp_ldisc.select        = ppp_tty_select;
+#else
+       ppp_ldisc.poll          = ppp_tty_poll;
+#endif
        ppp_ldisc.receive_room  = ppp_tty_room;
        ppp_ldisc.receive_buf   = ppp_tty_receive;
        ppp_ldisc.write_wakeup  = ppp_tty_wakeup;
-       
+
        status = tty_register_ldisc (N_PPP, &ppp_ldisc);
        if (status == 0)
                printk (KERN_INFO "PPP line discipline registered.\n");
@@ -377,10 +450,11 @@ ppp_first_time (void)
 static int
 ppp_init_dev (struct device *dev)
 {
-       int    indx;
-
+#if LINUX_VERSION_CODE < VERSION(2,1,15)
        dev->hard_header      = ppp_dev_header;
        dev->rebuild_header   = ppp_dev_rebuild;
+#endif
+
        dev->hard_header_len  = PPP_HARD_HDR_LEN;
 
        /* device INFO */
@@ -394,11 +468,19 @@ ppp_init_dev (struct device *dev)
        dev->tx_queue_len     = 10;
        dev->type             = ARPHRD_PPP;
 
-       for (indx = 0; indx < DEV_NUMBUFFS; indx++)
-               skb_queue_head_init (&dev->buffs[indx]);
+#if LINUX_VERSION_CODE < VERSION(2,1,20)
+       {
+               int    indx;
+
+               for (indx = 0; indx < DEV_NUMBUFFS; indx++)
+                       skb_queue_head_init (&dev->buffs[indx]);
+       }
+#else
+       dev_init_buffers(dev);
+#endif
 
        /* New-style flags */
-       dev->flags      = IFF_POINTOPOINT;
+       dev->flags      = IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
        dev->family     = AF_INET;
        dev->pa_addr    = 0;
        dev->pa_brdaddr = 0;
@@ -450,6 +532,7 @@ ppp_init_ctrl_blk (register struct ppp *ppp)
        ppp->sc_rc_state = NULL;
 }
 
+#if LINUX_VERSION_CODE < VERSION(2,1,18)
 static struct symbol_table ppp_syms = {
 #include <linux/symtab_begin.h>
        X(ppp_register_compressor),
@@ -457,6 +540,11 @@ static struct symbol_table ppp_syms = {
        X(ppp_crc16_table),
 #include <linux/symtab_end.h>
 };
+#else
+EXPORT_SYMBOL(ppp_register_compressor);
+EXPORT_SYMBOL(ppp_unregister_compressor);
+EXPORT_SYMBOL(ppp_crc16_table);
+#endif
 
 /* called at boot/load time for each ppp device defined in the kernel */
 
@@ -470,8 +558,10 @@ ppp_init (struct device *dev)
        if (first_time) {
                first_time = 0;
                answer     = ppp_first_time();
+#if LINUX_VERSION_CODE < VERSION(2,1,18)
                if (answer == 0)
                        (void) register_symtab (&ppp_syms);
+#endif
        }
        if (answer == 0)
                answer = -ENODEV;
@@ -479,6 +569,14 @@ ppp_init (struct device *dev)
 }
 #endif
 
+#define BUFFER_MAGIC   0x1d10
+#define CHECK_BUF_MAGIC(buf)   do { \
+       if (buf->magic != BUFFER_MAGIC) { \
+               printk(KERN_WARNING "bad magic for ppp buffer %p at %s:%d\n", \
+                      buf, __FILE__, __LINE__); \
+       } \
+} while (0)
+
 /*
  * Routine to allocate a buffer for later use by the driver.
  */
@@ -499,7 +597,7 @@ ppp_alloc_buf (int size, int type)
                buf->head   = 0;
                buf->tail   = 0;
                buf->fcs    = PPP_INITFCS;
-
+               buf->magic  = BUFFER_MAGIC;
        }
        return (buf);
 }
@@ -511,8 +609,10 @@ ppp_alloc_buf (int size, int type)
 static void
 ppp_free_buf (struct ppp_buffer *ptr)
 {
-       if (ptr != NULL)
+       if (ptr != NULL) {
+               CHECK_BUF_MAGIC(ptr);
                kfree (ptr);
+       }
 }
 
 /*
@@ -527,6 +627,7 @@ lock_buffer (register struct ppp_buffer *buf)
 /*
  * Save the current state and if free then set it to the "busy" state
  */
+       CHECK_BUF_MAGIC(buf);
        save_flags (flags);
        cli ();
        state = buf->locked;
@@ -547,6 +648,7 @@ static int
 ppp_changedmtu (struct ppp *ppp, int new_mtu, int new_mru)
 {
        struct device *dev;
+       unsigned long flags;
 
        struct ppp_buffer *new_rbuf;
        struct ppp_buffer *new_wbuf;
@@ -562,7 +664,11 @@ ppp_changedmtu (struct ppp *ppp, int new_mtu, int new_mru)
 /*
  *  Allocate the buffer from the kernel for the data
  */
+       CHECK_PPP(0);
        dev = ppp2dev (ppp);
+       if (ppp->flags & SC_DEBUG)
+               printk(KERN_DEBUG "%s: changedmtu %d %d\n", ppp->name,
+                      new_mtu, new_mru);
        mru = new_mru;
        /* allow for possible escaping of every character */
        mtu = (new_mtu * 2) + 20;
@@ -573,10 +679,10 @@ ppp_changedmtu (struct ppp *ppp, int new_mtu, int new_mru)
 
        mru += 10;
 
-       new_wbuf = ppp_alloc_buf (mtu+PPP_HARD_HDR_LEN, BUFFER_TYPE_DEV_WR);
+       new_wbuf = ppp_alloc_buf (mtu+PPP_HDRLEN,       BUFFER_TYPE_DEV_WR);
        new_tbuf = ppp_alloc_buf ((PPP_MTU * 2) + 24,   BUFFER_TYPE_TTY_WR);
        new_rbuf = ppp_alloc_buf (mru + 84,             BUFFER_TYPE_DEV_RD);
-       new_cbuf = ppp_alloc_buf (mru+PPP_HARD_HDR_LEN, BUFFER_TYPE_VJ);
+       new_cbuf = ppp_alloc_buf (mru+PPP_HDRLEN,       BUFFER_TYPE_VJ);
 /*
  *  If the buffers failed to allocate then complain and release the partial
  *  allocations.
@@ -596,6 +702,7 @@ ppp_changedmtu (struct ppp *ppp, int new_mtu, int new_mru)
 /*
  *  Update the pointers to the new buffer structures.
  */
+       save_flags(flags);
        cli ();
        old_wbuf = ppp->wbuf;
        old_rbuf = ppp->rbuf;
@@ -607,6 +714,9 @@ ppp_changedmtu (struct ppp *ppp, int new_mtu, int new_mru)
        ppp->cbuf = new_cbuf;
        ppp->tbuf = new_tbuf;
 
+       if (old_wbuf)
+               new_wbuf->locked = old_wbuf->locked;
+
        ppp->rbuf->size -= 80;  /* reserve space for vj header expansion */
 
        dev->mem_start  = (unsigned long) buf_base (new_wbuf);
@@ -630,7 +740,7 @@ ppp_changedmtu (struct ppp *ppp, int new_mtu, int new_mru)
        ppp->tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
        ppp->flags      &= ~SC_XMIT_BUSY;
 
-       sti ();
+       restore_flags(flags);
 /*
  *  Release old buffer pointers
  */
@@ -648,6 +758,14 @@ ppp_changedmtu (struct ppp *ppp, int new_mtu, int new_mru)
 static void
 ppp_ccp_closed (struct ppp *ppp)
 {
+       unsigned long flags;
+
+       save_flags(flags);
+       cli();
+       ppp->flags &= ~(SC_CCP_OPEN | SC_CCP_UP | SC_COMP_RUN | SC_DECOMP_RUN);
+       restore_flags(flags);
+       if (ppp->flags & SC_DEBUG)
+               printk(KERN_DEBUG "%s: ccp closed\n", ppp->name);
        if (ppp->sc_xc_state) {
                (*ppp->sc_xcomp->comp_free) (ppp->sc_xc_state);
                ppp->sc_xc_state = NULL;
@@ -672,21 +790,25 @@ ppp_release (struct ppp *ppp)
        struct tty_struct *tty;
        struct device *dev;
 
+       CHECK_PPP_MAGIC(ppp);
        tty = ppp2tty (ppp);
        dev = ppp2dev (ppp);
 
+       if (ppp->flags & SC_DEBUG)
+               printk(KERN_DEBUG "ppp%s released\n", ppp->name);
+
        ppp_ccp_closed (ppp);
 
-        /* Ensure that the pppd process is not hanging on select() */
-        wake_up_interruptible (&ppp->read_wait);
-        wake_up_interruptible (&ppp->write_wait);
+       /* Ensure that the pppd process is not hanging on select()/poll() */
+       wake_up_interruptible (&ppp->read_wait);
+       wake_up_interruptible (&ppp->write_wait);
 
        if (tty != NULL && tty->disc_data == ppp)
                tty->disc_data = NULL;  /* Break the tty->ppp link */
 
        if (dev && dev->flags & IFF_UP) {
+               dev->flags &= ~IFF_UP;   /* prevent recursion */
                dev_close (dev); /* close the device properly */
-               dev->flags = 0;  /* prevent recursion */
        }
 
        ppp_free_buf (ppp->rbuf);
@@ -783,8 +905,9 @@ ppp_tty_open (struct tty_struct *tty)
                 * If we are taking over a ppp unit which is currently
                 * connected to a loopback pty, there's not much to do.
                 */
-               ppp->tty       = tty;
+               CHECK_PPP(-EINVAL);
                tty->disc_data = ppp;
+               ppp->tty       = tty;
 
        } else {
                ppp = ppp_alloc();
@@ -797,8 +920,8 @@ ppp_tty_open (struct tty_struct *tty)
  * Initialize the control block
  */
                ppp_init_ctrl_blk (ppp);
-               ppp->tty       = tty;
                tty->disc_data = ppp;
+               ppp->tty       = tty;
 /*
  * Allocate space for the default VJ header compression slots
  */
@@ -865,16 +988,21 @@ ppp_tty_wakeup_code (struct ppp *ppp, struct tty_struct *tty,
                     struct ppp_buffer *xbuf)
 {
        register int count, actual;
+       unsigned long flags;
+
+       CHECK_PPP_VOID();
+       CHECK_BUF_MAGIC(xbuf);
 /*
  * Prevent re-entrancy by ensuring that this routine is called only once.
  */
+       save_flags(flags);
        cli ();
        if (ppp->flags & SC_XMIT_BUSY) {
-               sti ();
+               restore_flags(flags);
                return;
        }
        ppp->flags |= SC_XMIT_BUSY;
-       sti ();
+       restore_flags(flags);
 /*
  * Send the next block of data to the modem
  */
@@ -909,9 +1037,8 @@ ppp_tty_wakeup_code (struct ppp *ppp, struct tty_struct *tty,
  * If the completed buffer came from the device write, then complete the
  * transmission block.
  */
+                       ppp2dev (ppp)->tbusy = 0;
                        if (ppp2dev (ppp) -> flags & IFF_UP) {
-                               if (xbuf->type == BUFFER_TYPE_DEV_WR)
-                                       ppp2dev (ppp)->tbusy = 0;
                                mark_bh (NET_BH);
                        }
 /*
@@ -921,6 +1048,7 @@ ppp_tty_wakeup_code (struct ppp *ppp, struct tty_struct *tty,
 /*
  * Look at the priorities. Choose a daemon write over the device driver.
  */
+                       save_flags(flags);
                        cli();
                        xbuf = ppp->s1buf;
                        ppp->s1buf = NULL;
@@ -928,21 +1056,25 @@ ppp_tty_wakeup_code (struct ppp *ppp, struct tty_struct *tty,
                                xbuf = ppp->s2buf;
                                ppp->s2buf = NULL;
                        }
-                       sti();
 /*
  * If there is a pending buffer then transmit it now.
  */
                        if (xbuf != NULL) {
                                ppp->flags &= ~SC_XMIT_BUSY;
                                ppp_kick_tty (ppp, xbuf);
+                               restore_flags(flags);
                                return;
                        }
+                       restore_flags(flags);
                }
        }
 /*
  * Clear the re-entry flag
  */
+       save_flags(flags);      /* &=~ may not be atomic */
+       cli ();
        ppp->flags &= ~SC_XMIT_BUSY;
+       restore_flags(flags);
 }
 
 /*
@@ -962,9 +1094,7 @@ ppp_tty_wakeup (struct tty_struct *tty)
 
        if (!ppp)
                return;
-
-       if (ppp->magic != PPP_MAGIC)
-               return;
+       CHECK_PPP_VOID();
 
        if (tty != ppp->tty) {
                tty->flags &= ~(1 << TTY_DO_WRITE_WAKEUP);
@@ -991,6 +1121,9 @@ static void
 ppp_kick_tty (struct ppp *ppp, struct ppp_buffer *xbuf)
 {
        unsigned long flags;
+
+       CHECK_PPP_VOID();
+       CHECK_BUF_MAGIC(xbuf);
 /*
  * Hold interrupts.
  */
@@ -1057,17 +1190,17 @@ ppp_tty_receive (struct tty_struct *tty, const __u8 * data,
        register struct ppp_buffer *buf = NULL;
        __u8 chr;
 
+       if (ppp != 0)
+               CHECK_PPP_VOID();
        /*
         * This can happen if stuff comes in on the backup tty.
         */
-       if (tty != ppp->tty)
+       if (ppp == 0 || tty != ppp->tty)
                return;
 /*
  * Fetch the pointer to the buffer. Be careful about race conditions.
  */
-       if (ppp != NULL)
-               buf = ppp->rbuf;
-
+       buf = ppp->rbuf;
        if (buf == NULL)
                return;
 /*
@@ -1077,7 +1210,7 @@ ppp_tty_receive (struct tty_struct *tty, const __u8 * data,
        if (ppp->magic != PPP_MAGIC) {
                if (ppp->flags & SC_DEBUG)
                        printk (KERN_DEBUG
-                               "PPP: handler called but couldn't find "
+                               "PPP: tty_receive called but couldn't find "
                                "PPP struct.\n");
                return;
        }
@@ -1174,13 +1307,25 @@ ppp_tty_receive (struct tty_struct *tty, const __u8 * data,
                         * 0x5d, if it follows an escape :-)
                         */
                        if (ppp->escape) {
-                               chr ^= ppp->escape;
+                               chr ^= PPP_TRANS;
                                ppp->escape = 0;
                        } else if (chr == PPP_ESCAPE) {
                                ppp->escape = PPP_TRANS;
                                break;
                        }
 
+                       /*
+                        * Decompress A/C and protocol compression here.
+                        */
+                       if (buf->count == 0 && chr != PPP_ALLSTATIONS) {
+                               buf_base(buf)[0] = PPP_ALLSTATIONS;
+                               buf_base(buf)[1] = PPP_UI;
+                               buf->count = 2;
+                       }
+                       if (buf->count == 2 && (chr & 1) != 0) {
+                               buf_base(buf)[2] = 0;
+                               buf->count = 3;
+                       }
 /*
  * If the count sent is within reason then store the character, bump the
  * count, and update the FCS for the character.
@@ -1201,6 +1346,161 @@ ppp_tty_receive (struct tty_struct *tty, const __u8 * data,
        }
 }
 
+/* on entry, a received frame is in ppp->rbuf.bufr
+   check it and dispose as appropriate */
+
+static int
+ppp_doframe (struct ppp *ppp)
+{
+       __u8    *data = buf_base (ppp->rbuf);
+       int     count = ppp->rbuf->count;
+       int     proto;
+       int     new_count;
+       __u8 *new_data;
+
+       CHECK_PPP(0);
+       CHECK_BUF_MAGIC(ppp->rbuf);
+/*
+ * If there is a pending error from the receiver then log it and discard
+ * the damaged frame.
+ */
+       if (ppp->toss) {
+               if ((ppp->flags & SC_DEBUG) && count > 0)
+                       printk (KERN_DEBUG
+                               "ppp_toss: tossing frame, reason = %x\n",
+                               ppp->toss);
+               return 0;
+       }
+/*
+ * An empty frame is ignored. This occurs if the FLAG sequence precedes and
+ * follows each frame.
+ */
+       if (count == 0)
+               return 1;
+/*
+ * Generate an error if the frame is too small.
+ */
+       if (count < PPP_HDRLEN + 2) {
+               if (ppp->flags & SC_DEBUG)
+                       printk (KERN_DEBUG
+                               "ppp: got runt ppp frame, %d chars\n", count);
+               ++ppp->estats.rx_length_errors;
+               return 0;
+       }
+/*
+ * Verify the CRC of the frame and discard the CRC characters from the
+ * end of the buffer.
+ */
+       if (ppp->rbuf->fcs != PPP_GOODFCS) {
+               if (ppp->flags & SC_DEBUG) {
+                       printk (KERN_DEBUG
+                               "ppp: frame with bad fcs, length = %d\n",
+                               count);
+                       ppp_print_buffer("bad frame", data, count);
+               }
+               ++ppp->estats.rx_crc_errors;
+               return 0;
+       }
+       count -= 2;             /* ignore the fcs characters */
+/*
+ * Obtain the protocol from the frame
+ */
+       proto = PPP_PROTOCOL(data);
+/*
+ * Process the active decompressor.
+ */
+       if ((ppp->sc_rc_state != (void *) 0) &&
+           (ppp->flags & SC_DECOMP_RUN)     &&
+           ((ppp->flags & (SC_DC_FERROR | SC_DC_ERROR)) == 0)) {
+               if (proto == PPP_COMP) {
+/*
+ * If the frame is compressed then decompress it.
+ */
+                       new_data = kmalloc (ppp->mru + PPP_HDRLEN, GFP_ATOMIC);
+                       if (new_data == NULL) {
+                               if (ppp->flags & SC_DEBUG)
+                                       printk (KERN_ERR
+                                               "ppp_doframe: no memory\n");
+                               new_count = DECOMP_ERROR;
+                       } else {
+                               new_count = (*ppp->sc_rcomp->decompress)
+                                       (ppp->sc_rc_state, data, count,
+                                        new_data, ppp->mru + PPP_HDRLEN);
+                       }
+                       switch (new_count) {
+                       default:
+                               ppp_doframe_lower (ppp, new_data, new_count);
+                               kfree (new_data);
+                               return 1;
+
+                       case DECOMP_ERROR:
+                               ppp->flags |= SC_DC_ERROR;
+                               break;
+
+                       case DECOMP_FATALERROR:
+                               ppp->flags |= SC_DC_FERROR;
+                               if (ppp->flags & SC_DEBUG)
+                                       printk(KERN_ERR "ppp: fatal decomp error\n");
+                               break;
+                       }
+/*
+ * Log the error condition and discard the frame.
+ */
+                       if (new_data != 0)
+                               kfree (new_data);
+                       slhc_toss (ppp->slcomp);
+                       ++ppp->stats.ppp_ierrors;
+               } else {
+/*
+ * The frame is not special. Pass it through the compressor without
+ * actually compressing the data
+ */
+                       (*ppp->sc_rcomp->incomp) (ppp->sc_rc_state,
+                                                 data, count);
+               }
+       }
+/*
+ * Process the uncompressed frame.
+ */
+       ppp_doframe_lower (ppp, data, count);
+       return 1;
+}
+
+static void ppp_doframe_lower (struct ppp *ppp, __u8 *data, int count)
+{
+       __u16           proto = PPP_PROTOCOL (data);
+       ppp_proto_type  *proto_ptr;
+
+       CHECK_PPP_VOID();
+/*
+ * Ignore empty frames
+ */
+       if (count <= PPP_HDRLEN)
+               return;
+/*
+ * Count the frame and print it
+ */
+       ++ppp->stats.ppp_ipackets;
+       if (ppp->flags & SC_LOG_INPKT)
+               ppp_print_buffer ("receive frame", data, count);
+/*
+ * Find the procedure to handle this protocol. The last one is marked
+ * as a protocol 0 which is the 'catch-all' to feed it to the pppd daemon.
+ */
+       proto_ptr = proto_list;
+       while (proto_ptr->proto != 0 && proto_ptr->proto != proto)
+               ++proto_ptr;
+/*
+ * Update the appropriate statistic counter.
+ */
+       if ((*proto_ptr->func) (ppp, proto,
+                               &data[PPP_HDRLEN],
+                               count - PPP_HDRLEN))
+               ppp->stats.ppp_ioctects += count;
+       else
+               ++ppp->stats.ppp_discards;
+}
+
 /*
  * Put the input frame into the networking system for the indicated protocol
  */
@@ -1229,7 +1529,10 @@ ppp_rcv_rx (struct ppp *ppp, __u16 proto, __u8 * data, int count)
 /*
  * Tag the frame and kick it to the proper receive routine
  */
+#if LINUX_VERSION_CODE < VERSION(2,1,15)
        skb->free = 1;
+#endif
+
        ppp->ddinfo.recv_idle = jiffies;
        netif_rx (skb);
        return 1;
@@ -1242,6 +1545,7 @@ ppp_rcv_rx (struct ppp *ppp, __u16 proto, __u8 * data, int count)
 static int
 rcv_proto_ip (struct ppp *ppp, __u16 proto, __u8 * data, int count)
 {
+       CHECK_PPP(0);
        if ((ppp2dev (ppp)->flags & IFF_UP) && (count > 0))
                if (ppp->sc_npmode[NP_IP] == NPMODE_PASS)
                        return ppp_rcv_rx (ppp, htons (ETH_P_IP), data, count);
@@ -1255,6 +1559,7 @@ rcv_proto_ip (struct ppp *ppp, __u16 proto, __u8 * data, int count)
 static int
 rcv_proto_ipx (struct ppp *ppp, __u16 proto, __u8 * data, int count)
 {
+       CHECK_PPP(0);
        if (((ppp2dev (ppp)->flags & IFF_UP) != 0) && (count > 0))
                return ppp_rcv_rx (ppp, htons (ETH_P_IPX), data, count);
        return 0;
@@ -1268,6 +1573,7 @@ static int
 rcv_proto_vjc_comp (struct ppp *ppp, __u16 proto,
                    __u8 *data, int count)
 {
+       CHECK_PPP(0);
        if ((ppp->flags & SC_REJ_COMP_TCP) == 0) {
                int new_count = slhc_uncompress (ppp->slcomp, data, count);
                if (new_count >= 0) {
@@ -1288,6 +1594,7 @@ static int
 rcv_proto_vjc_uncomp (struct ppp *ppp, __u16 proto,
                      __u8 *data, int count)
 {
+       CHECK_PPP(0);
        if ((ppp->flags & SC_REJ_COMP_TCP) == 0) {
                if (slhc_remember (ppp->slcomp, data, count) > 0) {
                        return rcv_proto_ip (ppp, PPP_IP, data, count);
@@ -1318,15 +1625,17 @@ rcv_proto_unknown (struct ppp *ppp, __u16 proto,
            goto failure;                                \
 }
 
+       CHECK_PPP(0);
 /*
  * The total length includes the protocol data.
  * Lock the user information buffer.
  */
-       if (set_bit (0, &ppp->ubuf->locked)) {
+       if (test_and_set_bit (0, &ppp->ubuf->locked)) {
                if (ppp->flags & SC_DEBUG)
                        printk (KERN_DEBUG
-                               "ppp_us_queue: can't get lock\n");
+                               "ppp: rcv_proto_unknown: can't get lock\n");
        } else {
+               CHECK_BUF_MAGIC(ppp->ubuf);
                current_idx = ppp->ubuf->head;
 /*
  * Insert the buffer length (not counted), the protocol, and the data
@@ -1362,15 +1671,14 @@ failure:
                clear_bit (0, &ppp->ubuf->locked);
                if (ppp->flags & SC_DEBUG)
                        printk (KERN_DEBUG
-                               "ppp_us_queue: ran out of buffer space.\n");
+                               "ppp: rcv_proto_unknown: buffer overflow\n");
        }
 /*
  * Discard the frame. There are no takers for this protocol.
  */
        if (ppp->flags & SC_DEBUG)
                printk (KERN_DEBUG
-                       "ppp: dropping packet on the floor.\n");
-       slhc_toss (ppp->slcomp);
+                       "ppp: rcv_proto_unknown: dropping packet\n");
        return 0;
 }
 
@@ -1387,10 +1695,12 @@ static void ppp_proto_ccp (struct ppp *ppp, __u8 *dp, int len, int rcvd)
        int slen    = CCP_LENGTH(dp);
        __u8 *opt = dp   + CCP_HDRLEN;
        int opt_len = slen - CCP_HDRLEN;
+       unsigned long flags;
 
        if (slen > len)
                return;
 
+       save_flags(flags);
        switch (CCP_CODE(dp)) {
        case CCP_CONFREQ:
        case CCP_TERMREQ:
@@ -1399,6 +1709,7 @@ static void ppp_proto_ccp (struct ppp *ppp, __u8 *dp, int len, int rcvd)
  * CCP must be going down - disable compression
  */
                if (ppp->flags & SC_CCP_UP) {
+                       cli();
                        ppp->flags &= ~(SC_CCP_UP   |
                                        SC_COMP_RUN |
                                        SC_DECOMP_RUN);
@@ -1427,8 +1738,13 @@ static void ppp_proto_ccp (struct ppp *ppp, __u8 *dp, int len, int rcvd)
                             opt_len,
                             ppp2dev (ppp)->base_addr,
                             0,
-                            ppp->flags & SC_DEBUG))
+                            ppp->flags & SC_DEBUG)) {
+                               if (ppp->flags & SC_DEBUG)
+                                       printk(KERN_DEBUG "%s: comp running\n",
+                                              ppp->name);
+                               cli();
                                ppp->flags |= SC_COMP_RUN;
+                       }
                        break;
                }
 /*
@@ -1445,33 +1761,47 @@ static void ppp_proto_ccp (struct ppp *ppp, __u8 *dp, int len, int rcvd)
                     0,
                     ppp->mru,
                     ppp->flags & SC_DEBUG)) {
+                       if (ppp->flags & SC_DEBUG)
+                               printk(KERN_DEBUG "%s: decomp running\n",
+                                      ppp->name);
+                       cli();
                        ppp->flags |= SC_DECOMP_RUN;
                        ppp->flags &= ~(SC_DC_ERROR | SC_DC_FERROR);
                }
                break;
 /*
- * The protocol sequence is complete at this end
+ * CCP Reset-ack resets compressors and decompressors as it passes through.
  */
        case CCP_RESETACK:
                if ((ppp->flags & SC_CCP_UP) == 0)
                        break;
 
                if (!rcvd) {
-                       if (ppp->sc_xc_state && (ppp->flags & SC_COMP_RUN))
+                       if (ppp->sc_xc_state && (ppp->flags & SC_COMP_RUN)) {
                                (*ppp->sc_xcomp->comp_reset)(ppp->sc_xc_state);
+                               if (ppp->flags & SC_DEBUG)
+                                       printk(KERN_DEBUG "%s: comp reset\n",
+                                              ppp->name);
+                       }
                } else {
                        if (ppp->sc_rc_state && (ppp->flags & SC_DECOMP_RUN)) {
                              (*ppp->sc_rcomp->decomp_reset)(ppp->sc_rc_state);
-                               ppp->flags &= ~SC_DC_ERROR;
+                             if (ppp->flags & SC_DEBUG)
+                                       printk(KERN_DEBUG "%s: decomp reset\n",
+                                              ppp->name);
+                             cli();
+                             ppp->flags &= ~SC_DC_ERROR;
                        }
                }
                break;
        }
+       restore_flags(flags);
 }
 
 static int
 rcv_proto_ccp (struct ppp *ppp, __u16 proto, __u8 *dp, int len)
 {
+       CHECK_PPP(0);
        ppp_proto_ccp (ppp, dp, len, 1);
        return rcv_proto_unknown (ppp, proto, dp, len);
 }
@@ -1486,199 +1816,26 @@ rcv_proto_lqr (struct ppp *ppp, __u16 proto, __u8 * data, int len)
        return rcv_proto_unknown (ppp, proto, data, len);
 }
 
-static void ppp_doframe_lower (struct ppp *ppp, __u8 *data, int count)
-{
-       __u16           proto = PPP_PROTOCOL (data);
-       ppp_proto_type  *proto_ptr;
-/*
- * Ignore empty frames
- */
-       if (count <= PPP_HDRLEN)
-               return;
-/*
- * Count the frame and print it
- */
-       ++ppp->stats.ppp_ipackets;
-       if (ppp->flags & SC_LOG_INPKT)
-               ppp_print_buffer ("receive frame", data, count);
-/*
- * Find the procedure to handle this protocol. The last one is marked
- * as a protocol 0 which is the 'catch-all' to feed it to the pppd daemon.
- */
-       proto_ptr = proto_list;
-       while (proto_ptr->proto != 0 && proto_ptr->proto != proto)
-               ++proto_ptr;
-/*
- * Update the appropriate statistic counter.
- */
-       if ((*proto_ptr->func) (ppp, proto,
-                               &data[PPP_HARD_HDR_LEN],
-                               count - PPP_HARD_HDR_LEN))
-               ppp->stats.ppp_ioctects += count;
-       else
-               ++ppp->stats.ppp_discards;
-}
-
-/* on entry, a received frame is in ppp->rbuf.bufr
-   check it and dispose as appropriate */
-
-static int
-ppp_doframe (struct ppp *ppp)
-{
-       __u8    *data = buf_base (ppp->rbuf);
-       int     count = ppp->rbuf->count;
-       int     addr, ctrl, proto;
-       int     new_count;
-       __u8 *new_data;
-/*
- * If there is a pending error from the receiver then log it and discard
- * the damaged frame.
- */
-       if (ppp->toss) {
-               if ((ppp->flags & SC_DEBUG) && count > 0)
-                       printk (KERN_DEBUG
-                               "ppp_toss: tossing frame, reason = %x\n",
-                               ppp->toss);
-               return 0;
-       }
-/*
- * An empty frame is ignored. This occurs if the FLAG sequence precedes and
- * follows each frame.
- */
-       if (count == 0)
-               return 1;
-/*
- * Generate an error if the frame is too small.
- */
-       if (count < PPP_HARD_HDR_LEN) {
-               if (ppp->flags & SC_DEBUG)
-                       printk (KERN_DEBUG
-                               "ppp: got runt ppp frame, %d chars\n", count);
-               ++ppp->estats.rx_length_errors;
-               return 0;
-       }
-/*
- * Verify the CRC of the frame and discard the CRC characters from the
- * end of the buffer.
- */
-       if (ppp->rbuf->fcs != PPP_GOODFCS) {
-               if (ppp->flags & SC_DEBUG) {
-                       printk (KERN_DEBUG
-                               "ppp: frame with bad fcs, length = %d\n",
-                               count);
-                       ppp_print_buffer("bad frame", data, count);
-               }
-               ++ppp->estats.rx_crc_errors;
-               return 0;
-       }
-       count -= 2;             /* ignore the fcs characters */
-/*
- * Ignore the leading ADDRESS and CONTROL fields in the frame.
- */
-       addr   = PPP_ALLSTATIONS;
-       ctrl   = PPP_UI;
-
-       if ((data[0] == PPP_ALLSTATIONS) && (data[1] == PPP_UI)) {
-               data  += 2;
-               count -= 2;
-       }
-/*
- * Obtain the protocol from the frame
- */
-       proto = (__u16) *data++;
-       if ((proto & 1) == 0) {
-               proto = (proto << 8) | (__u16) *data++;
-               --count;
-       }
-/*
- * Rewrite the header with the full information. This may encroach upon
- * the 'filler' area in the buffer header. This is the purpose for the
- * filler.
- */
-       *(--data) = proto;
-       *(--data) = proto >> 8;
-       *(--data) = ctrl;
-       *(--data) = addr;
-       count    += 3;
-/*
- * Process the active decompressor.
- */
-       if ((ppp->sc_rc_state != (void *) 0) &&
-           (ppp->flags & SC_DECOMP_RUN)     &&
-           ((ppp->flags & (SC_DC_FERROR | SC_DC_ERROR)) == 0)) {
-               if (proto == PPP_COMP) {
-/*
- * If the frame is compressed then decompress it.
- */
-                       new_data = kmalloc (ppp->mru + PPP_HDRLEN, GFP_ATOMIC);
-                       if (new_data == NULL) {
-                               if (ppp->flags & SC_DEBUG)
-                                       printk (KERN_ERR
-                                               "ppp_doframe: no memory\n");
-                               new_count = DECOMP_ERROR;
-                       } else {
-                               new_count = (*ppp->sc_rcomp->decompress)
-                                       (ppp->sc_rc_state, data, count,
-                                        new_data, ppp->mru + PPP_HDRLEN);
-                       }
-                       switch (new_count) {
-                       default:
-                               ppp_doframe_lower (ppp, new_data, new_count);
-                               kfree (new_data);
-                               return 1;
-
-                       case DECOMP_ERROR:
-                               ppp->flags |= SC_DC_ERROR;
-                               break;
-
-                       case DECOMP_FATALERROR:
-                               ppp->flags |= SC_DC_FERROR;
-                               if (ppp->flags & SC_DEBUG)
-                                       printk(KERN_ERR "ppp: fatal decomp error\n");
-                               break;
-                       }
-/*
- * Log the error condition and discard the frame.
- */
-                       if (new_data != 0)
-                               kfree (new_data);
-                       slhc_toss (ppp->slcomp);
-                       ++ppp->stats.ppp_ierrors;
-               } else {
-/*
- * The frame is not special. Pass it through the compressor without
- * actually compressing the data
- */
-                       (*ppp->sc_rcomp->incomp) (ppp->sc_rc_state,
-                                                 data, count);
-               }
-       }
-/*
- * Process the uncompressed frame.
- */
-       ppp_doframe_lower (ppp, data, count);
-       return 1;
-}
-
-/*************************************************************
- * LINE DISCIPLINE SUPPORT
- *    The following functions form support user programs
- *    which read and write data on a TTY with the PPP line
- *    discipline.  Reading is done from a circular queue,
- *    filled by the lower TTY levels.
- *************************************************************/
-
-/* read a PPP frame from the us_rbuff circular buffer,
-   waiting if necessary
-*/
-
-static int
-ppp_tty_read (struct tty_struct *tty, struct file *file, __u8 * buf,
-             unsigned int nr)
+/*************************************************************
+ * LINE DISCIPLINE SUPPORT
+ *    The following functions form support user programs
+ *    which read and write data on a TTY with the PPP line
+ *    discipline.  Reading is done from a circular queue,
+ *    filled by the lower TTY levels.
+ *************************************************************/
+
+/* read a PPP frame from the us_rbuff circular buffer,
+   waiting if necessary
+*/
+
+static int
+ppp_tty_read (struct tty_struct *tty, struct file *file, __u8 * buf,
+             unsigned int nr)
 {
        struct ppp *ppp = tty2ppp (tty);
        __u8 c;
-       int len, indx;
+       int len, ret;
+       int error;
 
 #define GETC(c)                                                \
 {                                                      \
@@ -1697,6 +1854,14 @@ ppp_tty_read (struct tty_struct *tty, struct file *file, __u8 * buf,
 
        CHECK_PPP (-ENXIO);
 
+/*
+ * Before we attempt to write the frame to the user, ensure that the
+ * user has access to the pages for the total buffer length.
+ */
+       error = verify_area (VERIFY_WRITE, buf, nr);
+       if (error != 0)
+               return (error);
+
 /*
  * Acquire the read lock.
  */
@@ -1706,11 +1871,12 @@ ppp_tty_read (struct tty_struct *tty, struct file *file, __u8 * buf,
                    || tty != ppp->tty)
                        return 0;
 
-               if (set_bit (0, &ppp->ubuf->locked) != 0) {
+               if (test_and_set_bit (0, &ppp->ubuf->locked) != 0) {
+#if 0
                        if (ppp->flags & SC_DEBUG)
                                printk (KERN_DEBUG
                                     "ppp_tty_read: sleeping(ubuf)\n");
-
+#endif
                        current->timeout = 0;
                        current->state   = TASK_INTERRUPTIBLE;
                        schedule ();
@@ -1719,13 +1885,7 @@ ppp_tty_read (struct tty_struct *tty, struct file *file, __u8 * buf,
                                return -EINTR;
                        continue;
                }
-/*
- * Before we attempt to write the frame to the user, ensure that the
- * user has access to the pages for the total buffer length.
- */
-               indx = verify_area (VERIFY_WRITE, buf, nr);
-               if (indx != 0)
-                       return (indx);
+
 /*
  * Fetch the length of the buffer from the first two bytes.
  */
@@ -1736,78 +1896,81 @@ ppp_tty_read (struct tty_struct *tty, struct file *file, __u8 * buf,
                        len = c << 8;
                        GETC (c);
                        len += c;
+                       if (len)
+                               break;
                }
+
 /*
  * If there is no length then wait for the data to arrive.
  */
-               if (len == 0) {
-                       /* no data */
-                       clear_bit (0, &ppp->ubuf->locked);
-                       if (file->f_flags & O_NONBLOCK)
-                               return -EAGAIN;
-                       current->timeout = 0;
-
-                       if (ppp->flags & SC_DEBUG)
-                               printk (KERN_DEBUG
-                                       "ppp_tty_read: sleeping(read_wait)\n");
+               /* no data */
+               clear_bit (0, &ppp->ubuf->locked);
+               if (file->f_flags & O_NONBLOCK)
+                       return -EAGAIN;
+               current->timeout = 0;
+#if 0
+               if (ppp->flags & SC_DEBUG)
+                       printk (KERN_DEBUG
+                               "ppp_tty_read: sleeping(read_wait)\n");
+#endif
+               interruptible_sleep_on (&ppp->read_wait);
+               if (current->signal & ~current->blocked)
+                       return -EINTR;
+       }
 
-                       interruptible_sleep_on (&ppp->read_wait);
-                       if (current->signal & ~current->blocked)
-                               return -EINTR;
-                       continue;
-               }
 /*
  * Ensure that the frame will fit within the caller's buffer. If not, then
  * discard the frame from the input buffer.
  */
-               if (len + 2 > nr) {
-                       /* Can't copy it, update us_rbuff_head */
+       if (len + 2 > nr) {
+               /* Can't copy it, update us_rbuff_head */
 
-                       if (ppp->flags & SC_DEBUG)
-                               printk (KERN_DEBUG
+               if (ppp->flags & SC_DEBUG)
+                       printk (KERN_DEBUG
                                "ppp: read of %u bytes too small for %d "
                                "frame\n", nr, len + 2);
-                       ppp->ubuf->tail += len;
-                       ppp->ubuf->tail &= ppp->ubuf->size;
-                       clear_bit (0, &ppp->ubuf->locked);
-                       ppp->stats.ppp_ierrors++;
-                       return -EOVERFLOW;
-               }
-/*
- * Before we attempt to write the frame to the user, ensure that the
- * page tables are proper.
- */
-               indx = verify_area (VERIFY_WRITE, buf, len + 2);
-               if (indx != 0) {
-                       ppp->ubuf->tail += len;
-                       ppp->ubuf->tail &= ppp->ubuf->size;
-                       clear_bit (0, &ppp->ubuf->locked);
-                       return (indx);
-               }
+               ppp->stats.ppp_ierrors++;
+               error = -EOVERFLOW;
+               goto out;
+       }
+
 /*
  * Fake the insertion of the ADDRESS and CONTROL information because these
  * were not saved in the buffer.
  */
-               put_user (PPP_ALLSTATIONS, buf++);
-               put_user (PPP_UI,          buf++);
+       PUT_USER (error, (u_char) PPP_ALLSTATIONS, buf);
+       if (error)
+               goto out;
+       ++buf;
+       PUT_USER (error, (u_char) PPP_UI, buf);
+       if (error)
+               goto out;
+       ++buf;
 
-               indx = len;
 /*
  * Copy the received data from the buffer to the caller's area.
  */
-               while (indx-- > 0) {
-                       GETC (c);
-                       put_user (c, buf);
-                       ++buf;
-               }
-
-               clear_bit (0, &ppp->ubuf->locked);
-               len += 2; /* Account for ADDRESS and CONTROL bytes */
-               if (ppp->flags & SC_DEBUG)
-                       printk (KERN_DEBUG
-                               "ppp_tty_read: passing %d bytes up\n", len);
-               return len;
+       ret = len + 2;  /* Account for ADDRESS and CONTROL bytes */
+       while (len-- > 0) {
+               GETC (c);
+               PUT_USER (error, c, buf);
+               if (error)
+                       goto out;
+               ++buf;
        }
+
+       clear_bit (0, &ppp->ubuf->locked);
+#if 0
+       if (ppp->flags & SC_DEBUG)
+               printk (KERN_DEBUG "ppp_tty_read: passing %d bytes up\n", ret);
+#endif
+       return ret;
+
+out:
+       ppp->ubuf->tail += len;
+       ppp->ubuf->tail &= ppp->ubuf->size;
+       clear_bit (0, &ppp->ubuf->locked);
+       return error;
 #undef GETC
 }
 
@@ -1855,6 +2018,8 @@ ppp_dev_xmit_lower (struct ppp *ppp, struct ppp_buffer *buf,
        int     address, control;
        int     proto;
 
+       CHECK_PPP_VOID();
+       CHECK_BUF_MAGIC(buf);
        ++ppp->stats.ppp_opackets;
        ppp->stats.ppp_ooctects += count;
 
@@ -1909,12 +2074,6 @@ ppp_dev_xmit_lower (struct ppp *ppp, struct ppp_buffer *buf,
  * Add the trailing flag character
  */
        ins_char (buf, PPP_FLAG);
-/*
- * Print the buffer
- */
-       if (ppp->flags & SC_LOG_FLUSH)
-               ppp_print_buffer ("ppp flush", buf_base (buf),
-                                 buf->count);
 /*
  * Send the block to the tty driver.
  */
@@ -1923,7 +2082,7 @@ ppp_dev_xmit_lower (struct ppp *ppp, struct ppp_buffer *buf,
 }
 
 /*
- * Send an frame to the remote with the proper bsd compression.
+ * Compress and send an frame to the peer.
  *
  * Return 0 if frame was queued for transmission.
  *       1 if frame must be re-queued for later driver support.
@@ -1937,6 +2096,9 @@ ppp_dev_xmit_frame (struct ppp *ppp, struct ppp_buffer *buf,
        int     address, control;
        __u8 *new_data;
        int     new_count;
+
+       CHECK_PPP(0);
+       CHECK_BUF_MAGIC(buf);
 /*
  * Print the buffer
  */
@@ -1956,7 +2118,7 @@ ppp_dev_xmit_frame (struct ppp *ppp, struct ppp_buffer *buf,
            (control == PPP_UI)                 &&
            (proto != PPP_LCP)                  &&
            (proto != PPP_CCP)) {
-               new_data = kmalloc (count, GFP_ATOMIC);
+               new_data = kmalloc (ppp->mtu, GFP_ATOMIC);
                if (new_data == NULL) {
                        if (ppp->flags & SC_DEBUG)
                                printk (KERN_ERR
@@ -1965,7 +2127,7 @@ ppp_dev_xmit_frame (struct ppp *ppp, struct ppp_buffer *buf,
                }
 
                new_count = (*ppp->sc_xcomp->compress)
-                   (ppp->sc_xc_state, data, new_data, count, count);
+                   (ppp->sc_xc_state, data, new_data, count, ppp->mtu);
 
                if (new_count > 0 && (ppp->flags & SC_CCP_UP)) {
                        ppp_dev_xmit_lower (ppp, buf, new_data, new_count, 0);
@@ -2010,8 +2172,8 @@ send_revise_frame (register struct ppp *ppp, __u8 *data, int len)
  */
        case PPP_CCP:
                ppp_proto_ccp (ppp,
-                              data + PPP_HARD_HDR_LEN,
-                              len  - PPP_HARD_HDR_LEN,
+                              data + PPP_HDRLEN,
+                              len  - PPP_HDRLEN,
                               0);
                break;
 
@@ -2033,7 +2195,8 @@ ppp_tty_write (struct tty_struct *tty, struct file *file, const __u8 * data,
 {
        struct ppp *ppp = tty2ppp (tty);
        __u8 *new_data;
-       int status;
+       int proto;
+
 /*
  * Verify the pointers.
  */
@@ -2065,14 +2228,23 @@ ppp_tty_write (struct tty_struct *tty, struct file *file, const __u8 * data,
                                "ppp_tty_write: no memory\n");
                return 0;
        }
+/*
+ * Retrieve the user's buffer
+ */
+       if (copy_from_user (new_data, data, count)) {
+               kfree (new_data);
+               return -EFAULT;
+       }
 /*
  * lock this PPP unit so we will be the only writer;
  * sleep if necessary
  */
        while (lock_buffer (ppp->tbuf) != 0) {
                current->timeout = 0;
+#if 0
                if (ppp->flags & SC_DEBUG)
                        printk (KERN_DEBUG "ppp_tty_write: sleeping\n");
+#endif
                interruptible_sleep_on (&ppp->write_wait);
 
                ppp = tty2ppp (tty);
@@ -2087,17 +2259,6 @@ ppp_tty_write (struct tty_struct *tty, struct file *file, const __u8 * data,
                        return -EINTR;
                }
        }
-/*
- * Ensure that the caller's buffer is valid.
- */
-       status = verify_area (VERIFY_READ, data, count);
-       if (status != 0) {
-               kfree (new_data);
-               ppp->tbuf->locked = 0;
-               return status;
-       }
-
-       memcpy_fromfs (new_data, data, count);
 /*
  * Change the LQR frame
  */
@@ -2105,7 +2266,19 @@ ppp_tty_write (struct tty_struct *tty, struct file *file, const __u8 * data,
 /*
  * Send the data
  */
-       ppp_dev_xmit_frame (ppp, ppp->tbuf, new_data, count);
+       if (proto == PPP_IP) {
+               /*
+                * IP frames can be sent by pppd when we're doing
+                * demand-dialling.  We send them via ppp_dev_xmit_ip
+                * to make sure that VJ compression happens properly.
+                */
+               ppp_dev_xmit_ip(ppp, ppp->tbuf, new_data + PPP_HDRLEN,
+                               count - PPP_HDRLEN);
+
+       } else {
+               ppp_dev_xmit_frame (ppp, ppp->tbuf, new_data, count);
+       }
+
        kfree (new_data);
        return (int) count;
 }
@@ -2123,29 +2296,41 @@ ppp_set_compression (struct ppp *ppp, struct ppp_option_data *odp)
        int nb;
        __u8 *ptr;
        __u8 ccp_option[CCP_MAX_OPTION_LENGTH];
+       unsigned long flags;
+
 /*
  * Fetch the compression parameters
  */
-       error = verify_area (VERIFY_READ, odp, sizeof (data));
-       if (error == 0) {
-               memcpy_fromfs (&data, odp, sizeof (data));
-               nb  = data.length;
-               ptr = data.ptr;
-               if ((__u32) nb >= (__u32)CCP_MAX_OPTION_LENGTH)
-                       nb = CCP_MAX_OPTION_LENGTH;
-       
-               error = verify_area (VERIFY_READ, ptr, nb);
-       }
+       COPY_FROM_USER (error,
+                       &data,
+                       odp,
+                       sizeof (data));
 
        if (error != 0)
                return error;
 
-       memcpy_fromfs (ccp_option, ptr, nb);
+       nb  = data.length;
+       ptr = data.ptr;
+       if ((__u32) nb >= (__u32)CCP_MAX_OPTION_LENGTH)
+               nb = CCP_MAX_OPTION_LENGTH;
+
+       COPY_FROM_USER (error,
+                       ccp_option,
+                       ptr,
+                       nb);
+
+       if (error != 0)
+               return error;
 
        if (ccp_option[1] < 2)  /* preliminary check on the length byte */
                return (-EINVAL);
 
-       cp = find_compressor ((int) (unsigned int) (__u8) ccp_option[0]);
+       save_flags(flags);
+       cli();
+       ppp->flags &= ~(SC_COMP_RUN | SC_DECOMP_RUN);
+       restore_flags(flags);
+
+       cp = find_compressor (ccp_option[0]);
        if (cp != (struct compressor *) 0) {
                /*
                 * Found a handler for the protocol - try to allocate
@@ -2161,11 +2346,14 @@ ppp_set_compression (struct ppp *ppp, struct ppp_option_data *odp)
 
                        if (ppp->sc_xc_state == NULL) {
                                if (ppp->flags & SC_DEBUG)
-                                       printk("ppp%ld: comp_alloc failed\n",
-                                              ppp2dev (ppp)->base_addr);
+                                       printk(KERN_DEBUG "%s: comp_alloc failed\n",
+                                              ppp->name);
                                error = -ENOBUFS;
+                       } else {
+                               if (ppp->flags & SC_DEBUG)
+                                       printk(KERN_DEBUG "%s: comp_alloc -> %p\n",
+                                              ppp->name, ppp->sc_xc_state);
                        }
-                       ppp->flags &= ~SC_COMP_RUN;
                } else {
                        if (ppp->sc_rc_state != NULL)
                                (*ppp->sc_rcomp->decomp_free)(ppp->sc_rc_state);
@@ -2173,18 +2361,21 @@ ppp_set_compression (struct ppp *ppp, struct ppp_option_data *odp)
                        ppp->sc_rc_state = cp->decomp_alloc(ccp_option, nb);
                        if (ppp->sc_rc_state == NULL) {
                                if (ppp->flags & SC_DEBUG)
-                                       printk("ppp%ld: decomp_alloc failed\n",
-                                              ppp2dev (ppp)->base_addr);
-                               error = ENOBUFS;
+                                       printk(KERN_DEBUG "%s: decomp_alloc failed\n",
+                                              ppp->name);
+                               error = -ENOBUFS;
+                       } else {
+                               if (ppp->flags & SC_DEBUG)
+                                       printk(KERN_DEBUG "%s: decomp_alloc -> %p\n",
+                                              ppp->name, ppp->sc_rc_state);
                        }
-                       ppp->flags &= ~SC_DECOMP_RUN;
                }
                return (error);
        }
 
        if (ppp->flags & SC_DEBUG)
-               printk(KERN_DEBUG "ppp%ld: no compressor for [%x %x %x], %x\n",
-                      ppp2dev (ppp)->base_addr, ccp_option[0], ccp_option[1],
+               printk(KERN_DEBUG "%s: no compressor for [%x %x %x], %x\n",
+                      ppp->name, ccp_option[0], ccp_option[1],
                       ccp_option[2], nb);
        return (-EINVAL);       /* no handler found */
 }
@@ -2220,52 +2411,45 @@ ppp_tty_ioctl (struct tty_struct *tty, struct file * file,
  */
        switch (param2) {
        case PPPIOCSMRU:
-               error = verify_area (VERIFY_READ, (void *) param3,
-                                    sizeof (temp_i));
-               if (error == 0) {
-                       temp_i = get_user ((int *) param3);
-                       if (ppp->flags & SC_DEBUG)
-                               printk (KERN_INFO
-                                "ppp_tty_ioctl: set mru to %x\n", temp_i);
+               GET_USER (error, temp_i, (int *) param3);
+               if (error != 0)
+                       break;
+               if (ppp->flags & SC_DEBUG)
+                       printk (KERN_INFO
+                               "ppp_tty_ioctl: set mru to %x\n", temp_i);
 
-                       if (ppp->mru != temp_i)
-                               ppp_changedmtu (ppp, ppp2dev (ppp)->mtu, temp_i);
-               }
+               if (ppp->mru != temp_i)
+                       ppp_changedmtu (ppp, ppp2dev (ppp)->mtu, temp_i);
                break;
 /*
  * Fetch the flags
  */
        case PPPIOCGFLAGS:
-               error = verify_area (VERIFY_WRITE, (void *) param3,
-                                    sizeof (temp_i));
-               if (error == 0) {
-                       temp_i = (ppp->flags & SC_MASK);
+               temp_i = (ppp->flags & SC_MASK);
 #ifndef CHECK_CHARACTERS /* Don't generate errors if we don't check chars. */
-                       temp_i |= SC_RCV_B7_1 | SC_RCV_B7_0 |
-                                 SC_RCV_ODDP | SC_RCV_EVNP;
+               temp_i |= SC_RCV_B7_1 | SC_RCV_B7_0 |
+                         SC_RCV_ODDP | SC_RCV_EVNP;
 #endif
-                       put_user (temp_i, (int *) param3);
-               }
+               PUT_USER (error, temp_i, (int *) param3);
                break;
 /*
  * Set the flags for the various options
  */
        case PPPIOCSFLAGS:
-               error = verify_area (VERIFY_READ, (void *) param3,
-                                    sizeof (temp_i));
-               if (error == 0) {
-                       temp_i  = get_user ((int *) param3) & SC_MASK;
-                       temp_i |= (ppp->flags & ~SC_MASK);
-
-                       if ((ppp->flags & SC_CCP_OPEN) &&
-                           (temp_i & SC_CCP_OPEN) == 0)
-                               ppp_ccp_closed (ppp);
-
-                       if ((ppp->flags | temp_i) & SC_DEBUG)
-                               printk (KERN_INFO
-                              "ppp_tty_ioctl: set flags to %x\n", temp_i);
-                       ppp->flags = temp_i;
-               }
+               GET_USER (error, temp_i, (int *) param3);
+               if (error != 0)
+                       break;
+               temp_i &= SC_MASK;
+               temp_i |= (ppp->flags & ~SC_MASK);
+
+               if ((ppp->flags & SC_CCP_OPEN) &&
+                   (temp_i & SC_CCP_OPEN) == 0)
+                       ppp_ccp_closed (ppp);
+
+               if ((ppp->flags | temp_i) & SC_DEBUG)
+                       printk (KERN_INFO
+                               "ppp_tty_ioctl: set flags to %x\n", temp_i);
+               ppp->flags = temp_i;
                break;
 /*
  * Set the compression mode
@@ -2278,122 +2462,108 @@ ppp_tty_ioctl (struct tty_struct *tty, struct file * file,
  * Retrieve the transmit async map
  */
        case PPPIOCGASYNCMAP:
-               error = verify_area (VERIFY_WRITE, (void *) param3,
-                                    sizeof (temp_i));
-               if (error == 0) {
-                       put_user (ppp->xmit_async_map[0], (int *) param3);
-               }
+               PUT_USER (error, ppp->xmit_async_map[0], (int *) param3);
                break;
 /*
  * Set the transmit async map
  */
        case PPPIOCSASYNCMAP:
-               error = verify_area (VERIFY_READ, (void *) param3,
-                                    sizeof (temp_i));
-               if (error == 0) {
-                       ppp->xmit_async_map[0] = get_user ((int *) param3);
-                       if (ppp->flags & SC_DEBUG)
-                               printk (KERN_INFO
-                                    "ppp_tty_ioctl: set xmit asyncmap %x\n",
-                                    ppp->xmit_async_map[0]);
-               }
+               GET_USER (error, temp_i, (int *) param3);
+               if (error != 0)
+                       break;
+               ppp->xmit_async_map[0] = temp_i;
+               if (ppp->flags & SC_DEBUG)
+                       printk (KERN_INFO
+                               "ppp_tty_ioctl: set xmit asyncmap %x\n",
+                               ppp->xmit_async_map[0]);
                break;
 /*
  * Set the receive async map
  */
        case PPPIOCSRASYNCMAP:
-               error = verify_area (VERIFY_READ, (void *) param3,
-                                    sizeof (temp_i));
-               if (error == 0) {
-                       ppp->recv_async_map = get_user ((int *) param3);
-                       if (ppp->flags & SC_DEBUG)
-                               printk (KERN_INFO
-                                    "ppp_tty_ioctl: set rcv asyncmap %x\n",
-                                    ppp->recv_async_map);
-               }
+               GET_USER (error, temp_i, (int *) param3);
+               if (error != 0)
+                       break;
+               ppp->recv_async_map = temp_i;
+               if (ppp->flags & SC_DEBUG)
+                       printk (KERN_INFO
+                               "ppp_tty_ioctl: set rcv asyncmap %x\n",
+                               ppp->recv_async_map);
                break;
 /*
  * Obtain the unit number for this device.
  */
        case PPPIOCGUNIT:
-               error = verify_area (VERIFY_WRITE, (void *) param3,
-                                    sizeof (temp_i));
-               if (error == 0) {
-                       put_user (ppp2dev (ppp)->base_addr, (int *) param3);
-                       if (ppp->flags & SC_DEBUG)
-                               printk (KERN_INFO
-                                       "ppp_tty_ioctl: get unit: %ld\n",
-                                       ppp2dev (ppp)->base_addr);
-               }
+               PUT_USER (error, ppp2dev (ppp)->base_addr, (int *) param3);
+               if (error != 0)
+                       break;
+               if (ppp->flags & SC_DEBUG)
+                       printk (KERN_INFO
+                               "ppp_tty_ioctl: get unit: %ld\n",
+                               ppp2dev (ppp)->base_addr);
                break;
 /*
  * Set the debug level
  */
        case PPPIOCSDEBUG:
-               error = verify_area (VERIFY_READ, (void *) param3,
-                                    sizeof (temp_i));
-               if (error == 0) {
-                       temp_i  = (get_user ((int *) param3) & 0x1F) << 16;
-                       temp_i |= (ppp->flags & ~0x1F0000);
-
-                       if ((ppp->flags | temp_i) & SC_DEBUG)
-                               printk (KERN_INFO
-                              "ppp_tty_ioctl: set flags to %x\n", temp_i);
-                       ppp->flags = temp_i;
-               }
+               GET_USER (error, temp_i, (int *) param3);
+               if (error != 0)
+                       break;
+               temp_i  = (temp_i & 0x1F) << 16;
+               temp_i |= (ppp->flags & ~0x1F0000);
+
+               if ((ppp->flags | temp_i) & SC_DEBUG)
+                       printk (KERN_INFO
+                               "ppp_tty_ioctl: set flags to %x\n", temp_i);
+               ppp->flags = temp_i;
                break;
 /*
  * Get the debug level
  */
        case PPPIOCGDEBUG:
-               error = verify_area (VERIFY_WRITE, (void *) param3,
-                                    sizeof (temp_i));
-               if (error == 0) {
-                       temp_i = (ppp->flags >> 16) & 0x1F;
-                       put_user (temp_i, (int *) param3);
-               }
+               temp_i = (ppp->flags >> 16) & 0x1F;
+               PUT_USER (error, temp_i, (int *) param3);
                break;
 /*
  * Get the times since the last send/receive frame operation
  */
        case PPPIOCGIDLE:
-               error = verify_area (VERIFY_WRITE, (void *) param3,
-                                    sizeof (struct ppp_idle));
-               if (error == 0) {
+               {
                        struct ppp_idle cur_ddinfo;
                        __u32 cur_jiffies = jiffies;
 
                        /* change absolute times to relative times. */
                        cur_ddinfo.xmit_idle = (cur_jiffies - ppp->ddinfo.xmit_idle) / HZ;
                        cur_ddinfo.recv_idle = (cur_jiffies - ppp->ddinfo.recv_idle) / HZ;
-                       memcpy_tofs ((void *) param3, &cur_ddinfo,
-                                    sizeof (cur_ddinfo));
+                       COPY_TO_USER (error,
+                                     (void *) param3,
+                                     &cur_ddinfo,
+                                     sizeof (cur_ddinfo));
                }
                break;
 /*
  * Retrieve the extended async map
  */
        case PPPIOCGXASYNCMAP:
-               error = verify_area (VERIFY_WRITE,
-                                    (void *) param3,
-                                    sizeof (ppp->xmit_async_map));
-               if (error == 0) {
-                       memcpy_tofs ((void *) param3,
-                                    ppp->xmit_async_map,
-                                    sizeof (ppp->xmit_async_map));
-               }
+               COPY_TO_USER (error,
+                             (void *) param3,
+                             ppp->xmit_async_map,
+                             sizeof (ppp->xmit_async_map));
                break;
 /*
  * Set the async extended map
  */
        case PPPIOCSXASYNCMAP:
-               error = verify_area (VERIFY_READ, (void *) param3,
-                                    sizeof (ppp->xmit_async_map));
-               if (error == 0) {
+               {
                        __u32 temp_tbl[8];
 
-                       memcpy_fromfs (temp_tbl, (void *) param3,
-                                      sizeof (ppp->xmit_async_map));
+                       COPY_FROM_USER (error,
+                                       temp_tbl,
+                                       (void *) param3,
+                                       sizeof (temp_tbl));
+
+                       if (error != 0)
+                               break;
                        temp_tbl[1]  =  0x00000000;
                        temp_tbl[2] &= ~0x40000000;
                        temp_tbl[3] |=  0x60000000;
@@ -2403,12 +2573,13 @@ ppp_tty_ioctl (struct tty_struct *tty, struct file * file,
                            (temp_tbl[6] & temp_tbl[7]) != 0)
                                error = -EINVAL;
                        else {
-                               memcpy (ppp->xmit_async_map, temp_tbl,
+                               memcpy (ppp->xmit_async_map,
+                                       temp_tbl,
                                        sizeof (ppp->xmit_async_map));
 
                                if (ppp->flags & SC_DEBUG)
                                        printk (KERN_INFO
-                                       "ppp_tty_ioctl: set xasyncmap\n");
+                                               "ppp_tty_ioctl: set xasyncmap\n");
                        }
                }
                break;
@@ -2416,25 +2587,24 @@ ppp_tty_ioctl (struct tty_struct *tty, struct file * file,
  * Set the maximum VJ header compression slot number.
  */
        case PPPIOCSMAXCID:
-               error = verify_area (VERIFY_READ, (void *) param3,
-                                    sizeof (temp_i));
-               if (error == 0) {
-                       temp_i = get_user ((int *) param3) + 1;
+               GET_USER (error, temp_i, (int *) param3);
+               if (error != 0)
+                       break;
+               temp_i = (temp_i & 255) + 1;
+               if (ppp->flags & SC_DEBUG)
+                       printk (KERN_INFO
+                               "ppp_tty_ioctl: set maxcid to %d\n",
+                               temp_i);
+               if (ppp->slcomp != NULL)
+                       slhc_free (ppp->slcomp);
+               ppp->slcomp = slhc_init (16, temp_i);
+
+               if (ppp->slcomp == NULL) {
                        if (ppp->flags & SC_DEBUG)
-                               printk (KERN_INFO
-                                    "ppp_tty_ioctl: set maxcid to %d\n",
-                                    temp_i);
-                       if (ppp->slcomp != NULL)
-                               slhc_free (ppp->slcomp);
-                       ppp->slcomp = slhc_init (16, temp_i);
-
-                       if (ppp->slcomp == NULL) {
-                               if (ppp->flags & SC_DEBUG)
-                                       printk (KERN_ERR
+                               printk (KERN_ERR
                                        "ppp: no space for compression buffers!\n");
-                               ppp_release (ppp);
-                               error = -ENOMEM;
-                       }
+                       ppp_release (ppp);
+                       error = -ENOMEM;
                }
                break;
 
@@ -2445,13 +2615,15 @@ ppp_tty_ioctl (struct tty_struct *tty, struct file * file,
 
     case PPPIOCGNPMODE:
     case PPPIOCSNPMODE:
-               error = verify_area (VERIFY_READ, (void *) param3,
-                                    sizeof (struct npioctl));
-               if (error == 0) {
+               {
                        struct npioctl npi;
-                       memcpy_fromfs (&npi,
-                                      (void *) param3,
-                                      sizeof (npi));
+
+                       COPY_FROM_USER (error,
+                                       &npi,
+                                       (void *) param3,
+                                       sizeof (npi));
+                       if (error != 0)
+                               break;
 
                        switch (npi.protocol) {
                        case PPP_IP:
@@ -2469,25 +2641,18 @@ ppp_tty_ioctl (struct tty_struct *tty, struct file * file,
 
                        if (param2 == PPPIOCGNPMODE) {
                                npi.mode = ppp->sc_npmode[npi.protocol];
-                               error = verify_area (VERIFY_WRITE,
-                                                    (void *) param3,
-                                                    sizeof (npi));
-                               if (error != 0)
-                                       break;
 
-                               memcpy_tofs ((void *) param3,
-                                            &npi,
-                                            sizeof (npi));
+                               COPY_TO_USER (error,
+                                             (void *) param3,
+                                             &npi,
+                                             sizeof (npi));
                                break;
                        }
 
-                       if (npi.mode != ppp->sc_npmode[npi.protocol]) {
-                               ppp->sc_npmode[npi.protocol] = npi.mode;
-                               if (npi.mode != NPMODE_QUEUE) {
-                                       /* ppp_requeue(ppp); maybe needed */
-                                       ppp_tty_wakeup (ppp2tty(ppp));
-                               }
-                       }
+                       ppp->sc_npmode[npi.protocol] = npi.mode;
+                       if (ppp->flags & SC_DEBUG)
+                               printk(KERN_DEBUG "ppp: set np %d to %d\n",
+                                      npi.protocol, npi.mode);
                }
                break;
 /*
@@ -2499,15 +2664,11 @@ ppp_tty_ioctl (struct tty_struct *tty, struct file * file,
                break;
 
        case FIONREAD:
-               error = verify_area (VERIFY_WRITE,
-                                    (void *) param3,
-                                    sizeof (int));
-               if (error == 0) {
+               {
                        int count = ppp->ubuf->tail - ppp->ubuf->head;
                        if (count < 0)
                                count += (ppp->ubuf->size + 1);
-
-                       put_user (count, (int *) param3);
+                       PUT_USER (error, count, (int *) param3);
                }
                break;
 /*
@@ -2529,9 +2690,10 @@ ppp_tty_ioctl (struct tty_struct *tty, struct file * file,
 /*
  * TTY callback.
  *
- * Process the select() statement for the PPP device.
+ * Process the select() (or poll()) statement for the PPP device.
  */
 
+#if LINUX_VERSION_CODE < VERSION(2,1,23)
 static int
 ppp_tty_select (struct tty_struct *tty, struct inode *inode,
                struct file *filp, int sel_type, select_table * wait)
@@ -2554,7 +2716,7 @@ ppp_tty_select (struct tty_struct *tty, struct inode *inode,
  */
        switch (sel_type) {
        case SEL_IN:
-               if (set_bit (0, &ppp->ubuf->locked) == 0) {
+               if (test_and_set_bit (0, &ppp->ubuf->locked) == 0) {
                        /* Test for the presence of data in the queue */
                        if (ppp->ubuf->head != ppp->ubuf->tail) {
                                clear_bit (0, &ppp->ubuf->locked);
@@ -2590,6 +2752,38 @@ ppp_tty_select (struct tty_struct *tty, struct inode *inode,
        return result;
 }
 
+#else  /* 2.1.23 or later */
+
+static unsigned int
+ppp_tty_poll (struct tty_struct *tty, struct file *filp, poll_table * wait)
+{
+       struct ppp *ppp = tty2ppp (tty);
+       unsigned int mask = 0;
+
+       if (ppp && ppp->magic == PPP_MAGIC && tty == ppp->tty) {
+               CHECK_PPP (0);
+
+               poll_wait(&ppp->read_wait, wait);
+               poll_wait(&ppp->write_wait, wait);
+
+               /* Must lock the user buffer area while checking. */
+               if(test_and_set_bit(0, &ppp->ubuf->locked) == 0) {
+                       if(ppp->ubuf->head != ppp->ubuf->tail)
+                               mask |= POLLIN | POLLRDNORM;
+                       clear_bit(0, &ppp->ubuf->locked);
+               }
+               if(tty->flags & (1 << TTY_OTHER_CLOSED))
+                       mask |= POLLHUP;
+               if(tty_hung_up_p(filp))
+                       mask |= POLLHUP;
+               if(ppp->tbuf->locked == 0)
+                       mask |= POLLOUT | POLLWRNORM;
+       }
+       return mask;
+}
+
+#endif
+
 /*************************************************************
  * NETWORK OUTPUT
  *    This routine accepts requests from the network layer
@@ -2608,7 +2802,7 @@ ppp_dev_open (struct device *dev)
        struct ppp *ppp = dev2ppp (dev);
 
        /* reset POINTOPOINT every time, since dev_close zaps it! */
-       dev->flags |= IFF_POINTOPOINT;
+       dev->flags |= IFF_POINTOPOINT | IFF_NOARP | IFF_MULTICAST;
 
        if (ppp2tty (ppp) == NULL) {
                if (ppp->flags & SC_DEBUG)
@@ -2659,19 +2853,15 @@ static int
 ppp_dev_ioctl_version (struct ppp *ppp, struct ifreq *ifr)
 {
        int error;
-       int len;
-       char *result;
-/*
- * Must have write access to the buffer.
- */
-       result = (char *) ifr->ifr_ifru.ifru_data;
-       len    = strlen (szVersion) + 1;
-       error  = verify_area (VERIFY_WRITE, result, len);
+       char *result  = (char *) ifr->ifr_ifru.ifru_data;
+       int  len      = strlen (szVersion) + 1;
 /*
  * Move the version data
  */
-       if (error == 0)
-               memcpy_tofs (result, szVersion, len);
+       COPY_TO_USER (error,
+                     result,
+                     szVersion,
+                     len);
 
        return error;
 }
@@ -2685,19 +2875,12 @@ ppp_dev_ioctl_stats (struct ppp *ppp, struct ifreq *ifr, struct device *dev)
 {
        struct ppp_stats *result, temp;
        int    error;
-/*
- * Must have write access to the buffer.
- */
-       result = (struct ppp_stats *) ifr->ifr_ifru.ifru_data;
-       error = verify_area (VERIFY_WRITE,
-                            result,
-                            sizeof (temp));
 /*
  * Supply the information for the caller. First move the version data
  * then move the ppp stats; and finally the vj stats.
  */
        memset (&temp, 0, sizeof(temp));
-       if (error == 0 && dev->flags & IFF_UP) {
+       if (dev->flags & IFF_UP) {
                memcpy (&temp.p, &ppp->stats, sizeof (struct pppstat));
                if (ppp->slcomp != NULL) {
                        temp.vj.vjs_packets    = ppp->slcomp->sls_o_compressed+
@@ -2712,8 +2895,13 @@ ppp_dev_ioctl_stats (struct ppp *ppp, struct ifreq *ifr, struct device *dev)
                }
        }
 
-       if (error == 0)
-               memcpy_tofs (result, &temp, sizeof (temp));
+       result = (struct ppp_stats *) ifr->ifr_ifru.ifru_data;
+
+       COPY_TO_USER (error,
+                     result,
+                     &temp,
+                     sizeof (temp));
+
        return error;
 }
 
@@ -2726,18 +2914,11 @@ ppp_dev_ioctl_comp_stats (struct ppp *ppp, struct ifreq *ifr, struct device *dev
 {
        struct ppp_comp_stats *result, temp;
        int    error;
-/*
- * Must have write access to the buffer.
- */
-       result = (struct ppp_comp_stats *) ifr->ifr_ifru.ifru_data;
-       error = verify_area (VERIFY_WRITE,
-                            result,
-                            sizeof (temp));
 /*
  * Supply the information for the caller.
  */
        memset (&temp, 0, sizeof(temp));
-       if (error == 0 && dev->flags & IFF_UP) {
+       if (dev->flags & IFF_UP) {
                if (ppp->sc_xc_state != NULL)
                        (*ppp->sc_xcomp->comp_stat) (ppp->sc_xc_state,
                                                     &temp.c);
@@ -2749,8 +2930,13 @@ ppp_dev_ioctl_comp_stats (struct ppp *ppp, struct ifreq *ifr, struct device *dev
 /*
  * Move the data to the caller's buffer
  */
-       if (error == 0)
-               memcpy_tofs (result, &temp, sizeof (temp));
+       result = (struct ppp_comp_stats *) ifr->ifr_ifru.ifru_data;
+
+       COPY_TO_USER (error,
+                     result,
+                     &temp,
+                     sizeof (temp));
+
        return error;
 }
 
@@ -2763,6 +2949,8 @@ ppp_dev_ioctl (struct device *dev, struct ifreq *ifr, int cmd)
 {
        struct ppp *ppp = dev2ppp (dev);
        int error;
+
+       CHECK_PPP_MAGIC(ppp);
 /*
  * Process the requests
  */
@@ -2791,41 +2979,15 @@ ppp_dev_ioctl (struct device *dev, struct ifreq *ifr, int cmd)
  *
  * Return 0 if frame was queued for transmission.
  *       1 if frame must be re-queued for later driver support.
+ *       -1 if frame should be dropped.
  */
 
 static int
-ppp_dev_xmit_ip (struct device *dev, struct ppp *ppp, __u8 *data)
+ppp_dev_xmit_ip (struct ppp *ppp, struct ppp_buffer *buf,
+                __u8 *data, int len)
 {
-       int               proto = PPP_IP;
-       int               len;
-       struct ppp_hdr    *hdr;
-       struct tty_struct *tty = ppp2tty (ppp);
-/*
- * Obtain the length from the IP header.
- */
-       len = ((struct iphdr *)data) -> tot_len;
-       len = ntohs (len);
-/*
- * Validate the tty interface
- */
-       if (tty == NULL) {
-               if (ppp->flags & SC_DEBUG)
-                       printk (KERN_ERR
-                               "ppp_dev_xmit: %s not connected to a TTY!\n",
-                               dev->name);
-               return 0;
-       }
-/*
- * Ensure that the PPP device is still up
- */
-       if (!(dev->flags & IFF_UP)) {
-               if (ppp->flags & SC_DEBUG)
-                       printk (KERN_WARNING
-                               "ppp_dev_xmit: packet sent on interface %s,"
-                               " which is down for IP\n",
-                               dev->name);
-               return 0;
-       }
+       int     proto = PPP_IP;
+       __u8    *hdr;
 /*
  * Branch on the type of processing for the IP frame.
  */
@@ -2833,46 +2995,32 @@ ppp_dev_xmit_ip (struct device *dev, struct ppp *ppp, __u8 *data)
        case NPMODE_PASS:
                break;
 
+       case NPMODE_QUEUE:
+               /*
+                * We may not send the packet now, so drop it.
+                * XXX It would be nice to be able to return it to the
+                * network system to be queued and retransmitted later.
+                */
+               if (ppp->flags & SC_DEBUG)
+                       printk(KERN_DEBUG "%s: returning frame\n",
+                              ppp->name);
+               return -1;
+
        case NPMODE_ERROR:
        case NPMODE_DROP:
                if (ppp->flags & SC_DEBUG)
                        printk (KERN_DEBUG
                                "ppp_dev_xmit: npmode = %d on %s\n",
-                               ppp->sc_npmode[NP_IP], dev->name);
-               return 0;
-
-       case NPMODE_QUEUE:
-               break;
+                               ppp->sc_npmode[NP_IP], ppp->name);
+               return -1;
 
        default:
                if (ppp->flags & SC_DEBUG)
                        printk (KERN_WARNING
                                "ppp_dev_xmit: unknown npmode %d on %s\n",
-                               ppp->sc_npmode[NP_IP],
-                               dev->name);
-               return 0;
-       }
-/*
- * Detect a change in the transfer size
- */
-       if (ppp->mtu != ppp2dev (ppp)->mtu) {
-               ppp_changedmtu (ppp,
-                               ppp2dev (ppp)->mtu,
-                               ppp->mru);
+                               ppp->sc_npmode[NP_IP], ppp->name);
+               return -1;
        }
-/*
- * Acquire the lock on the transmission buffer. If the buffer was busy then
- * mark the device as busy.
- */
-       if (lock_buffer (ppp->wbuf) != 0) {
-               dev->tbusy = 1;
-               return 1;
-       }
-/*
- * Print the frame being sent
- */
-       if (ppp->flags & SC_LOG_OUTPKT)
-               ppp_print_buffer ("ppp outpkt", data, len);
 /*
  * At this point, the buffer will be transmitted. There is no other exit.
  *
@@ -2880,7 +3028,7 @@ ppp_dev_xmit_ip (struct device *dev, struct ppp *ppp, __u8 *data)
  */
        if (ppp->flags & SC_COMP_TCP) {
                len = slhc_compress (ppp->slcomp, data, len,
-                                    buf_base (ppp->cbuf) + PPP_HARD_HDR_LEN,
+                                    buf_base (ppp->cbuf) + PPP_HDRLEN,
                                     &data,
                                     (ppp->flags & SC_NO_TCP_CCID) == 0);
 
@@ -2896,83 +3044,40 @@ ppp_dev_xmit_ip (struct device *dev, struct ppp *ppp, __u8 *data)
 /*
  * Send the frame
  */
-       len  += PPP_HARD_HDR_LEN;
-       hdr   = &((struct ppp_hdr *) data)[-1];
+       len  += PPP_HDRLEN;
+       hdr   = data - PPP_HDRLEN;
 
-       hdr->address     = PPP_ALLSTATIONS;
-       hdr->control     = PPP_UI;
-       hdr->protocol[0] = 0;
-       hdr->protocol[1] = proto;
+       hdr[0] = PPP_ALLSTATIONS;
+       hdr[1] = PPP_UI;
+       hdr[2] = 0;
+       hdr[3] = proto;
 
-       return ppp_dev_xmit_frame (ppp, ppp->wbuf, (__u8 *) hdr, len);
+       return ppp_dev_xmit_frame (ppp, ppp->wbuf, hdr, len);
 }
 
 /*
- * Send an IPX (or any other non-IP) frame to the remote.
+ * Send a non-IP data frame (such as an IPX frame) to the remote.
  *
  * Return 0 if frame was queued for transmission.
  *       1 if frame must be re-queued for later driver support.
  */
 static int
-ppp_dev_xmit_ipx (struct device *dev, struct ppp *ppp,
+ppp_dev_xmit_other (struct device *dev, struct ppp *ppp,
                  __u8 *data, int len, int proto)
 {
-       struct tty_struct *tty = ppp2tty (ppp);
-       struct ppp_hdr    *hdr;
-/*
- * Validate the tty interface
- */
-       if (tty == NULL) {
-               if (ppp->flags & SC_DEBUG)
-                       printk (KERN_ERR
-                               "ppp_dev_xmit: %s not connected to a TTY!\n",
-                               dev->name);
-               return 0;
-       }
-/*
- * Ensure that the PPP device is still up
- */
-       if (!(dev->flags & IFF_UP)) {
-               if (ppp->flags & SC_DEBUG)
-                       printk (KERN_WARNING
-                               "ppp_dev_xmit: packet sent on interface %s,"
-                               " which is down\n",
-                               dev->name);
-               return 0;
-       }
-/*
- * Detect a change in the transfer size
- */
-       if (ppp->mtu != ppp2dev (ppp)->mtu) {
-               ppp_changedmtu (ppp,
-                               ppp2dev (ppp)->mtu,
-                               ppp->mru);
-       }
-/*
- * Acquire the lock on the transmission buffer. If the buffer was busy then
- * mark the device as busy.
- */
-       if (lock_buffer (ppp->wbuf) != 0) {
-               dev->tbusy = 1;
-               return 1;
-       }
-/*
- * Print the frame being sent
- */
-       if (ppp->flags & SC_LOG_OUTPKT)
-               ppp_print_buffer ("ppp outpkt", data, len);
+       __u8    *hdr;
 /*
  * Send the frame
  */
-       len  += PPP_HARD_HDR_LEN;
-       hdr   = &((struct ppp_hdr *) data)[-1];
+       len += PPP_HDRLEN;
+       hdr = data - PPP_HDRLEN;
 
-       hdr->address     = PPP_ALLSTATIONS;
-       hdr->control     = PPP_UI;
-       hdr->protocol[0] = proto >> 8;
-       hdr->protocol[1] = proto;
+       hdr[0] = PPP_ALLSTATIONS;
+       hdr[1] = PPP_UI;
+       hdr[2] = proto >> 8;
+       hdr[3] = proto;
 
-       return ppp_dev_xmit_frame (ppp, ppp->wbuf, (__u8 *) hdr, len);
+       return ppp_dev_xmit_frame (ppp, ppp->wbuf, hdr, len);
 }
 
 /*
@@ -2999,7 +3104,6 @@ ppp_dev_xmit (sk_buff *skb, struct device *dev)
  */
        if (!ppp->inuse) {
                dev_kfree_skb (skb, FREE_WRITE);
-               dev_close (dev);
                return 0;
        }
 /*
@@ -3018,17 +3122,48 @@ ppp_dev_xmit (sk_buff *skb, struct device *dev)
  */
        len   = skb->len;
        data  = skb_data(skb);
+
+       if (data == (__u8 *) 0) {
+               if (ppp->flags & SC_DEBUG)
+                       printk (KERN_CRIT "ppp_dev_xmit: %s Null skb data\n",
+                               dev->name);
+               dev_kfree_skb (skb, FREE_WRITE);
+               return 0;
+       }
+/*
+ * Detect a change in the transfer size
+ */
+       if (ppp->mtu != ppp2dev (ppp)->mtu) {
+               ppp_changedmtu (ppp,
+                               ppp2dev (ppp)->mtu,
+                               ppp->mru);
+       }
+/*
+ * Acquire the lock on the transmission buffer. If the buffer was busy then
+ * mark the device as busy.
+ * We also require that ppp->tbuf be unlocked, in order to serialize
+ * calls to ppp_dev_xmit_frame (which does compression) and the output
+ * of frames w.r.t. tty writes from pppd.
+ */
+       CHECK_BUF_MAGIC(ppp->wbuf);
+       if (ppp->tbuf->locked || lock_buffer (ppp->wbuf) != 0) {
+               dev->tbusy = 1;
+               if (ppp->flags & SC_DEBUG)
+                       printk(KERN_DEBUG "dev_xmit blocked, t=%d w=%d\n",
+                              ppp->tbuf->locked, ppp->wbuf->locked);
+               return 1;
+       }
 /*
  * Look at the protocol in the skb to determine the difference between
  * an IP frame and an IPX frame.
  */
        switch (ntohs (skb->protocol)) {
        case ETH_P_IPX:
-               answer = ppp_dev_xmit_ipx (dev, ppp, data, len, PPP_IPX);
+               answer = ppp_dev_xmit_other (dev, ppp, data, len, PPP_IPX);
                break;
 
        case ETH_P_IP:
-               answer = ppp_dev_xmit_ip (dev, ppp, data);
+               answer = ppp_dev_xmit_ip (ppp, ppp->wbuf, data, len);
                break;
 
        default: /* All others have no support at this time. */
@@ -3039,8 +3174,19 @@ ppp_dev_xmit (sk_buff *skb, struct device *dev)
  * This is the end of the transmission. Release the buffer if it was sent.
  */
        if (answer == 0) {
+               /* packet queued OK */
                dev_kfree_skb (skb, FREE_WRITE);
                ppp->ddinfo.xmit_idle = jiffies;
+       } else {
+               ppp->wbuf->locked = 0;
+               if (answer < 0) {
+                       /* packet should be dropped */
+                       dev_kfree_skb (skb, FREE_WRITE);
+                       answer = 0;
+               } else {
+                       /* packet should be queued for later */
+                       dev->tbusy = 1;
+               }
        }
        return answer;
 }
@@ -3062,6 +3208,7 @@ ppp_dev_stats (struct device *dev)
        return &ppp->estats;
 }
 
+#if LINUX_VERSION_CODE < VERSION(2,1,15)
 static int ppp_dev_header (sk_buff *skb, struct device *dev,
                           __u16 type, void *daddr,
                           void *saddr, unsigned int len)
@@ -3071,10 +3218,11 @@ static int ppp_dev_header (sk_buff *skb, struct device *dev,
 
 static int
 ppp_dev_rebuild (void *eth, struct device *dev,
-                 unsigned long raddr, struct sk_buff *skb)
+                unsigned long raddr, struct sk_buff *skb)
 {
        return (0);
 }
+#endif
 
 /*************************************************************
  * UTILITIES
@@ -3085,26 +3233,16 @@ ppp_dev_rebuild (void *eth, struct device *dev,
 static struct ppp *
 ppp_find (int pid_value)
 {
-       int             if_num;
-       ppp_ctrl_t      *ctl;
        struct ppp      *ppp;
 
-       /* try to find the exact same free device which we had before */
-       ctl      = ppp_list;
-       if_num   = 0;
-
-       while (ctl) {
-               ppp = ctl2ppp (ctl);
-               if (ppp->sc_xfer == pid_value) {
-                       set_bit(0, &ppp->inuse);
+       /* try to find the device which this pid is already using */
+       for (ppp = ppp_list; ppp != 0; ppp = ppp->next) {
+               if (ppp->inuse && ppp->sc_xfer == pid_value) {
                        ppp->sc_xfer = 0;
-                       return (ppp);
-               }
-               ctl = ctl->next;
-               if (++if_num == max_dev)
                        break;
+               }
        }
-       return NULL;
+       return ppp;
 }
 
 /* allocate or create a PPP channel */
@@ -3113,66 +3251,58 @@ ppp_alloc (void)
 {
        int             if_num;
        int             status;
-       ppp_ctrl_t      *ctl;
        struct device   *dev;
        struct ppp      *ppp;
 
        /* try to find an free device */
-       ctl      = ppp_list;
-       if_num   = 0;
-  
-       while (ctl) {
-               ppp = ctl2ppp (ctl);
+       if_num = 0;
+       for (ppp = ppp_list; ppp != 0; ppp = ppp->next) {
                if (!set_bit(0, &ppp->inuse))
-                       return (ppp);
-               ctl = ctl->next;
-               if (++if_num == max_dev)
-                       return (NULL);
-       }
-/*
- * There are no available items. Allocate a device from the system pool
- */
-       ctl = (ppp_ctrl_t *) kmalloc (sizeof(ppp_ctrl_t), GFP_KERNEL);
-       if (ctl) {
-               (void) memset(ctl, 0, sizeof(ppp_ctrl_t));
-               ppp = ctl2ppp (ctl);
-               dev = ctl2dev (ctl);
-
-               /* initialize channel control data */
-               set_bit(0, &ppp->inuse);
-
-               ppp->line      = if_num;
-               ppp->tty       = NULL;
-               ppp->backup_tty = NULL;
-               ppp->dev       = dev;
-    
-               dev->next      = NULL;
-               dev->init      = ppp_init_dev;
-               dev->name      = ctl->name;
-               dev->base_addr = (__u32) if_num;
-               dev->priv      = (void *) ppp;
-
-               sprintf (dev->name, "ppp%d", if_num);
-    
-               /* link in the new channel */
-               ctl->next      = ppp_list;
-               ppp_list       = ctl;
-
-               /* register device so that we can be ifconfig'd */
-               /* ppp_init_dev() will be called as a side-effect */
-
-               status = register_netdev (dev);
-               if (status == 0) {
-                       printk (KERN_INFO "registered device %s\n", dev->name);
-                       return (ppp);
-               }
+                       return ppp;
+               ++if_num;
+       }
+/*
+ * There are no available units, so make a new one.
+ */
+       ppp = (struct ppp *) kmalloc (sizeof(struct ppp), GFP_KERNEL);
+       if (ppp == 0)
+               return 0;
+       memset(ppp, 0, sizeof(*ppp));
+
+       /* initialize channel control data */
+       set_bit(0, &ppp->inuse);
 
+       ppp->line      = if_num;
+       ppp->tty       = NULL;
+       ppp->backup_tty = NULL;
+       if (ppp_last == 0)
+               ppp_list = ppp;
+       else
+               ppp_last->next = ppp;
+       ppp_last = ppp;
+       ppp->next = 0;
+
+       dev = ppp2dev(ppp);
+       dev->next      = NULL;
+       dev->init      = ppp_init_dev;
+       dev->name      = ppp->name;
+       sprintf(dev->name, "ppp%d", if_num);
+       dev->base_addr = (__u32) if_num;
+       dev->priv      = (void *) ppp;
+
+       /* register device so that we can be ifconfig'd */
+       /* ppp_init_dev() will be called as a side-effect */
+       status = register_netdev (dev);
+       if (status == 0) {
+               printk (KERN_INFO "registered device %s\n", dev->name);
+       } else {
                printk (KERN_ERR
                       "ppp_alloc - register_netdev(%s) = %d failure.\n",
                        dev->name, status);
+               ppp = NULL;
                /* This one will forever be busy as it is not initialized */
        }
-       return (NULL);
+       return ppp;
 }
 
 /*
@@ -3336,8 +3466,10 @@ init_module(void)
        if (status != 0)
                printk (KERN_INFO
                       "PPP: ppp_init() failure %d\n", status);
+#if LINUX_VERSION_CODE < VERSION(2,1,18)
        else
                (void) register_symtab (&ppp_syms);
+#endif
        return (status);
 }
 
@@ -3345,27 +3477,23 @@ void
 cleanup_module(void)
 {
        int status;
-       ppp_ctrl_t *ctl, *next_ctl;
        struct device *dev;
-       struct ppp *ppp;
+       struct ppp *ppp, *next_ppp;
        int busy_flag = 0;
 /*
  * Ensure that the devices are not in operation.
  */
-       ctl = ppp_list;
-       while (ctl) {
-               ppp = ctl2ppp (ctl);
+       for (ppp = ppp_list; ppp != 0; ppp = ppp->next) {
                if (ppp->inuse && ppp->tty != NULL) {
                        busy_flag = 1;
                        break;
                }
 
-               dev = ctl2dev (ctl);
+               dev = ppp2dev (ppp);
                if (dev->start || dev->flags & IFF_UP) {
                        busy_flag = 1;
                        break;
                }
-               ctl = ctl->next;
        }
 /*
  * Ensure that there are no compressor modules registered
@@ -3392,17 +3520,12 @@ cleanup_module(void)
                       "PPP: ppp line discipline successfully unregistered\n");
 /*
  * De-register the devices so that there is no problem with them
- */    
-       next_ctl = ppp_list;
-       while (next_ctl) {
-               ctl      = next_ctl;
-               next_ctl = ctl->next;
-               ppp      = ctl2ppp (ctl);
-               dev      = ctl2dev (ctl);
-
-               ppp_release       (ppp);
-               unregister_netdev (dev);
-               kfree (ctl);
+ */
+       for (ppp = ppp_list; ppp != 0; ppp = next_ppp) {
+               next_ppp = ppp->next;
+               ppp_release (ppp);
+               unregister_netdev (&ppp->dev);
+               kfree (ppp);
        }
 }
 #endif