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