Debian Codegraph @

share/libc/netinet/tcp.h

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