BSD 4_3 release
[unix-history] / usr / src / sys / netimp / if_imp.c
index fb08167..24c2e4e 100644 (file)
@@ -1,4 +1,10 @@
-/*     if_imp.c        6.1     83/07/29        */
+/*
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)if_imp.c    7.1 (Berkeley) 6/4/86
+ */
 
 #include "imp.h"
 #if NIMP > 0
 
 #include "imp.h"
 #if NIMP > 0
  *
  * The IMP-host protocol is handled here, leaving
  * hardware specifics to the lower level interface driver.
  *
  * The IMP-host protocol is handled here, leaving
  * hardware specifics to the lower level interface driver.
- *
- * NB: only handles IMPS on class A networks.
  */
 #include "../machine/pte.h"
 
  */
 #include "../machine/pte.h"
 
-#include "../h/param.h"
-#include "../h/systm.h"
-#include "../h/mbuf.h"
-#include "../h/buf.h"
-#include "../h/protosw.h"
-#include "../h/socket.h"
-#include "../h/vmmac.h"
-#include "../h/time.h"
-#include "../h/kernel.h"
-#include "../h/errno.h"
-#include "../h/ioctl.h"
+#include "param.h"
+#include "systm.h"
+#include "mbuf.h"
+#include "buf.h"
+#include "protosw.h"
+#include "socket.h"
+#include "vmmac.h"
+#include "time.h"
+#include "kernel.h"
+#include "errno.h"
+#include "ioctl.h"
 
 #include "../vax/cpu.h"
 #include "../vax/mtpr.h"
 
 #include "../vax/cpu.h"
 #include "../vax/mtpr.h"
 #include "../net/netisr.h"
 #include "../netinet/in.h"
 #include "../netinet/in_systm.h"
 #include "../net/netisr.h"
 #include "../netinet/in.h"
 #include "../netinet/in_systm.h"
+#include "../netinet/in_var.h"
 #include "../netinet/ip.h"
 #include "../netinet/ip_var.h"
 /* define IMPLEADERS here to get leader printing code */
 #include "../netinet/ip.h"
 #include "../netinet/ip_var.h"
 /* define IMPLEADERS here to get leader printing code */
-#include "../netimp/if_imp.h"
-#include "../netimp/if_imphost.h"
+#include "if_imp.h"
+#include "if_imphost.h"
 
 /*
  * IMP software status per interface.
 
 /*
  * IMP software status per interface.
@@ -63,6 +68,9 @@ struct imp_softc {
        char    imp_dropcnt;            /* used during initialization */
 } imp_softc[NIMP];
 
        char    imp_dropcnt;            /* used during initialization */
 } imp_softc[NIMP];
 
+struct ifqueue impintrq;
+int    impqmaxlen = IFQ_MAXLEN;
+
 /*
  * Messages from IMP regarding why
  * it's going down.
 /*
  * Messages from IMP regarding why
  * it's going down.
@@ -74,6 +82,8 @@ static char *impmessage[] = {
        "for emergency reset"
 };
 
        "for emergency reset"
 };
 
+#define HOSTDEADTIMER  10              /* How long to wait when down */
+
 int    impdown(), impinit(), impioctl(), impoutput();
 
 /*
 int    impdown(), impinit(), impioctl(), impoutput();
 
 /*
@@ -87,9 +97,18 @@ impattach(ui, reset)
        struct uba_device *ui;
        int (*reset)();
 {
        struct uba_device *ui;
        int (*reset)();
 {
-       struct imp_softc *sc = &imp_softc[ui->ui_unit];
-       register struct ifnet *ifp = &sc->imp_if;
+       struct imp_softc *sc;
+       register struct ifnet *ifp;
 
 
+#ifdef lint
+       impintr();
+#endif
+       if (ui->ui_unit >= NIMP) {
+               printf("imp%d: not configured\n", ui->ui_unit);
+               return (0);
+       }
+       sc = &imp_softc[ui->ui_unit];
+       ifp = &sc->imp_if;
        /* UNIT COULD BE AMBIGUOUS */
        ifp->if_unit = ui->ui_unit;
        ifp->if_name = "imp";
        /* UNIT COULD BE AMBIGUOUS */
        ifp->if_unit = ui->ui_unit;
        ifp->if_name = "imp";
