1*12761Ssam /* if_loop.c 4.18 83/05/27 */ 25122Swnj 35122Swnj /* 45122Swnj * Loopback interface driver for protocol testing and timing. 55122Swnj */ 65122Swnj 75122Swnj #include "../h/param.h" 85122Swnj #include "../h/systm.h" 95122Swnj #include "../h/mbuf.h" 105122Swnj #include "../h/socket.h" 1110907Ssam #include "../h/errno.h" 1210907Ssam 1310907Ssam #include "../net/if.h" 1410907Ssam #include "../net/netisr.h" 1510907Ssam #include "../net/route.h" 1610907Ssam 178397Swnj #include "../netinet/in.h" 188397Swnj #include "../netinet/in_systm.h" 198397Swnj #include "../netinet/ip.h" 208397Swnj #include "../netinet/ip_var.h" 215122Swnj 2212460Ssam #ifdef vax 2312460Ssam #include "../vax/mtpr.h" 2412460Ssam #endif 2510907Ssam 265296Sroot #define LONET 127 27*12761Ssam #define LOHOST 1 /* can't be 0, that's broadcast */ 285207Swnj #define LOMTU (1024+512) 295122Swnj 305122Swnj struct ifnet loif; 315122Swnj int looutput(); 325122Swnj 335122Swnj loattach() 345122Swnj { 355122Swnj register struct ifnet *ifp = &loif; 366337Ssam register struct sockaddr_in *sin; 375122Swnj 385172Swnj ifp->if_name = "lo"; 395122Swnj ifp->if_mtu = LOMTU; 405122Swnj ifp->if_net = LONET; 41*12761Ssam ifp->if_host[0] = LOHOST; 426337Ssam sin = (struct sockaddr_in *)&ifp->if_addr; 436337Ssam sin->sin_family = AF_INET; 44*12761Ssam sin->sin_addr = if_makeaddr(ifp->if_net, LOHOST); 456337Ssam ifp->if_flags = IFF_UP; 465122Swnj ifp->if_output = looutput; 475161Swnj if_attach(ifp); 487154Swnj if_rtinit(ifp, RTF_UP); 495122Swnj } 505122Swnj 516337Ssam looutput(ifp, m0, dst) 525122Swnj struct ifnet *ifp; 535122Swnj struct mbuf *m0; 546337Ssam struct sockaddr *dst; 555122Swnj { 565122Swnj int s = splimp(); 576209Swnj register struct ifqueue *ifq; 585122Swnj 595172Swnj ifp->if_opackets++; 606337Ssam switch (dst->sa_family) { 615122Swnj 625122Swnj #ifdef INET 636337Ssam case AF_INET: 646209Swnj ifq = &ipintrq; 656209Swnj if (IF_QFULL(ifq)) { 666209Swnj IF_DROP(ifq); 676337Ssam m_freem(m0); 686209Swnj splx(s); 696544Sfeldman return (ENOBUFS); 706209Swnj } 716209Swnj IF_ENQUEUE(ifq, m0); 726262Swnj schednetisr(NETISR_IP); 735122Swnj break; 745122Swnj #endif 755122Swnj default: 765122Swnj splx(s); 776337Ssam printf("lo%d: can't handle af%d\n", ifp->if_unit, 786337Ssam dst->sa_family); 796337Ssam m_freem(m0); 806544Sfeldman return (EAFNOSUPPORT); 815122Swnj } 825172Swnj ifp->if_ipackets++; 835122Swnj splx(s); 846544Sfeldman return (0); 855122Swnj } 86