xref: /minix3/sys/netinet/tcp.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: tcp.h,v 1.31 2015/02/14 12:57:53 he Exp $	*/
2f6aac1c3SLionel Sambuc 
3f6aac1c3SLionel Sambuc /*
4f6aac1c3SLionel Sambuc  * Copyright (c) 1982, 1986, 1993
5f6aac1c3SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
6f6aac1c3SLionel Sambuc  *
7f6aac1c3SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
8f6aac1c3SLionel Sambuc  * modification, are permitted provided that the following conditions
9f6aac1c3SLionel Sambuc  * are met:
10f6aac1c3SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
11f6aac1c3SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
12f6aac1c3SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
13f6aac1c3SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
14f6aac1c3SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
15f6aac1c3SLionel Sambuc  * 3. Neither the name of the University nor the names of its contributors
16f6aac1c3SLionel Sambuc  *    may be used to endorse or promote products derived from this software
17f6aac1c3SLionel Sambuc  *    without specific prior written permission.
18f6aac1c3SLionel Sambuc  *
19f6aac1c3SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20f6aac1c3SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21f6aac1c3SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22f6aac1c3SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23f6aac1c3SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24f6aac1c3SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25f6aac1c3SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26f6aac1c3SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27f6aac1c3SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28f6aac1c3SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29f6aac1c3SLionel Sambuc  * SUCH DAMAGE.
30f6aac1c3SLionel Sambuc  *
31f6aac1c3SLionel Sambuc  *	@(#)tcp.h	8.1 (Berkeley) 6/10/93
32f6aac1c3SLionel Sambuc  */
33f6aac1c3SLionel Sambuc 
34f6aac1c3SLionel Sambuc #ifndef _NETINET_TCP_H_
35f6aac1c3SLionel Sambuc #define _NETINET_TCP_H_
36f6aac1c3SLionel Sambuc 
37f6aac1c3SLionel Sambuc #include <sys/featuretest.h>
38f6aac1c3SLionel Sambuc 
39f6aac1c3SLionel Sambuc #if defined(_NETBSD_SOURCE)
4001624e6fSBen Gras #include <sys/types.h>
41f6aac1c3SLionel Sambuc 
4201624e6fSBen Gras typedef uint32_t tcp_seq;
43f6aac1c3SLionel Sambuc /*
44f6aac1c3SLionel Sambuc  * TCP header.
45f6aac1c3SLionel Sambuc  * Per RFC 793, September, 1981.
46f6aac1c3SLionel Sambuc  * Updated by RFC 3168, September, 2001.
47f6aac1c3SLionel Sambuc  */
48f6aac1c3SLionel Sambuc struct tcphdr {
4901624e6fSBen Gras 	uint16_t th_sport;		/* source port */
5001624e6fSBen Gras 	uint16_t th_dport;		/* destination port */
51f6aac1c3SLionel Sambuc 	tcp_seq	  th_seq;		/* sequence number */
52f6aac1c3SLionel Sambuc 	tcp_seq	  th_ack;		/* acknowledgement number */
53f6aac1c3SLionel Sambuc #if BYTE_ORDER == LITTLE_ENDIAN
54f6aac1c3SLionel Sambuc 	/*LINTED non-portable bitfields*/
5501624e6fSBen Gras 	uint8_t  th_x2:4,		/* (unused) */
56f6aac1c3SLionel Sambuc 		  th_off:4;		/* data offset */
57f6aac1c3SLionel Sambuc #endif
58f6aac1c3SLionel Sambuc #if BYTE_ORDER == BIG_ENDIAN
59f6aac1c3SLionel Sambuc 	/*LINTED non-portable bitfields*/
6001624e6fSBen Gras 	uint8_t  th_off:4,		/* data offset */
61f6aac1c3SLionel Sambuc 		  th_x2:4;		/* (unused) */
62f6aac1c3SLionel Sambuc #endif
6301624e6fSBen Gras 	uint8_t  th_flags;
64f6aac1c3SLionel Sambuc #define	TH_FIN	  0x01
65f6aac1c3SLionel Sambuc #define	TH_SYN	  0x02
66f6aac1c3SLionel Sambuc #define	TH_RST	  0x04
67f6aac1c3SLionel Sambuc #define	TH_PUSH	  0x08
68f6aac1c3SLionel Sambuc #define	TH_ACK	  0x10
69f6aac1c3SLionel Sambuc #define	TH_URG	  0x20
70f6aac1c3SLionel Sambuc #define	TH_ECE	  0x40
71f6aac1c3SLionel Sambuc #define	TH_CWR	  0x80
7201624e6fSBen Gras 	uint16_t th_win;			/* window */
7301624e6fSBen Gras 	uint16_t th_sum;			/* checksum */
7401624e6fSBen Gras 	uint16_t th_urp;			/* urgent pointer */
75f6aac1c3SLionel Sambuc } __packed;
76f6aac1c3SLionel Sambuc 
77f6aac1c3SLionel Sambuc #define	TCPOPT_EOL		0
78f6aac1c3SLionel Sambuc #define	TCPOPT_NOP		1
79f6aac1c3SLionel Sambuc #define	TCPOPT_MAXSEG		2
80f6aac1c3SLionel Sambuc #define	   TCPOLEN_MAXSEG		4
81f6aac1c3SLionel Sambuc #define	TCPOPT_WINDOW		3
82f6aac1c3SLionel Sambuc #define	   TCPOLEN_WINDOW		3
83f6aac1c3SLionel Sambuc #define	TCPOPT_SACK_PERMITTED	4		/* Experimental */
84f6aac1c3SLionel Sambuc #define	   TCPOLEN_SACK_PERMITTED	2
85f6aac1c3SLionel Sambuc #define	TCPOPT_SACK		5		/* Experimental */
86f6aac1c3SLionel Sambuc #define	TCPOPT_TIMESTAMP	8
87f6aac1c3SLionel Sambuc #define	   TCPOLEN_TIMESTAMP		10
88f6aac1c3SLionel Sambuc #define	   TCPOLEN_TSTAMP_APPA		(TCPOLEN_TIMESTAMP+2) /* appendix A */
89f6aac1c3SLionel Sambuc 
90f6aac1c3SLionel Sambuc #define TCPOPT_TSTAMP_HDR	\
91f6aac1c3SLionel Sambuc     (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
92f6aac1c3SLionel Sambuc 
93f6aac1c3SLionel Sambuc #define	TCPOPT_SIGNATURE	19		/* Keyed MD5: RFC 2385 */
94f6aac1c3SLionel Sambuc #define	   TCPOLEN_SIGNATURE		18
95f6aac1c3SLionel Sambuc #define    TCPOLEN_SIGLEN		(TCPOLEN_SIGNATURE+2) /* padding */
96f6aac1c3SLionel Sambuc 
97f6aac1c3SLionel Sambuc #define MAX_TCPOPTLEN	40	/* max # bytes that go in options */
98f6aac1c3SLionel Sambuc 
99f6aac1c3SLionel Sambuc /*
100f6aac1c3SLionel Sambuc  * Default maximum segment size for TCP.
101f6aac1c3SLionel Sambuc  * This is defined by RFC 1112 Sec 4.2.2.6.
102f6aac1c3SLionel Sambuc  */
103f6aac1c3SLionel Sambuc #define	TCP_MSS		536
104f6aac1c3SLionel Sambuc 
105f6aac1c3SLionel Sambuc #define	TCP_MINMSS	216
106f6aac1c3SLionel Sambuc 
107f6aac1c3SLionel Sambuc #define	TCP_MAXWIN	65535	/* largest value for (unscaled) window */
108f6aac1c3SLionel Sambuc 
109f6aac1c3SLionel Sambuc #define	TCP_MAX_WINSHIFT	14	/* maximum window shift */
110f6aac1c3SLionel Sambuc 
111f6aac1c3SLionel Sambuc #define	TCP_MAXBURST	4	/* maximum segments in a burst */
112f6aac1c3SLionel Sambuc 
113f6aac1c3SLionel Sambuc #endif /* _NETBSD_SOURCE */
114f6aac1c3SLionel Sambuc 
115f6aac1c3SLionel Sambuc /*
116f6aac1c3SLionel Sambuc  * User-settable options (used with setsockopt).
117f6aac1c3SLionel Sambuc  */
118f6aac1c3SLionel Sambuc #define	TCP_NODELAY	1	/* don't delay send to coalesce packets */
11901624e6fSBen Gras #define	TCP_MAXSEG	2	/* set maximum segment size */
12001624e6fSBen Gras #define	TCP_KEEPIDLE	3
12101624e6fSBen Gras #ifdef notyet
12201624e6fSBen Gras #define	TCP_NOPUSH	4	/* reserved for FreeBSD compat */
12301624e6fSBen Gras #endif
12401624e6fSBen Gras #define	TCP_KEEPINTVL	5
12501624e6fSBen Gras #define	TCP_KEEPCNT	6
12601624e6fSBen Gras #define	TCP_KEEPINIT	7
12701624e6fSBen Gras #ifdef notyet
12801624e6fSBen Gras #define	TCP_NOOPT	8	/* reserved for FreeBSD compat */
12901624e6fSBen Gras #endif
130*0a6a1f1dSLionel Sambuc #define	TCP_INFO	9	/* retrieve tcp_info structure */
13101624e6fSBen Gras #define	TCP_MD5SIG	0x10	/* use MD5 digests (RFC2385) */
13201624e6fSBen Gras #define	TCP_CONGCTL	0x20	/* selected congestion control */
133f6aac1c3SLionel Sambuc 
134*0a6a1f1dSLionel Sambuc #define	TCPI_OPT_TIMESTAMPS	0x01
135*0a6a1f1dSLionel Sambuc #define	TCPI_OPT_SACK		0x02
136*0a6a1f1dSLionel Sambuc #define	TCPI_OPT_WSCALE		0x04
137*0a6a1f1dSLionel Sambuc #define	TCPI_OPT_ECN		0x08
138*0a6a1f1dSLionel Sambuc #define	TCPI_OPT_TOE		0x10
139*0a6a1f1dSLionel Sambuc 
140*0a6a1f1dSLionel Sambuc /*
141*0a6a1f1dSLionel Sambuc  * The TCP_INFO socket option comes from the Linux 2.6 TCP API, and permits
142*0a6a1f1dSLionel Sambuc  * the caller to query certain information about the state of a TCP
143*0a6a1f1dSLionel Sambuc  * connection.  We provide an overlapping set of fields with the Linux
144*0a6a1f1dSLionel Sambuc  * implementation, but since this is a fixed size structure, room has been
145*0a6a1f1dSLionel Sambuc  * left for growth.  In order to maximize potential future compatibility with
146*0a6a1f1dSLionel Sambuc  * the Linux API, the same variable names and order have been adopted, and
147*0a6a1f1dSLionel Sambuc  * padding left to make room for omitted fields in case they are added later.
148*0a6a1f1dSLionel Sambuc  *
149*0a6a1f1dSLionel Sambuc  * XXX: This is currently an unstable ABI/API, in that it is expected to
150*0a6a1f1dSLionel Sambuc  * change.
151*0a6a1f1dSLionel Sambuc  */
152*0a6a1f1dSLionel Sambuc struct tcp_info {
153*0a6a1f1dSLionel Sambuc 	uint8_t		tcpi_state; /* TCP FSM state. */
154*0a6a1f1dSLionel Sambuc 	uint8_t		__tcpi_ca_state;
155*0a6a1f1dSLionel Sambuc 	uint8_t		__tcpi_retransmits;
156*0a6a1f1dSLionel Sambuc 	uint8_t		__tcpi_probes;
157*0a6a1f1dSLionel Sambuc 	uint8_t		__tcpi_backoff;
158*0a6a1f1dSLionel Sambuc 	uint8_t		tcpi_options;	       /* Options enabled on conn. */
159*0a6a1f1dSLionel Sambuc 	uint8_t		tcpi_snd_wscale:4,	/* RFC1323 send shift value. */
160*0a6a1f1dSLionel Sambuc 			tcpi_rcv_wscale:4; /* RFC1323 recv shift value. */
161*0a6a1f1dSLionel Sambuc 
162*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_rto;		/* Retransmission timeout (usec). */
163*0a6a1f1dSLionel Sambuc 	uint32_t	__tcpi_ato;
164*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_snd_mss;		/* Max segment size for send. */
165*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_rcv_mss;		/* Max segment size for receive. */
166*0a6a1f1dSLionel Sambuc 
167*0a6a1f1dSLionel Sambuc 	uint32_t	__tcpi_unacked;
168*0a6a1f1dSLionel Sambuc 	uint32_t	__tcpi_sacked;
169*0a6a1f1dSLionel Sambuc 	uint32_t	__tcpi_lost;
170*0a6a1f1dSLionel Sambuc 	uint32_t	__tcpi_retrans;
171*0a6a1f1dSLionel Sambuc 	uint32_t	__tcpi_fackets;
172*0a6a1f1dSLionel Sambuc 
173*0a6a1f1dSLionel Sambuc 	/* Times; measurements in usecs. */
174*0a6a1f1dSLionel Sambuc 	uint32_t	__tcpi_last_data_sent;
175*0a6a1f1dSLionel Sambuc 	uint32_t	__tcpi_last_ack_sent;	/* Also unimpl. on Linux? */
176*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_last_data_recv;	/* Time since last recv data. */
177*0a6a1f1dSLionel Sambuc 	uint32_t	__tcpi_last_ack_recv;
178*0a6a1f1dSLionel Sambuc 
179*0a6a1f1dSLionel Sambuc 	/* Metrics; variable units. */
180*0a6a1f1dSLionel Sambuc 	uint32_t	__tcpi_pmtu;
181*0a6a1f1dSLionel Sambuc 	uint32_t	__tcpi_rcv_ssthresh;
182*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_rtt;		/* Smoothed RTT in usecs. */
183*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_rttvar;		/* RTT variance in usecs. */
184*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_snd_ssthresh;	/* Slow start threshold. */
185*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_snd_cwnd;		/* Send congestion window. */
186*0a6a1f1dSLionel Sambuc 	uint32_t	__tcpi_advmss;
187*0a6a1f1dSLionel Sambuc 	uint32_t	__tcpi_reordering;
188*0a6a1f1dSLionel Sambuc 
189*0a6a1f1dSLionel Sambuc 	uint32_t	__tcpi_rcv_rtt;
190*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_rcv_space;		/* Advertised recv window. */
191*0a6a1f1dSLionel Sambuc 
192*0a6a1f1dSLionel Sambuc 	/* FreeBSD/NetBSD extensions to tcp_info. */
193*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_snd_wnd;		/* Advertised send window. */
194*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_snd_bwnd;		/* No longer used. */
195*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_snd_nxt;		/* Next egress seqno */
196*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_rcv_nxt;		/* Next ingress seqno */
197*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_toe_tid;		/* HWTID for TOE endpoints */
198*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_snd_rexmitpack;	/* Retransmitted packets */
199*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_rcv_ooopack;	/* Out-of-order packets */
200*0a6a1f1dSLionel Sambuc 	uint32_t	tcpi_snd_zerowin;	/* Zero-sized windows sent */
201*0a6a1f1dSLionel Sambuc 
202*0a6a1f1dSLionel Sambuc 	/* Padding to grow without breaking ABI. */
203*0a6a1f1dSLionel Sambuc 	uint32_t	__tcpi_pad[26];		/* Padding. */
204*0a6a1f1dSLionel Sambuc };
205*0a6a1f1dSLionel Sambuc 
206f6aac1c3SLionel Sambuc #endif /* !_NETINET_TCP_H_ */
207