1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef _LINUX_TCP_H
18#define _LINUX_TCP_H
19
20
21#include <linux/skbuff.h>
22#include <net/sock.h>
23#include <net/inet_connection_sock.h>
24#include <net/inet_timewait_sock.h>
25#include <uapi/linux/tcp.h>
26
27static inline struct tcphdr *tcp_hdr(const struct sk_buff *skb)
28{
29 return (struct tcphdr *)skb_transport_header(skb);
30}
31
32static inline unsigned int __tcp_hdrlen(const struct tcphdr *th)
33{
34 return th->doff * 4;
35}
36
37static inline unsigned int tcp_hdrlen(const struct sk_buff *skb)
38{
39 return __tcp_hdrlen(tcp_hdr(skb));
40}
41
42static inline struct tcphdr *inner_tcp_hdr(const struct sk_buff *skb)
43{
44 return (struct tcphdr *)skb_inner_transport_header(skb);
45}
46
47static inline unsigned int inner_tcp_hdrlen(const struct sk_buff *skb)
48{
49 return inner_tcp_hdr(skb)->doff * 4;
50}
51
52static inline unsigned int tcp_optlen(const struct sk_buff *skb)
53{
54 return (tcp_hdr(skb)->doff - 5) * 4;
55}
56
57
58#define TCP_FASTOPEN_COOKIE_MIN 4
59#define TCP_FASTOPEN_COOKIE_MAX 16
60#define TCP_FASTOPEN_COOKIE_SIZE 8
61
62
63struct tcp_fastopen_cookie {
64 s8 len;
65 u8 val[TCP_FASTOPEN_COOKIE_MAX];
66 bool exp;
67};
68
69
70struct tcp_sack_block_wire {
71 __be32 start_seq;
72 __be32 end_seq;
73};
74
75struct tcp_sack_block {
76 u32 start_seq;
77 u32 end_seq;
78};
79
80
81#define TCP_SACK_SEEN (1 << 0)
82#define TCP_FACK_ENABLED (1 << 1)
83#define TCP_DSACK_SEEN (1 << 2)
84
85struct tcp_options_received {
86
87 long ts_recent_stamp;
88 u32 ts_recent;
89 u32 rcv_tsval;
90 u32 rcv_tsecr;
91 u16 saw_tstamp : 1,
92 tstamp_ok : 1,
93 dsack : 1,
94 wscale_ok : 1,
95 sack_ok : 4,
96 snd_wscale : 4,
97 rcv_wscale : 4;
98 u8 num_sacks;
99 u16 user_mss;
100 u16 mss_clamp;
101};
102
103static inline void tcp_clear_options(struct tcp_options_received *rx_opt)
104{
105 rx_opt->tstamp_ok = rx_opt->sack_ok = 0;
106 rx_opt->wscale_ok = rx_opt->snd_wscale = 0;
107}
108
109
110
111
112
113#define TCP_NUM_SACKS 4
114
115struct tcp_request_sock_ops;
116
117struct tcp_request_sock {
118 struct inet_request_sock req;
119 const struct tcp_request_sock_ops *af_specific;
120 struct skb_mstamp snt_synack;
121 bool tfo_listener;
122 u32 txhash;
123 u32 rcv_isn;
124 u32 snt_isn;
125 u32 last_oow_ack_time;
126 u32 rcv_nxt;
127
128
129
130};
131
132static inline struct tcp_request_sock *tcp_rsk(const struct request_sock *req)
133{
134 return (struct tcp_request_sock *)req;
135}
136
137struct tcp_sock {
138
139 struct inet_connection_sock inet_conn;
140 u16 tcp_header_len;
141 u16 gso_segs;
142
143
144
145
146
147 __be32 pred_flags;
148
149
150
151
152
153
154 u64 bytes_received;
155
156
157
158 u32 segs_in;
159
160
161 u32 data_segs_in;
162
163
164 u32 rcv_nxt;
165 u32 copied_seq;
166 u32 rcv_wup;
167 u32 snd_nxt;
168 u32 segs_out;
169
170
171 u32 data_segs_out;
172
173
174 u64 bytes_acked;
175
176
177
178 struct u64_stats_sync syncp;
179
180 u32 snd_una;
181 u32 snd_sml;
182 u32 rcv_tstamp;
183 u32 lsndtime;
184 u32 last_oow_ack_time;
185
186 u32 tsoffset;
187
188 struct list_head tsq_node;
189 unsigned long tsq_flags;
190
191
192 struct {
193 struct sk_buff_head prequeue;
194 struct task_struct *task;
195 struct msghdr *msg;
196 int memory;
197 int len;
198 } ucopy;
199
200 u32 snd_wl1;
201 u32 snd_wnd;
202 u32 max_window;
203 u32 mss_cache;
204
205 u32 window_clamp;
206 u32 rcv_ssthresh;
207
208
209 struct tcp_rack {
210 struct skb_mstamp mstamp;
211 u8 advanced;
212 u8 reord;
213 } rack;
214 u16 advmss;
215 u8 unused;
216 u8 nonagle : 4,
217 thin_lto : 1,
218 thin_dupack : 1,
219 repair : 1,
220 frto : 1;
221 u8 repair_queue;
222 u8 do_early_retrans:1,
223 syn_data:1,
224 syn_fastopen:1,
225 syn_fastopen_exp:1,
226 syn_data_acked:1,
227 save_syn:1,
228 is_cwnd_limited:1;
229 u32 tlp_high_seq;
230
231
232 u32 srtt_us;
233 u32 mdev_us;
234 u32 mdev_max_us;
235 u32 rttvar_us;
236 u32 rtt_seq;
237 struct rtt_meas {
238 u32 rtt, ts;
239 } rtt_min[3];
240
241 u32 packets_out;
242 u32 retrans_out;
243 u32 max_packets_out;
244 u32 max_packets_seq;
245
246 u16 urg_data;
247 u8 ecn_flags;
248 u8 keepalive_probes;
249 u32 reordering;
250 u32 snd_up;
251
252
253
254
255 struct tcp_options_received rx_opt;
256
257
258
259
260 u32 snd_ssthresh;
261 u32 snd_cwnd;
262 u32 snd_cwnd_cnt;
263 u32 snd_cwnd_clamp;
264 u32 snd_cwnd_used;
265 u32 snd_cwnd_stamp;
266 u32 prior_cwnd;
267 u32 prr_delivered;
268
269 u32 prr_out;
270 u32 delivered;
271
272 u32 rcv_wnd;
273 u32 write_seq;
274 u32 notsent_lowat;
275 u32 pushed_seq;
276 u32 lost_out;
277 u32 sacked_out;
278 u32 fackets_out;
279
280
281 struct sk_buff* lost_skb_hint;
282 struct sk_buff *retransmit_skb_hint;
283
284
285
286
287 struct sk_buff_head out_of_order_queue;
288
289
290 struct tcp_sack_block duplicate_sack[1];
291 struct tcp_sack_block selective_acks[4];
292
293 struct tcp_sack_block recv_sack_cache[4];
294
295 struct sk_buff *highest_sack;
296
297
298
299
300
301 int lost_cnt_hint;
302 u32 retransmit_high;
303
304 u32 prior_ssthresh;
305 u32 high_seq;
306
307 u32 retrans_stamp;
308
309
310 u32 undo_marker;
311 int undo_retrans;
312 u32 total_retrans;
313
314 u32 urg_seq;
315 unsigned int keepalive_time;
316 unsigned int keepalive_intvl;
317
318 int linger2;
319
320
321 struct {
322 u32 rtt;
323 u32 seq;
324 u32 time;
325 } rcv_rtt_est;
326
327
328 struct {
329 int space;
330 u32 seq;
331 u32 time;
332 } rcvq_space;
333
334
335 struct {
336 u32 probe_seq_start;
337 u32 probe_seq_end;
338 } mtu_probe;
339 u32 mtu_info;
340
341
342
343#ifdef CONFIG_TCP_MD5SIG
344
345 const struct tcp_sock_af_ops *af_specific;
346
347
348 struct tcp_md5sig_info __rcu *md5sig_info;
349#endif
350
351
352 struct tcp_fastopen_request *fastopen_req;
353
354
355
356 struct request_sock *fastopen_rsk;
357 u32 *saved_syn;
358};
359
360enum tsq_flags {
361 TSQ_THROTTLED,
362 TSQ_QUEUED,
363 TCP_TSQ_DEFERRED,
364 TCP_WRITE_TIMER_DEFERRED,
365 TCP_DELACK_TIMER_DEFERRED,
366 TCP_MTU_REDUCED_DEFERRED,
367
368
369};
370
371static inline struct tcp_sock *tcp_sk(const struct sock *sk)
372{
373 return (struct tcp_sock *)sk;
374}
375
376struct tcp_timewait_sock {
377 struct inet_timewait_sock tw_sk;
378#define tw_rcv_nxt tw_sk.__tw_common.skc_tw_rcv_nxt
379#define tw_snd_nxt tw_sk.__tw_common.skc_tw_snd_nxt
380 u32 tw_rcv_wnd;
381 u32 tw_ts_offset;
382 u32 tw_ts_recent;
383
384
385 u32 tw_last_oow_ack_time;
386
387 long tw_ts_recent_stamp;
388#ifdef CONFIG_TCP_MD5SIG
389 struct tcp_md5sig_key *tw_md5_key;
390#endif
391};
392
393static inline struct tcp_timewait_sock *tcp_twsk(const struct sock *sk)
394{
395 return (struct tcp_timewait_sock *)sk;
396}
397
398static inline bool tcp_passive_fastopen(const struct sock *sk)
399{
400 return (sk->sk_state == TCP_SYN_RECV &&
401 tcp_sk(sk)->fastopen_rsk != NULL);
402}
403
404static inline void fastopen_queue_tune(struct sock *sk, int backlog)
405{
406 struct request_sock_queue *queue = &inet_csk(sk)->icsk_accept_queue;
407 int somaxconn = READ_ONCE(sock_net(sk)->core.sysctl_somaxconn);
408
409 queue->fastopenq.max_qlen = min_t(unsigned int, backlog, somaxconn);
410}
411
412static inline void tcp_move_syn(struct tcp_sock *tp,
413 struct request_sock *req)
414{
415 tp->saved_syn = req->saved_syn;
416 req->saved_syn = NULL;
417}
418
419static inline void tcp_saved_syn_free(struct tcp_sock *tp)
420{
421 kfree(tp->saved_syn);
422 tp->saved_syn = NULL;
423}
424
425#endif
426