1/*
2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)tcp.h 8.1 (Berkeley) 6/10/93
30 */
31
32#ifndef _NETINET_TCP_H
33#define _NETINET_TCP_H 1
34
35#include <features.h>
36
37/*
38 * User-settable options (used with setsockopt).
39 */
40#define TCP_NODELAY 1 /* Don't delay send to coalesce packets */
41#define TCP_MAXSEG 2 /* Set maximum segment size */
42#define TCP_CORK 3 /* Control sending of partial frames */
43#define TCP_KEEPIDLE 4 /* Start keeplives after this period */
44#define TCP_KEEPINTVL 5 /* Interval between keepalives */
45#define TCP_KEEPCNT 6 /* Number of keepalives before death */
46#define TCP_SYNCNT 7 /* Number of SYN retransmits */
47#define TCP_LINGER2 8 /* Life time of orphaned FIN-WAIT-2 state */
48#define TCP_DEFER_ACCEPT 9 /* Wake up listener only when data arrive */
49#define TCP_WINDOW_CLAMP 10 /* Bound advertised window */
50#define TCP_INFO 11 /* Information about this connection. */
51#define TCP_QUICKACK 12 /* Bock/reenable quick ACKs. */
52#define TCP_CONGESTION 13 /* Congestion control algorithm. */
53#define TCP_MD5SIG 14 /* TCP MD5 Signature (RFC2385) */
54#define TCP_COOKIE_TRANSACTIONS 15 /* TCP Cookie Transactions */
55#define TCP_THIN_LINEAR_TIMEOUTS 16 /* Use linear timeouts for thin streams*/
56#define TCP_THIN_DUPACK 17 /* Fast retrans. after 1 dupack */
57#define TCP_USER_TIMEOUT 18 /* How long for loss retry before timeout */
58#define TCP_REPAIR 19 /* TCP sock is under repair right now */
59#define TCP_REPAIR_QUEUE 20 /* Set TCP queue to repair */
60#define TCP_QUEUE_SEQ 21 /* Set sequence number of repaired queue. */
61#define TCP_REPAIR_OPTIONS 22 /* Repair TCP connection options */
62#define TCP_FASTOPEN 23 /* Enable FastOpen on listeners */
63#define TCP_TIMESTAMP 24 /* TCP time stamp */
64#define TCP_NOTSENT_LOWAT 25 /* Limit number of unsent bytes in
65 write queue. */
66#define TCP_CC_INFO 26 /* Get Congestion Control
67 (optional) info. */
68#define TCP_SAVE_SYN 27 /* Record SYN headers for new
69 connections. */
70#define TCP_SAVED_SYN 28 /* Get SYN headers recorded for
71 connection. */
72
73#ifdef __USE_MISC
74# include <sys/types.h>
75# include <sys/socket.h>
76
77typedef u_int32_t tcp_seq;
78/*
79 * TCP header.
80 * Per RFC 793, September, 1981.
81 */
82struct tcphdr
83 {
84 __extension__ union
85 {
86 struct
87 {
88 u_int16_t th_sport; /* source port */
89 u_int16_t th_dport; /* destination port */
90 tcp_seq th_seq; /* sequence number */
91 tcp_seq th_ack; /* acknowledgement number */
92# if __BYTE_ORDER == __LITTLE_ENDIAN
93 u_int8_t th_x2:4; /* (unused) */
94 u_int8_t th_off:4; /* data offset */
95# endif
96# if __BYTE_ORDER == __BIG_ENDIAN
97 u_int8_t th_off:4; /* data offset */
98 u_int8_t th_x2:4; /* (unused) */
99# endif
100 u_int8_t th_flags;
101# define TH_FIN 0x01
102# define TH_SYN 0x02
103# define TH_RST 0x04
104# define TH_PUSH 0x08
105# define TH_ACK 0x10
106# define TH_URG 0x20
107 u_int16_t th_win; /* window */
108 u_int16_t th_sum; /* checksum */
109 u_int16_t th_urp; /* urgent pointer */
110 };
111 struct
112 {
113 u_int16_t source;
114 u_int16_t dest;
115 u_int32_t seq;
116 u_int32_t ack_seq;
117# if __BYTE_ORDER == __LITTLE_ENDIAN
118 u_int16_t res1:4;
119 u_int16_t doff:4;
120 u_int16_t fin:1;
121 u_int16_t syn:1;
122 u_int16_t rst:1;
123 u_int16_t psh:1;
124 u_int16_t ack:1;
125 u_int16_t urg:1;
126 u_int16_t res2:2;
127# elif __BYTE_ORDER == __BIG_ENDIAN
128 u_int16_t doff:4;
129 u_int16_t res1:4;
130 u_int16_t res2:2;
131 u_int16_t urg:1;
132 u_int16_t ack:1;
133 u_int16_t psh:1;
134 u_int16_t rst:1;
135 u_int16_t syn:1;
136 u_int16_t fin:1;
137# else
138# error "Adjust your <bits/endian.h> defines"
139# endif
140 u_int16_t window;
141 u_int16_t check;
142 u_int16_t urg_ptr;
143 };
144 };
145};
146
147enum
148{
149 TCP_ESTABLISHED = 1,
150 TCP_SYN_SENT,
151 TCP_SYN_RECV,
152 TCP_FIN_WAIT1,
153 TCP_FIN_WAIT2,
154 TCP_TIME_WAIT,
155 TCP_CLOSE,
156 TCP_CLOSE_WAIT,
157 TCP_LAST_ACK,
158 TCP_LISTEN,
159 TCP_CLOSING /* now a valid state */
160};
161
162# define TCPOPT_EOL 0
163# define TCPOPT_NOP 1
164# define TCPOPT_MAXSEG 2
165# define TCPOLEN_MAXSEG 4
166# define TCPOPT_WINDOW 3
167# define TCPOLEN_WINDOW 3
168# define TCPOPT_SACK_PERMITTED 4 /* Experimental */
169# define TCPOLEN_SACK_PERMITTED 2
170# define TCPOPT_SACK 5 /* Experimental */
171# define TCPOPT_TIMESTAMP 8
172# define TCPOLEN_TIMESTAMP 10
173# define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */
174
175# define TCPOPT_TSTAMP_HDR \
176 (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
177
178/*
179 * Default maximum segment size for TCP.
180 * With an IP MSS of 576, this is 536,
181 * but 512 is probably more convenient.
182 * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
183 */
184# define TCP_MSS 512
185
186# define TCP_MAXWIN 65535 /* largest value for (unscaled) window */
187
188# define TCP_MAX_WINSHIFT 14 /* maximum window shift */
189
190# define SOL_TCP 6 /* TCP level */
191
192
193# define TCPI_OPT_TIMESTAMPS 1
194# define TCPI_OPT_SACK 2
195# define TCPI_OPT_WSCALE 4
196# define TCPI_OPT_ECN 8 /* ECN was negociated at TCP session init */
197# define TCPI_OPT_ECN_SEEN 16 /* we received at least one packet with ECT */
198# define TCPI_OPT_SYN_DATA 32 /* SYN-ACK acked data in SYN sent or rcvd */
199
200/* Values for tcpi_state. */
201enum tcp_ca_state
202{
203 TCP_CA_Open = 0,
204 TCP_CA_Disorder = 1,
205 TCP_CA_CWR = 2,
206 TCP_CA_Recovery = 3,
207 TCP_CA_Loss = 4
208};
209
210struct tcp_info
211{
212 u_int8_t tcpi_state;
213 u_int8_t tcpi_ca_state;
214 u_int8_t tcpi_retransmits;
215 u_int8_t tcpi_probes;
216 u_int8_t tcpi_backoff;
217 u_int8_t tcpi_options;
218 u_int8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
219
220 u_int32_t tcpi_rto;
221 u_int32_t tcpi_ato;
222 u_int32_t tcpi_snd_mss;
223 u_int32_t tcpi_rcv_mss;
224
225 u_int32_t tcpi_unacked;
226 u_int32_t tcpi_sacked;
227 u_int32_t tcpi_lost;
228 u_int32_t tcpi_retrans;
229 u_int32_t tcpi_fackets;
230
231 /* Times. */
232 u_int32_t tcpi_last_data_sent;
233 u_int32_t tcpi_last_ack_sent; /* Not remembered, sorry. */
234 u_int32_t tcpi_last_data_recv;
235 u_int32_t tcpi_last_ack_recv;
236
237 /* Metrics. */
238 u_int32_t tcpi_pmtu;
239 u_int32_t tcpi_rcv_ssthresh;
240 u_int32_t tcpi_rtt;
241 u_int32_t tcpi_rttvar;
242 u_int32_t tcpi_snd_ssthresh;
243 u_int32_t tcpi_snd_cwnd;
244 u_int32_t tcpi_advmss;
245 u_int32_t tcpi_reordering;
246
247 u_int32_t tcpi_rcv_rtt;
248 u_int32_t tcpi_rcv_space;
249
250 u_int32_t tcpi_total_retrans;
251};
252
253
254/* For TCP_MD5SIG socket option. */
255#define TCP_MD5SIG_MAXKEYLEN 80
256
257struct tcp_md5sig
258{
259 struct sockaddr_storage tcpm_addr; /* Address associated. */
260 u_int16_t __tcpm_pad1; /* Zero. */
261 u_int16_t tcpm_keylen; /* Key length. */
262 u_int32_t __tcpm_pad2; /* Zero. */
263 u_int8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN]; /* Key (binary). */
264};
265
266/* For socket repair options. */
267struct tcp_repair_opt
268{
269 u_int32_t opt_code;
270 u_int32_t opt_val;
271};
272
273/* Queue to repair, for TCP_REPAIR_QUEUE. */
274enum
275{
276 TCP_NO_QUEUE,
277 TCP_RECV_QUEUE,
278 TCP_SEND_QUEUE,
279 TCP_QUEUES_NR,
280};
281
282/* For cookie transactions socket options. */
283#define TCP_COOKIE_MIN 8 /* 64-bits */
284#define TCP_COOKIE_MAX 16 /* 128-bits */
285#define TCP_COOKIE_PAIR_SIZE (2*TCP_COOKIE_MAX)
286
287/* Flags for both getsockopt and setsockopt */
288#define TCP_COOKIE_IN_ALWAYS (1 << 0) /* Discard SYN without cookie */
289#define TCP_COOKIE_OUT_NEVER (1 << 1) /* Prohibit outgoing cookies,
290 * supercedes everything. */
291
292/* Flags for getsockopt */
293#define TCP_S_DATA_IN (1 << 2) /* Was data received? */
294#define TCP_S_DATA_OUT (1 << 3) /* Was data sent? */
295
296#define TCP_MSS_DEFAULT 536U /* IPv4 (RFC1122, RFC2581) */
297#define TCP_MSS_DESIRED 1220U /* IPv6 (tunneled), EDNS0 (RFC3226) */
298
299struct tcp_cookie_transactions
300{
301 u_int16_t tcpct_flags;
302 u_int8_t __tcpct_pad1;
303 u_int8_t tcpct_cookie_desired;
304 u_int16_t tcpct_s_data_desired;
305 u_int16_t tcpct_used;
306 u_int8_t tcpct_value[TCP_MSS_DEFAULT];
307};
308
309#endif /* Misc. */
310
311#endif /* netinet/tcp.h */
312