tcp.h revision 167606
1281SN/A/*-
2281SN/A * Copyright (c) 1982, 1986, 1993
3281SN/A *	The Regents of the University of California.  All rights reserved.
4281SN/A *
5281SN/A * Redistribution and use in source and binary forms, with or without
61113Sjoehw * modification, are permitted provided that the following conditions
71113Sjoehw * are met:
81113Sjoehw * 1. Redistributions of source code must retain the above copyright
91113Sjoehw *    notice, this list of conditions and the following disclaimer.
101113Sjoehw * 2. Redistributions in binary form must reproduce the above copyright
111113Sjoehw *    notice, this list of conditions and the following disclaimer in the
12281SN/A *    documentation and/or other materials provided with the distribution.
13281SN/A * 4. Neither the name of the University nor the names of its contributors
14281SN/A *    may be used to endorse or promote products derived from this software
15281SN/A *    without specific prior written permission.
16281SN/A *
17281SN/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18281SN/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19281SN/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20281SN/A * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21281SN/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22281SN/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23281SN/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24281SN/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25281SN/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26510SN/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27464SN/A * SUCH DAMAGE.
28281SN/A *
29281SN/A *	@(#)tcp.h	8.1 (Berkeley) 6/10/93
30464SN/A * $FreeBSD: head/sys/netinet/tcp.h 167606 2007-03-15 15:59:28Z andre $
31464SN/A */
32281SN/A
33281SN/A#ifndef _NETINET_TCP_H_
34281SN/A#define _NETINET_TCP_H_
35281SN/A
36281SN/A#include <sys/cdefs.h>
37281SN/A
38281SN/A#if __BSD_VISIBLE
39281SN/A
40281SN/Atypedef	u_int32_t tcp_seq;
41281SN/A
42281SN/A#define tcp6_seq	tcp_seq	/* for KAME src sync over BSD*'s */
43281SN/A#define tcp6hdr		tcphdr	/* for KAME src sync over BSD*'s */
44281SN/A
45281SN/A/*
46281SN/A * TCP header.
47281SN/A * Per RFC 793, September, 1981.
48281SN/A */
49281SN/Astruct tcphdr {
50281SN/A	u_short	th_sport;		/* source port */
51281SN/A	u_short	th_dport;		/* destination port */
52281SN/A	tcp_seq	th_seq;			/* sequence number */
53281SN/A	tcp_seq	th_ack;			/* acknowledgement number */
54281SN/A#if BYTE_ORDER == LITTLE_ENDIAN
55281SN/A	u_int	th_x2:4,		/* (unused) */
56281SN/A		th_off:4;		/* data offset */
57281SN/A#endif
58281SN/A#if BYTE_ORDER == BIG_ENDIAN
59281SN/A	u_int	th_off:4,		/* data offset */
60281SN/A		th_x2:4;		/* (unused) */
61281SN/A#endif
62281SN/A	u_char	th_flags;
63281SN/A#define	TH_FIN	0x01
64281SN/A#define	TH_SYN	0x02
65281SN/A#define	TH_RST	0x04
66281SN/A#define	TH_PUSH	0x08
67281SN/A#define	TH_ACK	0x10
68281SN/A#define	TH_URG	0x20
69281SN/A#define	TH_ECE	0x40
70281SN/A#define	TH_CWR	0x80
71281SN/A#define	TH_FLAGS	(TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|TH_ECE|TH_CWR)
72281SN/A
73281SN/A	u_short	th_win;			/* window */
74281SN/A	u_short	th_sum;			/* checksum */
75281SN/A	u_short	th_urp;			/* urgent pointer */
76281SN/A};
77281SN/A
78281SN/A#define	TCPOPT_EOL		0
79281SN/A#define	   TCPOLEN_EOL			1
80515SN/A#define	TCPOPT_NOP		1
81281SN/A#define	   TCPOLEN_NOP			1
82281SN/A#define	TCPOPT_MAXSEG		2
83281SN/A#define    TCPOLEN_MAXSEG		4
84281SN/A#define TCPOPT_WINDOW		3
85281SN/A#define    TCPOLEN_WINDOW		3
86281SN/A#define TCPOPT_SACK_PERMITTED	4
87281SN/A#define    TCPOLEN_SACK_PERMITTED	2
88281SN/A#define TCPOPT_SACK		5
89281SN/A#define	   TCPOLEN_SACKHDR		2
90281SN/A#define    TCPOLEN_SACK			8	/* 2*sizeof(tcp_seq) */
91281SN/A#define TCPOPT_TIMESTAMP	8
92281SN/A#define    TCPOLEN_TIMESTAMP		10
93281SN/A#define    TCPOLEN_TSTAMP_APPA		(TCPOLEN_TIMESTAMP+2) /* appendix A */
94281SN/A#define    TCPOPT_TSTAMP_HDR		\
95281SN/A    (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
96281SN/A
97281SN/A#define	MAX_TCPOPTLEN		40	/* Absolute maximum TCP options len */
98281SN/A
99281SN/A#define	TCPOPT_SIGNATURE		19	/* Keyed MD5: RFC 2385 */
100281SN/A#define	   TCPOLEN_SIGNATURE		18
101281SN/A
102281SN/A/* Option definitions */
103281SN/A#define TCPOPT_SACK_PERMIT_HDR	\
104281SN/A(TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_SACK_PERMITTED<<8|TCPOLEN_SACK_PERMITTED)
105281SN/A#define	TCPOPT_SACK_HDR		(TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_SACK<<8)
106281SN/A/* Miscellaneous constants */
107281SN/A#define	MAX_SACK_BLKS	6	/* Max # SACK blocks stored at receiver side */
108281SN/A#define	TCP_MAX_SACK	4	/* MAX # SACKs sent in any segment */
109281SN/A
110281SN/A
111293SN/A/*
112281SN/A * Default maximum segment size for TCP.
113281SN/A * With an IP MTU of 576, this is 536,
114281SN/A * but 512 is probably more convenient.
115281SN/A * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
116281SN/A */
117281SN/A#define	TCP_MSS	512
118281SN/A/*
119281SN/A * TCP_MINMSS is defined to be 216 which is fine for the smallest
120281SN/A * link MTU (256 bytes, AX.25 packet radio) in the Internet.
121281SN/A * However it is very unlikely to come across such low MTU interfaces
122281SN/A * these days (anno dato 2003).
123281SN/A * See tcp_subr.c tcp_minmss SYSCTL declaration for more comments.
124281SN/A * Setting this to "0" disables the minmss check.
125281SN/A */
126281SN/A#define	TCP_MINMSS 216
127281SN/A/*
128464SN/A * TCP_MINMSSOVERLOAD is defined to be 1000 which should cover any type
129464SN/A * of interactive TCP session.
130464SN/A * See tcp_subr.c tcp_minmssoverload SYSCTL declaration and tcp_input.c
131464SN/A * for more comments.
132464SN/A * Setting this to "0" disables the minmssoverload check.
133464SN/A */
134515SN/A#define	TCP_MINMSSOVERLOAD 0	/* XXX: Disabled until refined */
135515SN/A
136515SN/A/*
137515SN/A * Default maximum segment size for TCP6.
138515SN/A * With an IP6 MSS of 1280, this is 1220,
139515SN/A * but 1024 is probably more convenient. (xxx kazu in doubt)
140515SN/A * This should be defined as MIN(1024, IP6_MSS - sizeof (struct tcpip6hdr))
141515SN/A */
142515SN/A#define	TCP6_MSS	1024
143515SN/A
144515SN/A#define	TCP_MAXWIN	65535	/* largest value for (unscaled) window */
145515SN/A#define	TTCP_CLIENT_SND_WND	4096	/* dflt send window for T/TCP client */
146515SN/A
147515SN/A#define TCP_MAX_WINSHIFT	14	/* maximum window shift */
148515SN/A
149515SN/A#define TCP_MAXBURST		4	/* maximum segments in a burst */
150515SN/A
151515SN/A#define TCP_MAXHLEN	(0xf<<2)	/* max length of header in bytes */
152515SN/A#define TCP_MAXOLEN	(TCP_MAXHLEN - sizeof(struct tcphdr))
153515SN/A					/* max space left for options */
154515SN/A#endif /* __BSD_VISIBLE */
155515SN/A
156515SN/A/*
157515SN/A * User-settable options (used with setsockopt).
158510SN/A */
159510SN/A#define	TCP_NODELAY	0x01	/* don't delay send to coalesce packets */
160515SN/A#if __BSD_VISIBLE
161510SN/A#define	TCP_MAXSEG	0x02	/* set maximum segment size */
162515SN/A#define TCP_NOPUSH	0x04	/* don't push last block of write */
163510SN/A#define TCP_NOOPT	0x08	/* don't use TCP options */
164464SN/A#define TCP_MD5SIG	0x10	/* use MD5 digests (RFC2385) */
165464SN/A#define	TCP_INFO	0x20	/* retrieve tcp_info structure */
166464SN/A
167464SN/A#define	TCPI_OPT_TIMESTAMPS	0x01
168464SN/A#define	TCPI_OPT_SACK		0x02
169464SN/A#define	TCPI_OPT_WSCALE		0x04
170510SN/A#define	TCPI_OPT_ECN		0x08
171464SN/A
172510SN/A/*
173515SN/A * The TCP_INFO socket option comes from the Linux 2.6 TCP API, and permits
174515SN/A * the caller to query certain information about the state of a TCP
175510SN/A * connection.  We provide an overlapping set of fields with the Linux
176510SN/A * implementation, but since this is a fixed size structure, room has been
177464SN/A * left for growth.  In order to maximize potential future compatibility with
178464SN/A * the Linux API, the same variable names and order have been adopted, and
179281SN/A * padding left to make room for omitted fields in case they are added later.
180 *
181 * XXX: This is currently an unstable ABI/API, in that it is expected to
182 * change.
183 */
184struct tcp_info {
185	u_int8_t	tcpi_state;		/* TCP FSM state. */
186	u_int8_t	__tcpi_ca_state;
187	u_int8_t	__tcpi_retransmits;
188	u_int8_t	__tcpi_probes;
189	u_int8_t	__tcpi_backoff;
190	u_int8_t	tcpi_options;		/* Options enabled on conn. */
191	u_int8_t	tcpi_snd_wscale:4,	/* RFC1323 send shift value. */
192			tcpi_rcv_wscale:4;	/* RFC1323 recv shift value. */
193
194	u_int32_t	__tcpi_rto;
195	u_int32_t	__tcpi_ato;
196	u_int32_t	__tcpi_snd_mss;
197	u_int32_t	__tcpi_rcv_mss;
198
199	u_int32_t	__tcpi_unacked;
200	u_int32_t	__tcpi_sacked;
201	u_int32_t	__tcpi_lost;
202	u_int32_t	__tcpi_retrans;
203	u_int32_t	__tcpi_fackets;
204
205	/* Times; measurements in usecs. */
206	u_int32_t	__tcpi_last_data_sent;
207	u_int32_t	__tcpi_last_ack_sent;	/* Also unimpl. on Linux? */
208	u_int32_t	__tcpi_last_data_recv;
209	u_int32_t	__tcpi_last_ack_recv;
210
211	/* Metrics; variable units. */
212	u_int32_t	__tcpi_pmtu;
213	u_int32_t	__tcpi_rcv_ssthresh;
214	u_int32_t	tcpi_rtt;		/* Smoothed RTT in usecs. */
215	u_int32_t	tcpi_rttvar;		/* RTT variance in usecs. */
216	u_int32_t	tcpi_snd_ssthresh;	/* Slow start threshold. */
217	u_int32_t	tcpi_snd_cwnd;		/* Send congestion window. */
218	u_int32_t	__tcpi_advmss;
219	u_int32_t	__tcpi_reordering;
220
221	u_int32_t	__tcpi_rcv_rtt;
222	u_int32_t	tcpi_rcv_space;		/* Advertised recv window. */
223
224	/* FreeBSD extensions to tcp_info. */
225	u_int32_t	tcpi_snd_wnd;		/* Advertised send window. */
226	u_int32_t	tcpi_snd_bwnd;		/* Bandwidth send window. */
227
228	/* Padding to grow without breaking ABI. */
229	u_int32_t	__tcpi_pad[32];		/* Padding. */
230};
231#endif
232
233#endif /* !_NETINET_TCP_H_ */
234