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#define TCP_ULP          31
 36#define TCP_MD5SIG_EXT   32
 37#define TCP_FASTOPEN_KEY 33
 38#define TCP_FASTOPEN_NO_COOKIE 34
 39#define TCP_ZEROCOPY_RECEIVE   35
 40#define TCP_INQ          36
 41#define TCP_TX_DELAY     37
 42
 43#define TCP_CM_INQ TCP_INQ
 44
 45#define TCP_ESTABLISHED  1
 46#define TCP_SYN_SENT     2
 47#define TCP_SYN_RECV     3
 48#define TCP_FIN_WAIT1    4
 49#define TCP_FIN_WAIT2    5
 50#define TCP_TIME_WAIT    6
 51#define TCP_CLOSE        7
 52#define TCP_CLOSE_WAIT   8
 53#define TCP_LAST_ACK     9
 54#define TCP_LISTEN       10
 55#define TCP_CLOSING      11
 56
 57enum {
 58	TCP_NLA_PAD,
 59	TCP_NLA_BUSY,
 60	TCP_NLA_RWND_LIMITED,
 61	TCP_NLA_SNDBUF_LIMITED,
 62	TCP_NLA_DATA_SEGS_OUT,
 63	TCP_NLA_TOTAL_RETRANS,
 64	TCP_NLA_PACING_RATE,
 65	TCP_NLA_DELIVERY_RATE,
 66	TCP_NLA_SND_CWND,
 67	TCP_NLA_REORDERING,
 68	TCP_NLA_MIN_RTT,
 69	TCP_NLA_RECUR_RETRANS,
 70	TCP_NLA_DELIVERY_RATE_APP_LMT,
 71	TCP_NLA_SNDQ_SIZE,
 72	TCP_NLA_CA_STATE,
 73	TCP_NLA_SND_SSTHRESH,
 74	TCP_NLA_DELIVERED,
 75	TCP_NLA_DELIVERED_CE,
 76	TCP_NLA_BYTES_SENT,
 77	TCP_NLA_BYTES_RETRANS,
 78	TCP_NLA_DSACK_DUPS,
 79	TCP_NLA_REORD_SEEN,
 80	TCP_NLA_SRTT,
 81	TCP_NLA_TIMEOUT_REHASH,
 82	TCP_NLA_BYTES_NOTSENT,
 83	TCP_NLA_EDT,
 84	TCP_NLA_TTL,
 85};
 86
 87#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 88#define TCPOPT_EOL              0
 89#define TCPOPT_NOP              1
 90#define TCPOPT_MAXSEG           2
 91#define TCPOPT_WINDOW           3
 92#define TCPOPT_SACK_PERMITTED   4
 93#define TCPOPT_SACK             5
 94#define TCPOPT_TIMESTAMP        8
 95#define TCPOLEN_SACK_PERMITTED  2
 96#define TCPOLEN_WINDOW          3
 97#define TCPOLEN_MAXSEG          4
 98#define TCPOLEN_TIMESTAMP       10
 99
