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