xref: /original-bsd/sys/net/if_loop.c (revision 05858660)
1 /*	if_loop.c	4.7	82/03/19	*/
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 "../net/in.h"
12 #include "../net/in_systm.h"
13 #include "../net/if.h"
14 #include "../net/ip.h"
15 #include "../net/ip_var.h"
16 #include "../h/mtpr.h"
17 
18 #define	LONET	127
19 #define	LOMTU	(1024+512)
20 
21 struct	ifnet loif;
22 int	looutput();
23 
24 loattach()
25 {
26 	register struct ifnet *ifp = &loif;
27 
28 	ifp->if_name = "lo";
29 	ifp->if_mtu = LOMTU;
30 	ifp->if_net = LONET;
31 	ifp->if_addr = if_makeaddr(ifp->if_net, 0);
32 	ifp->if_output = looutput;
33 	if_attach(ifp);
34 }
35 
36 looutput(ifp, m0, pf)
37 	struct ifnet *ifp;
38 	struct mbuf *m0;
39 	int pf;
40 {
41 	int s = splimp();
42 	register struct ifqueue *ifq;
43 
44 	ifp->if_opackets++;
45 	switch (pf) {
46 
47 #ifdef INET
48 	case PF_INET:
49 		ifq = &ipintrq;
50 		if (IF_QFULL(ifq)) {
51 			IF_DROP(ifq);
52 			(void) m_freem(m0);
53 			splx(s);
54 			return (0);
55 		}
56 		IF_ENQUEUE(ifq, m0);
57 		schednetisr(NETISR_IP);
58 		break;
59 #endif
60 
61 	default:
62 		splx(s);
63 		printf("lo%d: can't encapsulate pf%d\n", ifp->if_unit, pf);
64 		(void) m_freem(m0);
65 		return (0);
66 	}
67 	ifp->if_ipackets++;
68 	splx(s);
69 	return (1);
70 }
71