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