HAMMER 60I/Many: Mirroring
[dragonfly.git] / sys / net / net_osdep.h
blob41e9534d6d551bf06211d2340e68ab6c4e94b870
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.
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.
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.
35 * glue for kernel code programming differences.
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.
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 * }
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
63 * - ifa_ifwithaf()
64 * bsdi[34], netbsd, and openbsd define it in sys/net/if.c
65 * freebsd (all versions) does not have it.
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.
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)
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).
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 *
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
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
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
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}()
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)
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).
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.
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
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);
186 * - ovbcopy()
187 * in NetBSD 1.4 or later, ovbcopy() is not supplied in the kernel.
188 * we have updated sys/systm.h to include declaration.
190 * - splnet()
191 * NetBSD 1.4 or later requires splsoftnet().
192 * other operating systems use splnet().
194 * - splimp()
195 * NetBSD-current (2001/4/13): use splnet() in network, splvm() in vm.
196 * other operating systems: use splimp().
198 * - struct ifnet for loopback interface
199 * BSDI3: struct ifnet loif;
200 * BSDI4: struct ifnet *loifp;
201 * NetBSD, OpenBSD 2.8, FreeBSD2: struct ifnet loif[NLOOP];
202 * OpenBSD 2.9: struct ifnet *lo0ifp;
204 * odd thing is that many of them refers loif as ifnet *loif,
205 * not loif[NLOOP], from outside of if_loop.c.
207 * - number of bpf pseudo devices
208 * others: bpfilter.h, NBPFILTER
209 * FreeBSD4: use_bpf.h, NBPF
210 * solution:
211 * #if defined(__FreeBSD__) && __FreeBSD__ >= 4
212 * #include "use_bpf.h"
213 * #define NBPFILTER NBPF
214 * #else
215 * #include "bpfilter.h"
216 * #endif
218 * - protosw for IPv4 (sys/netinet)
219 * FreeBSD4: struct ipprotosw in netinet/ipprotosw.h
220 * others: struct protosw in sys/protosw.h
222 * - protosw in general.
223 * NetBSD 1.5 has extra member for ipfilter (netbsd-current dropped
224 * it so it will go away in 1.6).
225 * NetBSD 1.5 requires PR_LISTEN flag bit with protocols that permit
226 * listen/accept (like tcp).
228 * - header files with defopt (opt_xx.h)
229 * FreeBSD3: opt_{inet,ipsec,ip6fw,altq}.h
230 * FreeBSD4: opt_{inet,inet6,ipsec,ip6fw,altq}.h
231 * NetBSD: opt_{inet,ipsec,altq}.h
232 * others: does not use defopt
234 * - (m->m_flags & M_EXT) != 0 does *not* mean that the max data length of
235 * the mbuf == MCLBYTES.
237 * - sys/kern/uipc_mbuf.c:m_dup()
238 * freebsd[34]: copies the whole mbuf chain.
239 * netbsd: similar arg with m_copym().
240 * others: no m_dup().
242 * - ifa_refcnt (struct ifaddr) management (IFAREF/IFAFREE).
243 * NetBSD 1.5: always use IFAREF whenever reference gets added.
244 * always use IFAFREE whenever reference gets freed.
245 * IFAFREE frees ifaddr when ifa_refcnt reaches 0.
246 * others: do not increase refcnt for ifp->if_addrlist and in_ifaddr.
247 * use IFAFREE once when ifaddr is disconnected from
248 * ifp->if_addrlist and in_ifaddr. IFAFREE frees ifaddr when
249 * ifa_refcnt goes negative. in KAME environment, IFAREF is
250 * provided as a compatibility wrapper (use it instead of
251 * ifa_refcnt++ to reduce #ifdef).
253 * - ifnet.if_lastchange
254 * freebsd, bsdi, netbsd-current (jun 14 2001-),
255 * openbsd-current (jun 15 2001-): updated only when IFF_UP changes.
256 * (RFC1573 ifLastChange interpretation)
257 * netbsd151, openbsd29: updated whenever packets go through the interface.
258 * (4.4BSD interpretation)
260 * - kernel compilation options ("options HOGE" in kernel config file)
261 * freebsd4: sys/conf/options has to have mapping between option
262 * and a header file (opt_hoge.h).
263 * netbsd: by default, -DHOGE will go into
264 * sys/arch/foo/compile/BAR/Makefile.
265 * if you define mapping in sys/conf/files, you can create
266 * a header file like opt_hoge.h to help make dependencies.
267 * bsdi/openbsd: always use -DHOGE in Makefile. there's no need/way
268 * to have opt_hoge.h.
270 * therefore, opt_hoge.h is mandatory on freebsd4 only.
272 * - MALLOC() macro
273 * Use it only if the size of the allocation is constant.
274 * When we do NOT collect statistics about kernel memory usage, the result
275 * of macro expansion contains a large set of condition branches. If the
276 * size is not constant, compilation optimization cannot be applied, and
277 * a bunch of the large branch will be embedded in the kernel code.
279 * - M_COPY_PKTHDR
280 * openbsd30: M_COPY_PKTHDR is deprecated. use M_MOVE_PKTHDR or
281 * M_DUP_PKTHDR, depending on how you want to handle m_tag.
282 * others: M_COPY_PKTHDR is available as usual.
285 #ifndef _NET_NET_OSDEP_H_
286 #define _NET_NET_OSDEP_H_
287 #ifdef _KERNEL
289 struct ifnet;
290 extern const char *if_name (struct ifnet *);
292 #define HAVE_OLD_BPF
294 #define if_list if_link
296 #define WITH_CONVERT_AND_STRIP_IP_LEN
298 #if 1 /* at this moment, all OSes do this */
299 #define WITH_CONVERT_IP_OFF
300 #endif
302 #endif /*_KERNEL*/
303 #endif /*_NET_NET_OSDEP_H_*/