1*6208Swnj /* if_imp.c 4.15 82/03/15 */ 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 */ 615924Sroot 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; 895989Sroot /* the host and imp fields will be filled in by the imp */ 906044Swnj ifp->if_addr = if_makeaddr(ifp->if_net, 0); 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 99*6208Swnj #ifdef notdef 1005640Sroot /* 101*6208Swnj * Timer routine to keep priming the IMP until it sends 102*6208Swnj * us the noops we need. Since we depend on the host and 103*6208Swnj * imp values returned in the noop messages, we must wait 104*6208Swnj * for them before we allow any outgoing traffic. 105*6208Swnj */ 106*6208Swnj imptimer(sc) 107*6208Swnj register struct imp_softc *sc; 108*6208Swnj { 109*6208Swnj int s = splimp(); 110*6208Swnj 111*6208Swnj if (sc->imp_state != IMPS_INIT) { 112*6208Swnj splx(s); 113*6208Swnj return; 114*6208Swnj } 115*6208Swnj sc->imp_dropcnt = IMP_DROPCNT; 116*6208Swnj impnoops(sc); 117*6208Swnj timeout(imptimer, (caddr_t)sc, 30 * hz); 118*6208Swnj splx(s); 119*6208Swnj } 120*6208Swnj #endif 121*6208Swnj 122*6208Swnj /* 1235640Sroot * IMP initialization routine: call hardware module to 1245640Sroot * setup UNIBUS resources, init state and get ready for 1255640Sroot * NOOPs the IMP should send us, and that we want to drop. 1265640Sroot */ 1275640Sroot impinit(unit) 1285640Sroot int unit; 1295640Sroot { 1305640Sroot register struct imp_softc *sc = &imp_softc[unit]; 1315640Sroot 1325771Swnj if ((*sc->imp_cb.ic_init)(unit) == 0) { 1335771Swnj sc->imp_state = IMPS_DOWN; 1345771Swnj return; 1355771Swnj } 1365640Sroot sc->imp_state = IMPS_INIT; 137*6208Swnj #ifdef notdef 138*6208Swnj imptimer(sc); 139*6208Swnj #else 1405640Sroot sc->imp_dropcnt = IMP_DROPCNT; 1415771Swnj impnoops(sc); 142*6208Swnj #endif 1435640Sroot } 1445640Sroot 1455640Sroot struct sockproto impproto = { PF_IMPLINK }; 1465645Ssam struct sockaddr_in impdst = { AF_IMPLINK }; 1475645Ssam struct sockaddr_in impsrc = { AF_IMPLINK }; 1485640Sroot 1495640Sroot /* 1505640Sroot * ARPAnet 1822 input routine. 1515640Sroot * Called from hardware input interrupt routine to handle 1822 1525640Sroot * IMP-host messages. Type 0 messages (non-control) are 1535640Sroot * passed to higher level protocol processors on the basis 1545640Sroot * of link number. Other type messages (control) are handled here. 1555640Sroot */ 1565771Swnj impinput(unit, m) 1575640Sroot int unit; 1585771Swnj register struct mbuf *m; 1595640Sroot { 1605640Sroot register struct imp_leader *ip; 1615640Sroot register struct imp_softc *sc = &imp_softc[unit]; 1625640Sroot register struct host *hp; 1635640Sroot register struct ifqueue *inq; 1645771Swnj struct control_leader *cp; 1655640Sroot struct in_addr addr; 1665924Sroot struct mbuf *next; 1675640Sroot 1685932Sroot COUNT(IMPINPUT); 1695647Ssam /* 1705771Swnj * Verify leader length. Be careful with control 1715771Swnj * message which don't get a length included. 1725647Ssam * We should generate a "bad leader" message 1735647Ssam * to the IMP about messages too short. 1745647Ssam */ 1755771Swnj if (m->m_len < sizeof(struct control_leader) && 1765771Swnj (m = m_pullup(m, sizeof(struct control_leader))) == 0) 1775771Swnj return; 1785771Swnj cp = mtod(m, struct control_leader *); 1795771Swnj if (cp->dl_mtype == IMPTYPE_DATA) 1805771Swnj if (m->m_len < sizeof(struct imp_leader) && 1815771Swnj (m = m_pullup(m, sizeof(struct imp_leader))) == 0) 1825771Swnj return; 1835640Sroot ip = mtod(m, struct imp_leader *); 1845640Sroot 1855647Ssam /* 1865647Ssam * Check leader type -- should notify IMP 1875647Ssam * in case of failure... 1885647Ssam */ 1895771Swnj if (ip->il_format != IMP_NFF) { 1905771Swnj sc->imp_if.if_collisions++; /* XXX */ 1915640Sroot goto drop; 1925771Swnj } 1935640Sroot 1945640Sroot /* 1955640Sroot * Certain messages require a host structure. 1965640Sroot * Do this in one shot here. 1975640Sroot */ 1985640Sroot switch (ip->il_mtype) { 1995640Sroot 2005640Sroot case IMPTYPE_RFNM: 2015640Sroot case IMPTYPE_INCOMPLETE: 2025640Sroot case IMPTYPE_HOSTDEAD: 2035640Sroot case IMPTYPE_HOSTUNREACH: 2045640Sroot case IMPTYPE_BADDATA: 2055859Sroot #ifdef notdef 2065771Swnj addr.s_net = ip->il_network; 2075859Sroot #else 2085859Sroot addr.s_net = 0; 2095859Sroot #endif 2105771Swnj addr.s_imp = ip->il_imp; 2115771Swnj addr.s_host = ip->il_host; 2125771Swnj hp = hostlookup(addr); 2135640Sroot break; 2145640Sroot } 2155640Sroot 2165640Sroot switch (ip->il_mtype) { 2175640Sroot 2185640Sroot /* 2195640Sroot * Data for a protocol. Dispatch to the appropriate 2205640Sroot * protocol routine (running at software interrupt). 2215640Sroot * If this isn't a raw interface, advance pointer 2225647Ssam * into mbuf past leader (done below). 2235640Sroot */ 2245640Sroot case IMPTYPE_DATA: 2255771Swnj ip->il_length = 2265771Swnj (ntohs(ip->il_length) >> 3) - sizeof(struct imp_leader); 2275640Sroot break; 2285640Sroot 2295640Sroot /* 2305640Sroot * IMP leader error. Reset the IMP and discard the packet. 2315640Sroot */ 2325640Sroot case IMPTYPE_BADLEADER: 2335647Ssam /* 2345647Ssam * According to 1822 document, this message 2355647Ssam * will be generated in response to the 2365647Ssam * first noop sent to the IMP after 2375647Ssam * the host resets the IMP interface. 2385647Ssam */ 2395771Swnj if (sc->imp_state != IMPS_INIT) { 2405924Sroot impmsg(sc, "leader error"); 2415771Swnj hostreset(sc->imp_if.if_net); /* XXX */ 2425647Ssam impnoops(sc); 2435647Ssam } 2446044Swnj goto rawlinkin; 2455640Sroot 2465640Sroot /* 2475640Sroot * IMP going down. Print message, and if not immediate, 2485640Sroot * set off a timer to insure things will be reset at the 2495640Sroot * appropriate time. 2505640Sroot */ 2515640Sroot case IMPTYPE_DOWN: 2525640Sroot if ((ip->il_link & IMP_DMASK) == 0) { 2535640Sroot sc->imp_state = IMPS_GOINGDOWN; 2546160Ssam timeout(impdown, (caddr_t)sc, 30 * hz); 2555640Sroot } 2566160Ssam impmsg(sc, "going down %s", 2576160Ssam (u_int)impmessage[ip->il_link&IMP_DMASK]); 2586044Swnj goto rawlinkin; 2595640Sroot 2605640Sroot /* 2615640Sroot * A NOP usually seen during the initialization sequence. 2625640Sroot * Compare the local address with that in the message. 2635640Sroot * Reset the local address notion if it doesn't match. 2645640Sroot */ 2655771Swnj case IMPTYPE_NOOP: { 2665771Swnj register struct in_addr *sin; 2675771Swnj 2685647Ssam if (sc->imp_state == IMPS_DOWN) { 2695647Ssam sc->imp_state = IMPS_INIT; 2705647Ssam sc->imp_dropcnt = IMP_DROPCNT; 2715647Ssam } 2726095Swnj if (sc->imp_state != IMPS_INIT || --sc->imp_dropcnt > 0) 2736044Swnj goto rawlinkin; 2745771Swnj sc->imp_state = IMPS_UP; 2755771Swnj sin = &sc->imp_if.if_addr; 2765771Swnj sc->imp_if.if_host[0] = sin->s_host = ip->il_host; 2775771Swnj sin->s_imp = ip->il_imp; 2786160Ssam impmsg(sc, "reset (host %d/imp %d)", (u_int)ip->il_host, 2795771Swnj ntohs(ip->il_imp)); 2805771Swnj /* restart output in case something was q'd */ 2815771Swnj (*sc->imp_cb.ic_start)(sc->imp_if.if_unit); 2826044Swnj goto rawlinkin; 2835989Sroot } 2845640Sroot 2855640Sroot /* 2865640Sroot * RFNM or INCOMPLETE message, record in 2875640Sroot * host table and prime output routine. 2885640Sroot * 2895647Ssam * SHOULD NOTIFY PROTOCOL ABOUT INCOMPLETES. 2905640Sroot */ 2915640Sroot case IMPTYPE_RFNM: 2925640Sroot case IMPTYPE_INCOMPLETE: 2935924Sroot if (hp && hp->h_rfnm) 2945924Sroot if (next = hostdeque(hp)) 2956160Ssam (void) impsnd(&sc->imp_if, next); 2965859Sroot goto rawlinkin; 2975640Sroot 2985640Sroot /* 2995640Sroot * Host or IMP can't be reached. Flush any packets 3005640Sroot * awaiting transmission and release the host structure. 3015640Sroot * 3025771Swnj * TODO: NOTIFY THE PROTOCOL 3035640Sroot */ 3045640Sroot case IMPTYPE_HOSTDEAD: 3055924Sroot impmsg(sc, "host dead"); /* XXX */ 3065771Swnj goto common; /* XXX */ 3075771Swnj 3085771Swnj /* SHOULD SIGNAL ROUTING DAEMON */ 3095640Sroot case IMPTYPE_HOSTUNREACH: 3105924Sroot impmsg(sc, "host unreachable"); /* XXX */ 3115771Swnj common: 3125640Sroot if (hp) 3135771Swnj hostfree(hp); /* won't work right */ 3145859Sroot goto rawlinkin; 3155640Sroot 3165640Sroot /* 3175640Sroot * Error in data. Clear RFNM status for this host and send 3185640Sroot * noops to the IMP to clear the interface. 3195640Sroot */ 3205640Sroot case IMPTYPE_BADDATA: 3215924Sroot impmsg(sc, "data error"); 3225640Sroot if (hp) 3235640Sroot hp->h_rfnm = 0; 3245640Sroot impnoops(sc); 3255859Sroot goto rawlinkin; 3265640Sroot 3275640Sroot /* 3285647Ssam * Interface reset. 3295640Sroot */ 3305640Sroot case IMPTYPE_RESET: 3315924Sroot impmsg(sc, "interface reset"); 3325647Ssam impnoops(sc); 3336044Swnj goto rawlinkin; 3345640Sroot 3355640Sroot default: 3365640Sroot sc->imp_if.if_collisions++; /* XXX */ 3376044Swnj goto rawlinkin; 3385640Sroot } 3395640Sroot 3405640Sroot /* 3415640Sroot * Queue on protocol's input queue. 3425640Sroot */ 3435640Sroot switch (ip->il_link) { 3445640Sroot 3455640Sroot #ifdef INET 3465640Sroot case IMPLINK_IP: 3475640Sroot m->m_len -= sizeof(struct imp_leader); 3485640Sroot m->m_off += sizeof(struct imp_leader); 3495640Sroot setipintr(); 3505640Sroot inq = &ipintrq; 3515640Sroot break; 3525640Sroot #endif 3535640Sroot 3545640Sroot default: 3555868Sroot rawlinkin: 3565640Sroot impproto.sp_protocol = ip->il_link; 3575645Ssam impdst.sin_addr = sc->imp_if.if_addr; 3585645Ssam impsrc.sin_addr.s_net = ip->il_network; 3595645Ssam impsrc.sin_addr.s_host = ip->il_host; 3605645Ssam impsrc.sin_addr.s_imp = ip->il_imp; 3616160Ssam raw_input(m, &impproto, (struct sockaddr *)&impdst, 3626160Ssam (struct sockaddr *)&impsrc); 3635640Sroot return; 3645640Sroot } 365*6208Swnj if (IF_QFULL(inq)) { 366*6208Swnj IF_DROP(inq); 367*6208Swnj goto drop; 368*6208Swnj } 3695640Sroot IF_ENQUEUE(inq, m); 3705640Sroot return; 3715640Sroot 3725640Sroot drop: 3735640Sroot m_freem(m); 3745640Sroot } 3755640Sroot 3765647Ssam /* 3775647Ssam * Bring the IMP down after notification. 3785647Ssam */ 3795647Ssam impdown(sc) 3805647Ssam struct imp_softc *sc; 3815647Ssam { 382*6208Swnj 3835647Ssam sc->imp_state = IMPS_DOWN; 3845924Sroot impmsg(sc, "marked down"); 3855647Ssam /* notify protocols with messages waiting? */ 3865647Ssam } 3875647Ssam 3885640Sroot /*VARARGS*/ 3895924Sroot impmsg(sc, fmt, a1, a2) 3905640Sroot struct imp_softc *sc; 3915640Sroot char *fmt; 3926160Ssam u_int a1; 3935640Sroot { 394*6208Swnj 3955640Sroot printf("imp%d: ", sc->imp_if.if_unit); 3965640Sroot printf(fmt, a1, a2); 3975640Sroot printf("\n"); 3985640Sroot } 3995640Sroot 4005640Sroot /* 4015640Sroot * ARPAnet 1822 output routine. 4025640Sroot * Called from higher level protocol routines to set up messages for 4035640Sroot * transmission to the imp. Sets up the header and calls impsnd to 4045640Sroot * enqueue the message for this IMP's hardware driver. 4055640Sroot */ 4065640Sroot impoutput(ifp, m0, pf) 4075640Sroot register struct ifnet *ifp; 4085640Sroot struct mbuf *m0; 4095640Sroot { 4105640Sroot register struct imp_leader *imp; 4115640Sroot register struct mbuf *m = m0; 4126144Ssam int x, dhost, dimp, dlink, len; 4135640Sroot 4145771Swnj COUNT(IMPOUTPUT); 4155640Sroot /* 4165640Sroot * Don't even try if the IMP is unavailable. 4175640Sroot */ 4185647Ssam x = imp_softc[ifp->if_unit].imp_state; 4195647Ssam if (x == IMPS_DOWN || x == IMPS_GOINGDOWN) 4205647Ssam goto drop; 4215640Sroot 4225640Sroot switch (pf) { 4235640Sroot 4245640Sroot #ifdef INET 4255640Sroot case PF_INET: { 4265640Sroot register struct ip *ip = mtod(m0, struct ip *); 4275640Sroot 4285640Sroot dhost = ip->ip_dst.s_host; 4295640Sroot dimp = ip->ip_dst.s_imp; 4305640Sroot dlink = IMPLINK_IP; 4316160Ssam len = ntohs((u_short)ip->ip_len); 4325640Sroot break; 4335640Sroot } 4345640Sroot #endif 4355640Sroot case PF_IMPLINK: 4365640Sroot goto leaderexists; 4375640Sroot 4385640Sroot default: 4395640Sroot printf("imp%d: can't encapsulate pf%d\n", ifp->if_unit, pf); 4405647Ssam goto drop; 4415640Sroot } 4425640Sroot 4435640Sroot /* 4445640Sroot * Add IMP leader. If there's not enough space in the 4455640Sroot * first mbuf, allocate another. If that should fail, we 4465640Sroot * drop this sucker. 4475640Sroot */ 4485640Sroot if (m->m_off > MMAXOFF || 4495640Sroot MMINOFF + sizeof(struct imp_leader) > m->m_off) { 4505640Sroot m = m_get(M_DONTWAIT); 4515647Ssam if (m == 0) 4525647Ssam goto drop; 4535640Sroot m->m_next = m0; 4545640Sroot m->m_off = MMINOFF; 4555640Sroot m->m_len = sizeof(struct imp_leader); 4565640Sroot } else { 4575640Sroot m->m_off -= sizeof(struct imp_leader); 4585640Sroot m->m_len += sizeof(struct imp_leader); 4595640Sroot } 4605640Sroot imp = mtod(m, struct imp_leader *); 4615640Sroot imp->il_format = IMP_NFF; 4625859Sroot imp->il_mtype = IMPTYPE_DATA; 4635868Sroot imp->il_network = 0; 4645640Sroot imp->il_host = dhost; 4655771Swnj imp->il_imp = dimp; 4666160Ssam imp->il_length = 4676160Ssam htons((u_short)(len + sizeof(struct imp_leader)) << 3); 4685640Sroot imp->il_link = dlink; 4695859Sroot imp->il_flags = imp->il_htype = imp->il_subtype = 0; 4705640Sroot 4715640Sroot leaderexists: 4725640Sroot /* 4735640Sroot * Hand message to impsnd to perform RFNM counting 4745640Sroot * and eventual transmission. 4755640Sroot */ 4765640Sroot return (impsnd(ifp, m)); 4775647Ssam drop: 4785647Ssam m_freem(m0); 4795647Ssam return (0); 4805640Sroot } 4815640Sroot 4825640Sroot /* 4835640Sroot * Put a message on an interface's output queue. 4845640Sroot * Perform RFNM counting: no more than 8 message may be 4855640Sroot * in flight to any one host. 4865640Sroot */ 4875640Sroot impsnd(ifp, m) 4885640Sroot struct ifnet *ifp; 4895640Sroot struct mbuf *m; 4905640Sroot { 4915640Sroot register struct imp_leader *ip; 4925640Sroot register struct host *hp; 4935640Sroot struct impcb *icp; 4945640Sroot int x; 4955640Sroot 4965771Swnj COUNT(IMPSND); 4975640Sroot ip = mtod(m, struct imp_leader *); 4985640Sroot 4995640Sroot /* 5005640Sroot * Do RFNM counting for data messages 5015640Sroot * (no more than 8 outstanding to any host) 5025640Sroot */ 5036095Swnj x = splimp(); 5045640Sroot if (ip->il_mtype == IMPTYPE_DATA) { 5055640Sroot struct in_addr addr; 5065640Sroot 5075859Sroot #ifdef notdef 5085771Swnj addr.s_net = ip->il_network; 5095859Sroot #else 5105859Sroot addr.s_net = 0; 5115859Sroot #endif 5125640Sroot addr.s_host = ip->il_host; 5135640Sroot addr.s_imp = ip->il_imp; 5145771Swnj if ((hp = hostlookup(addr)) == 0) 5155771Swnj hp = hostenter(addr); 5165640Sroot 5175640Sroot /* 5185647Ssam * If IMP would block, queue until RFNM 5195640Sroot */ 5205640Sroot if (hp) { 5215640Sroot if (hp->h_rfnm < 8) { 5225640Sroot hp->h_rfnm++; 5235640Sroot goto enque; 5245640Sroot } 5256095Swnj if (hp->h_qcnt < 8) { /* high water mark */ 5266095Swnj HOST_ENQUE(hp, m); 5276095Swnj goto start; 5286095Swnj } 5295640Sroot } 5305640Sroot m_freem(m); 5315859Sroot splx(x); 5325640Sroot return (0); 5335640Sroot } 5345640Sroot enque: 535*6208Swnj if (IF_QFULL(&ifp->if_snd)) { 536*6208Swnj IF_DROP(&ifp->if_snd); 537*6208Swnj m_freem(m); 538*6208Swnj splx(x); 539*6208Swnj return (0); 540*6208Swnj } 5415640Sroot IF_ENQUEUE(&ifp->if_snd, m); 5426095Swnj start: 5435640Sroot splx(x); 5445640Sroot icp = &imp_softc[ifp->if_unit].imp_cb; 5455640Sroot if (icp->ic_oactive == 0) 5465640Sroot (*icp->ic_start)(ifp->if_unit); 5475640Sroot return (1); 5485640Sroot } 5495640Sroot 5505640Sroot /* 5515640Sroot * Put three 1822 NOOPs at the head of the output queue. 5525640Sroot * Part of host-IMP initialization procedure. 5535640Sroot * (Should return success/failure, but noone knows 5545640Sroot * what to do with this, so why bother?) 5555640Sroot */ 5565640Sroot impnoops(sc) 5575640Sroot register struct imp_softc *sc; 5585640Sroot { 5595640Sroot register i; 5605640Sroot register struct mbuf *m; 5615771Swnj register struct control_leader *cp; 5625640Sroot int x; 5635640Sroot 5645771Swnj COUNT(IMPNOOPS); 5655640Sroot sc->imp_state = IMPS_INIT; 5665640Sroot sc->imp_dropcnt = IMP_DROPCNT; 5675771Swnj for (i = 0; i < IMP_DROPCNT + 1; i++ ) { 5685640Sroot if ((m = m_getclr(M_DONTWAIT)) == 0) 5695640Sroot return; 5705640Sroot m->m_off = MMINOFF; 5715771Swnj m->m_len = sizeof(struct control_leader); 5725771Swnj cp = mtod(m, struct control_leader *); 5735771Swnj cp->dl_format = IMP_NFF; 5745771Swnj cp->dl_link = i; 5755771Swnj cp->dl_mtype = IMPTYPE_NOOP; 5765640Sroot x = splimp(); 5775640Sroot IF_PREPEND(&sc->imp_if.if_snd, m); 5785640Sroot splx(x); 5795640Sroot } 5805640Sroot if (sc->imp_cb.ic_oactive == 0) 5815640Sroot (*sc->imp_cb.ic_start)(sc->imp_if.if_unit); 5825640Sroot } 5835771Swnj 5845859Sroot #ifdef IMPLEADERS 5855771Swnj printleader(routine, ip) 5865771Swnj char *routine; 5875771Swnj register struct imp_leader *ip; 5885771Swnj { 5895771Swnj printf("%s: ", routine); 5905771Swnj printbyte((char *)ip, 12); 5915771Swnj printf("<fmt=%x,net=%x,flags=%x,mtype=", ip->il_format, ip->il_network, 5925771Swnj ip->il_flags); 5935771Swnj if (ip->il_mtype <= IMPTYPE_READY) 5945771Swnj printf("%s,", impleaders[ip->il_mtype]); 5955771Swnj else 5965771Swnj printf("%x,", ip->il_mtype); 5975771Swnj printf("htype=%x,host=%x,imp=%x,link=", ip->il_htype, ip->il_host, 5985771Swnj ip->il_impno); 5995771Swnj if (ip->il_link == IMPLINK_IP) 6005771Swnj printf("ip,"); 6015771Swnj else 6025771Swnj printf("%x,", ip->il_link); 6035771Swnj printf("subtype=%x,len=%x>\n",ip->il_subtype,ntohs(ip->il_length)>>3); 6045771Swnj } 6055771Swnj 6065771Swnj printbyte(cp, n) 6075771Swnj register char *cp; 6085771Swnj int n; 6095771Swnj { 6105771Swnj register i, j, c; 6115771Swnj 6125771Swnj for (i=0; i<n; i++) { 6135771Swnj c = *cp++; 6145771Swnj for (j=0; j<2; j++) 6155771Swnj putchar("0123456789abcdef"[(c>>((1-j)*4))&0xf]); 6165771Swnj putchar(' '); 6175771Swnj } 6185771Swnj putchar('\n'); 6195771Swnj } 6205640Sroot #endif 6215859Sroot #endif 622