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