1 /* if_loop.c 6.3 85/03/18 */ 2 3 /* 4 * Loopback interface driver for protocol testing and timing. 5 */ 6 7 #include "param.h" 8 #include "systm.h" 9 #include "mbuf.h" 10 #include "socket.h" 11 #include "errno.h" 12 #include "ioctl.h" 13 14 #include "../net/if.h" 15 #include "../net/netisr.h" 16 #include "../net/route.h" 17 18 #include "in.h" 19 #include "in_systm.h" 20 #include "ip.h" 21 #include "ip_var.h" 22 23 #ifdef vax 24 #include "../vax/mtpr.h" 25 #endif 26 27 #define LONET 127 28 #define LOHOST 1 /* can't be 0, that's broadcast */ 29 #define LOMTU (1024+512) 30 31 struct ifnet loif; 32 int looutput(), loioctl(); 33 34 loattach() 35 { 36 register struct ifnet *ifp = &loif; 37 register struct sockaddr_in *sin; 38 39 ifp->if_name = "lo"; 40 ifp->if_mtu = LOMTU; 41 ifp->if_ioctl = loioctl; 42 ifp->if_output = looutput; 43 if_attach(ifp); 44 } 45 46 looutput(ifp, m0, dst) 47 struct ifnet *ifp; 48 struct mbuf *m0; 49 struct sockaddr *dst; 50 { 51 int s = splimp(); 52 register struct ifqueue *ifq; 53 54 ifp->if_opackets++; 55 switch (dst->sa_family) { 56 57 #ifdef INET 58 case AF_INET: 59 ifq = &ipintrq; 60 if (IF_QFULL(ifq)) { 61 IF_DROP(ifq); 62 m_freem(m0); 63 splx(s); 64 return (ENOBUFS); 65 } 66 IF_ENQUEUE(ifq, m0); 67 schednetisr(NETISR_IP); 68 break; 69 #endif 70 default: 71 splx(s); 72 printf("lo%d: can't handle af%d\n", ifp->if_unit, 73 dst->sa_family); 74 m_freem(m0); 75 return (EAFNOSUPPORT); 76 } 77 ifp->if_ipackets++; 78 splx(s); 79 return (0); 80 } 81 82 /* 83 * Process an ioctl request. 84 */ 85 /* ARGSUSED */ 86 loioctl(ifp, cmd, data) 87 register struct ifnet *ifp; 88 int cmd; 89 caddr_t data; 90 { 91 int error = 0; 92 93 switch (cmd) { 94 95 case SIOCSIFADDR: 96 ifp->if_flags |= IFF_UP; 97 /* 98 * Everything else is done at a higher level. 99 */ 100 break; 101 102 default: 103 error = EINVAL; 104 } 105 return (error); 106 } 107