]> git.ozlabs.org Git - ppp.git/blobdiff - freebsd-2.0/if_ppp.c
fix compilation problems
[ppp.git] / freebsd-2.0 / if_ppp.c
index f6f4e84ce99df7a365e0204d0b03d00ad7e723a5..6e450ea5687968e15a7932b60d1dcc1d1b9845f4 100644 (file)
@@ -69,8 +69,9 @@
  * Paul Mackerras (paulus@cs.anu.edu.au).
  */
 
  * Paul Mackerras (paulus@cs.anu.edu.au).
  */
 
-/* $Id: if_ppp.c,v 1.4 1995/07/11 06:37:41 paulus Exp $ */
+/* $Id: if_ppp.c,v 1.11 1997/03/04 03:27:28 paulus Exp $ */
 /* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
 /* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
+/* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
 
 #include "ppp.h"
 #if NPPP > 0
 
 #include "ppp.h"
 #if NPPP > 0
@@ -85,6 +86,8 @@
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <sys/kernel.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <sys/kernel.h>
+#include <sys/time.h>
+#include <sys/malloc.h>
 
 #include <net/if.h>
 #include <net/if_types.h>
 
 #include <net/if.h>
 #include <net/if_types.h>
 
 #include "bpfilter.h"
 #if NBPFILTER > 0
 
 #include "bpfilter.h"
 #if NBPFILTER > 0
-#include <sys/time.h>
 #include <net/bpf.h>
 #endif
 
 #include <net/bpf.h>
 #endif
 
 #include <net/if_pppvar.h>
 #include <machine/cpu.h>
 
 #include <net/if_pppvar.h>
 #include <machine/cpu.h>
 
+#define splsoftnet     splnet
+
 #ifndef NETISR_PPP
 /* This definition should be moved to net/netisr.h */
 #define NETISR_PPP     26      /* PPP software interrupt */
 #ifndef NETISR_PPP
 /* This definition should be moved to net/netisr.h */
 #define NETISR_PPP     26      /* PPP software interrupt */
 #include <net/ppp-comp.h>
 #endif
 
 #include <net/ppp-comp.h>
 #endif
 
-void   pppattach __P((void));
-int    pppioctl __P((struct ppp_softc *sc, int cmd, caddr_t data, int flag,
-                     struct proc *));
-int    pppoutput __P((struct ifnet *ifp, struct mbuf *m0,
-                      struct sockaddr *dst, struct rtentry *rtp));
-int    pppsioctl __P((struct ifnet *ifp, int cmd, caddr_t data));
-void   pppintr __P((void));
-
+static int     pppsioctl __P((struct ifnet *, int, caddr_t));
+static int     pppoutput __P((struct ifnet *, struct mbuf *,
+                              struct sockaddr *, struct rtentry *));
 static void    ppp_requeue __P((struct ppp_softc *));
 static void    ppp_outpkt __P((struct ppp_softc *));
 static void    ppp_requeue __P((struct ppp_softc *));
 static void    ppp_outpkt __P((struct ppp_softc *));
-static int     ppp_ccp __P((struct ppp_softc *, struct mbuf *m, int rcvd));
+static void    ppp_ccp __P((struct ppp_softc *, struct mbuf *m, int rcvd));
 static void    ppp_ccp_closed __P((struct ppp_softc *));
 static void    ppp_inproc __P((struct ppp_softc *, struct mbuf *));
 static void    pppdumpm __P((struct mbuf *m0));
 static void    ppp_ccp_closed __P((struct ppp_softc *));
 static void    ppp_inproc __P((struct ppp_softc *, struct mbuf *));
 static void    pppdumpm __P((struct mbuf *m0));
@@ -166,10 +165,14 @@ static void       pppdumpm __P((struct mbuf *m0));
  */
 
 extern struct compressor ppp_bsd_compress;
  */
 
 extern struct compressor ppp_bsd_compress;
+extern struct compressor ppp_deflate;
 
 struct compressor *ppp_compressors[8] = {
 #if DO_BSD_COMPRESS
     &ppp_bsd_compress,
 
 struct compressor *ppp_compressors[8] = {
 #if DO_BSD_COMPRESS
     &ppp_bsd_compress,
+#endif
+#if DO_DEFLATE
+    &ppp_deflate,
 #endif
     NULL
 };
 #endif
     NULL
 };
@@ -191,7 +194,7 @@ pppattach()
        sc->sc_if.if_name = "ppp";
        sc->sc_if.if_unit = i++;
        sc->sc_if.if_mtu = PPP_MTU;
        sc->sc_if.if_name = "ppp";
        sc->sc_if.if_unit = i++;
        sc->sc_if.if_mtu = PPP_MTU;
-       sc->sc_if.if_flags = IFF_POINTOPOINT;
+       sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
        sc->sc_if.if_type = IFT_PPP;
        sc->sc_if.if_hdrlen = PPP_HDRLEN;
        sc->sc_if.if_ioctl = pppsioctl;
        sc->sc_if.if_type = IFT_PPP;
        sc->sc_if.if_hdrlen = PPP_HDRLEN;
        sc->sc_if.if_ioctl = pppsioctl;
