1*fdd8201dSApple OSS Distributions /* 2*fdd8201dSApple OSS Distributions * Copyright (c) 2000-2010 Apple Inc. All rights reserved. 3*fdd8201dSApple OSS Distributions * 4*fdd8201dSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*fdd8201dSApple OSS Distributions * 6*fdd8201dSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*fdd8201dSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*fdd8201dSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*fdd8201dSApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*fdd8201dSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*fdd8201dSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*fdd8201dSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*fdd8201dSApple OSS Distributions * terms of an Apple operating system software license agreement. 14*fdd8201dSApple OSS Distributions * 15*fdd8201dSApple OSS Distributions * Please obtain a copy of the License at 16*fdd8201dSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*fdd8201dSApple OSS Distributions * 18*fdd8201dSApple OSS Distributions * The Original Code and all software distributed under the License are 19*fdd8201dSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*fdd8201dSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*fdd8201dSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*fdd8201dSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*fdd8201dSApple OSS Distributions * Please see the License for the specific language governing rights and 24*fdd8201dSApple OSS Distributions * limitations under the License. 25*fdd8201dSApple OSS Distributions * 26*fdd8201dSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*fdd8201dSApple OSS Distributions */ 28*fdd8201dSApple OSS Distributions /* 29*fdd8201dSApple OSS Distributions * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 30*fdd8201dSApple OSS Distributions * All rights reserved. 31*fdd8201dSApple OSS Distributions * 32*fdd8201dSApple OSS Distributions * Redistribution and use in source and binary forms, with or without 33*fdd8201dSApple OSS Distributions * modification, are permitted provided that the following conditions 34*fdd8201dSApple OSS Distributions * are met: 35*fdd8201dSApple OSS Distributions * 1. Redistributions of source code must retain the above copyright 36*fdd8201dSApple OSS Distributions * notice, this list of conditions and the following disclaimer. 37*fdd8201dSApple OSS Distributions * 2. Redistributions in binary form must reproduce the above copyright 38*fdd8201dSApple OSS Distributions * notice, this list of conditions and the following disclaimer in the 39*fdd8201dSApple OSS Distributions * documentation and/or other materials provided with the distribution. 40*fdd8201dSApple OSS Distributions * 3. Neither the name of the project nor the names of its contributors 41*fdd8201dSApple OSS Distributions * may be used to endorse or promote products derived from this software 42*fdd8201dSApple OSS Distributions * without specific prior written permission. 43*fdd8201dSApple OSS Distributions * 44*fdd8201dSApple OSS Distributions * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 45*fdd8201dSApple OSS Distributions * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 46*fdd8201dSApple OSS Distributions * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 47*fdd8201dSApple OSS Distributions * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 48*fdd8201dSApple OSS Distributions * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 49*fdd8201dSApple OSS Distributions * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 50*fdd8201dSApple OSS Distributions * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 51*fdd8201dSApple OSS Distributions * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 52*fdd8201dSApple OSS Distributions * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 53*fdd8201dSApple OSS Distributions * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 54*fdd8201dSApple OSS Distributions * SUCH DAMAGE. 55*fdd8201dSApple OSS Distributions */ 56*fdd8201dSApple OSS Distributions /* 57*fdd8201dSApple OSS Distributions * glue for kernel code programming differences. 58*fdd8201dSApple OSS Distributions */ 59*fdd8201dSApple OSS Distributions 60*fdd8201dSApple OSS Distributions /* 61*fdd8201dSApple OSS Distributions * OS dependencies: 62*fdd8201dSApple OSS Distributions * 63*fdd8201dSApple OSS Distributions * - whether the IPv4 input routine convert the byte order of some fileds 64*fdd8201dSApple OSS Distributions * of the IP header (x: convert to the host byte order, s: strip the header 65*fdd8201dSApple OSS Distributions * length for possible reassembly) 66*fdd8201dSApple OSS Distributions * ip_len ip_id ip_off 67*fdd8201dSApple OSS Distributions * bsdi3: xs x x 68*fdd8201dSApple OSS Distributions * bsdi4: xs x 69*fdd8201dSApple OSS Distributions * FreeBSD: xs x 70*fdd8201dSApple OSS Distributions * NetBSD: x x 71*fdd8201dSApple OSS Distributions * OpenBSD: xs x x 72*fdd8201dSApple OSS Distributions * 73*fdd8201dSApple OSS Distributions * - ifa_ifwithaf() 74*fdd8201dSApple OSS Distributions * bsdi[34], netbsd, and openbsd define it in sys/net/if.c 75*fdd8201dSApple OSS Distributions * freebsd (all versions) does not have it. 76*fdd8201dSApple OSS Distributions * 77*fdd8201dSApple OSS Distributions * - struct rt_addrinfo 78*fdd8201dSApple OSS Distributions * bsdi4, netbsd 1.5R and beyond: rti_addrs, rti_info[], rti_flags, rti_ifa, 79*fdd8201dSApple OSS Distributions * rti_ifp, and rti_rtm. 80*fdd8201dSApple OSS Distributions * others: rti_addrs and rti_info[] only. 81*fdd8201dSApple OSS Distributions * 82*fdd8201dSApple OSS Distributions * - ifa->ifa_rtrequest 83*fdd8201dSApple OSS Distributions * bsdi4, netbsd 1.5R and beyond: rt_addrinfo * 84*fdd8201dSApple OSS Distributions * others: sockaddr * (note that sys/net/route.c:rtrequest() has an unsafe 85*fdd8201dSApple OSS Distributions * typecast code, from 4.3BSD-reno) 86*fdd8201dSApple OSS Distributions * 87*fdd8201dSApple OSS Distributions * - side effects of rtrequest{,1}(RTM_DELETE) 88*fdd8201dSApple OSS Distributions * BSDI[34]: delete all cloned routes underneath the route. 89*fdd8201dSApple OSS Distributions * FreeBSD[234]: delete all protocol-cloned routes underneath the route. 90*fdd8201dSApple OSS Distributions * note that cloned routes from an interface direct route 91*fdd8201dSApple OSS Distributions * still remain. 92*fdd8201dSApple OSS Distributions * NetBSD: 1.5 have no side effects. KAME/netbsd15, and post-1.5R, have 93*fdd8201dSApple OSS Distributions * the same effects as of BSDI. 94*fdd8201dSApple OSS Distributions * OpenBSD: have no side effects. KAME/openbsd has the same effects as 95*fdd8201dSApple OSS Distributions * of BSDI (the change is not merged - yet). 96*fdd8201dSApple OSS Distributions * 97*fdd8201dSApple OSS Distributions * - privileged process 98*fdd8201dSApple OSS Distributions * NetBSD, FreeBSD 3 99*fdd8201dSApple OSS Distributions * struct proc *p; 100*fdd8201dSApple OSS Distributions * if (p && !suser(p->p_ucred, &p->p_acflag)) 101*fdd8201dSApple OSS Distributions * privileged; 102*fdd8201dSApple OSS Distributions * FreeBSD 4 103*fdd8201dSApple OSS Distributions * struct proc *p; 104*fdd8201dSApple OSS Distributions * if (p && !suser(p)) 105*fdd8201dSApple OSS Distributions * privileged; 106*fdd8201dSApple OSS Distributions * OpenBSD, BSDI [34], FreeBSD 2 107*fdd8201dSApple OSS Distributions * struct socket *so; 108*fdd8201dSApple OSS Distributions * if (so->so_state & SS_PRIV) 109*fdd8201dSApple OSS Distributions * privileged; 110*fdd8201dSApple OSS Distributions * - foo_control 111*fdd8201dSApple OSS Distributions * NetBSD, FreeBSD 3 112*fdd8201dSApple OSS Distributions * needs to give struct proc * as argument 113*fdd8201dSApple OSS Distributions * OpenBSD, BSDI [34], FreeBSD 2 114*fdd8201dSApple OSS Distributions * do not need struct proc * 115*fdd8201dSApple OSS Distributions * 116*fdd8201dSApple OSS Distributions * - bpf: 117*fdd8201dSApple OSS Distributions * OpenBSD, NetBSD 1.5, BSDI [34] 118*fdd8201dSApple OSS Distributions * need caddr_t * (= if_bpf **) and struct ifnet * 119*fdd8201dSApple OSS Distributions * FreeBSD 2, FreeBSD 3, NetBSD post-1.5N 120*fdd8201dSApple OSS Distributions * need only struct ifnet * as argument 121*fdd8201dSApple OSS Distributions * 122*fdd8201dSApple OSS Distributions * - struct ifnet 123*fdd8201dSApple OSS Distributions * use queue.h? member names if name 124*fdd8201dSApple OSS Distributions * --- --- --- 125*fdd8201dSApple OSS Distributions * FreeBSD 2 no old standard if_name+unit 126*fdd8201dSApple OSS Distributions * FreeBSD 3 yes strange if_name+unit 127*fdd8201dSApple OSS Distributions * OpenBSD yes standard if_xname 128*fdd8201dSApple OSS Distributions * NetBSD yes standard if_xname 129*fdd8201dSApple OSS Distributions * BSDI [34] no old standard if_name+unit 130*fdd8201dSApple OSS Distributions * 131*fdd8201dSApple OSS Distributions * - usrreq 132*fdd8201dSApple OSS Distributions * NetBSD, OpenBSD, BSDI [34], FreeBSD 2 133*fdd8201dSApple OSS Distributions * single function with PRU_xx, arguments are mbuf 134*fdd8201dSApple OSS Distributions * FreeBSD 3 135*fdd8201dSApple OSS Distributions * separates functions, non-mbuf arguments 136*fdd8201dSApple OSS Distributions * 137*fdd8201dSApple OSS Distributions * - {set,get}sockopt 138*fdd8201dSApple OSS Distributions * NetBSD, OpenBSD, BSDI [34], FreeBSD 2 139*fdd8201dSApple OSS Distributions * manipulation based on mbuf 140*fdd8201dSApple OSS Distributions * FreeBSD 3 141*fdd8201dSApple OSS Distributions * non-mbuf manipulation using sooptcopy{in,out}() 142*fdd8201dSApple OSS Distributions * 143*fdd8201dSApple OSS Distributions * - timeout() and untimeout() 144*fdd8201dSApple OSS Distributions * NetBSD 1.4.x, OpenBSD, BSDI [34], FreeBSD 2 145*fdd8201dSApple OSS Distributions * timeout() is a void function 146*fdd8201dSApple OSS Distributions * FreeBSD 3 147*fdd8201dSApple OSS Distributions * timeout() is non-void, must keep returned value for untimeout() 148*fdd8201dSApple OSS Distributions * callout_xx is also available (sys/callout.h) 149*fdd8201dSApple OSS Distributions * NetBSD 1.5 150*fdd8201dSApple OSS Distributions * timeout() is obsoleted, use callout_xx (sys/callout.h) 151*fdd8201dSApple OSS Distributions * OpenBSD 2.8 152*fdd8201dSApple OSS Distributions * timeout_{add,set,del} is encouraged (sys/timeout.h) 153*fdd8201dSApple OSS Distributions * 154*fdd8201dSApple OSS Distributions * - sysctl 155*fdd8201dSApple OSS Distributions * NetBSD, OpenBSD 156*fdd8201dSApple OSS Distributions * foo_sysctl() 157*fdd8201dSApple OSS Distributions * BSDI [34] 158*fdd8201dSApple OSS Distributions * foo_sysctl() but with different style. sysctl_int_arr() takes 159*fdd8201dSApple OSS Distributions * care of most of the cases. 160*fdd8201dSApple OSS Distributions * FreeBSD 161*fdd8201dSApple OSS Distributions * linker hack. however, there are freebsd version differences 162*fdd8201dSApple OSS Distributions * (how wonderful!). 163*fdd8201dSApple OSS Distributions * on FreeBSD[23] function arg #define includes paren. 164*fdd8201dSApple OSS Distributions * int foo SYSCTL_HANDLER_ARGS; 165*fdd8201dSApple OSS Distributions * on FreeBSD4, function arg #define does not include paren. 166*fdd8201dSApple OSS Distributions * int foo(SYSCTL_HANDLER_ARGS); 167*fdd8201dSApple OSS Distributions * on some versions, forward reference to the tree is okay. 168*fdd8201dSApple OSS Distributions * on some versions, you need SYSCTL_DECL(). you need things 169*fdd8201dSApple OSS Distributions * like this. 170*fdd8201dSApple OSS Distributions * #ifdef SYSCTL_DECL 171*fdd8201dSApple OSS Distributions * SYSCTL_DECL(net_inet_ip6); 172*fdd8201dSApple OSS Distributions * #endif 173*fdd8201dSApple OSS Distributions * it is hard to share functions between freebsd and non-freebsd. 174*fdd8201dSApple OSS Distributions * 175*fdd8201dSApple OSS Distributions * - if_ioctl 176*fdd8201dSApple OSS Distributions * NetBSD, FreeBSD 3, BSDI [34] 177*fdd8201dSApple OSS Distributions * 2nd argument is u_long cmd 178*fdd8201dSApple OSS Distributions * FreeBSD 2 179*fdd8201dSApple OSS Distributions * 2nd argument is int cmd 180*fdd8201dSApple OSS Distributions * 181*fdd8201dSApple OSS Distributions * - if attach routines 182*fdd8201dSApple OSS Distributions * NetBSD 183*fdd8201dSApple OSS Distributions * void xxattach(int); 184*fdd8201dSApple OSS Distributions * FreeBSD 2, FreeBSD 3 185*fdd8201dSApple OSS Distributions * void xxattach(void *); 186*fdd8201dSApple OSS Distributions * PSEUDO_SET(xxattach, if_xx); 187*fdd8201dSApple OSS Distributions * 188*fdd8201dSApple OSS Distributions * - ovbcopy() 189*fdd8201dSApple OSS Distributions * in NetBSD 1.4 or later, ovbcopy() is not supplied in the kernel. 190*fdd8201dSApple OSS Distributions * bcopy() is safe against overwrites. 191*fdd8201dSApple OSS Distributions * 192*fdd8201dSApple OSS Distributions * - splnet() 193*fdd8201dSApple OSS Distributions * NetBSD 1.4 or later requires splsoftnet(). 194*fdd8201dSApple OSS Distributions * other operating systems use splnet(). 195*fdd8201dSApple OSS Distributions * 196*fdd8201dSApple OSS Distributions * - dtom() 197*fdd8201dSApple OSS Distributions * NEVER USE IT! 198*fdd8201dSApple OSS Distributions * 199*fdd8201dSApple OSS Distributions * - struct ifnet for loopback interface 200*fdd8201dSApple OSS Distributions * BSDI3: struct ifnet loif; 201*fdd8201dSApple OSS Distributions * BSDI4: struct ifnet *loifp; 202*fdd8201dSApple OSS Distributions * NetBSD, OpenBSD 2.8, FreeBSD2: struct ifnet loif[NLOOP]; 203*fdd8201dSApple OSS Distributions * OpenBSD 2.9: struct ifnet *lo0ifp; 204*fdd8201dSApple OSS Distributions * 205*fdd8201dSApple OSS Distributions * odd thing is that many of them refers loif as ifnet *loif, 206*fdd8201dSApple OSS Distributions * not loif[NLOOP], from outside of if_loop.c. 207*fdd8201dSApple OSS Distributions * 208*fdd8201dSApple OSS Distributions * - number of bpf pseudo devices 209*fdd8201dSApple OSS Distributions * others: bpfilter.h, NBPFILTER 210*fdd8201dSApple OSS Distributions * FreeBSD4: bpf.h, NBPF 211*fdd8201dSApple OSS Distributions * solution: 212*fdd8201dSApple OSS Distributions * #if defined(__FreeBSD__) && __FreeBSD__ >= 4 213*fdd8201dSApple OSS Distributions * #include "bpf.h" 214*fdd8201dSApple OSS Distributions * #define NBPFILTER NBPF 215*fdd8201dSApple OSS Distributions * #else 216*fdd8201dSApple OSS Distributions * #include "bpfilter.h" 217*fdd8201dSApple OSS Distributions * #endif 218*fdd8201dSApple OSS Distributions * 219*fdd8201dSApple OSS Distributions * - protosw for IPv4 (sys/netinet) 220*fdd8201dSApple OSS Distributions * FreeBSD4: struct ipprotosw in netinet/ipprotosw.h 221*fdd8201dSApple OSS Distributions * others: struct protosw in sys/protosw.h 222*fdd8201dSApple OSS Distributions * 223*fdd8201dSApple OSS Distributions * - protosw in general. 224*fdd8201dSApple OSS Distributions * NetBSD 1.5 has extra member for ipfilter (netbsd-current dropped 225*fdd8201dSApple OSS Distributions * it so it will go away in 1.6). 226*fdd8201dSApple OSS Distributions * NetBSD 1.5 requires PR_LISTEN flag bit with protocols that permit 227*fdd8201dSApple OSS Distributions * listen/accept (like tcp). 228*fdd8201dSApple OSS Distributions * 229*fdd8201dSApple OSS Distributions * - header files with defopt (opt_xx.h) 230*fdd8201dSApple OSS Distributions * FreeBSD3: opt_{inet,ipsec,ip6fw,altq}.h 231*fdd8201dSApple OSS Distributions * FreeBSD4: opt_{inet,inet6,ipsec,ip6fw,altq}.h 232*fdd8201dSApple OSS Distributions * NetBSD: opt_{inet,ipsec,altq}.h 233*fdd8201dSApple OSS Distributions * others: does not use defopt 234*fdd8201dSApple OSS Distributions * 235*fdd8201dSApple OSS Distributions * - (m->m_flags & M_EXT) != 0 does *not* mean that the max data length of 236*fdd8201dSApple OSS Distributions * the mbuf == MCLBYTES. 237*fdd8201dSApple OSS Distributions * 238*fdd8201dSApple OSS Distributions * - sys/kern/uipc_mbuf.c:m_dup() 239*fdd8201dSApple OSS Distributions * freebsd[34]: copies the whole mbuf chain. 240*fdd8201dSApple OSS Distributions * netbsd: similar arg with m_copym(). 241*fdd8201dSApple OSS Distributions * others: no m_dup(). 242*fdd8201dSApple OSS Distributions * 243*fdd8201dSApple OSS Distributions * - ifa_refcnt (struct ifaddr) management (IFAREF/IFAFREE). 244*fdd8201dSApple OSS Distributions * NetBSD 1.5: always use IFAREF whenever reference gets added. 245*fdd8201dSApple OSS Distributions * always use IFAFREE whenever reference gets freed. 246*fdd8201dSApple OSS Distributions * IFAFREE frees ifaddr when ifa_refcnt reaches 0. 247*fdd8201dSApple OSS Distributions * Darwin: always use IFA_ADDREF whenever reference gets added. 248*fdd8201dSApple OSS Distributions * always use IFA_REMREF whenever reference gets freed. 249*fdd8201dSApple OSS Distributions * IFA_ADDREF and IFA_REMREF are responsible for determining 250*fdd8201dSApple OSS Distributions * when to free. 251*fdd8201dSApple OSS Distributions * others: do not increase refcnt for ifp->if_addrlist and in_ifaddr. 252*fdd8201dSApple OSS Distributions * use IFAFREE once when ifaddr is disconnected from 253*fdd8201dSApple OSS Distributions * ifp->if_addrlist and in_ifaddr. IFAFREE frees ifaddr when 254*fdd8201dSApple OSS Distributions * ifa_refcnt goes negative. 255*fdd8201dSApple OSS Distributions */ 256*fdd8201dSApple OSS Distributions 257*fdd8201dSApple OSS Distributions #ifndef __NET_NET_OSDEP_H_DEFINED_ 258*fdd8201dSApple OSS Distributions #define __NET_NET_OSDEP_H_DEFINED_ 259*fdd8201dSApple OSS Distributions #include <sys/appleapiopts.h> 260*fdd8201dSApple OSS Distributions #ifdef KERNEL_PRIVATE 261*fdd8201dSApple OSS Distributions 262*fdd8201dSApple OSS Distributions struct ifnet; 263*fdd8201dSApple OSS Distributions 264*fdd8201dSApple OSS Distributions #define HAVE_OLD_BPF 265*fdd8201dSApple OSS Distributions 266*fdd8201dSApple OSS Distributions #define ifa_list ifa_link 267*fdd8201dSApple OSS Distributions #define if_addrlist if_addrhead 268*fdd8201dSApple OSS Distributions #define if_list if_link 269*fdd8201dSApple OSS Distributions 270*fdd8201dSApple OSS Distributions #define WITH_CONVERT_AND_STRIP_IP_LEN 271*fdd8201dSApple OSS Distributions 272*fdd8201dSApple OSS Distributions #if 1 /* at this moment, all OSes do this */ 273*fdd8201dSApple OSS Distributions #define WITH_CONVERT_IP_OFF 274*fdd8201dSApple OSS Distributions #endif 275*fdd8201dSApple OSS Distributions 276*fdd8201dSApple OSS Distributions #endif /* KERNEL_PRIVATE */ 277*fdd8201dSApple OSS Distributions #endif /*__NET_NET_OSDEP_H_DEFINED_ */ 278