@@ -100,7 +119,7 @@ impattach(ui, reset)
        ifp->if_output = impoutput;
        /* reset is handled at the hardware level */
        if_attach(ifp);
        ifp->if_output = impoutput;
        /* reset is handled at the hardware level */
        if_attach(ifp);
-       return ((int)&sc->imp_if);
+       return ((int)ifp);
 }
 
 /*
 }
 
 /*
@@ -113,10 +132,8 @@ impinit(unit)
 {
        int s = splimp();
        register struct imp_softc *sc = &imp_softc[unit];
 {
        int s = splimp();
        register struct imp_softc *sc = &imp_softc[unit];
-       struct sockaddr_in *sin;
 
 
-       sin = (struct sockaddr_in *)&sc->imp_if.if_addr;
-       if (in_netof(sin->sin_addr) == 0)
+       if (sc->imp_if.if_addrlist == 0)
                return;
        if ((*sc->imp_cb.ic_init)(unit) == 0) {
                sc->imp_state = IMPS_DOWN;
                return;
        if ((*sc->imp_cb.ic_init)(unit) == 0) {
                sc->imp_state = IMPS_DOWN;
@@ -124,15 +141,12 @@ impinit(unit)
                splx(s);
                return;
        }
                splx(s);
                return;
        }
-       sc->imp_if.if_flags |= IFF_RUNNING;
        sc->imp_state = IMPS_INIT;
        impnoops(sc);
        sc->imp_state = IMPS_INIT;
        impnoops(sc);
+       impintrq.ifq_maxlen = impqmaxlen;
        splx(s);
 }
 
        splx(s);
 }
 
-struct sockproto impproto = { PF_IMPLINK };
-struct sockaddr_in impdst = { AF_IMPLINK };
-struct sockaddr_in impsrc = { AF_IMPLINK };
 #ifdef IMPLEADERS
 int    impprintfs = 0;
 #endif
 #ifdef IMPLEADERS
 int    impprintfs = 0;
 #endif
@@ -150,6 +164,7 @@ impinput(unit, m)
 {
        register struct imp_leader *ip;
        register struct imp_softc *sc = &imp_softc[unit];
 {
        register struct imp_leader *ip;
        register struct imp_softc *sc = &imp_softc[unit];
+       struct ifnet *ifp;
        register struct host *hp;
        register struct ifqueue *inq;
        struct control_leader *cp;
        register struct host *hp;
        register struct ifqueue *inq;
        struct control_leader *cp;
@@ -157,6 +172,12 @@ impinput(unit, m)
        struct mbuf *next;
        struct sockaddr_in *sin;
 
        struct mbuf *next;
        struct sockaddr_in *sin;
 
+       /*
+        * Pull the interface pointer out of the mbuf
+        * and save for later; adjust mbuf to look at rest of data.
+        */
+       ifp = *(mtod(m, struct ifnet **));
+       IF_ADJ(m);
        /* verify leader length. */
        if (m->m_len < sizeof(struct control_leader) &&
            (m = m_pullup(m, sizeof(struct control_leader))) == 0)
        /* verify leader length. */
        if (m->m_len < sizeof(struct control_leader) &&
            (m = m_pullup(m, sizeof(struct control_leader))) == 0)
@@ -171,25 +192,40 @@ impinput(unit, m)
        if (impprintfs)
                printleader("impinput", ip);
 #endif
        if (impprintfs)
                printleader("impinput", ip);
 #endif
