print only occasional error messages
[unix-history] / usr / src / sys / vax / if / if_en.c
index a57a698..685c53a 100644 (file)
@@ -1,4 +1,4 @@
-/*     if_en.c 4.24    81/12/22        */
+/*     if_en.c 4.41    82/03/15        */
 
 #include "en.h"
 
 
 #include "en.h"
 
@@ -26,6 +26,7 @@
 #include "../net/if_uba.h"
 #include "../net/ip.h"
 #include "../net/ip_var.h"
 #include "../net/if_uba.h"
 #include "../net/ip.h"
 #include "../net/ip_var.h"
+#include "../net/pup.h"
 
 #define        ENMTU   (1024+512)
 
 
 #define        ENMTU   (1024+512)
 
@@ -101,11 +102,20 @@ COUNT(ENATTACH);
        es->es_if.if_net = ui->ui_flags;
        es->es_if.if_host[0] =
            (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff;
        es->es_if.if_net = ui->ui_flags;
        es->es_if.if_host[0] =
            (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff;
+#ifdef ENKLUDGE
+       if (es->es_if.if_net == 10) {
+               es->es_if.if_host[0] <<= 16;
+               es->es_if.if_host[0] |= 0x4e;
+       }
+#endif
        es->es_if.if_addr =
            if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]);
        es->es_if.if_addr =
            if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]);
+       es->es_if.if_broadaddr =
+           if_makeaddr(es->es_if.if_net, 0);
        es->es_if.if_init = eninit;
        es->es_if.if_output = enoutput;
        es->es_if.if_ubareset = enreset;
        es->es_if.if_init = eninit;
        es->es_if.if_output = enoutput;
        es->es_if.if_ubareset = enreset;
+       es->es_ifuba.ifu_flags = UBA_NEEDBDP | UBA_NEED16;
        if_attach(&es->es_if);
 }
 
        if_attach(&es->es_if);
 }
 
@@ -139,7 +149,7 @@ eninit(unit)
        int s;
 
        if (if_ubainit(&es->es_ifuba, ui->ui_ubanum,
        int s;
 
        if (if_ubainit(&es->es_ifuba, ui->ui_ubanum,
-           sizeof (struct en_header), (int)btop(ENMTU)) == 0) { 
+           sizeof (struct en_header), (int)btoc(ENMTU)) == 0) { 
                printf("en%d: can't initialize\n", unit);
                return;
        }
                printf("en%d: can't initialize\n", unit);
                return;
        }
@@ -242,13 +252,14 @@ COUNT(ENXINT);
        es->es_mask = ~0;
        if (addr->en_ostat&EN_OERROR) {
                es->es_if.if_oerrors++;
        es->es_mask = ~0;
        if (addr->en_ostat&EN_OERROR) {
                es->es_if.if_oerrors++;
-               printf("en%d: output error\n", unit);
+               if (es->es_if.if_oerrors % 100 == 0)
+                       printf("en%d: += 100 output errors\n", unit);
+       }
+       if (es->es_ifuba.ifu_xtofree) {
+               m_freem(es->es_ifuba.ifu_xtofree);
+               es->es_ifuba.ifu_xtofree = 0;
        }
        if (es->es_if.if_snd.ifq_head == 0) {
        }
        if (es->es_if.if_snd.ifq_head == 0) {
-               if (es->es_ifuba.ifu_xtofree) {
-                       m_freem(es->es_ifuba.ifu_xtofree);
-                       es->es_ifuba.ifu_xtofree = 0;
-               }
                es->es_lastx = 0;
                return;
        }
                es->es_lastx = 0;
                return;
        }
@@ -288,6 +299,9 @@ COUNT(ENCOLLIDE);
        enstart(unit);
 }
 
        enstart(unit);
 }
 
