conditional kludge for byte swapping -- quiet cmu-stanford mafia
[unix-history] / usr / src / sys / vax / if / if_en.c
index b9fe1c5..f439693 100644 (file)
@@ -1,36 +1,41 @@
-/*     if_en.c 4.51    82/04/04        */
+/*     if_en.c 4.81    83/06/26        */
 
 #include "en.h"
 
 #include "en.h"
-#include "imp.h"
 
 /*
  * Xerox prototype (3 Mb) Ethernet interface driver.
  */
 
 /*
  * Xerox prototype (3 Mb) Ethernet interface driver.
  */
+#include "../machine/pte.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
 
 #include "../h/param.h"
 #include "../h/systm.h"
 #include "../h/mbuf.h"
-#include "../h/pte.h"
 #include "../h/buf.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
 #include "../h/buf.h"
 #include "../h/protosw.h"
 #include "../h/socket.h"
-#include "../h/ubareg.h"
-#include "../h/ubavar.h"
-#include "../h/enreg.h"
-#include "../h/cpu.h"
-#include "../h/mtpr.h"
 #include "../h/vmmac.h"
 #include "../h/vmmac.h"
-#include "../net/in.h"
-#include "../net/in_systm.h"
+#include "../h/errno.h"
+#include "../h/ioctl.h"
+
 #include "../net/if.h"
 #include "../net/if.h"
-#include "../net/if_en.h"
-#include "../net/if_uba.h"
-#include "../net/ip.h"
-#include "../net/ip_var.h"
-#include "../net/pup.h"
+#include "../net/netisr.h"
 #include "../net/route.h"
 #include "../net/route.h"
+#include "../netinet/in.h"
+#include "../netinet/in_systm.h"
+#include "../netinet/ip.h"
+#include "../netinet/ip_var.h"
+#include "../netpup/pup.h"
+
+#include "../vax/cpu.h"
+#include "../vax/mtpr.h"
+#include "../vaxif/if_en.h"
+#include "../vaxif/if_enreg.h"
+#include "../vaxif/if_uba.h"
+#include "../vaxuba/ubareg.h"
+#include "../vaxuba/ubavar.h"
 
 #define        ENMTU   (1024+512)
 
 #define        ENMTU   (1024+512)
+#define        ENMRU   (1024+512+16)           /* 16 is enough to receive trailer */
 
 int    enprobe(), enattach(), enrint(), enxint(), encollide();
 struct uba_device *eninfo[NEN];
 
 int    enprobe(), enattach(), enrint(), enxint(), encollide();
 struct uba_device *eninfo[NEN];
@@ -39,7 +44,15 @@ struct       uba_driver endriver =
        { enprobe, 0, enattach, 0, enstd, "en", eninfo };
 #define        ENUNIT(x)       minor(x)
 
        { enprobe, 0, enattach, 0, enstd, "en", eninfo };
 #define        ENUNIT(x)       minor(x)
 
-int    eninit(),enoutput(),enreset();
+int    eninit(),enoutput(),enreset(),enioctl();
+
+#ifdef notdef
+/*
+ * If you need to byte swap IP's in the system, define
+ * this and do a SIOCSIFFLAGS at boot time.
+ */
+#define        ENF_SWABIPS     0x100
+#endif
 
 /*
  * Ethernet software status per interface.
 
 /*
  * Ethernet software status per interface.
@@ -73,7 +86,6 @@ enprobe(reg)
        register int br, cvec;          /* r11, r10 value-result */
        register struct endevice *addr = (struct endevice *)reg;
 
        register int br, cvec;          /* r11, r10 value-result */
        register struct endevice *addr = (struct endevice *)reg;
 
-COUNT(ENPROBE);
 #ifdef lint
        br = 0; cvec = br; br = cvec;
        enrint(0); enxint(0); encollide(0);
 #ifdef lint
        br = 0; cvec = br; br = cvec;
        enrint(0); enxint(0); encollide(0);
