1 /* if_loop.c 4.5 81/12/22 */ 2 3 /* 4 * Loopback interface driver for protocol testing and timing. 5 */ 6 7 #include "../h/param.h" 8 #include "../h/systm.h" 9 #include "../h/mbuf.h" 10 #include "../h/socket.h" 11 #include "../net/in.h" 12 #include "../net/in_systm.h" 13 #include "../net/if.h" 14 #include "../net/ip.h" 15 #include "../net/ip_var.h" 16 #include "../h/mtpr.h" 17 18 #define LONET 127 19 #define LOMTU (1024+512) 20 21 struct ifnet loif; 22 int looutput(); 23 24 loattach() 25 { 26 register struct ifnet *ifp = &loif; 27 28 ifp->if_name = "lo"; 29 ifp->if_mtu = LOMTU; 30 ifp->if_net = LONET; 31 ifp->if_addr = if_makeaddr(ifp->if_net, 0); 32 ifp->if_output = looutput; 33 if_attach(ifp); 34 } 35 36 looutput(ifp, m0, pf) 37 struct ifnet *ifp; 38 struct mbuf *m0; 39 int pf; 40 { 41 int s = splimp(); 42 43 ifp->if_opackets++; 44 switch (pf) { 45 46 #ifdef INET 47 case PF_INET: 48 IF_ENQUEUE(&ipintrq, m0); 49 setipintr(); 50 break; 51 #endif 52 53 default: 54 splx(s); 55 printf("lo%d: can't encapsulate pf%d\n", ifp->if_unit, pf); 56 m_freem(m0); 57 return (0); 58 } 59 ifp->if_ipackets++; 60 splx(s); 61 return (1); 62 } 63