1 /* if_loop.c 4.16 83/02/11 */ 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 "../h/errno.h" 12 13 #include "../net/if.h" 14 #include "../net/netisr.h" 15 #include "../net/route.h" 16 17 #include "../netinet/in.h" 18 #include "../netinet/in_systm.h" 19 #include "../netinet/ip.h" 20 #include "../netinet/ip_var.h" 21 22 #include "../machine/mtpr.h" 23 24 #define LONET 127 25 #define LOMTU (1024+512) 26 27 struct ifnet loif; 28 int looutput(); 29 30 loattach() 31 { 32 register struct ifnet *ifp = &loif; 33 register struct sockaddr_in *sin; 34 35 ifp->if_name = "lo"; 36 ifp->if_mtu = LOMTU; 37 ifp->if_net = LONET; 38 sin = (struct sockaddr_in *)&ifp->if_addr; 39 sin->sin_family = AF_INET; 40 sin->sin_addr = if_makeaddr(ifp->if_net, 0); 41 ifp->if_flags = IFF_UP; 42 ifp->if_output = looutput; 43 if_attach(ifp); 44 if_rtinit(ifp, RTF_UP); 45 } 46 47 looutput(ifp, m0, dst) 48 struct ifnet *ifp; 49 struct mbuf *m0; 50 struct sockaddr *dst; 51 { 52 int s = splimp(); 53 register struct ifqueue *ifq; 54 55 ifp->if_opackets++; 56 switch (dst->sa_family) { 57 58 #ifdef INET 59 case AF_INET: 60 ifq = &ipintrq; 61 if (IF_QFULL(ifq)) { 62 IF_DROP(ifq); 63 m_freem(m0); 64 splx(s); 65 return (ENOBUFS); 66 } 67 IF_ENQUEUE(ifq, m0); 68 schednetisr(NETISR_IP); 69 break; 70 #endif 71 default: 72 splx(s); 73 printf("lo%d: can't handle af%d\n", ifp->if_unit, 74 dst->sa_family); 75 m_freem(m0); 76 return (EAFNOSUPPORT); 77 } 78 ifp->if_ipackets++; 79 splx(s); 80 return (0); 81 } 82