1*5924Sroot /* if_imp.c 4.8 82/02/21 */ 25640Sroot 35640Sroot #include "imp.h" 45640Sroot #if NIMP > 0 55640Sroot /* 65640Sroot * ARPAnet IMP interface driver. 75640Sroot * 85640Sroot * The IMP-host protocol is handled here, leaving 95640Sroot * hardware specifics to the lower level interface driver. 105771Swnj * 115771Swnj * TODO: 125771Swnj * rethink coupling between this module and device driver 135771Swnj * pass more error indications up to protocol modules 145640Sroot */ 155640Sroot #include "../h/param.h" 165640Sroot #include "../h/systm.h" 175640Sroot #include "../h/mbuf.h" 185640Sroot #include "../h/pte.h" 195640Sroot #include "../h/buf.h" 205640Sroot #include "../h/protosw.h" 215640Sroot #include "../h/socket.h" 225640Sroot #include "../h/ubareg.h" 235640Sroot #include "../h/ubavar.h" 245640Sroot #include "../h/cpu.h" 255640Sroot #include "../h/mtpr.h" 265640Sroot #include "../h/vmmac.h" 275640Sroot #include "../net/in.h" 285640Sroot #include "../net/in_systm.h" 295640Sroot #include "../net/if.h" 305640Sroot #include "../net/if_imp.h" 315859Sroot #include "../net/if_imphost.h" 325640Sroot #include "../net/ip.h" 335640Sroot #include "../net/ip_var.h" 345640Sroot 355640Sroot /* 365640Sroot * IMP software status per interface. 375640Sroot * (partially shared with the hardware specific module) 385640Sroot * 395640Sroot * Each interface is referenced by a network interface structure, 405640Sroot * imp_if, which the routing code uses to locate the interface. 415640Sroot * This structure contains the output queue for the interface, its 425640Sroot * address, ... IMP specific structures used in connecting the 435640Sroot * IMP software modules to the hardware specific interface routines 445771Swnj * are stored here. The common structures are made visible to the 455771Swnj * interface driver by passing a pointer to the hardware routine 465771Swnj * at "attach" time. 475640Sroot * 485640Sroot * NOTE: imp_if and imp_cb are assumed adjacent in hardware code. 495640Sroot */ 505640Sroot struct imp_softc { 515640Sroot struct ifnet imp_if; /* network visible interface */ 525640Sroot struct impcb imp_cb; /* hooks to hardware module */ 535640Sroot u_char imp_state; /* current state of IMP */ 545640Sroot char imp_dropcnt; /* used during initialization */ 555640Sroot } imp_softc[NIMP]; 565640Sroot 575640Sroot /* 585640Sroot * Messages from IMP regarding why 595640Sroot * it's going down. 605640Sroot */ 61*5924Sroot static char *impmessage[] = { 625640Sroot "in 30 seconds", 635640Sroot "for hardware PM", 645640Sroot "to reload software", 655640Sroot "for emergency reset" 665640Sroot }; 675640Sroot 685771Swnj int impdown(), impinit(), impoutput(); 695771Swnj 705640Sroot /* 715640Sroot * IMP attach routine. Called from hardware device attach routine 725640Sroot * at configuration time with a pointer to the UNIBUS device structure. 735640Sroot * Sets up local state and returns pointer to base of ifnet+impcb 745640Sroot * structures. This is then used by the device's attach routine 755640Sroot * set up its back pointers. 765640Sroot */ 775640Sroot impattach(ui) 785640Sroot struct uba_device *ui; 795640Sroot { 805640Sroot struct imp_softc *sc = &imp_softc[ui->ui_unit]; 815640Sroot register struct ifnet *ifp = &sc->imp_if; 825640Sroot 835640Sroot COUNT(IMPATTACH); 845640Sroot /* UNIT COULD BE AMBIGUOUS */ 855640Sroot ifp->if_unit = ui->ui_unit; 865640Sroot ifp->if_name = "imp"; 875640Sroot ifp->if_mtu = IMP_MTU; 885640Sroot ifp->if_net = ui->ui_flags; 895861Sroot /* this should be found by talking to the imp */ 90*5924Sroot ifp->if_addr.s_addr = 0x4e00000a; 915771Swnj ifp->if_init = impinit; 925771Swnj ifp->if_output = impoutput; 935771Swnj /* reset is handled at the hardware level */ 945640Sroot if_attach(ifp); 955640Sroot /* kludge to hand pointers back to hardware attach routine */ 965640Sroot return ((int)&sc->imp_if); 975640Sroot } 985640Sroot 995640Sroot /* 1005640Sroot * IMP initialization routine: call hardware module to 1015640Sroot * setup UNIBUS resources, init state and get ready for 1025640Sroot * NOOPs the IMP should send us, and that we want to drop. 1035640Sroot */ 1045640Sroot impinit(unit) 1055640Sroot int unit; 1065640Sroot { 1075640Sroot register struct imp_softc *sc = &imp_softc[unit]; 1085640Sroot 1095771Swnj if ((*sc->imp_cb.ic_init)(unit) == 0) { 1105771Swnj sc->imp_state = IMPS_DOWN; 1115771Swnj return; 1125771Swnj } 1135640Sroot sc->imp_state = IMPS_INIT; 1145640Sroot sc->imp_dropcnt = IMP_DROPCNT; 1155771Swnj impnoops(sc); 1165640Sroot } 1175640Sroot 1185640Sroot struct sockproto impproto = { PF_IMPLINK }; 1195645Ssam struct sockaddr_in impdst = { AF_IMPLINK }; 1205645Ssam struct sockaddr_in impsrc = { AF_IMPLINK }; 1215640Sroot 1225640Sroot /* 1235640Sroot * ARPAnet 1822 input routine. 1245640Sroot * Called from hardware input interrupt routine to handle 1822 1255640Sroot * IMP-host messages. Type 0 messages (non-control) are 1265640Sroot * passed to higher level protocol processors on the basis 1275640Sroot * of link number. Other type messages (control) are handled here. 1285640Sroot */ 1295771Swnj impinput(unit, m) 1305640Sroot int unit; 1315771Swnj register struct mbuf *m; 1325640Sroot { 1335640Sroot int s; 1345640Sroot register struct imp_leader *ip; 1355640Sroot register struct imp_softc *sc = &imp_softc[unit]; 1365640Sroot register struct host *hp; 1375640Sroot register struct ifqueue *inq; 1385771Swnj struct control_leader *cp; 1395640Sroot struct in_addr addr; 140*5924Sroot struct mbuf *next; 1415640Sroot 1425640Sroot COUNT(IMP_INPUT); 1435647Ssam /* 1445771Swnj * Verify leader length. Be careful with control 1455771Swnj * message which don't get a length included. 1465647Ssam * We should generate a "bad leader" message 1475647Ssam * to the IMP about messages too short. 1485647Ssam */ 1495771Swnj if (m->m_len < sizeof(struct control_leader) && 1505771Swnj (m = m_pullup(m, sizeof(struct control_leader))) == 0) 1515771Swnj return; 1525771Swnj cp = mtod(m, struct control_leader *); 1535771Swnj if (cp->dl_mtype == IMPTYPE_DATA) 1545771Swnj if (m->m_len < sizeof(struct imp_leader) && 1555771Swnj (m = m_pullup(m, sizeof(struct imp_leader))) == 0) 1565771Swnj return; 1575640Sroot ip = mtod(m, struct imp_leader *); 1585640Sroot 1595647Ssam /* 1605647Ssam * Check leader type -- should notify IMP 1615647Ssam * in case of failure... 1625647Ssam */ 1635771Swnj if (ip->il_format != IMP_NFF) { 1645771Swnj sc->imp_if.if_collisions++; /* XXX */ 1655640Sroot goto drop; 1665771Swnj } 1675640Sroot 1685640Sroot /* 1695640Sroot * Certain messages require a host structure. 1705640Sroot * Do this in one shot here. 1715640Sroot */ 1725640Sroot switch (ip->il_mtype) { 1735640Sroot 1745640Sroot case IMPTYPE_RFNM: 1755640Sroot case IMPTYPE_INCOMPLETE: 1765640Sroot case IMPTYPE_HOSTDEAD: 1775640Sroot case IMPTYPE_HOSTUNREACH: 1785640Sroot case IMPTYPE_BADDATA: 1795859Sroot #ifdef notdef 1805771Swnj addr.s_net = ip->il_network; 1815859Sroot #else 1825859Sroot addr.s_net = 0; 1835859Sroot #endif 1845771Swnj addr.s_imp = ip->il_imp; 1855771Swnj addr.s_host = ip->il_host; 1865771Swnj hp = hostlookup(addr); 1875640Sroot break; 1885640Sroot } 1895640Sroot 1905640Sroot switch (ip->il_mtype) { 1915640Sroot 1925640Sroot /* 1935640Sroot * Data for a protocol. Dispatch to the appropriate 1945640Sroot * protocol routine (running at software interrupt). 1955640Sroot * If this isn't a raw interface, advance pointer 1965647Ssam * into mbuf past leader (done below). 1975640Sroot */ 1985640Sroot case IMPTYPE_DATA: 1995771Swnj ip->il_length = 2005771Swnj (ntohs(ip->il_length) >> 3) - sizeof(struct imp_leader); 2015640Sroot break; 2025640Sroot 2035640Sroot /* 2045640Sroot * IMP leader error. Reset the IMP and discard the packet. 2055640Sroot */ 2065640Sroot case IMPTYPE_BADLEADER: 2075647Ssam /* 2085647Ssam * According to 1822 document, this message 2095647Ssam * will be generated in response to the 2105647Ssam * first noop sent to the IMP after 2115647Ssam * the host resets the IMP interface. 2125647Ssam */ 2135771Swnj if (sc->imp_state != IMPS_INIT) { 214*5924Sroot impmsg(sc, "leader error"); 2155771Swnj hostreset(sc->imp_if.if_net); /* XXX */ 2165647Ssam impnoops(sc); 2175647Ssam } 2185640Sroot goto drop; 2195640Sroot 2205640Sroot /* 2215640Sroot * IMP going down. Print message, and if not immediate, 2225640Sroot * set off a timer to insure things will be reset at the 2235640Sroot * appropriate time. 2245640Sroot */ 2255640Sroot case IMPTYPE_DOWN: 2265640Sroot if ((ip->il_link & IMP_DMASK) == 0) { 2275640Sroot sc->imp_state = IMPS_GOINGDOWN; 2285771Swnj timeout(impdown, sc, 30 * hz); 2295640Sroot } 230*5924Sroot impmsg(sc, "going down %s", impmessage[ip->il_link&IMP_DMASK]); 2315640Sroot goto drop; 2325640Sroot 2335640Sroot /* 2345640Sroot * A NOP usually seen during the initialization sequence. 2355640Sroot * Compare the local address with that in the message. 2365640Sroot * Reset the local address notion if it doesn't match. 2375640Sroot */ 2385771Swnj case IMPTYPE_NOOP: { 2395771Swnj register struct in_addr *sin; 2405771Swnj 2415647Ssam if (sc->imp_state == IMPS_DOWN) { 2425647Ssam sc->imp_state = IMPS_INIT; 2435647Ssam sc->imp_dropcnt = IMP_DROPCNT; 2445647Ssam } 2455771Swnj if (sc->imp_state != IMPS_INIT) 2465771Swnj goto drop; 2475771Swnj if (--sc->imp_dropcnt > 0) 2485771Swnj goto drop; 2495771Swnj sc->imp_state = IMPS_UP; 2505771Swnj sin = &sc->imp_if.if_addr; 2515771Swnj sc->imp_if.if_host[0] = sin->s_host = ip->il_host; 2525771Swnj sin->s_imp = ip->il_imp; 253*5924Sroot impmsg(sc, "reset (host %d/imp %d)", ip->il_host, 2545771Swnj ntohs(ip->il_imp)); 2555771Swnj /* restart output in case something was q'd */ 2565771Swnj (*sc->imp_cb.ic_start)(sc->imp_if.if_unit); 2575771Swnj goto drop; 2585640Sroot } 2595640Sroot 2605640Sroot /* 2615640Sroot * RFNM or INCOMPLETE message, record in 2625640Sroot * host table and prime output routine. 2635640Sroot * 2645647Ssam * SHOULD NOTIFY PROTOCOL ABOUT INCOMPLETES. 2655640Sroot */ 2665640Sroot case IMPTYPE_RFNM: 2675640Sroot case IMPTYPE_INCOMPLETE: 268*5924Sroot if (hp && hp->h_rfnm) 269*5924Sroot if (next = hostdeque(hp)) 270*5924Sroot (void) impsnd(sc, next); 2715859Sroot goto rawlinkin; 2725640Sroot 2735640Sroot /* 2745640Sroot * Host or IMP can't be reached. Flush any packets 2755640Sroot * awaiting transmission and release the host structure. 2765640Sroot * 2775771Swnj * TODO: NOTIFY THE PROTOCOL 2785640Sroot */ 2795640Sroot case IMPTYPE_HOSTDEAD: 280*5924Sroot impmsg(sc, "host dead"); /* XXX */ 2815771Swnj goto common; /* XXX */ 2825771Swnj 2835771Swnj /* SHOULD SIGNAL ROUTING DAEMON */ 2845640Sroot case IMPTYPE_HOSTUNREACH: 285*5924Sroot impmsg(sc, "host unreachable"); /* XXX */ 2865771Swnj common: 2875640Sroot if (hp) 2885771Swnj hostfree(hp); /* won't work right */ 2895859Sroot goto rawlinkin; 2905640Sroot 2915640Sroot /* 2925640Sroot * Error in data. Clear RFNM status for this host and send 2935640Sroot * noops to the IMP to clear the interface. 2945640Sroot */ 2955640Sroot case IMPTYPE_BADDATA: 296*5924Sroot impmsg(sc, "data error"); 2975640Sroot if (hp) 2985640Sroot hp->h_rfnm = 0; 2995640Sroot impnoops(sc); 3005859Sroot goto rawlinkin; 3015640Sroot 3025640Sroot /* 3035647Ssam * Interface reset. 3045640Sroot */ 3055640Sroot case IMPTYPE_RESET: 306*5924Sroot impmsg(sc, "interface reset"); 3075647Ssam impnoops(sc); 3085640Sroot goto drop; 3095640Sroot 3105640Sroot default: 3115640Sroot sc->imp_if.if_collisions++; /* XXX */ 3125640Sroot goto drop; 3135640Sroot } 3145640Sroot 3155640Sroot /* 3165640Sroot * Queue on protocol's input queue. 3175640Sroot */ 3185640Sroot switch (ip->il_link) { 3195640Sroot 3205640Sroot #ifdef INET 3215640Sroot case IMPLINK_IP: 3225640Sroot m->m_len -= sizeof(struct imp_leader); 3235640Sroot m->m_off += sizeof(struct imp_leader); 3245640Sroot setipintr(); 3255640Sroot inq = &ipintrq; 3265640Sroot break; 3275640Sroot #endif 3285640Sroot 3295640Sroot default: 3305868Sroot rawlinkin: 3315640Sroot impproto.sp_protocol = ip->il_link; 3325645Ssam impdst.sin_addr = sc->imp_if.if_addr; 3335645Ssam impsrc.sin_addr.s_net = ip->il_network; 3345645Ssam impsrc.sin_addr.s_host = ip->il_host; 3355645Ssam impsrc.sin_addr.s_imp = ip->il_imp; 3365771Swnj raw_input(m, &impproto, &impdst, &impsrc); 3375640Sroot return; 3385640Sroot } 3395640Sroot IF_ENQUEUE(inq, m); 3405640Sroot return; 3415640Sroot 3425640Sroot drop: 3435640Sroot m_freem(m); 3445640Sroot } 3455640Sroot 3465647Ssam /* 3475647Ssam * Bring the IMP down after notification. 3485647Ssam */ 3495647Ssam impdown(sc) 3505647Ssam struct imp_softc *sc; 3515647Ssam { 3525647Ssam sc->imp_state = IMPS_DOWN; 353*5924Sroot impmsg(sc, "marked down"); 3545647Ssam /* notify protocols with messages waiting? */ 3555647Ssam } 3565647Ssam 3575640Sroot /*VARARGS*/ 358*5924Sroot impmsg(sc, fmt, a1, a2) 3595640Sroot struct imp_softc *sc; 3605640Sroot char *fmt; 3615640Sroot { 3625640Sroot printf("imp%d: ", sc->imp_if.if_unit); 3635640Sroot printf(fmt, a1, a2); 3645640Sroot printf("\n"); 3655640Sroot } 3665640Sroot 3675640Sroot /* 3685640Sroot * ARPAnet 1822 output routine. 3695640Sroot * Called from higher level protocol routines to set up messages for 3705640Sroot * transmission to the imp. Sets up the header and calls impsnd to 3715640Sroot * enqueue the message for this IMP's hardware driver. 3725640Sroot */ 3735640Sroot impoutput(ifp, m0, pf) 3745640Sroot register struct ifnet *ifp; 3755640Sroot struct mbuf *m0; 3765640Sroot { 3775640Sroot register struct imp_leader *imp; 3785640Sroot register struct mbuf *m = m0; 3795771Swnj int x, dhost, dimp, dlink, len, dnet; 3805640Sroot 3815771Swnj COUNT(IMPOUTPUT); 3825771Swnj #ifdef notdef 3835640Sroot /* 3845640Sroot * Don't even try if the IMP is unavailable. 3855640Sroot */ 3865647Ssam x = imp_softc[ifp->if_unit].imp_state; 3875647Ssam if (x == IMPS_DOWN || x == IMPS_GOINGDOWN) 3885647Ssam goto drop; 3895771Swnj #endif 3905640Sroot 3915640Sroot switch (pf) { 3925640Sroot 3935640Sroot #ifdef INET 3945640Sroot case PF_INET: { 3955640Sroot register struct ip *ip = mtod(m0, struct ip *); 3965640Sroot 3975771Swnj dnet = ip->ip_dst.s_net; 3985640Sroot dhost = ip->ip_dst.s_host; 3995640Sroot dimp = ip->ip_dst.s_imp; 4005640Sroot dlink = IMPLINK_IP; 4015640Sroot len = ntohs(ip->ip_len); 4025640Sroot break; 4035640Sroot } 4045640Sroot #endif 4055640Sroot case PF_IMPLINK: 4065640Sroot goto leaderexists; 4075640Sroot 4085640Sroot default: 4095640Sroot printf("imp%d: can't encapsulate pf%d\n", ifp->if_unit, pf); 4105647Ssam goto drop; 4115640Sroot } 4125640Sroot 4135640Sroot /* 4145640Sroot * Add IMP leader. If there's not enough space in the 4155640Sroot * first mbuf, allocate another. If that should fail, we 4165640Sroot * drop this sucker. 4175640Sroot */ 4185640Sroot if (m->m_off > MMAXOFF || 4195640Sroot MMINOFF + sizeof(struct imp_leader) > m->m_off) { 4205640Sroot m = m_get(M_DONTWAIT); 4215647Ssam if (m == 0) 4225647Ssam goto drop; 4235640Sroot m->m_next = m0; 4245640Sroot m->m_off = MMINOFF; 4255640Sroot m->m_len = sizeof(struct imp_leader); 4265640Sroot } else { 4275640Sroot m->m_off -= sizeof(struct imp_leader); 4285640Sroot m->m_len += sizeof(struct imp_leader); 4295640Sroot } 4305640Sroot imp = mtod(m, struct imp_leader *); 4315640Sroot imp->il_format = IMP_NFF; 4325859Sroot imp->il_mtype = IMPTYPE_DATA; 4335868Sroot #ifdef notdef 4345771Swnj imp->il_network = dnet; 4355868Sroot #else 4365868Sroot imp->il_network = 0; 4375868Sroot #endif 4385640Sroot imp->il_host = dhost; 4395771Swnj imp->il_imp = dimp; 4405771Swnj imp->il_length = htons((len + sizeof(struct imp_leader)) << 3); 4415640Sroot imp->il_link = dlink; 4425859Sroot imp->il_flags = imp->il_htype = imp->il_subtype = 0; 4435640Sroot 4445640Sroot leaderexists: 4455640Sroot /* 4465640Sroot * Hand message to impsnd to perform RFNM counting 4475640Sroot * and eventual transmission. 4485640Sroot */ 4495640Sroot return (impsnd(ifp, m)); 4505647Ssam drop: 4515647Ssam m_freem(m0); 4525647Ssam return (0); 4535640Sroot } 4545640Sroot 4555640Sroot /* 4565640Sroot * Put a message on an interface's output queue. 4575640Sroot * Perform RFNM counting: no more than 8 message may be 4585640Sroot * in flight to any one host. 4595640Sroot */ 4605640Sroot impsnd(ifp, m) 4615640Sroot struct ifnet *ifp; 4625640Sroot struct mbuf *m; 4635640Sroot { 4645640Sroot register struct imp_leader *ip; 4655640Sroot register struct host *hp; 4665640Sroot struct impcb *icp; 4675640Sroot int x; 4685640Sroot 4695771Swnj COUNT(IMPSND); 4705640Sroot ip = mtod(m, struct imp_leader *); 4715640Sroot 4725640Sroot /* 4735640Sroot * Do RFNM counting for data messages 4745640Sroot * (no more than 8 outstanding to any host) 4755640Sroot */ 4765640Sroot if (ip->il_mtype == IMPTYPE_DATA) { 4775640Sroot struct in_addr addr; 4785640Sroot 4795859Sroot #ifdef notdef 4805771Swnj addr.s_net = ip->il_network; 4815859Sroot #else 4825859Sroot addr.s_net = 0; 4835859Sroot #endif 4845640Sroot addr.s_host = ip->il_host; 4855640Sroot addr.s_imp = ip->il_imp; 4865859Sroot x = splimp(); 4875771Swnj if ((hp = hostlookup(addr)) == 0) 4885771Swnj hp = hostenter(addr); 4895640Sroot 4905640Sroot /* 4915647Ssam * If IMP would block, queue until RFNM 4925640Sroot */ 4935640Sroot if (hp) { 4945640Sroot if (hp->h_rfnm < 8) { 4955640Sroot hp->h_rfnm++; 4965859Sroot splx(x); 4975640Sroot goto enque; 4985640Sroot } 499*5924Sroot if (hp->h_qcnt >= 8) /* high water mark */ 5005640Sroot goto drop; 501*5924Sroot HOST_ENQUE(hp, m); 5025859Sroot splx(x); 5035640Sroot goto start; 5045640Sroot } 5055640Sroot drop: 5065640Sroot m_freem(m); 5075859Sroot splx(x); 5085640Sroot return (0); 5095640Sroot } 5105640Sroot enque: 5115640Sroot x = splimp(); 5125640Sroot IF_ENQUEUE(&ifp->if_snd, m); 5135640Sroot splx(x); 5145640Sroot 5155640Sroot start: 5165640Sroot icp = &imp_softc[ifp->if_unit].imp_cb; 5175640Sroot if (icp->ic_oactive == 0) 5185640Sroot (*icp->ic_start)(ifp->if_unit); 5195640Sroot return (1); 5205640Sroot } 5215640Sroot 5225640Sroot /* 5235640Sroot * Put three 1822 NOOPs at the head of the output queue. 5245640Sroot * Part of host-IMP initialization procedure. 5255640Sroot * (Should return success/failure, but noone knows 5265640Sroot * what to do with this, so why bother?) 5275640Sroot */ 5285640Sroot impnoops(sc) 5295640Sroot register struct imp_softc *sc; 5305640Sroot { 5315640Sroot register i; 5325640Sroot register struct mbuf *m; 5335771Swnj register struct control_leader *cp; 5345640Sroot int x; 5355640Sroot 5365771Swnj COUNT(IMPNOOPS); 5375640Sroot sc->imp_state = IMPS_INIT; 5385640Sroot sc->imp_dropcnt = IMP_DROPCNT; 5395771Swnj for (i = 0; i < IMP_DROPCNT + 1; i++ ) { 5405640Sroot if ((m = m_getclr(M_DONTWAIT)) == 0) 5415640Sroot return; 5425640Sroot m->m_off = MMINOFF; 5435771Swnj m->m_len = sizeof(struct control_leader); 5445771Swnj cp = mtod(m, struct control_leader *); 5455771Swnj cp->dl_format = IMP_NFF; 5465771Swnj cp->dl_link = i; 5475771Swnj cp->dl_mtype = IMPTYPE_NOOP; 5485640Sroot x = splimp(); 5495640Sroot IF_PREPEND(&sc->imp_if.if_snd, m); 5505640Sroot splx(x); 5515640Sroot } 5525640Sroot if (sc->imp_cb.ic_oactive == 0) 5535640Sroot (*sc->imp_cb.ic_start)(sc->imp_if.if_unit); 5545640Sroot } 5555771Swnj 5565859Sroot #ifdef IMPLEADERS 5575771Swnj printleader(routine, ip) 5585771Swnj char *routine; 5595771Swnj register struct imp_leader *ip; 5605771Swnj { 5615771Swnj printf("%s: ", routine); 5625771Swnj printbyte((char *)ip, 12); 5635771Swnj printf("<fmt=%x,net=%x,flags=%x,mtype=", ip->il_format, ip->il_network, 5645771Swnj ip->il_flags); 5655771Swnj if (ip->il_mtype <= IMPTYPE_READY) 5665771Swnj printf("%s,", impleaders[ip->il_mtype]); 5675771Swnj else 5685771Swnj printf("%x,", ip->il_mtype); 5695771Swnj printf("htype=%x,host=%x,imp=%x,link=", ip->il_htype, ip->il_host, 5705771Swnj ip->il_impno); 5715771Swnj if (ip->il_link == IMPLINK_IP) 5725771Swnj printf("ip,"); 5735771Swnj else 5745771Swnj printf("%x,", ip->il_link); 5755771Swnj printf("subtype=%x,len=%x>\n",ip->il_subtype,ntohs(ip->il_length)>>3); 5765771Swnj } 5775771Swnj 5785771Swnj printbyte(cp, n) 5795771Swnj register char *cp; 5805771Swnj int n; 5815771Swnj { 5825771Swnj register i, j, c; 5835771Swnj 5845771Swnj for (i=0; i<n; i++) { 5855771Swnj c = *cp++; 5865771Swnj for (j=0; j<2; j++) 5875771Swnj putchar("0123456789abcdef"[(c>>((1-j)*4))&0xf]); 5885771Swnj putchar(' '); 5895771Swnj } 5905771Swnj putchar('\n'); 5915771Swnj } 5925640Sroot #endif 5935859Sroot #endif 594