]>
git.saurik.com Git - apple/xnu.git/blob - bsd/net/net_osdep.h
e99df6f5480953efb585b76d3df653900db0cd31
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
32 * All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
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.
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
59 * glue for kernel code programming differences.
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)
76 * bsdi[34], netbsd, and openbsd define it in sys/net/if.c
77 * freebsd (all versions) does not have it.
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.
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)
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
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).
99 * - privileged process
102 * if (p && !suser(p->p_ucred, &p->p_acflag))
106 * if (p && !suser(p))
108 * OpenBSD, BSDI [34], FreeBSD 2
110 * if (so->so_state & SS_PRIV)
114 * needs to give struct proc * as argument
115 * OpenBSD, BSDI [34], FreeBSD 2
116 * do not need struct proc *
119 * OpenBSD, NetBSD 1.5, BSDI [34]
120 * need caddr_t * (= if_bpf **) and struct ifnet *
121 * FreeBSD 2, FreeBSD 3, NetBSD post-1.5N
122 * need only struct ifnet * as argument
125 * use queue.h? member names if name
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
134 * NetBSD, OpenBSD, BSDI [34], FreeBSD 2
135 * single function with PRU_xx, arguments are mbuf
137 * separates functions, non-mbuf arguments
140 * NetBSD, OpenBSD, BSDI [34], FreeBSD 2
141 * manipulation based on mbuf
143 * non-mbuf manipulation using sooptcopy{in,out}()
145 * - timeout() and untimeout()
146 * NetBSD 1.4.x, OpenBSD, BSDI [34], FreeBSD 2
147 * timeout() is a void function
149 * timeout() is non-void, must keep returned value for untimeout()
150 * callout_xx is also available (sys/callout.h)
152 * timeout() is obsoleted, use callout_xx (sys/callout.h)
154 * timeout_{add,set,del} is encouraged (sys/timeout.h)
160 * foo_sysctl() but with different style. sysctl_int_arr() takes
161 * care of most of the cases.
163 * linker hack. however, there are freebsd version differences
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
173 * SYSCTL_DECL(net_inet_ip6);
175 * it is hard to share functions between freebsd and non-freebsd.
178 * NetBSD, FreeBSD 3, BSDI [34]
179 * 2nd argument is u_long cmd
181 * 2nd argument is int cmd
183 * - if attach routines
185 * void xxattach(int);
186 * FreeBSD 2, FreeBSD 3
187 * void xxattach(void *);
188 * PSEUDO_SET(xxattach, if_xx);
191 * in NetBSD 1.4 or later, ovbcopy() is not supplied in the kernel.
192 * bcopy() is safe against overwrites.
195 * NetBSD 1.4 or later requires splsoftnet().
196 * other operating systems use splnet().
201 * - struct ifnet for loopback interface
202 * BSDI3: struct ifnet loif;
203 * BSDI4: struct ifnet *loifp;
204 * NetBSD, OpenBSD 2.8, FreeBSD2: struct ifnet loif[NLOOP];
205 * OpenBSD 2.9: struct ifnet *lo0ifp;
207 * odd thing is that many of them refers loif as ifnet *loif,
208 * not loif[NLOOP], from outside of if_loop.c.
210 * - number of bpf pseudo devices
211 * others: bpfilter.h, NBPFILTER
212 * FreeBSD4: bpf.h, NBPF
214 * #if defined(__FreeBSD__) && __FreeBSD__ >= 4
216 * #define NBPFILTER NBPF
218 * #include "bpfilter.h"
221 * - protosw for IPv4 (sys/netinet)
222 * FreeBSD4: struct ipprotosw in netinet/ipprotosw.h
223 * others: struct protosw in sys/protosw.h
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).
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
237 * - (m->m_flags & M_EXT) != 0 does *not* mean that the max data length of
238 * the mbuf == MCLBYTES.
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().
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.
258 #ifndef __NET_NET_OSDEP_H_DEFINED_
259 #define __NET_NET_OSDEP_H_DEFINED_
260 #include <sys/appleapiopts.h>
261 #ifdef KERNEL_PRIVATE
264 extern const char *if_name(struct ifnet
*);
268 #define ifa_list ifa_link
269 #define if_addrlist if_addrhead
270 #define if_list if_link
274 #define IFAREF(ifa) do { ++(ifa)->ifa_refcnt; } while (0)
277 #define WITH_CONVERT_AND_STRIP_IP_LEN
279 #if 1 /* at this moment, all OSes do this */
280 #define WITH_CONVERT_IP_OFF
283 #endif /* KERNEL_PRIVATE */
284 #endif /*__NET_NET_OSDEP_H_DEFINED_ */