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