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