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