+       inq = &impintrq;
 
        /* check leader type */
        if (ip->il_format != IMP_NFF) {
                sc->imp_if.if_collisions++;     /* XXX */
 
        /* check leader type */
        if (ip->il_format != IMP_NFF) {
                sc->imp_if.if_collisions++;     /* XXX */
-               goto drop;
+               goto rawlinkin;
        }
 
        if (ip->il_mtype != IMPTYPE_DATA) {
        }
 
        if (ip->il_mtype != IMPTYPE_DATA) {
-#ifdef notdef
-               addr.s_net = ip->il_network;
-#else
-               addr.s_net = sc->imp_if.if_net;
-#endif
-               addr.s_imp = ip->il_imp;
-               addr.s_host = ip->il_host;
+               /* If not data packet, build IP addr from leader (BRL) */
+               imp_leader_to_addr(&addr, ip, &sc->imp_if);
        }
        }
+
        switch (ip->il_mtype) {
 
        case IMPTYPE_DATA:
        switch (ip->il_mtype) {
 
        case IMPTYPE_DATA:
+               /*
+                * Data for a protocol.  Dispatch to the appropriate
+                * protocol routine (running at software interrupt).
+                * If this isn't a raw interface, advance pointer
+                * into mbuf past leader.
+                */
+               switch (ip->il_link) {
+
+               case IMPLINK_IP:
+                       m->m_len -= sizeof(struct imp_leader);
+                       m->m_off += sizeof(struct imp_leader);
+                       schednetisr(NETISR_IP);
+                       inq = &ipintrq;
+                       break;
+
+               default:
+                       break;
+               }
                break;
 
        /*
                break;
 
        /*
@@ -204,10 +240,10 @@ impinput(unit, m)
                 */
                if (sc->imp_state != IMPS_INIT) {
                        impmsg(sc, "leader error");
                 */
                if (sc->imp_state != IMPS_INIT) {
                        impmsg(sc, "leader error");
-                       hostreset(sc->imp_if.if_net);
+                       hostreset(((struct in_ifaddr *)&sc->imp_if.if_addrlist)->ia_net);
                        impnoops(sc);
                }
                        impnoops(sc);
                }
-               goto drop;
+               break;
 
        /*
         * IMP going down.  Print message, and if not immediate,
 
        /*
         * IMP going down.  Print message, and if not immediate,
@@ -216,14 +252,14 @@ impinput(unit, m)
         */
        case IMPTYPE_DOWN:
                if (sc->imp_state < IMPS_INIT)
         */
        case IMPTYPE_DOWN:
                if (sc->imp_state < IMPS_INIT)
-                       goto drop;
+                       break;
                if ((ip->il_link & IMP_DMASK) == 0) {
                        sc->imp_state = IMPS_GOINGDOWN;
                        timeout(impdown, (caddr_t)sc, 30 * hz);
                }
                impmsg(sc, "going down %s",
                        (u_int)impmessage[ip->il_link&IMP_DMASK]);
                if ((ip->il_link & IMP_DMASK) == 0) {
                        sc->imp_state = IMPS_GOINGDOWN;
                        timeout(impdown, (caddr_t)sc, 30 * hz);
                }
                impmsg(sc, "going down %s",
                        (u_int)impmessage[ip->il_link&IMP_DMASK]);
-               goto drop;
+               break;
 
        /*
         * A NOP usually seen during the initialization sequence.
 
        /*
         * A NOP usually seen during the initialization sequence.
@@ -236,20 +272,23 @@ impinput(unit, m)
                        sc->imp_dropcnt = IMP_DROPCNT;
                }
                if (sc->imp_state == IMPS_INIT && --sc->imp_dropcnt > 0)
                        sc->imp_dropcnt = IMP_DROPCNT;
                }
                if (sc->imp_state == IMPS_INIT && --sc->imp_dropcnt > 0)
-                       goto drop;
-               sin = (struct sockaddr_in *)&sc->imp_if.if_addr;
-               if (sin->sin_addr.s_host != ip->il_host ||
-                   sin->sin_addr.s_imp != ip->il_imp) {
-                       sc->imp_if.if_host[0] =
-                               sin->sin_addr.s_host = ip->il_host;
-                       sin->sin_addr.s_imp = ip->il_imp;
-                       impmsg(sc, "reset (host %d/imp %d)", (u_int)ip->il_host,
-                               ntohs(ip->il_imp));
+                       break;
+               sin = (struct sockaddr_in *)&sc->imp_if.if_addrlist->ifa_addr;
+               if (ip->il_imp != 0) {
+                       struct in_addr leader_addr;
+
+                       imp_leader_to_addr(&leader_addr, ip, &sc->imp_if);
+                       if (sin->sin_addr.s_addr != leader_addr.s_addr) {
+                               impmsg(sc, "address reset to x%x (%d/%d)",
+                                       ntohl(leader_addr.s_addr),
+                                       (u_int)ip->il_host,
+                                       ntohs(ip->il_imp));
+                               sin->sin_addr.s_addr = leader_addr.s_addr;
+                       }
                }
                sc->imp_state = IMPS_UP;
                sc->imp_if.if_flags |= IFF_UP;
                }
                sc->imp_state = IMPS_UP;
                sc->imp_if.if_flags |= IFF_UP;
-               if_rtinit(&sc->imp_if, RTF_UP);
-               goto drop;
+               break;
 
        /*
         * RFNM or INCOMPLETE message, send next
 
        /*
         * RFNM or INCOMPLETE message, send next
@@ -260,6 +299,7 @@ impinput(unit, m)
        case IMPTYPE_RFNM:
        case IMPTYPE_INCOMPLETE:
                if (hp = hostlookup(addr)) {
        case IMPTYPE_RFNM:
        case IMPTYPE_INCOMPLETE:
                if (hp = hostlookup(addr)) {
+                       hp->h_timer = HOSTTIMER;
                        if (hp->h_rfnm == 0)
                                hp->h_flags &= ~HF_INUSE;
                        else if (next = hostdeque(hp))
                        if (hp->h_rfnm == 0)
                                hp->h_flags &= ~HF_INUSE;
                        else if (next = hostdeque(hp))
@@ -270,12 +310,16 @@ impinput(unit, m)
        /*
         * Host or IMP can't be reached.  Flush any packets
         * awaiting transmission and release the host structure.
        /*
         * Host or IMP can't be reached.  Flush any packets
         * awaiting transmission and release the host structure.
+        * Enqueue for notifying protocols at software interrupt time.
         */
        case IMPTYPE_HOSTDEAD:
        case IMPTYPE_HOSTUNREACH:
         */
        case IMPTYPE_HOSTDEAD:
        case IMPTYPE_HOSTUNREACH:
-               impnotify((int)ip->il_mtype, (struct control_leader *)ip,
-                   hostlookup(addr));
-               goto rawlinkin;
+               if (hp = hostlookup(addr)) {
+                       hp->h_flags |= (1 << (int)ip->il_mtype);
+                       hostfree(hp);
+                       hp->h_timer = HOSTDEADTIMER;
+               }
+               break;
 
        /*
         * Error in data.  Clear RFNM status for this host and send
 
        /*
         * Error in data.  Clear RFNM status for this host and send
@@ -286,50 +330,45 @@ impinput(unit, m)
                if (hp = hostlookup(addr))
                        hp->h_rfnm = 0;
                impnoops(sc);
                if (hp = hostlookup(addr))
                        hp->h_rfnm = 0;
                impnoops(sc);
-               goto drop;
+               break;
 
        /*
         * Interface reset.
         */
        case IMPTYPE_RESET:
                impmsg(sc, "interface reset");
 
        /*
         * Interface reset.
         */
        case IMPTYPE_RESET:
                impmsg(sc, "interface reset");
+               /* clear RFNM counts */
+               hostreset(((struct in_ifaddr *)&sc->imp_if.if_addrlist)->ia_net);
                impnoops(sc);
                impnoops(sc);
-               goto drop;
+               break;
 
        default:
                sc->imp_if.if_collisions++;             /* XXX */
 
        default:
                sc->imp_if.if_collisions++;             /* XXX */
-               goto drop;
+               break;
        }
 
        }
 
