1 /* if_loop.c 4.8 82/03/28 */ 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 register struct sockaddr_in *sin; 28 29 ifp->if_name = "lo"; 30 ifp->if_mtu = LOMTU; 31 ifp->if_net = LONET; 32 sin = (struct sockaddr_in *)&ifp->if_addr; 33 sin->sin_family = AF_INET; 34 sin->sin_addr = if_makeaddr(ifp->if_net, 0); 35 ifp->if_flags = IFF_UP; 36 ifp->if_output = looutput; 37 if_attach(ifp); 38 } 39 40 looutput(ifp, m0, dst) 41 struct ifnet *ifp; 42 struct mbuf *m0; 43 struct sockaddr *dst; 44 { 45 int s = splimp(); 46 register struct ifqueue *ifq; 47 48 ifp->if_opackets++; 49 switch (dst->sa_family) { 50 51 #ifdef INET 52 case AF_INET: 53 ifq = &ipintrq; 54 if (IF_QFULL(ifq)) { 55 IF_DROP(ifq); 56 m_freem(m0); 57 splx(s); 58 return (0); 59 } 60 IF_ENQUEUE(ifq, m0); 61 schednetisr(NETISR_IP); 62 break; 63 #endif 64 default: 65 splx(s); 66 printf("lo%d: can't handle af%d\n", ifp->if_unit, 67 dst->sa_family); 68 m_freem(m0); 69 return (0); 70 } 71 ifp->if_ipackets++; 72 splx(s); 73 return (1); 74 } 75