branch for network release (dk.h for dkstat.h XXX)
[unix-history] / usr / src / sys / net / if_sl.c
index f59d19a..52ee29d 100644 (file)
@@ -1,4 +1,16 @@
-/*     @(#)if_sl.c     5.4 (Berkeley) %G% */
+/*
+ * Copyright (c) 1987 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is given
+ * to the University of California at Berkeley. The name of the University
+ * may not be used to endorse or promote products derived from this
+ * software without specific prior written permission. This software
+ * is provided ``as is'' without express or implied warranty.
+ *
+ *     @(#)if_sl.c     7.6.1.1 (Berkeley) %G%
+ */
 
 /*
  * Serial Line interface
 
 /*
  * Serial Line interface
 #if INET
 #include "../netinet/in.h"
 #include "../netinet/in_systm.h"
 #if INET
 #include "../netinet/in.h"
 #include "../netinet/in_systm.h"
+#include "../netinet/in_var.h"
 #include "../netinet/ip.h"
 #include "../netinet/ip.h"
-#include "../netinet/ip_var.h"
 #endif
 
 #endif
 
-#ifdef vax
-#include "../vax/mtpr.h"
-#endif vax
+#include "../machine/mtpr.h"
 
 /*
  * N.B.: SLMTU is now a hard limit on input packet size.
 
 /*
  * N.B.: SLMTU is now a hard limit on input packet size.
@@ -69,7 +79,6 @@ struct sl_softc {
 
 /* flags */
 #define        SC_ESCAPED      0x0001  /* saw a FRAME_ESCAPE */
 
 /* flags */
 #define        SC_ESCAPED      0x0001  /* saw a FRAME_ESCAPE */
-#define        SC_OACTIVE      0x0002  /* output tty is active */
 
 #define FRAME_END              0300            /* Frame End */
 #define FRAME_ESCAPE           0333            /* Frame Esc */
 
 #define FRAME_END              0300            /* Frame End */
 #define FRAME_ESCAPE           0333            /* Frame Esc */
@@ -214,7 +223,7 @@ sloutput(ifp, m, dst)
                return (ENOBUFS);
        }
        IF_ENQUEUE(&ifp->if_snd, m);
                return (ENOBUFS);
        }
        IF_ENQUEUE(&ifp->if_snd, m);
-       if ((sc->sc_flags & SC_OACTIVE) == 0) {
+       if (sc->sc_ttyp->t_outq.c_cc == 0) {
                splx(s);
                slstart(sc->sc_ttyp);
        } else
                splx(s);
                slstart(sc->sc_ttyp);
        } else
@@ -234,7 +243,7 @@ slstart(tp)
        register struct mbuf *m;
        register int len;
        register u_char *cp;
        register struct mbuf *m;
        register int len;
        register u_char *cp;
-       int flush, nd, np, n, s;
+       int nd, np, n, s;
        struct mbuf *m2;
        extern int cfreecount;
 
        struct mbuf *m2;
        extern int cfreecount;
 
@@ -259,8 +268,7 @@ slstart(tp)
                 * If system is getting low on clists
                 * and we have something running already, stop here.
                 */
                 * If system is getting low on clists
                 * and we have something running already, stop here.
                 */
-               if (cfreecount < CLISTRESERVE + SLMTU &&
-                   sc->sc_flags & SC_OACTIVE)
+               if (cfreecount < CLISTRESERVE + SLMTU && tp->t_outq.c_cc == 0)
                        return;
 
                /*
                        return;
 
                /*
@@ -268,22 +276,16 @@ slstart(tp)
                 */
                s = splimp();
                IF_DEQUEUE(&sc->sc_if.if_snd, m);
                 */
                s = splimp();
                IF_DEQUEUE(&sc->sc_if.if_snd, m);
-               if (m == NULL) {
-                       if (tp->t_outq.c_cc == 0)
-                               sc->sc_flags &= ~SC_OACTIVE;
-                       splx(s);
-                       return;
-               }
-               flush = !(sc->sc_flags & SC_OACTIVE);
-               sc->sc_flags |= SC_OACTIVE;
                splx(s);
                splx(s);
+               if (m == NULL)
+                       return;
 
                /*
                 * The extra FRAME_END will start up a new packet, and thus
                 * will flush any accumulated garbage.  We do this whenever
                 * the line may have been idle for some time.
                 */
 
                /*
                 * The extra FRAME_END will start up a new packet, and thus
                 * will flush any accumulated garbage.  We do this whenever
                 * the line may have been idle for some time.
                 */
-               if (flush)
+               if (tp->t_outq.c_cc == 0)
                        (void) putc(FRAME_END, &tp->t_outq);
 
                while (m) {
                        (void) putc(FRAME_END, &tp->t_outq);
 
                while (m) {
@@ -304,6 +306,8 @@ slstart(tp)
                                         */
                                        if (b_to_q((char *)cp, n, &tp->t_outq))
                                                break;
                                         */
                                        if (b_to_q((char *)cp, n, &tp->t_outq))
                                                break;
+                                       len -= n;
+                                       cp += n;
                                }
                                /*
                                 * If there are characters left in the mbuf,
                                }
                                /*
                                 * If there are characters left in the mbuf,
@@ -398,7 +402,7 @@ sl_btom(sc, len, ifp)
                        if (m->m_len == CLBYTES) {
                                cp = mtod(m, char *);
                                m->m_off = (int)sc->sc_buf - (int)m;
                        if (m->m_len == CLBYTES) {
                                cp = mtod(m, char *);
                                m->m_off = (int)sc->sc_buf - (int)m;
-                               sc->sc_buf = mtod(m, char *);
+                               sc->sc_buf = cp;
                                if (ifp) {
                                        m->m_off += sizeof(ifp);
                                        count = MIN(len,
                                if (ifp) {
                                        m->m_off += sizeof(ifp);
                                        count = MIN(len,
@@ -494,7 +498,7 @@ slinput(c, tp)
                        return;
                }
        }
                        return;
                }
        }
-       if (++sc->sc_ilen >= SLMTU) {
+       if (++sc->sc_ilen > SLMTU) {
                sc->sc_if.if_ierrors++;
                sc->sc_mp = sc->sc_buf + sizeof(struct ifnet *);
                sc->sc_ilen = 0;
                sc->sc_if.if_ierrors++;
                sc->sc_mp = sc->sc_buf + sizeof(struct ifnet *);
                sc->sc_ilen = 0;