]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet/tcp.h
xnu-792.12.6.tar.gz
[apple/xnu.git] / bsd / netinet / tcp.h
CommitLineData
1c79356b 1/*
8ad349bb 2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
1c79356b 3 *
8ad349bb 4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
1c79356b 5 *
8ad349bb
A
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
1c79356b
A
29 */
30/*
31 * Copyright (c) 1982, 1986, 1993
32 * The Regents of the University of California. All rights reserved.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * @(#)tcp.h 8.1 (Berkeley) 6/10/93
9bccf70c 63 * $FreeBSD: src/sys/netinet/tcp.h,v 1.13.2.3 2001/03/01 22:08:42 jlemon Exp $
1c79356b
A
64 */
65
66#ifndef _NETINET_TCP_H_
67#define _NETINET_TCP_H_
9bccf70c 68#include <sys/appleapiopts.h>
91447636
A
69#include <sys/_types.h>
70#include <machine/endian.h>
1c79356b 71
91447636
A
72#ifndef _POSIX_C_SOURCE
73typedef __uint32_t tcp_seq;
74typedef __uint32_t tcp_cc; /* connection count per rfc1644 */
1c79356b
A
75
76#define tcp6_seq tcp_seq /* for KAME src sync over BSD*'s */
77#define tcp6hdr tcphdr /* for KAME src sync over BSD*'s */
78
79/*
80 * TCP header.
81 * Per RFC 793, September, 1981.
82 */
83struct tcphdr {
91447636
A
84 unsigned short th_sport; /* source port */
85 unsigned short th_dport; /* destination port */
1c79356b
A
86 tcp_seq th_seq; /* sequence number */
87 tcp_seq th_ack; /* acknowledgement number */
91447636
A
88#if __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN
89 unsigned int th_x2:4, /* (unused) */
90 th_off:4; /* data offset */
1c79356b 91#endif
91447636
A
92#if __DARWIN_BYTE_ORDER == __DARWIN_BIG_ENDIAN
93 unsigned int th_off:4, /* data offset */
94 th_x2:4; /* (unused) */
1c79356b 95#endif
91447636 96 unsigned char th_flags;
1c79356b
A
97#define TH_FIN 0x01
98#define TH_SYN 0x02
99#define TH_RST 0x04
100#define TH_PUSH 0x08
101#define TH_ACK 0x10
102#define TH_URG 0x20
9bccf70c
A
103#define TH_ECE 0x40
104#define TH_CWR 0x80
105#define TH_FLAGS (TH_FIN|TH_SYN|TH_RST|TH_ACK|TH_URG|TH_ECE|TH_CWR)
1c79356b 106
91447636
A
107 unsigned short th_win; /* window */
108 unsigned short th_sum; /* checksum */
109 unsigned short th_urp; /* urgent pointer */
1c79356b
A
110};
111
112#define TCPOPT_EOL 0
113#define TCPOPT_NOP 1
114#define TCPOPT_MAXSEG 2
8ad349bb 115#define TCPOLEN_MAXSEG 4
1c79356b 116#define TCPOPT_WINDOW 3
8ad349bb 117#define TCPOLEN_WINDOW 3
1c79356b 118#define TCPOPT_SACK_PERMITTED 4 /* Experimental */
8ad349bb 119#define TCPOLEN_SACK_PERMITTED 2
1c79356b 120#define TCPOPT_SACK 5 /* Experimental */
8ad349bb 121#define TCPOLEN_SACK 8 /* len of sack block */
1c79356b 122#define TCPOPT_TIMESTAMP 8
8ad349bb
A
123#define TCPOLEN_TIMESTAMP 10
124#define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */
125#define TCPOPT_TSTAMP_HDR \
1c79356b
A
126 (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
127
8ad349bb
A
128#define MAX_TCPOPTLEN 40 /* Absolute maximum TCP options len */
129
1c79356b
A
130#define TCPOPT_CC 11 /* CC options: RFC-1644 */
131#define TCPOPT_CCNEW 12
132#define TCPOPT_CCECHO 13
133#define TCPOLEN_CC 6
134#define TCPOLEN_CC_APPA (TCPOLEN_CC+2)
135#define TCPOPT_CC_HDR(ccopt) \
136 (TCPOPT_NOP<<24|TCPOPT_NOP<<16|(ccopt)<<8|TCPOLEN_CC)
8ad349bb
A
137#define TCPOPT_SIGNATURE 19 /* Keyed MD5: RFC 2385 */
138#define TCPOLEN_SIGNATURE 18
139
140/* Option definitions */
141#define TCPOPT_SACK_PERMIT_HDR \
142(TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_SACK_PERMITTED<<8|TCPOLEN_SACK_PERMITTED)
143#define TCPOPT_SACK_HDR (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_SACK<<8)
144/* Miscellaneous constants */
145#define MAX_SACK_BLKS 6 /* Max # SACK blocks stored at sender side */
146#define TCP_MAX_SACK 3 /* MAX # SACKs sent in any segment */
147
1c79356b
A
148
149/*
150 * Default maximum segment size for TCP.
4a249263 151 * With an IP MTU of 576, this is 536,
1c79356b
A
152 * but 512 is probably more convenient.
153 * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
154 */
155#define TCP_MSS 512
156
e5568f75
A
157/*
158 * TCP_MINMSS is defined to be 216 which is fine for the smallest
159 * link MTU (256 bytes, SLIP interface) in the Internet.
160 * However it is very unlikely to come across such low MTU interfaces
161 * these days (anno dato 2004).
162 * Probably it can be set to 512 without ill effects. But we play safe.
163 * See tcp_subr.c tcp_minmss SYSCTL declaration for more comments.
164 * Setting this to "0" disables the minmss check.
165 */
166#define TCP_MINMSS 216
167
91447636
A
168/*
169 * TCP_MINMSSOVERLOAD is defined to be 1000 which should cover any type
170 * of interactive TCP session.
171 * See tcp_subr.c tcp_minmssoverload SYSCTL declaration and tcp_input.c
172 * for more comments.
173 * Setting this to "0" disables the minmssoverload check.
174 */
175#define TCP_MINMSSOVERLOAD 1000
176
1c79356b
A
177/*
178 * Default maximum segment size for TCP6.
179 * With an IP6 MSS of 1280, this is 1220,
180 * but 1024 is probably more convenient. (xxx kazu in doubt)
181 * This should be defined as MIN(1024, IP6_MSS - sizeof (struct tcpip6hdr))
182 */
183#define TCP6_MSS 1024
184
185#define TCP_MAXWIN 65535 /* largest value for (unscaled) window */
186#define TTCP_CLIENT_SND_WND 4096 /* dflt send window for T/TCP client */
187
188#define TCP_MAX_WINSHIFT 14 /* maximum window shift */
189
9bccf70c
A
190#define TCP_MAXBURST 4 /* maximum segments in a burst */
191
1c79356b
A
192#define TCP_MAXHLEN (0xf<<2) /* max length of header in bytes */
193#define TCP_MAXOLEN (TCP_MAXHLEN - sizeof(struct tcphdr))
194 /* max space left for options */
91447636 195#endif /* _POSIX_C_SOURCE */
1c79356b
A
196
197/*
198 * User-settable options (used with setsockopt).
199 */
200#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
91447636 201#ifndef _POSIX_C_SOURCE
8ad349bb
A
202#define TCP_MAXSEG 0x02 /* set maximum segment size */
203#define TCP_NOPUSH 0x04 /* don't push last block of write */
204#define TCP_NOOPT 0x08 /* don't use TCP options */
55e303ae 205#define TCP_KEEPALIVE 0x10 /* idle time used when SO_KEEPALIVE is enabled */
8ad349bb 206
91447636 207#endif /* _POSIX_C_SOURCE */
1c79356b
A
208
209#endif