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