]> git.ozlabs.org Git - ppp.git/commitdiff
Fix compilation problems; fix spls; add software flow control
authorPaul Mackerras <paulus@samba.org>
Fri, 27 Oct 1995 03:34:44 +0000 (03:34 +0000)
committerPaul Mackerras <paulus@samba.org>
Fri, 27 Oct 1995 03:34:44 +0000 (03:34 +0000)
freebsd-2.0/if_ppp.c
freebsd-2.0/ppp_tty.c

index d62251aa5dba80ef5dc9fd3fb3f3dbea5eaec5c8..702bcca74c538133e584c5558f40fd41059ad28e 100644 (file)
@@ -69,7 +69,7 @@
  * Paul Mackerras (paulus@cs.anu.edu.au).
  */
 
-/* $Id: if_ppp.c,v 1.5 1995/08/16 01:36:38 paulus Exp $ */
+/* $Id: if_ppp.c,v 1.6 1995/10/27 03:34:42 paulus Exp $ */
 /* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
 
 #include "ppp.h"
 #endif
 
 void   pppattach __P((void));
-int    pppioctl __P((struct ppp_softc *sc, int cmd, caddr_t data, int flag,
+int    pppioctl __P((struct ppp_softc *sc, u_long 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));
+int    pppsioctl __P((struct ifnet *ifp, u_long cmd, caddr_t data));
 void   pppintr __P((void));
 
 static void    ppp_requeue __P((struct ppp_softc *));
@@ -205,7 +205,7 @@ pppattach()
        bpfattach(&sc->sc_bpf, &sc->sc_if, DLT_PPP, PPP_HDRLEN);
 #endif
     }
-    netisrs[NETISR_PPP] = ppp_intr;
+    netisrs[NETISR_PPP] = pppintr;
 }
 
 /*
@@ -300,8 +300,9 @@ pppdealloc(sc)
 int
 pppioctl(sc, cmd, data, flag, p)
     struct ppp_softc *sc;
+    u_long cmd;
     caddr_t data;
-    int cmd, flag;
+    int flag;
     struct proc *p;
 {
     int s, error, flags, mru, nb, npx;
@@ -387,8 +388,8 @@ pppioctl(sc, cmd, data, flag, p)
                 * a compressor or decompressor.
                 */
                error = 0;
-               s = splnet();
                if (odp->transmit) {
+                   s = splnet();
                    if (sc->sc_xc_state != NULL)
                        (*sc->sc_xcomp->comp_free)(sc->sc_xc_state);
                    sc->sc_xcomp = *cp;
@@ -401,7 +402,9 @@ pppioctl(sc, cmd, data, flag, p)
                    }
                    splimp();
                    sc->sc_flags &= ~SC_COMP_RUN;
+                   splx(s);
                } else {
+                   s = splnet();
                    if (sc->sc_rc_state != NULL)
                        (*sc->sc_rcomp->decomp_free)(sc->sc_rc_state);
                    sc->sc_rcomp = *cp;
@@ -414,8 +417,8 @@ pppioctl(sc, cmd, data, flag, p)
                    }
                    splimp();
                    sc->sc_flags &= ~SC_DECOMP_RUN;
+                   splx(s);
                }
-               splx(s);
                return (error);
            }
        if (sc->sc_flags & SC_DEBUG)
