]>
git.saurik.com Git - apple/xnu.git/blob - bsd/net/net_osdep.h
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
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. Neither the name of the project nor the names of its contributors
36 * may be used to endorse or promote products derived from this software
37 * without specific prior written permission.
39 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
40 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
43 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
44 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
45 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
48 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52 * glue for kernel code programming differences.
58 * - whether the IPv4 input routine convert the byte order of some fileds
59 * of the IP header (x: convert to the host byte order, s: strip the header
60 * length for possible reassembly)
69 * bsdi[34], netbsd, and openbsd define it in sys/net/if.c
70 * freebsd (all versions) does not have it.
72 * - struct rt_addrinfo
73 * bsdi4, netbsd 1.5R and beyond: rti_addrs, rti_info[], rti_flags, rti_ifa,
74 * rti_ifp, and rti_rtm.
75 * others: rti_addrs and rti_info[] only.
77 * - ifa->ifa_rtrequest
78 * bsdi4, netbsd 1.5R and beyond: rt_addrinfo *
79 * others: sockaddr * (note that sys/net/route.c:rtrequest() has an unsafe
80 * typecast code, from 4.3BSD-reno)
82 * - side effects of rtrequest{,1}(RTM_DELETE)
83 * BSDI[34]: delete all cloned routes underneath the route.
84 * FreeBSD[234]: delete all protocol-cloned routes underneath the route.
85 * note that cloned routes from an interface direct route
87 * NetBSD: 1.5 have no side effects. KAME/netbsd15, and post-1.5R, have
88 * the same effects as of BSDI.
89 * OpenBSD: have no side effects. KAME/openbsd has the same effects as
90 * of BSDI (the change is not merged - yet).
92 * - privileged process
95 * if (p && !suser(p->p_ucred, &p->p_acflag))
101 * OpenBSD, BSDI [34], FreeBSD 2
103 * if (so->so_state & SS_PRIV)
107 * needs to give struct proc * as argument
108 * OpenBSD, BSDI [34], FreeBSD 2
109 * do not need struct proc *
112 * OpenBSD, NetBSD 1.5, BSDI [34]
113 * need caddr_t * (= if_bpf **) and struct ifnet *
114 * FreeBSD 2, FreeBSD 3, NetBSD post-1.5N
115 * need only struct ifnet * as argument
118 * use queue.h? member names if name
120 * FreeBSD 2 no old standard if_name+unit
121 * FreeBSD 3 yes strange if_name+unit
122 * OpenBSD yes standard if_xname
123 * NetBSD yes standard if_xname
124 * BSDI [34] no old standard if_name+unit
127 * NetBSD, OpenBSD, BSDI [34], FreeBSD 2
128 * single function with PRU_xx, arguments are mbuf
130 * separates functions, non-mbuf arguments
133 * NetBSD, OpenBSD, BSDI [34], FreeBSD 2
134 * manipulation based on mbuf
136 * non-mbuf manipulation using sooptcopy{in,out}()
138 * - timeout() and untimeout()
139 * NetBSD 1.4.x, OpenBSD, BSDI [34], FreeBSD 2
140 * timeout() is a void function
142 * timeout() is non-void, must keep returned value for untimeout()
143 * callout_xx is also available (sys/callout.h)
145 * timeout() is obsoleted, use callout_xx (sys/callout.h)
147 * timeout_{add,set,del} is encouraged (sys/timeout.h)
153 * foo_sysctl() but with different style. sysctl_int_arr() takes
154 * care of most of the cases.
156 * linker hack. however, there are freebsd version differences
158 * on FreeBSD[23] function arg #define includes paren.
159 * int foo SYSCTL_HANDLER_ARGS;
160 * on FreeBSD4, function arg #define does not include paren.
161 * int foo(SYSCTL_HANDLER_ARGS);
162 * on some versions, forward reference to the tree is okay.
163 * on some versions, you need SYSCTL_DECL(). you need things
166 * SYSCTL_DECL(net_inet_ip6);
168 * it is hard to share functions between freebsd and non-freebsd.
171 * NetBSD, FreeBSD 3, BSDI [34]
172 * 2nd argument is u_long cmd
174 * 2nd argument is int cmd
176 * - if attach routines
178 * void xxattach(int);
179 * FreeBSD 2, FreeBSD 3
180 * void xxattach(void *);
181 * PSEUDO_SET(xxattach, if_xx);
184 * in NetBSD 1.4 or later, ovbcopy() is not supplied in the kernel.
185 * bcopy() is safe against overwrites.
188 * NetBSD 1.4 or later requires splsoftnet().
189 * other operating systems use splnet().
194 * - struct ifnet for loopback interface
195 * BSDI3: struct ifnet loif;
196 * BSDI4: struct ifnet *loifp;
197 * NetBSD, OpenBSD 2.8, FreeBSD2: struct ifnet loif[NLOOP];
198 * OpenBSD 2.9: struct ifnet *lo0ifp;
200 * odd thing is that many of them refers loif as ifnet *loif,
201 * not loif[NLOOP], from outside of if_loop.c.
203 * - number of bpf pseudo devices
204 * others: bpfilter.h, NBPFILTER
205 * FreeBSD4: bpf.h, NBPF
207 * #if defined(__FreeBSD__) && __FreeBSD__ >= 4
209 * #define NBPFILTER NBPF
211 * #include "bpfilter.h"
214 * - protosw for IPv4 (sys/netinet)
215 * FreeBSD4: struct ipprotosw in netinet/ipprotosw.h
216 * others: struct protosw in sys/protosw.h
218 * - protosw in general.
219 * NetBSD 1.5 has extra member for ipfilter (netbsd-current dropped
220 * it so it will go away in 1.6).
221 * NetBSD 1.5 requires PR_LISTEN flag bit with protocols that permit
222 * listen/accept (like tcp).
224 * - header files with defopt (opt_xx.h)
225 * FreeBSD3: opt_{inet,ipsec,ip6fw,altq}.h
226 * FreeBSD4: opt_{inet,inet6,ipsec,ip6fw,altq}.h
227 * NetBSD: opt_{inet,ipsec,altq}.h
228 * others: does not use defopt
230 * - (m->m_flags & M_EXT) != 0 does *not* mean that the max data length of
231 * the mbuf == MCLBYTES.
233 * - sys/kern/uipc_mbuf.c:m_dup()
234 * freebsd[34]: copies the whole mbuf chain.
235 * netbsd: similar arg with m_copym().
236 * others: no m_dup().
238 * - ifa_refcnt (struct ifaddr) management (IFAREF/IFAFREE).
239 * NetBSD 1.5: always use IFAREF whenever reference gets added.
240 * always use IFAFREE whenever reference gets freed.
241 * IFAFREE frees ifaddr when ifa_refcnt reaches 0.
242 * Darwin: always use ifaref whenever reference gets added.
243 * always use ifafree whenever reference gets freed.
244 * ifaref and ifafree are responsible for determining when to free.
245 * others: do not increase refcnt for ifp->if_addrlist and in_ifaddr.
246 * use IFAFREE once when ifaddr is disconnected from
247 * ifp->if_addrlist and in_ifaddr. IFAFREE frees ifaddr when
248 * ifa_refcnt goes negative.
251 #ifndef __NET_NET_OSDEP_H_DEFINED_
252 #define __NET_NET_OSDEP_H_DEFINED_
253 #include <sys/appleapiopts.h>
254 #ifdef KERNEL_PRIVATE
257 extern const char *if_name(struct ifnet
*);
261 #define ifa_list ifa_link
262 #define if_addrlist if_addrhead
263 #define if_list if_link
267 #define IFAREF(ifa) do { ++(ifa)->ifa_refcnt; } while (0)
270 #define WITH_CONVERT_AND_STRIP_IP_LEN
272 #if 1 /* at this moment, all OSes do this */
273 #define WITH_CONVERT_IP_OFF
276 #endif /* KERNEL_PRIVATE */
277 #endif /*__NET_NET_OSDEP_H_DEFINED_ */