100#define SOL_TCP 6
101
102#include <sys/types.h>
103#include <sys/socket.h>
104#include <stdint.h>
105
106typedef uint32_t tcp_seq;
107
108#define TH_FIN 0x01
109#define TH_SYN 0x02
110#define TH_RST 0x04
111#define TH_PUSH 0x08
112#define TH_ACK 0x10
113#define TH_URG 0x20
114
115struct tcphdr {
116#ifdef _GNU_SOURCE
117#ifdef __GNUC__
118	__extension__
119#endif
120	union { struct {
121
122	uint16_t source;
123	uint16_t dest;
124	uint32_t seq;
125	uint32_t ack_seq;
126#if __BYTE_ORDER == __LITTLE_ENDIAN
127	uint16_t res1:4;
128	uint16_t doff:4;
129	uint16_t fin:1;
130	uint16_t syn:1;
131	uint16_t rst:1;
132	uint16_t psh:1;
133	uint16_t ack:1;
134	uint16_t urg:1;
135	uint16_t res2:2;
136#else
137	uint16_t doff:4;
138	uint16_t res1:4;
139	uint16_t res2:2;
140	uint16_t urg:1;
141	uint16_t ack:1;
142	uint16_t psh:1;
143	uint16_t rst:1;
144	uint16_t syn:1;
145	uint16_t fin:1;
146#endif
147	uint16_t window;
148	uint16_t check;
149	uint16_t urg_ptr;
150
151	}; struct {
152#endif
153
154	uint16_t th_sport;
155	uint16_t th_dport;
156	uint32_t th_seq;
157	uint32_t th_ack;
158#if __BYTE_ORDER == __LITTLE_ENDIAN
159	uint8_t th_x2:4;
160	uint8_t th_off:4;
161#else
162	uint8_t th_off:4;
163	uint8_t th_x2:4;
164#endif
165	uint8_t th_flags;
166	uint16_t th_win;
167	uint16_t th_sum;
168	uint16_t th_urp;
169
170#ifdef _GNU_SOURCE
171	}; };
172#endif
173};
174#endif
175
176#ifdef _GNU_SOURCE
177#define TCPI_OPT_TIMESTAMPS	1
178#define TCPI_OPT_SACK		2
179#define TCPI_OPT_WSCALE		4
180#define TCPI_OPT_ECN		8
181
182#define TCP_CA_Open		0
183#define TCP_CA_Disorder		1
184#define TCP_CA_CWR		2
185#define TCP_CA_Recovery		3
186#define TCP_CA_Loss		4
187
188enum tcp_fastopen_client_fail {
189	TFO_STATUS_UNSPEC,
190	TFO_COOKIE_UNAVAILABLE,
191	TFO_DATA_NOT_ACKED,
192	TFO_SYN_RETRANSMITTED,
193};
194
195struct tcp_info {
196	uint8_t tcpi_state;
197	uint8_t tcpi_ca_state;
198	uint8_t tcpi_retransmits;
199	uint8_t tcpi_probes;
200	uint8_t tcpi_backoff;
201	uint8_t tcpi_options;
202	uint8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
203	uint8_t tcpi_delivery_rate_app_limited : 1, tcpi_fastopen_client_fail : 2;
204	uint32_t tcpi_rto;
205	uint32_t tcpi_ato;
206	uint32_t tcpi_snd_mss;
207	uint32_t tcpi_rcv_mss;
208	uint32_t tcpi_unacked;
209	uint32_t tcpi_sacked;
210	uint32_t tcpi_lost;
211	uint32_t tcpi_retrans;
212	uint32_t tcpi_fackets;
213	uint32_t tcpi_last_data_sent;
214	uint32_t tcpi_last_ack_sent;
215	uint32_t tcpi_last_data_recv;
216	uint32_t tcpi_last_ack_recv;
217	uint32_t tcpi_pmtu;
218	uint32_t tcpi_rcv_ssthresh;
219	uint32_t tcpi_rtt;
220	uint32_t tcpi_rttvar;
221	uint32_t tcpi_snd_ssthresh;
222	uint32_t tcpi_snd_cwnd;
223	uint32_t tcpi_advmss;
224	uint32_t tcpi_reordering;
225	uint32_t tcpi_rcv_rtt;
226	uint32_t tcpi_rcv_space;
227	uint32_t tcpi_total_retrans;
228	uint64_t tcpi_pacing_rate;
229	uint64_t tcpi_max_pacing_rate;
230	uint64_t tcpi_bytes_acked;
231	uint64_t tcpi_bytes_received;
232	uint32_t tcpi_segs_out;
233	uint32_t tcpi_segs_in;
234	uint32_t tcpi_notsent_bytes;
235	uint32_t tcpi_min_rtt;
236	uint32_t tcpi_data_segs_in;
237	uint32_t tcpi_data_segs_out;
238	uint64_t tcpi_delivery_rate;
239	uint64_t tcpi_busy_time;
240	uint64_t tcpi_rwnd_limited;
241	uint64_t tcpi_sndbuf_limited;
242	uint32_t tcpi_delivered;
243	uint32_t tcpi_delivered_ce;
244	uint64_t tcpi_bytes_sent;
245	uint64_t tcpi_bytes_retrans;
246	uint32_t tcpi_dsack_dups;
247	uint32_t tcpi_reord_seen;
248	uint32_t tcpi_rcv_ooopack;
249	uint32_t tcpi_snd_wnd;
250};
251
252#define TCP_MD5SIG_MAXKEYLEN    80
253
254#define TCP_MD5SIG_FLAG_PREFIX  0x1
255#define TCP_MD5SIG_FLAG_IFINDEX 0x2
256
257struct tcp_md5sig {
258	struct sockaddr_storage tcpm_addr;
259	uint8_t tcpm_flags;
260	uint8_t tcpm_prefixlen;
261	uint16_t tcpm_keylen;
262	int tcpm_ifindex;
263	uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
264};
265
266struct tcp_diag_md5sig {
267	uint8_t tcpm_family;
268	uint8_t tcpm_prefixlen;
269	uint16_t tcpm_keylen;
270	uint32_t tcpm_addr[4];
271	uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
272};
273
274#define TCP_REPAIR_ON		1
275#define TCP_REPAIR_OFF		0
276#define TCP_REPAIR_OFF_NO_WP	-1
277
278struct tcp_repair_window {
279	uint32_t snd_wl1;
280	uint32_t snd_wnd;
281	uint32_t max_window;
282	uint32_t rcv_wnd;
283	uint32_t rcv_wup;
284};
285
286#define TCP_RECEIVE_ZEROCOPY_FLAG_TLB_CLEAN_HINT 0x1
287
288struct tcp_zerocopy_receive {
289	uint64_t address;
290	uint32_t length;
291	uint32_t recv_skip_hint;
292	uint32_t inq;
293	int32_t err;
294	uint64_t copybuf_address;
295	int32_t copybuf_len;
296	uint32_t flags;
297	uint64_t msg_control;
298	uint64_t msg_controllen;
299	uint32_t msg_flags;
300	uint32_t reserved;
301};
302
303#endif
304
305#endif