+struct sockaddr_pup pupsrc = { AF_PUP };
+struct sockaddr_pup pupdst = { AF_PUP };
+struct sockproto pupproto = { PF_PUP };
 /*
  * Ethernet interface receiver interrupt.
  * If input error just drop packet.
 /*
  * Ethernet interface receiver interrupt.
  * If input error just drop packet.
@@ -317,7 +331,8 @@ COUNT(ENRINT);
        UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp);
        if (addr->en_istat&EN_IERROR) {
                es->es_if.if_ierrors++;
        UBAPURGE(es->es_ifuba.ifu_uba, es->es_ifuba.ifu_r.ifrw_bdp);
        if (addr->en_istat&EN_IERROR) {
                es->es_if.if_ierrors++;
-               printf("en%d: input error\n", unit);
+               if (es->es_if.if_ierrors % 100 == 0)
+                       printf("en%d: += 100 input errors\n", unit);
                goto setup;
        }
 
                goto setup;
        }
 
@@ -349,13 +364,18 @@ COUNT(ENRINT);
                len = htons((u_short)endataaddr(en, off ? off+2 : 0, struct ip *)->ip_len);
                if (off)
                        len += 2;
                len = htons((u_short)endataaddr(en, off ? off+2 : 0, struct ip *)->ip_len);
                if (off)
                        len += 2;
-               setipintr();
-               inq = &ipintrq;
                break;
 #endif
                break;
 #endif
-
+#ifdef PUP
+       case ENPUP_PUPTYPE:
+               len = endataaddr(en, off, struct pup_header *)->pup_length;
+               if (off)
+                       len -= 2;
+               break;
+#endif
+               
        default:
        default:
-               printf("en%d: unknow pkt type 0x%x\n", en->en_type);
+               printf("en%d: unknown pkt type 0x%x\n", unit, en->en_type);
                goto setup;
        }
        if (len == 0)
                goto setup;
        }
        if (len == 0)
@@ -374,7 +394,30 @@ COUNT(ENRINT);
                m->m_off += 2;
                m->m_len -= 2;
        }
                m->m_off += 2;
                m->m_len -= 2;
        }
-       IF_ENQUEUE(inq, m);
+       switch (en->en_type) {
+
+#ifdef INET
+       case ENPUP_IPTYPE:
+               setipintr();
+               inq = &ipintrq;
+               break;
+#endif
+       case ENPUP_PUPTYPE: {
+               struct pup_header *pup = mtod(m, struct pup_header *);
+
+               pupproto.sp_protocol = pup->pup_type;
+               pupdst.spup_addr = pup->pup_dport;
+               pupsrc.spup_addr = pup->pup_sport;
+               raw_input(m, &pupproto, (struct sockaddr *)&pupdst,
+                (struct sockaddr *)&pupsrc);
+               goto setup;
+               }
+       }
+       if (IF_QFULL(inq)) {
+               IF_DROP(inq);
+               (void) m_freem(m);
+       } else
+               IF_ENQUEUE(inq, m);
 
 setup:
        /*
 
 setup:
        /*
@@ -396,20 +439,24 @@ enoutput(ifp, m0, pf)
        struct mbuf *m0;
        int pf;
 {
        struct mbuf *m0;
        int pf;
 {
-       int type, dest;
+       int type, dest, s, off;
        register struct mbuf *m = m0;
        register struct en_header *en;
        register struct mbuf *m = m0;
        register struct en_header *en;
-       int s;
 
 
+COUNT(ENOUTPUT);
        switch (pf) {
 
 #ifdef INET
        case PF_INET: {
                register struct ip *ip = mtod(m0, struct ip *);
        switch (pf) {
 
 #ifdef INET
        case PF_INET: {
                register struct ip *ip = mtod(m0, struct ip *);
-               int off;
 
 
+#ifndef ENKLUDGE
                dest = ip->ip_dst.s_addr >> 24;
                dest = ip->ip_dst.s_addr >> 24;
+#else
+               dest = (ip->ip_dst.s_addr >> 8) & 0xff;
+#endif
                off = ntohs((u_short)ip->ip_len) - m->m_len;
                off = ntohs((u_short)ip->ip_len) - m->m_len;
+#ifndef ENKLUDGE
                if (off > 0 && (off & 0x1ff) == 0 && m->m_off >= MMINOFF + 2) {
                        type = ENPUP_TRAIL + (off>>9);
                        m->m_off -= 2;
                if (off > 0 && (off & 0x1ff) == 0 && m->m_off >= MMINOFF + 2) {
                        type = ENPUP_TRAIL + (off>>9);
                        m->m_off -= 2;
@@ -417,11 +464,30 @@ enoutput(ifp, m0, pf)
                        *mtod(m, u_short *) = ENPUP_IPTYPE;
                        goto gottrailertype;
                }
                        *mtod(m, u_short *) = ENPUP_IPTYPE;
                        goto gottrailertype;
                }
+#endif
                type = ENPUP_IPTYPE;
                off = 0;
                goto gottype;
                }
 #endif
                type = ENPUP_IPTYPE;
                off = 0;
                goto gottype;
                }
 #endif
+#ifdef PUP
+       case PF_PUP: {
+               register struct pup_header *pup = mtod(m, struct pup_header *);
+
+               dest = pup->pup_dhost;
+               off = pup->pup_length - m->m_len;
+               if (off > 0 && (off & 0x1ff) == 0 && m->m_off >= MMINOFF + 2) {
+                       type = ENPUP_TRAIL + (off>>9);
+                       m->m_off -= 2;
+                       m->m_len += 2;
+                       *mtod(m, u_short *) = ENPUP_PUPTYPE;
+                       goto gottrailertype;
+               }
+               type = ENPUP_PUPTYPE;
+               off = 0;
+               goto gottype;
+               }
+#endif
 
        default:
                printf("en%d: can't encapsulate pf%d\n", ifp->if_unit, pf);
 
        default:
                printf("en%d: can't encapsulate pf%d\n", ifp->if_unit, pf);
@@ -448,7 +514,7 @@ gottype:
         */
        if (m->m_off > MMAXOFF ||
            MMINOFF + sizeof (struct en_header) > m->m_off) {
         */
        if (m->m_off > MMAXOFF ||
            MMINOFF + sizeof (struct en_header) > m->m_off) {
-               m = m_get(0);
+               m = m_get(M_DONTWAIT);
                if (m == 0) {
                        m_freem(m0);
                        return (0);
                if (m == 0) {
                        m_freem(m0);
                        return (0);
@@ -470,6 +536,12 @@ gottype:
         * not yet active.
         */
        s = splimp();
         * not yet active.
         */
        s = splimp();
+       if (IF_QFULL(&ifp->if_snd)) {
+               IF_DROP(&ifp->if_snd);
+               m_freem(m);
+               splx(s);
+               return (0);
+       }
        IF_ENQUEUE(&ifp->if_snd, m);
        if (en_softc[ifp->if_unit].es_oactive == 0)
                enstart(ifp->if_unit);
        IF_ENQUEUE(&ifp->if_snd, m);
        if (en_softc[ifp->if_unit].es_oactive == 0)
                enstart(ifp->if_unit);