@@ -205,7 +208,7 @@ pppattach()
        bpfattach(&sc->sc_bpf, &sc->sc_if, DLT_PPP, PPP_HDRLEN);
 #endif
     }
        bpfattach(&sc->sc_bpf, &sc->sc_if, DLT_PPP, PPP_HDRLEN);
 #endif
     }
-    netisrs[NETISR_PPP] = ppp_intr;
+    netisrs[NETISR_PPP] = pppintr;
 }
 
 /*
 }
 
 /*
@@ -232,8 +235,12 @@ pppalloc(pid)
     sc->sc_flags = 0;
     sc->sc_mru = PPP_MRU;
     sc->sc_relinq = NULL;
     sc->sc_flags = 0;
     sc->sc_mru = PPP_MRU;
     sc->sc_relinq = NULL;
+    bzero((char *)&sc->sc_stats, sizeof(sc->sc_stats));
 #ifdef VJC
 #ifdef VJC
-    vj_compress_init(&sc->sc_comp, -1);
+    MALLOC(sc->sc_comp, struct vjcompress *, sizeof(struct vjcompress),
+          M_DEVBUF, M_NOWAIT);
+    if (sc->sc_comp)
+       vj_compress_init(sc->sc_comp, -1);
 #endif
 #ifdef PPP_COMPRESS
     sc->sc_xc_state = NULL;
 #endif
 #ifdef PPP_COMPRESS
     sc->sc_xc_state = NULL;
@@ -249,7 +256,7 @@ pppalloc(pid)
 }
 
 /*
 }
 
 /*
- * Deallocate a ppp unit.  Must be called at splnet or higher.
+ * Deallocate a ppp unit.  Must be called at splsoftnet or higher.
  */
 void
 pppdealloc(sc)
  */
 void
 pppdealloc(sc)
@@ -292,6 +299,12 @@ pppdealloc(sc)
     sc->sc_xc_state = NULL;
     sc->sc_rc_state = NULL;
 #endif /* PPP_COMPRESS */
     sc->sc_xc_state = NULL;
     sc->sc_rc_state = NULL;
 #endif /* PPP_COMPRESS */
+#ifdef VJC
+    if (sc->sc_comp != 0) {
+       FREE(sc->sc_comp, M_DEVBUF);
+       sc->sc_comp = 0;
+    }
+#endif
 }
 
 /*
 }
 
 /*
@@ -300,8 +313,9 @@ pppdealloc(sc)
 int
 pppioctl(sc, cmd, data, flag, p)
     struct ppp_softc *sc;
 int
 pppioctl(sc, cmd, data, flag, p)
     struct ppp_softc *sc;
+    int cmd;
     caddr_t data;
     caddr_t data;
-    int cmd, flag;
+    int flag;
     struct proc *p;
 {
     int s, error, flags, mru, nb, npx;
     struct proc *p;
 {
     int s, error, flags, mru, nb, npx;
@@ -327,10 +341,10 @@ pppioctl(sc, cmd, data, flag, p)
        break;
 
     case PPPIOCSFLAGS:
        break;
 
     case PPPIOCSFLAGS:
-       if (error = suser(p->p_ucred, &p->p_acflag))
+       if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
            return (error);
        flags = *(int *)data & SC_MASK;
            return (error);
        flags = *(int *)data & SC_MASK;
-       s = splnet();
+       s = splsoftnet();
 #ifdef PPP_COMPRESS
        if (sc->sc_flags & SC_CCP_OPEN && !(flags & SC_CCP_OPEN))
            ppp_ccp_closed(sc);
 #ifdef PPP_COMPRESS
        if (sc->sc_flags & SC_CCP_OPEN && !(flags & SC_CCP_OPEN))
            ppp_ccp_closed(sc);
@@ -341,7 +355,7 @@ pppioctl(sc, cmd, data, flag, p)
        break;
 
     case PPPIOCSMRU:
        break;
 
     case PPPIOCSMRU:
-       if (error = suser(p->p_ucred, &p->p_acflag))
+       if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
            return (error);
        mru = *(int *)data;
        if (mru >= PPP_MRU && mru <= PPP_MAXMRU)
            return (error);
        mru = *(int *)data;
        if (mru >= PPP_MRU && mru <= PPP_MAXMRU)
@@ -354,29 +368,31 @@ pppioctl(sc, cmd, data, flag, p)
 
 #ifdef VJC
     case PPPIOCSMAXCID:
 
 #ifdef VJC
     case PPPIOCSMAXCID:
-       if (error = suser(p->p_ucred, &p->p_acflag))
+       if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
            return (error);
            return (error);
-       s = splnet();
-       vj_compress_init(&sc->sc_comp, *(int *)data);
-       splx(s);
+       if (sc->sc_comp) {
+           s = splsoftnet();
+           vj_compress_init(sc->sc_comp, *(int *)data);
+           splx(s);
+       }
        break;
 #endif
 
     case PPPIOCXFERUNIT:
        break;
 #endif
 
     case PPPIOCXFERUNIT:
-       if (error = suser(p->p_ucred, &p->p_acflag))
+       if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
            return (error);
        sc->sc_xfer = p->p_pid;
        break;
 
 #ifdef PPP_COMPRESS
     case PPPIOCSCOMPRESS:
            return (error);
        sc->sc_xfer = p->p_pid;
        break;
 
 #ifdef PPP_COMPRESS
     case PPPIOCSCOMPRESS:
-       if (error = suser(p->p_ucred, &p->p_acflag))
+       if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
            return (error);
        odp = (struct ppp_option_data *) data;
        nb = odp->length;
        if (nb > sizeof(ccp_option))
            nb = sizeof(ccp_option);
            return (error);
        odp = (struct ppp_option_data *) data;
        nb = odp->length;
        if (nb > sizeof(ccp_option))
            nb = sizeof(ccp_option);
-       if (error = copyin(odp->ptr, ccp_option, nb))
+       if ((error = copyin(odp->ptr, ccp_option, nb)) != 0)
            return (error);
        if (ccp_option[1] < 2)  /* preliminary check on the length byte */
            return (EINVAL);
            return (error);
        if (ccp_option[1] < 2)  /* preliminary check on the length byte */
            return (EINVAL);