@@ -96,31 +108,21 @@ enattach(ui)
        struct uba_device *ui;
 {
        register struct en_softc *es = &en_softc[ui->ui_unit];
        struct uba_device *ui;
 {
        register struct en_softc *es = &en_softc[ui->ui_unit];
-       register struct sockaddr_in *sin;
-COUNT(ENATTACH);
 
        es->es_if.if_unit = ui->ui_unit;
        es->es_if.if_name = "en";
        es->es_if.if_mtu = ENMTU;
 
        es->es_if.if_unit = ui->ui_unit;
        es->es_if.if_name = "en";
        es->es_if.if_mtu = ENMTU;
-       es->es_if.if_net = ui->ui_flags & 0xff;
-       es->es_if.if_host[0] =
-        (~(((struct endevice *)eninfo[ui->ui_unit]->ui_addr)->en_addr)) & 0xff;
-       sin = (struct sockaddr_in *)&es->es_if.if_addr;
-       sin->sin_family = AF_INET;
-       sin->sin_addr = if_makeaddr(es->es_if.if_net, es->es_if.if_host[0]);
-       sin = (struct sockaddr_in *)&es->es_if.if_broadaddr;
-       sin->sin_family = AF_INET;
-       sin->sin_addr = if_makeaddr(es->es_if.if_net, 0);
-       es->es_if.if_flags = IFF_BROADCAST;
        es->es_if.if_init = eninit;
        es->es_if.if_output = enoutput;
        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 NIMP == 0
-       /* here's one for you john baby.... */
-       enlhinit((ui->ui_flags &~ 0xff) | 0x0a);
+       es->es_if.if_ioctl = enioctl;
+       es->es_if.if_reset = enreset;
+       es->es_ifuba.ifu_flags = UBA_NEEDBDP | UBA_NEED16 | UBA_CANTWAIT;
+#if defined(VAX750)
+       /* don't chew up 750 bdp's */
+       if (cpu == VAX_750 && ui->ui_unit > 0)
+               es->es_ifuba.ifu_flags &= ~UBA_NEEDBDP;
 #endif
 #endif
+       if_attach(&es->es_if);
 }
 
 /*
 }
 
 /*
@@ -131,7 +133,6 @@ enreset(unit, uban)
        int unit, uban;
 {
        register struct uba_device *ui;
        int unit, uban;
 {
        register struct uba_device *ui;
-COUNT(ENRESET);
 
        if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0 ||
            ui->ui_ubanum != uban)
 
        if (unit >= NEN || (ui = eninfo[unit]) == 0 || ui->ui_alive == 0 ||
            ui->ui_ubanum != uban)
@@ -150,10 +151,13 @@ eninit(unit)
        register struct en_softc *es = &en_softc[unit];
        register struct uba_device *ui = eninfo[unit];
        register struct endevice *addr;
        register struct en_softc *es = &en_softc[unit];
        register struct uba_device *ui = eninfo[unit];
        register struct endevice *addr;
+       struct sockaddr_in *sin = (struct sockaddr_in *)&es->es_if.if_addr;
        int s;
 
        int s;
 
+       if (in_netof(sin->sin_addr) == 0)
+               return;
        if (if_ubainit(&es->es_ifuba, ui->ui_ubanum,
        if (if_ubainit(&es->es_ifuba, ui->ui_ubanum,
-           sizeof (struct en_header), (int)btoc(ENMTU)) == 0) { 
+           sizeof (struct en_header), (int)btoc(ENMRU)) == 0) { 
                printf("en%d: can't initialize\n", unit);
                es->es_if.if_flags &= ~IFF_UP;
                return;
                printf("en%d: can't initialize\n", unit);
                es->es_if.if_flags &= ~IFF_UP;
                return;
@@ -167,17 +171,17 @@ eninit(unit)
         */
        s = splimp();
        addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
         */
        s = splimp();
        addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
-       addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1;
+       addr->en_iwc = -(sizeof (struct en_header) + ENMRU) >> 1;
        addr->en_istat = EN_IEN|EN_GO;
        es->es_oactive = 1;
        addr->en_istat = EN_IEN|EN_GO;
        es->es_oactive = 1;
-       es->es_if.if_flags |= IFF_UP;
+       es->es_if.if_flags |= IFF_UP|IFF_RUNNING;
        enxint(unit);
        splx(s);
        enxint(unit);
        splx(s);
-       if_rtinit(&es->es_if, RTF_DIRECT|RTF_UP);
+       if_rtinit(&es->es_if, RTF_UP);
 }
 
 int    enalldelay = 0;
 }
 
 int    enalldelay = 0;
