Commit | Line | Data |
---|---|---|
0939c871 | 1 | /* if_loop.c 4.5 81/12/22 */ |
0a486d2b BJ |
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 | ||
0939c871 | 18 | #define LONET 127 |
56e0df97 | 19 | #define LOMTU (1024+512) |
0a486d2b BJ |
20 | |
21 | struct ifnet loif; | |
22 | int looutput(); | |
23 | ||
24 | loattach() | |
25 | { | |
26 | register struct ifnet *ifp = &loif; | |
27 | ||
b454c3ea | 28 | ifp->if_name = "lo"; |
0a486d2b BJ |
29 | ifp->if_mtu = LOMTU; |
30 | ifp->if_net = LONET; | |
b454c3ea | 31 | ifp->if_addr = if_makeaddr(ifp->if_net, 0); |
0a486d2b | 32 | ifp->if_output = looutput; |
405c9168 | 33 | if_attach(ifp); |
0a486d2b BJ |
34 | } |
35 | ||
36 | looutput(ifp, m0, pf) | |
37 | struct ifnet *ifp; | |
38 | struct mbuf *m0; | |
39 | int pf; | |
40 | { | |
41 | int s = splimp(); | |
42 | ||
b454c3ea | 43 | ifp->if_opackets++; |
0a486d2b BJ |
44 | switch (pf) { |
45 | ||
46 | #ifdef INET | |
47 | case PF_INET: | |
48 | IF_ENQUEUE(&ipintrq, m0); | |
49 | setipintr(); | |
50 | break; | |
51 | #endif | |
52 | ||
53 | default: | |
54 | splx(s); | |
55 | printf("lo%d: can't encapsulate pf%d\n", ifp->if_unit, pf); | |
56 | m_freem(m0); | |
57 | return (0); | |
58 | } | |
b454c3ea | 59 | ifp->if_ipackets++; |
0a486d2b BJ |
60 | splx(s); |
61 | return (1); | |
62 | } |