1*10907Ssam /* if_loop.c 4.16 83/02/11 */ 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" 11*10907Ssam #include "../h/errno.h" 12*10907Ssam 13*10907Ssam #include "../net/if.h" 14*10907Ssam #include "../net/netisr.h" 15*10907Ssam #include "../net/route.h" 16*10907Ssam 178397Swnj #include "../netinet/in.h" 188397Swnj #include "../netinet/in_systm.h" 198397Swnj #include "../netinet/ip.h" 208397Swnj #include "../netinet/ip_var.h" 215122Swnj 22*10907Ssam #include "../machine/mtpr.h" 23*10907Ssam 245296Sroot #define LONET 127 255207Swnj #define LOMTU (1024+512) 265122Swnj 275122Swnj struct ifnet loif; 285122Swnj int looutput(); 295122Swnj 305122Swnj loattach() 315122Swnj { 325122Swnj register struct ifnet *ifp = &loif; 336337Ssam register struct sockaddr_in *sin; 345122Swnj 355172Swnj ifp->if_name = "lo"; 365122Swnj ifp->if_mtu = LOMTU; 375122Swnj ifp->if_net = LONET; 386337Ssam sin = (struct sockaddr_in *)&ifp->if_addr; 396337Ssam sin->sin_family = AF_INET; 406337Ssam sin->sin_addr = if_makeaddr(ifp->if_net, 0); 416337Ssam ifp->if_flags = IFF_UP; 425122Swnj ifp->if_output = looutput; 435161Swnj if_attach(ifp); 447154Swnj if_rtinit(ifp, RTF_UP); 455122Swnj } 465122Swnj 476337Ssam looutput(ifp, m0, dst) 485122Swnj struct ifnet *ifp; 495122Swnj struct mbuf *m0; 506337Ssam struct sockaddr *dst; 515122Swnj { 525122Swnj int s = splimp(); 536209Swnj register struct ifqueue *ifq; 545122Swnj 555172Swnj ifp->if_opackets++; 566337Ssam switch (dst->sa_family) { 575122Swnj 585122Swnj #ifdef INET 596337Ssam case AF_INET: 606209Swnj ifq = &ipintrq; 616209Swnj if (IF_QFULL(ifq)) { 626209Swnj IF_DROP(ifq); 636337Ssam m_freem(m0); 646209Swnj splx(s); 656544Sfeldman return (ENOBUFS); 666209Swnj } 676209Swnj IF_ENQUEUE(ifq, m0); 686262Swnj schednetisr(NETISR_IP); 695122Swnj break; 705122Swnj #endif 715122Swnj default: 725122Swnj splx(s); 736337Ssam printf("lo%d: can't handle af%d\n", ifp->if_unit, 746337Ssam dst->sa_family); 756337Ssam m_freem(m0); 766544Sfeldman return (EAFNOSUPPORT); 775122Swnj } 785172Swnj ifp->if_ipackets++; 795122Swnj splx(s); 806544Sfeldman return (0); 815122Swnj } 82