@@ -387,8 +403,8 @@ pppioctl(sc, cmd, data, flag, p)
                 * a compressor or decompressor.
                 */
                error = 0;
                 * a compressor or decompressor.
                 */
                error = 0;
-               s = splnet();
                if (odp->transmit) {
                if (odp->transmit) {
+                   s = splsoftnet();
                    if (sc->sc_xc_state != NULL)
                        (*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
                    sc->sc_xcomp = *cp;
                    if (sc->sc_xc_state != NULL)
                        (*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
                    sc->sc_xcomp = *cp;
@@ -401,7 +417,9 @@ pppioctl(sc, cmd, data, flag, p)
                    }
                    splimp();
                    sc->sc_flags &= ~SC_COMP_RUN;
                    }
                    splimp();
                    sc->sc_flags &= ~SC_COMP_RUN;
+                   splx(s);
                } else {
                } else {
+                   s = splsoftnet();
                    if (sc->sc_rc_state != NULL)
                        (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
                    sc->sc_rcomp = *cp;
                    if (sc->sc_rc_state != NULL)
                        (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
                    sc->sc_rcomp = *cp;
@@ -414,8 +432,8 @@ pppioctl(sc, cmd, data, flag, p)
                    }
                    splimp();
                    sc->sc_flags &= ~SC_DECOMP_RUN;
                    }
                    splimp();
                    sc->sc_flags &= ~SC_DECOMP_RUN;
+                   splx(s);
                }
                }
-               splx(s);
                return (error);
            }
        if (sc->sc_flags & SC_DEBUG)
                return (error);
            }
        if (sc->sc_flags & SC_DEBUG)
