FreeBSD/Linux Kernel Cross Reference
sys/net/net_osdep.h
1 /* $NetBSD: net_osdep.h,v 1.10 2005/02/26 22:45:09 perry Exp $ */
2 /* $KAME: net_osdep.h,v 1.51 2001/07/06 06:21:43 itojun 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 * - RTFREE()
39 * bsdi does not escape this macro using do-clause, so it is recommended
40 * to escape the macro explicitly.
41 * e.g.
42 * if (rt) {
43 * RTFREE(rt);
44 * }
45 *
46 * - whether the IPv4 input routine convert the byte order of some fileds
47 * of the IP header (x: convert to the host byte order, s: strip the header
48 * length for possible reassembly)
49 * ip_len ip_id ip_off
50 * bsdi3: xs x x
51 * bsdi4: xs x
52 * freebsd[23]: xs x x
53 * freebsd4: xs x
54 * NetBSD: x x
55 * OpenBSD: xs x x
56 *
57 * - ifa_ifwithaf()
58 * bsdi[34], netbsd, and openbsd define it in sys/net/if.c
59 * freebsd (all versions) does not have it.
60 *
61 * - struct rt_addrinfo
62 * bsdi4, netbsd 1.5R and beyond: rti_addrs, rti_info[], rti_flags, rti_ifa,
63 * rti_ifp, and rti_rtm.
64 * others: rti_addrs and rti_info[] only.
65 *
66 * - ifa->ifa_rtrequest
67 * bsdi4, netbsd 1.5R and beyond: rt_addrinfo *
68 * others: sockaddr * (note that sys/net/route.c:rtrequest() has an unsafe
69 * typecast code, from 4.3BSD-reno)
70 *
71 * - side effects of rtrequest{,1}(RTM_DELETE)
72 * BSDI[34]: delete all cloned routes underneath the route.
73 * FreeBSD[234]: delete all protocol-cloned routes underneath the route.
74 * note that cloned routes from an interface direct route
75 * still remain.
76 * NetBSD: 1.5 have no side effects. KAME/netbsd15, and post-1.5R, have
77 * the same effects as of BSDI.
78 * OpenBSD: have no side effects. KAME/openbsd has the same effects as
79 * of BSDI (the change is not merged - yet).
80 *
81 * - privileged process
82 * NetBSD, FreeBSD 3
83 * struct proc *p;
84 * if (p && !suser(p->p_ucred, &p->p_acflag))
85 * privileged;
86 * FreeBSD 4
87 * struct proc *p;
88 * if (p && !suser(p))
89 * privileged;
90 * OpenBSD, BSDI [34], FreeBSD 2
91 * struct socket *so;
92 * if (so->so_state & SS_PRIV)
93 * privileged;
94 * - foo_control
95 * NetBSD, FreeBSD 3
96 * needs to give struct proc * as argument
97 * OpenBSD, BSDI [34], FreeBSD 2
98 * do not need struct proc *
99 *
100 * - bpf:
101 * OpenBSD, NetBSD 1.5, BSDI [34]
102 * need caddr_t * (= if_bpf **) and struct ifnet *
103 * FreeBSD 2, FreeBSD 3, NetBSD post-1.5N
104 * need only struct ifnet * as argument
105 *
106 * - struct ifnet
107 * use queue.h? member names if name
108 * --- --- ---
109 * FreeBSD 2 no old standard if_name+unit
110 * FreeBSD 3 yes strange if_name+unit
111 * OpenBSD yes standard if_xname
112 * NetBSD yes standard if_xname
113 * BSDI [34] no old standard if_name+unit
114 *
115 * - usrreq
116 * NetBSD, OpenBSD, BSDI [34], FreeBSD 2
117 * single function with PRU_xx, arguments are mbuf
118 * FreeBSD 3
119 * separates functions, non-mbuf arguments
120 *
121 * - {set,get}sockopt
122 * NetBSD, OpenBSD, BSDI [34], FreeBSD 2
123 * manipulation based on mbuf
124 * FreeBSD 3
125 * non-mbuf manipulation using sooptcopy{in,out}()
126 *
127 * - timeout() and untimeout()
128 * NetBSD 1.4.x, OpenBSD, BSDI [34], FreeBSD 2
129 * timeout() is a void function
130 * FreeBSD 3
131 * timeout() is non-void, must keep returned value for untimeout()
132 * callout_xx is also available (sys/callout.h)
133 * NetBSD 1.5
134 * timeout() is obsoleted, use callout_xx (sys/callout.h)
135 * OpenBSD 2.8
136 * timeout_{add,set,del} is encouraged (sys/timeout.h)
137 *
138 * - kernel internal time structure
139 * FreeBSD 2, NetBSD, OpenBSD, BSD/OS
140 * mono_time.tv_u?sec, time.tv_u?sec
141 * FreeBSD [34]
142 * time_second
143 * if you need portability, #ifdef out FreeBSD[34], or use microtime(&tv)
144 * then touch tv.tv_sec.
145 *
146 * - sysctl
147 * NetBSD, OpenBSD
148 * foo_sysctl()
149 * BSDI [34]
150 * foo_sysctl() but with different style. sysctl_int_arr() takes
151 * care of most of the cases.
152 * FreeBSD
153 * linker hack. however, there are freebsd version differences
154 * (how wonderful!).
155 * on FreeBSD[23] function arg #define includes paren.
156 * int foo SYSCTL_HANDLER_ARGS;
157 * on FreeBSD4, function arg #define does not include paren.
158 * int foo(SYSCTL_HANDLER_ARGS);
159 * on some versions, forward reference to the tree is okay.
160 * on some versions, you need SYSCTL_DECL(). you need things
161 * like this.
162 * #ifdef SYSCTL_DECL
163 * SYSCTL_DECL(net_inet_ip6);
164 * #endif
165 * it is hard to share functions between freebsd and non-freebsd.
166 *
167 * - if_ioctl
168 * NetBSD, FreeBSD 3, BSDI [34]
169 * 2nd argument is u_long cmd
170 * FreeBSD 2
171 * 2nd argument is int cmd
172 *
173 * - if attach routines
174 * NetBSD
175 * void xxattach(int);
176 * FreeBSD 2, FreeBSD 3
177 * void xxattach(void *);
178 * PSEUDO_SET(xxattach, if_xx);
179 *
180 * - ovbcopy()
181 * in NetBSD 1.4 or later, ovbcopy() is not supplied in the kernel.
182 * we have updated sys/systm.h to include declaration.
183 *
184 * - splnet()
185 * NetBSD 1.4 or later requires splsoftnet().
186 * other operating systems use splnet().
187 *
188 * - splimp()
189 * NetBSD-current (2001/4/13): use splnet() in network, splvm() in vm.
190 * other operating systems: use splimp().
191 *
192 * - dtom()
193 * NEVER USE IT!
194 *
195 * - struct ifnet for loopback interface
196 * BSDI3: struct ifnet loif;
197 * BSDI4: struct ifnet *loifp;
198 * NetBSD 2.0, OpenBSD 2.8, FreeBSD2: struct ifnet loif[NLOOP];
199 * NetBSD 3.0, OpenBSD 2.9: struct ifnet *lo0ifp;
200 *
201 * odd thing is that many of them refers loif as ifnet *loif,
202 * not loif[NLOOP], from outside of if_loop.c.
203 *
204 * - number of bpf pseudo devices
205 * others: bpfilter.h, NBPFILTER
206 * FreeBSD4: bpf.h, NBPF
207 * solution:
208 * #if defined(__FreeBSD__) && __FreeBSD__ >= 4
209 * #include "bpf.h"
210 * #define NBPFILTER NBPF
211 * #else
212 * #include "bpfilter.h"
213 * #endif
214 *
215 * - protosw for IPv4 (sys/netinet)
216 * FreeBSD4: struct ipprotosw in netinet/ipprotosw.h
217 * others: struct protosw in sys/protosw.h
218 *
219 * - protosw in general.
220 * NetBSD 1.5 has extra member for ipfilter (netbsd-current dropped
221 * it so it will go away in 1.6).
222 * NetBSD 1.5 requires PR_LISTEN flag bit with protocols that permit
223 * listen/accept (like tcp).
224 *
225 * - header files with defopt (opt_xx.h)
226 * FreeBSD3: opt_{inet,ipsec,ip6fw,altq}.h
227 * FreeBSD4: opt_{inet,inet6,ipsec,ip6fw,altq}.h
228 * NetBSD: opt_{inet,ipsec,altq}.h
229 * others: does not use defopt
230 *
231 * - IN_MULTICAST/IN_CLASS[A-D] macro.
232 * OpenBSD and NetBSD: net endian (kernel) or host endian (userland)
233 * others: always host endian
234 *
235 * - (m->m_flags & M_EXT) != 0 does *not* mean that the max data length of
236 * the mbuf == MCLBYTES.
237 *
238 * - sys/kern/uipc_mbuf.c:m_dup()
239 * freebsd[34]: copies the whole mbuf chain.
240 * netbsd: similar arg with m_copym().
241 * others: no m_dup().
242 *
243 * - ifa_refcnt (struct ifaddr) management (IFAREF/IFAFREE).
244 * NetBSD 1.5: always use IFAREF whenever reference gets added.
245 * always use IFAFREE whenever reference gets freed.
246 * IFAFREE frees ifaddr when ifa_refcnt reaches 0.
247 * others: do not increase refcnt for ifp->if_addrlist and in_ifaddr.
248 * use IFAFREE once when ifaddr is disconnected from
249 * ifp->if_addrlist and in_ifaddr. IFAFREE frees ifaddr when
250 * ifa_refcnt goes negative. in KAME environment, IFAREF is
251 * provided as a compatibility wrapper (use it instead of
252 * ifa_refcnt++ to reduce #ifdef).
253 *
254 * - ifnet.if_lastchange
255 * freebsd, bsdi, netbsd-current (jun 14 2001-),
256 * openbsd-current (jun 15 2001-): updated only when IFF_UP changes.
257 * (RFC1573 ifLastChange interpretation)
258 * netbsd151, openbsd29: updated whenever packets go through the interface.
259 * (4.4BSD interpretation)
260 *
261 * - kernel compilation options ("options HOGE" in kernel config file)
262 * freebsd4: sys/conf/options has to have mapping between option
263 * and a header file (opt_hoge.h).
264 * netbsd: by default, -DHOGE will go into
265 * sys/arch/foo/compile/BAR/Makefile.
266 * if you define mapping in sys/conf/files, you can create
267 * a header file like opt_hoge.h to help make dependencies.
268 * bsdi/openbsd: always use -DHOGE in Makefile. there's no need/way
269 * to have opt_hoge.h.
270 *
271 * therefore, opt_hoge.h is mandatory on freebsd4 only.
272 *
273 * - MALLOC() macro
274 * Use it only if the size of the allocation is constant.
275 * When we do NOT collect statistics about kernel memory usage, the result
276 * of macro expansion contains a large set of condition branches. If the
277 * size is not constant, compilation optimization cannot be applied, and
278 * a bunch of the large branch will be embedded in the kernel code.
279 *
280 * - M_COPY_PKTHDR
281 * openbsd30: M_COPY_PKTHDR is deprecated. use M_MOVE_PKTHDR or
282 * M_DUP_PKTHDR, depending on how you want to handle m_tag.
283 * others: M_COPY_PKTHDR is available as usual.
284 */
285
286 #ifndef __NET_NET_OSDEP_H_DEFINED_
287 #define __NET_NET_OSDEP_H_DEFINED_
288 #ifdef _KERNEL
289
290 #define if_name(ifp) ((ifp)->if_xname)
291
292 #if defined(__NetBSD__) && __NetBSD_Version__ >= 104000000
293 #define ovbcopy(src, dst, len) memmove((dst), (src), (len))
294 #endif
295
296 #endif /*_KERNEL*/
297 #endif /*__NET_NET_OSDEP_H_DEFINED_ */
Cache object: c0b6f7afc4fad0770fc77e31c050fe42
|