1*6337Ssam /* if_loop.c 4.8 82/03/28 */ 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" 115122Swnj #include "../net/in.h" 125122Swnj #include "../net/in_systm.h" 135122Swnj #include "../net/if.h" 145122Swnj #include "../net/ip.h" 155122Swnj #include "../net/ip_var.h" 165122Swnj #include "../h/mtpr.h" 175122Swnj 185296Sroot #define LONET 127 195207Swnj #define LOMTU (1024+512) 205122Swnj 215122Swnj struct ifnet loif; 225122Swnj int looutput(); 235122Swnj 245122Swnj loattach() 255122Swnj { 265122Swnj register struct ifnet *ifp = &loif; 27*6337Ssam register struct sockaddr_in *sin; 285122Swnj 295172Swnj ifp->if_name = "lo"; 305122Swnj ifp->if_mtu = LOMTU; 315122Swnj ifp->if_net = LONET; 32*6337Ssam sin = (struct sockaddr_in *)&ifp->if_addr; 33*6337Ssam sin->sin_family = AF_INET; 34*6337Ssam sin->sin_addr = if_makeaddr(ifp->if_net, 0); 35*6337Ssam ifp->if_flags = IFF_UP; 365122Swnj ifp->if_output = looutput; 375161Swnj if_attach(ifp); 385122Swnj } 395122Swnj 40*6337Ssam looutput(ifp, m0, dst) 415122Swnj struct ifnet *ifp; 425122Swnj struct mbuf *m0; 43*6337Ssam struct sockaddr *dst; 445122Swnj { 455122Swnj int s = splimp(); 466209Swnj register struct ifqueue *ifq; 475122Swnj 485172Swnj ifp->if_opackets++; 49*6337Ssam switch (dst->sa_family) { 505122Swnj 515122Swnj #ifdef INET 52*6337Ssam case AF_INET: 536209Swnj ifq = &ipintrq; 546209Swnj if (IF_QFULL(ifq)) { 556209Swnj IF_DROP(ifq); 56*6337Ssam m_freem(m0); 576209Swnj splx(s); 586209Swnj return (0); 596209Swnj } 606209Swnj IF_ENQUEUE(ifq, m0); 616262Swnj schednetisr(NETISR_IP); 625122Swnj break; 635122Swnj #endif 645122Swnj default: 655122Swnj splx(s); 66*6337Ssam printf("lo%d: can't handle af%d\n", ifp->if_unit, 67*6337Ssam dst->sa_family); 68*6337Ssam m_freem(m0); 695122Swnj return (0); 705122Swnj } 715172Swnj ifp->if_ipackets++; 725122Swnj splx(s); 735122Swnj return (1); 745122Swnj } 75