]>
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 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
24 * All rights reserved.
26 * Redistribution and use in source and binary forms, with or without
27 * modification, are permitted provided that the following conditions
29 * 1. Redistributions of source code must retain the above copyright
30 * notice, this list of conditions and the following disclaimer.
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in the
33 * documentation and/or other materials provided with the distribution.
34 * 3. Neither the name of the project nor the names of its contributors
35 * may be used to endorse or promote products derived from this software
36 * without specific prior written permission.
38 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
39 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
41 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
42 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
44 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
46 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
47 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * glue for kernel code programming differences.
57 * - whether the IPv4 input routine convert the byte order of some fileds
58 * of the IP header (x: convert to the host byte order, s: strip the header
59 * length for possible reassembly)
68 * bsdi[34], netbsd, and openbsd define it in sys/net/if.c
69 * freebsd (all versions) does not have it.
71 * - struct rt_addrinfo
72 * bsdi4, netbsd 1.5R and beyond: rti_addrs, rti_info[], rti_flags, rti_ifa,
73 * rti_ifp, and rti_rtm.
74 * others: rti_addrs and rti_info[] only.
76 * - ifa->ifa_rtrequest
77 * bsdi4, netbsd 1.5R and beyond: rt_addrinfo *
78 * others: sockaddr * (note that sys/net/route.c:rtrequest() has an unsafe
79 * typecast code, from 4.3BSD-reno)
81 * - side effects of rtrequest{,1}(RTM_DELETE)
82 * BSDI[34]: delete all cloned routes underneath the route.
83 * FreeBSD[234]: delete all protocol-cloned routes underneath the route.
84 * note that cloned routes from an interface direct route
86 * NetBSD: 1.5 have no side effects. KAME/netbsd15, and post-1.5R, have
87 * the same effects as of BSDI.
88 * OpenBSD: have no side effects. KAME/openbsd has the same effects as
89 * of BSDI (the change is not merged - yet).
91 * - privileged process
94 * if (p && !suser(p->p_ucred, &p->p_acflag))
100 * OpenBSD, BSDI [34], FreeBSD 2
102 * if (so->so_state & SS_PRIV)
106 * needs to give struct proc * as argument
107 * OpenBSD, BSDI [34], FreeBSD 2
108 * do not need struct proc *
111 * OpenBSD, NetBSD 1.5, BSDI [34]
112 * need caddr_t * (= if_bpf **) and struct ifnet *
113 * FreeBSD 2, FreeBSD 3, NetBSD post-1.5N
114 * need only struct ifnet * as argument
117 * use queue.h? member names if name
119 * FreeBSD 2 no old standard if_name+unit
120 * FreeBSD 3 yes strange if_name+unit
121 * OpenBSD yes standard if_xname
122 * NetBSD yes standard if_xname
123 * BSDI [34] no old standard if_name+unit
126 * NetBSD, OpenBSD, BSDI [34], FreeBSD 2
127 * single function with PRU_xx, arguments are mbuf
129 * separates functions, non-mbuf arguments
132 * NetBSD, OpenBSD, BSDI [34], FreeBSD 2
133 * manipulation based on mbuf
135 * non-mbuf manipulation using sooptcopy{in,out}()
137 * - timeout() and untimeout()
138 * NetBSD 1.4.x, OpenBSD, BSDI [34], FreeBSD 2
139 * timeout() is a void function
141 * timeout() is non-void, must keep returned value for untimeout()
142 * callout_xx is also available (sys/callout.h)
144 * timeout() is obsoleted, use callout_xx (sys/callout.h)
146 * timeout_{add,set,del} is encouraged (sys/timeout.h)
152 * foo_sysctl() but with different style. sysctl_int_arr() takes
153 * care of most of the cases.
155 * linker hack. however, there are freebsd version differences
157 * on FreeBSD[23] function arg #define includes paren.
158 * int foo SYSCTL_HANDLER_ARGS;
159 * on FreeBSD4, function arg #define does not include paren.
160 * int foo(SYSCTL_HANDLER_ARGS);
161 * on some versions, forward reference to the tree is okay.
162 * on some versions, you need SYSCTL_DECL(). you need things
165 * SYSCTL_DECL(net_inet_ip6);
167 * it is hard to share functions between freebsd and non-freebsd.
170 * NetBSD, FreeBSD 3, BSDI [34]
171 * 2nd argument is u_long cmd
173 * 2nd argument is int cmd
175 * - if attach routines
177 * void xxattach(int);
178 * FreeBSD 2, FreeBSD 3
179 * void xxattach(void *);
180 * PSEUDO_SET(xxattach, if_xx);
183 * in NetBSD 1.4 or later, ovbcopy() is not supplied in the kernel.
184 * bcopy() is safe against overwrites.
187 * NetBSD 1.4 or later requires splsoftnet().
188 * other operating systems use splnet().
193 * - struct ifnet for loopback interface
194 * BSDI3: struct ifnet loif;
195 * BSDI4: struct ifnet *loifp;
196 * NetBSD, OpenBSD 2.8, FreeBSD2: struct ifnet loif[NLOOP];
197 * OpenBSD 2.9: struct ifnet *lo0ifp;
199 * odd thing is that many of them refers loif as ifnet *loif,
200 * not loif[NLOOP], from outside of if_loop.c.
202 * - number of bpf pseudo devices
203 * others: bpfilter.h, NBPFILTER
204 * FreeBSD4: bpf.h, NBPF
206 * #if defined(__FreeBSD__) && __FreeBSD__ >= 4
208 * #define NBPFILTER NBPF
210 * #include "bpfilter.h"
213 * - protosw for IPv4 (sys/netinet)
214 * FreeBSD4: struct ipprotosw in netinet/ipprotosw.h
215 * others: struct protosw in sys/protosw.h
217 * - protosw in general.
218 * NetBSD 1.5 has extra member for ipfilter (netbsd-current dropped
219 * it so it will go away in 1.6).
220 * NetBSD 1.5 requires PR_LISTEN flag bit with protocols that permit
221 * listen/accept (like tcp).
223 * - header files with defopt (opt_xx.h)
224 * FreeBSD3: opt_{inet,ipsec,ip6fw,altq}.h
225 * FreeBSD4: opt_{inet,inet6,ipsec,ip6fw,altq}.h
226 * NetBSD: opt_{inet,ipsec,altq}.h
227 * others: does not use defopt
229 * - (m->m_flags & M_EXT) != 0 does *not* mean that the max data length of
230 * the mbuf == MCLBYTES.
232 * - sys/kern/uipc_mbuf.c:m_dup()
233 * freebsd[34]: copies the whole mbuf chain.
234 * netbsd: similar arg with m_copym().
235 * others: no m_dup().
237 * - ifa_refcnt (struct ifaddr) management (IFAREF/IFAFREE).
238 * NetBSD 1.5: always use IFAREF whenever reference gets added.
239 * always use IFAFREE whenever reference gets freed.
240 * IFAFREE frees ifaddr when ifa_refcnt reaches 0.
241 * Darwin: always use ifaref whenever reference gets added.
242 * always use ifafree whenever reference gets freed.
243 * ifaref and ifafree are responsible for determining when to free.
244 * others: do not increase refcnt for ifp->if_addrlist and in_ifaddr.
245 * use IFAFREE once when ifaddr is disconnected from
246 * ifp->if_addrlist and in_ifaddr. IFAFREE frees ifaddr when
247 * ifa_refcnt goes negative.
250 #ifndef __NET_NET_OSDEP_H_DEFINED_
251 #define __NET_NET_OSDEP_H_DEFINED_
252 #include <sys/appleapiopts.h>
253 #ifdef KERNEL_PRIVATE
256 extern const char *if_name(struct ifnet
*);
260 #define ifa_list ifa_link
261 #define if_addrlist if_addrhead
262 #define if_list if_link
266 #define IFAREF(ifa) do { ++(ifa)->ifa_refcnt; } while (0)
269 #define WITH_CONVERT_AND_STRIP_IP_LEN
271 #if 1 /* at this moment, all OSes do this */
272 #define WITH_CONVERT_IP_OFF
275 #endif /* KERNEL_PRIVATE */
276 #endif /*__NET_NET_OSDEP_H_DEFINED_ */