@@ -441,7 +444,7 @@ pppioctl(sc, cmd, data, flag, p)
            if (error = suser(p->p_ucred, &p->p_acflag))
                return (error);
            if (npi->mode != sc->sc_npmode[npx]) {
-               s = splimp();
+               s = splnet();
                sc->sc_npmode[npx] = npi->mode;
                if (npi->mode != NPMODE_QUEUE) {
                    ppp_requeue(sc);
@@ -453,7 +456,7 @@ pppioctl(sc, cmd, data, flag, p)
        break;
 
     case PPPIOCGIDLE:
-       s = splimp();
+       s = splnet();
        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;
@@ -472,7 +475,7 @@ pppioctl(sc, cmd, data, flag, p)
 int
 pppsioctl(ifp, cmd, data)
     register struct ifnet *ifp;
-    int cmd;
+    u_long cmd;
     caddr_t data;
 {
     struct proc *p = curproc;  /* XXX */
@@ -671,7 +674,7 @@ pppoutput(ifp, m0, dst, rtp)
     /*
      * Put the packet on the appropriate queue.
      */
-    s = splimp();              /* splnet should be OK now */
+    s = splnet();
     if (mode == NPMODE_QUEUE) {
        /* XXX we should limit the number of packets on this queue */
        *sc->sc_npqtail = m0;
@@ -679,7 +682,7 @@ pppoutput(ifp, m0, dst, rtp)
        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++;
@@ -701,7 +704,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.
- * Should be called at splimp (actually splnet would probably suffice).
+ * Should be called at splnet.
  */
 static void
 ppp_requeue(sc)
@@ -750,11 +753,11 @@ 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.
+ * Get a packet to send.  This procedure is intended to be called at
+ * spltty or 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.
  */
 struct mbuf *
 ppp_dequeue(sc)
@@ -799,7 +802,9 @@ pppintr()
            && (sc->sc_if.if_snd.ifq_head || sc->sc_fastq.ifq_head))
            ppp_outpkt(sc);
        for (;;) {
+           s = splimp();
            IF_DEQUEUE(&sc->sc_rawq, m);
+           splx(s);
            if (m == NULL)
                break;
            ppp_inproc(sc, m);
@@ -935,10 +940,8 @@ ppp_outpkt(sc)
        --m->m_len;
     }
 
-    s = splimp();
     sc->sc_togo = m;
     (*sc->sc_start)(sc);
-    splx(s);
 }
 
 #ifdef PPP_COMPRESS
@@ -1081,6 +1084,7 @@ ppppktin(sc, m, lost)
 
 /*
  * Process a received PPP packet, doing decompression as necessary.
+ * Should be called at splnet.
  */
 #define COMPTYPE(proto)        ((proto) == PPP_VJC_COMP? TYPE_COMPRESSED_TCP: \
                         TYPE_UNCOMPRESSED_TCP)
@@ -1100,6 +1104,9 @@ ppp_inproc(sc, m)
     sc->sc_if.if_ipackets++;
 
     if (sc->sc_flags & SC_LOG_INPKT) {
+       ilen = 0;
+       for (mp = m; mp != NULL; mp = mp->m_next)
+           ilen += mp->m_len;
        printf("ppp%d: got %d bytes\n", sc->sc_if.if_unit, ilen);
        pppdumpm(m);
     }
index 5ad17d22572a8d75f0bd72b362c028db643ca410..81ffe925b97f4a1e7c3252bf7aaacb66e930507d 100644 (file)
@@ -70,7 +70,7 @@
  * Paul Mackerras (paulus@cs.anu.edu.au).
  */
 
-/* $Id: ppp_tty.c,v 1.3 1995/08/16 01:36:40 paulus Exp $ */
+/* $Id: ppp_tty.c,v 1.4 1995/10/27 03:34:44 paulus Exp $ */
 /* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */
 
 #include "ppp.h"
@@ -111,7 +111,7 @@ int pppopen __P((dev_t dev, struct tty *tp));
 int    pppclose __P((struct tty *tp, int flag));
 int    pppread __P((struct tty *tp, struct uio *uio, int flag));
 int    pppwrite __P((struct tty *tp, struct uio *uio, int flag));
-int    ppptioctl __P((struct tty *tp, int cmd, caddr_t data, int flag,
+int    ppptioctl __P((struct tty *tp, u_long cmd, caddr_t data, int flag,
                       struct proc *));
 int    pppinput __P((int c, struct tty *tp));
 int    pppstart __P((struct tty *tp));
@@ -171,6 +171,7 @@ TEXT_SET(pseudo_set, pppasyncattach);
 /*
  * Line specific open routine for async tty devices.
  * Attach the given tty to the first available ppp unit.
+ * Called from device open routine or ttioctl.
  */
 /* ARGSUSED */
 int
@@ -185,19 +186,24 @@ pppopen(dev, tp)
     if (error = suser(p->p_ucred, &p->p_acflag))
        return (error);
 
+    s = spltty();
+
     if (tp->t_line == PPPDISC) {
        sc = (struct ppp_softc *) tp->t_sc;
-       if (sc != NULL && sc->sc_devp == (void *) tp)
+       if (sc != NULL && sc->sc_devp == (void *) tp) {
+           splx(s);
            return (0);
+       }
     }
 
-    if ((sc = pppalloc(p->p_pid)) == NULL)
+    if ((sc = pppalloc(p->p_pid)) == NULL) {
+       splx(s);
        return ENXIO;
+    }
 
     if (sc->sc_relinq)
        (*sc->sc_relinq)(sc);   /* get previous owner to relinquish the unit */
 
-    s = splimp();
     sc->sc_ilen = 0;
     sc->sc_m = NULL;
     bzero(sc->sc_asyncmap, sizeof(sc->sc_asyncmap));
@@ -214,13 +220,14 @@ pppopen(dev, tp)
 
     tp->t_sc = (caddr_t) sc;
     ttyflush(tp, FREAD | FWRITE);
-    splx(s);
 
+    splx(s);
     return (0);
 }
 
 /*
- * Line specific close routine.
+ * Line specific close routine, called from device close routine
+ * and from ttioctl.
  * Detach the tty from the ppp unit.
  * Mimics part of ttyclose().
  */
@@ -233,8 +240,8 @@ pppclose(tp, flag)
     struct mbuf *m;
     int s;
 
-    ttywflush(tp);
-    s = splimp();              /* paranoid; splnet probably ok */
+    s = spltty();
+    ttyflush(tp, FREAD|FWRITE);
     tp->t_line = 0;
     sc = (struct ppp_softc *) tp->t_sc;
     if (sc != NULL) {
@@ -257,7 +264,7 @@ pppasyncrelinq(sc)
 {
     int s;
 
-    s = splimp();
+    s = spltty();
     if (sc->sc_outm) {
        m_freem(sc->sc_outm);
        sc->sc_outm = NULL;
@@ -293,7 +300,7 @@ pppread(tp, uio, flag)
      * Loop waiting for input, checking that nothing disasterous
      * happens in the meantime.
      */
-    s = splimp();
+    s = spltty();
     for (;;) {
        if (tp != (struct tty *) sc->sc_devp || tp->t_line != PPPDISC) {
            splx(s);
@@ -301,7 +308,8 @@ pppread(tp, uio, flag)
        }
        if (sc->sc_inq.ifq_head != NULL)
            break;
-       if ((tp->t_state & TS_CONNECTED) == 0 && (tp->t_state & TS_ISOPEN)) {
+       if ((tp->t_state & TS_CARR_ON) == 0 && (tp->t_cflag & CLOCAL) == 0
+           && (tp->t_state & TS_ISOPEN)) {
            splx(s);
            return 0;           /* end of file */
        }
@@ -309,7 +317,7 @@ pppread(tp, uio, flag)
            splx(s);
            return (EWOULDBLOCK);
        }
-       error = ttysleep(tp, TSA_HUP_OR_INPUT(tp), TTIPRI | PCATCH, "pppin", 0);
+       error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI | PCATCH, "ttyin", 0);
        if (error) {
            splx(s);
            return error;
@@ -344,7 +352,7 @@ pppwrite(tp, uio, flag)
     struct sockaddr dst;
     int len, error;
 
-    if ((tp->t_state & TS_CONNECTED) == 0)
+    if ((tp->t_state & TS_CARR_ON) == 0 && (tp->t_cflag & CLOCAL) == 0)
        return 0;               /* wrote 0 bytes */
     if (tp->t_line != PPPDISC)
        return (EINVAL);
@@ -387,8 +395,9 @@ pppwrite(tp, uio, flag)
 int
 ppptioctl(tp, cmd, data, flag, p)
     struct tty *tp;
+    u_long cmd;
     caddr_t data;
-    int cmd, flag;
+    int flag;
     struct proc *p;
 {
     struct ppp_softc *sc = (struct ppp_softc *) tp->t_sc;
@@ -497,7 +506,7 @@ pppfcs(fcs, cp, len)
 
 /*
  * This gets called from pppoutput when a new packet is
- * put on a queue.
+ * put on a queue, at splnet.
  */
 static void
 pppasyncstart(sc)
@@ -506,30 +515,34 @@ pppasyncstart(sc)
     register struct tty *tp = (struct tty *) sc->sc_devp;
     int s;
 
-    s = splimp();
+    s = spltty();
     pppstart(tp);
     splx(s);
 }
 
 /*
  * This gets called when a received packet is placed on
- * the inq.
+ * the inq, at splnet.
  */
 static void
 pppasyncctlp(sc)
     struct ppp_softc *sc;
 {
     struct tty *tp;
+    int s;
 
     /* Put a placeholder byte in canq for ttselect()/ttnread(). */
+    s = spltty();
     tp = (struct tty *) sc->sc_devp;
     putc(0, &tp->t_canq);
     ttwakeup(tp);
+    splx(s);
 }
 
 /*
  * Start output on async tty interface.  Get another datagram
  * to send from the interface queue and start sending it.
+ * Called at spltty or higher.
  */
 int
 pppstart(tp)
@@ -542,7 +555,7 @@ pppstart(tp)
     int n, s, ndone, done, idle;
     struct mbuf *m2;
 
-    if ((tp->t_state & TS_CONNECTED) == 0
+    if ((tp->t_state & TS_CARR_ON) == 0 && (tp->t_cflag & CLOCAL) == 0
        || sc == NULL || tp != (struct tty *) sc->sc_devp) {
        if (tp->t_oproc != NULL)
            (*tp->t_oproc)(tp);
@@ -724,7 +737,7 @@ ppp_timeout(x)
     struct tty *tp = (struct tty *) sc->sc_devp;
     int s;
 
-    s = splimp();
+    s = spltty();
     sc->sc_flags &= ~SC_TIMEOUT;
     pppstart(tp);
     splx(s);
@@ -741,7 +754,7 @@ pppgetm(sc)
     int len;
     int s;
 
-    s = splimp();
+    s = spltty();
     mp = &sc->sc_m;
     for (len = sc->sc_mru + PPP_HDRLEN + PPP_FCSLEN; len > 0; ){
        if ((m = *mp) == NULL) {
@@ -778,7 +791,7 @@ pppinput(c, tp)
     if (sc == NULL || tp != (struct tty *) sc->sc_devp)
        return 0;
 
-    s = spltty();
+    s = spltty();              /* should be unnecessary */
     ++tk_nin;
     ++sc->sc_bytesrcvd;
 
@@ -791,6 +804,22 @@ pppinput(c, tp)
 
     c &= 0xff;
 
+    if (sc->sc_flags & SC_XONXOFF) {
+       if (c == XOFF) {
+           if ((tp->t_state & TS_TTSTOP) == 0) {
+               tp->t_state |= TS_TTSTOP;
+               (*cdevsw[major(tp->t_dev)].d_stop)(tp, 0);
+           }
+           return 0;
+       }
+       if (c == XON) {
+           tp->t_state &= ~TS_TTSTOP;
+           if (tp->t_oproc != NULL)
+               (*tp->t_oproc)(tp);
+           return 0;
+       }
+    }
+
     if (c & 0x80)
        sc->sc_flags |= SC_RCV_B7_1;
     else