2 /* $KAME: net_osdep.h,v 1.68 2001/12/21 08:14:58 itojun Exp $ */
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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
33 * glue for kernel code programming differences.
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.
43 * bsdi does not escape this macro using do-clause, so it is recommended
44 * to escape the macro explicitly.
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)
62 * bsdi[34], netbsd, and openbsd define it in sys/net/if.c
63 * freebsd (all versions) does not have it.
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.
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)
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
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).
85 * - privileged process
88 * if (p && !suser(p->p_ucred, &p->p_acflag))
98 * OpenBSD, BSDI [34], FreeBSD 2
100 * if (so->so_state & SS_PRIV)
104 * needs to give struct proc * as argument
105 * OpenBSD, BSDI [34], FreeBSD 2
106 * do not need struct proc *
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
115 * use queue.h? member names if name
117 * FreeBSD 2 no old standard if_name+unit
118 * FreeBSD 3 yes strange if_name+unit
119 * OpenBSD yes standard if_xname
120 * NetBSD yes standard if_xname
121 * BSDI [34] no old standard if_name+unit
124 * NetBSD, OpenBSD, BSDI [34], FreeBSD 2
125 * single function with PRU_xx, arguments are mbuf
127 * separates functions, non-mbuf arguments
130 * NetBSD, OpenBSD, BSDI [34], FreeBSD 2
131 * manipulation based on mbuf
133 * non-mbuf manipulation using sooptcopy{in,out}()
135 * - timeout() and untimeout()
136 * NetBSD 1.4.x, OpenBSD, BSDI [34], FreeBSD 2
137 * timeout() is a void function
139 * timeout() is non-void, must keep returned value for untimeout()
140 * callout_xx is also available (sys/callout.h)
142 * timeout() is obsoleted, use callout_xx (sys/callout.h)
144 * timeout_{add,set,del} is encouraged (sys/timeout.h)
146 * - kernel internal time structure
147 * FreeBSD 2, NetBSD, OpenBSD, BSD/OS
148 * mono_time.tv_u?sec, time.tv_u?sec
151 * if you need portability, #ifdef out FreeBSD[34], or use microtime(&tv)
152 * then touch tv.tv_sec (note: microtime is an expensive operation).
158 * foo_sysctl() but with different style. sysctl_int_arr() takes
159 * care of most of the cases.
161 * linker hack. however, there are freebsd version differences
163 * on FreeBSD[23] function arg #define includes paren.
164 * int foo SYSCTL_HANDLER_ARGS;
165 * on FreeBSD4, function arg #define does not include paren.
166 * int foo(SYSCTL_HANDLER_ARGS);
167 * on some versions, forward reference to the tree is okay.
168 * on some versions, you need SYSCTL_DECL(). you need things
171 * SYSCTL_DECL(net_inet_ip6);
173 * it is hard to share functions between freebsd and non-freebsd.
176 * NetBSD, FreeBSD 3, BSDI [34]
177 * 2nd argument is u_long cmd
179 * 2nd argument is int cmd
181 * - if attach routines
183 * void xxattach(int);
184 * FreeBSD 2, FreeBSD 3
185 * void xxattach(void *);
186 * PSEUDO_SET(xxattach, if_xx);
189 * in NetBSD 1.4 or later, ovbcopy() is not supplied in the kernel.
190 * we have updated sys/systm.h to include declaration.
193 * NetBSD 1.4 or later requires splsoftnet().
194 * other operating systems use splnet().
197 * NetBSD-current (2001/4/13): use splnet() in network, splvm() in vm.
198 * other operating systems: use splimp().
203 * - struct ifnet for loopback interface
204 * BSDI3: struct ifnet loif;
205 * BSDI4: struct ifnet *loifp;
206 * NetBSD, OpenBSD 2.8, FreeBSD2: struct ifnet loif[NLOOP];
207 * OpenBSD 2.9: struct ifnet *lo0ifp;
209 * odd thing is that many of them refers loif as ifnet *loif,
210 * not loif[NLOOP], from outside of if_loop.c.
212 * - number of bpf pseudo devices
213 * others: bpfilter.h, NBPFILTER
214 * FreeBSD4: bpf.h, NBPF
216 * #if defined(__FreeBSD__) && __FreeBSD__ >= 4
218 * #define NBPFILTER NBPF
220 * #include "bpfilter.h"
223 * - protosw for IPv4 (sys/netinet)
224 * FreeBSD4: struct ipprotosw in netinet/ipprotosw.h
225 * others: struct protosw in sys/protosw.h
227 * - protosw in general.
228 * NetBSD 1.5 has extra member for ipfilter (netbsd-current dropped
229 * it so it will go away in 1.6).
230 * NetBSD 1.5 requires PR_LISTEN flag bit with protocols that permit
231 * listen/accept (like tcp).
233 * - header files with defopt (opt_xx.h)
234 * FreeBSD3: opt_{inet,ipsec,ip6fw,altq}.h
235 * FreeBSD4: opt_{inet,inet6,ipsec,ip6fw,altq}.h
236 * NetBSD: opt_{inet,ipsec,altq}.h
237 * others: does not use defopt
239 * - IN_MULTICAST/IN_CLASS[A-D] macro.
240 * OpenBSD and NetBSD: net endian (kernel) or host endian (userland)
241 * others: always host endian
243 * - (m->m_flags & M_EXT) != 0 does *not* mean that the max data length of
244 * the mbuf == MCLBYTES.
246 * - sys/kern/uipc_mbuf.c:m_dup()
247 * freebsd[34]: copies the whole mbuf chain.
248 * netbsd: similar arg with m_copym().
249 * others: no m_dup().
251 * - ifa_refcnt (struct ifaddr) management (IFAREF/IFAFREE).
252 * NetBSD 1.5: always use IFAREF whenever reference gets added.
253 * always use IFAFREE whenever reference gets freed.
254 * IFAFREE frees ifaddr when ifa_refcnt reaches 0.
255 * others: do not increase refcnt for ifp->if_addrlist and in_ifaddr.
256 * use IFAFREE once when ifaddr is disconnected from
257 * ifp->if_addrlist and in_ifaddr. IFAFREE frees ifaddr when
258 * ifa_refcnt goes negative. in KAME environment, IFAREF is
259 * provided as a compatibility wrapper (use it instead of
260 * ifa_refcnt++ to reduce #ifdef).
262 * - ifnet.if_lastchange
263 * freebsd, bsdi, netbsd-current (jun 14 2001-),
264 * openbsd-current (jun 15 2001-): updated only when IFF_UP changes.
265 * (RFC1573 ifLastChange interpretation)
266 * netbsd151, openbsd29: updated whenever packets go through the interface.
267 * (4.4BSD interpretation)
269 * - kernel compilation options ("options HOGE" in kernel config file)
270 * freebsd4: sys/conf/options has to have mapping between option
271 * and a header file (opt_hoge.h).
272 * netbsd: by default, -DHOGE will go into
273 * sys/arch/foo/compile/BAR/Makefile.
274 * if you define mapping in sys/conf/files, you can create
275 * a header file like opt_hoge.h to help make dependencies.
276 * bsdi/openbsd: always use -DHOGE in Makefile. there's no need/way
277 * to have opt_hoge.h.
279 * therefore, opt_hoge.h is mandatory on freebsd4 only.
282 * Use it only if the size of the allocation is constant.
283 * When we do NOT collect statistics about kernel memory usage, the result
284 * of macro expansion contains a large set of condition branches. If the
285 * size is not constant, compilation optimization cannot be applied, and
286 * a bunch of the large branch will be embedded in the kernel code.
289 * openbsd30: M_COPY_PKTHDR is deprecated. use M_MOVE_PKTHDR or
290 * M_DUP_PKTHDR, depending on how you want to handle m_tag.
291 * others: M_COPY_PKTHDR is available as usual.
294 #ifndef __NET_NET_OSDEP_H_DEFINED_
295 #define __NET_NET_OSDEP_H_DEFINED_
299 extern const char *if_name(struct ifnet *);
303 #define ifa_list ifa_link
304 #define if_addrlist if_addrhead
305 #define if_list if_link
307 #define WITH_CONVERT_AND_STRIP_IP_LEN
309 #if 1 /* at this moment, all OSes do this */
310 #define WITH_CONVERT_IP_OFF
316 #include <sys/module.h>
317 #define PSEUDO_SET(sym, name) \
318 static int name ## _modevent(module_t mod, int type, void *data) \
320 void (*initfunc)(void *) = (void (*)(void *))data; \
323 /* printf(#name " module load\n"); */ \
327 printf(#name " module unload - not possible for this module type\n"); \
332 static moduledata_t name ## _mod = { \
337 DECLARE_MODULE(name, name ## _mod, SI_SUB_PSEUDO, SI_ORDER_ANY)
340 #endif /*__NET_NET_OSDEP_H_DEFINED_ */