in.h revision 183550
1153151Sjkim/*- 2181648Sjkim * Copyright (c) 1982, 1986, 1990, 1993 3181648Sjkim * The Regents of the University of California. All rights reserved. 4153151Sjkim * 5153151Sjkim * Redistribution and use in source and binary forms, with or without 6153151Sjkim * modification, are permitted provided that the following conditions 7153151Sjkim * are met: 8153151Sjkim * 1. Redistributions of source code must retain the above copyright 9153151Sjkim * notice, this list of conditions and the following disclaimer. 10153151Sjkim * 2. Redistributions in binary form must reproduce the above copyright 11153151Sjkim * notice, this list of conditions and the following disclaimer in the 12153151Sjkim * documentation and/or other materials provided with the distribution. 13153151Sjkim * 4. Neither the name of the University nor the names of its contributors 14153151Sjkim * may be used to endorse or promote products derived from this software 15153151Sjkim * without specific prior written permission. 16153151Sjkim * 17153151Sjkim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18153151Sjkim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19153151Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20153151Sjkim * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21153151Sjkim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22153151Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23153151Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24153151Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25153151Sjkim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26153151Sjkim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27153151Sjkim * SUCH DAMAGE. 28153151Sjkim * 29153151Sjkim * @(#)in.h 8.3 (Berkeley) 1/3/94 30153151Sjkim * $FreeBSD: head/sys/netinet/in.h 183550 2008-10-02 15:37:58Z zec $ 31153151Sjkim */ 32153151Sjkim 33153151Sjkim#ifndef _NETINET_IN_H_ 34153151Sjkim#define _NETINET_IN_H_ 35153151Sjkim 36153151Sjkim#include <sys/cdefs.h> 37153151Sjkim#include <sys/_types.h> 38153151Sjkim#include <machine/endian.h> 39153151Sjkim 40153151Sjkim/* Protocols common to RFC 1700, POSIX, and X/Open. */ 41153151Sjkim#define IPPROTO_IP 0 /* dummy for IP */ 42153151Sjkim#define IPPROTO_ICMP 1 /* control message protocol */ 43153151Sjkim#define IPPROTO_TCP 6 /* tcp */ 44153151Sjkim#define IPPROTO_UDP 17 /* user datagram protocol */ 45153151Sjkim 46153151Sjkim#define INADDR_ANY (u_int32_t)0x00000000 47153151Sjkim#define INADDR_BROADCAST (u_int32_t)0xffffffff /* must be masked */ 48153151Sjkim 49153151Sjkim#ifndef _UINT8_T_DECLARED 50153151Sjkimtypedef __uint8_t uint8_t; 51153151Sjkim#define _UINT8_T_DECLARED 52153151Sjkim#endif 53153151Sjkim 54153151Sjkim#ifndef _UINT16_T_DECLARED 55153151Sjkimtypedef __uint16_t uint16_t; 56153151Sjkim#define _UINT16_T_DECLARED 57153151Sjkim#endif 58153151Sjkim 59153151Sjkim#ifndef _UINT32_T_DECLARED 60153151Sjkimtypedef __uint32_t uint32_t; 61153151Sjkim#define _UINT32_T_DECLARED 62153151Sjkim#endif 63153151Sjkim 64153151Sjkim#ifndef _IN_ADDR_T_DECLARED 65153151Sjkimtypedef uint32_t in_addr_t; 66153151Sjkim#define _IN_ADDR_T_DECLARED 67153151Sjkim#endif 68153151Sjkim 69153151Sjkim#ifndef _IN_PORT_T_DECLARED 70153151Sjkimtypedef uint16_t in_port_t; 71153151Sjkim#define _IN_PORT_T_DECLARED 72153151Sjkim#endif 73153151Sjkim 74153151Sjkim#ifndef _SA_FAMILY_T_DECLARED 75153151Sjkimtypedef __sa_family_t sa_family_t; 76153151Sjkim#define _SA_FAMILY_T_DECLARED 77153151Sjkim#endif 78153151Sjkim 79153151Sjkim/* Internet address (a structure for historical reasons). */ 80153151Sjkim#ifndef _STRUCT_IN_ADDR_DECLARED 81153151Sjkimstruct in_addr { 82153151Sjkim in_addr_t s_addr; 83153151Sjkim}; 84153151Sjkim#define _STRUCT_IN_ADDR_DECLARED 85153151Sjkim#endif 86153151Sjkim 87153151Sjkim#ifndef _SOCKLEN_T_DECLARED 88153151Sjkimtypedef __socklen_t socklen_t; 89153151Sjkim#define _SOCKLEN_T_DECLARED 90153151Sjkim#endif 91153151Sjkim 92153151Sjkim/* Avoid collision with original definition in sys/socket.h. */ 93153151Sjkim#ifndef _STRUCT_SOCKADDR_STORAGE_DECLARED 94153151Sjkim/* 95153151Sjkim * RFC 2553: protocol-independent placeholder for socket addresses 96153151Sjkim */ 97153151Sjkim#define _SS_MAXSIZE 128U 98153151Sjkim#define _SS_ALIGNSIZE (sizeof(__int64_t)) 99153151Sjkim#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(unsigned char) - \ 100153151Sjkim sizeof(sa_family_t)) 101153151Sjkim#define _SS_PAD2SIZE (_SS_MAXSIZE - sizeof(unsigned char) - \ 102153151Sjkim sizeof(sa_family_t) - _SS_PAD1SIZE - _SS_ALIGNSIZE) 103153151Sjkim 104153151Sjkimstruct sockaddr_storage { 105153151Sjkim unsigned char ss_len; /* address length */ 106153995Sjkim sa_family_t ss_family; /* address family */ 107153995Sjkim char __ss_pad1[_SS_PAD1SIZE]; 108181648Sjkim __int64_t __ss_align; /* force desired struct alignment */ 109153995Sjkim char __ss_pad2[_SS_PAD2SIZE]; 110153151Sjkim}; 111153151Sjkim#define _STRUCT_SOCKADDR_STORAGE_DECLARED 112153157Sjkim#endif 113153151Sjkim 114181648Sjkim/* Socket address, internet style. */ 115153151Sjkimstruct sockaddr_in { 116153151Sjkim uint8_t sin_len; 117153151Sjkim sa_family_t sin_family; 118153151Sjkim in_port_t sin_port; 119153151Sjkim struct in_addr sin_addr; 120153151Sjkim char sin_zero[8]; 121153151Sjkim}; 122153151Sjkim 123153151Sjkim#ifndef _KERNEL 124153151Sjkim 125153151Sjkim#ifndef _BYTEORDER_PROTOTYPED 126153151Sjkim#define _BYTEORDER_PROTOTYPED 127153151Sjkim__BEGIN_DECLS 128153151Sjkimuint32_t htonl(uint32_t); 129153151Sjkimuint16_t htons(uint16_t); 130153151Sjkimuint32_t ntohl(uint32_t); 131153151Sjkimuint16_t ntohs(uint16_t); 132153151Sjkim__END_DECLS 133153151Sjkim#endif 134153151Sjkim 135179968Sjkim#ifndef _BYTEORDER_FUNC_DEFINED 136153151Sjkim#define _BYTEORDER_FUNC_DEFINED 137153151Sjkim#define htonl(x) __htonl(x) 138153151Sjkim#define htons(x) __htons(x) 139179968Sjkim#define ntohl(x) __ntohl(x) 140181645Sjkim#define ntohs(x) __ntohs(x) 141153151Sjkim#endif 142153151Sjkim 143153151Sjkim#endif /* !_KERNEL */ 144153151Sjkim 145153151Sjkim#if __POSIX_VISIBLE >= 200112 146153151Sjkim#define IPPROTO_RAW 255 /* raw IP packet */ 147181648Sjkim#define INET_ADDRSTRLEN 16 148153151Sjkim#endif 149153151Sjkim 150179968Sjkim#if __BSD_VISIBLE 151153151Sjkim/* 152153151Sjkim * Constants and structures defined by the internet system, 153153151Sjkim * Per RFC 790, September 1981, and numerous additions. 154153151Sjkim */ 155153151Sjkim 156153151Sjkim/* 157153151Sjkim * Protocols (RFC 1700) 158153151Sjkim */ 159153151Sjkim#define IPPROTO_HOPOPTS 0 /* IP6 hop-by-hop options */ 160153151Sjkim#define IPPROTO_IGMP 2 /* group mgmt protocol */ 161153151Sjkim#define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ 162153151Sjkim#define IPPROTO_IPV4 4 /* IPv4 encapsulation */ 163153151Sjkim#define IPPROTO_IPIP IPPROTO_IPV4 /* for compatibility */ 164153151Sjkim#define IPPROTO_ST 7 /* Stream protocol II */ 165179968Sjkim#define IPPROTO_EGP 8 /* exterior gateway protocol */ 166179968Sjkim#define IPPROTO_PIGP 9 /* private interior gateway */ 167179968Sjkim#define IPPROTO_RCCMON 10 /* BBN RCC Monitoring */ 168181645Sjkim#define IPPROTO_NVPII 11 /* network voice protocol*/ 169181697Sjkim#define IPPROTO_PUP 12 /* pup */ 170179978Sjkim#define IPPROTO_ARGUS 13 /* Argus */ 171153151Sjkim#define IPPROTO_EMCON 14 /* EMCON */ 172153151Sjkim#define IPPROTO_XNET 15 /* Cross Net Debugger */ 173153151Sjkim#define IPPROTO_CHAOS 16 /* Chaos*/ 174153151Sjkim#define IPPROTO_MUX 18 /* Multiplexing */ 175179968Sjkim#define IPPROTO_MEAS 19 /* DCN Measurement Subsystems */ 176153151Sjkim#define IPPROTO_HMP 20 /* Host Monitoring */ 177153151Sjkim#define IPPROTO_PRM 21 /* Packet Radio Measurement */ 178153151Sjkim#define IPPROTO_IDP 22 /* xns idp */ 179153151Sjkim#define IPPROTO_TRUNK1 23 /* Trunk-1 */ 180179978Sjkim#define IPPROTO_TRUNK2 24 /* Trunk-2 */ 181179968Sjkim#define IPPROTO_LEAF1 25 /* Leaf-1 */ 182179968Sjkim#define IPPROTO_LEAF2 26 /* Leaf-2 */ 183179968Sjkim#define IPPROTO_RDP 27 /* Reliable Data */ 184181645Sjkim#define IPPROTO_IRTP 28 /* Reliable Transaction */ 185181697Sjkim#define IPPROTO_TP 29 /* tp-4 w/ class negotiation */ 186153151Sjkim#define IPPROTO_BLT 30 /* Bulk Data Transfer */ 187153151Sjkim#define IPPROTO_NSP 31 /* Network Services */ 188153151Sjkim#define IPPROTO_INP 32 /* Merit Internodal */ 189153151Sjkim#define IPPROTO_SEP 33 /* Sequential Exchange */ 190179968Sjkim#define IPPROTO_3PC 34 /* Third Party Connect */ 191153151Sjkim#define IPPROTO_IDPR 35 /* InterDomain Policy Routing */ 192153151Sjkim#define IPPROTO_XTP 36 /* XTP */ 193153151Sjkim#define IPPROTO_DDP 37 /* Datagram Delivery */ 194153151Sjkim#define IPPROTO_CMTP 38 /* Control Message Transport */ 195179978Sjkim#define IPPROTO_TPXX 39 /* TP++ Transport */ 196179968Sjkim#define IPPROTO_IL 40 /* IL transport protocol */ 197181645Sjkim#define IPPROTO_IPV6 41 /* IP6 header */ 198181697Sjkim#define IPPROTO_SDRP 42 /* Source Demand Routing */ 199153151Sjkim#define IPPROTO_ROUTING 43 /* IP6 routing header */ 200153151Sjkim#define IPPROTO_FRAGMENT 44 /* IP6 fragmentation header */ 201153151Sjkim#define IPPROTO_IDRP 45 /* InterDomain Routing*/ 202153151Sjkim#define IPPROTO_RSVP 46 /* resource reservation */ 203179968Sjkim#define IPPROTO_GRE 47 /* General Routing Encap. */ 204153151Sjkim#define IPPROTO_MHRP 48 /* Mobile Host Routing */ 205153151Sjkim#define IPPROTO_BHA 49 /* BHA */ 206153151Sjkim#define IPPROTO_ESP 50 /* IP6 Encap Sec. Payload */ 207181648Sjkim#define IPPROTO_AH 51 /* IP6 Auth Header */ 208153151Sjkim#define IPPROTO_INLSP 52 /* Integ. Net Layer Security */ 209153151Sjkim#define IPPROTO_SWIPE 53 /* IP with encryption */ 210153151Sjkim#define IPPROTO_NHRP 54 /* Next Hop Resolution */ 211181648Sjkim#define IPPROTO_MOBILE 55 /* IP Mobility */ 212153151Sjkim#define IPPROTO_TLSP 56 /* Transport Layer Security */ 213153151Sjkim#define IPPROTO_SKIP 57 /* SKIP */ 214153151Sjkim#define IPPROTO_ICMPV6 58 /* ICMP6 */ 215179968Sjkim#define IPPROTO_NONE 59 /* IP6 no next header */ 216179968Sjkim#define IPPROTO_DSTOPTS 60 /* IP6 destination option */ 217179968Sjkim#define IPPROTO_AHIP 61 /* any host internal protocol */ 218179968Sjkim#define IPPROTO_CFTP 62 /* CFTP */ 219181645Sjkim#define IPPROTO_HELLO 63 /* "hello" routing protocol */ 220181697Sjkim#define IPPROTO_SATEXPAK 64 /* SATNET/Backroom EXPAK */ 221179978Sjkim#define IPPROTO_KRYPTOLAN 65 /* Kryptolan */ 222153151Sjkim#define IPPROTO_RVD 66 /* Remote Virtual Disk */ 223153151Sjkim#define IPPROTO_IPPC 67 /* Pluribus Packet Core */ 224153151Sjkim#define IPPROTO_ADFS 68 /* Any distributed FS */ 225153151Sjkim#define IPPROTO_SATMON 69 /* Satnet Monitoring */ 226179968Sjkim#define IPPROTO_VISA 70 /* VISA Protocol */ 227153151Sjkim#define IPPROTO_IPCV 71 /* Packet Core Utility */ 228153151Sjkim#define IPPROTO_CPNX 72 /* Comp. Prot. Net. Executive */ 229153151Sjkim#define IPPROTO_CPHB 73 /* Comp. Prot. HeartBeat */ 230153151Sjkim#define IPPROTO_WSN 74 /* Wang Span Network */ 231179978Sjkim#define IPPROTO_PVP 75 /* Packet Video Protocol */ 232179968Sjkim#define IPPROTO_BRSATMON 76 /* BackRoom SATNET Monitoring */ 233179968Sjkim#define IPPROTO_ND 77 /* Sun net disk proto (temp.) */ 234179968Sjkim#define IPPROTO_WBMON 78 /* WIDEBAND Monitoring */ 235179968Sjkim#define IPPROTO_WBEXPAK 79 /* WIDEBAND EXPAK */ 236181645Sjkim#define IPPROTO_EON 80 /* ISO cnlp */ 237181697Sjkim#define IPPROTO_VMTP 81 /* VMTP */ 238153151Sjkim#define IPPROTO_SVMTP 82 /* Secure VMTP */ 239153151Sjkim#define IPPROTO_VINES 83 /* Banyon VINES */ 240153151Sjkim#define IPPROTO_TTP 84 /* TTP */ 241153151Sjkim#define IPPROTO_IGP 85 /* NSFNET-IGP */ 242179968Sjkim#define IPPROTO_DGP 86 /* dissimilar gateway prot. */ 243153151Sjkim#define IPPROTO_TCF 87 /* TCF */ 244153151Sjkim#define IPPROTO_IGRP 88 /* Cisco/GXS IGRP */ 245153151Sjkim#define IPPROTO_OSPFIGP 89 /* OSPFIGP */ 246153151Sjkim#define IPPROTO_SRPC 90 /* Strite RPC protocol */ 247179978Sjkim#define IPPROTO_LARP 91 /* Locus Address Resoloution */ 248179968Sjkim#define IPPROTO_MTP 92 /* Multicast Transport */ 249179968Sjkim#define IPPROTO_AX25 93 /* AX.25 Frames */ 250181645Sjkim#define IPPROTO_IPEIP 94 /* IP encapsulated in IP */ 251181697Sjkim#define IPPROTO_MICP 95 /* Mobile Int.ing control */ 252153151Sjkim#define IPPROTO_SCCSP 96 /* Semaphore Comm. security */ 253153151Sjkim#define IPPROTO_ETHERIP 97 /* Ethernet IP encapsulation */ 254153151Sjkim#define IPPROTO_ENCAP 98 /* encapsulation header */ 255153151Sjkim#define IPPROTO_APES 99 /* any private encr. scheme */ 256179968Sjkim#define IPPROTO_GMTP 100 /* GMTP*/ 257153151Sjkim#define IPPROTO_IPCOMP 108 /* payload compression (IPComp) */ 258153151Sjkim#define IPPROTO_SCTP 132 /* SCTP */ 259153151Sjkim/* 101-254: Partly Unassigned */ 260179968Sjkim#define IPPROTO_PIM 103 /* Protocol Independent Mcast */ 261181645Sjkim#define IPPROTO_CARP 112 /* CARP */ 262181697Sjkim#define IPPROTO_PGM 113 /* PGM */ 263179978Sjkim#define IPPROTO_PFSYNC 240 /* PFSYNC */ 264153151Sjkim/* 255: Reserved */ 265153151Sjkim/* BSD Private, local use, namespace incursion, no longer used */ 266153151Sjkim#define IPPROTO_OLD_DIVERT 254 /* OLD divert pseudo-proto */ 267153151Sjkim#define IPPROTO_MAX 256 268179978Sjkim 269179968Sjkim/* last return value of *_input(), meaning "all job for this pkt is done". */ 270181648Sjkim#define IPPROTO_DONE 257 271179968Sjkim 272153151Sjkim/* Only used internally, so can be outside the range of valid IP protocols. */ 273153151Sjkim#define IPPROTO_DIVERT 258 /* divert pseudo-protocol */ 274153151Sjkim 275179968Sjkim/* 276153151Sjkim * Defined to avoid confusion. The master value is defined by 277153151Sjkim * PROTO_SPACER in sys/protosw.h. 278153151Sjkim */ 279179968Sjkim#define IPPROTO_SPACER 32767 /* spacer for loadable protos */ 280153151Sjkim 281153151Sjkim/* 282153151Sjkim * Local port number conventions: 283179968Sjkim * 284179968Sjkim * When a user does a bind(2) or connect(2) with a port number of zero, 285179968Sjkim * a non-conflicting local port address is chosen. 286153151Sjkim * The default range is IPPORT_HIFIRSTAUTO through 287153151Sjkim * IPPORT_HILASTAUTO, although that is settable by sysctl. 288153151Sjkim * 289179968Sjkim * A user may set the IPPROTO_IP option IP_PORTRANGE to change this 290179968Sjkim * default assignment range. 291179968Sjkim * 292153151Sjkim * The value IP_PORTRANGE_DEFAULT causes the default behavior. 293153151Sjkim * 294153151Sjkim * The value IP_PORTRANGE_HIGH changes the range of candidate port numbers 295153151Sjkim * into the "high" range. These are reserved for client outbound connections 296153151Sjkim * which do not want to be filtered by any firewalls. 297153151Sjkim * 298153151Sjkim * The value IP_PORTRANGE_LOW changes the range to the "low" are 299153151Sjkim * that is (by convention) restricted to privileged processes. This 300179968Sjkim * convention is based on "vouchsafe" principles only. It is only secure 301179968Sjkim * if you trust the remote host to restrict these ports. 302179968Sjkim * 303153151Sjkim * The default range of ports and the high range can be changed by 304153151Sjkim * sysctl(3). (net.inet.ip.port{hi,low}{first,last}_auto) 305153151Sjkim * 306179968Sjkim * Changing those values has bad security implications if you are 307179968Sjkim * using a stateless firewall that is allowing packets outside of that 308179968Sjkim * range in order to allow transparent outgoing connections. 309153151Sjkim * 310153151Sjkim * Such a firewall configuration will generally depend on the use of these 311153151Sjkim * default values. If you change them, you may find your Security 312153151Sjkim * Administrator looking for you with a heavy object. 313153151Sjkim * 314153151Sjkim * For a slightly more orthodox text view on this: 315153151Sjkim * 316153151Sjkim * ftp://ftp.isi.edu/in-notes/iana/assignments/port-numbers 317181697Sjkim * 318181697Sjkim * port numbers are divided into three ranges: 319179968Sjkim * 320181697Sjkim * 0 - 1023 Well Known Ports 321153151Sjkim * 1024 - 49151 Registered Ports 322153151Sjkim * 49152 - 65535 Dynamic and/or Private Ports 323153151Sjkim * 324181697Sjkim */ 325181697Sjkim 326179968Sjkim/* 327181697Sjkim * Ports < IPPORT_RESERVED are reserved for 328153151Sjkim * privileged processes (e.g. root). (IP_PORTRANGE_LOW) 329153151Sjkim */ 330153151Sjkim#define IPPORT_RESERVED 1024 331181697Sjkim 332181697Sjkim/* 333179968Sjkim * Default local port range, used by IP_PORTRANGE_DEFAULT 334181697Sjkim */ 335153151Sjkim#define IPPORT_EPHEMERALFIRST 10000 336153151Sjkim#define IPPORT_EPHEMERALLAST 65535 337153151Sjkim 338181697Sjkim/* 339181697Sjkim * Dynamic port range, used by IP_PORTRANGE_HIGH. 340181697Sjkim */ 341181697Sjkim#define IPPORT_HIFIRSTAUTO 49152 342153151Sjkim#define IPPORT_HILASTAUTO 65535 343153151Sjkim 344153151Sjkim/* 345181697Sjkim * Scanning for a free reserved port return a value below IPPORT_RESERVED, 346181697Sjkim * but higher than IPPORT_RESERVEDSTART. Traditionally the start value was 347179968Sjkim * 512, but that conflicts with some well-known-services that firewalls may 348181697Sjkim * have a fit if we use. 349153151Sjkim */ 350153151Sjkim#define IPPORT_RESERVEDSTART 600 351153151Sjkim 352181697Sjkim#define IPPORT_MAX 65535 353181697Sjkim 354179968Sjkim/* 355181697Sjkim * Definitions of bits in internet address integers. 356153151Sjkim * On subnets, the decomposition of addresses to host and net parts 357153151Sjkim * is done according to subnet mask, not the masks here. 358153151Sjkim */ 359181697Sjkim#define IN_CLASSA(i) (((u_int32_t)(i) & 0x80000000) == 0) 360181697Sjkim#define IN_CLASSA_NET 0xff000000 361179968Sjkim#define IN_CLASSA_NSHIFT 24 362181697Sjkim#define IN_CLASSA_HOST 0x00ffffff 363153151Sjkim#define IN_CLASSA_MAX 128 364153151Sjkim 365153151Sjkim#define IN_CLASSB(i) (((u_int32_t)(i) & 0xc0000000) == 0x80000000) 366181697Sjkim#define IN_CLASSB_NET 0xffff0000 367181697Sjkim#define IN_CLASSB_NSHIFT 16 368181697Sjkim#define IN_CLASSB_HOST 0x0000ffff 369181697Sjkim#define IN_CLASSB_MAX 65536 370153151Sjkim 371153151Sjkim#define IN_CLASSC(i) (((u_int32_t)(i) & 0xe0000000) == 0xc0000000) 372153151Sjkim#define IN_CLASSC_NET 0xffffff00 373179968Sjkim#define IN_CLASSC_NSHIFT 8 374153151Sjkim#define IN_CLASSC_HOST 0x000000ff 375153151Sjkim 376153151Sjkim#define IN_CLASSD(i) (((u_int32_t)(i) & 0xf0000000) == 0xe0000000) 377179968Sjkim#define IN_CLASSD_NET 0xf0000000 /* These ones aren't really */ 378153151Sjkim#define IN_CLASSD_NSHIFT 28 /* net and host fields, but */ 379153151Sjkim#define IN_CLASSD_HOST 0x0fffffff /* routing needn't know. */ 380153151Sjkim#define IN_MULTICAST(i) IN_CLASSD(i) 381179968Sjkim 382179968Sjkim#define IN_EXPERIMENTAL(i) (((u_int32_t)(i) & 0xf0000000) == 0xf0000000) 383153151Sjkim#define IN_BADCLASS(i) (((u_int32_t)(i) & 0xf0000000) == 0xf0000000) 384153151Sjkim 385153151Sjkim#define IN_LINKLOCAL(i) (((u_int32_t)(i) & 0xffff0000) == 0xa9fe0000) 386153151Sjkim#define IN_LOOPBACK(i) (((u_int32_t)(i) & 0xff000000) == 0x7f000000) 387181697Sjkim#define IN_ZERONET(i) (((u_int32_t)(i) & 0xff000000) == 0) 388153151Sjkim 389179978Sjkim#define IN_PRIVATE(i) ((((u_int32_t)(i) & 0xff000000) == 0x0a000000) || \ 390153151Sjkim (((u_int32_t)(i) & 0xfff00000) == 0xac100000) || \ 391153151Sjkim (((u_int32_t)(i) & 0xffff0000) == 0xc0a80000)) 392153151Sjkim 393153151Sjkim#define IN_LOCAL_GROUP(i) (((u_int32_t)(i) & 0xffffff00) == 0xe0000000) 394179968Sjkim 395179978Sjkim#define IN_ANY_LOCAL(i) (IN_LINKLOCAL(i) || IN_LOCAL_GROUP(i)) 396153151Sjkim 397179968Sjkim#define INADDR_LOOPBACK (u_int32_t)0x7f000001 398153151Sjkim#ifndef _KERNEL 399153151Sjkim#define INADDR_NONE 0xffffffff /* -1 return */ 400153151Sjkim#endif 401179968Sjkim 402153151Sjkim#define INADDR_UNSPEC_GROUP (u_int32_t)0xe0000000 /* 224.0.0.0 */ 403153151Sjkim#define INADDR_ALLHOSTS_GROUP (u_int32_t)0xe0000001 /* 224.0.0.1 */ 404153151Sjkim#define INADDR_ALLRTRS_GROUP (u_int32_t)0xe0000002 /* 224.0.0.2 */ 405179968Sjkim#define INADDR_ALLRPTS_GROUP (u_int32_t)0xe0000016 /* 224.0.0.22, IGMPv3 */ 406153151Sjkim#define INADDR_CARP_GROUP (u_int32_t)0xe0000012 /* 224.0.0.18 */ 407153151Sjkim#define INADDR_PFSYNC_GROUP (u_int32_t)0xe00000f0 /* 224.0.0.240 */ 408153151Sjkim#define INADDR_ALLMDNS_GROUP (u_int32_t)0xe00000fb /* 224.0.0.251 */ 409179968Sjkim#define INADDR_MAX_LOCAL_GROUP (u_int32_t)0xe00000ff /* 224.0.0.255 */ 410153151Sjkim 411153151Sjkim#define IN_LOOPBACKNET 127 /* official! */ 412153151Sjkim 413153151Sjkim/* 414179968Sjkim * Options for use with [gs]etsockopt at the IP level. 415153151Sjkim * First word of comment is data type; bool is stored in int. 416153151Sjkim */ 417153151Sjkim#define IP_OPTIONS 1 /* buf/ip_opts; set/get IP options */ 418153151Sjkim#define IP_HDRINCL 2 /* int; header is included with data */ 419153151Sjkim#define IP_TOS 3 /* int; IP type of service and preced. */ 420153151Sjkim#define IP_TTL 4 /* int; IP time to live */ 421153151Sjkim#define IP_RECVOPTS 5 /* bool; receive all IP opts w/dgram */ 422153151Sjkim#define IP_RECVRETOPTS 6 /* bool; receive IP opts for response */ 423153151Sjkim#define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/dgram */ 424153151Sjkim#define IP_SENDSRCADDR IP_RECVDSTADDR /* cmsg_type to set src addr */ 425153151Sjkim#define IP_RETOPTS 8 /* ip_opts; set/get IP options */ 426153151Sjkim#define IP_MULTICAST_IF 9 /* struct in_addr *or* struct ip_mreqn; 427179968Sjkim * set/get IP multicast i/f */ 428179968Sjkim#define IP_MULTICAST_TTL 10 /* u_char; set/get IP multicast ttl */ 429179968Sjkim#define IP_MULTICAST_LOOP 11 /* u_char; set/get IP multicast loopback */ 430153151Sjkim#define IP_ADD_MEMBERSHIP 12 /* ip_mreq; add an IP group membership */ 431153151Sjkim#define IP_DROP_MEMBERSHIP 13 /* ip_mreq; drop an IP group membership */ 432153151Sjkim#define IP_MULTICAST_VIF 14 /* set/get IP mcast virt. iface */ 433153151Sjkim#define IP_RSVP_ON 15 /* enable RSVP in kernel */ 434179968Sjkim#define IP_RSVP_OFF 16 /* disable RSVP in kernel */ 435179978Sjkim#define IP_RSVP_VIF_ON 17 /* set RSVP per-vif socket */ 436179968Sjkim#define IP_RSVP_VIF_OFF 18 /* unset RSVP per-vif socket */ 437153151Sjkim#define IP_PORTRANGE 19 /* int; range to choose for unspec port */ 438179968Sjkim#define IP_RECVIF 20 /* bool; receive reception if w/dgram */ 439153151Sjkim/* for IPSEC */ 440153151Sjkim#define IP_IPSEC_POLICY 21 /* int; set/get security policy */ 441153151Sjkim#define IP_FAITH 22 /* bool; accept FAITH'ed connections */ 442179968Sjkim 443153151Sjkim#define IP_ONESBCAST 23 /* bool: send all-ones broadcast */ 444153151Sjkim 445153151Sjkim#define IP_FW_TABLE_ADD 40 /* add entry */ 446179968Sjkim#define IP_FW_TABLE_DEL 41 /* delete entry */ 447153151Sjkim#define IP_FW_TABLE_FLUSH 42 /* flush table */ 448153151Sjkim#define IP_FW_TABLE_GETSIZE 43 /* get table size */ 449153151Sjkim#define IP_FW_TABLE_LIST 44 /* list table contents */ 450179968Sjkim 451153151Sjkim#define IP_FW_ADD 50 /* add a firewall rule to chain */ 452153151Sjkim#define IP_FW_DEL 51 /* delete a firewall rule from chain */ 453153151Sjkim#define IP_FW_FLUSH 52 /* flush firewall rule chain */ 454179968Sjkim#define IP_FW_ZERO 53 /* clear single/all firewall counter(s) */ 455153151Sjkim#define IP_FW_GET 54 /* get entire firewall rule chain */ 456153151Sjkim#define IP_FW_RESETLOG 55 /* reset logging counters */ 457153151Sjkim 458153151Sjkim#define IP_FW_NAT_CFG 56 /* add/config a nat rule */ 459153151Sjkim#define IP_FW_NAT_DEL 57 /* delete a nat rule */ 460153151Sjkim#define IP_FW_NAT_GET_CONFIG 58 /* get configuration of a nat rule */ 461153151Sjkim#define IP_FW_NAT_GET_LOG 59 /* get log of a nat rule */ 462179968Sjkim 463153151Sjkim#define IP_DUMMYNET_CONFIGURE 60 /* add/configure a dummynet pipe */ 464153151Sjkim#define IP_DUMMYNET_DEL 61 /* delete a dummynet pipe from chain */ 465153151Sjkim#define IP_DUMMYNET_FLUSH 62 /* flush dummynet */ 466179968Sjkim#define IP_DUMMYNET_GET 64 /* get entire dummynet pipes */ 467153151Sjkim 468153151Sjkim#define IP_RECVTTL 65 /* bool; receive IP TTL w/dgram */ 469153151Sjkim#define IP_MINTTL 66 /* minimum TTL for packet or drop */ 470153151Sjkim#define IP_DONTFRAG 67 /* don't fragment packet */ 471153151Sjkim 472153151Sjkim/* IPv4 Source Filter Multicast API [RFC3678] */ 473153151Sjkim#define IP_ADD_SOURCE_MEMBERSHIP 70 /* join a source-specific group */ 474153151Sjkim#define IP_DROP_SOURCE_MEMBERSHIP 71 /* drop a single source */ 475153151Sjkim#define IP_BLOCK_SOURCE 72 /* block a source */ 476153157Sjkim#define IP_UNBLOCK_SOURCE 73 /* unblock a source */ 477153151Sjkim 478153151Sjkim/* The following option is private; do not use it from user applications. */ 479181648Sjkim#define IP_MSFILTER 74 /* set/get filter list */ 480153151Sjkim 481153151Sjkim/* Protocol Independent Multicast API [RFC3678] */ 482153151Sjkim#define MCAST_JOIN_GROUP 80 /* join an any-source group */ 483153151Sjkim#define MCAST_LEAVE_GROUP 81 /* leave all sources for group */ 484153151Sjkim#define MCAST_JOIN_SOURCE_GROUP 82 /* join a source-specific group */ 485153151Sjkim#define MCAST_LEAVE_SOURCE_GROUP 83 /* leave a single source */ 486153151Sjkim#define MCAST_BLOCK_SOURCE 84 /* block a source */ 487153151Sjkim#define MCAST_UNBLOCK_SOURCE 85 /* unblock a source */ 488153151Sjkim 489153151Sjkim/* 490153151Sjkim * Defaults and limits for options 491153151Sjkim */ 492153151Sjkim#define IP_DEFAULT_MULTICAST_TTL 1 /* normally limit m'casts to 1 hop */ 493153151Sjkim#define IP_DEFAULT_MULTICAST_LOOP 1 /* normally hear sends if a member */ 494153151Sjkim 495153151Sjkim/* 496153151Sjkim * The imo_membership vector for each socket is now dynamically allocated at 497153151Sjkim * run-time, bounded by USHRT_MAX, and is reallocated when needed, sized 498153151Sjkim * according to a power-of-two increment. 499153151Sjkim */ 500153151Sjkim#define IP_MIN_MEMBERSHIPS 31 501153151Sjkim#define IP_MAX_MEMBERSHIPS 4095 502153151Sjkim#define IP_MAX_SOURCE_FILTER 1024 /* # of filters per socket, per group */ 503181648Sjkim 504153151Sjkim/* 505 * Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP. 506 */ 507struct ip_mreq { 508 struct in_addr imr_multiaddr; /* IP multicast address of group */ 509 struct in_addr imr_interface; /* local IP address of interface */ 510}; 511 512/* 513 * Modified argument structure for IP_MULTICAST_IF, obtained from Linux. 514 * This is used to specify an interface index for multicast sends, as 515 * the IPv4 legacy APIs do not support this (unless IP_SENDIF is available). 516 */ 517struct ip_mreqn { 518 struct in_addr imr_multiaddr; /* IP multicast address of group */ 519 struct in_addr imr_address; /* local IP address of interface */ 520 int imr_ifindex; /* Interface index; cast to uint32_t */ 521}; 522 523/* 524 * Argument structure for IPv4 Multicast Source Filter APIs. [RFC3678] 525 */ 526struct ip_mreq_source { 527 struct in_addr imr_multiaddr; /* IP multicast address of group */ 528 struct in_addr imr_sourceaddr; /* IP address of source */ 529 struct in_addr imr_interface; /* local IP address of interface */ 530}; 531 532/* 533 * Argument structures for Protocol-Independent Multicast Source 534 * Filter APIs. [RFC3678] 535 */ 536struct group_req { 537 uint32_t gr_interface; /* interface index */ 538 struct sockaddr_storage gr_group; /* group address */ 539}; 540 541struct group_source_req { 542 uint32_t gsr_interface; /* interface index */ 543 struct sockaddr_storage gsr_group; /* group address */ 544 struct sockaddr_storage gsr_source; /* source address */ 545}; 546 547#ifndef __MSFILTERREQ_DEFINED 548#define __MSFILTERREQ_DEFINED 549/* 550 * The following structure is private; do not use it from user applications. 551 * It is used to communicate IP_MSFILTER/IPV6_MSFILTER information between 552 * the RFC 3678 libc functions and the kernel. 553 */ 554struct __msfilterreq { 555 uint32_t msfr_ifindex; /* interface index */ 556 uint32_t msfr_fmode; /* filter mode for group */ 557 uint32_t msfr_nsrcs; /* # of sources in msfr_srcs */ 558 struct sockaddr_storage msfr_group; /* group address */ 559 struct sockaddr_storage *msfr_srcs; /* pointer to the first member 560 * of a contiguous array of 561 * sources to filter in full. 562 */ 563}; 564#endif 565 566struct sockaddr; 567 568/* 569 * Advanced (Full-state) APIs [RFC3678] 570 * The RFC specifies uint_t for the 6th argument to [sg]etsourcefilter(). 571 * We use uint32_t here to be consistent. 572 */ 573int setipv4sourcefilter(int, struct in_addr, struct in_addr, uint32_t, 574 uint32_t, struct in_addr *); 575int getipv4sourcefilter(int, struct in_addr, struct in_addr, uint32_t *, 576 uint32_t *, struct in_addr *); 577int setsourcefilter(int, uint32_t, struct sockaddr *, socklen_t, 578 uint32_t, uint32_t, struct sockaddr_storage *); 579int getsourcefilter(int, uint32_t, struct sockaddr *, socklen_t, 580 uint32_t *, uint32_t *, struct sockaddr_storage *); 581 582/* 583 * Filter modes; also used to represent per-socket filter mode internally. 584 */ 585#define MCAST_INCLUDE 1 /* fmode: include these source(s) */ 586#define MCAST_EXCLUDE 2 /* fmode: exclude these source(s) */ 587 588/* 589 * Argument for IP_PORTRANGE: 590 * - which range to search when port is unspecified at bind() or connect() 591 */ 592#define IP_PORTRANGE_DEFAULT 0 /* default range */ 593#define IP_PORTRANGE_HIGH 1 /* "high" - request firewall bypass */ 594#define IP_PORTRANGE_LOW 2 /* "low" - vouchsafe security */ 595 596/* 597 * Definitions for inet sysctl operations. 598 * 599 * Third level is protocol number. 600 * Fourth level is desired variable within that protocol. 601 */ 602#define IPPROTO_MAXID (IPPROTO_AH + 1) /* don't list to IPPROTO_MAX */ 603 604#define CTL_IPPROTO_NAMES { \ 605 { "ip", CTLTYPE_NODE }, \ 606 { "icmp", CTLTYPE_NODE }, \ 607 { "igmp", CTLTYPE_NODE }, \ 608 { "ggp", CTLTYPE_NODE }, \ 609 { 0, 0 }, \ 610 { 0, 0 }, \ 611 { "tcp", CTLTYPE_NODE }, \ 612 { 0, 0 }, \ 613 { "egp", CTLTYPE_NODE }, \ 614 { 0, 0 }, \ 615 { 0, 0 }, \ 616 { 0, 0 }, \ 617 { "pup", CTLTYPE_NODE }, \ 618 { 0, 0 }, \ 619 { 0, 0 }, \ 620 { 0, 0 }, \ 621 { 0, 0 }, \ 622 { "udp", CTLTYPE_NODE }, \ 623 { 0, 0 }, \ 624 { 0, 0 }, \ 625 { 0, 0 }, \ 626 { 0, 0 }, \ 627 { "idp", CTLTYPE_NODE }, \ 628 { 0, 0 }, \ 629 { 0, 0 }, \ 630 { 0, 0 }, \ 631 { 0, 0 }, \ 632 { 0, 0 }, \ 633 { 0, 0 }, \ 634 { 0, 0 }, \ 635 { 0, 0 }, \ 636 { 0, 0 }, \ 637 { 0, 0 }, \ 638 { 0, 0 }, \ 639 { 0, 0 }, \ 640 { 0, 0 }, \ 641 { 0, 0 }, \ 642 { 0, 0 }, \ 643 { 0, 0 }, \ 644 { 0, 0 }, \ 645 { 0, 0 }, \ 646 { 0, 0 }, \ 647 { 0, 0 }, \ 648 { 0, 0 }, \ 649 { 0, 0 }, \ 650 { 0, 0 }, \ 651 { 0, 0 }, \ 652 { 0, 0 }, \ 653 { 0, 0 }, \ 654 { 0, 0 }, \ 655 { 0, 0 }, \ 656 { "ipsec", CTLTYPE_NODE }, \ 657 { 0, 0 }, \ 658 { 0, 0 }, \ 659 { 0, 0 }, \ 660 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 661 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 662 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 663 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 664 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 665 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 666 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 667 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 668 { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, \ 669 { 0, 0 }, \ 670 { 0, 0 }, \ 671 { 0, 0 }, \ 672 { "pim", CTLTYPE_NODE }, \ 673} 674 675/* 676 * Names for IP sysctl objects 677 */ 678#define IPCTL_FORWARDING 1 /* act as router */ 679#define IPCTL_SENDREDIRECTS 2 /* may send redirects when forwarding */ 680#define IPCTL_DEFTTL 3 /* default TTL */ 681#ifdef notyet 682#define IPCTL_DEFMTU 4 /* default MTU */ 683#endif 684#define IPCTL_RTEXPIRE 5 /* cloned route expiration time */ 685#define IPCTL_RTMINEXPIRE 6 /* min value for expiration time */ 686#define IPCTL_RTMAXCACHE 7 /* trigger level for dynamic expire */ 687#define IPCTL_SOURCEROUTE 8 /* may perform source routes */ 688#define IPCTL_DIRECTEDBROADCAST 9 /* may re-broadcast received packets */ 689#define IPCTL_INTRQMAXLEN 10 /* max length of netisr queue */ 690#define IPCTL_INTRQDROPS 11 /* number of netisr q drops */ 691#define IPCTL_STATS 12 /* ipstat structure */ 692#define IPCTL_ACCEPTSOURCEROUTE 13 /* may accept source routed packets */ 693#define IPCTL_FASTFORWARDING 14 /* use fast IP forwarding code */ 694#define IPCTL_KEEPFAITH 15 /* FAITH IPv4->IPv6 translater ctl */ 695#define IPCTL_GIF_TTL 16 /* default TTL for gif encap packet */ 696#define IPCTL_MAXID 17 697 698#define IPCTL_NAMES { \ 699 { 0, 0 }, \ 700 { "forwarding", CTLTYPE_INT }, \ 701 { "redirect", CTLTYPE_INT }, \ 702 { "ttl", CTLTYPE_INT }, \ 703 { "mtu", CTLTYPE_INT }, \ 704 { "rtexpire", CTLTYPE_INT }, \ 705 { "rtminexpire", CTLTYPE_INT }, \ 706 { "rtmaxcache", CTLTYPE_INT }, \ 707 { "sourceroute", CTLTYPE_INT }, \ 708 { "directed-broadcast", CTLTYPE_INT }, \ 709 { "intr-queue-maxlen", CTLTYPE_INT }, \ 710 { "intr-queue-drops", CTLTYPE_INT }, \ 711 { "stats", CTLTYPE_STRUCT }, \ 712 { "accept_sourceroute", CTLTYPE_INT }, \ 713 { "fastforwarding", CTLTYPE_INT }, \ 714} 715 716#endif /* __BSD_VISIBLE */ 717 718#ifdef _KERNEL 719 720struct ifnet; struct mbuf; /* forward declarations for Standard C */ 721 722int in_broadcast(struct in_addr, struct ifnet *); 723int in_canforward(struct in_addr); 724int in_localaddr(struct in_addr); 725int in_localip(struct in_addr); 726char *inet_ntoa(struct in_addr); /* in libkern */ 727char *inet_ntoa_r(struct in_addr ina, char *buf); /* in libkern */ 728void in_ifdetach(struct ifnet *); 729 730#define in_hosteq(s, t) ((s).s_addr == (t).s_addr) 731#define in_nullhost(x) ((x).s_addr == INADDR_ANY) 732 733#define satosin(sa) ((struct sockaddr_in *)(sa)) 734#define sintosa(sin) ((struct sockaddr *)(sin)) 735#define ifatoia(ifa) ((struct in_ifaddr *)(ifa)) 736 737#endif /* _KERNEL */ 738 739/* INET6 stuff */ 740#if __POSIX_VISIBLE >= 200112 741#define __KAME_NETINET_IN_H_INCLUDED_ 742#include <netinet6/in6.h> 743#undef __KAME_NETINET_IN_H_INCLUDED_ 744#endif 745 746#ifdef _KERNEL 747#include <netinet/vinet.h> 748#endif 749 750#endif /* !_NETINET_IN_H_*/ 751