Commit | Line | Data |
---|---|---|
4766fb62 | 1 | /* if_loop.c 4.11 82/04/16 */ |
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" | |
f6311fb6 | 17 | #include "../net/route.h" |
4766fb62 | 18 | #include <errno.h> |
0a486d2b | 19 | |
0939c871 | 20 | #define LONET 127 |
56e0df97 | 21 | #define LOMTU (1024+512) |
0a486d2b BJ |
22 | |
23 | struct ifnet loif; | |
24 | int looutput(); | |
25 | ||
26 | loattach() | |
27 | { | |
28 | register struct ifnet *ifp = &loif; | |
ee787340 | 29 | register struct sockaddr_in *sin; |
0a486d2b | 30 | |
f6311fb6 | 31 | COUNT(LOATTACH); |
b454c3ea | 32 | ifp->if_name = "lo"; |
0a486d2b BJ |
33 | ifp->if_mtu = LOMTU; |
34 | ifp->if_net = LONET; | |
ee787340 SL |
35 | sin = (struct sockaddr_in *)&ifp->if_addr; |
36 | sin->sin_family = AF_INET; | |
37 | sin->sin_addr = if_makeaddr(ifp->if_net, 0); | |
38 | ifp->if_flags = IFF_UP; | |
0a486d2b | 39 | ifp->if_output = looutput; |
405c9168 | 40 | if_attach(ifp); |
f6311fb6 | 41 | if_rtinit(ifp, RTF_DIRECT|RTF_UP); |
0a486d2b BJ |
42 | } |
43 | ||
ee787340 | 44 | looutput(ifp, m0, dst) |
0a486d2b BJ |
45 | struct ifnet *ifp; |
46 | struct mbuf *m0; | |
ee787340 | 47 | struct sockaddr *dst; |
0a486d2b BJ |
48 | { |
49 | int s = splimp(); | |
1e977657 | 50 | register struct ifqueue *ifq; |
0a486d2b | 51 | |
f6311fb6 | 52 | COUNT(LOOUTPUT); |
b454c3ea | 53 | ifp->if_opackets++; |
ee787340 | 54 | switch (dst->sa_family) { |
0a486d2b BJ |
55 | |
56 | #ifdef INET | |
ee787340 | 57 | case AF_INET: |
1e977657 BJ |
58 | ifq = &ipintrq; |
59 | if (IF_QFULL(ifq)) { | |
60 | IF_DROP(ifq); | |
ee787340 | 61 | m_freem(m0); |
1e977657 | 62 | splx(s); |
4c5902e0 | 63 | return (ENOBUFS); |
1e977657 BJ |
64 | } |
65 | IF_ENQUEUE(ifq, m0); | |
9c8692e9 | 66 | schednetisr(NETISR_IP); |
0a486d2b BJ |
67 | break; |
68 | #endif | |
0a486d2b BJ |
69 | default: |
70 | splx(s); | |
ee787340 SL |
71 | printf("lo%d: can't handle af%d\n", ifp->if_unit, |
72 | dst->sa_family); | |
73 | m_freem(m0); | |
4c5902e0 | 74 | return (EAFNOSUPPORT); |
0a486d2b | 75 | } |
b454c3ea | 76 | ifp->if_ipackets++; |
0a486d2b | 77 | splx(s); |
4c5902e0 | 78 | return (0); |
0a486d2b | 79 | } |