1*13094Ssam /* if_imp.c 4.51 83/06/13 */ 25640Sroot 35640Sroot #include "imp.h" 45640Sroot #if NIMP > 0 55640Sroot /* 66582Ssam * ARPANET IMP interface driver. 75640Sroot * 85640Sroot * The IMP-host protocol is handled here, leaving 95640Sroot * hardware specifics to the lower level interface driver. 1013067Ssam * 1113067Ssam * NB: only handles IMPS on class A networks. 125640Sroot */ 139800Ssam #include "../machine/pte.h" 149800Ssam 155640Sroot #include "../h/param.h" 165640Sroot #include "../h/systm.h" 175640Sroot #include "../h/mbuf.h" 185640Sroot #include "../h/buf.h" 195640Sroot #include "../h/protosw.h" 205640Sroot #include "../h/socket.h" 218705Sroot #include "../h/vmmac.h" 2210874Ssam #include "../h/time.h" 2310874Ssam #include "../h/kernel.h" 2410899Ssam #include "../h/errno.h" 2513067Ssam #include "../h/ioctl.h" 268705Sroot 278705Sroot #include "../vax/cpu.h" 288533Sroot #include "../vax/mtpr.h" 298782Sroot #include "../vaxuba/ubareg.h" 308782Sroot #include "../vaxuba/ubavar.h" 318705Sroot 328705Sroot #include "../net/if.h" 338705Sroot #include "../net/route.h" 3410899Ssam 358705Sroot #include "../net/netisr.h" 368408Swnj #include "../netinet/in.h" 378408Swnj #include "../netinet/in_systm.h" 388705Sroot #include "../netinet/ip.h" 398705Sroot #include "../netinet/ip_var.h" 407199Ssam /* define IMPLEADERS here to get leader printing code */ 418408Swnj #include "../netimp/if_imp.h" 428408Swnj #include "../netimp/if_imphost.h" 435640Sroot 445640Sroot /* 455640Sroot * IMP software status per interface. 465640Sroot * (partially shared with the hardware specific module) 475640Sroot * 485640Sroot * Each interface is referenced by a network interface structure, 495640Sroot * imp_if, which the routing code uses to locate the interface. 505640Sroot * This structure contains the output queue for the interface, its 515640Sroot * address, ... IMP specific structures used in connecting the 525640Sroot * IMP software modules to the hardware specific interface routines 535771Swnj * are stored here. The common structures are made visible to the 545771Swnj * interface driver by passing a pointer to the hardware routine 555771Swnj * at "attach" time. 565640Sroot * 575640Sroot * NOTE: imp_if and imp_cb are assumed adjacent in hardware code. 585640Sroot */ 595640Sroot struct imp_softc { 605640Sroot struct ifnet imp_if; /* network visible interface */ 615640Sroot struct impcb imp_cb; /* hooks to hardware module */ 625640Sroot u_char imp_state; /* current state of IMP */ 635640Sroot char imp_dropcnt; /* used during initialization */ 645640Sroot } imp_softc[NIMP]; 655640Sroot 665640Sroot /* 675640Sroot * Messages from IMP regarding why 685640Sroot * it's going down. 695640Sroot */ 705924Sroot static char *impmessage[] = { 715640Sroot "in 30 seconds", 725640Sroot "for hardware PM", 735640Sroot "to reload software", 745640Sroot "for emergency reset" 755640Sroot }; 765640Sroot 7713067Ssam int impdown(), impinit(), impioctl(), impoutput(); 785771Swnj 795640Sroot /* 805640Sroot * IMP attach routine. Called from hardware device attach routine 815640Sroot * at configuration time with a pointer to the UNIBUS device structure. 825640Sroot * Sets up local state and returns pointer to base of ifnet+impcb 835640Sroot * structures. This is then used by the device's attach routine 845640Sroot * set up its back pointers. 855640Sroot */ 868815Sroot impattach(ui, reset) 875640Sroot struct uba_device *ui; 888815Sroot int (*reset)(); 895640Sroot { 905640Sroot struct imp_softc *sc = &imp_softc[ui->ui_unit]; 915640Sroot register struct ifnet *ifp = &sc->imp_if; 925640Sroot 935640Sroot /* UNIT COULD BE AMBIGUOUS */ 945640Sroot ifp->if_unit = ui->ui_unit; 955640Sroot ifp->if_name = "imp"; 966271Sroot ifp->if_mtu = IMPMTU - sizeof(struct imp_leader); 979001Sroot ifp->if_reset = reset; 985771Swnj ifp->if_init = impinit; 9913067Ssam ifp->if_ioctl = impioctl; 1005771Swnj ifp->if_output = impoutput; 1015771Swnj /* reset is handled at the hardware level */ 1025640Sroot if_attach(ifp); 1035640Sroot return ((int)&sc->imp_if); 1045640Sroot } 1055640Sroot 1065640Sroot /* 1075640Sroot * IMP initialization routine: call hardware module to 1085640Sroot * setup UNIBUS resources, init state and get ready for 1095640Sroot * NOOPs the IMP should send us, and that we want to drop. 1105640Sroot */ 1115640Sroot impinit(unit) 1125640Sroot int unit; 1135640Sroot { 1146500Ssam int s = splimp(); 1155640Sroot register struct imp_softc *sc = &imp_softc[unit]; 11613067Ssam struct sockaddr_in *sin; 1175640Sroot 118*13094Ssam sin = (struct sockaddr_in *)&sc->imp_if.if_addr; 11913067Ssam if (in_netof(sin->sin_addr) == 0) 12013067Ssam return; 1215771Swnj if ((*sc->imp_cb.ic_init)(unit) == 0) { 1225771Swnj sc->imp_state = IMPS_DOWN; 1236336Ssam sc->imp_if.if_flags &= ~IFF_UP; 1246500Ssam splx(s); 1255771Swnj return; 1265771Swnj } 127*13094Ssam sc->imp_if.if_flags |= IFF_RUNNING; 1285640Sroot sc->imp_state = IMPS_INIT; 1295771Swnj impnoops(sc); 1306500Ssam splx(s); 1315640Sroot } 1325640Sroot 1335640Sroot struct sockproto impproto = { PF_IMPLINK }; 1345645Ssam struct sockaddr_in impdst = { AF_IMPLINK }; 1355645Ssam struct sockaddr_in impsrc = { AF_IMPLINK }; 1367199Ssam #ifdef IMPLEADERS 1377170Ssam int impprintfs = 0; 1387199Ssam #endif 1395640Sroot 1405640Sroot /* 1415640Sroot * ARPAnet 1822 input routine. 1425640Sroot * Called from hardware input interrupt routine to handle 1822 1435640Sroot * IMP-host messages. Type 0 messages (non-control) are 1445640Sroot * passed to higher level protocol processors on the basis 1455640Sroot * of link number. Other type messages (control) are handled here. 1465640Sroot */ 1475771Swnj impinput(unit, m) 1485640Sroot int unit; 1495771Swnj register struct mbuf *m; 1505640Sroot { 1515640Sroot register struct imp_leader *ip; 1525640Sroot register struct imp_softc *sc = &imp_softc[unit]; 1535640Sroot register struct host *hp; 1545640Sroot register struct ifqueue *inq; 1555771Swnj struct control_leader *cp; 1565640Sroot struct in_addr addr; 1575924Sroot struct mbuf *next; 1586336Ssam struct sockaddr_in *sin; 1595640Sroot 1606257Sroot /* verify leader length. */ 1615771Swnj if (m->m_len < sizeof(struct control_leader) && 1625771Swnj (m = m_pullup(m, sizeof(struct control_leader))) == 0) 1635771Swnj return; 1645771Swnj cp = mtod(m, struct control_leader *); 1655771Swnj if (cp->dl_mtype == IMPTYPE_DATA) 1665771Swnj if (m->m_len < sizeof(struct imp_leader) && 1675771Swnj (m = m_pullup(m, sizeof(struct imp_leader))) == 0) 1685771Swnj return; 1695640Sroot ip = mtod(m, struct imp_leader *); 1707199Ssam #ifdef IMPLEADERS 1717170Ssam if (impprintfs) 1727170Ssam printleader("impinput", ip); 1737199Ssam #endif 1745640Sroot 1756257Sroot /* check leader type */ 1765771Swnj if (ip->il_format != IMP_NFF) { 1775771Swnj sc->imp_if.if_collisions++; /* XXX */ 1785640Sroot goto drop; 1795771Swnj } 1805640Sroot 1816588Ssam if (ip->il_mtype != IMPTYPE_DATA) { 1825859Sroot #ifdef notdef 1835771Swnj addr.s_net = ip->il_network; 1845859Sroot #else 1856588Ssam addr.s_net = sc->imp_if.if_net; 1865859Sroot #endif 1875771Swnj addr.s_imp = ip->il_imp; 1885771Swnj addr.s_host = ip->il_host; 1895640Sroot } 1905640Sroot switch (ip->il_mtype) { 1915640Sroot 1925640Sroot case IMPTYPE_DATA: 1935640Sroot break; 1945640Sroot 1955640Sroot /* 1965640Sroot * IMP leader error. Reset the IMP and discard the packet. 1975640Sroot */ 1985640Sroot case IMPTYPE_BADLEADER: 1995647Ssam /* 2005647Ssam * According to 1822 document, this message 2015647Ssam * will be generated in response to the 2025647Ssam * first noop sent to the IMP after 2035647Ssam * the host resets the IMP interface. 2045647Ssam */ 2055771Swnj if (sc->imp_state != IMPS_INIT) { 2065924Sroot impmsg(sc, "leader error"); 2076582Ssam hostreset(sc->imp_if.if_net); 2085647Ssam impnoops(sc); 2095647Ssam } 2106582Ssam goto drop; 2115640Sroot 2125640Sroot /* 2135640Sroot * IMP going down. Print message, and if not immediate, 2145640Sroot * set off a timer to insure things will be reset at the 2155640Sroot * appropriate time. 2165640Sroot */ 2175640Sroot case IMPTYPE_DOWN: 2186599Ssam if (sc->imp_state < IMPS_INIT) 2196598Ssam goto drop; 2205640Sroot if ((ip->il_link & IMP_DMASK) == 0) { 2215640Sroot sc->imp_state = IMPS_GOINGDOWN; 2226160Ssam timeout(impdown, (caddr_t)sc, 30 * hz); 2235640Sroot } 2246160Ssam impmsg(sc, "going down %s", 2256160Ssam (u_int)impmessage[ip->il_link&IMP_DMASK]); 2266582Ssam goto drop; 2275640Sroot 2285640Sroot /* 2295640Sroot * A NOP usually seen during the initialization sequence. 2305640Sroot * Compare the local address with that in the message. 2315640Sroot * Reset the local address notion if it doesn't match. 2325640Sroot */ 2336336Ssam case IMPTYPE_NOOP: 2345647Ssam if (sc->imp_state == IMPS_DOWN) { 2355647Ssam sc->imp_state = IMPS_INIT; 2365647Ssam sc->imp_dropcnt = IMP_DROPCNT; 2375647Ssam } 2386500Ssam if (sc->imp_state == IMPS_INIT && --sc->imp_dropcnt > 0) 2396271Sroot goto drop; 2406500Ssam sin = (struct sockaddr_in *)&sc->imp_if.if_addr; 2416500Ssam if (sin->sin_addr.s_host != ip->il_host || 2426500Ssam sin->sin_addr.s_imp != ip->il_imp) { 2436500Ssam sc->imp_if.if_host[0] = 2446500Ssam sin->sin_addr.s_host = ip->il_host; 2456500Ssam sin->sin_addr.s_imp = ip->il_imp; 2466500Ssam impmsg(sc, "reset (host %d/imp %d)", (u_int)ip->il_host, 2476500Ssam ntohs(ip->il_imp)); 2486500Ssam } 2495771Swnj sc->imp_state = IMPS_UP; 2506336Ssam sc->imp_if.if_flags |= IFF_UP; 2517201Ssam if_rtinit(&sc->imp_if, RTF_UP); 2526271Sroot goto drop; 2535640Sroot 2545640Sroot /* 2556582Ssam * RFNM or INCOMPLETE message, send next 2566582Ssam * message on the q. We could pass incomplete's 2576582Ssam * up to the next level, but this currently isn't 2586582Ssam * needed. 2595640Sroot */ 2605640Sroot case IMPTYPE_RFNM: 2615640Sroot case IMPTYPE_INCOMPLETE: 2626588Ssam if (hp = hostlookup(addr)) { 2636588Ssam if (hp->h_rfnm == 0) 2646588Ssam hp->h_flags &= ~HF_INUSE; 2656588Ssam else if (next = hostdeque(hp)) 2666588Ssam (void) impsnd(&sc->imp_if, next); 2676588Ssam } 2686271Sroot goto drop; 2695640Sroot 2705640Sroot /* 2715640Sroot * Host or IMP can't be reached. Flush any packets 2725640Sroot * awaiting transmission and release the host structure. 2735640Sroot */ 2745640Sroot case IMPTYPE_HOSTDEAD: 27511230Ssam case IMPTYPE_HOSTUNREACH: 2768705Sroot impnotify((int)ip->il_mtype, (struct control_leader *)ip, 2778705Sroot hostlookup(addr)); 2785859Sroot goto rawlinkin; 2795640Sroot 2805640Sroot /* 2815640Sroot * Error in data. Clear RFNM status for this host and send 2825640Sroot * noops to the IMP to clear the interface. 2835640Sroot */ 28411230Ssam case IMPTYPE_BADDATA: 2855924Sroot impmsg(sc, "data error"); 2866588Ssam if (hp = hostlookup(addr)) 2875640Sroot hp->h_rfnm = 0; 2885640Sroot impnoops(sc); 2896582Ssam goto drop; 2905640Sroot 2915640Sroot /* 2925647Ssam * Interface reset. 2935640Sroot */ 2945640Sroot case IMPTYPE_RESET: 2955924Sroot impmsg(sc, "interface reset"); 2965647Ssam impnoops(sc); 2976582Ssam goto drop; 2985640Sroot 2995640Sroot default: 3005640Sroot sc->imp_if.if_collisions++; /* XXX */ 3016582Ssam goto drop; 3025640Sroot } 3035640Sroot 3045640Sroot /* 3056257Sroot * Data for a protocol. Dispatch to the appropriate 3066257Sroot * protocol routine (running at software interrupt). 3076257Sroot * If this isn't a raw interface, advance pointer 3086257Sroot * into mbuf past leader. 3095640Sroot */ 3105640Sroot switch (ip->il_link) { 3115640Sroot 3125640Sroot #ifdef INET 3135640Sroot case IMPLINK_IP: 3145640Sroot m->m_len -= sizeof(struct imp_leader); 3155640Sroot m->m_off += sizeof(struct imp_leader); 3166261Swnj schednetisr(NETISR_IP); 3175640Sroot inq = &ipintrq; 3185640Sroot break; 3195640Sroot #endif 3205640Sroot 3215640Sroot default: 3225868Sroot rawlinkin: 3235640Sroot impproto.sp_protocol = ip->il_link; 3246336Ssam sin = (struct sockaddr_in *)&sc->imp_if.if_addr; 3256336Ssam impdst.sin_addr = sin->sin_addr;; 3265645Ssam impsrc.sin_addr.s_net = ip->il_network; 3275645Ssam impsrc.sin_addr.s_host = ip->il_host; 3285645Ssam impsrc.sin_addr.s_imp = ip->il_imp; 3296527Ssam raw_input(m, &impproto, (struct sockaddr *)&impsrc, 3306527Ssam (struct sockaddr *)&impdst); 3315640Sroot return; 3325640Sroot } 3336208Swnj if (IF_QFULL(inq)) { 3346208Swnj IF_DROP(inq); 3356208Swnj goto drop; 3366208Swnj } 3375640Sroot IF_ENQUEUE(inq, m); 3385640Sroot return; 3395640Sroot 3405640Sroot drop: 3415640Sroot m_freem(m); 3425640Sroot } 3435640Sroot 3445647Ssam /* 3455647Ssam * Bring the IMP down after notification. 3465647Ssam */ 3475647Ssam impdown(sc) 3485647Ssam struct imp_softc *sc; 3495647Ssam { 35011230Ssam int s = splimp(); 3516208Swnj 3525647Ssam sc->imp_state = IMPS_DOWN; 3535924Sroot impmsg(sc, "marked down"); 3546588Ssam hostreset(sc->imp_if.if_net); 3556582Ssam if_down(&sc->imp_if); 35611230Ssam splx(s); 3575647Ssam } 3585647Ssam 3595640Sroot /*VARARGS*/ 3605924Sroot impmsg(sc, fmt, a1, a2) 3615640Sroot struct imp_softc *sc; 3625640Sroot char *fmt; 3636160Ssam u_int a1; 3645640Sroot { 3656208Swnj 3665640Sroot printf("imp%d: ", sc->imp_if.if_unit); 3675640Sroot printf(fmt, a1, a2); 3685640Sroot printf("\n"); 3695640Sroot } 3705640Sroot 3715640Sroot /* 3726582Ssam * Process an IMP "error" message, passing this 3736582Ssam * up to the higher level protocol. 3746582Ssam */ 3756582Ssam impnotify(what, cp, hp) 3766582Ssam int what; 3776582Ssam struct control_leader *cp; 3786582Ssam struct host *hp; 3796582Ssam { 3806582Ssam struct in_addr in; 3816582Ssam 3826582Ssam #ifdef notdef 3836582Ssam in.s_net = cp->dl_network; 3846582Ssam #else 3856588Ssam in.s_net = 10; /* XXX */ 3866582Ssam #endif 3876582Ssam in.s_host = cp->dl_host; 3886582Ssam in.s_imp = cp->dl_imp; 3896582Ssam if (cp->dl_link != IMPLINK_IP) 3906582Ssam raw_ctlinput(what, (caddr_t)&in); 3916582Ssam else 3926582Ssam ip_ctlinput(what, (caddr_t)&in); 3936588Ssam if (hp) { 3946588Ssam hp->h_flags |= (1 << what); 3956582Ssam hostfree(hp); 3966588Ssam } 3976582Ssam } 3986582Ssam 3996582Ssam /* 4005640Sroot * ARPAnet 1822 output routine. 4015640Sroot * Called from higher level protocol routines to set up messages for 4025640Sroot * transmission to the imp. Sets up the header and calls impsnd to 4035640Sroot * enqueue the message for this IMP's hardware driver. 4045640Sroot */ 4056336Ssam impoutput(ifp, m0, dst) 4065640Sroot register struct ifnet *ifp; 4075640Sroot struct mbuf *m0; 4086336Ssam struct sockaddr *dst; 4095640Sroot { 4105640Sroot register struct imp_leader *imp; 4115640Sroot register struct mbuf *m = m0; 4128782Sroot int dhost, dimp, dlink, len, dnet; 4136504Ssam int error = 0; 4145640Sroot 4155640Sroot /* 4165640Sroot * Don't even try if the IMP is unavailable. 4175640Sroot */ 4186504Ssam if (imp_softc[ifp->if_unit].imp_state != IMPS_UP) { 4196504Ssam error = ENETDOWN; 4205647Ssam goto drop; 4216504Ssam } 4225640Sroot 4236336Ssam switch (dst->sa_family) { 4245640Sroot 4255640Sroot #ifdef INET 4266336Ssam case AF_INET: { 4276336Ssam struct ip *ip = mtod(m0, struct ip *); 4286336Ssam struct sockaddr_in *sin = (struct sockaddr_in *)dst; 4295640Sroot 4306336Ssam dhost = sin->sin_addr.s_host; 4316336Ssam dimp = sin->sin_addr.s_impno; 4325640Sroot dlink = IMPLINK_IP; 4336244Sroot dnet = 0; 4346160Ssam len = ntohs((u_short)ip->ip_len); 4355640Sroot break; 4365640Sroot } 4375640Sroot #endif 4386336Ssam case AF_IMPLINK: 4395640Sroot goto leaderexists; 4405640Sroot 4415640Sroot default: 4426336Ssam printf("imp%d: can't handle af%d\n", ifp->if_unit, 4436336Ssam dst->sa_family); 4446504Ssam error = EAFNOSUPPORT; 4455647Ssam goto drop; 4465640Sroot } 4475640Sroot 4485640Sroot /* 4495640Sroot * Add IMP leader. If there's not enough space in the 4505640Sroot * first mbuf, allocate another. If that should fail, we 4515640Sroot * drop this sucker. 4525640Sroot */ 4535640Sroot if (m->m_off > MMAXOFF || 4545640Sroot MMINOFF + sizeof(struct imp_leader) > m->m_off) { 4559645Ssam m = m_get(M_DONTWAIT, MT_HEADER); 4566504Ssam if (m == 0) { 4576504Ssam error = ENOBUFS; 4585647Ssam goto drop; 4596504Ssam } 4605640Sroot m->m_next = m0; 4615640Sroot m->m_len = sizeof(struct imp_leader); 4625640Sroot } else { 4635640Sroot m->m_off -= sizeof(struct imp_leader); 4645640Sroot m->m_len += sizeof(struct imp_leader); 4655640Sroot } 4665640Sroot imp = mtod(m, struct imp_leader *); 4675640Sroot imp->il_format = IMP_NFF; 4685859Sroot imp->il_mtype = IMPTYPE_DATA; 4696244Sroot imp->il_network = dnet; 4705640Sroot imp->il_host = dhost; 4716244Sroot imp->il_imp = htons((u_short)dimp); 4726160Ssam imp->il_length = 4736160Ssam htons((u_short)(len + sizeof(struct imp_leader)) << 3); 4745640Sroot imp->il_link = dlink; 4755859Sroot imp->il_flags = imp->il_htype = imp->il_subtype = 0; 4765640Sroot 4775640Sroot leaderexists: 4785640Sroot return (impsnd(ifp, m)); 4795647Ssam drop: 4805647Ssam m_freem(m0); 4816504Ssam return (error); 4825640Sroot } 4835640Sroot 4845640Sroot /* 4855640Sroot * Put a message on an interface's output queue. 4865640Sroot * Perform RFNM counting: no more than 8 message may be 4875640Sroot * in flight to any one host. 4885640Sroot */ 4895640Sroot impsnd(ifp, m) 4905640Sroot struct ifnet *ifp; 4915640Sroot struct mbuf *m; 4925640Sroot { 4935640Sroot register struct imp_leader *ip; 4945640Sroot register struct host *hp; 4955640Sroot struct impcb *icp; 4966588Ssam int s, error; 4975640Sroot 4985640Sroot ip = mtod(m, struct imp_leader *); 4995640Sroot 5005640Sroot /* 5015640Sroot * Do RFNM counting for data messages 5025640Sroot * (no more than 8 outstanding to any host) 5035640Sroot */ 5046588Ssam s = splimp(); 5055640Sroot if (ip->il_mtype == IMPTYPE_DATA) { 5065640Sroot struct in_addr addr; 5075640Sroot 5085859Sroot #ifdef notdef 5095771Swnj addr.s_net = ip->il_network; 5105859Sroot #else 5116588Ssam addr.s_net = ifp->if_net; /* XXX */ 5125859Sroot #endif 5135640Sroot addr.s_host = ip->il_host; 5145640Sroot addr.s_imp = ip->il_imp; 5155771Swnj if ((hp = hostlookup(addr)) == 0) 5165771Swnj hp = hostenter(addr); 5176588Ssam if (hp && (hp->h_flags & (HF_DEAD|HF_UNREACH))) { 5186607Ssam error = hp->h_flags&HF_DEAD ? EHOSTDOWN : EHOSTUNREACH; 5196588Ssam hp->h_timer = HOSTTIMER; 5206588Ssam hp->h_flags &= ~HF_INUSE; 5216588Ssam goto bad; 5226588Ssam } 5235640Sroot 5245640Sroot /* 5255647Ssam * If IMP would block, queue until RFNM 5265640Sroot */ 5275640Sroot if (hp) { 5285640Sroot if (hp->h_rfnm < 8) { 5295640Sroot hp->h_rfnm++; 5305640Sroot goto enque; 5315640Sroot } 5326095Swnj if (hp->h_qcnt < 8) { /* high water mark */ 5336095Swnj HOST_ENQUE(hp, m); 5346095Swnj goto start; 5356095Swnj } 5365640Sroot } 5376588Ssam error = ENOBUFS; 5386588Ssam goto bad; 5395640Sroot } 5405640Sroot enque: 5416208Swnj if (IF_QFULL(&ifp->if_snd)) { 5426208Swnj IF_DROP(&ifp->if_snd); 5436588Ssam error = ENOBUFS; 5446588Ssam bad: 5456208Swnj m_freem(m); 5466588Ssam splx(s); 5476588Ssam return (error); 5486208Swnj } 5495640Sroot IF_ENQUEUE(&ifp->if_snd, m); 5506095Swnj start: 5515640Sroot icp = &imp_softc[ifp->if_unit].imp_cb; 5525640Sroot if (icp->ic_oactive == 0) 5535640Sroot (*icp->ic_start)(ifp->if_unit); 5546630Ssam splx(s); 5556504Ssam return (0); 5565640Sroot } 5575640Sroot 5585640Sroot /* 5595640Sroot * Put three 1822 NOOPs at the head of the output queue. 5605640Sroot * Part of host-IMP initialization procedure. 5615640Sroot * (Should return success/failure, but noone knows 5625640Sroot * what to do with this, so why bother?) 5636818Ssam * This routine is always called at splimp, so we don't 5646818Ssam * protect the call to IF_PREPEND. 5655640Sroot */ 5665640Sroot impnoops(sc) 5675640Sroot register struct imp_softc *sc; 5685640Sroot { 5695640Sroot register i; 5705640Sroot register struct mbuf *m; 5715771Swnj register struct control_leader *cp; 5725640Sroot 5735640Sroot sc->imp_dropcnt = IMP_DROPCNT; 5745771Swnj for (i = 0; i < IMP_DROPCNT + 1; i++ ) { 5759645Ssam if ((m = m_getclr(M_DONTWAIT, MT_HEADER)) == 0) 5765640Sroot return; 5775771Swnj m->m_len = sizeof(struct control_leader); 5785771Swnj cp = mtod(m, struct control_leader *); 5795771Swnj cp->dl_format = IMP_NFF; 5805771Swnj cp->dl_link = i; 5815771Swnj cp->dl_mtype = IMPTYPE_NOOP; 5825640Sroot IF_PREPEND(&sc->imp_if.if_snd, m); 5835640Sroot } 5845640Sroot if (sc->imp_cb.ic_oactive == 0) 5855640Sroot (*sc->imp_cb.ic_start)(sc->imp_if.if_unit); 5865640Sroot } 5877170Ssam 58813067Ssam /* 58913067Ssam * Process an ioctl request. 59013067Ssam */ 59113067Ssam impioctl(ifp, cmd, data) 59213067Ssam register struct ifnet *ifp; 59313067Ssam int cmd; 59413067Ssam caddr_t data; 59513067Ssam { 59613067Ssam struct ifreq *ifr = (struct ifreq *)data; 59713067Ssam struct sockaddr_in *sin; 59813067Ssam int s = splimp(), error = 0; 59913067Ssam 60013067Ssam switch (cmd) { 60113067Ssam 60213067Ssam case SIOCSIFADDR: 60313067Ssam if (ifp->if_flags & IFF_RUNNING) 60413067Ssam if_rtinit(ifp, -1); /* delete previous route */ 60513067Ssam sin = (struct sockaddr_in *)&ifr->ifr_addr; 60613067Ssam ifp->if_net = in_netof(sin->sin_addr); 60713067Ssam sin = (struct sockaddr_in *)&ifp->if_addr; 60813067Ssam sin->sin_family = AF_INET; 60913067Ssam /* host number filled in already, or filled in later */ 61013067Ssam sin->sin_addr = if_makeaddr(ifp->if_net, ifp->if_host[0]); 61113067Ssam if (ifp->if_flags & IFF_RUNNING) 61213067Ssam if_rtinit(ifp, RTF_UP); 61313067Ssam else 61413067Ssam impinit(ifp->if_unit); 61513067Ssam break; 61613067Ssam 61713067Ssam default: 61813067Ssam error = EINVAL; 61913067Ssam } 62013067Ssam splx(s); 62113067Ssam return (error); 62213067Ssam } 62313067Ssam 6247170Ssam #ifdef IMPLEADERS 6257170Ssam printleader(routine, ip) 6267170Ssam char *routine; 6277170Ssam register struct imp_leader *ip; 6287170Ssam { 6297170Ssam printf("%s: ", routine); 6307170Ssam printbyte((char *)ip, 12); 6317170Ssam printf("<fmt=%x,net=%x,flags=%x,mtype=", ip->il_format, ip->il_network, 6327170Ssam ip->il_flags); 6337170Ssam if (ip->il_mtype <= IMPTYPE_READY) 6347170Ssam printf("%s,", impleaders[ip->il_mtype]); 6357170Ssam else 6367170Ssam printf("%x,", ip->il_mtype); 6377170Ssam printf("htype=%x,host=%x,imp=%x,link=", ip->il_htype, ip->il_host, 6387170Ssam ntohs(ip->il_imp)); 6397170Ssam if (ip->il_link == IMPLINK_IP) 6407170Ssam printf("ip,"); 6417170Ssam else 6427170Ssam printf("%x,", ip->il_link); 6437170Ssam printf("subtype=%x,len=%x>\n",ip->il_subtype,ntohs(ip->il_length)>>3); 6447170Ssam } 6457170Ssam 6467170Ssam printbyte(cp, n) 6477170Ssam register char *cp; 6487170Ssam int n; 6497170Ssam { 6507170Ssam register i, j, c; 6517170Ssam 6527170Ssam for (i=0; i<n; i++) { 6537170Ssam c = *cp++; 6547170Ssam for (j=0; j<2; j++) 6557170Ssam putchar("0123456789abcdef"[(c>>((1-j)*4))&0xf]); 6567170Ssam putchar(' '); 6577170Ssam } 6587170Ssam putchar('\n'); 6597170Ssam } 6605640Sroot #endif 6617170Ssam #endif 662