MCLALLOC must be called at splimp
[unix-history] / usr / src / sys / net / if_sl.c
index a21e972..aa73143 100644 (file)
@@ -1,4 +1,4 @@
-/*     @(#)if_sl.c     5.3 (Berkeley) %G% */
+/*     @(#)if_sl.c     7.2 (Berkeley) %G% */
 
 /*
  * Serial Line interface
 
 /*
  * Serial Line interface
@@ -42,8 +42,8 @@
 #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
 
 #ifdef vax
 #endif
 
 #ifdef vax
@@ -201,6 +201,10 @@ sloutput(ifp, m, dst)
                m_freem(m);
                return (ENETDOWN);      /* sort of */
        }
                m_freem(m);
                return (ENETDOWN);      /* sort of */
        }
+       if ((sc->sc_ttyp->t_state & TS_CARR_ON) == 0) {
+               m_freem(m);
+               return (EHOSTUNREACH);
+       }
        s = splimp();
        if (IF_QFULL(&ifp->if_snd)) {
                IF_DROP(&ifp->if_snd);
        s = splimp();
        if (IF_QFULL(&ifp->if_snd)) {
                IF_DROP(&ifp->if_snd);
@@ -300,6 +304,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,
@@ -345,7 +351,10 @@ slinit(sc)
        struct mbuf *p;
 
        if (sc->sc_buf == (char *) 0) {
        struct mbuf *p;
 
        if (sc->sc_buf == (char *) 0) {
+               int s = splimp();
+
                MCLALLOC(p, 1);
                MCLALLOC(p, 1);
+               splx(s);
                if (p) {
                        sc->sc_buf = (char *)p;
                        sc->sc_mp = sc->sc_buf + sizeof(struct ifnet *);
                if (p) {
                        sc->sc_buf = (char *)p;
                        sc->sc_mp = sc->sc_buf + sizeof(struct ifnet *);
@@ -394,7 +403,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,
@@ -490,7 +499,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;