1*6209Swnj /* if_loop.c 4.6 82/03/15 */ 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; 275122Swnj 285172Swnj ifp->if_name = "lo"; 295122Swnj ifp->if_mtu = LOMTU; 305122Swnj ifp->if_net = LONET; 315172Swnj ifp->if_addr = if_makeaddr(ifp->if_net, 0); 325122Swnj ifp->if_output = looutput; 335161Swnj if_attach(ifp); 345122Swnj } 355122Swnj 365122Swnj looutput(ifp, m0, pf) 375122Swnj struct ifnet *ifp; 385122Swnj struct mbuf *m0; 395122Swnj int pf; 405122Swnj { 415122Swnj int s = splimp(); 42*6209Swnj register struct ifqueue *ifq; 435122Swnj 445172Swnj ifp->if_opackets++; 455122Swnj switch (pf) { 465122Swnj 475122Swnj #ifdef INET 485122Swnj case PF_INET: 49*6209Swnj ifq = &ipintrq; 50*6209Swnj if (IF_QFULL(ifq)) { 51*6209Swnj IF_DROP(ifq); 52*6209Swnj (void) m_freem(m0); 53*6209Swnj splx(s); 54*6209Swnj return (0); 55*6209Swnj } 56*6209Swnj IF_ENQUEUE(ifq, m0); 575122Swnj setipintr(); 585122Swnj break; 595122Swnj #endif 605122Swnj 615122Swnj default: 625122Swnj splx(s); 635122Swnj printf("lo%d: can't encapsulate pf%d\n", ifp->if_unit, pf); 64*6209Swnj (void) m_freem(m0); 655122Swnj return (0); 665122Swnj } 675172Swnj ifp->if_ipackets++; 685122Swnj splx(s); 695122Swnj return (1); 705122Swnj } 71