-int    enlastdel = 25;
+int    enlastdel = 50;
 int    enlastmask = (~0) << 5;
 
 /*
 int    enlastmask = (~0) << 5;
 
 /*
@@ -197,7 +201,6 @@ enstart(dev)
        register struct endevice *addr;
        struct mbuf *m;
        int dest;
        register struct endevice *addr;
        struct mbuf *m;
        int dest;
-COUNT(ENSTART);
 
        if (es->es_oactive)
                goto restart;
 
        if (es->es_oactive)
                goto restart;
@@ -214,6 +217,24 @@ COUNT(ENSTART);
        }
        dest = mtod(m, struct en_header *)->en_dhost;
        es->es_olen = if_wubaput(&es->es_ifuba, m);
        }
        dest = mtod(m, struct en_header *)->en_dhost;
        es->es_olen = if_wubaput(&es->es_ifuba, m);
+#ifdef ENF_SWABIPS
+       /*
+        * The Xerox interface does word at a time DMA, so
+        * someone must do byte swapping of user data if high
+        * and low ender machines are to communicate.  It doesn't
+        * belong here, but certain people depend on it, so...
+        *
+        * Should swab everybody, but this is a kludge anyway.
+        */
+       if (es->es_if.if_flags & ENF_SWABIPS) {
+               register struct en_header *en;
+
+               en = (struct en_header *)es->es_ifuba.ifu_w.ifrw_addr;
+               if (en->en_type == ENTYPE_IP)
+                       enswab((caddr_t)(en + 1), (caddr_t)(en + 1),
+                           es->es_olen - sizeof (struct en_header) + 1);
+       }
+#endif
 
        /*
         * Ethernet cannot take back-to-back packets (no
 
        /*
         * Ethernet cannot take back-to-back packets (no
@@ -254,14 +275,11 @@ enxint(unit)
        register struct uba_device *ui = eninfo[unit];
        register struct en_softc *es = &en_softc[unit];
        register struct endevice *addr = (struct endevice *)ui->ui_addr;
        register struct uba_device *ui = eninfo[unit];
        register struct en_softc *es = &en_softc[unit];
        register struct endevice *addr = (struct endevice *)ui->ui_addr;
-COUNT(ENXINT);
 
        if (es->es_oactive == 0)
                return;
        if (es->es_mask && (addr->en_ostat&EN_OERROR)) {
                es->es_if.if_oerrors++;
 
        if (es->es_oactive == 0)
                return;
        if (es->es_mask && (addr->en_ostat&EN_OERROR)) {
                es->es_if.if_oerrors++;
-               if (es->es_if.if_oerrors % 100 == 0)
-                       printf("en%d: += 100 output errors\n", unit);
                endocoll(unit);
                return;
        }
                endocoll(unit);
                return;
        }
@@ -289,7 +307,6 @@ encollide(unit)
        int unit;
 {
        struct en_softc *es = &en_softc[unit];
        int unit;
 {
        struct en_softc *es = &en_softc[unit];
-COUNT(ENCOLLIDE);
 
        es->es_if.if_collisions++;
        if (es->es_oactive == 0)
 
        es->es_if.if_collisions++;
        if (es->es_oactive == 0)
@@ -340,10 +357,9 @@ enrint(unit)
        struct endevice *addr = (struct endevice *)eninfo[unit]->ui_addr;
        register struct en_header *en;
        struct mbuf *m;
        struct endevice *addr = (struct endevice *)eninfo[unit]->ui_addr;
        register struct en_header *en;
        struct mbuf *m;
-       int len, plen; short resid;
+       int len; short resid;
        register struct ifqueue *inq;
        int off;
        register struct ifqueue *inq;
        int off;
-COUNT(ENRINT);
 
        es->es_if.if_ipackets++;
 
 
        es->es_if.if_ipackets++;
 
@@ -354,8 +370,6 @@ 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++;
-               if (es->es_if.if_ierrors % 100 == 0)
-                       printf("en%d: += 100 input errors\n", unit);
                goto setup;
        }
 
                goto setup;
        }
 
@@ -369,19 +383,20 @@ COUNT(ENRINT);
        resid = addr->en_iwc;
        if (resid)
                resid |= 0176000;
        resid = addr->en_iwc;
        if (resid)
                resid |= 0176000;
-       len = (((sizeof (struct en_header) + ENMTU) >> 1) + resid) << 1;
+       len = (((sizeof (struct en_header) + ENMRU) >> 1) + resid) << 1;
        len -= sizeof (struct en_header);
        len -= sizeof (struct en_header);
-       if (len >= ENMTU)
+       if (len > ENMRU)
                goto setup;                     /* sanity */
        en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr);
                goto setup;                     /* sanity */
        en = (struct en_header *)(es->es_ifuba.ifu_r.ifrw_addr);
