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