add TCP_FASTOPEN_CONNECT tcp socket option from linux v4.11
[musl] / include / netinet / tcp.h
1 #ifndef _NETINET_TCP_H
2 #define _NETINET_TCP_H
3
4 #include <features.h>
5
6 #define TCP_NODELAY 1
7 #define TCP_MAXSEG       2
8 #define TCP_CORK         3
9 #define TCP_KEEPIDLE     4
10 #define TCP_KEEPINTVL    5
11 #define TCP_KEEPCNT      6
12 #define TCP_SYNCNT       7
13 #define TCP_LINGER2      8
14 #define TCP_DEFER_ACCEPT 9
15 #define TCP_WINDOW_CLAMP 10
16 #define TCP_INFO         11
17 #define TCP_QUICKACK     12
18 #define TCP_CONGESTION   13
19 #define TCP_MD5SIG       14
20 #define TCP_THIN_LINEAR_TIMEOUTS 16
21 #define TCP_THIN_DUPACK  17
22 #define TCP_USER_TIMEOUT 18
23 #define TCP_REPAIR       19
24 #define TCP_REPAIR_QUEUE 20
25 #define TCP_QUEUE_SEQ    21
26 #define TCP_REPAIR_OPTIONS 22
27 #define TCP_FASTOPEN     23
28 #define TCP_TIMESTAMP    24
29 #define TCP_NOTSENT_LOWAT 25
30 #define TCP_CC_INFO      26
31 #define TCP_SAVE_SYN     27
32 #define TCP_SAVED_SYN    28
33 #define TCP_REPAIR_WINDOW 29
34 #define TCP_FASTOPEN_CONNECT 30
35
36 #define TCP_ESTABLISHED  1
37 #define TCP_SYN_SENT     2
38 #define TCP_SYN_RECV     3
39 #define TCP_FIN_WAIT1    4
40 #define TCP_FIN_WAIT2    5
41 #define TCP_TIME_WAIT    6
42 #define TCP_CLOSE        7
43 #define TCP_CLOSE_WAIT   8
44 #define TCP_LAST_ACK     9
45 #define TCP_LISTEN       10
46 #define TCP_CLOSING      11
47
48 enum {
49         TCP_NLA_PAD,
50         TCP_NLA_BUSY,
51         TCP_NLA_RWND_LIMITED,
52         TCP_NLA_SNDBUF_LIMITED,
53 };
54
55 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
56 #define TCPOPT_EOL              0
57 #define TCPOPT_NOP              1
58 #define TCPOPT_MAXSEG           2
59 #define TCPOPT_WINDOW           3
60 #define TCPOPT_SACK_PERMITTED   4
61 #define TCPOPT_SACK             5
62 #define TCPOPT_TIMESTAMP        8
63 #define TCPOLEN_SACK_PERMITTED  2
64 #define TCPOLEN_WINDOW          3
65 #define TCPOLEN_MAXSEG          4
66 #define TCPOLEN_TIMESTAMP       10
67
68 #define SOL_TCP 6
69
70 #include <sys/types.h>
71 #include <sys/socket.h>
72 #include <stdint.h>
73 #include <endian.h>
74
75 typedef uint32_t tcp_seq;
76
77 #define TH_FIN 0x01
78 #define TH_SYN 0x02
79 #define TH_RST 0x04
80 #define TH_PUSH 0x08
81 #define TH_ACK 0x10
82 #define TH_URG 0x20
83
84 struct tcphdr {
85 #ifdef _GNU_SOURCE
86 #ifdef __GNUC__
87         __extension__
88 #endif
89         union { struct {
90
91         uint16_t source;
92         uint16_t dest;
93         uint32_t seq;
94         uint32_t ack_seq;
95 #if __BYTE_ORDER == __LITTLE_ENDIAN
96         uint16_t res1:4;
97         uint16_t doff:4;
98         uint16_t fin:1;
99         uint16_t syn:1;
100         uint16_t rst:1;
101         uint16_t psh:1;
102         uint16_t ack:1;
103         uint16_t urg:1;
104         uint16_t res2:2;
105 #else
106         uint16_t doff:4;
107         uint16_t res1:4;
108         uint16_t res2:2;
109         uint16_t urg:1;
110         uint16_t ack:1;
111         uint16_t psh:1;
112         uint16_t rst:1;
113         uint16_t syn:1;
114         uint16_t fin:1;
115 #endif
116         uint16_t window;
117         uint16_t check;
118         uint16_t urg_ptr;
119
120         }; struct {
121 #endif
122
123         uint16_t th_sport;
124         uint16_t th_dport;
125         uint32_t th_seq;
126         uint32_t th_ack;
127 #if __BYTE_ORDER == __LITTLE_ENDIAN
128         uint8_t th_x2:4;
129         uint8_t th_off:4;
130 #else
131         uint8_t th_off:4;
132         uint8_t th_x2:4;
133 #endif
134         uint8_t th_flags;
135         uint16_t th_win;
136         uint16_t th_sum;
137         uint16_t th_urp;
138
139 #ifdef _GNU_SOURCE
140         }; };
141 #endif
142 };
143 #endif
144
145 #ifdef _GNU_SOURCE
146 #define TCPI_OPT_TIMESTAMPS     1
147 #define TCPI_OPT_SACK           2
148 #define TCPI_OPT_WSCALE         4
149 #define TCPI_OPT_ECN            8
150
151 #define TCP_CA_Open             0
152 #define TCP_CA_Disorder         1
153 #define TCP_CA_CWR              2
154 #define TCP_CA_Recovery         3
155 #define TCP_CA_Loss             4
156
157 struct tcp_info {
158         uint8_t tcpi_state;
159         uint8_t tcpi_ca_state;
160         uint8_t tcpi_retransmits;
161         uint8_t tcpi_probes;
162         uint8_t tcpi_backoff;
163         uint8_t tcpi_options;
164         uint8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
165         uint8_t tcpi_delivery_rate_app_limited : 1;
166         uint32_t tcpi_rto;
167         uint32_t tcpi_ato;
168         uint32_t tcpi_snd_mss;
169         uint32_t tcpi_rcv_mss;
170         uint32_t tcpi_unacked;
171         uint32_t tcpi_sacked;
172         uint32_t tcpi_lost;
173         uint32_t tcpi_retrans;
174         uint32_t tcpi_fackets;
175         uint32_t tcpi_last_data_sent;
176         uint32_t tcpi_last_ack_sent;
177         uint32_t tcpi_last_data_recv;
178         uint32_t tcpi_last_ack_recv;
179         uint32_t tcpi_pmtu;
180         uint32_t tcpi_rcv_ssthresh;
181         uint32_t tcpi_rtt;
182         uint32_t tcpi_rttvar;
183         uint32_t tcpi_snd_ssthresh;
184         uint32_t tcpi_snd_cwnd;
185         uint32_t tcpi_advmss;
186         uint32_t tcpi_reordering;
187         uint32_t tcpi_rcv_rtt;
188         uint32_t tcpi_rcv_space;
189         uint32_t tcpi_total_retrans;
190         uint64_t tcpi_pacing_rate;
191         uint64_t tcpi_max_pacing_rate;
192         uint64_t tcpi_bytes_acked;
193         uint64_t tcpi_bytes_received;
194         uint32_t tcpi_segs_out;
195         uint32_t tcpi_segs_in;
196         uint32_t tcpi_notsent_bytes;
197         uint32_t tcpi_min_rtt;
198         uint32_t tcpi_data_segs_in;
199         uint32_t tcpi_data_segs_out;
200         uint64_t tcpi_delivery_rate;
201         uint64_t tcpi_busy_time;
202         uint64_t tcpi_rwnd_limited;
203         uint64_t tcpi_sndbuf_limited;
204 };
205
206 #define TCP_MD5SIG_MAXKEYLEN    80
207
208 struct tcp_md5sig {
209         struct sockaddr_storage tcpm_addr;
210         uint16_t __tcpm_pad1;
211         uint16_t tcpm_keylen;
212         uint32_t __tcpm_pad2;
213         uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
214 };
215
216 struct tcp_repair_window {
217         uint32_t snd_wl1;
218         uint32_t snd_wnd;
219         uint32_t max_window;
220         uint32_t rcv_wnd;
221         uint32_t rcv_wup;
222 };
223
224 #endif
225
226 #endif