+       en->en_type = ntohs(en->en_type);
 #define        endataaddr(en, off, type)       ((type)(((caddr_t)((en)+1)+(off))))
 #define        endataaddr(en, off, type)       ((type)(((caddr_t)((en)+1)+(off))))
-       if (en->en_type >= ENPUP_TRAIL &&
-           en->en_type < ENPUP_TRAIL+ENPUP_NTRAILER) {
-               off = (en->en_type - ENPUP_TRAIL) * 512;
-               if (off >= ENMTU)
+       if (en->en_type >= ENTYPE_TRAIL &&
+           en->en_type < ENTYPE_TRAIL+ENTYPE_NTRAILER) {
+               off = (en->en_type - ENTYPE_TRAIL) * 512;
+               if (off > ENMTU)
                        goto setup;             /* sanity */
                        goto setup;             /* sanity */
-               en->en_type = *endataaddr(en, off, u_short *);
-               resid = *(endataaddr(en, off+2, u_short *));
+               en->en_type = ntohs(*endataaddr(en, off, u_short *));
+               resid = ntohs(*(endataaddr(en, off+2, u_short *)));
                if (off + resid > len)
                        goto setup;             /* sanity */
                len = off + resid;
                if (off + resid > len)
                        goto setup;             /* sanity */
                len = off + resid;
@@ -389,6 +404,10 @@ COUNT(ENRINT);
                off = 0;
        if (len == 0)
                goto setup;
                off = 0;
        if (len == 0)
                goto setup;
+#ifdef ENF_SWABIPS
+       if (es->es_if.if_flags & ENF_SWABIPS && en->en_type == ENTYPE_IP)
+               enswab((caddr_t)(en + 1), (caddr_t)(en + 1), len);
+#endif
        /*
         * Pull packet off interface.  Off is nonzero if packet
         * has trailing header; if_rubaget will then force this header
        /*
         * Pull packet off interface.  Off is nonzero if packet
         * has trailing header; if_rubaget will then force this header
@@ -405,20 +424,22 @@ COUNT(ENRINT);
        switch (en->en_type) {
 
 #ifdef INET
        switch (en->en_type) {
 
 #ifdef INET
-       case ENPUP_IPTYPE:
+       case ENTYPE_IP:
                schednetisr(NETISR_IP);
                inq = &ipintrq;
                break;
 #endif
 #ifdef PUP
                schednetisr(NETISR_IP);
                inq = &ipintrq;
                break;
 #endif
 #ifdef PUP
-       case ENPUP_PUPTYPE: {
+       case ENTYPE_PUP: {
                struct pup_header *pup = mtod(m, struct pup_header *);
 
                pupproto.sp_protocol = pup->pup_type;
                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);
+               bcopy((caddr_t)pup->pup_dnet, (caddr_t)pupdst.spup_net,
+                   sizeof (struct pupport));
+               bcopy((caddr_t)pup->pup_snet, (caddr_t)pupsrc.spup_net,
+                   sizeof (struct pupport));
+               raw_input(m, &pupproto, (struct sockaddr *)&pupsrc,
+                 (struct sockaddr *)&pupdst);
                goto setup;
        }
 #endif
                goto setup;
        }
 #endif
@@ -438,7 +459,7 @@ setup:
         * Reset for next packet.
         */
        addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
         * Reset for next packet.
         */
        addr->en_iba = es->es_ifuba.ifu_r.ifrw_info;
-       addr->en_iwc = -(sizeof (struct en_header) + ENMTU) >> 1;
+       addr->en_iwc = -(sizeof (struct en_header) + ENMRU) >> 1;
        addr->en_istat = EN_IEN|EN_GO;
 }
 
        addr->en_istat = EN_IEN|EN_GO;
 }
 
