FreeBSD/Linux Kernel Cross Reference
sys/net/net_osdep.h
1 /* $FreeBSD: releng/6.3/sys/net/net_osdep.h 173886 2007-11-24 19:45:58Z cvs2svn $ */
2 /* $KAME: net_osdep.h,v 1.80 2003/08/09 17:06:39 suz Exp $ */
3
4 /*-
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32 /*
33 * glue for kernel code programming differences.
34 */
35
36 /*
37 * OS dependencies:
38 * - ioctl
39 * FreeBSD 3 and later warn when sys/ioctl.h is included in a kernel source
40 * file. For socket ioctl, we are suggested to use sys/sockio.h.
41 *
42 * - RTFREE()
43 * bsdi does not escape this macro using do-clause, so it is recommended
44 * to escape the macro explicitly.
45 * e.g.
46 * if (rt) {
47 * RTFREE(rt);
48 * }
49 *
50 * - whether the IPv4 input routine convert the byte order of some fileds
51 * of the IP header (x: convert to the host byte order, s: strip the header
52 * length for possible reassembly)
53 * ip_len ip_id ip_off
54 * bsdi3: xs x x
55 * bsdi4: xs x
56 * freebsd[23]: xs x x
57 * freebsd4: xs x
58 * NetBSD: x x
59 * OpenBSD: xs x x
60 *
61 * - ifa_ifwithaf()
62 * bsdi[34], netbsd, and openbsd define it in sys/net/if.c
63 * freebsd (all versions) does not have it.
64 *
65 * - struct rt_addrinfo
66 * bsdi4, netbsd 1.5R and beyond: rti_addrs, rti_info[], rti_flags, rti_ifa,
67 * rti_ifp, and rti_rtm.
68 * others: rti_addrs and rti_info[] only.
69 *
70 * - ifa->ifa_rtrequest
71 * bsdi4, netbsd 1.5R and beyond: rt_addrinfo *
72 * others: sockaddr * (note that sys/net/route.c:rtrequest() has an unsafe
73 * typecast code, from 4.3BSD-reno)
74 *
75 * - side effects of rtrequest{,1}(RTM_DELETE)
76 * BSDI[34]: delete all cloned routes underneath the route.
77 * FreeBSD[234]: delete all protocol-cloned routes underneath the route.
78 * note that cloned routes from an interface direct route
79 * still remain.
80 * NetBSD: 1.5 have no side effects. KAME/netbsd15, and post-1.5R, have
81 * the same effects as of BSDI.
82 * OpenBSD: have no side effects. KAME/openbsd has the same effects as
83 * of BSDI (the change is not merged - yet).
84 *
85 * - privileged process
86 * NetBSD, FreeBSD 3
87 * struct proc *p;
88 * if (p && !suser(p->p_ucred, &p->p_acflag))
89 * privileged;
90 * FreeBSD 4
91 * struct proc *p;
92 * if (p && !suser(p))
93 * privileged;
94 * FreeBSD 5
95 * struct thread *td;
96 * if (suser(td))
97 * privileged;
98 * OpenBSD, BSDI [34], FreeBSD 2
99 * struct socket *so;
100 * if (so->so_state & SS_PRIV)
101 * privileged;
102 * - foo_control
103 * NetBSD, FreeBSD 3
104 * needs to give struct proc * as argument
105 * OpenBSD, BSDI [34], FreeBSD 2
106 * do not need struct proc *
107 *
108 * - bpf:
109 * OpenBSD, NetBSD 1.5, BSDI [34]
110 * need caddr_t * (= if_bpf **) and struct ifnet *
111 * FreeBSD 2, FreeBSD 3, NetBSD post-1.5N
112 * need only struct ifnet * as argument
113 *
114 * - bpfattach:
115 * OpenBSD, NetBSD 1.5, BSDI [34]
116 * bpfattach(caddr_t *, struct ifnet *, u_int, u_int)
117 * FreeBSD, NetBSD 1.6:
118 * bpfattach(struct ifnet *, u_int, u_int)
119 *
120 * - bpf_mtap:
121 * OpenBSD, NetBSD, BSDI [34]
122 * bpf_mtap(caddr_t, struct mbuf *)
123 * FreeBSD
124 * bpf_mtap(struct ifnet *, struct mbuf *)
125 *
126 * - struct ifnet
127 * use queue.h? member names if name
128 * --- --- ---
129 * FreeBSD 2 no old standard if_name+unit
130 * FreeBSD 3 yes strange if_name+unit
131 * FreeBSD 4 yes strange if_name+unit
132 * FreeBSD 5 yes standard if_xname
133 * OpenBSD yes standard if_xname
134 * NetBSD yes standard if_xname
135 * BSDI [34] no old standard if_name+unit
136 *
137 * - usrreq
138 * NetBSD, OpenBSD, BSDI [34], FreeBSD 2
139 * single function with PRU_xx, arguments are mbuf
140 * FreeBSD 3
141 * separates functions, non-mbuf arguments
142 *
143 * - {set,get}sockopt
144 * NetBSD, OpenBSD, BSDI [34], FreeBSD 2
145 * manipulation based on mbuf
146 * FreeBSD 3
147 * non-mbuf manipulation using sooptcopy{in,out}()
148 *
149 * - timeout() and untimeout()
150 * NetBSD 1.4.x, OpenBSD, BSDI [34], FreeBSD 2
151 * timeout() is a void function
152 * FreeBSD 3
153 * timeout() is non-void, must keep returned value for untimeout()
154 * callout_xx is also available (sys/callout.h)
155 * NetBSD 1.5
156 * timeout() is obsoleted, use callout_xx (sys/callout.h)
157 * OpenBSD 2.8
158 * timeout_{add,set,del} is encouraged (sys/timeout.h)
159 *
160 * - kernel internal time structure
161 * FreeBSD 2, NetBSD, OpenBSD, BSD/OS
162 * mono_time.tv_u?sec, time.tv_u?sec
163 * FreeBSD [34]
164 * time_second
165 * if you need portability, #ifdef out FreeBSD[34], or use microtime(&tv)
166 * then touch tv.tv_sec (note: microtime is an expensive operation, so
167 * the use of mono_time is preferred).
168 *
169 * - sysctl
170 * NetBSD, OpenBSD
171 * foo_sysctl()
172 * BSDI [34]
173 * foo_sysctl() but with different style. sysctl_int_arr() takes
174 * care of most of the cases.
175 * FreeBSD
176 * linker hack. however, there are freebsd version differences
177 * (how wonderful!).
178 * on FreeBSD[23] function arg #define includes paren.
179 * int foo SYSCTL_HANDLER_ARGS;
180 * on FreeBSD4, function arg #define does not include paren.
181 * int foo(SYSCTL_HANDLER_ARGS);
182 * on some versions, forward reference to the tree is okay.
183 * on some versions, you need SYSCTL_DECL(). you need things
184 * like this.
185 * #ifdef SYSCTL_DECL
186 * SYSCTL_DECL(net_inet_ip6);
187 * #endif
188 * it is hard to share functions between freebsd and non-freebsd.
189 *
190 * - if_ioctl
191 * NetBSD, FreeBSD 3, BSDI [34]
192 * 2nd argument is u_long cmd
193 * FreeBSD 2
194 * 2nd argument is int cmd
195 *
196 * - if attach routines
197 * NetBSD
198 * void xxattach(int);
199 * FreeBSD 2, FreeBSD 3
200 * void xxattach(void *);
201 * PSEUDO_SET(xxattach, if_xx);
202 *
203 * - ovbcopy()
204 * in NetBSD 1.4 or later, ovbcopy() is not supplied in the kernel.
205 * we have updated sys/systm.h to include declaration.
206 *
207 * - splnet()
208 * NetBSD 1.4 or later, and OpenBSD, requires splsoftnet().
209 * other operating systems use splnet().
210 *
211 * - splimp()
212 * NetBSD 1.6: use splnet() in network, splvm() in vm.
213 * other operating systems: use splimp().
214 *
215 * - dtom()
216 * NEVER USE IT!
217 *
218 * - struct ifnet for loopback interface
219 * BSDI3: struct ifnet loif;
220 * BSDI4: struct ifnet *loifp;
221 * NetBSD, OpenBSD 2.8, FreeBSD2: struct ifnet loif[NLOOP];
222 * OpenBSD 2.9: struct ifnet *lo0ifp;
223 *
224 * odd thing is that many of them refers loif as ifnet *loif,
225 * not loif[NLOOP], from outside of if_loop.c.
226 *
227 * - number of bpf pseudo devices
228 * others: bpfilter.h, NBPFILTER
229 * FreeBSD4: bpf.h, NBPF
230 * solution:
231 * #if defined(__FreeBSD__) && __FreeBSD__ >= 4
232 * #include "bpf.h"
233 * #define NBPFILTER NBPF
234 * #else
235 * #include "bpfilter.h"
236 * #endif
237 *
238 * - protosw for IPv4 (sys/netinet)
239 * FreeBSD4: struct ipprotosw in netinet/ipprotosw.h
240 * others: struct protosw in sys/protosw.h
241 *
242 * - protosw in general.
243 * NetBSD 1.5 has extra member for ipfilter (netbsd-current dropped
244 * it so it went away in 1.6).
245 * NetBSD 1.5 requires PR_LISTEN flag bit with protocols that permit
246 * listen/accept (like tcp).
247 *
248 * - header files with defopt (opt_xx.h)
249 * FreeBSD3: opt_{inet,ipsec,ip6fw,altq}.h
250 * FreeBSD4: opt_{inet,inet6,ipsec,ip6fw,altq}.h
251 * NetBSD: opt_{inet,ipsec,altq}.h
252 * others: does not use defopt
253 *
254 * - IN_MULTICAST/IN_CLASS[A-D] macro.
255 * OpenBSD and NetBSD: net endian (kernel) or host endian (userland)
256 * others: always host endian
257 *
258 * - (m->m_flags & M_EXT) != 0 does *not* mean that the max data length of
259 * the mbuf == MCLBYTES.
260 *
261 * - sys/kern/uipc_mbuf.c:m_dup()
262 * freebsd[34]: copies the whole mbuf chain.
263 * netbsd: similar arg with m_copym().
264 * others: no m_dup().
265 *
266 * - ifa_refcnt (struct ifaddr) management (IFAREF/IFAFREE).
267 * NetBSD 1.5: always use IFAREF whenever reference gets added.
268 * always use IFAFREE whenever reference gets freed.
269 * IFAFREE frees ifaddr when ifa_refcnt reaches 0.
270 * others: do not increase refcnt for ifp->if_addrlist and in_ifaddr.
271 * use IFAFREE once when ifaddr is disconnected from
272 * ifp->if_addrlist and in_ifaddr. IFAFREE frees ifaddr when
273 * ifa_refcnt goes negative. in KAME environment, IFAREF is
274 * provided as a compatibility wrapper (use it instead of
275 * ifa_refcnt++ to reduce #ifdef).
276 *
277 * - ifnet.if_lastchange
278 * freebsd, bsdi, netbsd-current (jun 14 2001-),
279 * openbsd-current (jun 15 2001-): updated only when IFF_UP changes.
280 * (RFC1573 ifLastChange interpretation)
281 * netbsd151, openbsd29: updated whenever packets go through the interface.
282 * (4.4BSD interpretation)
283 *
284 * - kernel compilation options ("options HOGE" in kernel config file)
285 * freebsd4: sys/conf/options has to have mapping between option
286 * and a header file (opt_hoge.h).
287 * netbsd: by default, -DHOGE will go into
288 * sys/arch/foo/compile/BAR/Makefile.
289 * if you define mapping in sys/conf/files, you can create
290 * a header file like opt_hoge.h to help make dependencies.
291 * bsdi/openbsd: always use -DHOGE in Makefile. there's no need/way
292 * to have opt_hoge.h.
293 *
294 * therefore, opt_hoge.h is mandatory on freebsd4 only.
295 *
296 * - MALLOC() macro
297 * Use it only if the size of the allocation is constant.
298 * When we do NOT collect statistics about kernel memory usage, the result
299 * of macro expansion contains a large set of condition branches. If the
300 * size is not constant, compilation optimization cannot be applied, and
301 * a bunch of the large branch will be embedded in the kernel code.
302 *
303 * - M_COPY_PKTHDR
304 * openbsd30, freebsd4(after 4.8): M_COPY_PKTHDR is deprecated.
305 * use M_MOVE_PKTHDR or M_DUP_PKTHDR, depending on how you want
306 * to handle m_tag.
307 * others: M_COPY_PKTHDR is available as usual.
308 *
309 * - M_READONLY() macro
310 * OpenBSD 3.0 and NetBSD 1.6 has it.
311 * FreeBSD 4.x uses M_WRITABLE() macro, which is opposite (NIH!).
312 * KAME tree has it for all platforms except FreeBSD 4.x.
313 *
314 * - TAILQ_EMPTY
315 * BSD/OS 4.x does not have this macro.
316 */
317
318 #ifndef __NET_NET_OSDEP_H_DEFINED_
319 #define __NET_NET_OSDEP_H_DEFINED_
320 #ifdef _KERNEL
321
322 #define if_name(ifp) ((ifp)->if_xname)
323
324 #define HAVE_NEW_BPFATTACH
325
326 #define ifa_list ifa_link
327 #define if_addrlist if_addrhead
328 #define if_list if_link
329
330 #define HAVE_PPSRATECHECK
331
332 /* sys/net/if.h */
333 #define WITH_CONVERT_AND_STRIP_IP_LEN
334 #define WITH_CONVERT_IP_OFF
335
336 #endif /*_KERNEL*/
337 #endif /*__NET_NET_OSDEP_H_DEFINED_ */
Cache object: afbca5bd9838bfceb3fad4d72d57577d
|