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