Commit | Line | Data |
---|---|---|
4d06a026 | 1 | /* if_loop.c 4.15 82/10/13 */ |
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" | |
fcfe450e BJ |
11 | #include "../netinet/in.h" |
12 | #include "../netinet/in_systm.h" | |
0a486d2b | 13 | #include "../net/if.h" |
fcfe450e BJ |
14 | #include "../net/netisr.h" |
15 | #include "../netinet/ip.h" | |
16 | #include "../netinet/ip_var.h" | |
4d06a026 | 17 | #include "../vax/mtpr.h" |
f6311fb6 | 18 | #include "../net/route.h" |
4766fb62 | 19 | #include <errno.h> |
0a486d2b | 20 | |
0939c871 | 21 | #define LONET 127 |
56e0df97 | 22 | #define LOMTU (1024+512) |
0a486d2b BJ |
23 | |
24 | struct ifnet loif; | |
25 | int looutput(); | |
26 | ||
27 | loattach() | |
28 | { | |
29 | register struct ifnet *ifp = &loif; | |
ee787340 | 30 | register struct sockaddr_in *sin; |
0a486d2b | 31 | |
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); |
a13c006d | 41 | if_rtinit(ifp, 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 | |
b454c3ea | 52 | ifp->if_opackets++; |
ee787340 | 53 | switch (dst->sa_family) { |
0a486d2b BJ |
54 | |
55 | #ifdef INET | |
ee787340 | 56 | case AF_INET: |
1e977657 BJ |
57 | ifq = &ipintrq; |
58 | if (IF_QFULL(ifq)) { | |
59 | IF_DROP(ifq); | |
ee787340 | 60 | m_freem(m0); |
1e977657 | 61 | splx(s); |
4c5902e0 | 62 | return (ENOBUFS); |
1e977657 BJ |
63 | } |
64 | IF_ENQUEUE(ifq, m0); | |
9c8692e9 | 65 | schednetisr(NETISR_IP); |
0a486d2b BJ |
66 | break; |
67 | #endif | |
0a486d2b BJ |
68 | default: |
69 | splx(s); | |
ee787340 SL |
70 | printf("lo%d: can't handle af%d\n", ifp->if_unit, |
71 | dst->sa_family); | |
72 | m_freem(m0); | |
4c5902e0 | 73 | return (EAFNOSUPPORT); |
0a486d2b | 74 | } |
b454c3ea | 75 | ifp->if_ipackets++; |
0a486d2b | 76 | splx(s); |
4c5902e0 | 77 | return (0); |
0a486d2b | 78 | } |