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