2 * Copyright (C) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
3 * Helsinki University of Technology, Finland.
5 * Copyright (C) 2005 - 2007 The AROS Dev Team
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
24 * Copyright (c) 1982, 1986 Regents of the University of California.
25 * All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * @(#)if_loop.c 7.13 (Berkeley) 4/26/91
59 * Loopback interface driver for protocol testing and timing.
64 #include <sys/param.h>
65 #include <sys/systm.h>
67 #include <sys/socket.h>
68 #include <sys/errno.h>
69 #include <sys/sockio.h>
70 #include <sys/synch.h>
73 #include <net/if_types.h>
74 #include <net/netisr.h>
75 #include <net/route.h>
79 #include <netinet/in.h>
80 #include <netinet/in_systm.h>
81 #include <netinet/in_var.h>
82 #include <netinet/ip.h>
87 #include <netns/ns_if.h>
91 #include <netiso/iso.h>
92 #include <netiso/iso_var.h>
95 #include <net/if_protos.h>
96 #include <net/if_loop_protos.h>
98 #define LOMTU (1024+512)
100 struct ifnet loif
= {0};
105 register struct ifnet
*ifp
= &loif
;
109 ifp
->if_flags
= IFF_LOOPBACK
;
110 ifp
->if_ioctl
= loioctl
;
111 ifp
->if_output
= looutput
;
112 ifp
->if_type
= IFT_LOOP
;
120 struct ifreq ifr
= { };
121 struct sockaddr_in
*ifr_saddr
= (struct sockaddr_in
*)&ifr
.ifr_addr
;
122 ifr
.ifr_addr
.sa_len
= sizeof(struct sockaddr_in
);
123 ifr
.ifr_addr
.sa_family
= AF_INET
;
124 ifr_saddr
->sin_addr
.s_addr
= htonl(0x7F000001);
125 in_control(NULL
, SIOCSIFADDR
, &ifr
, &loif
);
129 looutput(ifp
, m
, dst
, rt
)
131 register struct mbuf
*m
;
132 struct sockaddr
*dst
;
133 register struct rtentry
*rt
;
137 register struct ifqueue
*ifq
= 0;
139 if ((m
->m_flags
& M_PKTHDR
) == 0)
140 panic("looutput no HDR");
141 m
->m_pkthdr
.rcvif
= ifp
;
143 if (rt
&& rt
->rt_flags
& RTF_REJECT
) {
145 DROUTE(log(LOG_DEBUG
,"lo0: packet rejected");)
146 return (rt
->rt_flags
& RTF_HOST
? EHOSTUNREACH
: ENETUNREACH
);
149 ifp
->if_obytes
+= m
->m_pkthdr
.len
;
150 switch (dst
->sa_family
) {
171 printf("lo%ld: can't handle af%ld\n", (long)ifp
->if_unit
,
172 (long)dst
->sa_family
);
174 return (EAFNOSUPPORT
);
186 ifp
->if_ibytes
+= m
->m_pkthdr
.len
;
191 void lortrequest(int cmd
,
196 rt
->rt_rmx
.rmx_mtu
= LOMTU
;
200 * Process an ioctl request.
203 loioctl(register struct ifnet
*ifp
, int cmd
, caddr_t data
)
205 register struct ifaddr
*ifa
;
211 ifp
->if_flags
|= IFF_UP
;
212 ifa
= (struct ifaddr
*)data
;
213 if (ifa
!= 0 && ifa
->ifa_addr
->sa_family
== AF_ISO
)
214 ifa
->ifa_rtrequest
= lortrequest
;
216 * Everything else is done at a higher level.