1*19c3b8c2SApple OSS Distributions /* 2*19c3b8c2SApple OSS Distributions * Copyright (c) 2000-2016 Apple Inc. All rights reserved. 3*19c3b8c2SApple OSS Distributions * 4*19c3b8c2SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*19c3b8c2SApple OSS Distributions * 6*19c3b8c2SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*19c3b8c2SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*19c3b8c2SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*19c3b8c2SApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*19c3b8c2SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*19c3b8c2SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*19c3b8c2SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*19c3b8c2SApple OSS Distributions * terms of an Apple operating system software license agreement. 14*19c3b8c2SApple OSS Distributions * 15*19c3b8c2SApple OSS Distributions * Please obtain a copy of the License at 16*19c3b8c2SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*19c3b8c2SApple OSS Distributions * 18*19c3b8c2SApple OSS Distributions * The Original Code and all software distributed under the License are 19*19c3b8c2SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*19c3b8c2SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*19c3b8c2SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*19c3b8c2SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*19c3b8c2SApple OSS Distributions * Please see the License for the specific language governing rights and 24*19c3b8c2SApple OSS Distributions * limitations under the License. 25*19c3b8c2SApple OSS Distributions * 26*19c3b8c2SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*19c3b8c2SApple OSS Distributions */ 28*19c3b8c2SApple OSS Distributions /* 29*19c3b8c2SApple OSS Distributions * Copyright (c) 1982, 1986, 1993 30*19c3b8c2SApple OSS Distributions * The Regents of the University of California. All rights reserved. 31*19c3b8c2SApple OSS Distributions * 32*19c3b8c2SApple OSS Distributions * Redistribution and use in source and binary forms, with or without 33*19c3b8c2SApple OSS Distributions * modification, are permitted provided that the following conditions 34*19c3b8c2SApple OSS Distributions * are met: 35*19c3b8c2SApple OSS Distributions * 1. Redistributions of source code must retain the above copyright 36*19c3b8c2SApple OSS Distributions * notice, this list of conditions and the following disclaimer. 37*19c3b8c2SApple OSS Distributions * 2. Redistributions in binary form must reproduce the above copyright 38*19c3b8c2SApple OSS Distributions * notice, this list of conditions and the following disclaimer in the 39*19c3b8c2SApple OSS Distributions * documentation and/or other materials provided with the distribution. 40*19c3b8c2SApple OSS Distributions * 3. All advertising materials mentioning features or use of this software 41*19c3b8c2SApple OSS Distributions * must display the following acknowledgement: 42*19c3b8c2SApple OSS Distributions * This product includes software developed by the University of 43*19c3b8c2SApple OSS Distributions * California, Berkeley and its contributors. 44*19c3b8c2SApple OSS Distributions * 4. Neither the name of the University nor the names of its contributors 45*19c3b8c2SApple OSS Distributions * may be used to endorse or promote products derived from this software 46*19c3b8c2SApple OSS Distributions * without specific prior written permission. 47*19c3b8c2SApple OSS Distributions * 48*19c3b8c2SApple OSS Distributions * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 49*19c3b8c2SApple OSS Distributions * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 50*19c3b8c2SApple OSS Distributions * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 51*19c3b8c2SApple OSS Distributions * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 52*19c3b8c2SApple OSS Distributions * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53*19c3b8c2SApple OSS Distributions * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 54*19c3b8c2SApple OSS Distributions * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 55*19c3b8c2SApple OSS Distributions * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 56*19c3b8c2SApple OSS Distributions * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 57*19c3b8c2SApple OSS Distributions * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58*19c3b8c2SApple OSS Distributions * SUCH DAMAGE. 59*19c3b8c2SApple OSS Distributions * 60*19c3b8c2SApple OSS Distributions * @(#)ip.h 8.2 (Berkeley) 6/1/94 61*19c3b8c2SApple OSS Distributions * $FreeBSD: src/sys/netinet/ip.h,v 1.17 1999/12/22 19:13:20 shin Exp $ 62*19c3b8c2SApple OSS Distributions */ 63*19c3b8c2SApple OSS Distributions 64*19c3b8c2SApple OSS Distributions #ifndef _NETINET_IP_H_ 65*19c3b8c2SApple OSS Distributions #define _NETINET_IP_H_ 66*19c3b8c2SApple OSS Distributions #ifndef DRIVERKIT 67*19c3b8c2SApple OSS Distributions #include <sys/appleapiopts.h> 68*19c3b8c2SApple OSS Distributions #include <sys/types.h> /* XXX temporary hack to get u_ types */ 69*19c3b8c2SApple OSS Distributions #else 70*19c3b8c2SApple OSS Distributions #include <sys/_types.h> 71*19c3b8c2SApple OSS Distributions #include <sys/_types/_u_int.h> 72*19c3b8c2SApple OSS Distributions #include <sys/_types/_u_char.h> 73*19c3b8c2SApple OSS Distributions #include <sys/_types/_u_short.h> 74*19c3b8c2SApple OSS Distributions 75*19c3b8c2SApple OSS Distributions #include <machine/endian.h> 76*19c3b8c2SApple OSS Distributions #endif /* DRIVERKIT */ 77*19c3b8c2SApple OSS Distributions 78*19c3b8c2SApple OSS Distributions #include <netinet/in.h> 79*19c3b8c2SApple OSS Distributions #include <netinet/in_systm.h> 80*19c3b8c2SApple OSS Distributions 81*19c3b8c2SApple OSS Distributions /* 82*19c3b8c2SApple OSS Distributions * Definitions for internet protocol version 4. 83*19c3b8c2SApple OSS Distributions * Per RFC 791, September 1981. 84*19c3b8c2SApple OSS Distributions */ 85*19c3b8c2SApple OSS Distributions #define IPVERSION 4 86*19c3b8c2SApple OSS Distributions 87*19c3b8c2SApple OSS Distributions /* 88*19c3b8c2SApple OSS Distributions * Structure of an internet header, naked of options. 89*19c3b8c2SApple OSS Distributions */ 90*19c3b8c2SApple OSS Distributions struct ip { 91*19c3b8c2SApple OSS Distributions #ifdef _IP_VHL 92*19c3b8c2SApple OSS Distributions u_char ip_vhl; /* version << 4 | header length >> 2 */ 93*19c3b8c2SApple OSS Distributions #else 94*19c3b8c2SApple OSS Distributions #if BYTE_ORDER == LITTLE_ENDIAN 95*19c3b8c2SApple OSS Distributions u_int ip_hl:4, /* header length */ 96*19c3b8c2SApple OSS Distributions ip_v:4; /* version */ 97*19c3b8c2SApple OSS Distributions #endif 98*19c3b8c2SApple OSS Distributions #if BYTE_ORDER == BIG_ENDIAN 99*19c3b8c2SApple OSS Distributions u_int ip_v:4, /* version */ 100*19c3b8c2SApple OSS Distributions ip_hl:4; /* header length */ 101*19c3b8c2SApple OSS Distributions #endif 102*19c3b8c2SApple OSS Distributions #endif /* not _IP_VHL */ 103*19c3b8c2SApple OSS Distributions u_char ip_tos; /* type of service */ 104*19c3b8c2SApple OSS Distributions u_short ip_len; /* total length */ 105*19c3b8c2SApple OSS Distributions u_short ip_id; /* identification */ 106*19c3b8c2SApple OSS Distributions u_short ip_off; /* fragment offset field */ 107*19c3b8c2SApple OSS Distributions #define IP_RF 0x8000 /* reserved fragment flag */ 108*19c3b8c2SApple OSS Distributions #define IP_DF 0x4000 /* dont fragment flag */ 109*19c3b8c2SApple OSS Distributions #define IP_MF 0x2000 /* more fragments flag */ 110*19c3b8c2SApple OSS Distributions #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ 111*19c3b8c2SApple OSS Distributions u_char ip_ttl; /* time to live */ 112*19c3b8c2SApple OSS Distributions u_char ip_p; /* protocol */ 113*19c3b8c2SApple OSS Distributions u_short ip_sum; /* checksum */ 114*19c3b8c2SApple OSS Distributions struct in_addr ip_src, ip_dst; /* source and dest address */ 115*19c3b8c2SApple OSS Distributions }; 116*19c3b8c2SApple OSS Distributions 117*19c3b8c2SApple OSS Distributions #ifdef _IP_VHL 118*19c3b8c2SApple OSS Distributions #define IP_MAKE_VHL(v, hl) ((uint8_t)((v) << 4 | (hl))) 119*19c3b8c2SApple OSS Distributions #define IP_VHL_HL(vhl) ((vhl) & 0x0f) 120*19c3b8c2SApple OSS Distributions #define IP_VHL_V(vhl) ((vhl) >> 4) 121*19c3b8c2SApple OSS Distributions #define IP_VHL_BORING 0x45 122*19c3b8c2SApple OSS Distributions #endif 123*19c3b8c2SApple OSS Distributions 124*19c3b8c2SApple OSS Distributions #define IP_MAXPACKET 65535 /* maximum packet size */ 125*19c3b8c2SApple OSS Distributions 126*19c3b8c2SApple OSS Distributions /* 127*19c3b8c2SApple OSS Distributions * Definitions for IP type of service (ip_tos) 128*19c3b8c2SApple OSS Distributions */ 129*19c3b8c2SApple OSS Distributions #define IPTOS_LOWDELAY 0x10 130*19c3b8c2SApple OSS Distributions #define IPTOS_THROUGHPUT 0x08 131*19c3b8c2SApple OSS Distributions #define IPTOS_RELIABILITY 0x04 132*19c3b8c2SApple OSS Distributions #define IPTOS_MINCOST 0x02 133*19c3b8c2SApple OSS Distributions #if 1 134*19c3b8c2SApple OSS Distributions /* ECN RFC3168 obsoletes RFC2481, and these will be deprecated soon. */ 135*19c3b8c2SApple OSS Distributions #define IPTOS_CE 0x01 136*19c3b8c2SApple OSS Distributions #define IPTOS_ECT 0x02 137*19c3b8c2SApple OSS Distributions #endif 138*19c3b8c2SApple OSS Distributions 139*19c3b8c2SApple OSS Distributions #define IPTOS_DSCP_SHIFT 2 140*19c3b8c2SApple OSS Distributions 141*19c3b8c2SApple OSS Distributions /* 142*19c3b8c2SApple OSS Distributions * ECN (Explicit Congestion Notification) codepoints in RFC3168 143*19c3b8c2SApple OSS Distributions * mapped to the lower 2 bits of the TOS field. 144*19c3b8c2SApple OSS Distributions */ 145*19c3b8c2SApple OSS Distributions #define IPTOS_ECN_NOTECT 0x00 /* not-ECT */ 146*19c3b8c2SApple OSS Distributions #define IPTOS_ECN_ECT1 0x01 /* ECN-capable transport (1) */ 147*19c3b8c2SApple OSS Distributions #define IPTOS_ECN_ECT0 0x02 /* ECN-capable transport (0) */ 148*19c3b8c2SApple OSS Distributions #define IPTOS_ECN_CE 0x03 /* congestion experienced */ 149*19c3b8c2SApple OSS Distributions #define IPTOS_ECN_MASK 0x03 /* ECN field mask */ 150*19c3b8c2SApple OSS Distributions 151*19c3b8c2SApple OSS Distributions /* 152*19c3b8c2SApple OSS Distributions * Definitions for IP precedence (also in ip_tos) (hopefully unused) 153*19c3b8c2SApple OSS Distributions */ 154*19c3b8c2SApple OSS Distributions #define IPTOS_PREC_NETCONTROL 0xe0 155*19c3b8c2SApple OSS Distributions #define IPTOS_PREC_INTERNETCONTROL 0xc0 156*19c3b8c2SApple OSS Distributions #define IPTOS_PREC_CRITIC_ECP 0xa0 157*19c3b8c2SApple OSS Distributions #define IPTOS_PREC_FLASHOVERRIDE 0x80 158*19c3b8c2SApple OSS Distributions #define IPTOS_PREC_FLASH 0x60 159*19c3b8c2SApple OSS Distributions #define IPTOS_PREC_IMMEDIATE 0x40 160*19c3b8c2SApple OSS Distributions #define IPTOS_PREC_PRIORITY 0x20 161*19c3b8c2SApple OSS Distributions #define IPTOS_PREC_ROUTINE 0x00 162*19c3b8c2SApple OSS Distributions 163*19c3b8c2SApple OSS Distributions #ifdef PRIVATE 164*19c3b8c2SApple OSS Distributions /* 165*19c3b8c2SApple OSS Distributions * Definitions of traffic class for use within wireless LAN. 166*19c3b8c2SApple OSS Distributions * Mainly used by AFP for backup. Not recommended for general use. 167*19c3b8c2SApple OSS Distributions */ 168*19c3b8c2SApple OSS Distributions #define IP_TCLASS_BE 0x00 /* standard, best effort */ 169*19c3b8c2SApple OSS Distributions #define IP_TCLASS_BK 0x20 /* Background, low priority */ 170*19c3b8c2SApple OSS Distributions #define IP_TCLASS_VI 0x80 /* Interactive */ 171*19c3b8c2SApple OSS Distributions #define IP_TCLASS_VO 0xc0 /* Signalling */ 172*19c3b8c2SApple OSS Distributions 173*19c3b8c2SApple OSS Distributions #endif 174*19c3b8c2SApple OSS Distributions /* 175*19c3b8c2SApple OSS Distributions * Definitions for options. 176*19c3b8c2SApple OSS Distributions */ 177*19c3b8c2SApple OSS Distributions #define IPOPT_COPIED(o) ((o)&0x80) 178*19c3b8c2SApple OSS Distributions #define IPOPT_CLASS(o) ((o)&0x60) 179*19c3b8c2SApple OSS Distributions #define IPOPT_NUMBER(o) ((o)&0x1f) 180*19c3b8c2SApple OSS Distributions 181*19c3b8c2SApple OSS Distributions #define IPOPT_CONTROL 0x00 182*19c3b8c2SApple OSS Distributions #define IPOPT_RESERVED1 0x20 183*19c3b8c2SApple OSS Distributions #define IPOPT_DEBMEAS 0x40 184*19c3b8c2SApple OSS Distributions #define IPOPT_RESERVED2 0x60 185*19c3b8c2SApple OSS Distributions 186*19c3b8c2SApple OSS Distributions #define IPOPT_EOL 0 /* end of option list */ 187*19c3b8c2SApple OSS Distributions #define IPOPT_NOP 1 /* no operation */ 188*19c3b8c2SApple OSS Distributions 189*19c3b8c2SApple OSS Distributions #define IPOPT_RR 7 /* record packet route */ 190*19c3b8c2SApple OSS Distributions #define IPOPT_TS 68 /* timestamp */ 191*19c3b8c2SApple OSS Distributions #define IPOPT_SECURITY 130 /* provide s,c,h,tcc */ 192*19c3b8c2SApple OSS Distributions #define IPOPT_LSRR 131 /* loose source route */ 193*19c3b8c2SApple OSS Distributions #define IPOPT_SATID 136 /* satnet id */ 194*19c3b8c2SApple OSS Distributions #define IPOPT_SSRR 137 /* strict source route */ 195*19c3b8c2SApple OSS Distributions #define IPOPT_RA 148 /* router alert */ 196*19c3b8c2SApple OSS Distributions 197*19c3b8c2SApple OSS Distributions /* 198*19c3b8c2SApple OSS Distributions * Offsets to fields in options other than EOL and NOP. 199*19c3b8c2SApple OSS Distributions */ 200*19c3b8c2SApple OSS Distributions #define IPOPT_OPTVAL 0 /* option ID */ 201*19c3b8c2SApple OSS Distributions #define IPOPT_OLEN 1 /* option length */ 202*19c3b8c2SApple OSS Distributions #define IPOPT_OFFSET 2 /* offset within option */ 203*19c3b8c2SApple OSS Distributions #define IPOPT_MINOFF 4 /* min value of above */ 204*19c3b8c2SApple OSS Distributions 205*19c3b8c2SApple OSS Distributions /* 206*19c3b8c2SApple OSS Distributions * Time stamp option structure. 207*19c3b8c2SApple OSS Distributions */ 208*19c3b8c2SApple OSS Distributions struct ip_timestamp { 209*19c3b8c2SApple OSS Distributions u_char ipt_code; /* IPOPT_TS */ 210*19c3b8c2SApple OSS Distributions u_char ipt_len; /* size of structure (variable) */ 211*19c3b8c2SApple OSS Distributions u_char ipt_ptr; /* index of current entry */ 212*19c3b8c2SApple OSS Distributions #if BYTE_ORDER == LITTLE_ENDIAN 213*19c3b8c2SApple OSS Distributions u_int ipt_flg:4, /* flags, see below */ 214*19c3b8c2SApple OSS Distributions ipt_oflw:4; /* overflow counter */ 215*19c3b8c2SApple OSS Distributions #endif 216*19c3b8c2SApple OSS Distributions #if BYTE_ORDER == BIG_ENDIAN 217*19c3b8c2SApple OSS Distributions u_int ipt_oflw:4, /* overflow counter */ 218*19c3b8c2SApple OSS Distributions ipt_flg:4; /* flags, see below */ 219*19c3b8c2SApple OSS Distributions #endif 220*19c3b8c2SApple OSS Distributions union ipt_timestamp { 221*19c3b8c2SApple OSS Distributions n_long ipt_time[1]; 222*19c3b8c2SApple OSS Distributions struct ipt_ta { 223*19c3b8c2SApple OSS Distributions struct in_addr ipt_addr; 224*19c3b8c2SApple OSS Distributions n_long ipt_time; 225*19c3b8c2SApple OSS Distributions } ipt_ta[1]; 226*19c3b8c2SApple OSS Distributions } ipt_timestamp; 227*19c3b8c2SApple OSS Distributions }; 228*19c3b8c2SApple OSS Distributions 229*19c3b8c2SApple OSS Distributions /* flag bits for ipt_flg */ 230*19c3b8c2SApple OSS Distributions #define IPOPT_TS_TSONLY 0 /* timestamps only */ 231*19c3b8c2SApple OSS Distributions #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ 232*19c3b8c2SApple OSS Distributions #define IPOPT_TS_PRESPEC 3 /* specified modules only */ 233*19c3b8c2SApple OSS Distributions 234*19c3b8c2SApple OSS Distributions /* bits for security (not byte swapped) */ 235*19c3b8c2SApple OSS Distributions #define IPOPT_SECUR_UNCLASS 0x0000 236*19c3b8c2SApple OSS Distributions #define IPOPT_SECUR_CONFID 0xf135 237*19c3b8c2SApple OSS Distributions #define IPOPT_SECUR_EFTO 0x789a 238*19c3b8c2SApple OSS Distributions #define IPOPT_SECUR_MMMM 0xbc4d 239*19c3b8c2SApple OSS Distributions #define IPOPT_SECUR_RESTR 0xaf13 240*19c3b8c2SApple OSS Distributions #define IPOPT_SECUR_SECRET 0xd788 241*19c3b8c2SApple OSS Distributions #define IPOPT_SECUR_TOPSECRET 0x6bc5 242*19c3b8c2SApple OSS Distributions 243*19c3b8c2SApple OSS Distributions /* 244*19c3b8c2SApple OSS Distributions * Internet implementation parameters. 245*19c3b8c2SApple OSS Distributions */ 246*19c3b8c2SApple OSS Distributions #define MAXTTL 255 /* maximum time to live (seconds) */ 247*19c3b8c2SApple OSS Distributions #define IPDEFTTL 64 /* default ttl, from RFC 1340 */ 248*19c3b8c2SApple OSS Distributions #define IPFRAGTTL 30 /* time to live for frags (seconds) */ 249*19c3b8c2SApple OSS Distributions #define IPTTLDEC 1 /* subtracted when forwarding */ 250*19c3b8c2SApple OSS Distributions 251*19c3b8c2SApple OSS Distributions #define IP_MSS 576 /* default maximum segment size */ 252*19c3b8c2SApple OSS Distributions 253*19c3b8c2SApple OSS Distributions #endif 254