tcp.h revision 212765
1139823Simp/*-
21541Srgrimes * Copyright (c) 1982, 1986, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 4. Neither the name of the University nor the names of its contributors
141541Srgrimes *    may be used to endorse or promote products derived from this software
151541Srgrimes *    without specific prior written permission.
161541Srgrimes *
171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271541Srgrimes * SUCH DAMAGE.
281541Srgrimes *
291541Srgrimes *	@(#)tcp.h	8.1 (Berkeley) 6/10/93
3050477Speter * $FreeBSD: head/sys/netinet/tcp.h 212765 2010-09-16 21:06:45Z andre $
311541Srgrimes */
321541Srgrimes
332169Spaul#ifndef _NETINET_TCP_H_
342169Spaul#define _NETINET_TCP_H_
352169Spaul
36104343Smike#include <sys/cdefs.h>
37104343Smike
38104342Smike#if __BSD_VISIBLE
39104342Smike
4037622Sbdetypedef	u_int32_t tcp_seq;
416247Swollman
4255679Sshin#define tcp6_seq	tcp_seq	/* for KAME src sync over BSD*'s */
4355679Sshin#define tcp6hdr		tcphdr	/* for KAME src sync over BSD*'s */
4455679Sshin
451541Srgrimes/*
461541Srgrimes * TCP header.
471541Srgrimes * Per RFC 793, September, 1981.
481541Srgrimes */
491541Srgrimesstruct tcphdr {
501541Srgrimes	u_short	th_sport;		/* source port */
511541Srgrimes	u_short	th_dport;		/* destination port */
521541Srgrimes	tcp_seq	th_seq;			/* sequence number */
531541Srgrimes	tcp_seq	th_ack;			/* acknowledgement number */
548876Srgrimes#if BYTE_ORDER == LITTLE_ENDIAN
55203343Sluigi	u_char	th_x2:4,		/* (unused) */
561541Srgrimes		th_off:4;		/* data offset */
571541Srgrimes#endif
588876Srgrimes#if BYTE_ORDER == BIG_ENDIAN
59203343Sluigi	u_char	th_off:4,		/* data offset */
601541Srgrimes		th_x2:4;		/* (unused) */
611541Srgrimes#endif
621541Srgrimes	u_char	th_flags;
631541Srgrimes#define	TH_FIN	0x01
641541Srgrimes#define	TH_SYN	0x02
651541Srgrimes#define	TH_RST	0x04
661541Srgrimes#define	TH_PUSH	0x08
671541Srgrimes#define	TH_ACK	0x10
681541Srgrimes#define	TH_URG	0x20
6970826Srwatson#define	TH_ECE	0x40
7070826Srwatson#define	TH_CWR	0x80
71155817Sandre#define	TH_FLAGS	(TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|TH_ECE|TH_CWR)
72169997Sandre#define	PRINT_TH_FLAGS	"\20\1FIN\2SYN\3RST\4PUSH\5ACK\6URG\7ECE\10CWR"
736348Swollman
741541Srgrimes	u_short	th_win;			/* window */
751541Srgrimes	u_short	th_sum;			/* checksum */
761541Srgrimes	u_short	th_urp;			/* urgent pointer */
771541Srgrimes};
781541Srgrimes
791541Srgrimes#define	TCPOPT_EOL		0
80167606Sandre#define	   TCPOLEN_EOL			1
81177986Sandre#define	TCPOPT_PAD		0		/* padding after EOL */
82177986Sandre#define	   TCPOLEN_PAD			1
831541Srgrimes#define	TCPOPT_NOP		1
84167606Sandre#define	   TCPOLEN_NOP			1
851541Srgrimes#define	TCPOPT_MAXSEG		2
861541Srgrimes#define    TCPOLEN_MAXSEG		4
871541Srgrimes#define TCPOPT_WINDOW		3
881541Srgrimes#define    TCPOLEN_WINDOW		3
89167606Sandre#define TCPOPT_SACK_PERMITTED	4
901541Srgrimes#define    TCPOLEN_SACK_PERMITTED	2
91167606Sandre#define TCPOPT_SACK		5
92167606Sandre#define	   TCPOLEN_SACKHDR		2
93130989Sps#define    TCPOLEN_SACK			8	/* 2*sizeof(tcp_seq) */
941541Srgrimes#define TCPOPT_TIMESTAMP	8
951541Srgrimes#define    TCPOLEN_TIMESTAMP		10
961541Srgrimes#define    TCPOLEN_TSTAMP_APPA		(TCPOLEN_TIMESTAMP+2) /* appendix A */
97168904Sandre#define	TCPOPT_SIGNATURE	19		/* Keyed MD5: RFC 2385 */
98125680Sbms#define	   TCPOLEN_SIGNATURE		18
996247Swollman
100130989Sps/* Miscellaneous constants */
101149403Sps#define	MAX_SACK_BLKS	6	/* Max # SACK blocks stored at receiver side */
102146552Sps#define	TCP_MAX_SACK	4	/* MAX # SACKs sent in any segment */
103130989Sps
104130989Sps
1051541Srgrimes/*
106212653Sandre * The default maximum segment size (MSS) to be used for new TCP connections
107212653Sandre * when path MTU discovery is not enabled.
108212653Sandre *
109212653Sandre * RFC879 derives the default MSS from the largest datagram size hosts are
110212653Sandre * minimally required to handle directly or through IP reassembly minus the
111212653Sandre * size of the IP and TCP header.  With IPv6 the minimum MTU is specified
112212653Sandre * in RFC2460.
113212653Sandre *
114212653Sandre * For IPv4 the MSS is 576 - sizeof(struct tcpiphdr)
115212653Sandre * For IPv6 the MSS is IPV6_MMTU - sizeof(struct ip6_hdr) - sizeof(struct tcphdr)
116212653Sandre *
117212653Sandre * We use explicit numerical definition here to avoid header pollution.
1181541Srgrimes */
119212653Sandre#define	TCP_MSS		536
120212653Sandre#define	TCP6_MSS	1220
121212653Sandre
122124258Sandre/*
123212731Sandre * Limit the lowest MSS we accept for path MTU discovery and the TCP SYN MSS
124212731Sandre * option.  Allowing low values of MSS can consume significant resources and
125212731Sandre * be used to mount a resource exhaustion attack.
126212653Sandre * Connections requesting lower MSS values will be rounded up to this value
127212731Sandre * and the IP_DF flag will be cleared to allow fragmentation along the path.
128212653Sandre *
129212653Sandre * See tcp_subr.c tcp_minmss SYSCTL declaration for more comments.  Setting
130212653Sandre * it to "0" disables the minmss check.
131212653Sandre *
132212731Sandre * The default value is fine for TCP across the Internet's smallest official
133212731Sandre * link MTU (256 bytes for AX.25 packet radio).  However, a connection is very
134212731Sandre * unlikely to come across such low MTU interfaces these days (anno domini 2003).
135124258Sandre */
136124290Sandre#define	TCP_MINMSS 216
1371541Srgrimes
1381541Srgrimes#define	TCP_MAXWIN	65535	/* largest value for (unscaled) window */
1396247Swollman#define	TTCP_CLIENT_SND_WND	4096	/* dflt send window for T/TCP client */
1401541Srgrimes
1411541Srgrimes#define TCP_MAX_WINSHIFT	14	/* maximum window shift */
1421541Srgrimes
143133874Srwatson#define TCP_MAXBURST		4	/* maximum segments in a burst */
14460067Sjlemon
1456247Swollman#define TCP_MAXHLEN	(0xf<<2)	/* max length of header in bytes */
1466247Swollman#define TCP_MAXOLEN	(TCP_MAXHLEN - sizeof(struct tcphdr))
1476247Swollman					/* max space left for options */
148104342Smike#endif /* __BSD_VISIBLE */
1496247Swollman
1501541Srgrimes/*
1511541Srgrimes * User-settable options (used with setsockopt).
1521541Srgrimes */
1531541Srgrimes#define	TCP_NODELAY	0x01	/* don't delay send to coalesce packets */
154104342Smike#if __BSD_VISIBLE
1551541Srgrimes#define	TCP_MAXSEG	0x02	/* set maximum segment size */
1566247Swollman#define TCP_NOPUSH	0x04	/* don't push last block of write */
1576247Swollman#define TCP_NOOPT	0x08	/* don't use TCP options */
158125890Sbms#define TCP_MD5SIG	0x10	/* use MD5 digests (RFC2385) */
159138118Srwatson#define	TCP_INFO	0x20	/* retrieve tcp_info structure */
160174636Skmacy#define	TCP_CONGESTION	0x40	/* get/set congestion control algorithm */
161138118Srwatson
162174636Skmacy#define	TCP_CA_NAME_MAX	16	/* max congestion control name length */
163174636Skmacy
164138118Srwatson#define	TCPI_OPT_TIMESTAMPS	0x01
165138118Srwatson#define	TCPI_OPT_SACK		0x02
166138118Srwatson#define	TCPI_OPT_WSCALE		0x04
167138118Srwatson#define	TCPI_OPT_ECN		0x08
168178793Skmacy#define	TCPI_OPT_TOE		0x10
169138118Srwatson
170138118Srwatson/*
171138118Srwatson * The TCP_INFO socket option comes from the Linux 2.6 TCP API, and permits
172138118Srwatson * the caller to query certain information about the state of a TCP
173138118Srwatson * connection.  We provide an overlapping set of fields with the Linux
174138118Srwatson * implementation, but since this is a fixed size structure, room has been
175138118Srwatson * left for growth.  In order to maximize potential future compatibility with
176138118Srwatson * the Linux API, the same variable names and order have been adopted, and
177138118Srwatson * padding left to make room for omitted fields in case they are added later.
178138118Srwatson *
179138118Srwatson * XXX: This is currently an unstable ABI/API, in that it is expected to
180138118Srwatson * change.
181138118Srwatson */
182138118Srwatsonstruct tcp_info {
183138118Srwatson	u_int8_t	tcpi_state;		/* TCP FSM state. */
184138118Srwatson	u_int8_t	__tcpi_ca_state;
185138118Srwatson	u_int8_t	__tcpi_retransmits;
186138118Srwatson	u_int8_t	__tcpi_probes;
187138118Srwatson	u_int8_t	__tcpi_backoff;
188138118Srwatson	u_int8_t	tcpi_options;		/* Options enabled on conn. */
189138118Srwatson	u_int8_t	tcpi_snd_wscale:4,	/* RFC1323 send shift value. */
190138118Srwatson			tcpi_rcv_wscale:4;	/* RFC1323 recv shift value. */
191138118Srwatson
192200847Sjhb	u_int32_t	tcpi_rto;		/* Retransmission timeout (usec). */
193138118Srwatson	u_int32_t	__tcpi_ato;
194200847Sjhb	u_int32_t	tcpi_snd_mss;		/* Max segment size for send. */
195200847Sjhb	u_int32_t	tcpi_rcv_mss;		/* Max segment size for receive. */
196138118Srwatson
197138118Srwatson	u_int32_t	__tcpi_unacked;
198138118Srwatson	u_int32_t	__tcpi_sacked;
199138118Srwatson	u_int32_t	__tcpi_lost;
200138118Srwatson	u_int32_t	__tcpi_retrans;
201138118Srwatson	u_int32_t	__tcpi_fackets;
202138118Srwatson
203138118Srwatson	/* Times; measurements in usecs. */
204138118Srwatson	u_int32_t	__tcpi_last_data_sent;
205138118Srwatson	u_int32_t	__tcpi_last_ack_sent;	/* Also unimpl. on Linux? */
206200847Sjhb	u_int32_t	tcpi_last_data_recv;	/* Time since last recv data. */
207138118Srwatson	u_int32_t	__tcpi_last_ack_recv;
208138118Srwatson
209138118Srwatson	/* Metrics; variable units. */
210138118Srwatson	u_int32_t	__tcpi_pmtu;
211138118Srwatson	u_int32_t	__tcpi_rcv_ssthresh;
212166433Sbms	u_int32_t	tcpi_rtt;		/* Smoothed RTT in usecs. */
213166433Sbms	u_int32_t	tcpi_rttvar;		/* RTT variance in usecs. */
214138118Srwatson	u_int32_t	tcpi_snd_ssthresh;	/* Slow start threshold. */
215138118Srwatson	u_int32_t	tcpi_snd_cwnd;		/* Send congestion window. */
216138118Srwatson	u_int32_t	__tcpi_advmss;
217138118Srwatson	u_int32_t	__tcpi_reordering;
218138118Srwatson
219138118Srwatson	u_int32_t	__tcpi_rcv_rtt;
220138136Srwatson	u_int32_t	tcpi_rcv_space;		/* Advertised recv window. */
221138118Srwatson
222138118Srwatson	/* FreeBSD extensions to tcp_info. */
223138118Srwatson	u_int32_t	tcpi_snd_wnd;		/* Advertised send window. */
224212765Sandre	u_int32_t	tcpi_snd_bwnd;		/* No longer used. */
225178793Skmacy	u_int32_t	tcpi_snd_nxt;		/* Next egress seqno */
226178793Skmacy	u_int32_t	tcpi_rcv_nxt;		/* Next ingress seqno */
227178793Skmacy	u_int32_t	tcpi_toe_tid;		/* HWTID for TOE endpoints */
228178793Skmacy
229138118Srwatson	/* Padding to grow without breaking ABI. */
230178793Skmacy	u_int32_t	__tcpi_pad[29];		/* Padding. */
231138118Srwatson};
232104342Smike#endif
2332169Spaul
234104342Smike#endif /* !_NETINET_TCP_H_ */
235