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 <linux/dmaengine.h>
23#include <net/sock.h>
24#include <net/inet_connection_sock.h>
25#include <net/inet_timewait_sock.h>
26#include <uapi/linux/tcp.h>
27
28static inline struct tcphdr *tcp_hdr(const struct sk_buff *skb)
29{
30 return (struct tcphdr *)skb_transport_header(skb);
31}
32
33static inline unsigned int tcp_hdrlen(const struct sk_buff *skb)
34{
35 return tcp_hdr(skb)->doff * 4;
36}
37
38static inline unsigned int tcp_optlen(const struct sk_buff *skb)
39{
40 return (tcp_hdr(skb)->doff - 5) * 4;
41}
42
43
44#define TCP_FASTOPEN_COOKIE_MIN 4
45#define TCP_FASTOPEN_COOKIE_MAX 16
46#define TCP_FASTOPEN_COOKIE_SIZE 8
47
48
49struct tcp_fastopen_cookie {
50 s8 len;
51 u8 val[TCP_FASTOPEN_COOKIE_MAX];
52};
53
54
55struct tcp_sack_block_wire {
56 __be32 start_seq;
57 __be32 end_seq;
58};
59
60struct tcp_sack_block {
61 u32 start_seq;
62 u32 end_seq;
63};
64
65
66#define TCP_SACK_SEEN (1 << 0)
67#define TCP_FACK_ENABLED (1 << 1)
68#define TCP_DSACK_SEEN (1 << 2)
69
70struct tcp_options_received {
71
72 long ts_recent_stamp;
73 u32 ts_recent;
74 u32 rcv_tsval;
75 u32 rcv_tsecr;
76 u16 saw_tstamp : 1,
77 tstamp_ok : 1,
78 dsack : 1,
79 wscale_ok : 1,
80 sack_ok : 4,
81 snd_wscale : 4,
82 rcv_wscale : 4;
83 u8 cookie_plus:6,
84 cookie_out_never:1,
85 cookie_in_always:1;
86 u8 num_sacks;
87 u16 user_mss;
88 u16 mss_clamp;
89};
90
91static inline void tcp_clear_options(struct tcp_options_received *rx_opt)
92{
93 rx_opt->tstamp_ok = rx_opt->sack_ok = 0;
94 rx_opt->wscale_ok = rx_opt->snd_wscale = 0;
95 rx_opt->cookie_plus = 0;
96}
97
98
99
100
101
102#define TCP_NUM_SACKS 4
103
104struct tcp_cookie_values;
105struct tcp_request_sock_ops;
106
107struct tcp_request_sock {
108 struct inet_request_sock req;
109#ifdef CONFIG_TCP_MD5SIG
110
111 const struct tcp_request_sock_ops *af_specific;
112#endif
113 struct sock *listener;
114 u32 rcv_isn;
115 u32 snt_isn;
116 u32 snt_synack;
117 u32 rcv_nxt;
118
119
120
121};
122
123static inline struct tcp_request_sock *tcp_rsk(const struct request_sock *req)
124{
125 return (struct tcp_request_sock *)req;
126}
127
128struct tcp_sock {
129
130 struct inet_connection_sock inet_conn;
131 u16 tcp_header_len;
132 u16 xmit_size_goal_segs;
133
134
135
136
137
138 __be32 pred_flags;
139
140
141
142
143
144
145 u32 rcv_nxt;
146 u32 copied_seq;
147 u32 rcv_wup;
148 u32 snd_nxt;
149
150 u32 snd_una;
151 u32 snd_sml;
152 u32 rcv_tstamp;
153 u32 lsndtime;
154
155 struct list_head tsq_node;
156 unsigned long tsq_flags;
157
158
159 struct {
160 struct sk_buff_head prequeue;
161 struct task_struct *task;
162 struct iovec *iov;
163 int memory;
164 int len;
165#ifdef CONFIG_NET_DMA
166
167 struct dma_chan *dma_chan;
168 int wakeup;
169 struct dma_pinned_list *pinned_list;
170 dma_cookie_t dma_cookie;
171#endif
172 } ucopy;
173
174 u32 snd_wl1;
175 u32 snd_wnd;
176 u32 max_window;
177 u32 mss_cache;
178
179 u32 window_clamp;
180 u32 rcv_ssthresh;
181
182 u32 frto_highmark;
183 u16 advmss;
184 u8 frto_counter;
185 u8 nonagle : 4,
186 thin_lto : 1,
187 thin_dupack : 1,
188 repair : 1,
189 unused : 1;
190 u8 repair_queue;
191 u8 do_early_retrans:1,
192 early_retrans_delayed:1,
193 syn_data:1,
194 syn_fastopen:1,
195 syn_data_acked:1;
196
197
198 u32 srtt;
199 u32 mdev;
200 u32 mdev_max;
201 u32 rttvar;
202 u32 rtt_seq;
203
204 u32 packets_out;
205 u32 retrans_out;
206
207 u16 urg_data;
208 u8 ecn_flags;
209 u8 reordering;
210 u32 snd_up;
211
212 u8 keepalive_probes;
213
214
215
216 struct tcp_options_received rx_opt;
217
218
219
220
221 u32 snd_ssthresh;
222 u32 snd_cwnd;
223 u32 snd_cwnd_cnt;
224 u32 snd_cwnd_clamp;
225 u32 snd_cwnd_used;
226 u32 snd_cwnd_stamp;
227 u32 prior_cwnd;
228 u32 prr_delivered;
229
230 u32 prr_out;
231
232 u32 rcv_wnd;
233 u32 write_seq;
234 u32 pushed_seq;
235 u32 lost_out;
236 u32 sacked_out;
237 u32 fackets_out;
238 u32 tso_deferred;
239 u32 bytes_acked;
240
241
242 struct sk_buff* lost_skb_hint;
243 struct sk_buff *scoreboard_skb_hint;
244 struct sk_buff *retransmit_skb_hint;
245
246 struct sk_buff_head out_of_order_queue;
247
248
249 struct tcp_sack_block duplicate_sack[1];
250 struct tcp_sack_block selective_acks[4];
251
252 struct tcp_sack_block recv_sack_cache[4];
253
254 struct sk_buff *highest_sack;
255
256
257
258
259
260 int lost_cnt_hint;
261 u32 retransmit_high;
262
263 u32 lost_retrans_low;
264
265 u32 prior_ssthresh;
266 u32 high_seq;
267
268 u32 retrans_stamp;
269
270
271 u32 undo_marker;
272 int undo_retrans;
273 u32 total_retrans;
274
275 u32 urg_seq;
276 unsigned int keepalive_time;
277 unsigned int keepalive_intvl;
278
279 int linger2;
280
281
282 struct {
283 u32 rtt;
284 u32 seq;
285 u32 time;
286 } rcv_rtt_est;
287
288
289 struct {
290 int space;
291 u32 seq;
292 u32 time;
293 } rcvq_space;
294
295
296 struct {
297 u32 probe_seq_start;
298 u32 probe_seq_end;
299 } mtu_probe;
300 u32 mtu_info;
301
302
303
304#ifdef CONFIG_TCP_MD5SIG
305
306 const struct tcp_sock_af_ops *af_specific;
307
308
309 struct tcp_md5sig_info __rcu *md5sig_info;
310#endif
311
312
313
314
315
316 struct tcp_cookie_values *cookie_values;
317
318
319 struct tcp_fastopen_request *fastopen_req;
320
321
322
323 struct request_sock *fastopen_rsk;
324};
325
326enum tsq_flags {
327 TSQ_THROTTLED,
328 TSQ_QUEUED,
329 TCP_TSQ_DEFERRED,
330 TCP_WRITE_TIMER_DEFERRED,
331 TCP_DELACK_TIMER_DEFERRED,
332 TCP_MTU_REDUCED_DEFERRED,
333
334
335};
336
337static inline struct tcp_sock *tcp_sk(const struct sock *sk)
338{
339 return (struct tcp_sock *)sk;
340}
341
342struct tcp_timewait_sock {
343 struct inet_timewait_sock tw_sk;
344 u32 tw_rcv_nxt;
345 u32 tw_snd_nxt;
346 u32 tw_rcv_wnd;
347 u32 tw_ts_recent;
348 long tw_ts_recent_stamp;
349#ifdef CONFIG_TCP_MD5SIG
350 struct tcp_md5sig_key *tw_md5_key;
351#endif
352
353
354
355 struct tcp_cookie_values *tw_cookie_values;
356};
357
358static inline struct tcp_timewait_sock *tcp_twsk(const struct sock *sk)
359{
360 return (struct tcp_timewait_sock *)sk;
361}
362
363static inline bool tcp_passive_fastopen(const struct sock *sk)
364{
365 return (sk->sk_state == TCP_SYN_RECV &&
366 tcp_sk(sk)->fastopen_rsk != NULL);
367}
368
369static inline bool fastopen_cookie_present(struct tcp_fastopen_cookie *foc)
370{
371 return foc->len != -1;
372}
373
374extern void tcp_sock_destruct(struct sock *sk);
375
376static inline int fastopen_init_queue(struct sock *sk, int backlog)
377{
378 struct request_sock_queue *queue =
379 &inet_csk(sk)->icsk_accept_queue;
380
381 if (queue->fastopenq == NULL) {
382 queue->fastopenq = kzalloc(
383 sizeof(struct fastopen_queue),
384 sk->sk_allocation);
385 if (queue->fastopenq == NULL)
386 return -ENOMEM;
387
388 sk->sk_destruct = tcp_sock_destruct;
389 spin_lock_init(&queue->fastopenq->lock);
390 }
391 queue->fastopenq->max_qlen = backlog;
392 return 0;
393}
394
395#endif
396