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