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