+rawlinkin:
+       if (inq == &impintrq)
+               schednetisr(NETISR_IMP);
        /*
        /*
-        * Data for a protocol.  Dispatch to the appropriate
-        * protocol routine (running at software interrupt).
-        * If this isn't a raw interface, advance pointer
-        * into mbuf past leader.
+        * Re-insert interface pointer in the mbuf chain
+        * for the next protocol up.
         */
         */
-       switch (ip->il_link) {
-
-#ifdef INET
-       case IMPLINK_IP:
-               m->m_len -= sizeof(struct imp_leader);
-               m->m_off += sizeof(struct imp_leader);
-               schednetisr(NETISR_IP);
-               inq = &ipintrq;
-               break;
-#endif
+       if (M_HASCL(m) && (mtod(m, int) & CLOFSET) < sizeof(struct ifnet *)) {
+               struct mbuf *n;
 
 
-       default:
-       rawlinkin:
-               impproto.sp_protocol = ip->il_link;
-               sin = (struct sockaddr_in *)&sc->imp_if.if_addr;
-               impdst.sin_addr = sin->sin_addr;;
-               impsrc.sin_addr.s_net = ip->il_network;
-               impsrc.sin_addr.s_host = ip->il_host;
-               impsrc.sin_addr.s_imp = ip->il_imp;
-               raw_input(m, &impproto, (struct sockaddr *)&impsrc,
-                 (struct sockaddr *)&impdst);
-               return;
+               MGET(n, M_DONTWAIT, MT_HEADER);
+               if (n == 0)
+                       goto drop;
+               n->m_next = m;
+               m = n;
+               m->m_len = 0;
+               m->m_off = MMINOFF + sizeof(struct ifnet  *);
        }
        }
