xref: /csrg-svn/sys/net/if_loop.c (revision 12460)
1*12460Ssam /*	if_loop.c	4.17	83/05/15	*/
25122Swnj 
35122Swnj /*
45122Swnj  * Loopback interface driver for protocol testing and timing.
55122Swnj  */
65122Swnj 
75122Swnj #include "../h/param.h"
85122Swnj #include "../h/systm.h"
95122Swnj #include "../h/mbuf.h"
105122Swnj #include "../h/socket.h"
1110907Ssam #include "../h/errno.h"
1210907Ssam 
1310907Ssam #include "../net/if.h"
1410907Ssam #include "../net/netisr.h"
1510907Ssam #include "../net/route.h"
1610907Ssam 
178397Swnj #include "../netinet/in.h"
188397Swnj #include "../netinet/in_systm.h"
198397Swnj #include "../netinet/ip.h"
208397Swnj #include "../netinet/ip_var.h"
215122Swnj 
22*12460Ssam #ifdef vax
23*12460Ssam #include "../vax/mtpr.h"
24*12460Ssam #endif
2510907Ssam 
265296Sroot #define	LONET	127
275207Swnj #define	LOMTU	(1024+512)
285122Swnj 
295122Swnj struct	ifnet loif;
305122Swnj int	looutput();
315122Swnj 
325122Swnj loattach()
335122Swnj {
345122Swnj 	register struct ifnet *ifp = &loif;
356337Ssam 	register struct sockaddr_in *sin;
365122Swnj 
375172Swnj 	ifp->if_name = "lo";
385122Swnj 	ifp->if_mtu = LOMTU;
395122Swnj 	ifp->if_net = LONET;
406337Ssam 	sin = (struct sockaddr_in *)&ifp->if_addr;
416337Ssam 	sin->sin_family = AF_INET;
426337Ssam 	sin->sin_addr = if_makeaddr(ifp->if_net, 0);
436337Ssam 	ifp->if_flags = IFF_UP;
445122Swnj 	ifp->if_output = looutput;
455161Swnj 	if_attach(ifp);
467154Swnj 	if_rtinit(ifp, RTF_UP);
475122Swnj }
485122Swnj 
496337Ssam looutput(ifp, m0, dst)
505122Swnj 	struct ifnet *ifp;
515122Swnj 	struct mbuf *m0;
526337Ssam 	struct sockaddr *dst;
535122Swnj {
545122Swnj 	int s = splimp();
556209Swnj 	register struct ifqueue *ifq;
565122Swnj 
575172Swnj 	ifp->if_opackets++;
586337Ssam 	switch (dst->sa_family) {
595122Swnj 
605122Swnj #ifdef INET
616337Ssam 	case AF_INET:
626209Swnj 		ifq = &ipintrq;
636209Swnj 		if (IF_QFULL(ifq)) {
646209Swnj 			IF_DROP(ifq);
656337Ssam 			m_freem(m0);
666209Swnj 			splx(s);
676544Sfeldman 			return (ENOBUFS);
686209Swnj 		}
696209Swnj 		IF_ENQUEUE(ifq, m0);
706262Swnj 		schednetisr(NETISR_IP);
715122Swnj 		break;
725122Swnj #endif
735122Swnj 	default:
745122Swnj 		splx(s);
756337Ssam 		printf("lo%d: can't handle af%d\n", ifp->if_unit,
766337Ssam 			dst->sa_family);
776337Ssam 		m_freem(m0);
786544Sfeldman 		return (EAFNOSUPPORT);
795122Swnj 	}
805172Swnj 	ifp->if_ipackets++;
815122Swnj 	splx(s);
826544Sfeldman 	return (0);
835122Swnj }
84