]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/net_osdep.h
xnu-792.6.56.tar.gz
[apple/xnu.git] / bsd / net / net_osdep.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
25 * All rights reserved.
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
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.
38 *
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
49 * SUCH DAMAGE.
50 */
51 /*
52 * glue for kernel code programming differences.
53 */
54
55 /*
56 * OS dependencies:
57 *
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)
61 * ip_len ip_id ip_off
62 * bsdi3: xs x x
63 * bsdi4: xs x
64 * FreeBSD: xs x
65 * NetBSD: x x
66 * OpenBSD: xs x x
67 *
68 * - ifa_ifwithaf()
69 * bsdi[34], netbsd, and openbsd define it in sys/net/if.c
70 * freebsd (all versions) does not have it.
71 *
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.
76 *
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)
81 *
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
86 * still remain.
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).
91 *
92 * - privileged process
93 * NetBSD, FreeBSD 3
94 * struct proc *p;
95 * if (p && !suser(p->p_ucred, &p->p_acflag))
96 * privileged;
97 * FreeBSD 4
98 * struct proc *p;
99 * if (p && !suser(p))
100 * privileged;
101 * OpenBSD, BSDI [34], FreeBSD 2
102 * struct socket *so;
103 * if (so->so_state & SS_PRIV)
104 * privileged;
105 * - foo_control
106 * NetBSD, FreeBSD 3
107 * needs to give struct proc * as argument
108 * OpenBSD, BSDI [34], FreeBSD 2
109 * do not need struct proc *
110 *
111 * - bpf:
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
116 *
117 * - struct ifnet
118 * use queue.h? member names if name
119 * --- --- ---
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
125 *
126 * - usrreq
127 * NetBSD, OpenBSD, BSDI [34], FreeBSD 2
128 * single function with PRU_xx, arguments are mbuf
129 * FreeBSD 3
130 * separates functions, non-mbuf arguments
131 *
132 * - {set,get}sockopt
133 * NetBSD, OpenBSD, BSDI [34], FreeBSD 2
134 * manipulation based on mbuf
135 * FreeBSD 3
136 * non-mbuf manipulation using sooptcopy{in,out}()
137 *
138 * - timeout() and untimeout()
139 * NetBSD 1.4.x, OpenBSD, BSDI [34], FreeBSD 2
140 * timeout() is a void function
141 * FreeBSD 3
142 * timeout() is non-void, must keep returned value for untimeout()
143 * callout_xx is also available (sys/callout.h)
144 * NetBSD 1.5
145 * timeout() is obsoleted, use callout_xx (sys/callout.h)
146 * OpenBSD 2.8
147 * timeout_{add,set,del} is encouraged (sys/timeout.h)
148 *
149 * - sysctl
150 * NetBSD, OpenBSD
151 * foo_sysctl()
152 * BSDI [34]
153 * foo_sysctl() but with different style. sysctl_int_arr() takes
154 * care of most of the cases.
155 * FreeBSD
156 * linker hack. however, there are freebsd version differences
157 * (how wonderful!).
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
164 * like this.
165 * #ifdef SYSCTL_DECL
166 * SYSCTL_DECL(net_inet_ip6);
167 * #endif
168 * it is hard to share functions between freebsd and non-freebsd.
169 *
170 * - if_ioctl
171 * NetBSD, FreeBSD 3, BSDI [34]
172 * 2nd argument is u_long cmd
173 * FreeBSD 2
174 * 2nd argument is int cmd
175 *
176 * - if attach routines
177 * NetBSD
178 * void xxattach(int);
179 * FreeBSD 2, FreeBSD 3
180 * void xxattach(void *);
181 * PSEUDO_SET(xxattach, if_xx);
182 *
183 * - ovbcopy()
184 * in NetBSD 1.4 or later, ovbcopy() is not supplied in the kernel.
185 * bcopy() is safe against overwrites.
186 *
187 * - splnet()
188 * NetBSD 1.4 or later requires splsoftnet().
189 * other operating systems use splnet().
190 *
191 * - dtom()
192 * NEVER USE IT!
193 *
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;
199 *
200 * odd thing is that many of them refers loif as ifnet *loif,
201 * not loif[NLOOP], from outside of if_loop.c.
202 *
203 * - number of bpf pseudo devices
204 * others: bpfilter.h, NBPFILTER
205 * FreeBSD4: bpf.h, NBPF
206 * solution:
207 * #if defined(__FreeBSD__) && __FreeBSD__ >= 4
208 * #include "bpf.h"
209 * #define NBPFILTER NBPF
210 * #else
211 * #include "bpfilter.h"
212 * #endif
213 *
214 * - protosw for IPv4 (sys/netinet)
215 * FreeBSD4: struct ipprotosw in netinet/ipprotosw.h
216 * others: struct protosw in sys/protosw.h
217 *
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).
223 *
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
229 *
230 * - (m->m_flags & M_EXT) != 0 does *not* mean that the max data length of
231 * the mbuf == MCLBYTES.
232 *
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().
237 *
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.
249 */
250
251 #ifndef __NET_NET_OSDEP_H_DEFINED_
252 #define __NET_NET_OSDEP_H_DEFINED_
253 #include <sys/appleapiopts.h>
254 #ifdef KERNEL_PRIVATE
255
256 struct ifnet;
257 extern const char *if_name(struct ifnet *);
258
259 #define HAVE_OLD_BPF
260
261 #define ifa_list ifa_link
262 #define if_addrlist if_addrhead
263 #define if_list if_link
264
265 /* sys/net/if.h */
266 #ifndef __APPLE__
267 #define IFAREF(ifa) do { ++(ifa)->ifa_refcnt; } while (0)
268 #endif
269
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
274 #endif
275
276 #endif /* KERNEL_PRIVATE */
277 #endif /*__NET_NET_OSDEP_H_DEFINED_ */