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