@@ -453,35 +474,41 @@ enoutput(ifp, m0, dst)
        struct mbuf *m0;
        struct sockaddr *dst;
 {
        struct mbuf *m0;
        struct sockaddr *dst;
 {
-       int type, dest, s;
+       int type, dest, s, error;
        register struct mbuf *m = m0;
        register struct en_header *en;
        register int off;
 
        register struct mbuf *m = m0;
        register struct en_header *en;
        register int off;
 
-COUNT(ENOUTPUT);
        switch (dst->sa_family) {
 
 #ifdef INET
        case AF_INET:
        switch (dst->sa_family) {
 
 #ifdef INET
        case AF_INET:
-               dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr >> 24;
+               dest = ((struct sockaddr_in *)dst)->sin_addr.s_addr;
+               if (in_lnaof(*((struct in_addr *)&dest)) >= 0x100) {
+                       error = EPERM;          /* ??? */
+                       goto bad;
+               }
+               dest = (dest >> 24) & 0xff;
                off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
                off = ntohs((u_short)mtod(m, struct ip *)->ip_len) - m->m_len;
+               /* need per host negotiation */
+               if ((ifp->if_flags & IFF_NOTRAILERS) == 0)
                if (off > 0 && (off & 0x1ff) == 0 &&
                    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
                if (off > 0 && (off & 0x1ff) == 0 &&
                    m->m_off >= MMINOFF + 2 * sizeof (u_short)) {
-                       type = ENPUP_TRAIL + (off>>9);
+                       type = ENTYPE_TRAIL + (off>>9);
                        m->m_off -= 2 * sizeof (u_short);
                        m->m_len += 2 * sizeof (u_short);
                        m->m_off -= 2 * sizeof (u_short);
                        m->m_len += 2 * sizeof (u_short);
-                       *mtod(m, u_short *) = ENPUP_IPTYPE;
-                       *(mtod(m, u_short *) + 1) = m->m_len;
+                       *mtod(m, u_short *) = htons((u_short)ENTYPE_IP);
+                       *(mtod(m, u_short *) + 1) = ntohs((u_short)m->m_len);
                        goto gottrailertype;
                }
                        goto gottrailertype;
                }
-               type = ENPUP_IPTYPE;
+               type = ENTYPE_IP;
                off = 0;
                goto gottype;
 #endif
 #ifdef PUP
        case AF_PUP:
                off = 0;
                goto gottype;
 #endif
 #ifdef PUP
        case AF_PUP:
-               dest = ((struct sockaddr_pup *)dst)->spup_addr.pp_host;
-               type = ENPUP_PUPTYPE;
+               dest = ((struct sockaddr_pup *)dst)->spup_host;
+               type = ENTYPE_PUP;
                off = 0;
                goto gottype;
 #endif
                off = 0;
                goto gottype;
 #endif
@@ -489,8 +516,8 @@ COUNT(ENOUTPUT);
        default:
                printf("en%d: can't handle af%d\n", ifp->if_unit,
                        dst->sa_family);
        default:
                printf("en%d: can't handle af%d\n", ifp->if_unit,
                        dst->sa_family);
-               m_freem(m0);
-               return (0);
+               error = EAFNOSUPPORT;
+               goto bad;
        }
 
 gottrailertype:
        }
 
 gottrailertype:
@@ -512,10 +539,10 @@ 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(M_DONTWAIT);
+               m = m_get(M_DONTWAIT, MT_HEADER);
                if (m == 0) {
                if (m == 0) {
-                       m_freem(m0);
-                       return (0);
+                       error = ENOBUFS;
+                       goto bad;
                }
                m->m_next = m0;
                m->m_off = MMINOFF;
                }
                m->m_next = m0;
                m->m_off = MMINOFF;
@@ -527,7 +554,7 @@ gottype:
        en = mtod(m, struct en_header *);
        en->en_shost = ifp->if_host[0];
        en->en_dhost = dest;
        en = mtod(m, struct en_header *);
        en->en_shost = ifp->if_host[0];
        en->en_dhost = dest;
-       en->en_type = type;
+       en->en_type = htons((u_short)type);
 
        /*
         * Queue message on interface, and start output if interface
 
        /*
         * Queue message on interface, and start output if interface
@@ -536,61 +563,90 @@ gottype:
        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);
-               m_freem(m);
-               splx(s);
-               return (0);
+               error = ENOBUFS;
+               goto qfull;
        }
        IF_ENQUEUE(&ifp->if_snd, m);
        if (en_softc[ifp->if_unit].es_oactive == 0)
                enstart(ifp->if_unit);
        splx(s);
        }
        IF_ENQUEUE(&ifp->if_snd, m);
        if (en_softc[ifp->if_unit].es_oactive == 0)
                enstart(ifp->if_unit);
        splx(s);
-       return (1);
+       return (0);
+qfull:
+       m0 = m;
+       splx(s);
+bad:
+       m_freem(m0);
+       return (error);
 }
 
 }
 
-#if NIMP == 0 && NEN > 0
 /*
 /*
- * Logical host interface driver.
- * Allows host to appear as an ARPAnet
- * logical host.  Must also have routing
- * table entry set up to forward packets
- * to appropriate gateway on localnet.
+ * Process an ioctl request.
  */
  */
+enioctl(ifp, cmd, data)
+       register struct ifnet *ifp;
+       int cmd;
+       caddr_t data;
+{
+       struct ifreq *ifr = (struct ifreq *)data;
+       int s = splimp(), error = 0;
+
+       switch (cmd) {
+
+       case SIOCSIFADDR:
+               if (ifp->if_flags & IFF_RUNNING)
+                       if_rtinit(ifp, -1);     /* delete previous route */
+               ensetaddr(ifp, (struct sockaddr_in *)&ifr->ifr_addr);
+               if (ifp->if_flags & IFF_RUNNING)
+                       if_rtinit(ifp, RTF_UP);
+               else
+                       eninit(ifp->if_unit);
+               break;
 
 
-struct ifnet enlhif;
-int    enlhoutput();
+       default:
+               error = EINVAL;
+       }
+       splx(s);
+       return (error);
+}
 
 
-/*
- * Called by localnet interface to allow logical
- * host interface to "attach".  Nothing should ever
- * be sent locally to this interface, it's purpose
- * is simply to establish the host's arpanet address.
- */
-enlhinit(addr)
-       int addr;
-{
-       register struct ifnet *ifp = &enlhif;
+ensetaddr(ifp, sin)
+       register struct ifnet *ifp;
        register struct sockaddr_in *sin;
        register struct sockaddr_in *sin;
+{
+       struct endevice *enaddr;
 
 
-COUNT(ENLHINIT);
-       ifp->if_name = "lh";
-       ifp->if_mtu = ENMTU;
+       ifp->if_net = in_netof(sin->sin_addr);
+       enaddr = (struct endevice *)eninfo[ifp->if_unit]->ui_addr;
+       ifp->if_host[0] = (~enaddr->en_addr) & 0xff;
        sin = (struct sockaddr_in *)&ifp->if_addr;
        sin->sin_family = AF_INET;
        sin = (struct sockaddr_in *)&ifp->if_addr;
        sin->sin_family = AF_INET;
-       sin->sin_addr.s_addr = addr;
-       ifp->if_net = sin->sin_addr.s_net;
-       ifp->if_flags = IFF_UP;
-       ifp->if_output = enlhoutput;    /* should never be used */
-       if_attach(ifp);
+       sin->sin_addr = if_makeaddr(ifp->if_net, ifp->if_host[0]);
+       sin = (struct sockaddr_in *)&ifp->if_broadaddr;
+       sin->sin_family = AF_INET;
+       sin->sin_addr = if_makeaddr(ifp->if_net, INADDR_ANY);
+       ifp->if_flags |= IFF_BROADCAST;
 }
 
 }
 
-enlhoutput(ifp, m0, dst)
-       struct ifnet *ifp;
-       struct mbuf *m0;
-       struct sockaddr *dst;
+#ifdef ENF_SWABIPS
+/*
+ * Swab bytes
+ * Jeffrey Mogul, Stanford
+ */
+enswab(from, to, n)
+       register caddr_t *from, *to;
+       register int n;
 {
 {
-COUNT(ENLHOUTPUT);
-       ifp->if_oerrors++;
-       m_freem(m0);
-       return (0);
+       register unsigned long temp;
+       
+       n >>= 1; n++;
+#define        STEP    temp = *from++,*to++ = *from++,*to++ = temp
+       /* round to multiple of 8 */
+       while ((--n) & 07)
+               STEP;
+       n >>= 3;
+       while (--n >= 0) {
+               STEP; STEP; STEP; STEP;
+               STEP; STEP; STEP; STEP;
+       }
 }
 #endif
 }
 #endif