Branch data Line data Source code
1 : : /* SPDX-License-Identifier: GPL-2.0 */
2 : : /* Multipath TCP
3 : : *
4 : : * Copyright (c) 2017 - 2019, Intel Corporation.
5 : : */
6 : :
7 : : #ifndef __MPTCP_PROTOCOL_H
8 : : #define __MPTCP_PROTOCOL_H
9 : :
10 : : #include <linux/random.h>
11 : : #include <net/tcp.h>
12 : : #include <net/inet_connection_sock.h>
13 : : #include <uapi/linux/mptcp.h>
14 : : #include <net/genetlink.h>
15 : : #include <net/rstreason.h>
16 : :
17 : : #define MPTCP_SUPPORTED_VERSION 1
18 : :
19 : : /* MPTCP option bits */
20 : : #define OPTION_MPTCP_MPC_SYN BIT(0)
21 : : #define OPTION_MPTCP_MPC_SYNACK BIT(1)
22 : : #define OPTION_MPTCP_MPC_ACK BIT(2)
23 : : #define OPTION_MPTCP_MPJ_SYN BIT(3)
24 : : #define OPTION_MPTCP_MPJ_SYNACK BIT(4)
25 : : #define OPTION_MPTCP_MPJ_ACK BIT(5)
26 : : #define OPTION_MPTCP_ADD_ADDR BIT(6)
27 : : #define OPTION_MPTCP_RM_ADDR BIT(7)
28 : : #define OPTION_MPTCP_FASTCLOSE BIT(8)
29 : : #define OPTION_MPTCP_PRIO BIT(9)
30 : : #define OPTION_MPTCP_RST BIT(10)
31 : : #define OPTION_MPTCP_DSS BIT(11)
32 : : #define OPTION_MPTCP_FAIL BIT(12)
33 : :
34 : : #define OPTION_MPTCP_CSUMREQD BIT(13)
35 : :
36 : : #define OPTIONS_MPTCP_MPC (OPTION_MPTCP_MPC_SYN | OPTION_MPTCP_MPC_SYNACK | \
37 : : OPTION_MPTCP_MPC_ACK)
38 : : #define OPTIONS_MPTCP_MPJ (OPTION_MPTCP_MPJ_SYN | OPTION_MPTCP_MPJ_SYNACK | \
39 : : OPTION_MPTCP_MPJ_ACK)
40 : :
41 : : /* MPTCP option subtypes */
42 : : #define MPTCPOPT_MP_CAPABLE 0
43 : : #define MPTCPOPT_MP_JOIN 1
44 : : #define MPTCPOPT_DSS 2
45 : : #define MPTCPOPT_ADD_ADDR 3
46 : : #define MPTCPOPT_RM_ADDR 4
47 : : #define MPTCPOPT_MP_PRIO 5
48 : : #define MPTCPOPT_MP_FAIL 6
49 : : #define MPTCPOPT_MP_FASTCLOSE 7
50 : : #define MPTCPOPT_RST 8
51 : :
52 : : /* MPTCP suboption lengths */
53 : : #define TCPOLEN_MPTCP_MPC_SYN 4
54 : : #define TCPOLEN_MPTCP_MPC_SYNACK 12
55 : : #define TCPOLEN_MPTCP_MPC_ACK 20
56 : : #define TCPOLEN_MPTCP_MPC_ACK_DATA 22
57 : : #define TCPOLEN_MPTCP_MPJ_SYN 12
58 : : #define TCPOLEN_MPTCP_MPJ_SYNACK 16
59 : : #define TCPOLEN_MPTCP_MPJ_ACK 24
60 : : #define TCPOLEN_MPTCP_DSS_BASE 4
61 : : #define TCPOLEN_MPTCP_DSS_ACK32 4
62 : : #define TCPOLEN_MPTCP_DSS_ACK64 8
63 : : #define TCPOLEN_MPTCP_DSS_MAP32 10
64 : : #define TCPOLEN_MPTCP_DSS_MAP64 14
65 : : #define TCPOLEN_MPTCP_DSS_CHECKSUM 2
66 : : #define TCPOLEN_MPTCP_ADD_ADDR 16
67 : : #define TCPOLEN_MPTCP_ADD_ADDR_PORT 18
68 : : #define TCPOLEN_MPTCP_ADD_ADDR_BASE 8
69 : : #define TCPOLEN_MPTCP_ADD_ADDR_BASE_PORT 10
70 : : #define TCPOLEN_MPTCP_ADD_ADDR6 28
71 : : #define TCPOLEN_MPTCP_ADD_ADDR6_PORT 30
72 : : #define TCPOLEN_MPTCP_ADD_ADDR6_BASE 20
73 : : #define TCPOLEN_MPTCP_ADD_ADDR6_BASE_PORT 22
74 : : #define TCPOLEN_MPTCP_PORT_LEN 2
75 : : #define TCPOLEN_MPTCP_PORT_ALIGN 2
76 : : #define TCPOLEN_MPTCP_RM_ADDR_BASE 3
77 : : #define TCPOLEN_MPTCP_PRIO 3
78 : : #define TCPOLEN_MPTCP_PRIO_ALIGN 4
79 : : #define TCPOLEN_MPTCP_FASTCLOSE 12
80 : : #define TCPOLEN_MPTCP_RST 4
81 : : #define TCPOLEN_MPTCP_FAIL 12
82 : :
83 : : #define TCPOLEN_MPTCP_MPC_ACK_DATA_CSUM (TCPOLEN_MPTCP_DSS_CHECKSUM + TCPOLEN_MPTCP_MPC_ACK_DATA)
84 : :
85 : : /* MPTCP MP_JOIN flags */
86 : : #define MPTCPOPT_BACKUP BIT(0)
87 : : #define MPTCPOPT_THMAC_LEN 8
88 : :
89 : : /* MPTCP MP_CAPABLE flags */
90 : : #define MPTCP_VERSION_MASK (0x0F)
91 : : #define MPTCP_CAP_CHECKSUM_REQD BIT(7)
92 : : #define MPTCP_CAP_EXTENSIBILITY BIT(6)
93 : : #define MPTCP_CAP_DENY_JOIN_ID0 BIT(5)
94 : : #define MPTCP_CAP_HMAC_SHA256 BIT(0)
95 : : #define MPTCP_CAP_FLAG_MASK (0x1F)
96 : :
97 : : /* MPTCP DSS flags */
98 : : #define MPTCP_DSS_DATA_FIN BIT(4)
99 : : #define MPTCP_DSS_DSN64 BIT(3)
100 : : #define MPTCP_DSS_HAS_MAP BIT(2)
101 : : #define MPTCP_DSS_ACK64 BIT(1)
102 : : #define MPTCP_DSS_HAS_ACK BIT(0)
103 : : #define MPTCP_DSS_FLAG_MASK (0x1F)
104 : :
105 : : /* MPTCP ADD_ADDR flags */
106 : : #define MPTCP_ADDR_ECHO BIT(0)
107 : :
108 : : /* MPTCP MP_PRIO flags */
109 : : #define MPTCP_PRIO_BKUP BIT(0)
110 : :
111 : : /* MPTCP TCPRST flags */
112 : : #define MPTCP_RST_TRANSIENT BIT(0)
113 : :
114 : : /* MPTCP socket atomic flags */
115 : : #define MPTCP_WORK_RTX 1
116 : : #define MPTCP_FALLBACK_DONE 2
117 : : #define MPTCP_WORK_CLOSE_SUBFLOW 3
118 : :
119 : : /* MPTCP socket release cb flags */
120 : : #define MPTCP_PUSH_PENDING 1
121 : : #define MPTCP_CLEAN_UNA 2
122 : : #define MPTCP_ERROR_REPORT 3
123 : : #define MPTCP_RETRANSMIT 4
124 : : #define MPTCP_FLUSH_JOIN_LIST 5
125 : : #define MPTCP_SYNC_STATE 6
126 : : #define MPTCP_SYNC_SNDBUF 7
127 : :
128 : : struct mptcp_skb_cb {
129 : : u64 map_seq;
130 : : u64 end_seq;
131 : : u32 offset;
132 : : u8 has_rxtstamp;
133 : : u8 cant_coalesce;
134 : : };
135 : :
136 : : #define MPTCP_SKB_CB(__skb) ((struct mptcp_skb_cb *)&((__skb)->cb[0]))
137 : :
138 : 18 : static inline bool before64(__u64 seq1, __u64 seq2)
139 : : {
140 [ + + - + : 12502532 : return (__s64)(seq1 - seq2) < 0;
+ + + + +
+ + + -
+ ][ + + ]
[ + + + +
+ + + + +
+ + + + +
- + + + +
+ + + + +
+ + + + ]
141 : : }
142 : :
143 : : #define after64(seq2, seq1) before64(seq1, seq2)
144 : :
145 : : struct mptcp_options_received {
146 : : u64 sndr_key;
147 : : u64 rcvr_key;
148 : : u64 data_ack;
149 : : u64 data_seq;
150 : : u32 subflow_seq;
151 : : u16 data_len;
152 : : __sum16 csum;
153 : : struct_group(status,
154 : : u16 suboptions;
155 : : u16 use_map:1,
156 : : dsn64:1,
157 : : data_fin:1,
158 : : use_ack:1,
159 : : ack64:1,
160 : : mpc_map:1,
161 : : reset_reason:4,
162 : : reset_transient:1,
163 : : echo:1,
164 : : backup:1,
165 : : deny_join_id0:1,
166 : : __unused:2;
167 : : );
168 : : u8 join_id;
169 : : u32 token;
170 : : u32 nonce;
171 : : u64 thmac;
172 : : u8 hmac[MPTCPOPT_HMAC_LEN];
173 : : struct mptcp_addr_info addr;
174 : : struct mptcp_rm_list rm_list;
175 : : u64 ahmac;
176 : : u64 fail_seq;
177 : : };
178 : :
179 : 0 : static inline __be32 mptcp_option(u8 subopt, u8 len, u8 nib, u8 field)
180 : : {
181 [ + - + + : 1708170 : return htonl((TCPOPT_MPTCP << 24) | (len << 16) | (subopt << 12) |
+ + ][ + -
+ + + + +
- ]
182 : : ((nib & 0xF) << 8) | field);
183 : : }
184 : :
185 : : enum mptcp_pm_status {
186 : : MPTCP_PM_ADD_ADDR_RECEIVED,
187 : : MPTCP_PM_ADD_ADDR_SEND_ACK,
188 : : MPTCP_PM_RM_ADDR_RECEIVED,
189 : : MPTCP_PM_ESTABLISHED,
190 : : MPTCP_PM_SUBFLOW_ESTABLISHED,
191 : : MPTCP_PM_ALREADY_ESTABLISHED, /* persistent status, set after ESTABLISHED event */
192 : : MPTCP_PM_MPC_ENDPOINT_ACCOUNTED /* persistent status, set after MPC local address is
193 : : * accounted int id_avail_bitmap
194 : : */
195 : : };
196 : :
197 : : enum mptcp_pm_type {
198 : : MPTCP_PM_TYPE_KERNEL = 0,
199 : : MPTCP_PM_TYPE_USERSPACE,
200 : :
201 : : __MPTCP_PM_TYPE_NR,
202 : : __MPTCP_PM_TYPE_MAX = __MPTCP_PM_TYPE_NR - 1,
203 : : };
204 : :
205 : : /* Status bits below MPTCP_PM_ALREADY_ESTABLISHED need pm worker actions */
206 : : #define MPTCP_PM_WORK_MASK ((1 << MPTCP_PM_ALREADY_ESTABLISHED) - 1)
207 : :
208 : : enum mptcp_addr_signal_status {
209 : : MPTCP_ADD_ADDR_SIGNAL,
210 : : MPTCP_ADD_ADDR_ECHO,
211 : : MPTCP_RM_ADDR_SIGNAL,
212 : : };
213 : :
214 : : /* max value of mptcp_addr_info.id */
215 : : #define MPTCP_PM_MAX_ADDR_ID U8_MAX
216 : :
217 : : struct mptcp_pm_data {
218 : : struct mptcp_addr_info local;
219 : : struct mptcp_addr_info remote;
220 : : struct list_head anno_list;
221 : : struct list_head userspace_pm_local_addr_list;
222 : :
223 : : spinlock_t lock; /*protects the whole PM data */
224 : :
225 : : struct_group(reset,
226 : :
227 : : u8 addr_signal;
228 : : bool server_side;
229 : : bool work_pending;
230 : : bool accept_addr;
231 : : bool accept_subflow;
232 : : bool remote_deny_join_id0;
233 : : u8 add_addr_signaled;
234 : : u8 add_addr_accepted;
235 : : u8 local_addr_used;
236 : : u8 pm_type;
237 : : u8 extra_subflows;
238 : : u8 status;
239 : :
240 : : );
241 : :
242 : : DECLARE_BITMAP(id_avail_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
243 : : struct mptcp_rm_list rm_list_tx;
244 : : struct mptcp_rm_list rm_list_rx;
245 : : };
246 : :
247 : : struct mptcp_pm_local {
248 : : struct mptcp_addr_info addr;
249 : : u32 flags;
250 : : int ifindex;
251 : : };
252 : :
253 : : struct mptcp_pm_addr_entry {
254 : : struct list_head list;
255 : : struct mptcp_addr_info addr;
256 : : u32 flags;
257 : : int ifindex;
258 : : struct socket *lsk;
259 : : };
260 : :
261 : : struct mptcp_data_frag {
262 : : struct list_head list;
263 : : u64 data_seq;
264 : : u16 data_len;
265 : : u16 offset;
266 : : u8 overhead;
267 : : u8 eor; /* currently using 1 bit */
268 : : u16 already_sent;
269 : : struct page *page;
270 : : };
271 : :
272 : : /* Arbitrary compromise between as low as possible to react timely to subflow
273 : : * close event and as big as possible to avoid being fouled by biased large
274 : : * samples due to peer sending data on a different subflow WRT to the incoming
275 : : * ack.
276 : : */
277 : : #define MPTCP_RTT_SAMPLES 5
278 : :
279 : : /* MPTCP connection sock */
280 : : struct mptcp_sock {
281 : : /* inet_connection_sock must be the first member */
282 : : struct inet_connection_sock sk;
283 : : u64 local_key; /* protected by the first subflow socket lock
284 : : * lockless access read
285 : : */
286 : : u64 remote_key; /* same as above */
287 : : u64 write_seq;
288 : : u64 bytes_sent;
289 : : u64 snd_nxt;
290 : : u64 bytes_received;
291 : : u64 ack_seq;
292 : : atomic64_t rcv_wnd_sent;
293 : : u64 rcv_data_fin_seq;
294 : : u64 bytes_retrans;
295 : : u64 bytes_consumed;
296 : : int snd_burst;
297 : : int old_wspace;
298 : : u64 recovery_snd_nxt; /* in recovery mode accept up to this seq;
299 : : * recovery related fields are under data_lock
300 : : * protection
301 : : */
302 : : u64 bytes_acked;
303 : : u64 snd_una;
304 : : u64 wnd_end;
305 : : u32 last_data_sent;
306 : : u32 last_data_recv;
307 : : u32 last_ack_recv;
308 : : unsigned long timer_ival;
309 : : u32 token;
310 : : unsigned long flags;
311 : : unsigned long cb_flags;
312 : : bool recovery; /* closing subflow write queue reinjected */
313 : : bool can_ack;
314 : : bool fully_established;
315 : : bool rcv_data_fin;
316 : : bool snd_data_fin_enable;
317 : : bool rcv_fastclose;
318 : : bool use_64bit_ack; /* Set when we received a 64-bit DSN */
319 : : bool csum_enabled;
320 : : bool allow_infinite_fallback;
321 : : u8 pending_state; /* A subflow asked to set this sk_state,
322 : : * protected by the msk data lock
323 : : */
324 : : u8 mpc_endpoint_id;
325 : : u8 recvmsg_inq:1,
326 : : cork:1,
327 : : nodelay:1,
328 : : fastopening:1,
329 : : in_accept_queue:1,
330 : : free_first:1,
331 : : rcvspace_init:1,
332 : : fastclosing:1;
333 : : u32 notsent_lowat;
334 : : int keepalive_cnt;
335 : : int keepalive_idle;
336 : : int keepalive_intvl;
337 : : int maxseg;
338 : : struct work_struct work;
339 : : struct sk_buff *ooo_last_skb;
340 : : struct rb_root out_of_order_queue;
341 : : struct list_head conn_list;
342 : : struct list_head rtx_queue;
343 : : struct mptcp_data_frag *first_pending;
344 : : struct list_head join_list;
345 : : struct sock *first; /* The mptcp ops can safely dereference, using suitable
346 : : * ONCE annotation, the subflow outside the socket
347 : : * lock as such sock is freed after close().
348 : : */
349 : : struct mptcp_pm_data pm;
350 : : struct mptcp_sched_ops *sched;
351 : :
352 : : /* Most recent rtt_us observed by in use incoming subflows. */
353 : : struct {
354 : : u32 samples[MPTCP_RTT_SAMPLES];
355 : : u32 next_sample;
356 : : } rcv_rtt_est;
357 : :
358 : : struct {
359 : : int space; /* bytes copied in last measurement window */
360 : : int copied; /* bytes copied in this measurement window */
361 : : u64 time; /* start time of measurement window */
362 : : } rcvq_space;
363 : : u8 scaling_ratio;
364 : : bool allow_subflows;
365 : :
366 : : u32 subflow_id;
367 : : u32 setsockopt_seq;
368 : : char ca_name[TCP_CA_NAME_MAX];
369 : :
370 : : spinlock_t fallback_lock; /* protects fallback,
371 : : * allow_infinite_fallback and
372 : : * allow_join
373 : : */
374 : :
375 : : struct list_head backlog_list; /* protected by the data lock */
376 : : u32 backlog_len;
377 : : u32 backlog_unaccounted;
378 : : };
379 : :
380 : : #define mptcp_data_lock(sk) spin_lock_bh(&(sk)->sk_lock.slock)
381 : : #define mptcp_data_unlock(sk) spin_unlock_bh(&(sk)->sk_lock.slock)
382 : :
383 : : #define mptcp_for_each_subflow(__msk, __subflow) \
384 : : list_for_each_entry(__subflow, &((__msk)->conn_list), node)
385 : : #define mptcp_for_each_subflow_safe(__msk, __subflow, __tmp) \
386 : : list_for_each_entry_safe(__subflow, __tmp, &((__msk)->conn_list), node)
387 : : #define mptcp_next_subflow(__msk, __subflow) \
388 : : list_next_entry_circular(__subflow, &((__msk)->conn_list), node)
389 : :
390 : : extern struct genl_family mptcp_genl_family;
391 : :
392 : 65 : static inline void msk_owned_by_me(const struct mptcp_sock *msk)
393 : : {
394 : 1587561 : sock_owned_by_me((const struct sock *)msk);
395 : : }
396 : :
397 : : #ifdef CONFIG_DEBUG_NET
398 : : /* MPTCP-specific: we might (indirectly) call this helper with the wrong sk */
399 : : #undef tcp_sk
400 : : #define tcp_sk(ptr) ({ \
401 : : typeof(ptr) _ptr = (ptr); \
402 : : WARN_ON(_ptr->sk_protocol != IPPROTO_TCP); \
403 : : container_of_const(_ptr, struct tcp_sock, inet_conn.icsk_inet.sk); \
404 : : })
405 : : #define mptcp_sk(ptr) ({ \
406 : : typeof(ptr) _ptr = (ptr); \
407 : : WARN_ON(_ptr->sk_protocol != IPPROTO_MPTCP); \
408 : : container_of_const(_ptr, struct mptcp_sock, sk.icsk_inet.sk); \
409 : : })
410 : :
411 : : #else /* !CONFIG_DEBUG_NET */
412 : : #define mptcp_sk(ptr) container_of_const(ptr, struct mptcp_sock, sk.icsk_inet.sk)
413 : : #endif
414 : :
415 : 6453024 : static inline int mptcp_win_from_space(const struct sock *sk, int space)
416 : : {
417 [ - + ]: 6453024 : return __tcp_win_from_space(mptcp_sk(sk)->scaling_ratio, space);
418 : : }
419 : :
420 : 5408 : static inline int mptcp_space_from_win(const struct sock *sk, int win)
421 : : {
422 [ - + ]: 5408 : return __tcp_space_from_win(mptcp_sk(sk)->scaling_ratio, win);
423 : : }
424 : :
425 : 3832330 : static inline int __mptcp_space(const struct sock *sk)
426 : : {
427 : 13447500 : return mptcp_win_from_space(sk, READ_ONCE(sk->sk_rcvbuf) -
428 [ - + ]: 3832330 : READ_ONCE(mptcp_sk(sk)->backlog_len) -
429 : 3832330 : sk_rmem_alloc_get(sk));
430 : : }
431 : :
432 : 4193181 : static inline struct mptcp_data_frag *mptcp_send_head(const struct sock *sk)
433 : : {
434 [ - + ]: 4193181 : const struct mptcp_sock *msk = mptcp_sk(sk);
435 : :
436 : 4193181 : return msk->first_pending;
437 : : }
438 : :
439 : 0 : static inline void mptcp_init_rtt_est(struct mptcp_sock *msk)
440 : : {
441 : 5021 : int i;
442 : :
443 [ + + + + ]: 30666 : for (i = 0; i < MPTCP_RTT_SAMPLES; ++i)
444 : 25105 : msk->rcv_rtt_est.samples[i] = U32_MAX;
445 : 5021 : msk->rcv_rtt_est.next_sample = 0;
446 : 5021 : msk->scaling_ratio = TCP_DEFAULT_SCALING_RATIO;
447 : : }
448 : :
449 : 0 : static inline u32 mptcp_rtt_us_est(const struct mptcp_sock *msk)
450 : : {
451 : 0 : u32 rtt_us = READ_ONCE(msk->rcv_rtt_est.samples[0]);
452 : 0 : int i;
453 : :
454 : : /* Lockless access of collected samples. */
455 [ + + - - : 5252430 : for (i = 1; i < MPTCP_RTT_SAMPLES; ++i)
- - ]
456 : 0 : rtt_us = min(rtt_us, READ_ONCE(msk->rcv_rtt_est.samples[i]));
457 [ + + ]: 1050486 : return rtt_us;
458 : : }
459 : :
460 : 538851 : static inline struct mptcp_data_frag *mptcp_send_next(struct sock *sk)
461 : : {
462 [ - + ]: 538851 : struct mptcp_sock *msk = mptcp_sk(sk);
463 : 538851 : struct mptcp_data_frag *cur;
464 : :
465 : 538851 : cur = msk->first_pending;
466 [ + + ]: 538851 : return list_is_last(&cur->list, &msk->rtx_queue) ? NULL :
467 : 216513 : list_next_entry(cur, list);
468 : : }
469 : :
470 : 707768 : static inline struct mptcp_data_frag *mptcp_pending_tail(const struct sock *sk)
471 : : {
472 [ - + ]: 707768 : const struct mptcp_sock *msk = mptcp_sk(sk);
473 : :
474 [ + + ]: 707768 : if (!msk->first_pending)
475 : : return NULL;
476 : :
477 [ - + + - ]: 385461 : if (WARN_ON_ONCE(list_empty(&msk->rtx_queue)))
478 : : return NULL;
479 : :
480 : 385461 : return list_last_entry(&msk->rtx_queue, struct mptcp_data_frag, list);
481 : : }
482 : :
483 : 502753 : static inline struct mptcp_data_frag *mptcp_rtx_head(struct sock *sk)
484 : : {
485 [ - + ]: 502753 : struct mptcp_sock *msk = mptcp_sk(sk);
486 : :
487 [ + + ]: 502753 : if (msk->snd_una == msk->snd_nxt)
488 : : return NULL;
489 : :
490 [ + + ]: 425876 : return list_first_entry_or_null(&msk->rtx_queue, struct mptcp_data_frag, list);
491 : : }
492 : :
493 : : struct csum_pseudo_header {
494 : : __be64 data_seq;
495 : : __be32 subflow_seq;
496 : : __be16 data_len;
497 : : __sum16 csum;
498 : : };
499 : :
500 : : struct mptcp_subflow_request_sock {
501 : : struct tcp_request_sock sk;
502 : : u16 mp_capable : 1,
503 : : mp_join : 1,
504 : : backup : 1,
505 : : request_bkup : 1,
506 : : csum_reqd : 1,
507 : : allow_join_id0 : 1;
508 : : u8 local_id;
509 : : u8 remote_id;
510 : : u64 local_key;
511 : : u64 idsn;
512 : : u32 token;
513 : : u32 ssn_offset;
514 : : u64 thmac;
515 : : u32 local_nonce;
516 : : u32 remote_nonce;
517 : : struct mptcp_sock *msk;
518 : : struct hlist_nulls_node token_node;
519 : : };
520 : :
521 : : static inline struct mptcp_subflow_request_sock *
522 : : mptcp_subflow_rsk(const struct request_sock *rsk)
523 : : {
524 : : return (struct mptcp_subflow_request_sock *)rsk;
525 : : }
526 : :
527 : : struct mptcp_delegated_action {
528 : : struct napi_struct napi;
529 : : local_lock_t bh_lock;
530 : : struct list_head head;
531 : : };
532 : :
533 : : DECLARE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions);
534 : :
535 : : #define MPTCP_DELEGATE_SCHEDULED 0
536 : : #define MPTCP_DELEGATE_SEND 1
537 : : #define MPTCP_DELEGATE_ACK 2
538 : : #define MPTCP_DELEGATE_SNDBUF 3
539 : :
540 : : #define MPTCP_DELEGATE_ACTIONS_MASK (~BIT(MPTCP_DELEGATE_SCHEDULED))
541 : : /* MPTCP subflow context */
542 : : struct mptcp_subflow_context {
543 : : struct list_head node;/* conn_list of subflows */
544 : :
545 : : struct_group(reset,
546 : :
547 : : unsigned long avg_pacing_rate; /* protected by msk socket lock */
548 : : u64 local_key;
549 : : u64 remote_key;
550 : : u64 idsn;
551 : : u64 map_seq;
552 : : u64 rcv_wnd_sent;
553 : : u32 snd_isn;
554 : : u32 token;
555 : : u32 rel_write_seq;
556 : : u32 map_subflow_seq;
557 : : u32 ssn_offset;
558 : : u32 map_data_len;
559 : : __wsum map_data_csum;
560 : : u32 map_csum_len;
561 : : u32 prev_rtt_seq;
562 : : u32 request_mptcp : 1, /* send MP_CAPABLE */
563 : : request_join : 1, /* send MP_JOIN */
564 : : request_bkup : 1,
565 : : mp_capable : 1, /* remote is MPTCP capable */
566 : : mp_join : 1, /* remote is JOINing */
567 : : pm_notified : 1, /* PM hook called for established status */
568 : : conn_finished : 1,
569 : : map_valid : 1,
570 : : map_csum_reqd : 1,
571 : : map_data_fin : 1,
572 : : mpc_map : 1,
573 : : backup : 1,
574 : : send_mp_prio : 1,
575 : : send_mp_fail : 1,
576 : : send_fastclose : 1,
577 : : send_infinite_map : 1,
578 : : remote_key_valid : 1, /* received the peer key from */
579 : : disposable : 1, /* ctx can be free at ulp release time */
580 : : closing : 1, /* must not pass rx data to msk anymore */
581 : : stale : 1, /* unable to snd/rcv data, do not use for xmit */
582 : : valid_csum_seen : 1, /* at least one csum validated */
583 : : is_mptfo : 1, /* subflow is doing TFO */
584 : : close_event_done : 1, /* has done the post-closed part */
585 : : mpc_drop : 1, /* the MPC option has been dropped in a rtx */
586 : : __unused : 8;
587 : : bool data_avail;
588 : : bool scheduled;
589 : : bool pm_listener; /* a listener managed by the kernel PM? */
590 : : bool fully_established; /* path validated */
591 : : u32 lent_mem_frag;
592 : : u32 remote_nonce;
593 : : u64 thmac;
594 : : u32 local_nonce;
595 : : u32 remote_token;
596 : : union {
597 : : u8 hmac[MPTCPOPT_HMAC_LEN]; /* MPJ subflow only */
598 : : u64 iasn; /* initial ack sequence number, MPC subflows only */
599 : : };
600 : : s16 local_id; /* if negative not initialized yet */
601 : : u8 remote_id;
602 : : u8 reset_seen:1;
603 : : u8 reset_transient:1;
604 : : u8 reset_reason:4;
605 : : u8 stale_count;
606 : :
607 : : u32 subflow_id;
608 : :
609 : : long delegated_status;
610 : : unsigned long fail_tout;
611 : :
612 : : );
613 : :
614 : : struct list_head delegated_node; /* link into delegated_action, protected by local BH */
615 : :
616 : : u32 setsockopt_seq;
617 : : u32 stale_rcv_tstamp;
618 : : int cached_sndbuf; /* sndbuf size when last synced with the msk sndbuf,
619 : : * protected by the msk socket lock
620 : : */
621 : :
622 : : struct sock *tcp_sock; /* tcp sk backpointer */
623 : : struct sock *conn; /* parent mptcp_sock */
624 : : const struct inet_connection_sock_af_ops *icsk_af_ops;
625 : : void (*tcp_state_change)(struct sock *sk);
626 : : void (*tcp_error_report)(struct sock *sk);
627 : :
628 : : struct rcu_head rcu;
629 : : };
630 : :
631 : : static inline struct mptcp_subflow_context *
632 : 42 : mptcp_subflow_ctx(const struct sock *sk)
633 : : {
634 [ - + ]: 780499 : const struct inet_connection_sock *icsk = inet_csk(sk);
[ - + + - ]
635 : :
636 : : /* Use RCU on icsk_ulp_data only for sock diag code */
637 [ - + + + : 54907872 : return (__force struct mptcp_subflow_context *)icsk->icsk_ulp_data;
- + - + ]
[ + + ][ + +
- + - + -
+ - + - +
+ + - + +
- + + - +
- + - + -
+ + + ][ +
+ + - + -
- + - + +
+ + + + +
+ + - + +
+ + + - +
- - - + +
+ + - + +
- + - + -
+ + + + -
+ + - + ]
[ - + + -
- + - + +
+ + + + -
+ + - + +
+ + + + +
- + - + ]
[ + + + -
- + - + -
+ - + - +
+ + - + +
- + + - +
- + - + -
+ + + ]
638 : : }
639 : :
640 : : static inline struct sock *
641 : 0 : mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
642 : : {
643 [ - + + + : 5445689 : return subflow->tcp_sock;
+ + ][ + + ]
[ + - + +
+ + - + -
- + + + +
- - - - ]
[ + - + +
+ + - + -
- - - + +
+ + - - -
- ]
644 : : }
645 : :
646 : : static inline void
647 : 30 : mptcp_subflow_ctx_reset(struct mptcp_subflow_context *subflow)
648 : : {
649 : 1577 : memset(&subflow->reset, 0, sizeof(subflow->reset));
650 : 1577 : subflow->request_mptcp = 1;
651 : 1577 : WRITE_ONCE(subflow->local_id, -1);
652 : 1577 : }
653 : :
654 : : /* Convert reset reasons in MPTCP to enum sk_rst_reason type */
655 : : static inline enum sk_rst_reason
656 : : sk_rst_convert_mptcp_reason(u32 reason)
657 : : {
658 : : switch (reason) {
659 : : case MPTCP_RST_EUNSPEC:
660 : : return SK_RST_REASON_MPTCP_RST_EUNSPEC;
661 : : case MPTCP_RST_EMPTCP:
662 : : return SK_RST_REASON_MPTCP_RST_EMPTCP;
663 : : case MPTCP_RST_ERESOURCE:
664 : : return SK_RST_REASON_MPTCP_RST_ERESOURCE;
665 : : case MPTCP_RST_EPROHIBIT:
666 : : return SK_RST_REASON_MPTCP_RST_EPROHIBIT;
667 : : case MPTCP_RST_EWQ2BIG:
668 : : return SK_RST_REASON_MPTCP_RST_EWQ2BIG;
669 : : case MPTCP_RST_EBADPERF:
670 : : return SK_RST_REASON_MPTCP_RST_EBADPERF;
671 : : case MPTCP_RST_EMIDDLEBOX:
672 : : return SK_RST_REASON_MPTCP_RST_EMIDDLEBOX;
673 : : default:
674 : : /* It should not happen, or else errors may occur
675 : : * in MPTCP layer
676 : : */
677 : : return SK_RST_REASON_ERROR;
678 : : }
679 : : }
680 : :
681 : : static inline void
682 : 48 : mptcp_send_active_reset_reason(struct sock *sk)
683 : : {
684 : 48 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
685 : 48 : enum sk_rst_reason reason;
686 : :
687 [ + - ]: 48 : reason = sk_rst_convert_mptcp_reason(subflow->reset_reason);
688 : 48 : tcp_send_active_reset(sk, GFP_ATOMIC, reason);
689 : 48 : }
690 : :
691 : : /* Made the fwd mem carried by the given skb available to the msk,
692 : : * To be paired with a previous mptcp_subflow_lend_fwdmem() before freeing
693 : : * the skb or setting the skb ownership.
694 : : */
695 : 1102495 : static inline void mptcp_borrow_fwdmem(struct sock *sk, struct sk_buff *skb)
696 : : {
697 : 1102495 : struct sock *ssk = skb->sk;
698 : :
699 : : /* The subflow just lend the skb fwd memory; if the subflow meanwhile
700 : : * closed, mptcp_close_ssk() already released the ssk rcv memory.
701 : : */
702 [ - + ]: 1102495 : DEBUG_NET_WARN_ON_ONCE(skb->destructor);
703 [ + - ]: 1102495 : sk_forward_alloc_add(sk, skb->truesize);
704 [ + - ]: 1102495 : if (!ssk)
705 : : return;
706 : :
707 : 1102495 : atomic_sub(skb->truesize, &ssk->sk_rmem_alloc);
708 : 1102495 : skb->sk = NULL;
709 : : }
710 : :
711 : : static inline void
712 : 0 : __mptcp_subflow_lend_fwdmem(struct mptcp_subflow_context *subflow, int size)
713 : : {
714 : 1148235 : int frag = (subflow->lent_mem_frag + size) & (PAGE_SIZE - 1);
715 : :
716 : 45808 : subflow->lent_mem_frag = frag;
717 : : }
718 : :
719 : : static inline void
720 : 0 : mptcp_subflow_lend_fwdmem(struct mptcp_subflow_context *subflow,
721 : : struct sk_buff *skb)
722 : : {
723 : 1102477 : __mptcp_subflow_lend_fwdmem(subflow, skb->truesize);
724 : 1102477 : skb->destructor = NULL;
725 : : }
726 : :
727 : : static inline u64
728 : 5438467 : mptcp_subflow_get_map_offset(const struct mptcp_subflow_context *subflow)
729 : : {
730 [ - + ]: 5438467 : return tcp_sk(mptcp_subflow_tcp_sock(subflow))->copied_seq -
731 : 5438467 : subflow->ssn_offset -
732 : 5438467 : subflow->map_subflow_seq;
733 : : }
734 : :
735 : : static inline u64
736 : 36 : mptcp_subflow_get_mapped_dsn(const struct mptcp_subflow_context *subflow)
737 : : {
738 [ - + ]: 2211519 : return subflow->map_seq + mptcp_subflow_get_map_offset(subflow);
739 : : }
740 : :
741 : : void mptcp_subflow_process_delegated(struct sock *ssk, long actions);
742 : :
743 : 136722 : static inline void mptcp_subflow_delegate(struct mptcp_subflow_context *subflow, int action)
744 : : {
745 [ - + ]: 136722 : long old, set_bits = BIT(MPTCP_DELEGATE_SCHEDULED) | BIT(action);
746 : 136722 : struct mptcp_delegated_action *delegated;
747 : 136722 : bool schedule;
748 : :
749 : : /* the caller held the subflow bh socket lock */
750 [ + - + - : 136722 : lockdep_assert_in_softirq();
+ - + - -
+ ]
751 : :
752 : : /* The implied barrier pairs with tcp_release_cb_override()
753 : : * mptcp_napi_poll(), and ensures the below list check sees list
754 : : * updates done prior to delegated status bits changes
755 : : */
756 [ - + - + ]: 136722 : old = set_mask_bits(&subflow->delegated_status, 0, set_bits);
757 [ + + ]: 136722 : if (!(old & BIT(MPTCP_DELEGATE_SCHEDULED))) {
758 [ - + + - ]: 50996 : if (WARN_ON_ONCE(!list_empty(&subflow->delegated_node)))
759 : : return;
760 : :
761 [ + - + - : 50996 : local_lock_nested_bh(&mptcp_delegated_actions.bh_lock);
+ - + - -
+ ]
762 : 50996 : delegated = this_cpu_ptr(&mptcp_delegated_actions);
763 : 50996 : schedule = list_empty(&delegated->head);
764 : 50996 : list_add_tail(&subflow->delegated_node, &delegated->head);
765 : 50996 : local_unlock_nested_bh(&mptcp_delegated_actions.bh_lock);
766 : 50996 : sock_hold(mptcp_subflow_tcp_sock(subflow));
767 [ + + ]: 50996 : if (schedule)
768 : 48965 : napi_schedule(&delegated->napi);
769 : : }
770 : : }
771 : :
772 : : static inline struct mptcp_subflow_context *
773 : 99856 : mptcp_subflow_delegated_next(struct mptcp_delegated_action *delegated)
774 : : {
775 : 99856 : struct mptcp_subflow_context *ret;
776 : :
777 [ + - + - : 99856 : local_lock_nested_bh(&mptcp_delegated_actions.bh_lock);
+ - + - -
+ ]
778 [ + + ]: 99856 : if (list_empty(&delegated->head)) {
779 : 27170 : local_unlock_nested_bh(&mptcp_delegated_actions.bh_lock);
780 : 27164 : return NULL;
781 : : }
782 : :
783 : 50996 : ret = list_first_entry(&delegated->head, struct mptcp_subflow_context, delegated_node);
784 : 50996 : list_del_init(&ret->delegated_node);
785 : 50996 : local_unlock_nested_bh(&mptcp_delegated_actions.bh_lock);
786 : 50996 : return ret;
787 : : }
788 : :
789 : : void __mptcp_inherit_memcg(struct sock *sk, struct sock *ssk, gfp_t gfp);
790 : : void __mptcp_inherit_cgrp_data(struct sock *sk, struct sock *ssk);
791 : :
792 : : int mptcp_is_enabled(const struct net *net);
793 : : unsigned int mptcp_get_add_addr_timeout(const struct net *net);
794 : : int mptcp_is_checksum_enabled(const struct net *net);
795 : : int mptcp_allow_join_id0(const struct net *net);
796 : : unsigned int mptcp_stale_loss_cnt(const struct net *net);
797 : : unsigned int mptcp_close_timeout(const struct sock *sk);
798 : : int mptcp_get_pm_type(const struct net *net);
799 : : const char *mptcp_get_path_manager(const struct net *net);
800 : : const char *mptcp_get_scheduler(const struct net *net);
801 : :
802 : : void mptcp_active_disable(struct sock *sk);
803 : : bool mptcp_active_should_disable(struct sock *ssk);
804 : : void mptcp_active_enable(struct sock *sk);
805 : :
806 : : void mptcp_get_available_schedulers(char *buf, size_t maxlen);
807 : : void __mptcp_subflow_fully_established(struct mptcp_sock *msk,
808 : : struct mptcp_subflow_context *subflow,
809 : : const struct mptcp_options_received *mp_opt);
810 : : bool __mptcp_retransmit_pending_data(struct sock *sk);
811 : : void mptcp_check_and_set_pending(struct sock *sk);
812 : : void __mptcp_push_pending(struct sock *sk, unsigned int flags);
813 : : bool mptcp_subflow_data_available(struct sock *sk);
814 : : void __init mptcp_subflow_init(void);
815 : : void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how);
816 : : void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
817 : : struct mptcp_subflow_context *subflow);
818 : : void __mptcp_subflow_send_ack(struct sock *ssk);
819 : : void mptcp_subflow_reset(struct sock *ssk);
820 : : void mptcp_subflow_queue_clean(struct sock *sk, struct sock *ssk);
821 : : void mptcp_sock_graft(struct sock *sk, struct socket *parent);
822 : : struct sock *__mptcp_nmpc_sk(struct mptcp_sock *msk);
823 : : bool __mptcp_close(struct sock *sk, long timeout);
824 : : void mptcp_cancel_work(struct sock *sk);
825 : : void __mptcp_unaccepted_force_close(struct sock *sk);
826 : : void mptcp_set_state(struct sock *sk, int state);
827 : :
828 : : bool mptcp_addresses_equal(const struct mptcp_addr_info *a,
829 : : const struct mptcp_addr_info *b, bool use_port);
830 : : void mptcp_local_address(const struct sock_common *skc,
831 : : struct mptcp_addr_info *addr);
832 : : void mptcp_remote_address(const struct sock_common *skc,
833 : : struct mptcp_addr_info *addr);
834 : :
835 : : /* called with sk socket lock held */
836 : : int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_local *local,
837 : : const struct mptcp_addr_info *remote);
838 : : int mptcp_subflow_create_socket(struct sock *sk, unsigned short family,
839 : : struct socket **new_sock);
840 : : void mptcp_info2sockaddr(const struct mptcp_addr_info *info,
841 : : struct sockaddr_storage *addr,
842 : : unsigned short family);
843 : : struct mptcp_sched_ops *mptcp_sched_find(const char *name);
844 : : int mptcp_validate_scheduler(struct mptcp_sched_ops *sched);
845 : : int mptcp_register_scheduler(struct mptcp_sched_ops *sched);
846 : : void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched);
847 : : void mptcp_sched_init(void);
848 : : int mptcp_init_sched(struct mptcp_sock *msk,
849 : : struct mptcp_sched_ops *sched);
850 : : void mptcp_release_sched(struct mptcp_sock *msk);
851 : : void mptcp_subflow_set_scheduled(struct mptcp_subflow_context *subflow,
852 : : bool scheduled);
853 : : struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk);
854 : : struct sock *mptcp_subflow_get_retrans(struct mptcp_sock *msk);
855 : : int mptcp_sched_get_send(struct mptcp_sock *msk);
856 : : int mptcp_sched_get_retrans(struct mptcp_sock *msk);
857 : :
858 : 72 : static inline u64 mptcp_data_avail(const struct mptcp_sock *msk)
859 : : {
860 [ + + ]: 1068279 : return READ_ONCE(msk->bytes_received) - READ_ONCE(msk->bytes_consumed);
861 : : }
862 : :
863 : 1854295 : static inline bool mptcp_epollin_ready(const struct sock *sk)
864 : : {
865 [ - + ]: 1854295 : u64 data_avail = mptcp_data_avail(mptcp_sk(sk));
866 : :
867 [ + + ]: 1854295 : if (!data_avail)
868 : : return false;
869 : :
870 : : /* mptcp doesn't have to deal with small skbs in the receive queue,
871 : : * as it can always coalesce them
872 : : */
873 [ - + - - ]: 2557730 : return (data_avail >= sk->sk_rcvlowat) ||
874 : 0 : tcp_under_memory_pressure(sk);
875 : : }
876 : :
877 : : int mptcp_set_rcvlowat(struct sock *sk, int val);
878 : :
879 : 1279462 : static inline bool __tcp_can_send(const struct sock *ssk)
880 : : {
881 : : /* only send if our side has not closed yet */
882 [ + + ]: 1964150 : return ((1 << inet_sk_state_load(ssk)) & (TCPF_ESTABLISHED | TCPF_CLOSE_WAIT));
883 : : }
884 : :
885 : 1565121 : static inline bool __mptcp_subflow_active(struct mptcp_subflow_context *subflow)
886 : : {
887 : : /* can't send if JOIN hasn't completed yet (i.e. is usable for mptcp) */
888 [ + + - + : 1565121 : if (subflow->request_join && !READ_ONCE(subflow->fully_established))
+ + ]
[ + + + + ]
889 : : return false;
890 : :
891 : 1564676 : return __tcp_can_send(mptcp_subflow_tcp_sock(subflow));
892 : : }
893 : :
894 : : void mptcp_subflow_set_active(struct mptcp_subflow_context *subflow);
895 : :
896 : : bool mptcp_subflow_active(struct mptcp_subflow_context *subflow);
897 : :
898 : : void mptcp_subflow_drop_ctx(struct sock *ssk);
899 : :
900 : 30 : static inline void mptcp_subflow_tcp_fallback(struct sock *sk,
901 : : struct mptcp_subflow_context *ctx)
902 : : {
903 : 222 : sk->sk_data_ready = sock_def_readable;
904 : 222 : sk->sk_state_change = ctx->tcp_state_change;
905 : 222 : sk->sk_write_space = sk_stream_write_space;
906 : 222 : sk->sk_error_report = ctx->tcp_error_report;
907 : :
908 [ - + ]: 222 : inet_csk(sk)->icsk_af_ops = ctx->icsk_af_ops;
909 : : }
910 : :
911 : : void __init mptcp_proto_init(void);
912 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
913 : : int __init mptcp_proto_v6_init(void);
914 : : void __init mptcp_subflow_v6_init(void);
915 : : #endif
916 : :
917 : : struct sock *mptcp_sk_clone_init(const struct sock *sk,
918 : : const struct mptcp_options_received *mp_opt,
919 : : struct sock *ssk,
920 : : struct request_sock *req);
921 : : void mptcp_get_options(const struct sk_buff *skb,
922 : : struct mptcp_options_received *mp_opt);
923 : :
924 : : void mptcp_finish_connect(struct sock *sk);
925 : : void __mptcp_sync_state(struct sock *sk, int state);
926 : : void mptcp_reset_tout_timer(struct mptcp_sock *msk, unsigned long fail_tout);
927 : :
928 : 1105 : static inline void mptcp_stop_tout_timer(struct sock *sk)
929 : : {
930 [ + + ]: 1105 : if (!inet_csk(sk)->icsk_mtup.probe_timestamp)
931 : : return;
932 : :
933 : 4 : sk_stop_timer(sk, &inet_csk(sk)->mptcp_tout_timer);
934 : 4 : inet_csk(sk)->icsk_mtup.probe_timestamp = 0;
935 : : }
936 : :
937 : 54 : static inline void mptcp_set_close_tout(struct sock *sk, unsigned long tout)
938 : : {
939 : : /* avoid 0 timestamp, as that means no close timeout */
940 : 36 : inet_csk(sk)->icsk_mtup.probe_timestamp = tout ? : 1;
941 : : }
942 : :
943 : 1386 : static inline void mptcp_start_tout_timer(struct sock *sk)
944 : : {
945 : 1386 : mptcp_set_close_tout(sk, tcp_jiffies32);
946 [ - + ]: 1386 : mptcp_reset_tout_timer(mptcp_sk(sk), 0);
947 : 1386 : }
948 : :
949 : 3368 : static inline bool mptcp_is_fully_established(struct sock *sk)
950 : : {
951 [ + + ]: 3368 : return inet_sk_state_load(sk) == TCP_ESTABLISHED &&
952 [ - + - + : 3019 : READ_ONCE(mptcp_sk(sk)->fully_established);
- + ]
[ - + - + ]
953 : : }
954 : :
955 : 60 : static inline u64 mptcp_stamp(void)
956 : : {
957 [ + - ]: 1053542 : return div_u64(tcp_clock_ns(), NSEC_PER_USEC);
958 : : }
959 : :
960 : : void mptcp_data_ready(struct sock *sk, struct sock *ssk);
961 : : bool mptcp_finish_join(struct sock *sk);
962 : : bool mptcp_schedule_work(struct sock *sk);
963 : : int mptcp_setsockopt(struct sock *sk, int level, int optname,
964 : : sockptr_t optval, unsigned int optlen);
965 : : int mptcp_getsockopt(struct sock *sk, int level, int optname,
966 : : char __user *optval, int __user *option);
967 : :
968 : : u64 __mptcp_expand_seq(u64 old_seq, u64 cur_seq);
969 : 153 : static inline u64 mptcp_expand_seq(u64 old_seq, u64 cur_seq, bool use_64bit)
970 : : {
971 [ + + + + ]: 3150772 : if (use_64bit)
[ + + ]
972 : : return cur_seq;
973 : :
974 : 296096 : return __mptcp_expand_seq(old_seq, cur_seq);
975 : : }
976 : : void __mptcp_check_push(struct sock *sk, struct sock *ssk);
977 : : void __mptcp_data_acked(struct sock *sk);
978 : : void __mptcp_error_report(struct sock *sk);
979 : : bool mptcp_update_rcv_data_fin(struct mptcp_sock *msk, u64 data_fin_seq, bool use_64bit);
980 : 1789367 : static inline bool mptcp_data_fin_enabled(const struct mptcp_sock *msk)
981 : : {
982 [ + + + + ]: 3828511 : return READ_ONCE(msk->snd_data_fin_enable) &&
[ + + ]
983 [ + + ]: 251256 : READ_ONCE(msk->write_seq) == READ_ONCE(msk->snd_nxt);
[ + + - + ]
984 : : }
985 : :
986 : 3250118 : static inline u32 mptcp_notsent_lowat(const struct sock *sk)
987 : : {
988 [ - + ]: 3250118 : struct net *net = sock_net(sk);
989 : 3250118 : u32 val;
990 : :
991 [ - + ]: 3250118 : val = READ_ONCE(mptcp_sk(sk)->notsent_lowat);
992 [ + + ]: 3250118 : return val ?: READ_ONCE(net->ipv4.sysctl_tcp_notsent_lowat);
993 : : }
994 : :
995 : 2542350 : static inline bool mptcp_stream_memory_free(const struct sock *sk, int wake)
996 : : {
997 [ - + ]: 2542350 : const struct mptcp_sock *msk = mptcp_sk(sk);
998 : 2542350 : u32 notsent_bytes;
999 : :
1000 : 2542350 : notsent_bytes = READ_ONCE(msk->write_seq) - READ_ONCE(msk->snd_nxt);
1001 [ - + ]: 2542350 : return (notsent_bytes << wake) < mptcp_notsent_lowat(sk);
1002 : : }
1003 : :
1004 : 832890 : static inline bool __mptcp_stream_is_writeable(const struct sock *sk, int wake)
1005 : : {
1006 [ + - + + ]: 1665780 : return mptcp_stream_memory_free(sk, wake) &&
1007 : 832890 : __sk_stream_is_writeable(sk, wake);
1008 : : }
1009 : :
1010 : 1035450 : static inline void mptcp_write_space(struct sock *sk)
1011 : : {
1012 : : /* pairs with memory barrier in mptcp_poll */
1013 : 1035450 : smp_mb();
1014 [ + + ]: 1035450 : if (mptcp_stream_memory_free(sk, 1))
1015 [ + - ]: 1035390 : INDIRECT_CALL_1(sk->sk_write_space, sk_stream_write_space, sk);
1016 : 1035450 : }
1017 : :
1018 : 35340 : static inline void __mptcp_sync_sndbuf(struct sock *sk)
1019 : : {
1020 : 35340 : struct mptcp_subflow_context *subflow;
1021 : 35340 : int ssk_sndbuf, new_sndbuf;
1022 : :
1023 [ + - ]: 35340 : if (sk->sk_userlocks & SOCK_SNDBUF_LOCK)
1024 : : return;
1025 : :
1026 [ - + ]: 35340 : new_sndbuf = READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_wmem[0]);
1027 [ - + - + : 102216 : mptcp_for_each_subflow(mptcp_sk(sk), subflow) {
+ + ]
1028 : 66876 : ssk_sndbuf = READ_ONCE(mptcp_subflow_tcp_sock(subflow)->sk_sndbuf);
1029 : :
1030 : 66876 : subflow->cached_sndbuf = ssk_sndbuf;
1031 : 66876 : new_sndbuf += ssk_sndbuf;
1032 : : }
1033 : :
1034 : : /* the msk max wmem limit is <nr_subflows> * tcp wmem[2] */
1035 : 35340 : WRITE_ONCE(sk->sk_sndbuf, new_sndbuf);
1036 : 35340 : mptcp_write_space(sk);
1037 : : }
1038 : :
1039 : : /* The called held both the msk socket and the subflow socket locks,
1040 : : * possibly under BH
1041 : : */
1042 : 42 : static inline void __mptcp_propagate_sndbuf(struct sock *sk, struct sock *ssk)
1043 : : {
1044 : 3676 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1045 : :
1046 [ + + ]: 3676 : if (READ_ONCE(ssk->sk_sndbuf) != subflow->cached_sndbuf)
[ + + + - ]
1047 : 3572 : __mptcp_sync_sndbuf(sk);
1048 : : }
1049 : :
1050 : : /* the caller held only the subflow socket lock, either in process or
1051 : : * BH context. Additionally this can be called under the msk data lock,
1052 : : * so we can't acquire such lock here: let the delegate action acquires
1053 : : * the needed locks in suitable order.
1054 : : */
1055 : 878996 : static inline void mptcp_propagate_sndbuf(struct sock *sk, struct sock *ssk)
1056 : : {
1057 : 878996 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1058 : :
1059 [ + + ]: 878996 : if (likely(READ_ONCE(ssk->sk_sndbuf) == subflow->cached_sndbuf))
1060 : : return;
1061 : :
1062 : 122014 : local_bh_disable();
1063 : 122014 : mptcp_subflow_delegate(subflow, MPTCP_DELEGATE_SNDBUF);
1064 : 122014 : local_bh_enable();
1065 : : }
1066 : :
1067 : : #define MPTCP_TOKEN_MAX_RETRIES 4
1068 : :
1069 : : void __init mptcp_token_init(void);
1070 : 48 : static inline void mptcp_token_init_request(struct request_sock *req)
1071 : : {
1072 : 2356 : mptcp_subflow_rsk(req)->token_node.pprev = NULL;
1073 : : }
1074 : :
1075 : : int mptcp_token_new_request(struct request_sock *req);
1076 : : void mptcp_token_destroy_request(struct request_sock *req);
1077 : : int mptcp_token_new_connect(struct sock *ssk);
1078 : : void mptcp_token_accept(struct mptcp_subflow_request_sock *r,
1079 : : struct mptcp_sock *msk);
1080 : : bool mptcp_token_exists(u32 token);
1081 : : struct mptcp_sock *mptcp_token_get_sock(struct net *net, u32 token);
1082 : : struct mptcp_sock *mptcp_token_iter_next(const struct net *net, long *s_slot,
1083 : : long *s_num);
1084 : : void mptcp_token_destroy(struct mptcp_sock *msk);
1085 : :
1086 : : void mptcp_crypto_key_sha(u64 key, u32 *token, u64 *idsn);
1087 : :
1088 : : void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hmac);
1089 : : __sum16 __mptcp_make_csum(u64 data_seq, u32 subflow_seq, u16 data_len, __wsum sum);
1090 : :
1091 : : void __init mptcp_pm_init(void);
1092 : : void mptcp_pm_data_init(struct mptcp_sock *msk);
1093 : : void mptcp_pm_data_reset(struct mptcp_sock *msk);
1094 : : void mptcp_pm_destroy(struct mptcp_sock *msk);
1095 : : int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
1096 : : struct mptcp_addr_info *addr);
1097 : : int mptcp_pm_parse_entry(struct nlattr *attr, struct genl_info *info,
1098 : : bool require_family,
1099 : : struct mptcp_pm_addr_entry *entry);
1100 : : bool mptcp_pm_addr_families_match(const struct sock *sk,
1101 : : const struct mptcp_addr_info *loc,
1102 : : const struct mptcp_addr_info *rem);
1103 : : void mptcp_pm_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk);
1104 : : void mptcp_pm_new_connection(struct mptcp_sock *msk, const struct sock *ssk, int server_side);
1105 : : void mptcp_pm_fully_established(struct mptcp_sock *msk, const struct sock *ssk);
1106 : : bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk);
1107 : : void mptcp_pm_connection_closed(struct mptcp_sock *msk);
1108 : : void mptcp_pm_subflow_established(struct mptcp_sock *msk);
1109 : : bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk);
1110 : : void mptcp_pm_subflow_check_next(struct mptcp_sock *msk,
1111 : : const struct mptcp_subflow_context *subflow);
1112 : : void mptcp_pm_add_addr_received(const struct sock *ssk,
1113 : : const struct mptcp_addr_info *addr);
1114 : : void mptcp_pm_add_addr_echoed(struct mptcp_sock *msk,
1115 : : const struct mptcp_addr_info *addr);
1116 : : void mptcp_pm_add_addr_send_ack(struct mptcp_sock *msk);
1117 : : void mptcp_pm_send_ack(struct mptcp_sock *msk,
1118 : : struct mptcp_subflow_context *subflow,
1119 : : bool prio, bool backup);
1120 : : void mptcp_pm_addr_send_ack(struct mptcp_sock *msk);
1121 : : void mptcp_pm_nl_rm_addr(struct mptcp_sock *msk, u8 rm_id);
1122 : : void mptcp_pm_rm_subflow(struct mptcp_sock *msk,
1123 : : const struct mptcp_rm_list *rm_list);
1124 : : void mptcp_pm_rm_addr_received(struct mptcp_sock *msk,
1125 : : const struct mptcp_rm_list *rm_list);
1126 : : void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup);
1127 : : void mptcp_pm_mp_fail_received(struct sock *sk, u64 fail_seq);
1128 : : int mptcp_pm_mp_prio_send_ack(struct mptcp_sock *msk,
1129 : : struct mptcp_addr_info *addr,
1130 : : struct mptcp_addr_info *rem,
1131 : : u8 bkup);
1132 : : bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk,
1133 : : const struct mptcp_addr_info *addr);
1134 : : bool mptcp_pm_sport_in_anno_list(struct mptcp_sock *msk, const struct sock *sk);
1135 : : struct mptcp_pm_add_entry *
1136 : : mptcp_pm_del_add_timer(struct mptcp_sock *msk,
1137 : : const struct mptcp_addr_info *addr, bool check_id);
1138 : : bool mptcp_lookup_subflow_by_saddr(const struct list_head *list,
1139 : : const struct mptcp_addr_info *saddr);
1140 : : bool mptcp_remove_anno_list_by_saddr(struct mptcp_sock *msk,
1141 : : const struct mptcp_addr_info *addr);
1142 : : int mptcp_pm_nl_set_flags(struct mptcp_pm_addr_entry *local,
1143 : : struct genl_info *info);
1144 : : int mptcp_userspace_pm_set_flags(struct mptcp_pm_addr_entry *local,
1145 : : struct genl_info *info);
1146 : : int mptcp_pm_announce_addr(struct mptcp_sock *msk,
1147 : : const struct mptcp_addr_info *addr,
1148 : : bool echo);
1149 : : int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_list);
1150 : : void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk,
1151 : : struct mptcp_pm_addr_entry *entry);
1152 : :
1153 : : /* the default path manager, used in mptcp_pm_unregister */
1154 : : extern struct mptcp_pm_ops mptcp_pm_kernel;
1155 : :
1156 : : struct mptcp_pm_ops *mptcp_pm_find(const char *name);
1157 : : int mptcp_pm_register(struct mptcp_pm_ops *pm_ops);
1158 : : void mptcp_pm_unregister(struct mptcp_pm_ops *pm_ops);
1159 : : int mptcp_pm_validate(struct mptcp_pm_ops *pm_ops);
1160 : : void mptcp_pm_get_available(char *buf, size_t maxlen);
1161 : :
1162 : : void mptcp_userspace_pm_free_local_addr_list(struct mptcp_sock *msk);
1163 : :
1164 : : void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
1165 : : const struct sock *ssk, gfp_t gfp);
1166 : : void mptcp_event_addr_announced(const struct sock *ssk, const struct mptcp_addr_info *info);
1167 : : void mptcp_event_addr_removed(const struct mptcp_sock *msk, u8 id);
1168 : : void mptcp_event_pm_listener(const struct sock *ssk,
1169 : : enum mptcp_event_type event);
1170 : : bool mptcp_userspace_pm_active(const struct mptcp_sock *msk);
1171 : :
1172 : : void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context *subflow,
1173 : : struct request_sock *req);
1174 : : int mptcp_pm_genl_fill_addr(struct sk_buff *msg,
1175 : : struct netlink_callback *cb,
1176 : : struct mptcp_pm_addr_entry *entry);
1177 : :
1178 : 188 : static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk)
1179 : : {
1180 [ - + + - : 3778063 : return READ_ONCE(msk->pm.addr_signal) &
+ + - - ]
[ + + ]
1181 : : (BIT(MPTCP_ADD_ADDR_SIGNAL) | BIT(MPTCP_ADD_ADDR_ECHO));
1182 : : }
1183 : :
1184 : 0 : static inline bool mptcp_pm_should_add_signal_addr(struct mptcp_sock *msk)
1185 : : {
1186 [ + + + - ]: 132 : return READ_ONCE(msk->pm.addr_signal) & BIT(MPTCP_ADD_ADDR_SIGNAL);
1187 : : }
1188 : :
1189 : 6 : static inline bool mptcp_pm_should_add_signal_echo(struct mptcp_sock *msk)
1190 : : {
1191 [ + + ]: 867 : return READ_ONCE(msk->pm.addr_signal) & BIT(MPTCP_ADD_ADDR_ECHO);
1192 : : }
1193 : :
1194 : 182 : static inline bool mptcp_pm_should_rm_signal(struct mptcp_sock *msk)
1195 : : {
1196 [ - + + + ]: 3775475 : return READ_ONCE(msk->pm.addr_signal) & BIT(MPTCP_RM_ADDR_SIGNAL);
[ + + ]
1197 : : }
1198 : :
1199 : 6 : static inline bool mptcp_pm_is_userspace(const struct mptcp_sock *msk)
1200 : : {
1201 [ + + + + : 9943 : return READ_ONCE(msk->pm.pm_type) == MPTCP_PM_TYPE_USERSPACE;
+ + + + +
+ + + ]
[ + + ][ - +
+ - - + +
+ - + ]
1202 : : }
1203 : :
1204 : 15 : static inline bool mptcp_pm_is_kernel(const struct mptcp_sock *msk)
1205 : : {
1206 [ + + ]: 1107 : return READ_ONCE(msk->pm.pm_type) == MPTCP_PM_TYPE_KERNEL;
[ + - - - ]
1207 : : }
1208 : :
1209 : 12 : static inline unsigned int mptcp_add_addr_len(int family, bool echo, bool port)
1210 : : {
1211 : 1716 : u8 len = TCPOLEN_MPTCP_ADD_ADDR_BASE;
1212 : :
1213 [ + + ]: 1716 : if (family == AF_INET6)
1214 : 402 : len = TCPOLEN_MPTCP_ADD_ADDR6_BASE;
1215 [ + + ]: 1716 : if (!echo)
1216 : 932 : len += MPTCPOPT_THMAC_LEN;
1217 : : /* account for 2 trailing 'nop' options */
1218 [ + + ]: 1716 : if (port)
1219 : 190 : len += TCPOLEN_MPTCP_PORT_LEN + TCPOLEN_MPTCP_PORT_ALIGN;
1220 : :
1221 [ + + ]: 1716 : return len;
1222 : : }
1223 : :
1224 : 0 : static inline int mptcp_rm_addr_len(const struct mptcp_rm_list *rm_list)
1225 : : {
1226 [ - + ]: 216 : if (rm_list->nr == 0 || rm_list->nr > MPTCP_RM_IDS_MAX)
1227 : : return -EINVAL;
1228 : :
1229 [ - + ]: 216 : return TCPOLEN_MPTCP_RM_ADDR_BASE + roundup(rm_list->nr - 1, 4) + 1;
1230 : : }
1231 : :
1232 : : bool mptcp_pm_add_addr_signal(struct mptcp_sock *msk, const struct sk_buff *skb,
1233 : : unsigned int opt_size, unsigned int remaining,
1234 : : struct mptcp_addr_info *addr, bool *echo,
1235 : : bool *drop_other_suboptions);
1236 : : bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
1237 : : struct mptcp_rm_list *rm_list);
1238 : : int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
1239 : : int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk,
1240 : : struct mptcp_pm_addr_entry *skc);
1241 : : int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk,
1242 : : struct mptcp_pm_addr_entry *skc);
1243 : : bool mptcp_pm_is_backup(struct mptcp_sock *msk, struct sock_common *skc);
1244 : : bool mptcp_pm_nl_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc);
1245 : : bool mptcp_userspace_pm_is_backup(struct mptcp_sock *msk, struct mptcp_addr_info *skc);
1246 : : int mptcp_pm_nl_dump_addr(struct sk_buff *msg,
1247 : : struct netlink_callback *cb);
1248 : : int mptcp_userspace_pm_dump_addr(struct sk_buff *msg,
1249 : : struct netlink_callback *cb);
1250 : : int mptcp_pm_nl_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
1251 : : struct genl_info *info);
1252 : : int mptcp_userspace_pm_get_addr(u8 id, struct mptcp_pm_addr_entry *addr,
1253 : : struct genl_info *info);
1254 : :
1255 : 0 : static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflow)
1256 : : {
1257 : 1120 : int local_id = READ_ONCE(subflow->local_id);
1258 : :
1259 : 1120 : if (local_id < 0)
1260 : : return 0;
1261 : : return local_id;
1262 : : }
1263 : :
1264 : : void __init mptcp_pm_kernel_register(void);
1265 : : void __init mptcp_pm_userspace_register(void);
1266 : : void __init mptcp_pm_nl_init(void);
1267 : : void mptcp_pm_worker(struct mptcp_sock *msk);
1268 : : void __mptcp_pm_kernel_worker(struct mptcp_sock *msk);
1269 : : u8 mptcp_pm_get_endp_signal_max(const struct mptcp_sock *msk);
1270 : : u8 mptcp_pm_get_endp_subflow_max(const struct mptcp_sock *msk);
1271 : : u8 mptcp_pm_get_endp_laminar_max(const struct mptcp_sock *msk);
1272 : : u8 mptcp_pm_get_endp_fullmesh_max(const struct mptcp_sock *msk);
1273 : : u8 mptcp_pm_get_limit_add_addr_accepted(const struct mptcp_sock *msk);
1274 : : u8 mptcp_pm_get_limit_extra_subflows(const struct mptcp_sock *msk);
1275 : :
1276 : : /* called under PM lock */
1277 : 625 : static inline void __mptcp_pm_close_subflow(struct mptcp_sock *msk)
1278 : : {
1279 [ + - ]: 625 : if (--msk->pm.extra_subflows < mptcp_pm_get_limit_extra_subflows(msk))
1280 : 625 : WRITE_ONCE(msk->pm.accept_subflow, true);
1281 : 625 : }
1282 : :
1283 : 46 : static inline void mptcp_pm_close_subflow(struct mptcp_sock *msk)
1284 : : {
1285 : 46 : spin_lock_bh(&msk->pm.lock);
1286 : 46 : __mptcp_pm_close_subflow(msk);
1287 : 46 : spin_unlock_bh(&msk->pm.lock);
1288 : 46 : }
1289 : :
1290 : 1101 : static inline bool mptcp_pm_add_addr_c_flag_case(struct mptcp_sock *msk)
1291 : : {
1292 [ - + ]: 961 : return READ_ONCE(msk->pm.remote_deny_join_id0) &&
1293 [ + + + + ]: 38 : msk->pm.local_addr_used == 0 &&
[ # # ]
1294 [ + + - + ]: 1107 : mptcp_pm_get_limit_add_addr_accepted(msk) == 0 &&
1295 [ # # ]: 4 : msk->pm.extra_subflows < mptcp_pm_get_limit_extra_subflows(msk);
1296 : : }
1297 : :
1298 : : void mptcp_sockopt_sync_locked(struct mptcp_sock *msk, struct sock *ssk);
1299 : :
1300 : 0 : static inline struct mptcp_ext *mptcp_get_ext(const struct sk_buff *skb)
1301 : : {
1302 [ + - + + : 4486318 : return (struct mptcp_ext *)skb_ext_find(skb, SKB_EXT_MPTCP);
+ + + + ]
[ + + + - ]
[ + - + -
+ - ][ - -
- - - + -
+ + + + -
- - ][ + -
+ - + - -
- - - ]
1303 : : }
1304 : :
1305 : : void mptcp_diag_subflow_init(struct tcp_ulp_ops *ops);
1306 : :
1307 : 11695246 : static inline bool __mptcp_check_fallback(const struct mptcp_sock *msk)
1308 : : {
1309 [ - + - - : 11695246 : return test_bit(MPTCP_FALLBACK_DONE, &msk->flags);
- - ]
1310 : : }
1311 : :
1312 : 1234699 : static inline bool mptcp_check_fallback(const struct sock *sk)
1313 : : {
1314 : 1234699 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
1315 [ - + ]: 1234699 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
1316 : :
1317 : 1234699 : return __mptcp_check_fallback(msk);
1318 : : }
1319 : :
1320 : 1061 : static inline bool __mptcp_has_initial_subflow(const struct mptcp_sock *msk)
1321 : : {
1322 : 1061 : struct sock *ssk = READ_ONCE(msk->first);
1323 : :
1324 [ + - - + : 2122 : return ssk && ((1 << inet_sk_state_load(ssk)) &
+ + ]
[ + - + + ]
1325 : : (TCPF_ESTABLISHED | TCPF_SYN_SENT |
1326 : : TCPF_SYN_RECV | TCPF_LISTEN));
1327 : : }
1328 : :
1329 : : bool __mptcp_try_fallback(struct mptcp_sock *msk, int fb_mib);
1330 : :
1331 : 184 : static inline bool mptcp_try_fallback(struct sock *ssk, int fb_mib)
1332 : : {
1333 : 184 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1334 : 184 : struct sock *sk = subflow->conn;
1335 : 184 : struct mptcp_sock *msk;
1336 : :
1337 [ - + ]: 184 : msk = mptcp_sk(sk);
1338 [ + + ]: 184 : if (!__mptcp_try_fallback(msk, fb_mib))
1339 : : return false;
1340 [ - + - + : 172 : if (READ_ONCE(msk->snd_data_fin_enable) && !(ssk->sk_shutdown & SEND_SHUTDOWN)) {
- - ]
[ - + - - ]
1341 : 0 : gfp_t saved_allocation = ssk->sk_allocation;
1342 : :
1343 : : /* we are in a atomic (BH) scope, override ssk default for data
1344 : : * fin allocation
1345 : : */
1346 : 0 : ssk->sk_allocation = GFP_ATOMIC;
1347 : 0 : ssk->sk_shutdown |= SEND_SHUTDOWN;
1348 : 0 : tcp_shutdown(ssk, SEND_SHUTDOWN);
1349 : 0 : ssk->sk_allocation = saved_allocation;
1350 : : }
1351 : : return true;
1352 : : }
1353 : :
1354 : 28 : static inline void mptcp_early_fallback(struct mptcp_sock *msk,
1355 : : struct mptcp_subflow_context *subflow,
1356 : : int fb_mib)
1357 : : {
1358 : 28 : subflow->request_mptcp = 0;
1359 [ - + ]: 28 : WARN_ON_ONCE(!__mptcp_try_fallback(msk, fb_mib));
1360 : 28 : }
1361 : :
1362 : 123143 : static inline bool mptcp_check_infinite_map(struct sk_buff *skb)
1363 : : {
1364 : 123143 : struct mptcp_ext *mpext;
1365 : :
1366 [ + + ]: 123143 : mpext = skb ? mptcp_get_ext(skb) : NULL;
1367 [ + + + + ]: 23500 : if (mpext && mpext->infinite_map)
1368 : 1 : return true;
1369 : :
1370 : : return false;
1371 : : }
1372 : :
1373 : 0 : static inline bool is_active_ssk(struct mptcp_subflow_context *subflow)
1374 : : {
1375 [ + - - - ]: 6 : return (subflow->request_mptcp || subflow->request_join);
1376 : : }
1377 : :
1378 : 1736 : static inline bool subflow_simultaneous_connect(struct sock *sk)
1379 : : {
1380 : 1736 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
1381 : :
1382 : : /* Note that the sk state implies !subflow->conn_finished. */
1383 [ + + ]: 1736 : return sk->sk_state == TCP_SYN_RECV && is_active_ssk(subflow);
1384 : : }
1385 : :
1386 : : #ifdef CONFIG_SYN_COOKIES
1387 : : void subflow_init_req_cookie_join_save(const struct mptcp_subflow_request_sock *subflow_req,
1388 : : struct sk_buff *skb);
1389 : : bool mptcp_token_join_cookie_init_state(struct mptcp_subflow_request_sock *subflow_req,
1390 : : struct sk_buff *skb);
1391 : : void __init mptcp_join_cookie_init(void);
1392 : : #else
1393 : : static inline void
1394 : : subflow_init_req_cookie_join_save(const struct mptcp_subflow_request_sock *subflow_req,
1395 : : struct sk_buff *skb) {}
1396 : : static inline bool
1397 : : mptcp_token_join_cookie_init_state(struct mptcp_subflow_request_sock *subflow_req,
1398 : : struct sk_buff *skb)
1399 : : {
1400 : : return false;
1401 : : }
1402 : :
1403 : : static inline void mptcp_join_cookie_init(void) {}
1404 : : #endif
1405 : :
1406 : : #endif /* __MPTCP_PROTOCOL_H */
|