@@ -438,10 +456,10 @@ pppioctl(sc, cmd, data, flag, p)
        if (cmd == PPPIOCGNPMODE) {
            npi->mode = sc->sc_npmode[npx];
        } else {
        if (cmd == PPPIOCGNPMODE) {
            npi->mode = sc->sc_npmode[npx];
        } else {
-           if (error = suser(p->p_ucred, &p->p_acflag))
+           if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
                return (error);
            if (npi->mode != sc->sc_npmode[npx]) {
                return (error);
            if (npi->mode != sc->sc_npmode[npx]) {
-               s = splimp();
+               s = splsoftnet();
                sc->sc_npmode[npx] = npi->mode;
                if (npi->mode != NPMODE_QUEUE) {
                    ppp_requeue(sc);
                sc->sc_npmode[npx] = npi->mode;
                if (npi->mode != NPMODE_QUEUE) {
                    ppp_requeue(sc);
@@ -453,7 +471,7 @@ pppioctl(sc, cmd, data, flag, p)
        break;
 
     case PPPIOCGIDLE:
        break;
 
     case PPPIOCGIDLE:
-       s = splimp();
+       s = splsoftnet();
        t = time.tv_sec;
        ((struct ppp_idle *)data)->xmit_idle = t - sc->sc_last_sent;
        ((struct ppp_idle *)data)->recv_idle = t - sc->sc_last_recv;
        t = time.tv_sec;
        ((struct ppp_idle *)data)->xmit_idle = t - sc->sc_last_sent;
        ((struct ppp_idle *)data)->recv_idle = t - sc->sc_last_recv;
@@ -502,7 +520,7 @@ pppsioctl(ifp, cmd, data)
        break;
 
     case SIOCSIFMTU:
        break;
 
     case SIOCSIFMTU:
-       if (error = suser(p->p_ucred, &p->p_acflag))
+       if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
            break;
        sc->sc_if.if_mtu = ifr->ifr_mtu;
        break;
            break;
        sc->sc_if.if_mtu = ifr->ifr_mtu;
        break;
@@ -511,24 +529,38 @@ pppsioctl(ifp, cmd, data)
        ifr->ifr_mtu = sc->sc_if.if_mtu;
        break;
 
        ifr->ifr_mtu = sc->sc_if.if_mtu;
        break;
 
+    case SIOCADDMULTI:
+    case SIOCDELMULTI:
+       if (ifr == 0) {
+           error = EAFNOSUPPORT;
+           break;
+       }
+       switch(ifr->ifr_addr.sa_family) {
+#ifdef INET
+       case AF_INET:
+           break;
+#endif
+       default:
+           error = EAFNOSUPPORT;
+           break;
+       }
+       break;
+
     case SIOCGPPPSTATS:
        psp = &((struct ifpppstatsreq *) data)->stats;
        bzero(psp, sizeof(*psp));
     case SIOCGPPPSTATS:
        psp = &((struct ifpppstatsreq *) data)->stats;
        bzero(psp, sizeof(*psp));
-       psp->p.ppp_ibytes = sc->sc_bytesrcvd;
-       psp->p.ppp_ipackets = ifp->if_ipackets;
-       psp->p.ppp_ierrors = ifp->if_ierrors;
-       psp->p.ppp_obytes = sc->sc_bytessent;
-       psp->p.ppp_opackets = ifp->if_opackets;
-       psp->p.ppp_oerrors = ifp->if_oerrors;
-#ifdef VJC
-       psp->vj.vjs_packets = sc->sc_comp.sls_packets;
-       psp->vj.vjs_compressed = sc->sc_comp.sls_compressed;
-       psp->vj.vjs_searches = sc->sc_comp.sls_searches;
-       psp->vj.vjs_misses = sc->sc_comp.sls_misses;
-       psp->vj.vjs_uncompressedin = sc->sc_comp.sls_uncompressedin;
-       psp->vj.vjs_compressedin = sc->sc_comp.sls_compressedin;
-       psp->vj.vjs_errorin = sc->sc_comp.sls_errorin;
-       psp->vj.vjs_tossed = sc->sc_comp.sls_tossed;
+       psp->p = sc->sc_stats;
+#if defined(VJC) && !defined(SL_NO_STATS)
+       if (sc->sc_comp) {
+           psp->vj.vjs_packets = sc->sc_comp->sls_packets;
+           psp->vj.vjs_compressed = sc->sc_comp->sls_compressed;
+           psp->vj.vjs_searches = sc->sc_comp->sls_searches;
+           psp->vj.vjs_misses = sc->sc_comp->sls_misses;
+           psp->vj.vjs_uncompressedin = sc->sc_comp->sls_uncompressedin;
+           psp->vj.vjs_compressedin = sc->sc_comp->sls_compressedin;
+           psp->vj.vjs_errorin = sc->sc_comp->sls_errorin;
+           psp->vj.vjs_tossed = sc->sc_comp->sls_tossed;
+       }
 #endif /* VJC */
        break;
 
 #endif /* VJC */
        break;
 
@@ -562,16 +594,17 @@ pppoutput(ifp, m0, dst, rtp)
     struct rtentry *rtp;
 {
     register struct ppp_softc *sc = &ppp_softc[ifp->if_unit];
     struct rtentry *rtp;
 {
     register struct ppp_softc *sc = &ppp_softc[ifp->if_unit];
-    struct ppp_header *ph;
     int protocol, address, control;
     u_char *cp;
     int s, error;
     struct ip *ip;
     struct ifqueue *ifq;
     enum NPmode mode;
     int protocol, address, control;
     u_char *cp;
     int s, error;
     struct ip *ip;
     struct ifqueue *ifq;
     enum NPmode mode;
+    int len;
+    struct mbuf *m;
 
     if (sc->sc_devp == NULL || (ifp->if_flags & IFF_RUNNING) == 0
 
     if (sc->sc_devp == NULL || (ifp->if_flags & IFF_RUNNING) == 0
-       || (ifp->if_flags & IFF_UP) == 0 && dst->sa_family != AF_UNSPEC) {
+       || ((ifp->if_flags & IFF_UP) == 0 && dst->sa_family != AF_UNSPEC)) {
        error = ENETDOWN;       /* sort of */
        goto bad;
     }
        error = ENETDOWN;       /* sort of */
        goto bad;
     }
@@ -642,11 +675,22 @@ pppoutput(ifp, m0, dst, rtp)
     *cp++ = protocol & 0xff;
     m0->m_len += PPP_HDRLEN;
 
     *cp++ = protocol & 0xff;
     m0->m_len += PPP_HDRLEN;
 
+    len = 0;
+    for (m = m0; m != 0; m = m->m_next)
+       len += m->m_len;
+
     if (sc->sc_flags & SC_LOG_OUTPKT) {
        printf("ppp%d output: ", ifp->if_unit);
        pppdumpm(m0);
     }
 
     if (sc->sc_flags & SC_LOG_OUTPKT) {
        printf("ppp%d output: ", ifp->if_unit);
        pppdumpm(m0);
     }
 
+    if ((protocol & 0x8000) == 0) {
+       /*
+        * Update the time we sent the most recent data packet.
+        */
+       sc->sc_last_sent = time.tv_sec;
+    }
+
 #if NBPFILTER > 0
     /*
      * See if bpf wants to look at the packet.
 #if NBPFILTER > 0
     /*
      * See if bpf wants to look at the packet.
@@ -658,7 +702,7 @@ pppoutput(ifp, m0, dst, rtp)
     /*
      * Put the packet on the appropriate queue.
      */
     /*
      * Put the packet on the appropriate queue.
      */
-    s = splimp();              /* splnet should be OK now */
+    s = splsoftnet();
     if (mode == NPMODE_QUEUE) {
        /* XXX we should limit the number of packets on this queue */
        *sc->sc_npqtail = m0;
     if (mode == NPMODE_QUEUE) {
        /* XXX we should limit the number of packets on this queue */
        *sc->sc_npqtail = m0;
@@ -666,16 +710,20 @@ pppoutput(ifp, m0, dst, rtp)
        sc->sc_npqtail = &m0->m_nextpkt;
     } else {
        ifq = (m0->m_flags & M_HIGHPRI)? &sc->sc_fastq: &ifp->if_snd;
        sc->sc_npqtail = &m0->m_nextpkt;
     } else {
        ifq = (m0->m_flags & M_HIGHPRI)? &sc->sc_fastq: &ifp->if_snd;
-       if (IF_QFULL(ifq)) {
+       if (IF_QFULL(ifq) && dst->sa_family != AF_UNSPEC) {
            IF_DROP(ifq);
            splx(s);
            sc->sc_if.if_oerrors++;
            IF_DROP(ifq);
            splx(s);
            sc->sc_if.if_oerrors++;
+           sc->sc_stats.ppp_oerrors++;
            error = ENOBUFS;
            goto bad;
        }
        IF_ENQUEUE(ifq, m0);
        (*sc->sc_start)(sc);
     }
            error = ENOBUFS;
            goto bad;
        }
        IF_ENQUEUE(ifq, m0);
        (*sc->sc_start)(sc);
     }
+    ifp->if_lastchange = time;
+    ifp->if_opackets++;
+    ifp->if_obytes += len;
 
     splx(s);
     return (0);
 
     splx(s);
     return (0);
@@ -688,7 +736,7 @@ bad:
 /*
  * After a change in the NPmode for some NP, move packets from the
  * npqueue to the send queue or the fast queue as appropriate.
 /*
  * After a change in the NPmode for some NP, move packets from the
  * npqueue to the send queue or the fast queue as appropriate.
- * Should be called at splimp (actually splnet would probably suffice).
+ * Should be called at splsoftnet.
  */
 static void
 ppp_requeue(sc)
  */
 static void
 ppp_requeue(sc)
@@ -718,6 +766,7 @@ ppp_requeue(sc)
            if (IF_QFULL(ifq)) {
                IF_DROP(ifq);
                sc->sc_if.if_oerrors++;
            if (IF_QFULL(ifq)) {
                IF_DROP(ifq);
                sc->sc_if.if_oerrors++;
+               sc->sc_stats.ppp_oerrors++;
            } else
                IF_ENQUEUE(ifq, m);
            break;
            } else
                IF_ENQUEUE(ifq, m);
            break;
@@ -737,78 +786,34 @@ ppp_requeue(sc)
 }
 
 /*
 }
 
 /*
- * Get a packet to send.  This procedure is intended to be called
- * at spltty()/splimp(), so it takes little time.  If there isn't
- * a packet waiting to go out, it schedules a software interrupt
- * to prepare a new packet; the device start routine gets called
- * again when a packet is ready.
+ * Transmitter has finished outputting some stuff;
+ * remember to call sc->sc_start later at splsoftnet.
  */
  */
-struct mbuf *
-ppp_dequeue(sc)
+void
+ppp_restart(sc)
     struct ppp_softc *sc;
 {
     struct ppp_softc *sc;
 {
-    struct mbuf *m;
     int s = splimp();
 
     int s = splimp();
 
-    m = sc->sc_togo;
-    if (m) {
-       /*
-        * Had a packet waiting - send it.
-        */
-       sc->sc_togo = NULL;
-       sc->sc_flags |= SC_TBUSY;
-       splx(s);
-       return m;
-    }
-    /*
-     * Remember we wanted a packet and schedule a software interrupt.
-     */
     sc->sc_flags &= ~SC_TBUSY;
     schednetisr(NETISR_PPP);
     splx(s);
     sc->sc_flags &= ~SC_TBUSY;
     schednetisr(NETISR_PPP);
     splx(s);
-    return NULL;
-}
-
-/*
- * Software interrupt routine, called at splnet().
- */
-void
-pppintr()
-{
-    struct ppp_softc *sc;
-    int i, s;
-    struct mbuf *m;
-
-    s = splnet();
-    sc = ppp_softc;
-    for (i = 0; i < NPPP; ++i, ++sc) {
-       if (!(sc->sc_flags & SC_TBUSY) && sc->sc_togo == NULL
-           && (sc->sc_if.if_snd.ifq_head || sc->sc_fastq.ifq_head))
-           ppp_outpkt(sc);
-       for (;;) {
-           IF_DEQUEUE(&sc->sc_rawq, m);
-           if (m == NULL)
-               break;
-           ppp_inproc(sc, m);
-       }
-    }
-    splx(s);
 }
 
 /*
 }
 
 /*
- * Grab another packet off a queue and apply VJ compression,
- * packet compression, address/control and/or protocol compression
- * if enabled.  Should be called at splnet.
+ * Get a packet to send.  This procedure is intended to be called at
+ * splsoftnet, since it may involve time-consuming operations such as
+ * applying VJ compression, packet compression, address/control and/or
+ * protocol field compression to the packet.
  */
  */
-static void
-ppp_outpkt(sc)
+struct mbuf *
+ppp_dequeue(sc)
     struct ppp_softc *sc;
 {
     struct ppp_softc *sc;
 {
-    int s;
     struct mbuf *m, *mp;
     u_char *cp;
     int address, control, protocol;
     struct mbuf *m, *mp;
     u_char *cp;
     int address, control, protocol;
-    enum NPmode mode;
+    int s;
 
     /*
      * Grab a packet to send: first try the fast queue, then the
 
     /*
      * Grab a packet to send: first try the fast queue, then the
@@ -818,7 +823,9 @@ ppp_outpkt(sc)
     if (m == NULL)
        IF_DEQUEUE(&sc->sc_if.if_snd, m);
     if (m == NULL)
     if (m == NULL)
        IF_DEQUEUE(&sc->sc_if.if_snd, m);
     if (m == NULL)
-       return;
+       return NULL;
+
+    ++sc->sc_stats.ppp_opackets;
 
     /*
      * Extract the ppp header of the new packet.
 
     /*
      * Extract the ppp header of the new packet.
@@ -831,16 +838,11 @@ ppp_outpkt(sc)
 
     switch (protocol) {
     case PPP_IP:
 
     switch (protocol) {
     case PPP_IP:
-       /*
-        * Update the time we sent the most recent packet.
-        */
-       sc->sc_last_sent = time.tv_sec;
-
 #ifdef VJC
        /*
         * If the packet is a TCP/IP packet, see if we can compress it.
         */
 #ifdef VJC
        /*
         * If the packet is a TCP/IP packet, see if we can compress it.
         */
-       if (sc->sc_flags & SC_COMP_TCP) {
+       if ((sc->sc_flags & SC_COMP_TCP) && sc->sc_comp != NULL) {
            struct ip *ip;
            int type;
 
            struct ip *ip;
            int type;
 
@@ -854,7 +856,7 @@ ppp_outpkt(sc)
            }
            /* this code assumes the IP/TCP header is in one non-shared mbuf */
            if (ip->ip_p == IPPROTO_TCP) {
            }
            /* this code assumes the IP/TCP header is in one non-shared mbuf */
            if (ip->ip_p == IPPROTO_TCP) {
-               type = vj_compress_tcp(mp, ip, &sc->sc_comp,
+               type = vj_compress_tcp(mp, ip, sc->sc_comp,
                                       !(sc->sc_flags & SC_NO_TCP_CCID));
                switch (type) {
                case TYPE_UNCOMPRESSED_TCP:
                                       !(sc->sc_flags & SC_NO_TCP_CCID));
                switch (type) {
                case TYPE_UNCOMPRESSED_TCP:
@@ -891,13 +893,18 @@ ppp_outpkt(sc)
        for (mp = m; mp != NULL; mp = mp->m_next)
            slen += mp->m_len;
        clen = (*sc->sc_xcomp->compress)
        for (mp = m; mp != NULL; mp = mp->m_next)
            slen += mp->m_len;
        clen = (*sc->sc_xcomp->compress)
-           (sc->sc_xc_state, &mcomp, m, slen,
-            (sc->sc_flags & SC_CCP_UP? sc->sc_if.if_mtu: 0));
+           (sc->sc_xc_state, &mcomp, m, slen, sc->sc_if.if_mtu + PPP_HDRLEN);
        if (mcomp != NULL) {
        if (mcomp != NULL) {
-           m_freem(m);
-           m = mcomp;
-           cp = mtod(m, u_char *);
-           protocol = cp[3];
+           if (sc->sc_flags & SC_CCP_UP) {
+               /* Send the compressed packet instead of the original. */
+               m_freem(m);
+               m = mcomp;
+               cp = mtod(m, u_char *);
+               protocol = cp[3];
+           } else {
+               /* Can't transmit compressed packets until CCP is up. */
+               m_freem(mcomp);
+           }
        }
     }
 #endif /* PPP_COMPRESS */
        }
     }
 #endif /* PPP_COMPRESS */
@@ -922,9 +929,38 @@ ppp_outpkt(sc)
        --m->m_len;
     }
 
        --m->m_len;
     }
 
-    s = splimp();
-    sc->sc_togo = m;
-    (*sc->sc_start)(sc);
+    return m;
+}
+
+/*
+ * Software interrupt routine, called at splsoftnet.
+ */
+void
+pppintr()
+{
+    struct ppp_softc *sc;
+    int i, s, s2;
+    struct mbuf *m;
+
+    sc = ppp_softc;
+    s = splsoftnet();
+    for (i = 0; i < NPPP; ++i, ++sc) {
+       if (!(sc->sc_flags & SC_TBUSY)
+           && (sc->sc_if.if_snd.ifq_head || sc->sc_fastq.ifq_head)) {
+           s2 = splimp();
+           sc->sc_flags |= SC_TBUSY;
+           splx(s2);
+           (*sc->sc_start)(sc);
+       }
+       for (;;) {
+           s2 = splimp();
+           IF_DEQUEUE(&sc->sc_rawq, m);
+           splx(s2);
+           if (m == NULL)
+               break;
+           ppp_inproc(sc, m);
+       }
+    }
     splx(s);
 }
 
     splx(s);
 }
 
@@ -933,7 +969,7 @@ ppp_outpkt(sc)
  * Handle a CCP packet.  `rcvd' is 1 if the packet was received,
  * 0 if it is about to be transmitted.
  */
  * Handle a CCP packet.  `rcvd' is 1 if the packet was received,
  * 0 if it is about to be transmitted.
  */
-static int
+static void
 ppp_ccp(sc, m, rcvd)
     struct ppp_softc *sc;
     struct mbuf *m;
 ppp_ccp(sc, m, rcvd)
     struct ppp_softc *sc;
     struct mbuf *m;
@@ -962,7 +998,7 @@ ppp_ccp(sc, m, rcvd)
     slen = CCP_LENGTH(dp);
     if (dp + slen > ep) {
        if (sc->sc_flags & SC_DEBUG)
     slen = CCP_LENGTH(dp);
     if (dp + slen > ep) {
        if (sc->sc_flags & SC_DEBUG)
-           printf("if_ppp/ccp: not enough data in mbuf (%x+%x > %x+%x)\n",
+           printf("if_ppp/ccp: not enough data in mbuf (%p+%x > %p+%x)\n",
                   dp, slen, mtod(mp, u_char *), mp->m_len);
        return;
     }
                   dp, slen, mtod(mp, u_char *), mp->m_len);
        return;
     }
@@ -1068,6 +1104,7 @@ ppppktin(sc, m, lost)
 
 /*
  * Process a received PPP packet, doing decompression as necessary.
 
 /*
  * Process a received PPP packet, doing decompression as necessary.
+ * Should be called at splsoftnet.
  */
 #define COMPTYPE(proto)        ((proto) == PPP_VJC_COMP? TYPE_COMPRESSED_TCP: \
                         TYPE_UNCOMPRESSED_TCP)
  */
 #define COMPTYPE(proto)        ((proto) == PPP_VJC_COMP? TYPE_COMPRESSED_TCP: \
                         TYPE_UNCOMPRESSED_TCP)
@@ -1077,6 +1114,7 @@ ppp_inproc(sc, m)
     struct ppp_softc *sc;
     struct mbuf *m;
 {
     struct ppp_softc *sc;
     struct mbuf *m;
 {
+    struct ifnet *ifp = &sc->sc_if;
     struct ifqueue *inq;
     int s, ilen, xlen, proto, rv;
     u_char *cp, adrs, ctrl;
     struct ifqueue *inq;
     int s, ilen, xlen, proto, rv;
     u_char *cp, adrs, ctrl;
@@ -1084,10 +1122,13 @@ ppp_inproc(sc, m)
     u_char *iphdr;
     u_int hlen;
 
     u_char *iphdr;
     u_int hlen;
 
-    sc->sc_if.if_ipackets++;
+    sc->sc_stats.ppp_ipackets++;
 
     if (sc->sc_flags & SC_LOG_INPKT) {
 
     if (sc->sc_flags & SC_LOG_INPKT) {
-       printf("ppp%d: got %d bytes\n", sc->sc_if.if_unit, ilen);
+       ilen = 0;
+       for (mp = m; mp != NULL; mp = mp->m_next)
+           ilen += mp->m_len;
+       printf("ppp%d: got %d bytes\n", ifp->if_unit, ilen);
        pppdumpm(m);
     }
 
        pppdumpm(m);
     }
 
@@ -1129,7 +1170,7 @@ ppp_inproc(sc, m)
             * CCP down or issue a Reset-Req.
             */
            if (sc->sc_flags & SC_DEBUG)
             * CCP down or issue a Reset-Req.
             */
            if (sc->sc_flags & SC_DEBUG)
-               printf("ppp%d: decompress failed %d\n", sc->sc_if.if_unit, rv);
+               printf("ppp%d: decompress failed %d\n", ifp->if_unit, rv);
            s = splimp();
            sc->sc_flags |= SC_VJ_RESET;
            if (rv == DECOMP_ERROR)
            s = splimp();
            sc->sc_flags |= SC_VJ_RESET;
            if (rv == DECOMP_ERROR)
@@ -1159,7 +1200,8 @@ ppp_inproc(sc, m)
         * If we've missed a packet, we must toss subsequent compressed
         * packets which don't have an explicit connection ID.
         */
         * If we've missed a packet, we must toss subsequent compressed
         * packets which don't have an explicit connection ID.
         */
-       vj_uncompress_tcp(NULL, 0, TYPE_ERROR, &sc->sc_comp);
+       if (sc->sc_comp)
+           vj_uncompress_tcp(NULL, 0, TYPE_ERROR, sc->sc_comp);
        s = splimp();
        sc->sc_flags &= ~SC_VJ_RESET;
        splx(s);
        s = splimp();
        sc->sc_flags &= ~SC_VJ_RESET;
        splx(s);
@@ -1169,17 +1211,17 @@ ppp_inproc(sc, m)
      * See if we have a VJ-compressed packet to uncompress.
      */
     if (proto == PPP_VJC_COMP) {
      * See if we have a VJ-compressed packet to uncompress.
      */
     if (proto == PPP_VJC_COMP) {
-       if (sc->sc_flags & SC_REJ_COMP_TCP)
+       if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0)
            goto bad;
 
        xlen = vj_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
                                      ilen - PPP_HDRLEN, TYPE_COMPRESSED_TCP,
            goto bad;
 
        xlen = vj_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
                                      ilen - PPP_HDRLEN, TYPE_COMPRESSED_TCP,
-                                     &sc->sc_comp, &iphdr, &hlen);
+                                     sc->sc_comp, &iphdr, &hlen);
 
        if (xlen <= 0) {
            if (sc->sc_flags & SC_DEBUG)
                printf("ppp%d: VJ uncompress failed on type comp\n",
 
        if (xlen <= 0) {
            if (sc->sc_flags & SC_DEBUG)
                printf("ppp%d: VJ uncompress failed on type comp\n",
-                       sc->sc_if.if_unit);
+                       ifp->if_unit);
            goto bad;
        }
 
            goto bad;
        }
 
@@ -1221,17 +1263,17 @@ ppp_inproc(sc, m)
        ilen += hlen - xlen;
 
     } else if (proto == PPP_VJC_UNCOMP) {
        ilen += hlen - xlen;
 
     } else if (proto == PPP_VJC_UNCOMP) {
-       if (sc->sc_flags & SC_REJ_COMP_TCP)
+       if ((sc->sc_flags & SC_REJ_COMP_TCP) || sc->sc_comp == 0)
            goto bad;
 
        xlen = vj_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
                                      ilen - PPP_HDRLEN, TYPE_UNCOMPRESSED_TCP,
            goto bad;
 
        xlen = vj_uncompress_tcp_core(cp + PPP_HDRLEN, m->m_len - PPP_HDRLEN,
                                      ilen - PPP_HDRLEN, TYPE_UNCOMPRESSED_TCP,
-                                     &sc->sc_comp, &iphdr, &hlen);
+                                     sc->sc_comp, &iphdr, &hlen);
 
        if (xlen < 0) {
            if (sc->sc_flags & SC_DEBUG)
                printf("ppp%d: VJ uncompress failed on type uncomp\n",
 
        if (xlen < 0) {
            if (sc->sc_flags & SC_DEBUG)
                printf("ppp%d: VJ uncompress failed on type uncomp\n",
-                       sc->sc_if.if_unit);
+                       ifp->if_unit);
            goto bad;
        }
 
            goto bad;
        }
 
@@ -1254,7 +1296,14 @@ ppp_inproc(sc, m)
        }
     }
     m->m_pkthdr.len = ilen;
        }
     }
     m->m_pkthdr.len = ilen;
-    m->m_pkthdr.rcvif = &sc->sc_if;
+    m->m_pkthdr.rcvif = ifp;
+
+    /*
+     * Record the time that we received this packet.
+     */
+    if ((proto & 0x8000) == 0) {
+       sc->sc_last_recv = time.tv_sec;
+    }
 
 #if NBPFILTER > 0
     /* See if bpf wants to look at the packet. */
 
 #if NBPFILTER > 0
     /* See if bpf wants to look at the packet. */
@@ -1269,7 +1318,7 @@ ppp_inproc(sc, m)
        /*
         * IP packet - take off the ppp header and pass it up to IP.
         */
        /*
         * IP packet - take off the ppp header and pass it up to IP.
         */
-       if ((sc->sc_if.if_flags & IFF_UP) == 0
+       if ((ifp->if_flags & IFF_UP) == 0
            || sc->sc_npmode[NP_IP] != NPMODE_PASS) {
            /* interface is down - drop the packet. */
            m_freem(m);
            || sc->sc_npmode[NP_IP] != NPMODE_PASS) {
            /* interface is down - drop the packet. */
            m_freem(m);
@@ -1280,7 +1329,6 @@ ppp_inproc(sc, m)
        m->m_len -= PPP_HDRLEN;
        schednetisr(NETISR_IP);
        inq = &ipintrq;
        m->m_len -= PPP_HDRLEN;
        schednetisr(NETISR_IP);
        inq = &ipintrq;
-       sc->sc_last_recv = time.tv_sec; /* update time of last pkt rcvd */
        break;
 #endif
 
        break;
 #endif
 
@@ -1301,12 +1349,15 @@ ppp_inproc(sc, m)
        IF_DROP(inq);
        splx(s);
        if (sc->sc_flags & SC_DEBUG)
        IF_DROP(inq);
        splx(s);
        if (sc->sc_flags & SC_DEBUG)
-           printf("ppp%d: input queue full\n", sc->sc_if.if_unit);
-       sc->sc_if.if_iqdrops++;
+           printf("ppp%d: input queue full\n", ifp->if_unit);
+       ifp->if_iqdrops++;
        goto bad;
     }
     IF_ENQUEUE(inq, m);
     splx(s);
        goto bad;
     }
     IF_ENQUEUE(inq, m);
     splx(s);
+    ifp->if_ipackets++;
+    ifp->if_ibytes += ilen;
+    ifp->if_lastchange = time;
 
     if (rv)
        (*sc->sc_ctlp)(sc);
 
     if (rv)
        (*sc->sc_ctlp)(sc);
@@ -1316,6 +1367,7 @@ ppp_inproc(sc, m)
  bad:
     m_freem(m);
     sc->sc_if.if_ierrors++;
  bad:
     m_freem(m);
     sc->sc_if.if_ierrors++;
+    sc->sc_stats.ppp_ierrors++;
 }
 
 #define MAX_DUMP_BYTES 128
 }
 
 #define MAX_DUMP_BYTES 128