xref: /linux/include/uapi/linux/tcp.h (revision 1c885808e45601b2b6f68b30ac1d999e10b6f606)
1607ca46eSDavid Howells /*
2607ca46eSDavid Howells  * INET		An implementation of the TCP/IP protocol suite for the LINUX
3607ca46eSDavid Howells  *		operating system.  INET is implemented using the  BSD Socket
4607ca46eSDavid Howells  *		interface as the means of communication with the user level.
5607ca46eSDavid Howells  *
6607ca46eSDavid Howells  *		Definitions for the TCP protocol.
7607ca46eSDavid Howells  *
8607ca46eSDavid Howells  * Version:	@(#)tcp.h	1.0.2	04/28/93
9607ca46eSDavid Howells  *
10607ca46eSDavid Howells  * Author:	Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
11607ca46eSDavid Howells  *
12607ca46eSDavid Howells  *		This program is free software; you can redistribute it and/or
13607ca46eSDavid Howells  *		modify it under the terms of the GNU General Public License
14607ca46eSDavid Howells  *		as published by the Free Software Foundation; either version
15607ca46eSDavid Howells  *		2 of the License, or (at your option) any later version.
16607ca46eSDavid Howells  */
17607ca46eSDavid Howells #ifndef _UAPI_LINUX_TCP_H
18607ca46eSDavid Howells #define _UAPI_LINUX_TCP_H
19607ca46eSDavid Howells 
20607ca46eSDavid Howells #include <linux/types.h>
21607ca46eSDavid Howells #include <asm/byteorder.h>
22607ca46eSDavid Howells #include <linux/socket.h>
23607ca46eSDavid Howells 
24607ca46eSDavid Howells struct tcphdr {
25607ca46eSDavid Howells 	__be16	source;
26607ca46eSDavid Howells 	__be16	dest;
27607ca46eSDavid Howells 	__be32	seq;
28607ca46eSDavid Howells 	__be32	ack_seq;
29607ca46eSDavid Howells #if defined(__LITTLE_ENDIAN_BITFIELD)
30607ca46eSDavid Howells 	__u16	res1:4,
31607ca46eSDavid Howells 		doff:4,
32607ca46eSDavid Howells 		fin:1,
33607ca46eSDavid Howells 		syn:1,
34607ca46eSDavid Howells 		rst:1,
35607ca46eSDavid Howells 		psh:1,
36607ca46eSDavid Howells 		ack:1,
37607ca46eSDavid Howells 		urg:1,
38607ca46eSDavid Howells 		ece:1,
39607ca46eSDavid Howells 		cwr:1;
40607ca46eSDavid Howells #elif defined(__BIG_ENDIAN_BITFIELD)
41607ca46eSDavid Howells 	__u16	doff:4,
42607ca46eSDavid Howells 		res1:4,
43607ca46eSDavid Howells 		cwr:1,
44607ca46eSDavid Howells 		ece:1,
45607ca46eSDavid Howells 		urg:1,
46607ca46eSDavid Howells 		ack:1,
47607ca46eSDavid Howells 		psh:1,
48607ca46eSDavid Howells 		rst:1,
49607ca46eSDavid Howells 		syn:1,
50607ca46eSDavid Howells 		fin:1;
51607ca46eSDavid Howells #else
52607ca46eSDavid Howells #error	"Adjust your <asm/byteorder.h> defines"
53607ca46eSDavid Howells #endif
54607ca46eSDavid Howells 	__be16	window;
55607ca46eSDavid Howells 	__sum16	check;
56607ca46eSDavid Howells 	__be16	urg_ptr;
57607ca46eSDavid Howells };
58607ca46eSDavid Howells 
59607ca46eSDavid Howells /*
60607ca46eSDavid Howells  *	The union cast uses a gcc extension to avoid aliasing problems
61607ca46eSDavid Howells  *  (union is compatible to any of its members)
62607ca46eSDavid Howells  *  This means this part of the code is -fstrict-aliasing safe now.
63607ca46eSDavid Howells  */
64607ca46eSDavid Howells union tcp_word_hdr {
65607ca46eSDavid Howells 	struct tcphdr hdr;
66607ca46eSDavid Howells 	__be32 		  words[5];
67607ca46eSDavid Howells };
68607ca46eSDavid Howells 
69607ca46eSDavid Howells #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3])
70607ca46eSDavid Howells 
71607ca46eSDavid Howells enum {
72607ca46eSDavid Howells 	TCP_FLAG_CWR = __constant_cpu_to_be32(0x00800000),
73607ca46eSDavid Howells 	TCP_FLAG_ECE = __constant_cpu_to_be32(0x00400000),
74607ca46eSDavid Howells 	TCP_FLAG_URG = __constant_cpu_to_be32(0x00200000),
75607ca46eSDavid Howells 	TCP_FLAG_ACK = __constant_cpu_to_be32(0x00100000),
76607ca46eSDavid Howells 	TCP_FLAG_PSH = __constant_cpu_to_be32(0x00080000),
77607ca46eSDavid Howells 	TCP_FLAG_RST = __constant_cpu_to_be32(0x00040000),
78607ca46eSDavid Howells 	TCP_FLAG_SYN = __constant_cpu_to_be32(0x00020000),
79607ca46eSDavid Howells 	TCP_FLAG_FIN = __constant_cpu_to_be32(0x00010000),
80607ca46eSDavid Howells 	TCP_RESERVED_BITS = __constant_cpu_to_be32(0x0F000000),
81607ca46eSDavid Howells 	TCP_DATA_OFFSET = __constant_cpu_to_be32(0xF0000000)
82607ca46eSDavid Howells };
83607ca46eSDavid Howells 
84607ca46eSDavid Howells /*
85607ca46eSDavid Howells  * TCP general constants
86607ca46eSDavid Howells  */
87607ca46eSDavid Howells #define TCP_MSS_DEFAULT		 536U	/* IPv4 (RFC1122, RFC2581) */
88607ca46eSDavid Howells #define TCP_MSS_DESIRED		1220U	/* IPv6 (tunneled), EDNS0 (RFC3226) */
89607ca46eSDavid Howells 
90607ca46eSDavid Howells /* TCP socket options */
91607ca46eSDavid Howells #define TCP_NODELAY		1	/* Turn off Nagle's algorithm. */
92607ca46eSDavid Howells #define TCP_MAXSEG		2	/* Limit MSS */
93607ca46eSDavid Howells #define TCP_CORK		3	/* Never send partially complete segments */
94607ca46eSDavid Howells #define TCP_KEEPIDLE		4	/* Start keeplives after this period */
95607ca46eSDavid Howells #define TCP_KEEPINTVL		5	/* Interval between keepalives */
96607ca46eSDavid Howells #define TCP_KEEPCNT		6	/* Number of keepalives before death */
97607ca46eSDavid Howells #define TCP_SYNCNT		7	/* Number of SYN retransmits */
98607ca46eSDavid Howells #define TCP_LINGER2		8	/* Life time of orphaned FIN-WAIT-2 state */
99607ca46eSDavid Howells #define TCP_DEFER_ACCEPT	9	/* Wake up listener only when data arrive */
100607ca46eSDavid Howells #define TCP_WINDOW_CLAMP	10	/* Bound advertised window */
101607ca46eSDavid Howells #define TCP_INFO		11	/* Information about this connection. */
102607ca46eSDavid Howells #define TCP_QUICKACK		12	/* Block/reenable quick acks */
103607ca46eSDavid Howells #define TCP_CONGESTION		13	/* Congestion control algorithm */
104607ca46eSDavid Howells #define TCP_MD5SIG		14	/* TCP MD5 Signature (RFC2385) */
105607ca46eSDavid Howells #define TCP_THIN_LINEAR_TIMEOUTS 16      /* Use linear timeouts for thin streams*/
106607ca46eSDavid Howells #define TCP_THIN_DUPACK         17      /* Fast retrans. after 1 dupack */
107607ca46eSDavid Howells #define TCP_USER_TIMEOUT	18	/* How long for loss retry before timeout */
108607ca46eSDavid Howells #define TCP_REPAIR		19	/* TCP sock is under repair right now */
109607ca46eSDavid Howells #define TCP_REPAIR_QUEUE	20
110607ca46eSDavid Howells #define TCP_QUEUE_SEQ		21
111607ca46eSDavid Howells #define TCP_REPAIR_OPTIONS	22
112607ca46eSDavid Howells #define TCP_FASTOPEN		23	/* Enable FastOpen on listeners */
11393be6ce0SAndrey Vagin #define TCP_TIMESTAMP		24
114c9bee3b7SEric Dumazet #define TCP_NOTSENT_LOWAT	25	/* limit number of unsent bytes in write queue */
1156e9250f5SEric Dumazet #define TCP_CC_INFO		26	/* Get Congestion Control (optional) info */
116cd8ae852SEric Dumazet #define TCP_SAVE_SYN		27	/* Record SYN headers for new connections */
117cd8ae852SEric Dumazet #define TCP_SAVED_SYN		28	/* Get SYN headers recorded for connection */
118b1ed4c4fSAndrey Vagin #define TCP_REPAIR_WINDOW	29	/* Get/set window parameters */
119607ca46eSDavid Howells 
120607ca46eSDavid Howells struct tcp_repair_opt {
121607ca46eSDavid Howells 	__u32	opt_code;
122607ca46eSDavid Howells 	__u32	opt_val;
123607ca46eSDavid Howells };
124607ca46eSDavid Howells 
125b1ed4c4fSAndrey Vagin struct tcp_repair_window {
126b1ed4c4fSAndrey Vagin 	__u32	snd_wl1;
127b1ed4c4fSAndrey Vagin 	__u32	snd_wnd;
128b1ed4c4fSAndrey Vagin 	__u32	max_window;
129b1ed4c4fSAndrey Vagin 
130b1ed4c4fSAndrey Vagin 	__u32	rcv_wnd;
131b1ed4c4fSAndrey Vagin 	__u32	rcv_wup;
132b1ed4c4fSAndrey Vagin };
133b1ed4c4fSAndrey Vagin 
134607ca46eSDavid Howells enum {
135607ca46eSDavid Howells 	TCP_NO_QUEUE,
136607ca46eSDavid Howells 	TCP_RECV_QUEUE,
137607ca46eSDavid Howells 	TCP_SEND_QUEUE,
138607ca46eSDavid Howells 	TCP_QUEUES_NR,
139607ca46eSDavid Howells };
140607ca46eSDavid Howells 
141607ca46eSDavid Howells /* for TCP_INFO socket option */
142607ca46eSDavid Howells #define TCPI_OPT_TIMESTAMPS	1
143607ca46eSDavid Howells #define TCPI_OPT_SACK		2
144607ca46eSDavid Howells #define TCPI_OPT_WSCALE		4
145607ca46eSDavid Howells #define TCPI_OPT_ECN		8 /* ECN was negociated at TCP session init */
146607ca46eSDavid Howells #define TCPI_OPT_ECN_SEEN	16 /* we received at least one packet with ECT */
1476f73601eSYuchung Cheng #define TCPI_OPT_SYN_DATA	32 /* SYN-ACK acked data in SYN sent or rcvd */
148607ca46eSDavid Howells 
149607ca46eSDavid Howells enum tcp_ca_state {
150607ca46eSDavid Howells 	TCP_CA_Open = 0,
151607ca46eSDavid Howells #define TCPF_CA_Open	(1<<TCP_CA_Open)
152607ca46eSDavid Howells 	TCP_CA_Disorder = 1,
153607ca46eSDavid Howells #define TCPF_CA_Disorder (1<<TCP_CA_Disorder)
154607ca46eSDavid Howells 	TCP_CA_CWR = 2,
155607ca46eSDavid Howells #define TCPF_CA_CWR	(1<<TCP_CA_CWR)
156607ca46eSDavid Howells 	TCP_CA_Recovery = 3,
157607ca46eSDavid Howells #define TCPF_CA_Recovery (1<<TCP_CA_Recovery)
158607ca46eSDavid Howells 	TCP_CA_Loss = 4
159607ca46eSDavid Howells #define TCPF_CA_Loss	(1<<TCP_CA_Loss)
160607ca46eSDavid Howells };
161607ca46eSDavid Howells 
162607ca46eSDavid Howells struct tcp_info {
163607ca46eSDavid Howells 	__u8	tcpi_state;
164607ca46eSDavid Howells 	__u8	tcpi_ca_state;
165607ca46eSDavid Howells 	__u8	tcpi_retransmits;
166607ca46eSDavid Howells 	__u8	tcpi_probes;
167607ca46eSDavid Howells 	__u8	tcpi_backoff;
168607ca46eSDavid Howells 	__u8	tcpi_options;
169607ca46eSDavid Howells 	__u8	tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
170eb8329e0SYuchung Cheng 	__u8	tcpi_delivery_rate_app_limited:1;
171607ca46eSDavid Howells 
172607ca46eSDavid Howells 	__u32	tcpi_rto;
173607ca46eSDavid Howells 	__u32	tcpi_ato;
174607ca46eSDavid Howells 	__u32	tcpi_snd_mss;
175607ca46eSDavid Howells 	__u32	tcpi_rcv_mss;
176607ca46eSDavid Howells 
177607ca46eSDavid Howells 	__u32	tcpi_unacked;
178607ca46eSDavid Howells 	__u32	tcpi_sacked;
179607ca46eSDavid Howells 	__u32	tcpi_lost;
180607ca46eSDavid Howells 	__u32	tcpi_retrans;
181607ca46eSDavid Howells 	__u32	tcpi_fackets;
182607ca46eSDavid Howells 
183607ca46eSDavid Howells 	/* Times. */
184607ca46eSDavid Howells 	__u32	tcpi_last_data_sent;
185607ca46eSDavid Howells 	__u32	tcpi_last_ack_sent;     /* Not remembered, sorry. */
186607ca46eSDavid Howells 	__u32	tcpi_last_data_recv;
187607ca46eSDavid Howells 	__u32	tcpi_last_ack_recv;
188607ca46eSDavid Howells 
189607ca46eSDavid Howells 	/* Metrics. */
190607ca46eSDavid Howells 	__u32	tcpi_pmtu;
191607ca46eSDavid Howells 	__u32	tcpi_rcv_ssthresh;
192607ca46eSDavid Howells 	__u32	tcpi_rtt;
193607ca46eSDavid Howells 	__u32	tcpi_rttvar;
194607ca46eSDavid Howells 	__u32	tcpi_snd_ssthresh;
195607ca46eSDavid Howells 	__u32	tcpi_snd_cwnd;
196607ca46eSDavid Howells 	__u32	tcpi_advmss;
197607ca46eSDavid Howells 	__u32	tcpi_reordering;
198607ca46eSDavid Howells 
199607ca46eSDavid Howells 	__u32	tcpi_rcv_rtt;
200607ca46eSDavid Howells 	__u32	tcpi_rcv_space;
201607ca46eSDavid Howells 
202607ca46eSDavid Howells 	__u32	tcpi_total_retrans;
203977cb0ecSEric Dumazet 
204977cb0ecSEric Dumazet 	__u64	tcpi_pacing_rate;
205977cb0ecSEric Dumazet 	__u64	tcpi_max_pacing_rate;
2060df48c26SEric Dumazet 	__u64	tcpi_bytes_acked;    /* RFC4898 tcpEStatsAppHCThruOctetsAcked */
207bdd1f9edSEric Dumazet 	__u64	tcpi_bytes_received; /* RFC4898 tcpEStatsAppHCThruOctetsReceived */
2082efd055cSMarcelo Ricardo Leitner 	__u32	tcpi_segs_out;	     /* RFC4898 tcpEStatsPerfSegsOut */
2092efd055cSMarcelo Ricardo Leitner 	__u32	tcpi_segs_in;	     /* RFC4898 tcpEStatsPerfSegsIn */
210cd9b2660SEric Dumazet 
211cd9b2660SEric Dumazet 	__u32	tcpi_notsent_bytes;
212cd9b2660SEric Dumazet 	__u32	tcpi_min_rtt;
213a44d6eacSMartin KaFai Lau 	__u32	tcpi_data_segs_in;	/* RFC4898 tcpEStatsDataSegsIn */
214a44d6eacSMartin KaFai Lau 	__u32	tcpi_data_segs_out;	/* RFC4898 tcpEStatsDataSegsOut */
215eb8329e0SYuchung Cheng 
216eb8329e0SYuchung Cheng 	__u64   tcpi_delivery_rate;
217efd90174SFrancis Yan 
218efd90174SFrancis Yan 	__u64	tcpi_busy_time;      /* Time (usec) busy sending data */
219efd90174SFrancis Yan 	__u64	tcpi_rwnd_limited;   /* Time (usec) limited by receive window */
220efd90174SFrancis Yan 	__u64	tcpi_sndbuf_limited; /* Time (usec) limited by send buffer */
221607ca46eSDavid Howells };
222607ca46eSDavid Howells 
223*1c885808SFrancis Yan /* netlink attributes types for SCM_TIMESTAMPING_OPT_STATS */
224*1c885808SFrancis Yan enum {
225*1c885808SFrancis Yan 	TCP_NLA_PAD,
226*1c885808SFrancis Yan 	TCP_NLA_BUSY,		/* Time (usec) busy sending data */
227*1c885808SFrancis Yan 	TCP_NLA_RWND_LIMITED,	/* Time (usec) limited by receive window */
228*1c885808SFrancis Yan 	TCP_NLA_SNDBUF_LIMITED,	/* Time (usec) limited by send buffer */
229*1c885808SFrancis Yan };
230*1c885808SFrancis Yan 
231607ca46eSDavid Howells /* for TCP_MD5SIG socket option */
232607ca46eSDavid Howells #define TCP_MD5SIG_MAXKEYLEN	80
233607ca46eSDavid Howells 
234607ca46eSDavid Howells struct tcp_md5sig {
235607ca46eSDavid Howells 	struct __kernel_sockaddr_storage tcpm_addr;	/* address associated */
236607ca46eSDavid Howells 	__u16	__tcpm_pad1;				/* zero */
237607ca46eSDavid Howells 	__u16	tcpm_keylen;				/* key length */
238607ca46eSDavid Howells 	__u32	__tcpm_pad2;				/* zero */
239607ca46eSDavid Howells 	__u8	tcpm_key[TCP_MD5SIG_MAXKEYLEN];		/* key (binary) */
240607ca46eSDavid Howells };
241607ca46eSDavid Howells 
242607ca46eSDavid Howells #endif /* _UAPI_LINUX_TCP_H */
243