+       m->m_off -= sizeof(struct ifnet *);
+       m->m_len += sizeof(struct ifnet *);
+       *(mtod(m, struct ifnet **)) = ifp;
+
        if (IF_QFULL(inq)) {
                IF_DROP(inq);
                goto drop;
        if (IF_QFULL(inq)) {
                IF_DROP(inq);
                goto drop;
@@ -351,48 +390,68 @@ impdown(sc)
 
        sc->imp_state = IMPS_DOWN;
        impmsg(sc, "marked down");
 
        sc->imp_state = IMPS_DOWN;
        impmsg(sc, "marked down");
-       hostreset(sc->imp_if.if_net);
+       hostreset(((struct in_ifaddr *)&sc->imp_if.if_addrlist)->ia_net);
        if_down(&sc->imp_if);
        splx(s);
 }
 
        if_down(&sc->imp_if);
        splx(s);
 }
 
-/*VARARGS*/
-impmsg(sc, fmt, a1, a2)
+/*VARARGS2*/
+impmsg(sc, fmt, a1, a2, a3)
        struct imp_softc *sc;
        char *fmt;
        u_int a1;
 {
 
        printf("imp%d: ", sc->imp_if.if_unit);
        struct imp_softc *sc;
        char *fmt;
        u_int a1;
 {
 
        printf("imp%d: ", sc->imp_if.if_unit);
-       printf(fmt, a1, a2);
+       printf(fmt, a1, a2, a3);
        printf("\n");
 }
 
        printf("\n");
 }
 
+struct sockproto impproto = { PF_IMPLINK };
+struct sockaddr_in impdst = { AF_IMPLINK };
+struct sockaddr_in impsrc = { AF_IMPLINK };
+
 /*
 /*
- * Process an IMP "error" message, passing this
- * up to the higher level protocol.
+ * Pick up the IMP "error" messages enqueued earlier,
+ * passing these up to the higher level protocol
+ * and the raw interface.
  */
  */
