xref: /xnu-12377.1.9/bsd/net/net_osdep.h (revision f6217f891ac0bb64f3d375211650a4c1ff8ca1ea)
1*f6217f89SApple OSS Distributions /*
2*f6217f89SApple OSS Distributions  * Copyright (c) 2000-2010 Apple Inc. All rights reserved.
3*f6217f89SApple OSS Distributions  *
4*f6217f89SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*f6217f89SApple OSS Distributions  *
6*f6217f89SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*f6217f89SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*f6217f89SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*f6217f89SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*f6217f89SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*f6217f89SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*f6217f89SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*f6217f89SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*f6217f89SApple OSS Distributions  *
15*f6217f89SApple OSS Distributions  * Please obtain a copy of the License at
16*f6217f89SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*f6217f89SApple OSS Distributions  *
18*f6217f89SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*f6217f89SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*f6217f89SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*f6217f89SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*f6217f89SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*f6217f89SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*f6217f89SApple OSS Distributions  * limitations under the License.
25*f6217f89SApple OSS Distributions  *
26*f6217f89SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*f6217f89SApple OSS Distributions  */
28*f6217f89SApple OSS Distributions /*
29*f6217f89SApple OSS Distributions  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
30*f6217f89SApple OSS Distributions  * All rights reserved.
31*f6217f89SApple OSS Distributions  *
32*f6217f89SApple OSS Distributions  * Redistribution and use in source and binary forms, with or without
33*f6217f89SApple OSS Distributions  * modification, are permitted provided that the following conditions
34*f6217f89SApple OSS Distributions  * are met:
35*f6217f89SApple OSS Distributions  * 1. Redistributions of source code must retain the above copyright
36*f6217f89SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer.
37*f6217f89SApple OSS Distributions  * 2. Redistributions in binary form must reproduce the above copyright
38*f6217f89SApple OSS Distributions  *    notice, this list of conditions and the following disclaimer in the
39*f6217f89SApple OSS Distributions  *    documentation and/or other materials provided with the distribution.
40*f6217f89SApple OSS Distributions  * 3. Neither the name of the project nor the names of its contributors
41*f6217f89SApple OSS Distributions  *    may be used to endorse or promote products derived from this software
42*f6217f89SApple OSS Distributions  *    without specific prior written permission.
43*f6217f89SApple OSS Distributions  *
44*f6217f89SApple OSS Distributions  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
45*f6217f89SApple OSS Distributions  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46*f6217f89SApple OSS Distributions  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47*f6217f89SApple OSS Distributions  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
48*f6217f89SApple OSS Distributions  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49*f6217f89SApple OSS Distributions  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50*f6217f89SApple OSS Distributions  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51*f6217f89SApple OSS Distributions  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52*f6217f89SApple OSS Distributions  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53*f6217f89SApple OSS Distributions  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
54*f6217f89SApple OSS Distributions  * SUCH DAMAGE.
55*f6217f89SApple OSS Distributions  */
56*f6217f89SApple OSS Distributions /*
57*f6217f89SApple OSS Distributions  * glue for kernel code programming differences.
58*f6217f89SApple OSS Distributions  */
59*f6217f89SApple OSS Distributions 
60*f6217f89SApple OSS Distributions /*
61*f6217f89SApple OSS Distributions  * OS dependencies:
62*f6217f89SApple OSS Distributions  *
63*f6217f89SApple OSS Distributions  * - whether the IPv4 input routine convert the byte order of some fileds
64*f6217f89SApple OSS Distributions  *   of the IP header (x: convert to the host byte order, s: strip the header
65*f6217f89SApple OSS Distributions  *   length for possible reassembly)
66*f6217f89SApple OSS Distributions  *          ip_len ip_id ip_off
67*f6217f89SApple OSS Distributions  * bsdi3:       xs     x      x
68*f6217f89SApple OSS Distributions  * bsdi4:       xs            x
69*f6217f89SApple OSS Distributions  * FreeBSD:     xs            x
70*f6217f89SApple OSS Distributions  * NetBSD:       x            x
71*f6217f89SApple OSS Distributions  * OpenBSD:     xs     x      x
72*f6217f89SApple OSS Distributions  *
73*f6217f89SApple OSS Distributions  * - ifa_ifwithaf()
74*f6217f89SApple OSS Distributions  *   bsdi[34], netbsd, and openbsd define it in sys/net/if.c
75*f6217f89SApple OSS Distributions  *   freebsd (all versions) does not have it.
76*f6217f89SApple OSS Distributions  *
77*f6217f89SApple OSS Distributions  * - struct rt_addrinfo
78*f6217f89SApple OSS Distributions  *   bsdi4, netbsd 1.5R and beyond: rti_addrs, rti_info[], rti_flags, rti_ifa,
79*f6217f89SApple OSS Distributions  *	rti_ifp, and rti_rtm.
80*f6217f89SApple OSS Distributions  *   others: rti_addrs and rti_info[] only.
81*f6217f89SApple OSS Distributions  *
82*f6217f89SApple OSS Distributions  * - ifa->ifa_rtrequest
83*f6217f89SApple OSS Distributions  *   bsdi4, netbsd 1.5R and beyond: rt_addrinfo *
84*f6217f89SApple OSS Distributions  *   others: sockaddr * (note that sys/net/route.c:rtrequest() has an unsafe
85*f6217f89SApple OSS Distributions  *	typecast code, from 4.3BSD-reno)
86*f6217f89SApple OSS Distributions  *
87*f6217f89SApple OSS Distributions  * - side effects of rtrequest{,1}(RTM_DELETE)
88*f6217f89SApple OSS Distributions  *	BSDI[34]: delete all cloned routes underneath the route.
89*f6217f89SApple OSS Distributions  *	FreeBSD[234]: delete all protocol-cloned routes underneath the route.
90*f6217f89SApple OSS Distributions  *		      note that cloned routes from an interface direct route
91*f6217f89SApple OSS Distributions  *		      still remain.
92*f6217f89SApple OSS Distributions  *	NetBSD: 1.5 have no side effects.  KAME/netbsd15, and post-1.5R, have
93*f6217f89SApple OSS Distributions  *		the same effects as of BSDI.
94*f6217f89SApple OSS Distributions  *	OpenBSD: have no side effects.  KAME/openbsd has the same effects as
95*f6217f89SApple OSS Distributions  *		of BSDI (the change is not merged - yet).
96*f6217f89SApple OSS Distributions  *
97*f6217f89SApple OSS Distributions  * - privileged process
98*f6217f89SApple OSS Distributions  *	NetBSD, FreeBSD 3
99*f6217f89SApple OSS Distributions  *		struct proc *p;
100*f6217f89SApple OSS Distributions  *		if (p && !suser(p->p_ucred, &p->p_acflag))
101*f6217f89SApple OSS Distributions  *			privileged;
102*f6217f89SApple OSS Distributions  *	FreeBSD 4
103*f6217f89SApple OSS Distributions  *		struct proc *p;
104*f6217f89SApple OSS Distributions  *		if (p && !suser(p))
105*f6217f89SApple OSS Distributions  *			privileged;
106*f6217f89SApple OSS Distributions  *	OpenBSD, BSDI [34], FreeBSD 2
107*f6217f89SApple OSS Distributions  *		struct socket *so;
108*f6217f89SApple OSS Distributions  *		if (so->so_state & SS_PRIV)
109*f6217f89SApple OSS Distributions  *			privileged;
110*f6217f89SApple OSS Distributions  * - foo_control
111*f6217f89SApple OSS Distributions  *	NetBSD, FreeBSD 3
112*f6217f89SApple OSS Distributions  *		needs to give struct proc * as argument
113*f6217f89SApple OSS Distributions  *	OpenBSD, BSDI [34], FreeBSD 2
114*f6217f89SApple OSS Distributions  *		do not need struct proc *
115*f6217f89SApple OSS Distributions  *
116*f6217f89SApple OSS Distributions  * - bpf:
117*f6217f89SApple OSS Distributions  *	OpenBSD, NetBSD 1.5, BSDI [34]
118*f6217f89SApple OSS Distributions  *		need caddr_t * (= if_bpf **) and struct ifnet *
119*f6217f89SApple OSS Distributions  *	FreeBSD 2, FreeBSD 3, NetBSD post-1.5N
120*f6217f89SApple OSS Distributions  *		need only struct ifnet * as argument
121*f6217f89SApple OSS Distributions  *
122*f6217f89SApple OSS Distributions  * - struct ifnet
123*f6217f89SApple OSS Distributions  *			use queue.h?	member names	if name
124*f6217f89SApple OSS Distributions  *			---		---		---
125*f6217f89SApple OSS Distributions  *	FreeBSD 2	no		old standard	if_name+unit
126*f6217f89SApple OSS Distributions  *	FreeBSD 3	yes		strange		if_name+unit
127*f6217f89SApple OSS Distributions  *	OpenBSD		yes		standard	if_xname
128*f6217f89SApple OSS Distributions  *	NetBSD		yes		standard	if_xname
129*f6217f89SApple OSS Distributions  *	BSDI [34]	no		old standard	if_name+unit
130*f6217f89SApple OSS Distributions  *
131*f6217f89SApple OSS Distributions  * - usrreq
132*f6217f89SApple OSS Distributions  *	NetBSD, OpenBSD, BSDI [34], FreeBSD 2
133*f6217f89SApple OSS Distributions  *		single function with PRU_xx, arguments are mbuf
134*f6217f89SApple OSS Distributions  *	FreeBSD 3
135*f6217f89SApple OSS Distributions  *		separates functions, non-mbuf arguments
136*f6217f89SApple OSS Distributions  *
137*f6217f89SApple OSS Distributions  * - {set,get}sockopt
138*f6217f89SApple OSS Distributions  *	NetBSD, OpenBSD, BSDI [34], FreeBSD 2
139*f6217f89SApple OSS Distributions  *		manipulation based on mbuf
140*f6217f89SApple OSS Distributions  *	FreeBSD 3
141*f6217f89SApple OSS Distributions  *		non-mbuf manipulation using sooptcopy{in,out}()
142*f6217f89SApple OSS Distributions  *
143*f6217f89SApple OSS Distributions  * - timeout() and untimeout()
144*f6217f89SApple OSS Distributions  *	NetBSD 1.4.x, OpenBSD, BSDI [34], FreeBSD 2
145*f6217f89SApple OSS Distributions  *		timeout() is a void function
146*f6217f89SApple OSS Distributions  *	FreeBSD 3
147*f6217f89SApple OSS Distributions  *		timeout() is non-void, must keep returned value for untimeout()
148*f6217f89SApple OSS Distributions  *		callout_xx is also available (sys/callout.h)
149*f6217f89SApple OSS Distributions  *	NetBSD 1.5
150*f6217f89SApple OSS Distributions  *		timeout() is obsoleted, use callout_xx (sys/callout.h)
151*f6217f89SApple OSS Distributions  *	OpenBSD 2.8
152*f6217f89SApple OSS Distributions  *		timeout_{add,set,del} is encouraged (sys/timeout.h)
153*f6217f89SApple OSS Distributions  *
154*f6217f89SApple OSS Distributions  * - sysctl
155*f6217f89SApple OSS Distributions  *	NetBSD, OpenBSD
156*f6217f89SApple OSS Distributions  *		foo_sysctl()
157*f6217f89SApple OSS Distributions  *	BSDI [34]
158*f6217f89SApple OSS Distributions  *		foo_sysctl() but with different style.  sysctl_int_arr() takes
159*f6217f89SApple OSS Distributions  *		care of most of the cases.
160*f6217f89SApple OSS Distributions  *	FreeBSD
161*f6217f89SApple OSS Distributions  *		linker hack.  however, there are freebsd version differences
162*f6217f89SApple OSS Distributions  *		(how wonderful!).
163*f6217f89SApple OSS Distributions  *		on FreeBSD[23] function arg #define includes paren.
164*f6217f89SApple OSS Distributions  *			int foo SYSCTL_HANDLER_ARGS;
165*f6217f89SApple OSS Distributions  *		on FreeBSD4, function arg #define does not include paren.
166*f6217f89SApple OSS Distributions  *			int foo(SYSCTL_HANDLER_ARGS);
167*f6217f89SApple OSS Distributions  *		on some versions, forward reference to the tree is okay.
168*f6217f89SApple OSS Distributions  *		on some versions, you need SYSCTL_DECL().  you need things
169*f6217f89SApple OSS Distributions  *		like this.
170*f6217f89SApple OSS Distributions  *			#ifdef SYSCTL_DECL
171*f6217f89SApple OSS Distributions  *			SYSCTL_DECL(net_inet_ip6);
172*f6217f89SApple OSS Distributions  *			#endif
173*f6217f89SApple OSS Distributions  *		it is hard to share functions between freebsd and non-freebsd.
174*f6217f89SApple OSS Distributions  *
175*f6217f89SApple OSS Distributions  * - if_ioctl
176*f6217f89SApple OSS Distributions  *	NetBSD, FreeBSD 3, BSDI [34]
177*f6217f89SApple OSS Distributions  *		2nd argument is u_long cmd
178*f6217f89SApple OSS Distributions  *	FreeBSD 2
179*f6217f89SApple OSS Distributions  *		2nd argument is int cmd
180*f6217f89SApple OSS Distributions  *
181*f6217f89SApple OSS Distributions  * - if attach routines
182*f6217f89SApple OSS Distributions  *	NetBSD
183*f6217f89SApple OSS Distributions  *		void xxattach(int);
184*f6217f89SApple OSS Distributions  *	FreeBSD 2, FreeBSD 3
185*f6217f89SApple OSS Distributions  *		void xxattach(void *);
186*f6217f89SApple OSS Distributions  *		PSEUDO_SET(xxattach, if_xx);
187*f6217f89SApple OSS Distributions  *
188*f6217f89SApple OSS Distributions  * - ovbcopy()
189*f6217f89SApple OSS Distributions  *	in NetBSD 1.4 or later, ovbcopy() is not supplied in the kernel.
190*f6217f89SApple OSS Distributions  *	bcopy() is safe against overwrites.
191*f6217f89SApple OSS Distributions  *
192*f6217f89SApple OSS Distributions  * - splnet()
193*f6217f89SApple OSS Distributions  *	NetBSD 1.4 or later requires splsoftnet().
194*f6217f89SApple OSS Distributions  *	other operating systems use splnet().
195*f6217f89SApple OSS Distributions  *
196*f6217f89SApple OSS Distributions  * - struct ifnet for loopback interface
197*f6217f89SApple OSS Distributions  *	BSDI3: struct ifnet loif;
198*f6217f89SApple OSS Distributions  *	BSDI4: struct ifnet *loifp;
199*f6217f89SApple OSS Distributions  *	NetBSD, OpenBSD 2.8, FreeBSD2: struct ifnet loif[NLOOP];
200*f6217f89SApple OSS Distributions  *	OpenBSD 2.9: struct ifnet *lo0ifp;
201*f6217f89SApple OSS Distributions  *
202*f6217f89SApple OSS Distributions  *	odd thing is that many of them refers loif as ifnet *loif,
203*f6217f89SApple OSS Distributions  *	not loif[NLOOP], from outside of if_loop.c.
204*f6217f89SApple OSS Distributions  *
205*f6217f89SApple OSS Distributions  * - number of bpf pseudo devices
206*f6217f89SApple OSS Distributions  *	others: bpfilter.h, NBPFILTER
207*f6217f89SApple OSS Distributions  *	FreeBSD4: bpf.h, NBPF
208*f6217f89SApple OSS Distributions  *	solution:
209*f6217f89SApple OSS Distributions  *		#if defined(__FreeBSD__) && __FreeBSD__ >= 4
210*f6217f89SApple OSS Distributions  *		#include "bpf.h"
211*f6217f89SApple OSS Distributions  *		#define NBPFILTER	NBPF
212*f6217f89SApple OSS Distributions  *		#else
213*f6217f89SApple OSS Distributions  *		#include "bpfilter.h"
214*f6217f89SApple OSS Distributions  *		#endif
215*f6217f89SApple OSS Distributions  *
216*f6217f89SApple OSS Distributions  * - protosw for IPv4 (sys/netinet)
217*f6217f89SApple OSS Distributions  *	FreeBSD4: struct ipprotosw in netinet/ipprotosw.h
218*f6217f89SApple OSS Distributions  *	others: struct protosw in sys/protosw.h
219*f6217f89SApple OSS Distributions  *
220*f6217f89SApple OSS Distributions  * - protosw in general.
221*f6217f89SApple OSS Distributions  *	NetBSD 1.5 has extra member for ipfilter (netbsd-current dropped
222*f6217f89SApple OSS Distributions  *	it so it will go away in 1.6).
223*f6217f89SApple OSS Distributions  *	NetBSD 1.5 requires PR_LISTEN flag bit with protocols that permit
224*f6217f89SApple OSS Distributions  *	listen/accept (like tcp).
225*f6217f89SApple OSS Distributions  *
226*f6217f89SApple OSS Distributions  * - header files with defopt (opt_xx.h)
227*f6217f89SApple OSS Distributions  *	FreeBSD3: opt_{inet,ipsec,ip6fw,altq}.h
228*f6217f89SApple OSS Distributions  *	FreeBSD4: opt_{inet,inet6,ipsec,ip6fw,altq}.h
229*f6217f89SApple OSS Distributions  *	NetBSD: opt_{inet,ipsec,altq}.h
230*f6217f89SApple OSS Distributions  *	others: does not use defopt
231*f6217f89SApple OSS Distributions  *
232*f6217f89SApple OSS Distributions  * - (m->m_flags & M_EXT) != 0 does *not* mean that the max data length of
233*f6217f89SApple OSS Distributions  *   the mbuf == MCLBYTES.
234*f6217f89SApple OSS Distributions  *
235*f6217f89SApple OSS Distributions  * - sys/kern/uipc_mbuf.c:m_dup()
236*f6217f89SApple OSS Distributions  *	freebsd[34]: copies the whole mbuf chain.
237*f6217f89SApple OSS Distributions  *	netbsd: similar arg with m_copym().
238*f6217f89SApple OSS Distributions  *	others: no m_dup().
239*f6217f89SApple OSS Distributions  *
240*f6217f89SApple OSS Distributions  * - ifa_refcnt (struct ifaddr) management (IFAREF/IFAFREE).
241*f6217f89SApple OSS Distributions  *	NetBSD 1.5: always use IFAREF whenever reference gets added.
242*f6217f89SApple OSS Distributions  *		always use IFAFREE whenever reference gets freed.
243*f6217f89SApple OSS Distributions  *		IFAFREE frees ifaddr when ifa_refcnt reaches 0.
244*f6217f89SApple OSS Distributions  *	Darwin: always use ifa_addref whenever reference gets added.
245*f6217f89SApple OSS Distributions  *		always use ifa_remref whenever reference gets freed.
246*f6217f89SApple OSS Distributions  *		ifa_addref and ifa_remref are responsible for determining
247*f6217f89SApple OSS Distributions  *		when to free.
248*f6217f89SApple OSS Distributions  *	others: do not increase refcnt for ifp->if_addrlist and in_ifaddr.
249*f6217f89SApple OSS Distributions  *		use IFAFREE once when ifaddr is disconnected from
250*f6217f89SApple OSS Distributions  *		ifp->if_addrlist and in_ifaddr.  IFAFREE frees ifaddr when
251*f6217f89SApple OSS Distributions  *		ifa_refcnt goes negative.
252*f6217f89SApple OSS Distributions  */
253*f6217f89SApple OSS Distributions 
254*f6217f89SApple OSS Distributions #ifndef __NET_NET_OSDEP_H_DEFINED_
255*f6217f89SApple OSS Distributions #define __NET_NET_OSDEP_H_DEFINED_
256*f6217f89SApple OSS Distributions #include <sys/appleapiopts.h>
257*f6217f89SApple OSS Distributions #ifdef KERNEL_PRIVATE
258*f6217f89SApple OSS Distributions 
259*f6217f89SApple OSS Distributions struct ifnet;
260*f6217f89SApple OSS Distributions 
261*f6217f89SApple OSS Distributions #define HAVE_OLD_BPF
262*f6217f89SApple OSS Distributions 
263*f6217f89SApple OSS Distributions #define ifa_list        ifa_link
264*f6217f89SApple OSS Distributions #define if_addrlist     if_addrhead
265*f6217f89SApple OSS Distributions #define if_list         if_link
266*f6217f89SApple OSS Distributions 
267*f6217f89SApple OSS Distributions #define WITH_CONVERT_AND_STRIP_IP_LEN
268*f6217f89SApple OSS Distributions 
269*f6217f89SApple OSS Distributions #if 1                           /* at this moment, all OSes do this */
270*f6217f89SApple OSS Distributions #define WITH_CONVERT_IP_OFF
271*f6217f89SApple OSS Distributions #endif
272*f6217f89SApple OSS Distributions 
273*f6217f89SApple OSS Distributions #endif /* KERNEL_PRIVATE */
274*f6217f89SApple OSS Distributions #endif /*__NET_NET_OSDEP_H_DEFINED_ */
275