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