-impnotify(what, cp, hp)
-       int what;
-       struct control_leader *cp;
-       struct host *hp;
+impintr()
 {
 {
-       struct in_addr in;
+       register struct mbuf *m;
+       register struct control_leader *cp;
+       struct ifnet *ifp;
+       int s;
 
 
-#ifdef notdef
-       in.s_net = cp->dl_network;
-#else
-       in.s_net = 10;                  /* XXX */
-#endif
-       in.s_host = cp->dl_host;
-       in.s_imp = cp->dl_imp;
-       if (cp->dl_link != IMPLINK_IP)
-               raw_ctlinput(what, (caddr_t)&in);
-       else
-               ip_ctlinput(what, (caddr_t)&in);
-       if (hp) {
-               hp->h_flags |= (1 << what);
-               hostfree(hp);
+       for (;;) {
+               s = splimp();
+               IF_DEQUEUEIF(&impintrq, m, ifp);
+               splx(s);
+               if (m == 0)
+                       return;
+
+               cp = mtod(m, struct control_leader *);
+               imp_leader_to_addr(&impsrc.sin_addr, (struct imp_leader *)cp,
+                   ifp);
+               impproto.sp_protocol = cp->dl_link;
+               impdst.sin_addr = IA_SIN(ifp->if_addrlist)->sin_addr;
+
+               if (cp->dl_mtype == IMPTYPE_HOSTDEAD ||
+                   cp->dl_mtype == IMPTYPE_HOSTUNREACH)
+                       switch (cp->dl_link) {
+
+                       case IMPLINK_IP:
+                               pfctlinput((int)cp->dl_mtype,
+                                   (struct sockaddr *)&impsrc);
+                               break;
+                       default:
+                               raw_ctlinput((int)cp->dl_mtype,
+                                   (struct sockaddr *)&impsrc);
+                               break;
+                       }
+
+               raw_input(m, &impproto, (struct sockaddr *)&impsrc,
+                 (struct sockaddr *)&impdst);
        }
 }
 
        }
 }
 
@@ -409,7 +468,7 @@ impoutput(ifp, m0, dst)
 {
        register struct imp_leader *imp;
        register struct mbuf *m = m0;
 {
        register struct imp_leader *imp;
        register struct mbuf *m = m0;
-       int dhost, dimp, dlink, len, dnet;
+       int dlink, len;
        int error = 0;
 
        /*
        int error = 0;
 
        /*
@@ -422,20 +481,20 @@ impoutput(ifp, m0, dst)
 
        switch (dst->sa_family) {
 
 
        switch (dst->sa_family) {
 
-#ifdef INET
        case AF_INET: {
        case AF_INET: {
-               struct ip *ip = mtod(m0, struct ip *);
-               struct sockaddr_in *sin = (struct sockaddr_in *)dst;
+               struct ip *ip = mtod(m, struct ip *);
 
 
-               dhost = sin->sin_addr.s_host;
-               dimp = sin->sin_addr.s_impno;
                dlink = IMPLINK_IP;
                dlink = IMPLINK_IP;
-               dnet = 0;
                len = ntohs((u_short)ip->ip_len);
                break;
        }
                len = ntohs((u_short)ip->ip_len);
                break;
        }
-#endif
+
        case AF_IMPLINK:
        case AF_IMPLINK:
+               len = 0;
+               do
+                       len += m->m_len;
+               while (m = m->m_next);
+               m = m0;
                goto leaderexists;
 
        default:
                goto leaderexists;
 
        default:
@@ -466,11 +525,9 @@ impoutput(ifp, m0, dst)
        imp = mtod(m, struct imp_leader *);
        imp->il_format = IMP_NFF;
        imp->il_mtype = IMPTYPE_DATA;
        imp = mtod(m, struct imp_leader *);
        imp->il_format = IMP_NFF;
        imp->il_mtype = IMPTYPE_DATA;
-       imp->il_network = dnet;
-       imp->il_host = dhost;
-       imp->il_imp = htons((u_short)dimp);
-       imp->il_length =
-               htons((u_short)(len + sizeof(struct imp_leader)) << 3);
+       imp_addr_to_leader(imp,
+               ((struct sockaddr_in *)dst)->sin_addr.s_addr); /* BRL */
+       imp->il_length = htons((u_short)len << 3);              /* BRL */
        imp->il_link = dlink;
        imp->il_flags = imp->il_htype = imp->il_subtype = 0;
 
        imp->il_link = dlink;
        imp->il_flags = imp->il_htype = imp->il_subtype = 0;
 
@@ -505,18 +562,11 @@ impsnd(ifp, m)
        if (ip->il_mtype == IMPTYPE_DATA) {
                struct in_addr addr;
 
        if (ip->il_mtype == IMPTYPE_DATA) {
                struct in_addr addr;
 
-#ifdef notdef
-                addr.s_net = ip->il_network;
-#else
-               addr.s_net = ifp->if_net;       /* XXX */
-#endif
-                addr.s_host = ip->il_host;
-                addr.s_imp = ip->il_imp;
+               imp_leader_to_addr(&addr, ip, ifp);     /* BRL */
                if ((hp = hostlookup(addr)) == 0)
                        hp = hostenter(addr);
                if (hp && (hp->h_flags & (HF_DEAD|HF_UNREACH))) {
                        error = hp->h_flags&HF_DEAD ? EHOSTDOWN : EHOSTUNREACH;
                if ((hp = hostlookup(addr)) == 0)
                        hp = hostenter(addr);
                if (hp && (hp->h_flags & (HF_DEAD|HF_UNREACH))) {
                        error = hp->h_flags&HF_DEAD ? EHOSTDOWN : EHOSTUNREACH;
-                       hp->h_timer = HOSTTIMER;
                        hp->h_flags &= ~HF_INUSE;
                        goto bad;
                }
                        hp->h_flags &= ~HF_INUSE;
                        goto bad;
                }
@@ -525,7 +575,11 @@ impsnd(ifp, m)
                 * If IMP would block, queue until RFNM
                 */
                if (hp) {
                 * If IMP would block, queue until RFNM
                 */
                if (hp) {
-                       if (hp->h_rfnm < 8) {
+#ifndef NORFNM
+                       if (hp->h_rfnm < 8)
+#endif
+                       {
+                               hp->h_timer = HOSTTIMER;
                                hp->h_rfnm++;
                                goto enque;
                        }
                                hp->h_rfnm++;
                                goto enque;
                        }
@@ -541,6 +595,8 @@ enque:
        if (IF_QFULL(&ifp->if_snd)) {
                IF_DROP(&ifp->if_snd);
                error = ENOBUFS;
        if (IF_QFULL(&ifp->if_snd)) {
                IF_DROP(&ifp->if_snd);
                error = ENOBUFS;
+               if (ip->il_mtype == IMPTYPE_DATA)
+                       hp->h_rfnm--;
 bad:
                m_freem(m);
                splx(s);
 bad:
                m_freem(m);
                splx(s);
@@ -571,7 +627,7 @@ impnoops(sc)
        register struct control_leader *cp;
 
        sc->imp_dropcnt = IMP_DROPCNT;
        register struct control_leader *cp;
 
        sc->imp_dropcnt = IMP_DROPCNT;
-       for (i = 0; i < IMP_DROPCNT + 1; i++ ) { 
+       for (i = 0; i < IMP_DROPCNT + 1; i++) { 
                if ((m = m_getclr(M_DONTWAIT, MT_HEADER)) == 0) 
                        return;
                m->m_len = sizeof(struct control_leader);
                if ((m = m_getclr(M_DONTWAIT, MT_HEADER)) == 0) 
                        return;
                m->m_len = sizeof(struct control_leader);
@@ -593,24 +649,17 @@ impioctl(ifp, cmd, data)
        int cmd;
        caddr_t data;
 {
        int cmd;
        caddr_t data;
 {
-       struct ifreq *ifr = (struct ifreq *)data;
-       struct sockaddr_in *sin;
+       struct ifaddr *ifa = (struct ifaddr *) data;
        int s = splimp(), error = 0;
 
        switch (cmd) {
 
        case SIOCSIFADDR:
        int s = splimp(), error = 0;
 
        switch (cmd) {
 
        case SIOCSIFADDR:
-               if (ifp->if_flags & IFF_RUNNING)
-                       if_rtinit(ifp, -1);     /* delete previous route */
-               sin = (struct sockaddr_in *)&ifr->ifr_addr;
-               ifp->if_net = in_netof(sin->sin_addr);
-               sin = (struct sockaddr_in *)&ifp->if_addr;
-               sin->sin_family = AF_INET;
-               /* host number filled in already, or filled in later */
-               sin->sin_addr = if_makeaddr(ifp->if_net, ifp->if_host[0]);
-               if (ifp->if_flags & IFF_RUNNING)
-                       if_rtinit(ifp, RTF_UP);
-               else
+               if (ifa->ifa_addr.sa_family != AF_INET) {
+                       error = EINVAL;
+                       break;
+               }
+               if ((ifp->if_flags & IFF_RUNNING) == 0)
                        impinit(ifp->if_unit);
                break;
 
                        impinit(ifp->if_unit);
                break;
 
@@ -652,10 +701,74 @@ printbyte(cp, n)
        for (i=0; i<n; i++) {
                c = *cp++;
                for (j=0; j<2; j++)
        for (i=0; i<n; i++) {
                c = *cp++;
                for (j=0; j<2; j++)
-                       putchar("0123456789abcdef"[(c>>((1-j)*4))&0xf]);
-               putchar(' ');
+                       putchar("0123456789abcdef"[(c>>((1-j)*4))&0xf], 0);
+               putchar(' ', 0);
        }
        }
-       putchar('\n');
+       putchar('\n', 0);
 }
 #endif
 }
 #endif
+
+/*
+ * Routine to convert from IMP Leader to InterNet Address.
+ *
+ * This procedure is necessary because IMPs may be assigned Class A, B, or C
+ * network numbers, but only have 8 bits in the leader to reflect the
+ * IMP "network number".  The strategy is to take the network number from
+ * the ifnet structure, and blend in the host-on-imp and imp-on-net numbers
+ * from the leader.
+ *
+ * There is no support for "Logical Hosts".
+ *
+ * Class A:    Net.Host.0.Imp
+ * Class B:    Net.net.Host.Imp
+ * Class C:    Net.net.net.(Host4|Imp4)
+ */
+imp_leader_to_addr(ap, ip, ifp)
+       struct in_addr *ap;
+       register struct imp_leader *ip;
+       struct ifnet *ifp;
+{
+       register u_long final;
+       register struct sockaddr_in *sin;
+       int imp = ntohs(ip->il_imp);
+
+       sin = (struct sockaddr_in *)(&ifp->if_addrlist->ifa_addr);
+       final = ntohl(sin->sin_addr.s_addr);
+
+       if (IN_CLASSA(final)) {
+               final &= IN_CLASSA_NET;
+               final |= (imp & 0xFF) | ((ip->il_host & 0xFF)<<16);
+       } else if (IN_CLASSB(final)) {
+               final &= IN_CLASSB_NET;
+               final |= (imp & 0xFF) | ((ip->il_host & 0xFF)<<8);
+       } else {
+               final &= IN_CLASSC_NET;
+               final |= (imp & 0x0F) | ((ip->il_host & 0x0F)<<4);
+       }
+       ap->s_addr = htonl(final);
+}
+
+/*
+ * Function to take InterNet address and fill in IMP leader fields.
+ */
+imp_addr_to_leader(imp, a)
+       register struct imp_leader *imp;
+       u_long a;
+{
+       register u_long addr = ntohl(a);
+
+       imp->il_network = 0;    /* !! */
+
+       if (IN_CLASSA(addr)) {
+               imp->il_host = ((addr>>16) & 0xFF);
+               imp->il_imp = addr & 0xFF;
+       } else if (IN_CLASSB(addr)) {
+               imp->il_host = ((addr>>8) & 0xFF);
+               imp->il_imp = addr & 0xFF;
+       } else {
+               imp->il_host = ((addr>>4) & 0xF);
+               imp->il_imp = addr & 0xF;
+       }
+       imp->il_imp = htons(imp->il_imp);
+}
 #endif
 #endif