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 : : #define pr_fmt(fmt) "MPTCP: " fmt
8 : :
9 : : #include <linux/kernel.h>
10 : : #include <linux/module.h>
11 : : #include <linux/netdevice.h>
12 : : #include <linux/sched/signal.h>
13 : : #include <linux/atomic.h>
14 : : #include <net/aligned_data.h>
15 : : #include <net/rps.h>
16 : : #include <net/sock.h>
17 : : #include <net/inet_common.h>
18 : : #include <net/inet_hashtables.h>
19 : : #include <net/protocol.h>
20 : : #include <net/tcp_states.h>
21 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
22 : : #include <net/transp_v6.h>
23 : : #endif
24 : : #include <net/mptcp.h>
25 : : #include <net/hotdata.h>
26 : : #include <net/xfrm.h>
27 : : #include <asm/ioctls.h>
28 : : #include "protocol.h"
29 : : #include "mib.h"
30 : :
31 : : static unsigned int mptcp_inq_hint(const struct sock *sk);
32 : :
33 : : #define CREATE_TRACE_POINTS
34 : : #include <trace/events/mptcp.h>
35 : :
36 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
37 : : struct mptcp6_sock {
38 : : struct mptcp_sock msk;
39 : : struct ipv6_pinfo np;
40 : : };
41 : : #endif
42 : :
43 : : enum {
44 : : MPTCP_CMSG_TS = BIT(0),
45 : : MPTCP_CMSG_INQ = BIT(1),
46 : : };
47 : :
48 : : static struct percpu_counter mptcp_sockets_allocated ____cacheline_aligned_in_smp;
49 : :
50 : : static void __mptcp_destroy_sock(struct sock *sk);
51 : : static void mptcp_check_send_data_fin(struct sock *sk);
52 : :
53 : : DEFINE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions) = {
54 : : .bh_lock = INIT_LOCAL_LOCK(bh_lock),
55 : : };
56 : : static struct net_device *mptcp_napi_dev;
57 : :
58 : : /* Returns end sequence number of the receiver's advertised window */
59 : 24 : static u64 mptcp_wnd_end(const struct mptcp_sock *msk)
60 : : {
61 : 1764438 : return READ_ONCE(msk->wnd_end);
62 : : }
63 : :
64 : 178 : static const struct proto_ops *mptcp_fallback_tcp_ops(const struct sock *sk)
65 : : {
66 : 178 : unsigned short family = READ_ONCE(sk->sk_family);
67 : :
68 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
69 [ + + ]: 178 : if (family == AF_INET6)
70 : : return &inet6_stream_ops;
71 : : #endif
72 [ - + ]: 88 : WARN_ON_ONCE(family != AF_INET);
73 : : return &inet_stream_ops;
74 : : }
75 : :
76 : 212 : bool __mptcp_try_fallback(struct mptcp_sock *msk, int fb_mib)
77 : : {
78 : 212 : struct net *net = sock_net((struct sock *)msk);
79 : :
80 [ - + ]: 212 : if (__mptcp_check_fallback(msk))
81 : : return true;
82 : :
83 : : /* The caller possibly is not holding the msk socket lock, but
84 : : * in the fallback case only the current subflow is touching
85 : : * the OoO queue.
86 : : */
87 [ - + ]: 212 : if (!RB_EMPTY_ROOT(&msk->out_of_order_queue))
88 : : return false;
89 : :
90 : 212 : spin_lock_bh(&msk->fallback_lock);
91 [ - + + + ]: 212 : if (!msk->allow_infinite_fallback) {
[ + + ]
92 : 12 : spin_unlock_bh(&msk->fallback_lock);
93 : 12 : return false;
94 : : }
95 : :
96 : 200 : msk->allow_subflows = false;
97 : 200 : set_bit(MPTCP_FALLBACK_DONE, &msk->flags);
98 [ + - ]: 200 : __MPTCP_INC_STATS(net, fb_mib);
99 : 200 : spin_unlock_bh(&msk->fallback_lock);
100 : 200 : return true;
101 : : }
102 : :
103 : 3426 : static int __mptcp_socket_create(struct mptcp_sock *msk)
104 : : {
105 : 3426 : struct mptcp_subflow_context *subflow;
106 : 3426 : struct sock *sk = (struct sock *)msk;
107 : 3426 : struct socket *ssock;
108 : 3426 : int err;
109 : :
110 : 3426 : err = mptcp_subflow_create_socket(sk, sk->sk_family, &ssock);
111 [ + - ]: 3426 : if (err)
112 : : return err;
113 : :
114 [ - + ]: 3426 : msk->scaling_ratio = tcp_sk(ssock->sk)->scaling_ratio;
115 : 3426 : WRITE_ONCE(msk->first, ssock->sk);
116 : 3426 : subflow = mptcp_subflow_ctx(ssock->sk);
117 : 3426 : list_add(&subflow->node, &msk->conn_list);
118 : 3426 : sock_hold(ssock->sk);
119 : 3426 : subflow->request_mptcp = 1;
120 : 3426 : subflow->subflow_id = msk->subflow_id++;
121 : :
122 : : /* This is the first subflow, always with id 0 */
123 : 3426 : WRITE_ONCE(subflow->local_id, 0);
124 : 3426 : mptcp_sock_graft(msk->first, sk->sk_socket);
125 : 3426 : iput(SOCK_INODE(ssock));
126 : :
127 : 3426 : return 0;
128 : : }
129 : :
130 : : /* If the MPC handshake is not started, returns the first subflow,
131 : : * eventually allocating it.
132 : : */
133 : 10016 : struct sock *__mptcp_nmpc_sk(struct mptcp_sock *msk)
134 : : {
135 : 10016 : struct sock *sk = (struct sock *)msk;
136 : 10016 : int ret;
137 : :
138 [ - + + + ]: 10016 : if (!((1 << sk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)))
[ + + ]
139 : : return ERR_PTR(-EINVAL);
140 : :
141 [ + + ]: 9998 : if (!msk->first) {
142 : 3426 : ret = __mptcp_socket_create(msk);
143 [ - + ]: 3426 : if (ret)
144 : 0 : return ERR_PTR(ret);
145 : : }
146 : :
147 : 9998 : return msk->first;
148 : : }
149 : :
150 : 0 : static void mptcp_drop(struct sock *sk, struct sk_buff *skb)
151 : : {
152 : 284 : sk_drops_skbadd(sk, skb);
153 : 278 : __kfree_skb(skb);
154 : : }
155 : :
156 : 572648 : static bool __mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
157 : : struct sk_buff *from, bool *fragstolen,
158 : : int *delta)
159 : : {
160 : 572648 : int limit = READ_ONCE(sk->sk_rcvbuf);
161 : :
162 [ + + ]: 572648 : if (unlikely(MPTCP_SKB_CB(to)->cant_coalesce) ||
163 [ + + ]: 572623 : MPTCP_SKB_CB(from)->offset ||
164 [ + + + + ]: 1099707 : ((to->len + from->len) > (limit >> 3)) ||
165 : 527087 : !skb_try_coalesce(to, from, fragstolen, delta))
166 : 146824 : return false;
167 : :
168 [ - + - - ]: 425824 : pr_debug("colesced seq %llx into %llx new len %d new end seq %llx\n",
169 : : MPTCP_SKB_CB(from)->map_seq, MPTCP_SKB_CB(to)->map_seq,
170 : : to->len, MPTCP_SKB_CB(from)->end_seq);
171 : 425824 : MPTCP_SKB_CB(to)->end_seq = MPTCP_SKB_CB(from)->end_seq;
172 : 425824 : return true;
173 : : }
174 : :
175 : 525214 : static bool mptcp_try_coalesce(struct sock *sk, struct sk_buff *to,
176 : : struct sk_buff *from)
177 : : {
178 : 525214 : bool fragstolen;
179 : 525214 : int delta;
180 : :
181 [ + + ]: 525214 : if (!__mptcp_try_coalesce(sk, to, from, &fragstolen, &delta))
182 : : return false;
183 : :
184 : : /* note the fwd memory can reach a negative value after accounting
185 : : * for the delta, but the later skb free will restore a non
186 : : * negative one
187 : : */
188 : 397140 : atomic_add(delta, &sk->sk_rmem_alloc);
189 [ + - ]: 397140 : sk_mem_charge(sk, delta);
190 [ - + ]: 397140 : kfree_skb_partial(from, fragstolen);
191 : :
192 : 397140 : return true;
193 : : }
194 : :
195 : 0 : static bool mptcp_ooo_try_coalesce(struct mptcp_sock *msk, struct sk_buff *to,
196 : : struct sk_buff *from)
197 : : {
198 [ + + ]: 35785 : if (MPTCP_SKB_CB(from)->map_seq != MPTCP_SKB_CB(to)->end_seq)
199 : : return false;
200 : :
201 : 212305 : return mptcp_try_coalesce((struct sock *)msk, to, from);
202 : : }
203 : :
204 : : /* "inspired" by tcp_rcvbuf_grow(), main difference:
205 : : * - mptcp does not maintain a msk-level window clamp
206 : : * - returns true when the receive buffer is actually updated
207 : : */
208 : 5001 : static bool mptcp_rcvbuf_grow(struct sock *sk, u32 newval)
209 : : {
210 [ - + ]: 5001 : struct mptcp_sock *msk = mptcp_sk(sk);
211 [ + - ]: 5001 : const struct net *net = sock_net(sk);
212 : 5001 : u32 rcvwin, rcvbuf, cap, oldval;
213 : 5001 : u64 grow;
214 : :
215 : 5001 : oldval = msk->rcvq_space.space;
216 : 5001 : msk->rcvq_space.space = newval;
217 [ + - ]: 5001 : if (!READ_ONCE(net->ipv4.sysctl_tcp_moderate_rcvbuf) ||
218 [ - + ]: 5001 : (sk->sk_userlocks & SOCK_RCVBUF_LOCK))
219 : : return false;
220 : :
221 : : /* DRS is always one RTT late. */
222 : 5001 : rcvwin = newval << 1;
223 : :
224 : : /* slow start: allow the sender to double its rate. */
225 : 5001 : grow = (u64)rcvwin * (newval - oldval);
226 : 5001 : do_div(grow, oldval);
227 : 5001 : rcvwin += grow << 1;
228 : :
229 : 5001 : cap = READ_ONCE(net->ipv4.sysctl_tcp_rmem[2]);
230 : :
231 : 5001 : rcvbuf = min_t(u32, mptcp_space_from_win(sk, rcvwin), cap);
232 [ + + ]: 5001 : if (rcvbuf > sk->sk_rcvbuf) {
233 : 2734 : WRITE_ONCE(sk->sk_rcvbuf, rcvbuf);
234 : 2734 : return true;
235 : : }
236 : : return false;
237 : : }
238 : :
239 : : /* "inspired" by tcp_data_queue_ofo(), main differences:
240 : : * - use mptcp seqs
241 : : * - don't cope with sacks
242 : : */
243 : 191167 : static void mptcp_data_queue_ofo(struct mptcp_sock *msk, struct sk_buff *skb)
244 : : {
245 : 191167 : struct sock *sk = (struct sock *)msk;
246 : 191167 : struct rb_node **p, *parent;
247 : 191167 : u64 seq, end_seq, max_seq;
248 : 191167 : struct sk_buff *skb1;
249 : :
250 : 191167 : seq = MPTCP_SKB_CB(skb)->map_seq;
251 : 191167 : end_seq = MPTCP_SKB_CB(skb)->end_seq;
252 [ - + ]: 191167 : max_seq = atomic64_read(&msk->rcv_wnd_sent);
253 : :
254 [ - + - - ]: 191167 : pr_debug("msk=%p seq=%llx limit=%llx empty=%d\n", msk, seq, max_seq,
255 : : RB_EMPTY_ROOT(&msk->out_of_order_queue));
256 [ + + ]: 191167 : if (after64(end_seq, max_seq)) {
257 : : /* out of window */
258 : 36 : mptcp_drop(sk, skb);
259 [ - + - - ]: 36 : pr_debug("oow by %lld, rcv_wnd_sent %llu\n",
260 : : (unsigned long long)end_seq - (unsigned long)max_seq,
261 : : (unsigned long long)atomic64_read(&msk->rcv_wnd_sent));
262 [ # # ]: 36 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_NODSSWINDOW);
263 : 36 : return;
264 : : }
265 : :
266 : 191131 : p = &msk->out_of_order_queue.rb_node;
267 [ + - ]: 191131 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUE);
268 [ + + ]: 191131 : if (RB_EMPTY_ROOT(&msk->out_of_order_queue)) {
269 : 6107 : rb_link_node(&skb->rbnode, NULL, p);
270 : 6107 : rb_insert_color(&skb->rbnode, &msk->out_of_order_queue);
271 : 6107 : msk->ooo_last_skb = skb;
272 : 6107 : goto end;
273 : : }
274 : :
275 : : /* with 2 subflows, adding at end of ooo queue is quite likely
276 : : * Use of ooo_last_skb avoids the O(Log(N)) rbtree lookup.
277 : : */
278 [ + + + + ]: 342731 : if (mptcp_ooo_try_coalesce(msk, msk->ooo_last_skb, skb)) {
279 [ + - ]: 141564 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOMERGE);
280 [ + - ]: 141564 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUETAIL);
281 : 141564 : return;
282 : : }
283 : :
284 : : /* Can avoid an rbtree lookup if we are adding skb after ooo_last_skb */
285 [ + + ]: 43460 : if (!before64(seq, MPTCP_SKB_CB(msk->ooo_last_skb)->end_seq)) {
286 [ + - ]: 21928 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOQUEUETAIL);
287 : 21928 : parent = &msk->ooo_last_skb->rbnode;
288 : 21928 : p = &parent->rb_right;
289 : 21928 : goto insert;
290 : : }
291 : :
292 : : /* Find place to insert this segment. Handle overlaps on the way. */
293 : : parent = NULL;
294 [ + + ]: 123661 : while (*p) {
295 : 115785 : parent = *p;
296 : 115785 : skb1 = rb_to_skb(parent);
297 [ + + ]: 115785 : if (before64(seq, MPTCP_SKB_CB(skb1)->map_seq)) {
298 : 30173 : p = &parent->rb_left;
299 : 30173 : continue;
300 : : }
301 [ + + ]: 85612 : if (before64(seq, MPTCP_SKB_CB(skb1)->end_seq)) {
302 [ + + ]: 588 : if (!after64(end_seq, MPTCP_SKB_CB(skb1)->end_seq)) {
303 : : /* All the bits are present. Drop. */
304 : 476 : mptcp_drop(sk, skb);
305 [ + - ]: 476 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
306 : 476 : return;
307 : : }
308 [ + + ]: 112 : if (after64(seq, MPTCP_SKB_CB(skb1)->map_seq)) {
309 : : /* partial overlap:
310 : : * | skb |
311 : : * | skb1 |
312 : : * continue traversing
313 : : */
314 : : } else {
315 : : /* skb's seq == skb1's seq and skb covers skb1.
316 : : * Replace skb1 with skb.
317 : : */
318 : 23 : rb_replace_node(&skb1->rbnode, &skb->rbnode,
319 : : &msk->out_of_order_queue);
320 : 23 : mptcp_drop(sk, skb1);
321 [ + - ]: 23 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
322 : 23 : goto merge_right;
323 : : }
324 [ + + + + ]: 104239 : } else if (mptcp_ooo_try_coalesce(msk, skb1, skb)) {
325 [ + - ]: 13157 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_OFOMERGE);
326 : 13157 : return;
327 : : }
328 : 71956 : p = &parent->rb_right;
329 : : }
330 : :
331 : 7876 : insert:
332 : : /* Insert segment into RB tree. */
333 : 29804 : rb_link_node(&skb->rbnode, parent, p);
334 : 29804 : rb_insert_color(&skb->rbnode, &msk->out_of_order_queue);
335 : :
336 : : merge_right:
337 : : /* Remove other segments covered by skb. */
338 [ + + ]: 29873 : while ((skb1 = skb_rb_next(skb)) != NULL) {
339 [ + + ]: 7945 : if (before64(end_seq, MPTCP_SKB_CB(skb1)->end_seq))
340 : : break;
341 : 46 : rb_erase(&skb1->rbnode, &msk->out_of_order_queue);
342 : 46 : mptcp_drop(sk, skb1);
343 [ + - ]: 46 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
344 : : }
345 : : /* If there is no skb after us, we are the last_skb ! */
346 [ + + ]: 29827 : if (!skb1)
347 : 21928 : msk->ooo_last_skb = skb;
348 : :
349 : 7899 : end:
350 : 35934 : skb_condense(skb);
351 : 35934 : skb_set_owner_r(skb, sk);
352 : : }
353 : :
354 : 1200648 : static void mptcp_init_skb(struct sock *ssk, struct sk_buff *skb, int offset,
355 : : int copy_len)
356 : : {
357 : 1200648 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
358 : 1200648 : bool has_rxtstamp = TCP_SKB_CB(skb)->has_rxtstamp;
359 : :
360 : : /* the skb map_seq accounts for the skb offset:
361 : : * mptcp_subflow_get_mapped_dsn() is based on the current tp->copied_seq
362 : : * value
363 : : */
364 : 1200648 : MPTCP_SKB_CB(skb)->map_seq = mptcp_subflow_get_mapped_dsn(subflow);
365 : 1200648 : MPTCP_SKB_CB(skb)->end_seq = MPTCP_SKB_CB(skb)->map_seq + copy_len;
366 : 1200648 : MPTCP_SKB_CB(skb)->offset = offset;
367 : 1200648 : MPTCP_SKB_CB(skb)->has_rxtstamp = has_rxtstamp;
368 : 1200648 : MPTCP_SKB_CB(skb)->cant_coalesce = 0;
369 : :
370 : 1200648 : __skb_unlink(skb, &ssk->sk_receive_queue);
371 : :
372 : 1200648 : skb_ext_reset(skb);
373 [ - + ]: 1200648 : skb_dst_drop(skb);
374 : 1200648 : }
375 : :
376 : 1171960 : static bool __mptcp_move_skb(struct sock *sk, struct sk_buff *skb)
377 : : {
378 : 1171960 : u64 copy_len = MPTCP_SKB_CB(skb)->end_seq - MPTCP_SKB_CB(skb)->map_seq;
379 [ - + ]: 1171960 : struct mptcp_sock *msk = mptcp_sk(sk);
380 : 1171960 : struct sk_buff *tail;
381 : :
382 : 1171960 : mptcp_borrow_fwdmem(sk, skb);
383 : :
384 [ + + ]: 1171960 : if (MPTCP_SKB_CB(skb)->map_seq == msk->ack_seq) {
385 : : /* in sequence */
386 : 980787 : msk->bytes_received += copy_len;
387 : 980787 : WRITE_ONCE(msk->ack_seq, msk->ack_seq + copy_len);
388 [ + + ]: 980787 : tail = skb_peek_tail(&sk->sk_receive_queue);
389 [ + - + + ]: 312909 : if (tail && mptcp_try_coalesce(sk, tail, skb))
390 : : return true;
391 : :
392 : 754054 : skb_set_owner_r(skb, sk);
393 : 754054 : __skb_queue_tail(&sk->sk_receive_queue, skb);
394 : 754054 : return true;
395 [ + + ]: 191173 : } else if (after64(MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq)) {
396 : 191167 : mptcp_data_queue_ofo(msk, skb);
397 : 191167 : return false;
398 : : }
399 : :
400 : : /* Completely old data? */
401 [ + - ]: 6 : if (!after64(MPTCP_SKB_CB(skb)->end_seq, msk->ack_seq)) {
402 [ # # ]: 6 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
403 : 6 : mptcp_drop(sk, skb);
404 : 6 : return false;
405 : : }
406 : :
407 : : /* Partial packet: map_seq < ack_seq < end_seq.
408 : : * Skip the already-acked bytes and enqueue the new data.
409 : : */
410 : 0 : copy_len = MPTCP_SKB_CB(skb)->end_seq - msk->ack_seq;
411 : 0 : MPTCP_SKB_CB(skb)->offset += msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq;
412 : 0 : MPTCP_SKB_CB(skb)->map_seq += msk->ack_seq -
413 : : MPTCP_SKB_CB(skb)->map_seq;
414 : 0 : msk->bytes_received += copy_len;
415 : 0 : WRITE_ONCE(msk->ack_seq, msk->ack_seq + copy_len);
416 : :
417 : 0 : skb_set_owner_r(skb, sk);
418 : 0 : __skb_queue_tail(&sk->sk_receive_queue, skb);
419 : 0 : return true;
420 : : }
421 : :
422 : 54760 : static void mptcp_stop_rtx_timer(struct sock *sk)
423 : : {
424 : 54760 : sk_stop_timer(sk, &sk->mptcp_retransmit_timer);
425 [ - + ]: 54760 : mptcp_sk(sk)->timer_ival = 0;
426 : 54760 : }
427 : :
428 : 6695 : static void mptcp_close_wake_up(struct sock *sk)
429 : : {
430 [ + + ]: 6695 : if (sock_flag(sk, SOCK_DEAD))
431 : : return;
432 : :
433 : 4408 : sk->sk_state_change(sk);
434 [ + + ]: 4408 : if (sk->sk_shutdown == SHUTDOWN_MASK ||
435 [ + + ]: 2187 : sk->sk_state == TCP_CLOSE)
436 : 2277 : sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_HUP);
437 : : else
438 : 2131 : sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
439 : : }
440 : :
441 : 2370 : static void mptcp_shutdown_subflows(struct mptcp_sock *msk)
442 : : {
443 : 2370 : struct mptcp_subflow_context *subflow;
444 : :
445 [ + + ]: 5574 : mptcp_for_each_subflow(msk, subflow) {
446 : 3204 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
447 : 3204 : bool slow;
448 : :
449 : 3204 : slow = lock_sock_fast(ssk);
450 : 3204 : tcp_shutdown(ssk, SEND_SHUTDOWN);
451 : 3204 : unlock_sock_fast(ssk, slow);
452 : : }
453 : 2370 : }
454 : :
455 : : /* called under the msk socket lock */
456 : 465050 : static bool mptcp_pending_data_fin_ack(struct sock *sk)
457 : : {
458 [ - + ]: 465050 : struct mptcp_sock *msk = mptcp_sk(sk);
459 : :
460 : 245384 : return ((1 << sk->sk_state) &
461 [ - + + + ]: 465050 : (TCPF_FIN_WAIT1 | TCPF_CLOSING | TCPF_LAST_ACK)) &&
[ + + ]
462 [ + + ]: 84096 : msk->write_seq == READ_ONCE(msk->snd_una);
463 : : }
464 : :
465 : 12412 : static void mptcp_check_data_fin_ack(struct sock *sk)
466 : : {
467 [ - + ]: 12412 : struct mptcp_sock *msk = mptcp_sk(sk);
468 : :
469 : : /* Look for an acknowledged DATA_FIN */
470 [ + + ]: 12412 : if (mptcp_pending_data_fin_ack(sk)) {
471 : 2520 : WRITE_ONCE(msk->snd_data_fin_enable, 0);
472 : :
473 [ + + - ]: 2520 : switch (sk->sk_state) {
474 : 1345 : case TCP_FIN_WAIT1:
475 : 1345 : mptcp_set_state(sk, TCP_FIN_WAIT2);
476 : 1345 : break;
477 : 1175 : case TCP_CLOSING:
478 : : case TCP_LAST_ACK:
479 : 1175 : mptcp_shutdown_subflows(msk);
480 : 1175 : mptcp_set_state(sk, TCP_CLOSE);
481 : 1175 : break;
482 : : }
483 : :
484 : 2520 : mptcp_close_wake_up(sk);
485 : : }
486 : 12412 : }
487 : :
488 : : /* can be called with no lock acquired */
489 : 1090137 : static bool mptcp_pending_data_fin(struct sock *sk, u64 *seq)
490 : : {
491 [ - + ]: 1090137 : struct mptcp_sock *msk = mptcp_sk(sk);
492 : :
493 [ - + + + : 1127030 : if (READ_ONCE(msk->rcv_data_fin) &&
- + + + ]
[ + + + + ]
[ - + + +
+ + ][ + + ]
494 [ - + ]: 27 : ((1 << inet_sk_state_load(sk)) &
495 : : (TCPF_ESTABLISHED | TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2))) {
496 : 35979 : u64 rcv_data_fin_seq = READ_ONCE(msk->rcv_data_fin_seq);
497 : :
498 [ + + ]: 35979 : if (READ_ONCE(msk->ack_seq) == rcv_data_fin_seq) {
499 [ + + ]: 3084 : if (seq)
500 : 2498 : *seq = rcv_data_fin_seq;
501 : :
502 : 3084 : return true;
503 : : }
504 : : }
505 : :
506 : : return false;
507 : : }
508 : :
509 : 1314 : static void mptcp_set_datafin_timeout(struct sock *sk)
510 : : {
511 : 1314 : struct inet_connection_sock *icsk = inet_csk(sk);
512 : 1314 : u32 retransmits;
513 : :
514 : 1314 : retransmits = min_t(u32, icsk->icsk_retransmits,
515 : : ilog2(TCP_RTO_MAX / TCP_RTO_MIN));
516 : :
517 [ - + ]: 1314 : mptcp_sk(sk)->timer_ival = TCP_RTO_MIN << retransmits;
518 : 1314 : }
519 : :
520 : 1109998 : static void __mptcp_set_timeout(struct sock *sk, long tout)
521 : : {
522 [ + + - + ]: 1908044 : mptcp_sk(sk)->timer_ival = tout > 0 ? tout : TCP_RTO_MIN;
523 : 1109998 : }
524 : :
525 : 24 : static long mptcp_timeout_from_subflow(const struct mptcp_subflow_context *subflow)
526 : : {
527 : 1548283 : const struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
528 : :
529 [ + + + + ]: 1254023 : return inet_csk(ssk)->icsk_pending && !subflow->stale_count ?
530 [ + + + + ]: 2631314 : tcp_timeout_expires(ssk) - jiffies : 0;
531 : : }
532 : :
533 : 357597 : static void mptcp_set_timeout(struct sock *sk)
534 : : {
535 : 357597 : struct mptcp_subflow_context *subflow;
536 : 357597 : long tout = 0;
537 : :
538 [ - + - + : 800617 : mptcp_for_each_subflow(mptcp_sk(sk), subflow)
+ + ]
539 [ + + ]: 764782 : tout = max(tout, mptcp_timeout_from_subflow(subflow));
540 : 357597 : __mptcp_set_timeout(sk, tout);
541 : 357597 : }
542 : :
543 : 334029 : static inline bool tcp_can_send_ack(const struct sock *ssk)
544 : : {
545 [ - + ]: 799551 : return !((1 << inet_sk_state_load(ssk)) &
546 : : (TCPF_SYN_SENT | TCPF_SYN_RECV | TCPF_TIME_WAIT | TCPF_CLOSE | TCPF_LISTEN));
547 : : }
548 : :
549 : 6164 : void __mptcp_subflow_send_ack(struct sock *ssk)
550 : : {
551 [ + + ]: 6164 : if (tcp_can_send_ack(ssk))
552 : 6008 : tcp_send_ack(ssk);
553 : 6164 : }
554 : :
555 : 5129 : static void mptcp_subflow_send_ack(struct sock *ssk)
556 : : {
557 : 5129 : bool slow;
558 : :
559 : 5129 : slow = lock_sock_fast(ssk);
560 : 5129 : __mptcp_subflow_send_ack(ssk);
561 : 5129 : unlock_sock_fast(ssk, slow);
562 : 5129 : }
563 : :
564 : 3662 : static void mptcp_send_ack(struct mptcp_sock *msk)
565 : : {
566 : 3662 : struct mptcp_subflow_context *subflow;
567 : :
568 [ + + ]: 8791 : mptcp_for_each_subflow(msk, subflow)
569 : 5129 : mptcp_subflow_send_ack(mptcp_subflow_tcp_sock(subflow));
570 : 3662 : }
571 : :
572 : 560645 : static void mptcp_subflow_cleanup_rbuf(struct sock *ssk, int copied)
573 : : {
574 : 560645 : bool slow;
575 : :
576 : 560645 : slow = lock_sock_fast(ssk);
577 [ + + ]: 560645 : if (tcp_can_send_ack(ssk))
578 : 557997 : tcp_cleanup_rbuf(ssk, copied);
579 : 560645 : unlock_sock_fast(ssk, slow);
580 : 560645 : }
581 : :
582 : 1356050 : static bool mptcp_subflow_could_cleanup(const struct sock *ssk, bool rx_empty)
583 : : {
584 : 1356050 : const struct inet_connection_sock *icsk = inet_csk(ssk);
585 : 1356050 : u8 ack_pending = READ_ONCE(icsk->icsk_ack.pending);
586 [ - + ]: 1356050 : const struct tcp_sock *tp = tcp_sk(ssk);
587 : :
588 [ + + ]: 1356050 : return (ack_pending & ICSK_ACK_SCHED) &&
589 : 688190 : ((READ_ONCE(tp->rcv_nxt) - READ_ONCE(tp->rcv_wup) >
590 [ + + + + ]: 688190 : READ_ONCE(icsk->icsk_ack.rcv_mss)) ||
591 [ + + ]: 202582 : (rx_empty && ack_pending &
592 : : (ICSK_ACK_PUSHED2 | ICSK_ACK_PUSHED)));
593 : : }
594 : :
595 : 1243071 : static void mptcp_cleanup_rbuf(struct mptcp_sock *msk, int copied)
596 : : {
597 : 1243071 : int old_space = READ_ONCE(msk->old_wspace);
598 : 1243071 : struct mptcp_subflow_context *subflow;
599 : 1243071 : struct sock *sk = (struct sock *)msk;
600 : 1243071 : int space = __mptcp_space(sk);
601 : 1243071 : bool cleanup, rx_empty;
602 : :
603 [ + + + + : 1243071 : cleanup = (space > 0) && (space >= (old_space << 1)) && copied;
+ + ]
604 [ + + + + ]: 1243071 : rx_empty = !sk_rmem_alloc_get(sk) && copied;
605 : :
606 [ + + ]: 2832898 : mptcp_for_each_subflow(msk, subflow) {
607 [ + + ]: 1589827 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
608 : :
609 [ + + + + ]: 1589827 : if (cleanup || mptcp_subflow_could_cleanup(ssk, rx_empty))
610 : 560645 : mptcp_subflow_cleanup_rbuf(ssk, copied);
611 : : }
612 : 1243071 : }
613 : :
614 : 140487 : static void mptcp_check_data_fin(struct sock *sk)
615 : : {
616 [ - + ]: 140487 : struct mptcp_sock *msk = mptcp_sk(sk);
617 : 140487 : u64 rcv_data_fin_seq;
618 : :
619 : : /* Need to ack a DATA_FIN received from a peer while this side
620 : : * of the connection is in ESTABLISHED, FIN_WAIT1, or FIN_WAIT2.
621 : : * msk->rcv_data_fin was set when parsing the incoming options
622 : : * at the subflow level and the msk lock was not held, so this
623 : : * is the first opportunity to act on the DATA_FIN and change
624 : : * the msk state.
625 : : *
626 : : * If we are caught up to the sequence number of the incoming
627 : : * DATA_FIN, send the DATA_ACK now and do state transition. If
628 : : * not caught up, do nothing and let the recv code send DATA_ACK
629 : : * when catching up.
630 : : */
631 : :
632 [ + + ]: 140487 : if (mptcp_pending_data_fin(sk, &rcv_data_fin_seq)) {
633 : 2498 : WRITE_ONCE(msk->ack_seq, msk->ack_seq + 1);
634 : 2498 : WRITE_ONCE(msk->rcv_data_fin, 0);
635 : :
636 : 2498 : WRITE_ONCE(sk->sk_shutdown, sk->sk_shutdown | RCV_SHUTDOWN);
637 : 2498 : smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
638 : :
639 [ + + + - ]: 2498 : switch (sk->sk_state) {
640 : : case TCP_ESTABLISHED:
641 : 1030 : mptcp_set_state(sk, TCP_CLOSE_WAIT);
642 : 1030 : break;
643 : 273 : case TCP_FIN_WAIT1:
644 : 273 : mptcp_set_state(sk, TCP_CLOSING);
645 : 273 : break;
646 : 1195 : case TCP_FIN_WAIT2:
647 : 1195 : mptcp_shutdown_subflows(msk);
648 : 1195 : mptcp_set_state(sk, TCP_CLOSE);
649 : 1195 : break;
650 : : default:
651 : : /* Other states not expected */
652 : 0 : WARN_ON_ONCE(1);
653 : 0 : break;
654 : : }
655 : :
656 [ + + ]: 2498 : if (!__mptcp_check_fallback(msk))
657 : 2348 : mptcp_send_ack(msk);
658 : 2498 : mptcp_close_wake_up(sk);
659 : : }
660 : 140487 : }
661 : :
662 : 0 : static void mptcp_dss_corruption(struct mptcp_sock *msk, struct sock *ssk)
663 : : {
664 [ # # ]: 0 : if (!mptcp_try_fallback(ssk, MPTCP_MIB_DSSCORRUPTIONFALLBACK)) {
665 [ # # ]: 0 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_DSSCORRUPTIONRESET);
666 : 0 : mptcp_subflow_reset(ssk);
667 : : }
668 : 0 : }
669 : :
670 : 180174 : static void __mptcp_add_backlog(struct sock *sk,
671 : : struct mptcp_subflow_context *subflow,
672 : : struct sk_buff *skb)
673 : : {
674 [ - + ]: 180174 : struct mptcp_sock *msk = mptcp_sk(sk);
675 : 180174 : struct sk_buff *tail = NULL;
676 : 180174 : struct sock *ssk = skb->sk;
677 : 180174 : bool fragstolen;
678 : 180174 : int delta;
679 : :
680 [ + + ]: 180174 : if (unlikely(sk->sk_state == TCP_CLOSE)) {
681 : 4 : kfree_skb_reason(skb, SKB_DROP_REASON_SOCKET_CLOSE);
682 : 4 : return;
683 : : }
684 : :
685 : : /* Try to coalesce with the last skb in our backlog */
686 [ + + ]: 180170 : if (!list_empty(&msk->backlog_list))
687 : 49311 : tail = list_last_entry(&msk->backlog_list, struct sk_buff, list);
688 : :
689 [ + - + + ]: 49311 : if (tail && MPTCP_SKB_CB(skb)->map_seq == MPTCP_SKB_CB(tail)->end_seq &&
690 [ + + + + ]: 94870 : ssk == tail->sk &&
691 : 47434 : __mptcp_try_coalesce(sk, tail, skb, &fragstolen, &delta)) {
692 : 28684 : skb->truesize -= delta;
693 [ - + ]: 28684 : kfree_skb_partial(skb, fragstolen);
694 : 28684 : __mptcp_subflow_lend_fwdmem(subflow, delta);
695 : 28684 : goto account;
696 : : }
697 : :
698 : 151486 : list_add_tail(&skb->list, &msk->backlog_list);
699 : 151486 : mptcp_subflow_lend_fwdmem(subflow, skb);
700 : 151486 : delta = skb->truesize;
701 : :
702 : 180170 : account:
703 : 180170 : WRITE_ONCE(msk->backlog_len, msk->backlog_len + delta);
704 : :
705 : : /* Possibly not accept()ed yet, keep track of memory not CG
706 : : * accounted, mptcp_graft_subflows() will handle it.
707 : : */
708 [ + - ]: 180170 : if (!mem_cgroup_from_sk(ssk))
709 : 180170 : msk->backlog_unaccounted += delta;
710 : : }
711 : :
712 : 1121752 : static bool __mptcp_move_skbs_from_subflow(struct mptcp_sock *msk,
713 : : struct sock *ssk, bool own_msk)
714 : : {
715 [ - + ]: 1121752 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
716 : 1121752 : struct sock *sk = (struct sock *)msk;
717 : 1121752 : bool more_data_avail;
718 : 1121752 : struct tcp_sock *tp;
719 : 1121752 : bool ret = false;
720 : :
721 [ - + - - ]: 1121752 : pr_debug("msk=%p ssk=%p\n", msk, ssk);
722 [ - + ]: 1121752 : tp = tcp_sk(ssk);
723 : 1200696 : do {
724 : 1200696 : u32 map_remaining, offset;
725 : 1200696 : u32 seq = tp->copied_seq;
726 : 1200696 : struct sk_buff *skb;
727 : 1200696 : bool fin;
728 : :
729 : : /* try to move as much data as available */
730 : 2401392 : map_remaining = subflow->map_data_len -
731 : 1200696 : mptcp_subflow_get_map_offset(subflow);
732 : :
733 [ + - ]: 1200696 : skb = skb_peek(&ssk->sk_receive_queue);
734 [ + - ]: 1200696 : if (unlikely(!skb))
735 : : break;
736 : :
737 [ + + ]: 1200696 : if (__mptcp_check_fallback(msk)) {
738 : : /* Under fallback skbs have no MPTCP extension and TCP could
739 : : * collapse them between the dummy map creation and the
740 : : * current dequeue. Be sure to adjust the map size.
741 : : */
742 : 13212 : map_remaining = skb->len;
743 : 13212 : subflow->map_data_len = skb->len;
744 : : }
745 : :
746 : 1200696 : offset = seq - TCP_SKB_CB(skb)->seq;
747 : 1200696 : fin = TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN;
748 [ + + ]: 1200696 : if (fin)
749 : 152 : seq++;
750 : :
751 [ + + ]: 1200696 : if (offset < skb->len) {
752 : 1200648 : size_t len = skb->len - offset;
753 : :
754 : 1200648 : mptcp_init_skb(ssk, skb, offset, len);
755 : :
756 [ + + + - ]: 1767722 : if (own_msk && sk_rmem_alloc_get(sk) < sk->sk_rcvbuf) {
757 : 1020474 : mptcp_subflow_lend_fwdmem(subflow, skb);
758 : 1020474 : ret |= __mptcp_move_skb(sk, skb);
759 : : } else {
760 : 180174 : __mptcp_add_backlog(sk, subflow, skb);
761 : : }
762 : 1200648 : seq += len;
763 : :
764 [ - + ]: 1200648 : if (unlikely(map_remaining < len)) {
765 : 0 : DEBUG_NET_WARN_ON_ONCE(1);
766 : 0 : mptcp_dss_corruption(msk, ssk);
767 : : }
768 : : } else {
769 [ - + ]: 48 : if (unlikely(!fin)) {
770 : 0 : DEBUG_NET_WARN_ON_ONCE(1);
771 : 0 : mptcp_dss_corruption(msk, ssk);
772 : : }
773 : :
774 : 48 : sk_eat_skb(ssk, skb);
775 : : }
776 : :
777 : 1200696 : WRITE_ONCE(tp->copied_seq, seq);
778 : 1200696 : more_data_avail = mptcp_subflow_data_available(ssk);
779 : :
780 [ + + ]: 1200696 : } while (more_data_avail);
781 : :
782 [ + + ]: 1121752 : if (ret)
783 : 767554 : msk->last_data_recv = tcp_jiffies32;
784 : 1121752 : return ret;
785 : : }
786 : :
787 : 1080514 : static bool __mptcp_ofo_queue(struct mptcp_sock *msk)
788 : : {
789 : 1080514 : struct sock *sk = (struct sock *)msk;
790 : 1080514 : struct sk_buff *skb, *tail;
791 : 1080514 : bool moved = false;
792 : 1080514 : struct rb_node *p;
793 : 1080514 : u64 end_seq;
794 : :
795 [ + + ]: 1080514 : p = rb_first(&msk->out_of_order_queue);
796 [ - + - - ]: 1080514 : pr_debug("msk=%p empty=%d\n", msk, RB_EMPTY_ROOT(&msk->out_of_order_queue));
797 [ + + ]: 1116379 : while (p) {
798 : 336050 : skb = rb_to_skb(p);
799 [ + + ]: 336050 : if (after64(MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq))
800 : : break;
801 : :
802 : 35865 : p = rb_next(p);
803 : 35865 : rb_erase(&skb->rbnode, &msk->out_of_order_queue);
804 : :
805 [ + + ]: 35865 : if (unlikely(!after64(MPTCP_SKB_CB(skb)->end_seq,
806 : : msk->ack_seq))) {
807 : 80 : mptcp_drop(sk, skb);
808 [ + - ]: 80 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_DUPDATA);
809 : 80 : continue;
810 : : }
811 : :
812 : 35785 : end_seq = MPTCP_SKB_CB(skb)->end_seq;
813 [ + - ]: 35785 : tail = skb_peek_tail(&sk->sk_receive_queue);
814 [ + - + + ]: 71168 : if (!tail || !mptcp_ooo_try_coalesce(msk, tail, skb)) {
815 : 20099 : int delta = msk->ack_seq - MPTCP_SKB_CB(skb)->map_seq;
816 : :
817 : : /* skip overlapping data, if any */
818 [ - + - - ]: 20099 : pr_debug("uncoalesced seq=%llx ack seq=%llx delta=%d\n",
819 : : MPTCP_SKB_CB(skb)->map_seq, msk->ack_seq,
820 : : delta);
821 : 20099 : MPTCP_SKB_CB(skb)->offset += delta;
822 : 20099 : MPTCP_SKB_CB(skb)->map_seq += delta;
823 : 20099 : __skb_queue_tail(&sk->sk_receive_queue, skb);
824 : : }
825 : 35785 : msk->bytes_received += end_seq - msk->ack_seq;
826 : 35785 : WRITE_ONCE(msk->ack_seq, end_seq);
827 : 35785 : moved = true;
828 : : }
829 : 1080514 : return moved;
830 : : }
831 : :
832 : 7412 : static bool __mptcp_subflow_error_report(struct sock *sk, struct sock *ssk)
833 : : {
834 : 7412 : int ssk_state;
835 : 7412 : int err;
836 : :
837 : : /* only propagate errors on fallen-back sockets or
838 : : * on MPC connect
839 : : */
840 [ + + - + : 7412 : if (sk->sk_state != TCP_SYN_SENT && !__mptcp_check_fallback(mptcp_sk(sk)))
+ + ]
841 : : return false;
842 : :
843 [ + + ]: 237 : err = sock_error(ssk);
844 [ + + ]: 148 : if (!err)
845 : 89 : return false;
846 : :
847 : : /* We need to propagate only transition to CLOSE state.
848 : : * Orphaned socket will see such state change via
849 : : * subflow_sched_work_if_closed() and that path will properly
850 : : * destroy the msk as needed.
851 : : */
852 : 36 : ssk_state = inet_sk_state_load(ssk);
853 [ + - + + ]: 36 : if (ssk_state == TCP_CLOSE && !sock_flag(sk, SOCK_DEAD))
854 : 26 : mptcp_set_state(sk, ssk_state);
855 : 36 : WRITE_ONCE(sk->sk_err, -err);
856 : :
857 : : /* This barrier is coupled with smp_rmb() in mptcp_poll() */
858 : 36 : smp_wmb();
859 : 36 : sk_error_report(sk);
860 : 36 : return true;
861 : : }
862 : :
863 : 991 : void __mptcp_error_report(struct sock *sk)
864 : : {
865 : 991 : struct mptcp_subflow_context *subflow;
866 [ - + ]: 991 : struct mptcp_sock *msk = mptcp_sk(sk);
867 : :
868 [ + + ]: 2234 : mptcp_for_each_subflow(msk, subflow)
869 [ + + ]: 1269 : if (__mptcp_subflow_error_report(sk, mptcp_subflow_tcp_sock(subflow)))
870 : : break;
871 : 991 : }
872 : :
873 : : /* In most cases we will be able to lock the mptcp socket. If its already
874 : : * owned, we need to defer to the work queue to avoid ABBA deadlock.
875 : : */
876 : 949650 : static bool move_skbs_to_msk(struct mptcp_sock *msk, struct sock *ssk)
877 : : {
878 : 949650 : struct sock *sk = (struct sock *)msk;
879 : 949650 : bool moved;
880 : :
881 : 949650 : moved = __mptcp_move_skbs_from_subflow(msk, ssk, true);
882 : 949650 : __mptcp_ofo_queue(msk);
883 [ - + ]: 949650 : if (unlikely(ssk->sk_err))
884 : 0 : __mptcp_subflow_error_report(sk, ssk);
885 : :
886 : : /* If the moves have caught up with the DATA_FIN sequence number
887 : : * it's time to ack the DATA_FIN and change socket state, but
888 : : * this is not a good place to change state. Let the workqueue
889 : : * do it.
890 : : */
891 [ + + ]: 949650 : if (mptcp_pending_data_fin(sk, NULL))
892 : 586 : mptcp_schedule_work(sk);
893 : 949650 : return moved;
894 : : }
895 : :
896 : 1121752 : static void mptcp_rcv_rtt_update(struct mptcp_sock *msk,
897 : : struct mptcp_subflow_context *subflow)
898 : : {
899 [ - + ]: 1121752 : const struct tcp_sock *tp = tcp_sk(subflow->tcp_sock);
900 : 1121752 : u32 rtt_us = tp->rcv_rtt_est.rtt_us;
901 : 1121752 : int id;
902 : :
903 : : /* Update once per subflow per rcvwnd to avoid touching the msk
904 : : * too often.
905 : : */
906 [ + + + + ]: 1121752 : if (!rtt_us || tp->rcv_rtt_est.seq == subflow->prev_rtt_seq)
907 : : return;
908 : :
909 : 26797 : subflow->prev_rtt_seq = tp->rcv_rtt_est.seq;
910 : :
911 : : /* Pairs with READ_ONCE() in mptcp_rtt_us_est(). */
912 : 26797 : id = msk->rcv_rtt_est.next_sample;
913 : 26797 : WRITE_ONCE(msk->rcv_rtt_est.samples[id], rtt_us);
914 [ + + ]: 26797 : if (++msk->rcv_rtt_est.next_sample == MPTCP_RTT_SAMPLES)
915 : 4850 : msk->rcv_rtt_est.next_sample = 0;
916 : :
917 : : /* EWMA among the incoming subflows */
918 : 26797 : msk->scaling_ratio = ((msk->scaling_ratio << 3) - msk->scaling_ratio +
919 : 26797 : tp->scaling_ratio) >> 3;
920 : : }
921 : :
922 : 1121752 : void mptcp_data_ready(struct sock *sk, struct sock *ssk)
923 : : {
924 [ - + ]: 1121752 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
925 [ - + ]: 1121752 : struct mptcp_sock *msk = mptcp_sk(sk);
926 : :
927 : : /* The peer can send data while we are shutting down this
928 : : * subflow at subflow destruction time, but we must avoid enqueuing
929 : : * more data to the msk receive queue
930 : : */
931 [ + - ]: 1121752 : if (unlikely(subflow->closing))
932 : : return;
933 : :
934 : 1121752 : mptcp_data_lock(sk);
935 : 1121752 : mptcp_rcv_rtt_update(msk, subflow);
936 [ + + ]: 1121752 : if (!sock_owned_by_user(sk)) {
937 : : /* Wake-up the reader only for in-sequence data */
938 [ + + + - ]: 949650 : if (move_skbs_to_msk(msk, ssk) && mptcp_epollin_ready(sk))
939 : 767554 : sk->sk_data_ready(sk);
940 : : } else {
941 : 172102 : __mptcp_move_skbs_from_subflow(msk, ssk, false);
942 : : }
943 : 1121752 : mptcp_data_unlock(sk);
944 : : }
945 : :
946 : 1200 : static void mptcp_subflow_joined(struct mptcp_sock *msk, struct sock *ssk)
947 : : {
948 : 1200 : mptcp_subflow_ctx(ssk)->map_seq = READ_ONCE(msk->ack_seq);
949 : 1200 : msk->allow_infinite_fallback = false;
950 : 1200 : mptcp_event(MPTCP_EVENT_SUB_ESTABLISHED, msk, ssk, GFP_ATOMIC);
951 : 1200 : }
952 : :
953 : 612 : static bool __mptcp_finish_join(struct mptcp_sock *msk, struct sock *ssk)
954 : : {
955 : 612 : struct sock *sk = (struct sock *)msk;
956 : :
957 [ - + ]: 612 : if (sk->sk_state != TCP_ESTABLISHED)
958 : : return false;
959 : :
960 : 612 : spin_lock_bh(&msk->fallback_lock);
961 [ - + - + ]: 612 : if (!msk->allow_subflows) {
[ - + ]
962 : 0 : spin_unlock_bh(&msk->fallback_lock);
963 : 0 : return false;
964 : : }
965 : 612 : mptcp_subflow_joined(msk, ssk);
966 : 612 : spin_unlock_bh(&msk->fallback_lock);
967 : :
968 : 612 : mptcp_subflow_ctx(ssk)->subflow_id = msk->subflow_id++;
969 : 612 : mptcp_sockopt_sync_locked(msk, ssk);
970 : 612 : mptcp_stop_tout_timer(sk);
971 [ + - ]: 612 : __mptcp_propagate_sndbuf(sk, ssk);
972 : : return true;
973 : : }
974 : :
975 : 23 : static void __mptcp_flush_join_list(struct sock *sk, struct list_head *join_list)
976 : : {
977 : 23 : struct mptcp_subflow_context *tmp, *subflow;
978 [ - + ]: 23 : struct mptcp_sock *msk = mptcp_sk(sk);
979 : :
980 [ + + ]: 41 : list_for_each_entry_safe(subflow, tmp, join_list, node) {
981 : 18 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
982 : 18 : bool slow = lock_sock_fast(ssk);
983 : :
984 : 18 : list_move_tail(&subflow->node, &msk->conn_list);
985 [ - + ]: 18 : if (!__mptcp_finish_join(msk, ssk))
986 : 0 : mptcp_subflow_reset(ssk);
987 : 18 : unlock_sock_fast(ssk, slow);
988 : : }
989 : 23 : }
990 : :
991 : 0 : static bool mptcp_rtx_timer_pending(struct sock *sk)
992 : : {
993 : 475332 : return timer_pending(&sk->mptcp_retransmit_timer);
994 : : }
995 : :
996 : 440873 : static void mptcp_reset_rtx_timer(struct sock *sk)
997 : : {
998 : 440873 : unsigned long tout;
999 : :
1000 : : /* prevent rescheduling on close */
1001 [ + + ]: 440873 : if (unlikely(inet_sk_state_load(sk) == TCP_CLOSE))
1002 : : return;
1003 : :
1004 [ - + ]: 440827 : tout = mptcp_sk(sk)->timer_ival;
1005 : 440827 : sk_reset_timer(sk, &sk->mptcp_retransmit_timer, jiffies + tout);
1006 : : }
1007 : :
1008 : 15854 : bool mptcp_schedule_work(struct sock *sk)
1009 : : {
1010 [ + + ]: 15854 : if (inet_sk_state_load(sk) == TCP_CLOSE)
1011 : : return false;
1012 : :
1013 : : /* Get a reference on this socket, mptcp_worker() will release it.
1014 : : * As mptcp_worker() might complete before us, we can not avoid
1015 : : * a sock_hold()/sock_put() if schedule_work() returns false.
1016 : : */
1017 : 15030 : sock_hold(sk);
1018 : :
1019 [ - + + + ]: 15030 : if (schedule_work(&mptcp_sk(sk)->work))
1020 : : return true;
1021 : :
1022 : 1562 : sock_put(sk);
1023 : 1562 : return false;
1024 : : }
1025 : :
1026 : 722130 : static bool mptcp_skb_can_collapse_to(u64 write_seq,
1027 : : const struct sk_buff *skb,
1028 : : const struct mptcp_ext *mpext)
1029 : : {
1030 [ + + ]: 722130 : if (!tcp_skb_can_collapse_to(skb))
1031 : : return false;
1032 : :
1033 : : /* can collapse only if MPTCP level sequence is in order and this
1034 : : * mapping has not been xmitted yet
1035 : : */
1036 [ + - + + ]: 1340302 : return mpext && mpext->data_seq + mpext->data_len == write_seq &&
1037 [ + + ]: 647806 : !mpext->frozen;
1038 : : }
1039 : :
1040 : : /* we can append data to the given data frag if:
1041 : : * - there is space available in the backing page_frag
1042 : : * - the data frag tail matches the current page_frag free offset
1043 : : * - the data frag end sequence number matches the current write seq
1044 : : */
1045 : 635413 : static bool mptcp_frag_can_collapse_to(const struct mptcp_sock *msk,
1046 : : const struct page_frag *pfrag,
1047 : : const struct mptcp_data_frag *df)
1048 : : {
1049 [ + - ]: 339605 : return df && !df->eor &&
1050 [ + - ]: 339605 : pfrag->page == df->page &&
1051 [ + + ]: 339605 : pfrag->size - pfrag->offset > 0 &&
1052 [ + + + - ]: 803735 : pfrag->offset == (df->offset + df->data_len) &&
1053 [ - + ]: 168322 : df->data_seq + df->data_len == msk->write_seq;
1054 : : }
1055 : :
1056 : 0 : static void dfrag_uncharge(struct sock *sk, int len)
1057 : : {
1058 : 781642 : sk_mem_uncharge(sk, len);
1059 : 781642 : sk_wmem_queued_add(sk, -len);
1060 : 314572 : }
1061 : :
1062 : 467082 : static void dfrag_clear(struct sock *sk, struct mptcp_data_frag *dfrag)
1063 : : {
1064 : 467082 : int len = dfrag->data_len + dfrag->overhead;
1065 : :
1066 : 467082 : list_del(&dfrag->list);
1067 : 467082 : dfrag_uncharge(sk, len);
1068 : 467082 : put_page(dfrag->page);
1069 : 467082 : }
1070 : :
1071 : : /* called under both the msk socket lock and the data lock */
1072 : 452638 : static void __mptcp_clean_una(struct sock *sk)
1073 : : {
1074 [ - + ]: 452638 : struct mptcp_sock *msk = mptcp_sk(sk);
1075 : 452638 : struct mptcp_data_frag *dtmp, *dfrag;
1076 : 452638 : u64 snd_una;
1077 : :
1078 : 452638 : snd_una = msk->snd_una;
1079 [ + + ]: 919514 : list_for_each_entry_safe(dfrag, dtmp, &msk->rtx_queue, list) {
1080 [ + + ]: 852121 : if (after64(dfrag->data_seq + dfrag->data_len, snd_una))
1081 : : break;
1082 : :
1083 [ + + ]: 466876 : if (unlikely(dfrag == msk->first_pending)) {
1084 : : /* in recovery mode can see ack after the current snd head */
1085 [ - + - + ]: 3 : if (WARN_ON_ONCE(!msk->recovery))
[ - + ]
1086 : : break;
1087 : :
1088 : 3 : msk->first_pending = mptcp_send_next(sk);
1089 : : }
1090 : :
1091 : 466876 : dfrag_clear(sk, dfrag);
1092 : : }
1093 : :
1094 : 452638 : dfrag = mptcp_rtx_head(sk);
1095 [ + + + + ]: 452638 : if (dfrag && after64(snd_una, dfrag->data_seq)) {
1096 : 314572 : u64 delta = snd_una - dfrag->data_seq;
1097 : :
1098 : : /* prevent wrap around in recovery mode */
1099 [ + + ]: 314572 : if (unlikely(delta > dfrag->already_sent)) {
1100 [ - + - + ]: 6 : if (WARN_ON_ONCE(!msk->recovery))
[ - + ]
1101 : 0 : goto out;
1102 [ - + - + ]: 6 : if (WARN_ON_ONCE(delta > dfrag->data_len))
1103 : 0 : goto out;
1104 : 6 : dfrag->already_sent += delta - dfrag->already_sent;
1105 : : }
1106 : :
1107 : 314572 : dfrag->data_seq += delta;
1108 : 314572 : dfrag->offset += delta;
1109 : 314572 : dfrag->data_len -= delta;
1110 : 314572 : dfrag->already_sent -= delta;
1111 : :
1112 : 314572 : dfrag_uncharge(sk, delta);
1113 : : }
1114 : :
1115 : : /* all retransmitted data acked, recovery completed */
1116 [ - + + + : 452638 : if (unlikely(msk->recovery) && after64(msk->snd_una, msk->recovery_snd_nxt))
+ + ]
[ + + + + ]
1117 : 48 : msk->recovery = false;
1118 : :
1119 : 267364 : out:
1120 [ + + + + ]: 452638 : if (snd_una == msk->snd_nxt && snd_una == msk->write_seq) {
1121 [ + + + + ]: 64806 : if (mptcp_rtx_timer_pending(sk) && !mptcp_data_fin_enabled(msk))
[ + + ]
1122 : 49730 : mptcp_stop_rtx_timer(sk);
1123 : : } else {
1124 : 387832 : mptcp_reset_rtx_timer(sk);
1125 : : }
1126 : :
1127 [ + + ]: 452638 : if (mptcp_pending_data_fin_ack(sk))
1128 : 2464 : mptcp_schedule_work(sk);
1129 : 452638 : }
1130 : :
1131 : 91675 : static void __mptcp_clean_una_wakeup(struct sock *sk)
1132 : : {
1133 [ + - - + ]: 140893 : lockdep_assert_held_once(&sk->sk_lock.slock);
1134 : :
1135 : 140893 : __mptcp_clean_una(sk);
1136 : 140893 : mptcp_write_space(sk);
1137 : 137606 : }
1138 : :
1139 : 6165 : static void mptcp_clean_una_wakeup(struct sock *sk)
1140 : : {
1141 : 6165 : mptcp_data_lock(sk);
1142 : 6165 : __mptcp_clean_una_wakeup(sk);
1143 : 6165 : mptcp_data_unlock(sk);
1144 : 6165 : }
1145 : :
1146 : 0 : static void mptcp_enter_memory_pressure(struct sock *sk)
1147 : : {
1148 : 0 : struct mptcp_subflow_context *subflow;
1149 [ # # ]: 0 : struct mptcp_sock *msk = mptcp_sk(sk);
1150 : 0 : bool first = true;
1151 : :
1152 [ # # ]: 0 : mptcp_for_each_subflow(msk, subflow) {
1153 [ # # ]: 0 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
1154 : :
1155 [ # # # # ]: 0 : if (first && !ssk->sk_bypass_prot_mem) {
1156 : 0 : tcp_enter_memory_pressure(ssk);
1157 : 0 : first = false;
1158 : : }
1159 : :
1160 : 0 : sk_stream_moderate_sndbuf(ssk);
1161 : : }
1162 : 0 : __mptcp_sync_sndbuf(sk);
1163 : 0 : }
1164 : :
1165 : : /* ensure we get enough memory for the frag hdr, beyond some minimal amount of
1166 : : * data
1167 : : */
1168 : 467091 : static bool mptcp_page_frag_refill(struct sock *sk, struct page_frag *pfrag)
1169 : : {
1170 [ - + ]: 467091 : if (likely(skb_page_frag_refill(32U + sizeof(struct mptcp_data_frag),
1171 : : pfrag, sk->sk_allocation)))
1172 : : return true;
1173 : :
1174 : 0 : mptcp_enter_memory_pressure(sk);
1175 : 0 : return false;
1176 : : }
1177 : :
1178 : : static struct mptcp_data_frag *
1179 : 467091 : mptcp_carve_data_frag(const struct mptcp_sock *msk, struct page_frag *pfrag,
1180 : : int orig_offset)
1181 : : {
1182 : 467091 : int offset = ALIGN(orig_offset, sizeof(long));
1183 : 467091 : struct mptcp_data_frag *dfrag;
1184 : :
1185 : 467091 : dfrag = (struct mptcp_data_frag *)(page_to_virt(pfrag->page) + offset);
1186 : 467091 : dfrag->data_len = 0;
1187 : 467091 : dfrag->data_seq = msk->write_seq;
1188 : 467091 : dfrag->overhead = offset - orig_offset + sizeof(struct mptcp_data_frag);
1189 : 467091 : dfrag->offset = offset + sizeof(struct mptcp_data_frag);
1190 : 467091 : dfrag->already_sent = 0;
1191 : 467091 : dfrag->page = pfrag->page;
1192 : 467091 : dfrag->eor = 0;
1193 : :
1194 : 467091 : return dfrag;
1195 : : }
1196 : :
1197 : : struct mptcp_sendmsg_info {
1198 : : int mss_now;
1199 : : int size_goal;
1200 : : u16 limit;
1201 : : u16 sent;
1202 : : unsigned int flags;
1203 : : bool data_lock_held;
1204 : : };
1205 : :
1206 : 1176206 : static size_t mptcp_check_allowed_size(const struct mptcp_sock *msk,
1207 : : struct sock *ssk, u64 data_seq,
1208 : : size_t avail_size)
1209 : : {
1210 : 1176206 : u64 window_end = mptcp_wnd_end(msk);
1211 : 1176206 : u64 mptcp_snd_wnd;
1212 : :
1213 [ + + ]: 1176206 : if (__mptcp_check_fallback(msk))
1214 : : return avail_size;
1215 : :
1216 : 1102557 : mptcp_snd_wnd = window_end - data_seq;
1217 : 1102557 : avail_size = min(mptcp_snd_wnd, avail_size);
1218 : :
1219 [ - + + + ]: 1102557 : if (unlikely(tcp_sk(ssk)->snd_wnd < mptcp_snd_wnd)) {
1220 [ - + ]: 8189 : tcp_sk(ssk)->snd_wnd = min_t(u64, U32_MAX, mptcp_snd_wnd);
1221 [ + - ]: 8189 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_SNDWNDSHARED);
1222 : : }
1223 : :
1224 : : return avail_size;
1225 : : }
1226 : :
1227 : 573725 : static bool __mptcp_add_ext(struct sk_buff *skb, gfp_t gfp)
1228 : : {
1229 : 573725 : struct skb_ext *mpext = __skb_ext_alloc(gfp);
1230 : :
1231 [ + - ]: 573725 : if (!mpext)
1232 : : return false;
1233 : 573725 : __skb_ext_set(skb, SKB_EXT_MPTCP, mpext);
1234 : 573725 : return true;
1235 : : }
1236 : :
1237 : 573725 : static struct sk_buff *__mptcp_do_alloc_tx_skb(struct sock *sk, gfp_t gfp)
1238 : : {
1239 : 573725 : struct sk_buff *skb;
1240 : :
1241 : 573725 : skb = alloc_skb_fclone(MAX_TCP_HEADER, gfp);
1242 [ + - ]: 573725 : if (likely(skb)) {
1243 [ + - ]: 573725 : if (likely(__mptcp_add_ext(skb, gfp))) {
1244 : 573725 : skb_reserve(skb, MAX_TCP_HEADER);
1245 : 573725 : skb->ip_summed = CHECKSUM_PARTIAL;
1246 : 573725 : INIT_LIST_HEAD(&skb->tcp_tsorted_anchor);
1247 : 573725 : return skb;
1248 : : }
1249 : 0 : __kfree_skb(skb);
1250 : : } else {
1251 : 0 : mptcp_enter_memory_pressure(sk);
1252 : : }
1253 : : return NULL;
1254 : : }
1255 : :
1256 : 573725 : static struct sk_buff *__mptcp_alloc_tx_skb(struct sock *sk, struct sock *ssk, gfp_t gfp)
1257 : : {
1258 : 573725 : struct sk_buff *skb;
1259 : :
1260 : 573725 : skb = __mptcp_do_alloc_tx_skb(sk, gfp);
1261 [ - + ]: 573725 : if (!skb)
1262 : : return NULL;
1263 : :
1264 [ + - ]: 573725 : if (likely(sk_wmem_schedule(ssk, skb->truesize))) {
1265 : 573725 : tcp_skb_entail(ssk, skb);
1266 : 573725 : return skb;
1267 : : }
1268 : 0 : tcp_skb_tsorted_anchor_cleanup(skb);
1269 : 0 : kfree_skb(skb);
1270 : 0 : return NULL;
1271 : : }
1272 : :
1273 : 12 : static struct sk_buff *mptcp_alloc_tx_skb(struct sock *sk, struct sock *ssk, bool data_lock_held)
1274 : : {
1275 : 344097 : gfp_t gfp = data_lock_held ? GFP_ATOMIC : sk->sk_allocation;
1276 : :
1277 : 573725 : return __mptcp_alloc_tx_skb(sk, ssk, gfp);
1278 : : }
1279 : :
1280 : : /* note: this always recompute the csum on the whole skb, even
1281 : : * if we just appended a single frag. More status info needed
1282 : : */
1283 : 160228 : static void mptcp_update_data_checksum(struct sk_buff *skb, int added)
1284 : : {
1285 [ + - ]: 160228 : struct mptcp_ext *mpext = mptcp_get_ext(skb);
1286 : 160228 : __wsum csum = ~csum_unfold(mpext->csum);
1287 : 160228 : int offset = skb->len - added;
1288 : :
1289 [ # # ]: 160228 : mpext->csum = csum_fold(csum_block_add(csum, skb_checksum(skb, offset, added, 0), offset));
1290 : 160228 : }
1291 : :
1292 : 1 : static void mptcp_update_infinite_map(struct mptcp_sock *msk,
1293 : : struct sock *ssk,
1294 : : struct mptcp_ext *mpext)
1295 : : {
1296 [ + - ]: 1 : if (!mpext)
1297 : : return;
1298 : :
1299 : 1 : mpext->infinite_map = 1;
1300 : 1 : mpext->data_len = 0;
1301 : :
1302 [ - + ]: 1 : if (!mptcp_try_fallback(ssk, MPTCP_MIB_INFINITEMAPTX)) {
1303 [ # # ]: 0 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_FALLBACKFAILED);
1304 : 0 : mptcp_subflow_reset(ssk);
1305 : 0 : return;
1306 : : }
1307 : :
1308 : 1 : mptcp_subflow_ctx(ssk)->send_infinite_map = 0;
1309 : : }
1310 : :
1311 : : #define MPTCP_MAX_GSO_SIZE (GSO_LEGACY_MAX_SIZE - (MAX_TCP_HEADER + 1))
1312 : :
1313 : 1176207 : static int mptcp_sendmsg_frag(struct sock *sk, struct sock *ssk,
1314 : : struct mptcp_data_frag *dfrag,
1315 : : struct mptcp_sendmsg_info *info)
1316 : : {
1317 : 1176207 : u64 data_seq = dfrag->data_seq + info->sent;
1318 : 1176207 : int offset = dfrag->offset + info->sent;
1319 [ - + ]: 1176207 : struct mptcp_sock *msk = mptcp_sk(sk);
1320 : 1176207 : bool zero_window_probe = false;
1321 : 1176207 : struct mptcp_ext *mpext = NULL;
1322 : 1176207 : bool can_coalesce = false;
1323 : 1176207 : bool reuse_skb = true;
1324 : 1176207 : struct sk_buff *skb;
1325 : 1176207 : size_t copy;
1326 : 1176207 : int i;
1327 : :
1328 [ - + - - ]: 1176207 : pr_debug("msk=%p ssk=%p sending dfrag at seq=%llu len=%u already sent=%u\n",
1329 : : msk, ssk, dfrag->data_seq, dfrag->data_len, info->sent);
1330 : :
1331 [ + - - + ]: 1176207 : if (WARN_ON_ONCE(info->sent > info->limit ||
1332 : : info->limit > dfrag->data_len))
1333 : 0 : return 0;
1334 : :
1335 [ + + ]: 1176207 : if (unlikely(!__tcp_can_send(ssk)))
1336 : : return -EAGAIN;
1337 : :
1338 : : /* compute send limit */
1339 [ - + ]: 1176206 : if (unlikely(ssk->sk_gso_max_size > MPTCP_MAX_GSO_SIZE))
1340 : 0 : ssk->sk_gso_max_size = MPTCP_MAX_GSO_SIZE;
1341 : 1176206 : info->mss_now = tcp_send_mss(ssk, &info->size_goal, info->flags);
1342 : 1176206 : copy = info->size_goal;
1343 : :
1344 [ + + ]: 1176206 : skb = tcp_write_queue_tail(ssk);
1345 [ + - + + ]: 1020427 : if (skb && copy > skb->len) {
1346 : : /* Limit the write to the size available in the
1347 : : * current skb, if any, so that we create at most a new skb.
1348 : : * Explicitly tells TCP internals to avoid collapsing on later
1349 : : * queue management operation, to avoid breaking the ext <->
1350 : : * SSN association set here
1351 : : */
1352 [ + - ]: 722130 : mpext = mptcp_get_ext(skb);
1353 [ + + ]: 722130 : if (!mptcp_skb_can_collapse_to(data_seq, skb, mpext)) {
1354 : 119390 : TCP_SKB_CB(skb)->eor = 1;
1355 [ - + ]: 119390 : tcp_mark_push(tcp_sk(ssk), skb);
1356 : 119390 : goto alloc_skb;
1357 : : }
1358 : :
1359 [ + + ]: 602740 : i = skb_shinfo(skb)->nr_frags;
1360 [ + + ]: 602740 : can_coalesce = skb_can_coalesce(skb, i, dfrag->page, offset);
1361 [ + + + + ]: 602740 : if (!can_coalesce && i >= READ_ONCE(net_hotdata.sysctl_max_skb_frags)) {
1362 [ - + ]: 259 : tcp_mark_push(tcp_sk(ssk), skb);
1363 : 259 : goto alloc_skb;
1364 : : }
1365 : :
1366 : 602481 : copy -= skb->len;
1367 : : } else {
1368 [ + + ]: 12 : alloc_skb:
1369 [ - + + + ]: 573725 : skb = mptcp_alloc_tx_skb(sk, ssk, info->data_lock_held);
[ + + ]
1370 [ - + ]: 573725 : if (!skb)
1371 : : return -ENOMEM;
1372 : :
1373 [ + - ]: 573725 : i = skb_shinfo(skb)->nr_frags;
1374 : 573725 : reuse_skb = false;
1375 [ + - ]: 573725 : mpext = mptcp_get_ext(skb);
1376 : : }
1377 : :
1378 : : /* Zero window and all data acked? Probe. */
1379 : 1176206 : copy = mptcp_check_allowed_size(msk, ssk, data_seq, copy);
1380 [ + + ]: 1176206 : if (copy == 0) {
1381 : 313669 : u64 snd_una = READ_ONCE(msk->snd_una);
1382 : :
1383 : : /* No need for zero probe if there are any data pending
1384 : : * either at the msk or ssk level; skb is the current write
1385 : : * queue tail and can be empty at this point.
1386 : : */
1387 [ + + + + : 329491 : if (snd_una != msk->snd_nxt || skb->len ||
+ + ]
[ # # # # ]
1388 [ # # ]: 0 : skb != tcp_send_head(ssk)) {
1389 : 310193 : tcp_remove_empty_skb(ssk);
1390 : 310193 : return 0;
1391 : : }
1392 : :
1393 : 3476 : zero_window_probe = true;
1394 : 3476 : data_seq = snd_una - 1;
1395 : 3476 : copy = 1;
1396 : : }
1397 : :
1398 : 866013 : copy = min_t(size_t, copy, info->limit - info->sent);
1399 [ - + ]: 866013 : if (!sk_wmem_schedule(ssk, copy)) {
1400 : 0 : tcp_remove_empty_skb(ssk);
1401 : 0 : return -ENOMEM;
1402 : : }
1403 : :
1404 [ + + ]: 866013 : if (can_coalesce) {
1405 : 68851 : skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy);
1406 : : } else {
1407 : 797162 : get_page(dfrag->page);
1408 [ - + ]: 797174 : skb_fill_page_desc(skb, i, dfrag->page, offset, copy);
1409 : : }
1410 : :
1411 : 866013 : skb->len += copy;
1412 : 866013 : skb->data_len += copy;
1413 : 866013 : skb->truesize += copy;
1414 [ + - ]: 866013 : sk_wmem_queued_add(ssk, copy);
1415 [ + - ]: 866013 : sk_mem_charge(ssk, copy);
1416 [ - + - + ]: 866013 : WRITE_ONCE(tcp_sk(ssk)->write_seq, tcp_sk(ssk)->write_seq + copy);
1417 : 866013 : TCP_SKB_CB(skb)->end_seq += copy;
1418 [ + + ]: 866013 : tcp_skb_pcount_set(skb, 0);
1419 : :
1420 : : /* on skb reuse we just need to update the DSS len */
1421 [ + + ]: 866013 : if (reuse_skb) {
1422 : 363482 : TCP_SKB_CB(skb)->tcp_flags &= ~TCPHDR_PSH;
1423 : 363482 : mpext->data_len += copy;
1424 : 363482 : goto out;
1425 : : }
1426 : :
1427 : 502531 : memset(mpext, 0, sizeof(*mpext));
1428 : 502531 : mpext->data_seq = data_seq;
1429 [ - + ]: 502531 : mpext->subflow_seq = mptcp_subflow_ctx(ssk)->rel_write_seq;
1430 : 502531 : mpext->data_len = copy;
1431 : 502531 : mpext->use_map = 1;
1432 : 502531 : mpext->dsn64 = 1;
1433 : :
1434 [ - + - - ]: 502531 : pr_debug("data_seq=%llu subflow_seq=%u data_len=%u dsn64=%d\n",
1435 : : mpext->data_seq, mpext->subflow_seq, mpext->data_len,
1436 : : mpext->dsn64);
1437 : :
1438 [ + + ]: 502531 : if (zero_window_probe) {
1439 [ + - ]: 3476 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_WINPROBE);
1440 [ + + ]: 3476 : mptcp_subflow_ctx(ssk)->rel_write_seq += copy;
1441 : 3476 : mpext->frozen = 1;
1442 [ - + + + ]: 3476 : if (READ_ONCE(msk->csum_enabled))
[ + + ]
1443 : 2057 : mptcp_update_data_checksum(skb, copy);
1444 : 3476 : tcp_push_pending_frames(ssk);
1445 : 3476 : return 0;
1446 : : }
1447 : 499055 : out:
1448 [ - + + + ]: 862537 : if (READ_ONCE(msk->csum_enabled))
[ + + ]
1449 : 158171 : mptcp_update_data_checksum(skb, copy);
1450 [ + + ]: 862537 : if (mptcp_subflow_ctx(ssk)->send_infinite_map)
1451 : 1 : mptcp_update_infinite_map(msk, ssk, mpext);
1452 : 862537 : trace_mptcp_sendmsg_frag(mpext);
1453 [ + + ]: 862537 : mptcp_subflow_ctx(ssk)->rel_write_seq += copy;
1454 : :
1455 : : /* if this is the last chunk of a dfrag with MSG_EOR set,
1456 : : * mark the skb to prevent coalescing with subsequent data.
1457 : : */
1458 [ + + - + ]: 862537 : if (dfrag->eor && info->sent + copy >= dfrag->data_len)
1459 : 6 : TCP_SKB_CB(skb)->eor = 1;
1460 : :
1461 : : return copy;
1462 : : }
1463 : :
1464 : : #define MPTCP_SEND_BURST_SIZE ((1 << 16) - \
1465 : : sizeof(struct tcphdr) - \
1466 : : MAX_TCP_OPTION_SPACE - \
1467 : : sizeof(struct ipv6hdr) - \
1468 : : sizeof(struct frag_hdr))
1469 : :
1470 : : struct subflow_send_info {
1471 : : struct sock *ssk;
1472 : : u64 linger_time;
1473 : : };
1474 : :
1475 : 252 : void mptcp_subflow_set_active(struct mptcp_subflow_context *subflow)
1476 : : {
1477 [ - + ]: 252 : if (!subflow->stale)
1478 : : return;
1479 : :
1480 : 0 : subflow->stale = 0;
1481 [ # # ]: 0 : MPTCP_INC_STATS(sock_net(mptcp_subflow_tcp_sock(subflow)), MPTCP_MIB_SUBFLOWRECOVER);
1482 : : }
1483 : :
1484 : 1573086 : bool mptcp_subflow_active(struct mptcp_subflow_context *subflow)
1485 : : {
1486 [ + + ]: 1573086 : if (unlikely(subflow->stale)) {
1487 [ - + ]: 107420 : u32 rcv_tstamp = READ_ONCE(tcp_sk(mptcp_subflow_tcp_sock(subflow))->rcv_tstamp);
1488 : :
1489 [ - + ]: 107420 : if (subflow->stale_rcv_tstamp == rcv_tstamp)
1490 : : return false;
1491 : :
1492 : 0 : mptcp_subflow_set_active(subflow);
1493 : : }
1494 : 1465666 : return __mptcp_subflow_active(subflow);
1495 : : }
1496 : :
1497 : : #define SSK_MODE_ACTIVE 0
1498 : : #define SSK_MODE_BACKUP 1
1499 : : #define SSK_MODE_MAX 2
1500 : :
1501 : : /* implement the mptcp packet scheduler;
1502 : : * returns the subflow that will transmit the next DSS
1503 : : * additionally updates the rtx timeout
1504 : : */
1505 : 752401 : struct sock *mptcp_subflow_get_send(struct mptcp_sock *msk)
1506 : : {
1507 : 752401 : struct subflow_send_info send_info[SSK_MODE_MAX];
1508 : 752401 : struct mptcp_subflow_context *subflow;
1509 : 752401 : struct sock *sk = (struct sock *)msk;
1510 : 752401 : u32 pace, burst, wmem;
1511 : 752401 : int i, nr_active = 0;
1512 : 752401 : struct sock *ssk;
1513 : 752401 : u64 linger_time;
1514 : 752401 : long tout = 0;
1515 : :
1516 : : /* pick the subflow with the lower wmem/wspace ratio */
1517 [ + + ]: 2257203 : for (i = 0; i < SSK_MODE_MAX; ++i) {
1518 : 1504802 : send_info[i].ssk = NULL;
1519 : 1504802 : send_info[i].linger_time = -1;
1520 : : }
1521 : :
1522 [ + + ]: 1966488 : mptcp_for_each_subflow(msk, subflow) {
1523 [ + + + + ]: 1214087 : bool backup = subflow->backup || subflow->request_bkup;
1524 : :
1525 : 1214087 : trace_mptcp_subflow_get_send(subflow);
1526 : 1214087 : ssk = mptcp_subflow_tcp_sock(subflow);
1527 [ + + ]: 1214087 : if (!mptcp_subflow_active(subflow))
1528 : 108824 : continue;
1529 : :
1530 [ + + ]: 1105263 : tout = max(tout, mptcp_timeout_from_subflow(subflow));
1531 : 1105263 : nr_active += !backup;
1532 : 1105263 : pace = subflow->avg_pacing_rate;
1533 [ + + ]: 1105263 : if (unlikely(!pace)) {
1534 : : /* init pacing rate from socket */
1535 : 3532 : subflow->avg_pacing_rate = READ_ONCE(ssk->sk_pacing_rate);
1536 : 3532 : pace = subflow->avg_pacing_rate;
1537 [ - + ]: 3532 : if (!pace)
1538 : 0 : continue;
1539 : : }
1540 : :
1541 [ + + ]: 1105263 : linger_time = div_u64((u64)READ_ONCE(ssk->sk_wmem_queued) << 32, pace);
1542 [ + + ]: 1105263 : if (linger_time < send_info[backup].linger_time) {
1543 : 885948 : send_info[backup].ssk = ssk;
1544 : 885948 : send_info[backup].linger_time = linger_time;
1545 : : }
1546 : : }
1547 : 752401 : __mptcp_set_timeout(sk, tout);
1548 : :
1549 : : /* pick the best backup if no other subflow is active */
1550 [ + + ]: 752401 : if (!nr_active)
1551 : 36557 : send_info[SSK_MODE_ACTIVE].ssk = send_info[SSK_MODE_BACKUP].ssk;
1552 : :
1553 : : /* According to the blest algorithm, to avoid HoL blocking for the
1554 : : * faster flow, we need to:
1555 : : * - estimate the faster flow linger time
1556 : : * - use the above to estimate the amount of byte transferred
1557 : : * by the faster flow
1558 : : * - check that the amount of queued data is greater than the above,
1559 : : * otherwise do not use the picked, slower, subflow
1560 : : * We select the subflow with the shorter estimated time to flush
1561 : : * the queued mem, which basically ensure the above. We just need
1562 : : * to check that subflow has a non empty cwin.
1563 : : */
1564 : 752401 : ssk = send_info[SSK_MODE_ACTIVE].ssk;
1565 [ + + + + ]: 1504783 : if (!ssk || !sk_stream_memory_free(ssk))
1566 : 164169 : return NULL;
1567 : :
1568 : 588232 : burst = min(MPTCP_SEND_BURST_SIZE, mptcp_wnd_end(msk) - msk->snd_nxt);
1569 : 588232 : wmem = READ_ONCE(ssk->sk_wmem_queued);
1570 [ + + ]: 588232 : if (!burst)
1571 : : return ssk;
1572 : :
1573 : 366200 : subflow = mptcp_subflow_ctx(ssk);
1574 : 366200 : subflow->avg_pacing_rate = div_u64((u64)subflow->avg_pacing_rate * wmem +
1575 : 366200 : READ_ONCE(ssk->sk_pacing_rate) * burst,
1576 : : burst + wmem);
1577 : 366200 : msk->snd_burst = burst;
1578 : 366200 : return ssk;
1579 : : }
1580 : :
1581 : 428807 : static void mptcp_push_release(struct sock *ssk, struct mptcp_sendmsg_info *info)
1582 : : {
1583 [ - + ]: 428807 : tcp_push(ssk, 0, info->mss_now, tcp_sk(ssk)->nonagle, info->size_goal);
1584 : 428807 : release_sock(ssk);
1585 : 428807 : }
1586 : :
1587 : 862271 : static void mptcp_update_post_push(struct mptcp_sock *msk,
1588 : : struct mptcp_data_frag *dfrag,
1589 : : u32 sent)
1590 : : {
1591 : 862271 : u64 snd_nxt_new = dfrag->data_seq;
1592 : :
1593 : 862271 : dfrag->already_sent += sent;
1594 : :
1595 : 862271 : msk->snd_burst -= sent;
1596 : :
1597 : 862271 : snd_nxt_new += dfrag->already_sent;
1598 : :
1599 : : /* snd_nxt_new can be smaller than snd_nxt in case mptcp
1600 : : * is recovering after a failover. In that event, this re-sends
1601 : : * old segments.
1602 : : *
1603 : : * Thus compute snd_nxt_new candidate based on
1604 : : * the dfrag->data_seq that was sent and the data
1605 : : * that has been handed to the subflow for transmission
1606 : : * and skip update in case it was old dfrag.
1607 : : */
1608 [ + + ]: 862271 : if (likely(after64(snd_nxt_new, msk->snd_nxt))) {
1609 : 858113 : msk->bytes_sent += snd_nxt_new - msk->snd_nxt;
1610 : 858113 : WRITE_ONCE(msk->snd_nxt, snd_nxt_new);
1611 : : }
1612 : 862271 : }
1613 : :
1614 : 4692 : void mptcp_check_and_set_pending(struct sock *sk)
1615 : : {
1616 [ + + ]: 4692 : if (mptcp_send_head(sk)) {
1617 : 290 : mptcp_data_lock(sk);
1618 [ - + ]: 290 : mptcp_sk(sk)->cb_flags |= BIT(MPTCP_PUSH_PENDING);
1619 : 290 : mptcp_data_unlock(sk);
1620 : : }
1621 : 4692 : }
1622 : :
1623 : 652959 : static int __subflow_push_pending(struct sock *sk, struct sock *ssk,
1624 : : struct mptcp_sendmsg_info *info)
1625 : : {
1626 [ - + ]: 652959 : struct mptcp_sock *msk = mptcp_sk(sk);
1627 : 24 : struct mptcp_data_frag *dfrag;
1628 : 24 : int len, copied = 0, err = 0;
1629 : :
1630 [ + + ]: 1010556 : while ((dfrag = mptcp_send_head(sk))) {
1631 : 784575 : info->sent = dfrag->already_sent;
1632 : 784575 : info->limit = dfrag->data_len;
1633 : 784575 : len = dfrag->data_len - dfrag->already_sent;
1634 [ + + ]: 1646846 : while (len > 0) {
1635 : 1175940 : int ret = 0;
1636 : :
1637 : 1175940 : ret = mptcp_sendmsg_frag(sk, ssk, dfrag, info);
1638 [ + + ]: 1175940 : if (ret <= 0) {
1639 [ + + ]: 313669 : err = copied ? : ret;
1640 : 313669 : goto out;
1641 : : }
1642 : :
1643 : 862271 : info->sent += ret;
1644 : 862271 : copied += ret;
1645 : 862271 : len -= ret;
1646 : :
1647 : 862271 : mptcp_update_post_push(msk, dfrag, ret);
1648 : : }
1649 : 470906 : msk->first_pending = mptcp_send_next(sk);
1650 : :
1651 [ + + + + ]: 844815 : if (msk->snd_burst <= 0 ||
[ + - ]
1652 [ - + ]: 357609 : !sk_stream_memory_free(ssk) ||
[ + - - + ]
1653 : 357597 : !mptcp_subflow_active(mptcp_subflow_ctx(ssk))) {
1654 : 113309 : err = copied;
1655 : 113309 : goto out;
1656 : : }
1657 : 357597 : mptcp_set_timeout(sk);
1658 : : }
1659 : : err = copied;
1660 : :
1661 : 652959 : out:
1662 [ + + ]: 652959 : if (err > 0)
1663 : 433515 : msk->last_data_sent = tcp_jiffies32;
1664 : 652959 : return err;
1665 : : }
1666 : :
1667 : 685067 : void __mptcp_push_pending(struct sock *sk, unsigned int flags)
1668 : : {
1669 : 685067 : struct sock *prev_ssk = NULL, *ssk = NULL;
1670 [ - + ]: 685067 : struct mptcp_sock *msk = mptcp_sk(sk);
1671 : 685067 : struct mptcp_sendmsg_info info = {
1672 : : .flags = flags,
1673 : : };
1674 : 685067 : bool copied = false;
1675 : 685067 : int push_count = 1;
1676 : :
1677 [ + + + + ]: 1148573 : while (mptcp_send_head(sk) && (push_count > 0)) {
1678 : 514320 : struct mptcp_subflow_context *subflow;
1679 : 514320 : int ret = 0;
1680 : :
1681 [ + + ]: 514320 : if (mptcp_sched_get_send(msk))
1682 : : break;
1683 : :
1684 : 463506 : push_count = 0;
1685 : :
1686 [ + + ]: 1077652 : mptcp_for_each_subflow(msk, subflow) {
1687 [ - + + + ]: 614146 : if (READ_ONCE(subflow->scheduled)) {
[ + + ]
1688 : 463506 : mptcp_subflow_set_scheduled(subflow, false);
1689 : :
1690 : 463506 : prev_ssk = ssk;
1691 [ + + ]: 463506 : ssk = mptcp_subflow_tcp_sock(subflow);
1692 [ + + ]: 463506 : if (ssk != prev_ssk) {
1693 : : /* First check. If the ssk has changed since
1694 : : * the last round, release prev_ssk
1695 : : */
1696 [ + + ]: 428807 : if (prev_ssk)
1697 : 1945 : mptcp_push_release(prev_ssk, &info);
1698 : :
1699 : : /* Need to lock the new subflow only if different
1700 : : * from the previous one, otherwise we are still
1701 : : * helding the relevant lock
1702 : : */
1703 : 428807 : lock_sock(ssk);
1704 : : }
1705 : :
1706 : 463506 : push_count++;
1707 : :
1708 : 463506 : ret = __subflow_push_pending(sk, ssk, &info);
1709 [ + + ]: 463506 : if (ret <= 0) {
1710 [ + + + - ]: 136120 : if (ret != -EAGAIN ||
[ - + ]
1711 [ - + ]: 1 : (1 << ssk->sk_state) &
1712 : : (TCPF_FIN_WAIT1 | TCPF_FIN_WAIT2 | TCPF_CLOSE))
1713 : 87853 : push_count--;
1714 : 136119 : continue;
1715 : : }
1716 : : copied = true;
1717 : : }
1718 : : }
1719 : : }
1720 : :
1721 : : /* at this point we held the socket lock for the last subflow we used */
1722 [ + + ]: 685067 : if (ssk)
1723 : 426862 : mptcp_push_release(ssk, &info);
1724 : :
1725 : : /* Avoid scheduling the rtx timer if no data has been pushed; the timer
1726 : : * will be updated on positive acks by __mptcp_cleanup_una().
1727 : : */
1728 [ + + ]: 685067 : if (copied) {
1729 [ + + ]: 300709 : if (!mptcp_rtx_timer_pending(sk))
1730 : 51062 : mptcp_reset_rtx_timer(sk);
1731 : 300709 : mptcp_check_send_data_fin(sk);
1732 : : }
1733 : 685067 : }
1734 : :
1735 : 1587045 : static void __mptcp_subflow_push_pending(struct sock *sk, struct sock *ssk, bool first)
1736 : : {
1737 [ - + ]: 1587045 : struct mptcp_sock *msk = mptcp_sk(sk);
1738 : 1587045 : struct mptcp_sendmsg_info info = {
1739 : : .data_lock_held = true,
1740 : : };
1741 : 1587045 : bool keep_pushing = true;
1742 : 1587045 : struct sock *xmit_ssk;
1743 : 1587045 : int copied = 0;
1744 : :
1745 : 1587045 : info.flags = 0;
1746 [ + + + + ]: 1783334 : while (mptcp_send_head(sk) && keep_pushing) {
1747 [ + + ]: 315400 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1748 : 315400 : int ret = 0;
1749 : :
1750 : : /* check for a different subflow usage only after
1751 : : * spooling the first chunk of data
1752 : : */
1753 [ + + ]: 315400 : if (first) {
1754 : 9260 : mptcp_subflow_set_scheduled(subflow, false);
1755 : 9260 : ret = __subflow_push_pending(sk, ssk, &info);
1756 : 9260 : first = false;
1757 [ + + ]: 9260 : if (ret <= 0)
1758 : : break;
1759 : 5488 : copied += ret;
1760 : 5488 : continue;
1761 : : }
1762 : :
1763 [ + + ]: 306140 : if (mptcp_sched_get_send(msk))
1764 : 115339 : goto out;
1765 : :
1766 [ - + + + ]: 190801 : if (READ_ONCE(subflow->scheduled)) {
[ + + ]
1767 : 180193 : mptcp_subflow_set_scheduled(subflow, false);
1768 : 180193 : ret = __subflow_push_pending(sk, ssk, &info);
1769 [ + + ]: 180193 : if (ret <= 0)
1770 : 79553 : keep_pushing = false;
1771 : 180193 : copied += ret;
1772 : : }
1773 : :
1774 [ + + ]: 492846 : mptcp_for_each_subflow(msk, subflow) {
1775 [ - + + + ]: 302045 : if (READ_ONCE(subflow->scheduled)) {
[ + + ]
1776 [ + - ]: 10608 : xmit_ssk = mptcp_subflow_tcp_sock(subflow);
1777 [ + - ]: 10608 : if (xmit_ssk != ssk) {
1778 : 10608 : mptcp_subflow_delegate(subflow,
1779 : : MPTCP_DELEGATE_SEND);
1780 : 10608 : keep_pushing = false;
1781 : : }
1782 : : }
1783 : : }
1784 : : }
1785 : :
1786 : 1471644 : out:
1787 : : /* __mptcp_alloc_tx_skb could have released some wmem and we are
1788 : : * not going to flush it via release_sock()
1789 : : */
1790 [ + + ]: 1587045 : if (copied) {
1791 [ - + ]: 101403 : tcp_push(ssk, 0, info.mss_now, tcp_sk(ssk)->nonagle,
1792 : : info.size_goal);
1793 [ + + ]: 101403 : if (!mptcp_rtx_timer_pending(sk))
1794 : 21 : mptcp_reset_rtx_timer(sk);
1795 : :
1796 [ - + + + ]: 101403 : if (msk->snd_data_fin_enable &&
[ + + ]
1797 [ + + ]: 11924 : msk->snd_nxt + 1 == msk->write_seq)
1798 : 422 : mptcp_schedule_work(sk);
1799 : : }
1800 : 1587045 : }
1801 : :
1802 : : static int mptcp_disconnect(struct sock *sk, int flags);
1803 : :
1804 : 112 : static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
1805 : : size_t len, int *copied_syn)
1806 : : {
1807 : 112 : unsigned int saved_flags = msg->msg_flags;
1808 [ - + ]: 112 : struct mptcp_sock *msk = mptcp_sk(sk);
1809 : 112 : struct sock *ssk;
1810 : 112 : int ret;
1811 : :
1812 : : /* on flags based fastopen the mptcp is supposed to create the
1813 : : * first subflow right now. Otherwise we are in the defer_connect
1814 : : * path, and the first subflow must be already present.
1815 : : * Since the defer_connect flag is cleared after the first succsful
1816 : : * fastopen attempt, no need to check for additional subflow status.
1817 : : */
1818 [ + + ]: 112 : if (msg->msg_flags & MSG_FASTOPEN) {
1819 : 76 : ssk = __mptcp_nmpc_sk(msk);
1820 [ + + ]: 76 : if (IS_ERR(ssk))
1821 : 6 : return PTR_ERR(ssk);
1822 : : }
1823 [ + - ]: 106 : if (!msk->first)
1824 : : return -EINVAL;
1825 : :
1826 : 106 : ssk = msk->first;
1827 : :
1828 : 106 : lock_sock(ssk);
1829 : 106 : msg->msg_flags |= MSG_DONTWAIT;
1830 : 106 : msk->fastopening = 1;
1831 : 106 : ret = tcp_sendmsg_fastopen(ssk, msg, copied_syn, len, NULL);
1832 : 106 : msk->fastopening = 0;
1833 : 106 : msg->msg_flags = saved_flags;
1834 : 106 : release_sock(ssk);
1835 : :
1836 : : /* do the blocking bits of inet_stream_connect outside the ssk socket lock */
1837 [ + - + + ]: 106 : if (ret == -EINPROGRESS && !(msg->msg_flags & MSG_DONTWAIT)) {
1838 : 46 : ret = __inet_stream_connect(sk->sk_socket, msg->msg_name,
1839 : : msg->msg_namelen, msg->msg_flags, 1);
1840 : :
1841 : : /* Keep the same behaviour of plain TCP: zero the copied bytes in
1842 : : * case of any error, except timeout or signal
1843 : : */
1844 [ - + - - ]: 46 : if (ret && ret != -EINPROGRESS && ret != -ERESTARTSYS && ret != -EINTR)
1845 : 0 : *copied_syn = 0;
1846 [ + - ]: 60 : } else if (ret && ret != -EINPROGRESS) {
1847 : : /* The disconnect() op called by tcp_sendmsg_fastopen()/
1848 : : * __inet_stream_connect() can fail, due to looking check,
1849 : : * see mptcp_disconnect().
1850 : : * Attempt it again outside the problematic scope.
1851 : : */
1852 [ # # ]: 0 : if (!mptcp_disconnect(sk, 0)) {
1853 : 0 : sk->sk_disconnects++;
1854 : 0 : sk->sk_socket->state = SS_UNCONNECTED;
1855 : : }
1856 : : }
1857 : 106 : inet_clear_bit(DEFER_CONNECT, sk);
1858 : :
1859 : 106 : return ret;
1860 : : }
1861 : :
1862 : 635413 : static int do_copy_data_nocache(struct sock *sk, int copy,
1863 : : struct iov_iter *from, char *to)
1864 : : {
1865 [ - + ]: 635413 : if (sk->sk_route_caps & NETIF_F_NOCACHE_COPY) {
1866 [ # # ]: 0 : if (!copy_from_iter_full_nocache(to, copy, from))
1867 : 0 : return -EFAULT;
1868 [ - + ]: 635413 : } else if (!copy_from_iter_full(to, copy, from)) {
1869 : 0 : return -EFAULT;
1870 : : }
1871 : : return 0;
1872 : : }
1873 : :
1874 : : /* open-code sk_stream_memory_free() plus sent limit computation to
1875 : : * avoid indirect calls in fast-path.
1876 : : * Called under the msk socket lock, so we can avoid a bunch of ONCE
1877 : : * annotations.
1878 : : */
1879 : 640388 : static u32 mptcp_send_limit(const struct sock *sk)
1880 : : {
1881 [ - + ]: 640388 : const struct mptcp_sock *msk = mptcp_sk(sk);
1882 : 640388 : u32 limit, not_sent;
1883 : :
1884 [ + + ]: 640388 : if (sk->sk_wmem_queued >= READ_ONCE(sk->sk_sndbuf))
1885 : : return 0;
1886 : :
1887 : 635419 : limit = mptcp_notsent_lowat(sk);
1888 [ + + ]: 635419 : if (limit == UINT_MAX)
1889 : : return UINT_MAX;
1890 : :
1891 : 12 : not_sent = msk->write_seq - msk->snd_nxt;
1892 [ + + ]: 12 : if (not_sent >= limit)
1893 : : return 0;
1894 : :
1895 : 6 : return limit - not_sent;
1896 : : }
1897 : :
1898 : 1495889 : static void mptcp_rps_record_subflows(const struct mptcp_sock *msk)
1899 : : {
1900 : 1495889 : struct mptcp_subflow_context *subflow;
1901 : :
1902 [ - + ]: 1495889 : if (!rfs_is_needed())
1903 : : return;
1904 : :
1905 [ # # ]: 0 : mptcp_for_each_subflow(msk, subflow) {
1906 : 0 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
1907 : :
1908 : 0 : sock_rps_record_flow(ssk);
1909 : : }
1910 : : }
1911 : :
1912 : 461459 : static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
1913 : : {
1914 [ - + ]: 461459 : struct mptcp_sock *msk = mptcp_sk(sk);
1915 : 461459 : struct page_frag *pfrag;
1916 : 461459 : size_t copied = 0;
1917 : 461459 : int ret = 0;
1918 : 461459 : long timeo;
1919 : :
1920 : : /* silently ignore everything else */
1921 : 461459 : msg->msg_flags &= MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL |
1922 : : MSG_FASTOPEN | MSG_EOR;
1923 : :
1924 : 461459 : lock_sock(sk);
1925 : :
1926 : 461459 : mptcp_rps_record_subflows(msk);
1927 : :
1928 [ + + + + ]: 461459 : if (unlikely(inet_test_bit(DEFER_CONNECT, sk) ||
1929 : : msg->msg_flags & MSG_FASTOPEN)) {
1930 : 112 : int copied_syn = 0;
1931 : :
1932 : 112 : ret = mptcp_sendmsg_fastopen(sk, msg, len, &copied_syn);
1933 : 112 : copied += copied_syn;
1934 [ + + + + ]: 112 : if (ret == -EINPROGRESS && copied_syn > 0)
1935 : 42 : goto out;
1936 [ + + ]: 70 : else if (ret)
1937 : 24 : goto do_error;
1938 : : }
1939 : :
1940 [ + + ]: 461393 : timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
1941 : :
1942 [ - + + + ]: 461393 : if ((1 << sk->sk_state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) {
[ + + ]
1943 : 45 : ret = sk_stream_wait_connect(sk, &timeo);
1944 [ + - ]: 45 : if (ret)
1945 : 45 : goto do_error;
1946 : : }
1947 : :
1948 : 461348 : ret = -EPIPE;
1949 [ + - - + ]: 461348 : if (unlikely(sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)))
1950 : 0 : goto do_error;
1951 : :
1952 [ + - ]: 461348 : pfrag = sk_page_frag(sk);
1953 : :
1954 [ + + ]: 1101730 : while (msg_data_left(msg)) {
1955 : 640388 : int total_ts, frag_truesize = 0;
1956 : 640388 : struct mptcp_data_frag *dfrag;
1957 : 640388 : bool dfrag_collapsed;
1958 : 640388 : size_t psize, offset;
1959 : 640388 : u32 copy_limit;
1960 : :
1961 : : /* ensure fitting the notsent_lowat() constraint */
1962 : 640388 : copy_limit = mptcp_send_limit(sk);
1963 [ + + ]: 640388 : if (!copy_limit)
1964 : 4975 : goto wait_for_memory;
1965 : :
1966 : : /* reuse tail pfrag, if possible, or carve a new one from the
1967 : : * page allocator
1968 : : */
1969 : 635413 : dfrag = mptcp_pending_tail(sk);
1970 : 635413 : dfrag_collapsed = mptcp_frag_can_collapse_to(msk, pfrag, dfrag);
1971 [ + + ]: 635413 : if (!dfrag_collapsed) {
1972 [ - + ]: 467091 : if (!mptcp_page_frag_refill(sk, pfrag))
1973 : 0 : goto wait_for_memory;
1974 : :
1975 : 467091 : dfrag = mptcp_carve_data_frag(msk, pfrag, pfrag->offset);
1976 : 467091 : frag_truesize = dfrag->overhead;
1977 : : }
1978 : :
1979 : : /* we do not bound vs wspace, to allow a single packet.
1980 : : * memory accounting will prevent execessive memory usage
1981 : : * anyway
1982 : : */
1983 : 635413 : offset = dfrag->offset + dfrag->data_len;
1984 : 635413 : psize = pfrag->size - offset;
1985 : 635413 : psize = min_t(size_t, psize, msg_data_left(msg));
1986 : 635413 : psize = min_t(size_t, psize, copy_limit);
1987 : 635413 : total_ts = psize + frag_truesize;
1988 : :
1989 [ - + ]: 635413 : if (!sk_wmem_schedule(sk, total_ts))
1990 : 0 : goto wait_for_memory;
1991 : :
1992 : 635425 : ret = do_copy_data_nocache(sk, psize, &msg->msg_iter,
1993 : 635413 : page_address(dfrag->page) + offset);
1994 [ - + ]: 635413 : if (ret)
1995 : 0 : goto do_error;
1996 : :
1997 : : /* data successfully copied into the write queue */
1998 [ + + ]: 635413 : sk_forward_alloc_add(sk, -total_ts);
1999 : 635413 : copied += psize;
2000 : 635413 : dfrag->data_len += psize;
2001 : 635413 : frag_truesize += psize;
2002 : 635413 : pfrag->offset += frag_truesize;
2003 : 635413 : WRITE_ONCE(msk->write_seq, msk->write_seq + psize);
2004 : :
2005 : : /* charge data on mptcp pending queue to the msk socket
2006 : : * Note: we charge such data both to sk and ssk
2007 : : */
2008 [ + + ]: 635413 : sk_wmem_queued_add(sk, frag_truesize);
2009 [ + + ]: 635413 : if (!dfrag_collapsed) {
2010 : 467091 : get_page(dfrag->page);
2011 [ + + ]: 467091 : list_add_tail(&dfrag->list, &msk->rtx_queue);
2012 [ + + ]: 467091 : if (!msk->first_pending)
2013 : 295808 : msk->first_pending = dfrag;
2014 : : }
2015 [ - + - - ]: 635413 : pr_debug("msk=%p dfrag at seq=%llu len=%u sent=%u new=%d\n", msk,
2016 : : dfrag->data_seq, dfrag->data_len, dfrag->already_sent,
2017 : : !dfrag_collapsed);
2018 : :
2019 : 635413 : continue;
2020 : :
2021 : 4975 : wait_for_memory:
2022 : 4975 : set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
2023 : 4975 : __mptcp_push_pending(sk, msg->msg_flags);
2024 : 4975 : ret = sk_stream_wait_memory(sk, &timeo);
2025 [ + + ]: 4975 : if (ret)
2026 : 6 : goto do_error;
2027 : : }
2028 : :
2029 [ + + ]: 461342 : if (copied) {
2030 : : /* mark the last dfrag with EOR if MSG_EOR was set */
2031 [ + + ]: 461164 : if (msg->msg_flags & MSG_EOR) {
2032 : 6 : struct mptcp_data_frag *dfrag = mptcp_pending_tail(sk);
2033 : :
2034 [ + - ]: 6 : if (dfrag)
2035 : 6 : dfrag->eor = 1;
2036 : : }
2037 : 461164 : __mptcp_push_pending(sk, msg->msg_flags);
2038 : : }
2039 : :
2040 : 178 : out:
2041 : 461459 : release_sock(sk);
2042 : 461459 : return copied;
2043 : :
2044 : 75 : do_error:
2045 [ + + ]: 75 : if (copied)
2046 : 6 : goto out;
2047 : :
2048 : 69 : copied = sk_stream_error(sk, msg->msg_flags, ret);
2049 : 69 : goto out;
2050 : : }
2051 : :
2052 : : static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied);
2053 : :
2054 : 773843 : static void mptcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb)
2055 : : {
2056 : : /* avoid the indirect call, we know the destructor is sock_rfree */
2057 : 773843 : skb->destructor = NULL;
2058 : 773843 : skb->sk = NULL;
2059 : 773843 : atomic_sub(skb->truesize, &sk->sk_rmem_alloc);
2060 : 773843 : sk_mem_uncharge(sk, skb->truesize);
2061 : 773843 : __skb_unlink(skb, &sk->sk_receive_queue);
2062 : 773843 : skb_attempt_defer_free(skb);
2063 : 773843 : }
2064 : :
2065 : 996909 : static int __mptcp_recvmsg_mskq(struct sock *sk, struct msghdr *msg,
2066 : : size_t len, int flags, int copied_total,
2067 : : struct scm_timestamping_internal *tss,
2068 : : int *cmsg_flags, struct sk_buff **last)
2069 : : {
2070 [ - + ]: 996909 : struct mptcp_sock *msk = mptcp_sk(sk);
2071 : 996909 : struct sk_buff *skb, *tmp;
2072 : 996909 : int total_data_len = 0;
2073 : 996909 : int copied = 0;
2074 : :
2075 [ + + ]: 1575970 : skb_queue_walk_safe(&sk->sk_receive_queue, skb, tmp) {
2076 : 1004814 : u32 delta, offset = MPTCP_SKB_CB(skb)->offset;
2077 : 1004814 : u32 data_len = skb->len - offset;
2078 : 1004814 : u32 count;
2079 : 1004814 : int err;
2080 : :
2081 [ + + ]: 1004814 : if (flags & MSG_PEEK) {
2082 : : /* skip already peeked skbs */
2083 [ + + ]: 43874 : if (total_data_len + data_len <= copied_total) {
2084 : 11 : total_data_len += data_len;
2085 : 11 : *last = skb;
2086 : 11 : continue;
2087 : : }
2088 : :
2089 : : /* skip the already peeked data in the current skb */
2090 : 43863 : delta = copied_total - total_data_len;
2091 : 43863 : offset += delta;
2092 : 43863 : data_len -= delta;
2093 : : }
2094 : :
2095 : 1004803 : count = min_t(size_t, len - copied, data_len);
2096 [ + - ]: 1004803 : if (!(flags & MSG_TRUNC)) {
2097 : 1004803 : err = skb_copy_datagram_msg(skb, offset, msg, count);
2098 [ - + ]: 1004803 : if (unlikely(err < 0)) {
2099 [ # # ]: 0 : if (!copied)
2100 : : return err;
2101 : : break;
2102 : : }
2103 : : }
2104 : :
2105 [ + + ]: 1004803 : if (MPTCP_SKB_CB(skb)->has_rxtstamp) {
2106 : 720 : tcp_update_recv_tstamps(skb, tss);
2107 : 720 : *cmsg_flags |= MPTCP_CMSG_TS;
2108 : : }
2109 : :
2110 : 1004803 : copied += count;
2111 : :
2112 [ + + ]: 1004803 : if (!(flags & MSG_PEEK)) {
2113 : 960940 : msk->bytes_consumed += count;
2114 [ + + ]: 960940 : if (count < data_len) {
2115 : 344625 : MPTCP_SKB_CB(skb)->offset += count;
2116 : 344625 : MPTCP_SKB_CB(skb)->map_seq += count;
2117 : 344625 : break;
2118 : : }
2119 : :
2120 : 616315 : mptcp_eat_recv_skb(sk, skb);
2121 : : } else {
2122 : 43863 : *last = skb;
2123 : : }
2124 : :
2125 [ + + ]: 660178 : if (copied >= len)
2126 : : break;
2127 : : }
2128 : :
2129 : 996909 : mptcp_rcv_space_adjust(msk, copied);
2130 : 996909 : return copied;
2131 : : }
2132 : :
2133 : 2740 : static void mptcp_rcv_space_init(struct mptcp_sock *msk, const struct sock *ssk)
2134 : : {
2135 [ - + ]: 2740 : const struct tcp_sock *tp = tcp_sk(ssk);
2136 : :
2137 : 2740 : msk->rcvspace_init = 1;
2138 : 2740 : msk->rcvq_space.copied = 0;
2139 : :
2140 : : /* initial rcv_space offering made to peer */
2141 : 2740 : msk->rcvq_space.space = min_t(u32, tp->rcv_wnd,
2142 : : TCP_INIT_CWND * tp->advmss);
2143 [ + + ]: 2740 : if (msk->rcvq_space.space == 0)
2144 : 2 : msk->rcvq_space.space = TCP_INIT_CWND * TCP_MSS_DEFAULT;
2145 : 2740 : }
2146 : :
2147 : : /* receive buffer autotuning. See tcp_rcv_space_adjust for more information.
2148 : : *
2149 : : * Only difference: Use lowest rtt estimate of the subflows in use, see
2150 : : * mptcp_rcv_rtt_update() and mptcp_rtt_us_est().
2151 : : */
2152 : 1393583 : static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied)
2153 : : {
2154 : 1393583 : struct mptcp_subflow_context *subflow;
2155 : 1393583 : struct sock *sk = (struct sock *)msk;
2156 : 1393583 : u32 time, rtt_us;
2157 : 1393583 : u64 mstamp;
2158 : :
2159 : 1393583 : msk_owned_by_me(msk);
2160 : :
2161 [ + + ]: 1393583 : if (copied <= 0)
2162 : : return;
2163 : :
2164 [ + + ]: 1055505 : if (!msk->rcvspace_init)
2165 : 1130 : mptcp_rcv_space_init(msk, msk->first);
2166 : :
2167 : 1055505 : msk->rcvq_space.copied += copied;
2168 : :
2169 : 1055505 : mstamp = mptcp_stamp();
2170 : 1055505 : time = tcp_stamp_us_delta(mstamp, READ_ONCE(msk->rcvq_space.time));
2171 : :
2172 : 1055505 : rtt_us = mptcp_rtt_us_est(msk);
2173 [ + + + + ]: 1055505 : if (rtt_us == U32_MAX || time < (rtt_us >> 3))
2174 : : return;
2175 : :
2176 : 112409 : copied = msk->rcvq_space.copied;
2177 : 112409 : copied -= mptcp_inq_hint(sk);
2178 [ + + ]: 112409 : if (copied <= msk->rcvq_space.space)
2179 : 107408 : goto new_measure;
2180 : :
2181 : 5001 : trace_mptcp_rcvbuf_grow(sk, time);
2182 [ + + ]: 5001 : if (mptcp_rcvbuf_grow(sk, copied)) {
2183 : : /* Make subflows follow along. If we do not do this, we
2184 : : * get drops at subflow level if skbs can't be moved to
2185 : : * the mptcp rx queue fast enough (announced rcv_win can
2186 : : * exceed ssk->sk_rcvbuf).
2187 : : */
2188 [ + + ]: 5710 : mptcp_for_each_subflow(msk, subflow) {
2189 : 2976 : struct sock *ssk;
2190 : 2976 : bool slow;
2191 : :
2192 : 2976 : ssk = mptcp_subflow_tcp_sock(subflow);
2193 : 2976 : slow = lock_sock_fast(ssk);
2194 : : /* subflows can be added before tcp_init_transfer() */
2195 [ - + + - ]: 2976 : if (tcp_sk(ssk)->rcvq_space.space)
2196 : 2976 : tcp_rcvbuf_grow(ssk, copied);
2197 : 2976 : unlock_sock_fast(ssk, slow);
2198 : : }
2199 : : }
2200 : :
2201 : 5001 : new_measure:
2202 : 112409 : msk->rcvq_space.copied = 0;
2203 : 112409 : msk->rcvq_space.time = mstamp;
2204 : : }
2205 : :
2206 : 130864 : static bool __mptcp_move_skbs(struct sock *sk, struct list_head *skbs, u32 *delta)
2207 : : {
2208 : 130864 : struct sk_buff *skb = list_first_entry(skbs, struct sk_buff, list);
2209 [ - + ]: 130864 : struct mptcp_sock *msk = mptcp_sk(sk);
2210 : 130864 : bool moved = false;
2211 : :
2212 : 130864 : *delta = 0;
2213 : 172118 : while (1) {
2214 : : /* If the msk recvbuf is full stop, don't drop */
2215 [ + + ]: 151491 : if (sk_rmem_alloc_get(sk) > sk->sk_rcvbuf)
2216 : : break;
2217 : :
2218 : 151486 : prefetch(skb->next);
2219 : 151486 : list_del(&skb->list);
2220 : 151486 : *delta += skb->truesize;
2221 : :
2222 : 151486 : moved |= __mptcp_move_skb(sk, skb);
2223 [ + + ]: 151486 : if (list_empty(skbs))
2224 : : break;
2225 : :
2226 : 20627 : skb = list_first_entry(skbs, struct sk_buff, list);
2227 : : }
2228 : :
2229 : 130864 : __mptcp_ofo_queue(msk);
2230 [ + + ]: 130864 : if (moved)
2231 : 128075 : mptcp_check_data_fin((struct sock *)msk);
2232 : 130864 : return moved;
2233 : : }
2234 : :
2235 : 2213230 : static bool mptcp_can_spool_backlog(struct sock *sk, struct list_head *skbs)
2236 : : {
2237 [ - + ]: 2213230 : struct mptcp_sock *msk = mptcp_sk(sk);
2238 : :
2239 : : /* After CG initialization, subflows should never add skb before
2240 : : * gaining the CG themself.
2241 : : */
2242 [ + + + + : 2213230 : DEBUG_NET_WARN_ON_ONCE(msk->backlog_unaccounted && sk->sk_socket &&
- + ]
2243 : : mem_cgroup_from_sk(sk));
2244 : :
2245 : : /* Don't spool the backlog if the rcvbuf is full. */
2246 [ + + ]: 2213230 : if (list_empty(&msk->backlog_list) ||
2247 [ + + ]: 130881 : sk_rmem_alloc_get(sk) > sk->sk_rcvbuf)
2248 : 1278280 : return false;
2249 : :
2250 [ + - ]: 130864 : INIT_LIST_HEAD(skbs);
2251 [ + - ]: 130864 : list_splice_init(&msk->backlog_list, skbs);
2252 : : return true;
2253 : : }
2254 : :
2255 : 130864 : static void mptcp_backlog_spooled(struct sock *sk, u32 moved,
2256 : : struct list_head *skbs)
2257 : : {
2258 [ - + ]: 130864 : struct mptcp_sock *msk = mptcp_sk(sk);
2259 : :
2260 : 130864 : WRITE_ONCE(msk->backlog_len, msk->backlog_len - moved);
2261 [ + + ]: 130864 : list_splice(skbs, &msk->backlog_list);
2262 : 130864 : }
2263 : :
2264 : 22539 : static bool mptcp_move_skbs(struct sock *sk)
2265 : : {
2266 : 22539 : struct list_head skbs;
2267 : 22539 : bool enqueued = false;
2268 : 22539 : u32 moved;
2269 : :
2270 : 22539 : mptcp_data_lock(sk);
2271 [ + + ]: 68503 : while (mptcp_can_spool_backlog(sk, &skbs)) {
2272 : 23425 : mptcp_data_unlock(sk);
2273 : 23425 : enqueued |= __mptcp_move_skbs(sk, &skbs, &moved);
2274 : :
2275 : 23425 : mptcp_data_lock(sk);
2276 : 23425 : mptcp_backlog_spooled(sk, moved, &skbs);
2277 : : }
2278 : 22539 : mptcp_data_unlock(sk);
2279 : :
2280 [ + + + - ]: 22539 : if (enqueued && mptcp_epollin_ready(sk))
2281 : 22106 : sk->sk_data_ready(sk);
2282 : :
2283 : 22539 : return enqueued;
2284 : : }
2285 : :
2286 : 112839 : static unsigned int mptcp_inq_hint(const struct sock *sk)
2287 : : {
2288 [ - + ]: 112839 : const struct mptcp_sock *msk = mptcp_sk(sk);
2289 : 112839 : const struct sk_buff *skb;
2290 : :
2291 [ + + ]: 112839 : skb = skb_peek(&sk->sk_receive_queue);
2292 [ + - ]: 60347 : if (skb) {
2293 : 60347 : u64 hint_val = READ_ONCE(msk->ack_seq) - MPTCP_SKB_CB(skb)->map_seq;
2294 : :
2295 [ + - ]: 60347 : if (hint_val >= INT_MAX)
2296 : : return INT_MAX;
2297 : :
2298 : 60347 : return (unsigned int)hint_val;
2299 : : }
2300 : :
2301 [ + + + + ]: 52492 : if (sk->sk_state == TCP_CLOSE || (sk->sk_shutdown & RCV_SHUTDOWN))
2302 : 244 : return 1;
2303 : :
2304 : : return 0;
2305 : : }
2306 : :
2307 : 887557 : static int mptcp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
2308 : : int flags)
2309 : : {
2310 [ - + ]: 887557 : struct mptcp_sock *msk = mptcp_sk(sk);
2311 : 887557 : struct scm_timestamping_internal tss;
2312 : 887557 : int copied = 0, cmsg_flags = 0;
2313 : 887557 : int target;
2314 : 887557 : long timeo;
2315 : :
2316 : : /* MSG_ERRQUEUE is really a no-op till we support IP_RECVERR */
2317 [ - + ]: 887557 : if (unlikely(flags & MSG_ERRQUEUE))
2318 : 0 : return inet_recv_error(sk, msg, len);
2319 : :
2320 : 887557 : lock_sock(sk);
2321 [ - + ]: 887557 : if (unlikely(sk->sk_state == TCP_LISTEN)) {
2322 : 0 : copied = -ENOTCONN;
2323 : 0 : goto out_err;
2324 : : }
2325 : :
2326 : 887557 : mptcp_rps_record_subflows(msk);
2327 : :
2328 [ + + ]: 887557 : timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
2329 : :
2330 : 887557 : len = min_t(size_t, len, INT_MAX);
2331 [ + + ]: 887557 : target = sock_rcvlowat(sk, flags & MSG_WAITALL, len);
2332 : :
2333 [ + + ]: 887557 : if (unlikely(msk->recvmsg_inq))
2334 : 430 : cmsg_flags = MPTCP_CMSG_INQ;
2335 : :
2336 [ + + ]: 1003651 : while (copied < len) {
2337 : 996909 : struct sk_buff *last = NULL;
2338 : 996909 : int err, bytes_read;
2339 : :
2340 : 996909 : bytes_read = __mptcp_recvmsg_mskq(sk, msg, len - copied, flags,
2341 : : copied, &tss, &cmsg_flags,
2342 : : &last);
2343 [ - + ]: 996909 : if (unlikely(bytes_read < 0)) {
2344 [ # # ]: 0 : if (!copied)
2345 : 0 : copied = bytes_read;
2346 : 0 : goto out_err;
2347 : : }
2348 : :
2349 : 996909 : copied += bytes_read;
2350 : :
2351 [ + + + + ]: 996909 : if (!list_empty(&msk->backlog_list) && mptcp_move_skbs(sk))
2352 : 21226 : continue;
2353 : :
2354 : : /* only the MPTCP socket status is relevant here. The exit
2355 : : * conditions mirror closely tcp_recvmsg()
2356 : : */
2357 [ + + ]: 975683 : if (copied >= target)
2358 : : break;
2359 : :
2360 [ + + ]: 96858 : if (copied) {
2361 [ + - ]: 6 : if (tcp_recv_should_stop(sk) ||
2362 [ + - ]: 6 : !timeo)
2363 : : break;
2364 : : } else {
2365 [ + + ]: 96852 : if (sk->sk_err) {
2366 : 1 : copied = sock_error(sk);
2367 : 1 : break;
2368 : : }
2369 : :
2370 [ + + ]: 96851 : if (sk->sk_shutdown & RCV_SHUTDOWN)
2371 : : break;
2372 : :
2373 [ + + ]: 94880 : if (sk->sk_state == TCP_CLOSE) {
2374 : : copied = -ENOTCONN;
2375 : : break;
2376 : : }
2377 : :
2378 [ + - ]: 94862 : if (!timeo) {
2379 : : copied = -EAGAIN;
2380 : : break;
2381 : : }
2382 : :
2383 [ - + ]: 94862 : if (signal_pending(current)) {
2384 [ - - ]: 6 : copied = sock_intr_errno(timeo);
2385 : : break;
2386 : : }
2387 : : }
2388 : :
2389 [ - + - - ]: 94868 : pr_debug("block timeout %ld\n", timeo);
2390 : 94868 : mptcp_cleanup_rbuf(msk, copied);
2391 : 94868 : err = sk_wait_data(sk, &timeo, last);
2392 [ - + ]: 94868 : if (err < 0) {
2393 : 0 : err = copied ? : err;
2394 : 0 : goto out_err;
2395 : : }
2396 : : }
2397 : :
2398 : 887557 : mptcp_cleanup_rbuf(msk, copied);
2399 : :
2400 : 887557 : out_err:
2401 [ + + + - ]: 887557 : if (cmsg_flags && copied >= 0) {
2402 [ + + ]: 686 : if (cmsg_flags & MPTCP_CMSG_TS)
2403 : 678 : tcp_recv_timestamp(msg, sk, &tss);
2404 : :
2405 [ + + ]: 686 : if (cmsg_flags & MPTCP_CMSG_INQ) {
2406 : 430 : unsigned int inq = mptcp_inq_hint(sk);
2407 : :
2408 : 430 : put_cmsg(msg, SOL_TCP, TCP_CM_INQ, sizeof(inq), &inq);
2409 : : }
2410 : : }
2411 : :
2412 [ - + - - ]: 887557 : pr_debug("msk=%p rx queue empty=%d copied=%d\n",
2413 : : msk, skb_queue_empty(&sk->sk_receive_queue), copied);
2414 : :
2415 : 887557 : release_sock(sk);
2416 : 887557 : return copied;
2417 : : }
2418 : :
2419 : 6380 : static void mptcp_retransmit_timer(struct timer_list *t)
2420 : : {
2421 : 6380 : struct sock *sk = timer_container_of(sk, t, mptcp_retransmit_timer);
2422 [ - + ]: 6380 : struct mptcp_sock *msk = mptcp_sk(sk);
2423 : :
2424 : 6380 : bh_lock_sock(sk);
2425 [ + + ]: 6380 : if (!sock_owned_by_user(sk)) {
2426 : : /* we need a process context to retransmit */
2427 [ + + ]: 8057 : if (!test_and_set_bit(MPTCP_WORK_RTX, &msk->flags))
2428 : 5147 : mptcp_schedule_work(sk);
2429 : : } else {
2430 : : /* delegate our work to tcp_release_cb() */
2431 [ - + - - : 1227 : __set_bit(MPTCP_RETRANSMIT, &msk->cb_flags);
- - ]
2432 : : }
2433 : 6380 : bh_unlock_sock(sk);
2434 : 6380 : sock_put(sk);
2435 : 6380 : }
2436 : :
2437 : 115 : static void mptcp_tout_timer(struct timer_list *t)
2438 : : {
2439 : 115 : struct inet_connection_sock *icsk =
2440 : 115 : timer_container_of(icsk, t, mptcp_tout_timer);
2441 : 115 : struct sock *sk = &icsk->icsk_inet.sk;
2442 : :
2443 : 115 : mptcp_schedule_work(sk);
2444 : 115 : sock_put(sk);
2445 : 115 : }
2446 : :
2447 : : /* Find an idle subflow. Return NULL if there is unacked data at tcp
2448 : : * level.
2449 : : *
2450 : : * A backup subflow is returned only if that is the only kind available.
2451 : : */
2452 : 4804 : struct sock *mptcp_subflow_get_retrans(struct mptcp_sock *msk)
2453 : : {
2454 : 4804 : struct sock *backup = NULL, *pick = NULL;
2455 : 4804 : struct mptcp_subflow_context *subflow;
2456 : 4804 : int min_stale_count = INT_MAX;
2457 : :
2458 [ + + ]: 12160 : mptcp_for_each_subflow(msk, subflow) {
2459 : 7356 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
2460 : :
2461 [ + + ]: 7356 : if (!__mptcp_subflow_active(subflow))
2462 : 1734 : continue;
2463 : :
2464 : : /* still data outstanding at TCP level? skip this */
2465 [ + + ]: 5622 : if (!tcp_rtx_and_write_queues_empty(ssk)) {
2466 : 2607 : mptcp_pm_subflow_chk_stale(msk, ssk);
2467 : 2607 : min_stale_count = min_t(int, min_stale_count, subflow->stale_count);
2468 : 2607 : continue;
2469 : : }
2470 : :
2471 [ + + + + ]: 3015 : if (subflow->backup || subflow->request_bkup) {
2472 [ + + ]: 81 : if (!backup)
2473 : 71 : backup = ssk;
2474 : 81 : continue;
2475 : : }
2476 : :
2477 [ + + ]: 2934 : if (!pick)
2478 : 2169 : pick = ssk;
2479 : : }
2480 : :
2481 [ + + ]: 4804 : if (pick)
2482 : : return pick;
2483 : :
2484 : : /* use backup only if there are no progresses anywhere */
2485 [ + + ]: 2635 : return min_stale_count > 1 ? backup : NULL;
2486 : : }
2487 : :
2488 : 2150 : bool __mptcp_retransmit_pending_data(struct sock *sk)
2489 : : {
2490 : 2150 : struct mptcp_data_frag *cur, *rtx_head;
2491 [ - + ]: 2150 : struct mptcp_sock *msk = mptcp_sk(sk);
2492 : :
2493 [ + + ]: 2150 : if (__mptcp_check_fallback(msk))
2494 : : return false;
2495 : :
2496 : : /* the closing socket has some data untransmitted and/or unacked:
2497 : : * some data in the mptcp rtx queue has not really xmitted yet.
2498 : : * keep it simple and re-inject the whole mptcp level rtx queue
2499 : : */
2500 : 2065 : mptcp_data_lock(sk);
2501 : 2065 : __mptcp_clean_una_wakeup(sk);
2502 : 2065 : rtx_head = mptcp_rtx_head(sk);
2503 [ + + ]: 2065 : if (!rtx_head) {
2504 : 1992 : mptcp_data_unlock(sk);
2505 : 1992 : return false;
2506 : : }
2507 : :
2508 : 73 : msk->recovery_snd_nxt = msk->snd_nxt;
2509 : 73 : msk->recovery = true;
2510 : 73 : mptcp_data_unlock(sk);
2511 : :
2512 : 73 : msk->first_pending = rtx_head;
2513 : 73 : msk->snd_burst = 0;
2514 : :
2515 : : /* be sure to clear the "sent status" on all re-injected fragments */
2516 [ + + ]: 3939 : list_for_each_entry(cur, &msk->rtx_queue, list) {
2517 [ + + ]: 3883 : if (!cur->already_sent)
2518 : : break;
2519 : 3866 : cur->already_sent = 0;
2520 : : }
2521 : :
2522 : : return true;
2523 : : }
2524 : :
2525 : : /* flags for __mptcp_close_ssk() */
2526 : : #define MPTCP_CF_PUSH BIT(1)
2527 : :
2528 : : /* be sure to send a reset only if the caller asked for it, also
2529 : : * clean completely the subflow status when the subflow reaches
2530 : : * TCP_CLOSE state
2531 : : */
2532 : 1612 : static void __mptcp_subflow_disconnect(struct sock *ssk,
2533 : : struct mptcp_subflow_context *subflow,
2534 : : bool fastclosing)
2535 : : {
2536 [ - + + + : 1612 : if (((1 << ssk->sk_state) & (TCPF_CLOSE | TCPF_LISTEN)) ||
+ + ]
[ + + - + ]
2537 : : fastclosing) {
2538 : : /* The MPTCP code never wait on the subflow sockets, TCP-level
2539 : : * disconnect should never fail
2540 : : */
2541 [ - + ]: 1588 : WARN_ON_ONCE(tcp_disconnect(ssk, 0));
2542 : 1588 : mptcp_subflow_ctx_reset(subflow);
2543 : : } else {
2544 : 24 : tcp_shutdown(ssk, SEND_SHUTDOWN);
2545 : : }
2546 : 1612 : }
2547 : :
2548 : 2131 : static void mptcp_cleanup_ssk_backlog(struct sock *sk, struct sock *ssk)
2549 : : {
2550 [ - + ]: 2131 : struct mptcp_sock *msk = mptcp_sk(sk);
2551 : 2131 : struct sk_buff *skb;
2552 : :
2553 : 2131 : mptcp_data_lock(sk);
2554 [ + + ]: 2136 : list_for_each_entry(skb, &msk->backlog_list, list) {
2555 [ + - ]: 5 : if (skb->sk != ssk)
2556 : 5 : continue;
2557 : :
2558 : 0 : atomic_sub(skb->truesize, &skb->sk->sk_rmem_alloc);
2559 : 0 : skb->sk = NULL;
2560 : : }
2561 : 2131 : mptcp_data_unlock(sk);
2562 : 2131 : }
2563 : :
2564 : : /* subflow sockets can be either outgoing (connect) or incoming
2565 : : * (accept).
2566 : : *
2567 : : * Outgoing subflows use in-kernel sockets.
2568 : : * Incoming subflows do not have their own 'struct socket' allocated,
2569 : : * so we need to use tcp_close() after detaching them from the mptcp
2570 : : * parent socket.
2571 : : */
2572 : 7755 : static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
2573 : : struct mptcp_subflow_context *subflow,
2574 : : unsigned int flags)
2575 : : {
2576 [ - + ]: 7755 : struct mptcp_sock *msk = mptcp_sk(sk);
2577 : 7755 : bool dispose_it, need_push = false;
2578 : 7755 : int fwd_remaining;
2579 : :
2580 : : /* Do not pass RX data to the msk, even if the subflow socket is not
2581 : : * going to be freed (i.e. even for the first subflow on graceful
2582 : : * subflow close.
2583 : : */
2584 : 7755 : lock_sock_nested(ssk, SINGLE_DEPTH_NESTING);
2585 : 7755 : subflow->closing = 1;
2586 : :
2587 [ + + ]: 7755 : if (flags & MPTCP_CF_PUSH)
2588 : 2131 : mptcp_cleanup_ssk_backlog(sk, ssk);
2589 : :
2590 : : /* Borrow the fwd allocated page left-over; fwd memory for the subflow
2591 : : * could be negative at this point, but will be reach zero soon - when
2592 : : * the data allocated using such fragment will be freed.
2593 : : */
2594 [ + + ]: 7755 : if (subflow->lent_mem_frag) {
2595 : 2851 : fwd_remaining = PAGE_SIZE - subflow->lent_mem_frag;
2596 : 2851 : sk_forward_alloc_add(sk, fwd_remaining);
2597 : 2851 : sk_forward_alloc_add(ssk, -fwd_remaining);
2598 : 2851 : subflow->lent_mem_frag = 0;
2599 : : }
2600 : :
2601 : : /* If the first subflow moved to a close state before accept, e.g. due
2602 : : * to an incoming reset or listener shutdown, the subflow socket is
2603 : : * already deleted by inet_child_forget() and the mptcp socket can't
2604 : : * survive too.
2605 : : */
2606 [ + + + + : 7793 : if (msk->in_accept_queue && msk->first == ssk &&
+ + ]
2607 [ - + ]: 40 : (sock_flag(sk, SOCK_DEAD) || sock_flag(ssk, SOCK_DEAD))) {
2608 : : /* ensure later check in mptcp_worker() will dispose the msk */
2609 : 36 : sock_set_flag(sk, SOCK_DEAD);
2610 : 36 : mptcp_set_close_tout(sk, tcp_jiffies32 - (mptcp_close_timeout(sk) + 1));
2611 : 36 : mptcp_subflow_drop_ctx(ssk);
2612 : 36 : goto out_release;
2613 : : }
2614 : :
2615 [ + + + + ]: 7719 : dispose_it = msk->free_first || ssk != msk->first;
2616 : : if (dispose_it)
2617 : 6107 : list_del(&subflow->node);
2618 : :
2619 [ + + + + ]: 7719 : if (subflow->send_fastclose && ssk->sk_state != TCP_CLOSE)
2620 : 386 : tcp_set_state(ssk, TCP_CLOSE);
2621 : :
2622 [ + + + + ]: 7719 : need_push = (flags & MPTCP_CF_PUSH) && __mptcp_retransmit_pending_data(sk);
2623 [ + + ]: 7719 : if (!dispose_it) {
2624 : 1612 : __mptcp_subflow_disconnect(ssk, subflow, msk->fastclosing);
2625 : 1612 : release_sock(ssk);
2626 : :
2627 : 1612 : goto out;
2628 : : }
2629 : :
2630 : 6107 : subflow->disposable = 1;
2631 : :
2632 : : /* if ssk hit tcp_done(), tcp_cleanup_ulp() cleared the related ops
2633 : : * the ssk has been already destroyed, we just need to release the
2634 : : * reference owned by msk;
2635 : : */
2636 [ - + ]: 6107 : if (!inet_csk(ssk)->icsk_ulp_ops) {
2637 [ # # ]: 0 : WARN_ON_ONCE(!sock_flag(ssk, SOCK_DEAD));
2638 [ # # ]: 0 : kfree_rcu(subflow, rcu);
2639 : : } else {
2640 : : /* otherwise tcp will dispose of the ssk and subflow ctx */
2641 : 6107 : __tcp_close(ssk, 0);
2642 : :
2643 : : /* close acquired an extra ref */
2644 : 6107 : __sock_put(ssk);
2645 : : }
2646 : :
2647 : 6143 : out_release:
2648 : 6143 : __mptcp_subflow_error_report(sk, ssk);
2649 : 6143 : release_sock(ssk);
2650 : :
2651 : 6143 : sock_put(ssk);
2652 : :
2653 [ + + ]: 6143 : if (ssk == msk->first)
2654 : 4912 : WRITE_ONCE(msk->first, NULL);
2655 : :
2656 : 1231 : out:
2657 : 7755 : __mptcp_sync_sndbuf(sk);
2658 [ + + ]: 7755 : if (need_push)
2659 : 54 : __mptcp_push_pending(sk, 0);
2660 : :
2661 : : /* Catch every 'all subflows closed' scenario, including peers silently
2662 : : * closing them, e.g. due to timeout.
2663 : : * For established sockets, allow an additional timeout before closing,
2664 : : * as the protocol can still create more subflows.
2665 : : */
2666 [ + + + + : 11420 : if (list_is_singular(&msk->conn_list) && msk->first &&
+ + ]
[ + + + + ]
2667 [ + - ]: 30 : inet_sk_state_load(msk->first) == TCP_CLOSE) {
2668 [ + + + + ]: 1586 : if (sk->sk_state != TCP_ESTABLISHED ||
2669 [ - + ]: 27 : msk->in_accept_queue || sock_flag(sk, SOCK_DEAD)) {
2670 : 1559 : mptcp_set_state(sk, TCP_CLOSE);
2671 : 1559 : mptcp_close_wake_up(sk);
2672 : : } else {
2673 : 27 : mptcp_start_tout_timer(sk);
2674 : : }
2675 : : }
2676 : 7755 : }
2677 : :
2678 : 2183 : void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
2679 : : struct mptcp_subflow_context *subflow)
2680 : : {
2681 : : /* The first subflow can already be closed or disconnected */
2682 [ + + + + ]: 2183 : if (subflow->close_event_done || READ_ONCE(subflow->local_id) < 0)
2683 : : return;
2684 : :
2685 : 2131 : subflow->close_event_done = true;
2686 : :
2687 [ + + ]: 2131 : if (sk->sk_state == TCP_ESTABLISHED)
2688 [ - + ]: 331 : mptcp_event(MPTCP_EVENT_SUB_CLOSED, mptcp_sk(sk), ssk, GFP_KERNEL);
2689 : :
2690 : : /* subflow aborted before reaching the fully_established status
2691 : : * attempt the creation of the next subflow
2692 : : */
2693 [ - + ]: 2131 : mptcp_pm_subflow_check_next(mptcp_sk(sk), subflow);
2694 : :
2695 : 2131 : __mptcp_close_ssk(sk, ssk, subflow, MPTCP_CF_PUSH);
2696 : : }
2697 : :
2698 : 0 : static unsigned int mptcp_sync_mss(struct sock *sk, u32 pmtu)
2699 : : {
2700 : 0 : return 0;
2701 : : }
2702 : :
2703 : 1588 : static void __mptcp_close_subflow(struct sock *sk)
2704 : : {
2705 : 1588 : struct mptcp_subflow_context *subflow, *tmp;
2706 [ - + ]: 1588 : struct mptcp_sock *msk = mptcp_sk(sk);
2707 : :
2708 : 1588 : might_sleep();
2709 : :
2710 [ + + ]: 3914 : mptcp_for_each_subflow_safe(msk, subflow, tmp) {
2711 : 2326 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
2712 : 2326 : int ssk_state = inet_sk_state_load(ssk);
2713 : :
2714 [ + + + + ]: 2326 : if (ssk_state != TCP_CLOSE &&
2715 [ + + ]: 87 : (ssk_state != TCP_CLOSE_WAIT ||
2716 [ - + ]: 42 : inet_sk_state_load(sk) != TCP_ESTABLISHED ||
[ # # # # ]
2717 : 42 : __mptcp_check_fallback(msk)))
2718 : 341 : continue;
2719 : :
2720 : : /* 'subflow_data_ready' will re-sched once rx queue is empty */
2721 [ - + ]: 1985 : if (!skb_queue_empty_lockless(&ssk->sk_receive_queue))
2722 : 0 : continue;
2723 : :
2724 : 1985 : mptcp_close_ssk(sk, ssk, subflow);
2725 : : }
2726 : :
2727 : 1588 : }
2728 : :
2729 : 12412 : static bool mptcp_close_tout_expired(const struct sock *sk)
2730 : : {
2731 [ + + ]: 12412 : if (!inet_csk(sk)->icsk_mtup.probe_timestamp ||
2732 [ + + ]: 4754 : sk->sk_state == TCP_CLOSE)
2733 : : return false;
2734 : :
2735 : 3522 : return time_after32(tcp_jiffies32,
2736 : : inet_csk(sk)->icsk_mtup.probe_timestamp + mptcp_close_timeout(sk));
2737 : : }
2738 : :
2739 : 12412 : static void mptcp_check_fastclose(struct mptcp_sock *msk)
2740 : : {
2741 : 12412 : struct mptcp_subflow_context *subflow, *tmp;
2742 : 12412 : struct sock *sk = (struct sock *)msk;
2743 : :
2744 [ - + + + ]: 12412 : if (likely(!READ_ONCE(msk->rcv_fastclose)))
[ + + ]
2745 : : return;
2746 : :
2747 : 218 : mptcp_token_destroy(msk);
2748 : :
2749 [ + + ]: 483 : mptcp_for_each_subflow_safe(msk, subflow, tmp) {
2750 : 265 : struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow);
2751 : 265 : bool slow;
2752 : :
2753 : 265 : slow = lock_sock_fast(tcp_sk);
2754 [ + + ]: 265 : if (tcp_sk->sk_state != TCP_CLOSE) {
2755 : 30 : mptcp_send_active_reset_reason(tcp_sk);
2756 : 30 : tcp_set_state(tcp_sk, TCP_CLOSE);
2757 : : }
2758 : 265 : unlock_sock_fast(tcp_sk, slow);
2759 : : }
2760 : :
2761 : : /* Mirror the tcp_reset() error propagation */
2762 [ - + + - ]: 218 : switch (sk->sk_state) {
2763 : : case TCP_SYN_SENT:
2764 : 0 : WRITE_ONCE(sk->sk_err, ECONNREFUSED);
2765 : 0 : break;
2766 : : case TCP_CLOSE_WAIT:
2767 : 13 : WRITE_ONCE(sk->sk_err, EPIPE);
2768 : 13 : break;
2769 : : case TCP_CLOSE:
2770 : : return;
2771 : : default:
2772 : 205 : WRITE_ONCE(sk->sk_err, ECONNRESET);
2773 : : }
2774 : :
2775 : 218 : mptcp_set_state(sk, TCP_CLOSE);
2776 : 218 : WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
2777 : 218 : smp_mb__before_atomic(); /* SHUTDOWN must be visible first */
2778 : 218 : set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags);
2779 : :
2780 : : /* the calling mptcp_worker will properly destroy the socket */
2781 [ + + ]: 218 : if (sock_flag(sk, SOCK_DEAD))
2782 : : return;
2783 : :
2784 : 121 : sk->sk_state_change(sk);
2785 : 121 : sk_error_report(sk);
2786 : : }
2787 : :
2788 : 6165 : static void __mptcp_retrans(struct sock *sk)
2789 : : {
2790 : 6165 : struct mptcp_sendmsg_info info = { .data_lock_held = true, };
2791 [ - + ]: 6165 : struct mptcp_sock *msk = mptcp_sk(sk);
2792 : 6165 : struct mptcp_subflow_context *subflow;
2793 : 6165 : struct mptcp_data_frag *dfrag;
2794 : 6165 : struct sock *ssk;
2795 : 6165 : int ret, err;
2796 : 6165 : u16 len = 0;
2797 : :
2798 : 6165 : mptcp_clean_una_wakeup(sk);
2799 : :
2800 : : /* first check ssk: need to kick "stale" logic */
2801 : 6165 : err = mptcp_sched_get_retrans(msk);
2802 : 6165 : dfrag = mptcp_rtx_head(sk);
2803 [ + + ]: 6165 : if (!dfrag) {
2804 [ + + ]: 2879 : if (mptcp_data_fin_enabled(msk)) {
2805 : 1314 : struct inet_connection_sock *icsk = inet_csk(sk);
2806 : :
2807 : 1314 : WRITE_ONCE(icsk->icsk_retransmits,
2808 : : icsk->icsk_retransmits + 1);
2809 : 1314 : mptcp_set_datafin_timeout(sk);
2810 : 1314 : mptcp_send_ack(msk);
2811 : :
2812 : 1314 : goto reset_timer;
2813 : : }
2814 : :
2815 [ + + ]: 1565 : if (!mptcp_send_head(sk))
2816 : 1503 : goto clear_scheduled;
2817 : :
2818 : 62 : goto reset_timer;
2819 : : }
2820 : :
2821 [ + + ]: 3286 : if (err)
2822 : 3037 : goto reset_timer;
2823 : :
2824 [ + + ]: 752 : mptcp_for_each_subflow(msk, subflow) {
2825 [ - + + + ]: 503 : if (READ_ONCE(subflow->scheduled)) {
[ + + ]
2826 : 249 : u16 copied = 0;
2827 : :
2828 : 249 : mptcp_subflow_set_scheduled(subflow, false);
2829 : :
2830 : 249 : ssk = mptcp_subflow_tcp_sock(subflow);
2831 : :
2832 : 249 : lock_sock(ssk);
2833 : :
2834 : : /* limit retransmission to the bytes already sent on some subflows */
2835 : 249 : info.sent = 0;
2836 [ - + + + ]: 249 : info.limit = READ_ONCE(msk->csum_enabled) ? dfrag->data_len :
[ + + ]
2837 : : dfrag->already_sent;
2838 : :
2839 : : /*
2840 : : * make the whole retrans decision, xmit, disallow
2841 : : * fallback atomic, note that we can't retrans even
2842 : : * when an infinite fallback is in progress, i.e. new
2843 : : * subflows are disallowed.
2844 : : */
2845 : 249 : spin_lock_bh(&msk->fallback_lock);
2846 [ + - ]: 249 : if (__mptcp_check_fallback(msk) ||
2847 [ - + - + ]: 249 : !msk->allow_subflows) {
[ - + ]
2848 : 0 : spin_unlock_bh(&msk->fallback_lock);
2849 : 0 : release_sock(ssk);
2850 : 0 : goto clear_scheduled;
2851 : : }
2852 : :
2853 [ + + ]: 515 : while (info.sent < info.limit) {
2854 : 267 : ret = mptcp_sendmsg_frag(sk, ssk, dfrag, &info);
2855 [ + + ]: 267 : if (ret <= 0)
2856 : : break;
2857 : :
2858 [ + - ]: 266 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_RETRANSSEGS);
2859 : 266 : copied += ret;
2860 : 266 : info.sent += ret;
2861 : : }
2862 [ + + ]: 249 : if (copied) {
2863 : 248 : len = max(copied, len);
2864 [ - + ]: 248 : tcp_push(ssk, 0, info.mss_now, tcp_sk(ssk)->nonagle,
2865 : : info.size_goal);
2866 : 248 : msk->allow_infinite_fallback = false;
2867 : : }
2868 : 249 : spin_unlock_bh(&msk->fallback_lock);
2869 : :
2870 : 249 : release_sock(ssk);
2871 : : }
2872 : : }
2873 : :
2874 : 249 : msk->bytes_retrans += len;
2875 : 249 : dfrag->already_sent = max(dfrag->already_sent, len);
2876 : :
2877 : : /* With csum enabled retransmission can send new data. */
2878 [ + - ]: 249 : if (after64(dfrag->already_sent + dfrag->data_seq, msk->snd_nxt))
2879 : 0 : WRITE_ONCE(msk->snd_nxt, dfrag->already_sent + dfrag->data_seq);
2880 : :
2881 : 249 : reset_timer:
2882 : 4662 : mptcp_check_and_set_pending(sk);
2883 : :
2884 [ + + ]: 4662 : if (!mptcp_rtx_timer_pending(sk))
2885 : 70 : mptcp_reset_rtx_timer(sk);
2886 : :
2887 : 4592 : clear_scheduled:
2888 : : /* If no rtx data was available or in case of fallback, there
2889 : : * could be left-over scheduled subflows; clear them all
2890 : : * or later xmit could use bad ones
2891 : : */
2892 [ + + ]: 14877 : mptcp_for_each_subflow(msk, subflow)
2893 [ - + + + ]: 8712 : if (READ_ONCE(subflow->scheduled))
[ + + ]
2894 : 1946 : mptcp_subflow_set_scheduled(subflow, false);
2895 : 6165 : }
2896 : :
2897 : : /* schedule the timeout timer for the relevant event: either close timeout
2898 : : * or mp_fail timeout. The close timeout takes precedence on the mp_fail one
2899 : : */
2900 : 1441 : void mptcp_reset_tout_timer(struct mptcp_sock *msk, unsigned long fail_tout)
2901 : : {
2902 : 1441 : struct sock *sk = (struct sock *)msk;
2903 : 1441 : unsigned long timeout, close_timeout;
2904 : :
2905 [ + + + - ]: 1441 : if (!fail_tout && !inet_csk(sk)->icsk_mtup.probe_timestamp)
2906 : : return;
2907 : :
2908 : 2882 : close_timeout = (unsigned long)inet_csk(sk)->icsk_mtup.probe_timestamp -
2909 : 1441 : tcp_jiffies32 + jiffies + mptcp_close_timeout(sk);
2910 : :
2911 : : /* the close timeout takes precedence on the fail one, and here at least one of
2912 : : * them is active
2913 : : */
2914 [ + + ]: 1441 : timeout = inet_csk(sk)->icsk_mtup.probe_timestamp ? close_timeout : fail_tout;
2915 : :
2916 : 1441 : sk_reset_timer(sk, &inet_csk(sk)->mptcp_tout_timer, timeout);
2917 : : }
2918 : :
2919 : 0 : static void mptcp_mp_fail_no_response(struct mptcp_sock *msk)
2920 : : {
2921 : 0 : struct sock *ssk = msk->first;
2922 : 0 : bool slow;
2923 : :
2924 [ # # ]: 0 : if (!ssk)
2925 : : return;
2926 : :
2927 [ # # # # ]: 0 : pr_debug("MP_FAIL doesn't respond, reset the subflow\n");
2928 : :
2929 : 0 : slow = lock_sock_fast(ssk);
2930 : 0 : mptcp_subflow_reset(ssk);
2931 : 0 : WRITE_ONCE(mptcp_subflow_ctx(ssk)->fail_tout, 0);
2932 : 0 : unlock_sock_fast(ssk, slow);
2933 : : }
2934 : :
2935 : 5550 : static void mptcp_backlog_purge(struct sock *sk)
2936 : : {
2937 [ - + ]: 5550 : struct mptcp_sock *msk = mptcp_sk(sk);
2938 : 5550 : struct sk_buff *tmp, *skb;
2939 : 5550 : LIST_HEAD(backlog);
2940 : :
2941 : 5550 : mptcp_data_lock(sk);
2942 [ - + ]: 5550 : list_splice_init(&msk->backlog_list, &backlog);
2943 : 5550 : msk->backlog_len = 0;
2944 : 5550 : mptcp_data_unlock(sk);
2945 : :
2946 [ - + ]: 5550 : list_for_each_entry_safe(skb, tmp, &backlog, list) {
2947 : 0 : mptcp_borrow_fwdmem(sk, skb);
2948 : 0 : kfree_skb_reason(skb, SKB_DROP_REASON_SOCKET_CLOSE);
2949 : : }
2950 : 5550 : sk_mem_reclaim(sk);
2951 : 5550 : }
2952 : :
2953 : 510 : static void mptcp_do_fastclose(struct sock *sk)
2954 : : {
2955 : 510 : struct mptcp_subflow_context *subflow, *tmp;
2956 [ - + ]: 510 : struct mptcp_sock *msk = mptcp_sk(sk);
2957 : :
2958 : 510 : mptcp_set_state(sk, TCP_CLOSE);
2959 : 510 : mptcp_backlog_purge(sk);
2960 : 510 : msk->fastclosing = 1;
2961 : :
2962 : : /* Explicitly send the fastclose reset as need */
2963 [ + + ]: 510 : if (__mptcp_check_fallback(msk))
2964 : : return;
2965 : :
2966 [ + + ]: 950 : mptcp_for_each_subflow_safe(msk, subflow, tmp) {
2967 : 510 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
2968 : :
2969 : 510 : lock_sock(ssk);
2970 : :
2971 : : /* Some subflow socket states don't allow/need a reset.*/
2972 [ - + + + ]: 510 : if ((1 << ssk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE))
[ + + ]
2973 : 93 : goto unlock;
2974 : :
2975 : 417 : subflow->send_fastclose = 1;
2976 : :
2977 : : /* Initialize rcv_mss to TCP_MIN_MSS to avoid division by 0
2978 : : * issue in __tcp_select_window(), see tcp_disconnect().
2979 : : */
2980 : 417 : inet_csk(ssk)->icsk_ack.rcv_mss = TCP_MIN_MSS;
2981 : :
2982 : 417 : tcp_send_active_reset(ssk, ssk->sk_allocation,
2983 : : SK_RST_REASON_TCP_ABORT_ON_CLOSE);
2984 : 510 : unlock:
2985 : 510 : release_sock(ssk);
2986 : : }
2987 : : }
2988 : :
2989 : 13427 : static void mptcp_worker(struct work_struct *work)
2990 : : {
2991 : 13427 : struct mptcp_sock *msk = container_of(work, struct mptcp_sock, work);
2992 : 13427 : struct sock *sk = (struct sock *)msk;
2993 : 13427 : unsigned long fail_tout;
2994 : 13427 : int state;
2995 : :
2996 : 13427 : lock_sock(sk);
2997 : 13427 : state = sk->sk_state;
2998 [ - + + + ]: 13427 : if (unlikely((1 << state) & (TCPF_CLOSE | TCPF_LISTEN)))
[ + + ]
2999 : 1015 : goto unlock;
3000 : :
3001 : 12412 : mptcp_check_fastclose(msk);
3002 : :
3003 : 12412 : mptcp_pm_worker(msk);
3004 : :
3005 : 12412 : mptcp_check_send_data_fin(sk);
3006 : 12412 : mptcp_check_data_fin_ack(sk);
3007 : 12412 : mptcp_check_data_fin(sk);
3008 : :
3009 [ + + ]: 18751 : if (test_and_clear_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags))
3010 : 1588 : __mptcp_close_subflow(sk);
3011 : :
3012 [ + + ]: 12412 : if (mptcp_close_tout_expired(sk)) {
3013 : 118 : struct mptcp_subflow_context *subflow, *tmp;
3014 : :
3015 : 118 : mptcp_do_fastclose(sk);
3016 [ + + ]: 251 : mptcp_for_each_subflow_safe(msk, subflow, tmp)
3017 : 133 : __mptcp_close_ssk(sk, subflow->tcp_sock, subflow, 0);
3018 : 118 : mptcp_close_wake_up(sk);
3019 : : }
3020 : :
3021 [ + + + + ]: 12412 : if (sock_flag(sk, SOCK_DEAD) && sk->sk_state == TCP_CLOSE) {
3022 : 1338 : __mptcp_destroy_sock(sk);
3023 : 1338 : goto unlock;
3024 : : }
3025 : :
3026 [ + + ]: 16721 : if (test_and_clear_bit(MPTCP_WORK_RTX, &msk->flags))
3027 : 4947 : __mptcp_retrans(sk);
3028 : :
3029 [ + - + + ]: 11074 : fail_tout = msk->first ? READ_ONCE(mptcp_subflow_ctx(msk->first)->fail_tout) : 0;
3030 [ + + + - ]: 11074 : if (fail_tout && time_after(jiffies, fail_tout))
3031 : 0 : mptcp_mp_fail_no_response(msk);
3032 : :
3033 : 1127 : unlock:
3034 : 13427 : release_sock(sk);
3035 : 13427 : sock_put(sk);
3036 : 13427 : }
3037 : :
3038 : 5058 : static void __mptcp_init_sock(struct sock *sk)
3039 : : {
3040 [ - + ]: 5058 : struct mptcp_sock *msk = mptcp_sk(sk);
3041 : :
3042 : 5058 : INIT_LIST_HEAD(&msk->conn_list);
3043 : 5058 : INIT_LIST_HEAD(&msk->join_list);
3044 : 5058 : INIT_LIST_HEAD(&msk->rtx_queue);
3045 : 5058 : INIT_LIST_HEAD(&msk->backlog_list);
3046 : 5058 : INIT_WORK(&msk->work, mptcp_worker);
3047 : 5058 : msk->out_of_order_queue = RB_ROOT;
3048 : 5058 : msk->first_pending = NULL;
3049 : 5058 : msk->timer_ival = TCP_RTO_MIN;
3050 : 5058 : msk->scaling_ratio = TCP_DEFAULT_SCALING_RATIO;
3051 : 5058 : msk->backlog_len = 0;
3052 : 5058 : mptcp_init_rtt_est(msk);
3053 : :
3054 : 5058 : WRITE_ONCE(msk->first, NULL);
3055 : 5058 : inet_csk(sk)->icsk_sync_mss = mptcp_sync_mss;
3056 : 5058 : WRITE_ONCE(msk->csum_enabled, mptcp_is_checksum_enabled(sock_net(sk)));
3057 : 5058 : msk->allow_infinite_fallback = true;
3058 : 5058 : msk->allow_subflows = true;
3059 : 5058 : msk->recovery = false;
3060 : 5058 : msk->subflow_id = 1;
3061 : 5058 : msk->last_data_sent = tcp_jiffies32;
3062 : 5058 : msk->last_data_recv = tcp_jiffies32;
3063 : 5058 : msk->last_ack_recv = tcp_jiffies32;
3064 : :
3065 : 5058 : mptcp_pm_data_init(msk);
3066 : 5058 : spin_lock_init(&msk->fallback_lock);
3067 : :
3068 : : /* re-use the csk retrans timer for MPTCP-level retrans */
3069 : 5058 : timer_setup(&sk->mptcp_retransmit_timer, mptcp_retransmit_timer, 0);
3070 : 5058 : timer_setup(&msk->sk.mptcp_tout_timer, mptcp_tout_timer, 0);
3071 : 5058 : }
3072 : :
3073 : 3544 : static void mptcp_ca_reset(struct sock *sk)
3074 : : {
3075 : 3544 : struct inet_connection_sock *icsk = inet_csk(sk);
3076 : :
3077 : 3544 : tcp_assign_congestion_control(sk);
3078 [ - + ]: 3544 : strscpy(mptcp_sk(sk)->ca_name, icsk->icsk_ca_ops->name,
3079 : : sizeof(mptcp_sk(sk)->ca_name));
3080 : :
3081 : : /* no need to keep a reference to the ops, the name will suffice */
3082 : 3544 : tcp_cleanup_congestion_control(sk);
3083 : 3544 : icsk->icsk_ca_ops = NULL;
3084 : 3544 : }
3085 : :
3086 : 3448 : static int mptcp_init_sock(struct sock *sk)
3087 : : {
3088 : 3448 : struct net *net = sock_net(sk);
3089 : 3448 : int ret;
3090 : :
3091 : 3448 : __mptcp_init_sock(sk);
3092 : :
3093 [ + + ]: 3448 : if (!mptcp_is_enabled(net))
3094 : : return -ENOPROTOOPT;
3095 : :
3096 [ + + + - ]: 3438 : if (unlikely(!net->mib.mptcp_statistics) && !mptcp_mib_alloc(net))
3097 : : return -ENOMEM;
3098 : :
3099 : 3438 : rcu_read_lock();
3100 [ - + ]: 3438 : ret = mptcp_init_sched(mptcp_sk(sk),
3101 : : mptcp_sched_find(mptcp_get_scheduler(net)));
3102 : 3438 : rcu_read_unlock();
3103 [ + - ]: 3438 : if (ret)
3104 : : return ret;
3105 : :
3106 : 3438 : set_bit(SOCK_CUSTOM_SOCKOPT, &sk->sk_socket->flags);
3107 : :
3108 : : /* fetch the ca name; do it outside __mptcp_init_sock(), so that clone will
3109 : : * propagate the correct value
3110 : : */
3111 : 3438 : mptcp_ca_reset(sk);
3112 : :
3113 : 3438 : sk_sockets_allocated_inc(sk);
3114 : 3438 : sk->sk_rcvbuf = READ_ONCE(net->ipv4.sysctl_tcp_rmem[1]);
3115 : 3438 : sk->sk_sndbuf = READ_ONCE(net->ipv4.sysctl_tcp_wmem[1]);
3116 : 3438 : sk->sk_write_space = sk_stream_write_space;
3117 : :
3118 : 3438 : return 0;
3119 : : }
3120 : :
3121 : 5040 : static void __mptcp_clear_xmit(struct sock *sk)
3122 : : {
3123 [ - + ]: 5040 : struct mptcp_sock *msk = mptcp_sk(sk);
3124 : 5040 : struct mptcp_data_frag *dtmp, *dfrag;
3125 : :
3126 : 5040 : msk->first_pending = NULL;
3127 [ + + ]: 5246 : list_for_each_entry_safe(dfrag, dtmp, &msk->rtx_queue, list)
3128 : 206 : dfrag_clear(sk, dfrag);
3129 : 5040 : }
3130 : :
3131 : 3586 : void mptcp_cancel_work(struct sock *sk)
3132 : : {
3133 [ - + ]: 3586 : struct mptcp_sock *msk = mptcp_sk(sk);
3134 : :
3135 [ + + ]: 3586 : if (cancel_work_sync(&msk->work))
3136 : 41 : __sock_put(sk);
3137 : 3586 : }
3138 : :
3139 : 4063 : void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how)
3140 : : {
3141 : 4063 : lock_sock(ssk);
3142 : :
3143 [ - + + ]: 4063 : switch (ssk->sk_state) {
3144 : 0 : case TCP_LISTEN:
3145 [ # # ]: 0 : if (!(how & RCV_SHUTDOWN))
3146 : : break;
3147 : 18 : fallthrough;
3148 : : case TCP_SYN_SENT:
3149 [ - + ]: 18 : WARN_ON_ONCE(tcp_disconnect(ssk, O_NONBLOCK));
3150 : : break;
3151 : 4045 : default:
3152 [ - + + + ]: 4045 : if (__mptcp_check_fallback(mptcp_sk(sk))) {
3153 [ - + - - ]: 174 : pr_debug("Fallback\n");
3154 : 174 : ssk->sk_shutdown |= how;
3155 : 174 : tcp_shutdown(ssk, how);
3156 : :
3157 : : /* simulate the data_fin ack reception to let the state
3158 : : * machine move forward
3159 : : */
3160 [ - + - + ]: 174 : WRITE_ONCE(mptcp_sk(sk)->snd_una, mptcp_sk(sk)->snd_nxt);
3161 : 174 : mptcp_schedule_work(sk);
3162 : : } else {
3163 [ - + - - ]: 3871 : pr_debug("Sending DATA_FIN on subflow %p\n", ssk);
3164 : 3871 : tcp_send_ack(ssk);
3165 [ + + ]: 3871 : if (!mptcp_rtx_timer_pending(sk))
3166 : 1888 : mptcp_reset_rtx_timer(sk);
3167 : : }
3168 : : break;
3169 : : }
3170 : :
3171 : 4063 : release_sock(ssk);
3172 : 4063 : }
3173 : :
3174 : 24339 : void mptcp_set_state(struct sock *sk, int state)
3175 : : {
3176 : 25349 : int oldstate = sk->sk_state;
3177 : :
3178 [ + + - ]: 24319 : switch (state) {
3179 : 3254 : case TCP_ESTABLISHED:
3180 [ + - ]: 3254 : if (oldstate != TCP_ESTABLISHED)
3181 [ + - ]: 3254 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
3182 : : break;
3183 : : case TCP_CLOSE_WAIT:
3184 : : /* Unlike TCP, MPTCP sk would not have the TCP_SYN_RECV state:
3185 : : * MPTCP "accepted" sockets will be created later on. So no
3186 : : * transition from TCP_SYN_RECV to TCP_CLOSE_WAIT.
3187 : : */
3188 : : break;
3189 : 21065 : default:
3190 [ + + ]: 21065 : if (oldstate == TCP_ESTABLISHED || oldstate == TCP_CLOSE_WAIT)
3191 [ + - ]: 3254 : MPTCP_DEC_STATS(sock_net(sk), MPTCP_MIB_CURRESTAB);
3192 : : }
3193 : :
3194 : 25349 : inet_sk_state_store(sk, state);
3195 : 1030 : }
3196 : :
3197 : : static const unsigned char new_state[16] = {
3198 : : /* current state: new state: action: */
3199 : : [0 /* (Invalid) */] = TCP_CLOSE,
3200 : : [TCP_ESTABLISHED] = TCP_FIN_WAIT1 | TCP_ACTION_FIN,
3201 : : [TCP_SYN_SENT] = TCP_CLOSE,
3202 : : [TCP_SYN_RECV] = TCP_FIN_WAIT1 | TCP_ACTION_FIN,
3203 : : [TCP_FIN_WAIT1] = TCP_FIN_WAIT1,
3204 : : [TCP_FIN_WAIT2] = TCP_FIN_WAIT2,
3205 : : [TCP_TIME_WAIT] = TCP_CLOSE, /* should not happen ! */
3206 : : [TCP_CLOSE] = TCP_CLOSE,
3207 : : [TCP_CLOSE_WAIT] = TCP_LAST_ACK | TCP_ACTION_FIN,
3208 : : [TCP_LAST_ACK] = TCP_LAST_ACK,
3209 : : [TCP_LISTEN] = TCP_CLOSE,
3210 : : [TCP_CLOSING] = TCP_CLOSING,
3211 : : [TCP_NEW_SYN_RECV] = TCP_CLOSE, /* should not happen ! */
3212 : : };
3213 : :
3214 : 3447 : static int mptcp_close_state(struct sock *sk)
3215 : : {
3216 : 3447 : int next = (int)new_state[sk->sk_state];
3217 : 3447 : int ns = next & TCP_STATE_MASK;
3218 : :
3219 : 3447 : mptcp_set_state(sk, ns);
3220 : :
3221 : 3447 : return next & TCP_ACTION_FIN;
3222 : : }
3223 : :
3224 : 316100 : static void mptcp_check_send_data_fin(struct sock *sk)
3225 : : {
3226 : 316100 : struct mptcp_subflow_context *subflow;
3227 [ - + ]: 316100 : struct mptcp_sock *msk = mptcp_sk(sk);
3228 : :
3229 [ - + - - : 316100 : pr_debug("msk=%p snd_data_fin_enable=%d pending=%d snd_nxt=%llu write_seq=%llu\n",
- - ]
[ - + - - ]
3230 : : msk, msk->snd_data_fin_enable, !!mptcp_send_head(sk),
3231 : : msk->snd_nxt, msk->write_seq);
3232 : :
3233 : : /* we still need to enqueue subflows or not really shutting down,
3234 : : * skip this
3235 : : */
3236 [ - + + + : 319073 : if (!msk->snd_data_fin_enable || msk->snd_nxt + 1 != msk->write_seq ||
+ + - + ]
[ + + + +
- + ]
3237 : 2973 : mptcp_send_head(sk))
3238 : 313127 : return;
3239 : :
3240 : 2973 : WRITE_ONCE(msk->snd_nxt, msk->write_seq);
3241 : :
3242 [ + + ]: 6844 : mptcp_for_each_subflow(msk, subflow) {
3243 : 3871 : struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow);
3244 : :
3245 : 3871 : mptcp_subflow_shutdown(sk, tcp_sk, SEND_SHUTDOWN);
3246 : : }
3247 : : }
3248 : :
3249 : 2979 : static void __mptcp_wr_shutdown(struct sock *sk)
3250 : : {
3251 [ - + ]: 2979 : struct mptcp_sock *msk = mptcp_sk(sk);
3252 : :
3253 [ - + - - : 2979 : pr_debug("msk=%p snd_data_fin_enable=%d shutdown=%x state=%d pending=%d\n",
- - ]
[ - + - - ]
3254 : : msk, msk->snd_data_fin_enable, sk->sk_shutdown, sk->sk_state,
3255 : : !!mptcp_send_head(sk));
3256 : :
3257 : : /* will be ignored by fallback sockets */
3258 : 2979 : WRITE_ONCE(msk->write_seq, msk->write_seq + 1);
3259 : 2979 : WRITE_ONCE(msk->snd_data_fin_enable, 1);
3260 : :
3261 : 2979 : mptcp_check_send_data_fin(sk);
3262 : 2979 : }
3263 : :
3264 : 4924 : static void __mptcp_destroy_sock(struct sock *sk)
3265 : : {
3266 [ - + ]: 4924 : struct mptcp_sock *msk = mptcp_sk(sk);
3267 : :
3268 [ - + - - ]: 4924 : pr_debug("msk=%p\n", msk);
3269 : :
3270 : 4924 : might_sleep();
3271 : :
3272 : 4924 : mptcp_stop_rtx_timer(sk);
3273 : 4924 : sk_stop_timer(sk, &inet_csk(sk)->mptcp_tout_timer);
3274 : 4924 : msk->pm.status = 0;
3275 : 4924 : mptcp_release_sched(msk);
3276 : :
3277 : 4924 : sk->sk_prot->destroy(sk);
3278 : :
3279 : 4924 : sk_stream_kill_queues(sk);
3280 : 4924 : xfrm_sk_free_policy(sk);
3281 : :
3282 : 4924 : sock_put(sk);
3283 : 4924 : }
3284 : :
3285 : 36 : void __mptcp_unaccepted_force_close(struct sock *sk)
3286 : : {
3287 : 36 : sock_set_flag(sk, SOCK_DEAD);
3288 : 36 : mptcp_do_fastclose(sk);
3289 : 36 : __mptcp_destroy_sock(sk);
3290 : 36 : }
3291 : :
3292 : 0 : static __poll_t mptcp_check_readable(struct sock *sk)
3293 : : {
3294 [ + + ]: 1285669 : return mptcp_epollin_ready(sk) ? EPOLLIN | EPOLLRDNORM : 0;
3295 : : }
3296 : :
3297 : 3338 : static void mptcp_check_listen_stop(struct sock *sk)
3298 : : {
3299 : 3338 : struct sock *ssk;
3300 : :
3301 [ + + ]: 3338 : if (inet_sk_state_load(sk) != TCP_LISTEN)
3302 : : return;
3303 : :
3304 : 1736 : sock_prot_inuse_add(sock_net(sk), sk->sk_prot, -1);
3305 [ - + ]: 1736 : ssk = mptcp_sk(sk)->first;
3306 [ + - - + ]: 3472 : if (WARN_ON_ONCE(!ssk || inet_sk_state_load(ssk) != TCP_LISTEN))
3307 : 0 : return;
3308 : :
3309 : 1736 : lock_sock_nested(ssk, SINGLE_DEPTH_NESTING);
3310 : 1736 : tcp_set_state(ssk, TCP_CLOSE);
3311 : 1736 : mptcp_subflow_queue_clean(sk, ssk);
3312 : 1736 : inet_csk_listen_stop(ssk);
3313 : 1736 : mptcp_event_pm_listener(ssk, MPTCP_EVENT_LISTENER_CLOSED);
3314 : 1736 : release_sock(ssk);
3315 : : }
3316 : :
3317 : 4962 : bool __mptcp_close(struct sock *sk, long timeout)
3318 : : {
3319 : 4962 : struct mptcp_subflow_context *subflow;
3320 [ - + ]: 4962 : struct mptcp_sock *msk = mptcp_sk(sk);
3321 : 4962 : bool do_cancel_work = false;
3322 : 4962 : int subflows_alive = 0;
3323 : :
3324 : 4962 : WRITE_ONCE(sk->sk_shutdown, SHUTDOWN_MASK);
3325 : :
3326 [ - + + + ]: 4962 : if ((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) {
[ + + ]
3327 : 3232 : mptcp_check_listen_stop(sk);
3328 : 3232 : mptcp_set_state(sk, TCP_CLOSE);
3329 : 3232 : goto cleanup;
3330 : : }
3331 : :
3332 [ + + + - : 3222 : if (mptcp_data_avail(msk) || timeout < 0 ||
+ + ]
3333 [ + - ]: 1504 : (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime)) {
3334 : : /* If the msk has read data, or the caller explicitly ask it,
3335 : : * do the MPTCP equivalent of TCP reset, aka MPTCP fastclose
3336 : : */
3337 : 250 : mptcp_do_fastclose(sk);
3338 : 250 : timeout = 0;
3339 [ + + ]: 1480 : } else if (mptcp_close_state(sk)) {
3340 : 1159 : __mptcp_wr_shutdown(sk);
3341 : : }
3342 : :
3343 : 1730 : sk_stream_wait_close(sk, timeout);
3344 : :
3345 : 4962 : cleanup:
3346 : : /* orphan all the subflows */
3347 [ + + ]: 10514 : mptcp_for_each_subflow(msk, subflow) {
3348 : 5552 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
3349 : 5552 : bool slow = lock_sock_fast_nested(ssk);
3350 : :
3351 : 5552 : subflows_alive += ssk->sk_state != TCP_CLOSE;
3352 : :
3353 : : /* since the close timeout takes precedence on the fail one,
3354 : : * cancel the latter
3355 : : */
3356 [ + + ]: 5552 : if (ssk == msk->first)
3357 : 4950 : subflow->fail_tout = 0;
3358 : :
3359 : : /* detach from the parent socket, but allow data_ready to
3360 : : * push incoming data into the mptcp stack, to properly ack it
3361 : : */
3362 : 5552 : ssk->sk_socket = NULL;
3363 : 5552 : ssk->sk_wq = NULL;
3364 : 5552 : unlock_sock_fast(ssk, slow);
3365 : : }
3366 : 4962 : sock_orphan(sk);
3367 : :
3368 : : /* all the subflows are closed, only timeout can change the msk
3369 : : * state, let's not keep resources busy for no reasons
3370 : : */
3371 [ + + ]: 4962 : if (subflows_alive == 0)
3372 : 2795 : mptcp_set_state(sk, TCP_CLOSE);
3373 : :
3374 : 4962 : sock_hold(sk);
3375 [ - + - - ]: 4962 : pr_debug("msk=%p state=%d\n", sk, sk->sk_state);
3376 : 4962 : mptcp_pm_connection_closed(msk);
3377 : :
3378 [ + + ]: 4962 : if (sk->sk_state == TCP_CLOSE) {
3379 : 3550 : __mptcp_destroy_sock(sk);
3380 : 3550 : do_cancel_work = true;
3381 : : } else {
3382 : 1412 : mptcp_start_tout_timer(sk);
3383 : : }
3384 : :
3385 : 4962 : return do_cancel_work;
3386 : : }
3387 : :
3388 : 4962 : static void mptcp_close(struct sock *sk, long timeout)
3389 : : {
3390 : 4962 : bool do_cancel_work;
3391 : :
3392 : 4962 : lock_sock(sk);
3393 : :
3394 : 4962 : do_cancel_work = __mptcp_close(sk, timeout);
3395 : 4962 : release_sock(sk);
3396 [ + + ]: 4962 : if (do_cancel_work)
3397 : 3550 : mptcp_cancel_work(sk);
3398 : :
3399 : 4962 : sock_put(sk);
3400 : 4962 : }
3401 : :
3402 : 6788 : static void mptcp_copy_inaddrs(struct sock *msk, const struct sock *ssk)
3403 : : {
3404 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
3405 [ + - ]: 6788 : const struct ipv6_pinfo *ssk6 = inet6_sk(ssk);
3406 [ + - ]: 6788 : struct ipv6_pinfo *msk6 = inet6_sk(msk);
3407 : :
3408 : 6788 : msk->sk_v6_daddr = ssk->sk_v6_daddr;
3409 : 6788 : msk->sk_v6_rcv_saddr = ssk->sk_v6_rcv_saddr;
3410 : :
3411 [ + + ]: 6788 : if (msk6 && ssk6) {
3412 : 3032 : msk6->saddr = ssk6->saddr;
3413 : 3032 : msk6->flow_label = ssk6->flow_label;
3414 : : }
3415 : : #endif
3416 : :
3417 : 6788 : inet_sk(msk)->inet_num = inet_sk(ssk)->inet_num;
3418 : 6788 : inet_sk(msk)->inet_dport = inet_sk(ssk)->inet_dport;
3419 : 6788 : inet_sk(msk)->inet_sport = inet_sk(ssk)->inet_sport;
3420 : 6788 : inet_sk(msk)->inet_daddr = inet_sk(ssk)->inet_daddr;
3421 : 6788 : inet_sk(msk)->inet_saddr = inet_sk(ssk)->inet_saddr;
3422 : 6788 : inet_sk(msk)->inet_rcv_saddr = inet_sk(ssk)->inet_rcv_saddr;
3423 : 6788 : }
3424 : :
3425 : 5040 : static void mptcp_destroy_common(struct mptcp_sock *msk)
3426 : : {
3427 : 5040 : struct mptcp_subflow_context *subflow, *tmp;
3428 : 5040 : struct sock *sk = (struct sock *)msk;
3429 : :
3430 : 5040 : __mptcp_clear_xmit(sk);
3431 : 5040 : mptcp_backlog_purge(sk);
3432 : :
3433 : : /* join list will be eventually flushed (with rst) at sock lock release time */
3434 [ + + ]: 10531 : mptcp_for_each_subflow_safe(msk, subflow, tmp)
3435 : 5491 : __mptcp_close_ssk(sk, mptcp_subflow_tcp_sock(subflow), subflow, 0);
3436 : :
3437 : 5040 : __skb_queue_purge(&sk->sk_receive_queue);
3438 : 5040 : skb_rbtree_purge(&msk->out_of_order_queue);
3439 : :
3440 : : /* move all the rx fwd alloc into the sk_mem_reclaim_final in
3441 : : * inet_sock_destruct() will dispose it
3442 : : */
3443 : 5040 : mptcp_token_destroy(msk);
3444 : 5040 : mptcp_pm_destroy(msk);
3445 : 5040 : }
3446 : :
3447 : 106 : static int mptcp_disconnect(struct sock *sk, int flags)
3448 : : {
3449 [ - + ]: 106 : struct mptcp_sock *msk = mptcp_sk(sk);
3450 : :
3451 : : /* We are on the fastopen error path. We can't call straight into the
3452 : : * subflows cleanup code due to lock nesting (we are already under
3453 : : * msk->firstsocket lock).
3454 : : */
3455 [ + - ]: 106 : if (msk->fastopening)
3456 : : return -EBUSY;
3457 : :
3458 : 106 : mptcp_check_listen_stop(sk);
3459 : 106 : mptcp_set_state(sk, TCP_CLOSE);
3460 : :
3461 : 106 : mptcp_stop_rtx_timer(sk);
3462 : 106 : mptcp_stop_tout_timer(sk);
3463 : :
3464 : 106 : mptcp_pm_connection_closed(msk);
3465 : :
3466 : : /* msk->subflow is still intact, the following will not free the first
3467 : : * subflow
3468 : : */
3469 : 106 : mptcp_do_fastclose(sk);
3470 : 106 : mptcp_destroy_common(msk);
3471 : :
3472 : : /* The first subflow is already in TCP_CLOSE status, the following
3473 : : * can't overlap with a fallback anymore
3474 : : */
3475 : 106 : spin_lock_bh(&msk->fallback_lock);
3476 : 106 : msk->allow_subflows = true;
3477 : 106 : msk->allow_infinite_fallback = true;
3478 : 106 : WRITE_ONCE(msk->flags, 0);
3479 : 106 : spin_unlock_bh(&msk->fallback_lock);
3480 : :
3481 : 106 : msk->cb_flags = 0;
3482 : 106 : msk->recovery = false;
3483 : 106 : WRITE_ONCE(msk->can_ack, false);
3484 : 106 : WRITE_ONCE(msk->fully_established, false);
3485 : 106 : WRITE_ONCE(msk->rcv_data_fin, false);
3486 : 106 : WRITE_ONCE(msk->snd_data_fin_enable, false);
3487 : 106 : WRITE_ONCE(msk->rcv_fastclose, false);
3488 : 106 : WRITE_ONCE(msk->use_64bit_ack, false);
3489 : 106 : WRITE_ONCE(msk->csum_enabled, mptcp_is_checksum_enabled(sock_net(sk)));
3490 : 106 : mptcp_pm_data_reset(msk);
3491 : 106 : mptcp_ca_reset(sk);
3492 : 106 : msk->bytes_consumed = 0;
3493 : 106 : msk->bytes_acked = 0;
3494 : 106 : msk->bytes_received = 0;
3495 : 106 : msk->bytes_sent = 0;
3496 : 106 : msk->bytes_retrans = 0;
3497 : 106 : msk->rcvspace_init = 0;
3498 : 106 : msk->fastclosing = 0;
3499 : 106 : mptcp_init_rtt_est(msk);
3500 : :
3501 : : /* for fallback's sake */
3502 : 106 : WRITE_ONCE(msk->ack_seq, 0);
3503 : 106 : atomic64_set(&msk->rcv_wnd_sent, 0);
3504 : :
3505 : 106 : WRITE_ONCE(sk->sk_shutdown, 0);
3506 : 106 : sk_error_report(sk);
3507 : 106 : return 0;
3508 : : }
3509 : :
3510 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
3511 : 772 : static struct ipv6_pinfo *mptcp_inet6_sk(const struct sock *sk)
3512 : : {
3513 [ - + ]: 772 : struct mptcp6_sock *msk6 = container_of(mptcp_sk(sk), struct mptcp6_sock, msk);
3514 : :
3515 : 772 : return &msk6->np;
3516 : : }
3517 : :
3518 : 772 : static void mptcp_copy_ip6_options(struct sock *newsk, const struct sock *sk)
3519 : : {
3520 [ + - ]: 772 : const struct ipv6_pinfo *np = inet6_sk(sk);
3521 : 772 : struct ipv6_txoptions *opt;
3522 : 772 : struct ipv6_pinfo *newnp;
3523 : :
3524 [ + - ]: 772 : newnp = inet6_sk(newsk);
3525 : :
3526 : 772 : rcu_read_lock();
3527 [ + - - + : 772 : opt = rcu_dereference(np->opt);
- - - - -
- ]
3528 [ + - ]: 772 : if (opt) {
3529 : 0 : opt = ipv6_dup_options(newsk, opt);
3530 [ # # ]: 0 : if (!opt)
3531 [ # # ]: 0 : net_warn_ratelimited("%s: Failed to copy ip6 options\n", __func__);
3532 : : }
3533 : 772 : RCU_INIT_POINTER(newnp->opt, opt);
3534 : 772 : rcu_read_unlock();
3535 : 772 : }
3536 : : #endif
3537 : :
3538 : 838 : static void mptcp_copy_ip_options(struct sock *newsk, const struct sock *sk)
3539 : : {
3540 : 838 : struct ip_options_rcu *inet_opt, *newopt = NULL;
3541 : 838 : const struct inet_sock *inet = inet_sk(sk);
3542 : 838 : struct inet_sock *newinet;
3543 : :
3544 : 838 : newinet = inet_sk(newsk);
3545 : :
3546 : 838 : rcu_read_lock();
3547 [ + - - + : 838 : inet_opt = rcu_dereference(inet->inet_opt);
- - - - -
- ]
3548 [ + - ]: 838 : if (inet_opt) {
3549 : 0 : newopt = sock_kmemdup(newsk, inet_opt, sizeof(*inet_opt) +
3550 : 0 : inet_opt->opt.optlen, GFP_ATOMIC);
3551 [ # # ]: 0 : if (!newopt)
3552 [ # # ]: 0 : net_warn_ratelimited("%s: Failed to copy ip options\n", __func__);
3553 : : }
3554 : 838 : RCU_INIT_POINTER(newinet->inet_opt, newopt);
3555 : 838 : rcu_read_unlock();
3556 : 838 : }
3557 : :
3558 : 1610 : struct sock *mptcp_sk_clone_init(const struct sock *sk,
3559 : : const struct mptcp_options_received *mp_opt,
3560 : : struct sock *ssk,
3561 : : struct request_sock *req)
3562 : : {
3563 : 1610 : struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
3564 : 1610 : struct sock *nsk = sk_clone_lock(sk, GFP_ATOMIC);
3565 : 1610 : struct mptcp_subflow_context *subflow;
3566 : 1610 : struct mptcp_sock *msk;
3567 : :
3568 [ + - ]: 1610 : if (!nsk)
3569 : : return NULL;
3570 : :
3571 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
3572 [ + + ]: 1610 : if (nsk->sk_family == AF_INET6)
3573 : 772 : inet_sk(nsk)->pinet6 = mptcp_inet6_sk(nsk);
3574 : : #endif
3575 : :
3576 : 1610 : __mptcp_init_sock(nsk);
3577 : :
3578 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
3579 [ + + ]: 1610 : if (nsk->sk_family == AF_INET6)
3580 : 772 : mptcp_copy_ip6_options(nsk, sk);
3581 : : else
3582 : : #endif
3583 : 838 : mptcp_copy_ip_options(nsk, sk);
3584 : :
3585 [ - + ]: 1610 : msk = mptcp_sk(nsk);
3586 : 1610 : WRITE_ONCE(msk->local_key, subflow_req->local_key);
3587 : 1610 : WRITE_ONCE(msk->token, subflow_req->token);
3588 : 1610 : msk->in_accept_queue = 1;
3589 : 1610 : WRITE_ONCE(msk->fully_established, false);
3590 [ + + ]: 1610 : if (mp_opt->suboptions & OPTION_MPTCP_CSUMREQD)
3591 : 118 : WRITE_ONCE(msk->csum_enabled, true);
3592 : :
3593 : 1610 : WRITE_ONCE(msk->write_seq, subflow_req->idsn + 1);
3594 : 1610 : WRITE_ONCE(msk->snd_nxt, msk->write_seq);
3595 : 1610 : WRITE_ONCE(msk->snd_una, msk->write_seq);
3596 [ - + ]: 1610 : WRITE_ONCE(msk->wnd_end, msk->snd_nxt + tcp_sk(ssk)->snd_wnd);
3597 [ - + ]: 1610 : msk->setsockopt_seq = mptcp_sk(sk)->setsockopt_seq;
3598 [ - + ]: 1610 : mptcp_init_sched(msk, mptcp_sk(sk)->sched);
3599 : :
3600 : : /* passive msk is created after the first/MPC subflow */
3601 : 1610 : msk->subflow_id = 2;
3602 : :
3603 : 1610 : sock_reset_flag(nsk, SOCK_RCU_FREE);
3604 : 1610 : security_inet_csk_clone(nsk, req);
3605 : :
3606 : : /* this can't race with mptcp_close(), as the msk is
3607 : : * not yet exposted to user-space
3608 : : */
3609 : 1610 : mptcp_set_state(nsk, TCP_ESTABLISHED);
3610 : :
3611 : : /* The msk maintain a ref to each subflow in the connections list */
3612 : 1610 : WRITE_ONCE(msk->first, ssk);
3613 : 1610 : subflow = mptcp_subflow_ctx(ssk);
3614 : 1610 : list_add(&subflow->node, &msk->conn_list);
3615 : 1610 : sock_hold(ssk);
3616 : :
3617 : : /* new mpc subflow takes ownership of the newly
3618 : : * created mptcp socket
3619 : : */
3620 : 1610 : mptcp_token_accept(subflow_req, msk);
3621 : :
3622 : : /* set msk addresses early to ensure mptcp_pm_get_local_id()
3623 : : * uses the correct data
3624 : : */
3625 : 1610 : mptcp_copy_inaddrs(nsk, ssk);
3626 : :
3627 : 1610 : mptcp_rcv_space_init(msk, ssk);
3628 : 1610 : msk->rcvq_space.time = mptcp_stamp();
3629 : :
3630 [ + + ]: 1610 : if (mp_opt->suboptions & OPTION_MPTCP_MPC_ACK)
3631 : 1560 : __mptcp_subflow_fully_established(msk, subflow, mp_opt);
3632 : 1610 : bh_unlock_sock(nsk);
3633 : :
3634 : : /* note: the newly allocated socket refcount is 2 now */
3635 : 1610 : return nsk;
3636 : : }
3637 : :
3638 : 4934 : static void mptcp_destroy(struct sock *sk)
3639 : : {
3640 [ - + ]: 4934 : struct mptcp_sock *msk = mptcp_sk(sk);
3641 : :
3642 : : /* allow the following to close even the initial subflow */
3643 : 4934 : msk->free_first = 1;
3644 : 4934 : mptcp_destroy_common(msk);
3645 : 4934 : sk_sockets_allocated_dec(sk);
3646 : 4934 : }
3647 : :
3648 : 609824 : void __mptcp_data_acked(struct sock *sk)
3649 : : {
3650 [ + + ]: 609824 : if (!sock_owned_by_user(sk))
3651 : 311720 : __mptcp_clean_una(sk);
3652 : : else
3653 [ - + ]: 298104 : __set_bit(MPTCP_CLEAN_UNA, &mptcp_sk(sk)->cb_flags);
3654 : 609824 : }
3655 : :
3656 : 2039850 : void __mptcp_check_push(struct sock *sk, struct sock *ssk)
3657 : : {
3658 [ + + ]: 2039850 : if (!sock_owned_by_user(sk))
3659 : 1577562 : __mptcp_subflow_push_pending(sk, ssk, false);
3660 : : else
3661 [ - + ]: 462288 : __set_bit(MPTCP_PUSH_PENDING, &mptcp_sk(sk)->cb_flags);
3662 : 2039850 : }
3663 : :
3664 : : #define MPTCP_FLAGS_PROCESS_CTX_NEED (BIT(MPTCP_PUSH_PENDING) | \
3665 : : BIT(MPTCP_RETRANSMIT) | \
3666 : : BIT(MPTCP_FLUSH_JOIN_LIST))
3667 : :
3668 : : /* processes deferred events and flush wmem */
3669 : 1900742 : static void mptcp_release_cb(struct sock *sk)
3670 : : __must_hold(&sk->sk_lock.slock)
3671 : : {
3672 [ - + ]: 1900742 : struct mptcp_sock *msk = mptcp_sk(sk);
3673 : :
3674 : 266524 : for (;;) {
3675 : 2167266 : unsigned long flags = (msk->cb_flags & MPTCP_FLAGS_PROCESS_CTX_NEED);
3676 : 2167266 : struct list_head join_list, skbs;
3677 : 2167266 : bool spool_bl;
3678 : 2167266 : u32 moved;
3679 : :
3680 : 2167266 : spool_bl = mptcp_can_spool_backlog(sk, &skbs);
3681 [ + + ]: 2167266 : if (!flags && !spool_bl)
3682 : : break;
3683 : :
3684 [ + + ]: 266524 : INIT_LIST_HEAD(&join_list);
3685 [ + + ]: 266524 : list_splice_init(&msk->join_list, &join_list);
3686 : :
3687 : : /* the following actions acquire the subflow socket lock
3688 : : *
3689 : : * 1) can't be invoked in atomic scope
3690 : : * 2) must avoid ABBA deadlock with msk socket spinlock: the RX
3691 : : * datapath acquires the msk socket spinlock while helding
3692 : : * the subflow socket lock
3693 : : */
3694 : 266524 : msk->cb_flags &= ~flags;
3695 : 266524 : spin_unlock_bh(&sk->sk_lock.slock);
3696 : :
3697 [ + + ]: 266524 : if (flags & BIT(MPTCP_FLUSH_JOIN_LIST))
3698 : 17 : __mptcp_flush_join_list(sk, &join_list);
3699 [ + + ]: 266524 : if (flags & BIT(MPTCP_PUSH_PENDING))
3700 : 218855 : __mptcp_push_pending(sk, 0);
3701 [ + + ]: 266524 : if (flags & BIT(MPTCP_RETRANSMIT))
3702 : 1218 : __mptcp_retrans(sk);
3703 [ + + + + ]: 266524 : if (spool_bl && __mptcp_move_skbs(sk, &skbs, &moved)) {
3704 : : /* notify ack seq update */
3705 : 105095 : mptcp_cleanup_rbuf(msk, 0);
3706 : 105095 : sk->sk_data_ready(sk);
3707 : : }
3708 : :
3709 : 266524 : cond_resched();
3710 : 266524 : spin_lock_bh(&sk->sk_lock.slock);
3711 [ + + ]: 266524 : if (spool_bl)
3712 : 107439 : mptcp_backlog_spooled(sk, moved, &skbs);
3713 : : }
3714 : :
3715 [ - + - - : 3800970 : if (__test_and_clear_bit(MPTCP_CLEAN_UNA, &msk->cb_flags))
- - + + ]
3716 : 132688 : __mptcp_clean_una_wakeup(sk);
3717 [ + + ]: 1900742 : if (unlikely(msk->cb_flags)) {
3718 : : /* be sure to sync the msk state before taking actions
3719 : : * depending on sk_state (MPTCP_ERROR_REPORT)
3720 : : * On sk release avoid actions depending on the first subflow
3721 : : */
3722 [ - + - - : 8094 : if (__test_and_clear_bit(MPTCP_SYNC_STATE, &msk->cb_flags) && msk->first)
- - + + +
- ]
3723 : 1149 : __mptcp_sync_state(sk, msk->pending_state);
3724 [ - + - - : 8094 : if (__test_and_clear_bit(MPTCP_ERROR_REPORT, &msk->cb_flags))
- - + + ]
3725 : 584 : __mptcp_error_report(sk);
3726 [ - + - - : 8094 : if (__test_and_clear_bit(MPTCP_SYNC_SNDBUF, &msk->cb_flags))
- - + + ]
3727 : 2331 : __mptcp_sync_sndbuf(sk);
3728 : : }
3729 : 1900742 : }
3730 : :
3731 : : /* MP_JOIN client subflow must wait for 4th ack before sending any data:
3732 : : * TCP can't schedule delack timer before the subflow is fully established.
3733 : : * MPTCP uses the delack timer to do 3rd ack retransmissions
3734 : : */
3735 : 600 : static void schedule_3rdack_retransmission(struct sock *ssk)
3736 : : {
3737 : 600 : struct inet_connection_sock *icsk = inet_csk(ssk);
3738 [ - + ]: 600 : struct tcp_sock *tp = tcp_sk(ssk);
3739 : 600 : unsigned long timeout;
3740 : :
3741 [ - + + + ]: 600 : if (READ_ONCE(mptcp_subflow_ctx(ssk)->fully_established))
[ + + ]
3742 : : return;
3743 : :
3744 : : /* reschedule with a timeout above RTT, as we must look only for drop */
3745 [ + - ]: 95 : if (tp->srtt_us)
3746 [ - + ]: 95 : timeout = usecs_to_jiffies(tp->srtt_us >> (3 - 1));
3747 : : else
3748 : : timeout = TCP_TIMEOUT_INIT;
3749 : 95 : timeout += jiffies;
3750 : :
3751 [ - + ]: 95 : WARN_ON_ONCE(icsk->icsk_ack.pending & ICSK_ACK_TIMER);
3752 : 95 : smp_store_release(&icsk->icsk_ack.pending,
3753 : : icsk->icsk_ack.pending | ICSK_ACK_SCHED | ICSK_ACK_TIMER);
3754 : 95 : sk_reset_timer(ssk, &icsk->icsk_delack_timer, timeout);
3755 : : }
3756 : :
3757 : 31237 : void mptcp_subflow_process_delegated(struct sock *ssk, long status)
3758 : : {
3759 [ + + ]: 31237 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
3760 : 31237 : struct sock *sk = subflow->conn;
3761 : :
3762 [ + + ]: 31237 : if (status & BIT(MPTCP_DELEGATE_SEND)) {
3763 : 10265 : mptcp_data_lock(sk);
3764 [ + + ]: 10265 : if (!sock_owned_by_user(sk))
3765 : 9483 : __mptcp_subflow_push_pending(sk, ssk, true);
3766 : : else
3767 [ - + ]: 782 : __set_bit(MPTCP_PUSH_PENDING, &mptcp_sk(sk)->cb_flags);
3768 : 10265 : mptcp_data_unlock(sk);
3769 : : }
3770 [ + + ]: 31237 : if (status & BIT(MPTCP_DELEGATE_SNDBUF)) {
3771 : 18141 : mptcp_data_lock(sk);
3772 [ + + ]: 18141 : if (!sock_owned_by_user(sk))
3773 : 15100 : __mptcp_sync_sndbuf(sk);
3774 : : else
3775 [ - + ]: 3041 : __set_bit(MPTCP_SYNC_SNDBUF, &mptcp_sk(sk)->cb_flags);
3776 : 18141 : mptcp_data_unlock(sk);
3777 : : }
3778 [ + + ]: 31237 : if (status & BIT(MPTCP_DELEGATE_ACK))
3779 : 600 : schedule_3rdack_retransmission(ssk);
3780 : 31237 : }
3781 : :
3782 : 0 : static int mptcp_hash(struct sock *sk)
3783 : : {
3784 : : /* should never be called,
3785 : : * we hash the TCP subflows not the MPTCP socket
3786 : : */
3787 : 0 : WARN_ON_ONCE(1);
3788 : 0 : return 0;
3789 : : }
3790 : :
3791 : 10 : static void mptcp_unhash(struct sock *sk)
3792 : : {
3793 : : /* called from sk_common_release(), but nothing to do here */
3794 : 10 : }
3795 : :
3796 : 0 : static int mptcp_get_port(struct sock *sk, unsigned short snum)
3797 : : {
3798 [ # # ]: 0 : struct mptcp_sock *msk = mptcp_sk(sk);
3799 : :
3800 [ # # # # ]: 0 : pr_debug("msk=%p, ssk=%p\n", msk, msk->first);
3801 [ # # ]: 0 : if (WARN_ON_ONCE(!msk->first))
3802 : 0 : return -EINVAL;
3803 : :
3804 : 0 : return inet_csk_get_port(msk->first, snum);
3805 : : }
3806 : :
3807 : 1470 : void mptcp_finish_connect(struct sock *ssk)
3808 : : {
3809 : 1470 : struct mptcp_subflow_context *subflow;
3810 : 1470 : struct mptcp_sock *msk;
3811 : 1470 : struct sock *sk;
3812 : :
3813 [ - + ]: 1470 : subflow = mptcp_subflow_ctx(ssk);
3814 : 1470 : sk = subflow->conn;
3815 [ - + ]: 1470 : msk = mptcp_sk(sk);
3816 : :
3817 [ - + - - ]: 1470 : pr_debug("msk=%p, token=%u\n", sk, subflow->token);
3818 : :
3819 : 1470 : subflow->map_seq = subflow->iasn;
3820 : 1470 : subflow->map_subflow_seq = 1;
3821 : :
3822 : : /* the socket is not connected yet, no msk/subflow ops can access/race
3823 : : * accessing the field below
3824 : : */
3825 : 1470 : WRITE_ONCE(msk->local_key, subflow->local_key);
3826 : 1470 : WRITE_ONCE(msk->rcvq_space.time, mptcp_stamp());
3827 : :
3828 : 1470 : mptcp_pm_new_connection(msk, ssk, 0);
3829 : 1470 : }
3830 : :
3831 : 6248 : void mptcp_sock_graft(struct sock *sk, struct socket *parent)
3832 : : {
3833 : 6248 : write_lock_bh(&sk->sk_callback_lock);
3834 : 6248 : rcu_assign_pointer(sk->sk_wq, &parent->wq);
3835 [ + - ]: 6248 : sk_set_socket(sk, parent);
3836 : 6248 : write_unlock_bh(&sk->sk_callback_lock);
3837 : 6248 : }
3838 : :
3839 : : /* Can be called without holding the msk socket lock; use the callback lock
3840 : : * to avoid {READ_,WRITE_}ONCE annotations on sk_socket.
3841 : : */
3842 : 612 : static void mptcp_sock_check_graft(struct sock *sk, struct sock *ssk)
3843 : : {
3844 : 612 : struct socket *sock;
3845 : :
3846 : 612 : write_lock_bh(&sk->sk_callback_lock);
3847 : 612 : sock = sk->sk_socket;
3848 : 612 : write_unlock_bh(&sk->sk_callback_lock);
3849 [ + + ]: 612 : if (sock) {
3850 : 554 : mptcp_sock_graft(ssk, sock);
3851 : 554 : __mptcp_inherit_cgrp_data(sk, ssk);
3852 : 554 : __mptcp_inherit_memcg(sk, ssk, GFP_ATOMIC);
3853 : : }
3854 : 612 : }
3855 : :
3856 : 1200 : bool mptcp_finish_join(struct sock *ssk)
3857 : : {
3858 [ - + ]: 1200 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
3859 [ - + ]: 1200 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
3860 : 1200 : struct sock *parent = (void *)msk;
3861 : 1200 : bool ret = true;
3862 : :
3863 [ - + - - ]: 1200 : pr_debug("msk=%p, subflow=%p\n", msk, subflow);
3864 : :
3865 : : /* mptcp socket already closing? */
3866 [ - + ]: 1200 : if (!mptcp_is_fully_established(parent)) {
3867 : 0 : subflow->reset_reason = MPTCP_RST_EMPTCP;
3868 : 0 : return false;
3869 : : }
3870 : :
3871 : : /* Active subflow, already present inside the conn_list; is grafted
3872 : : * either by __mptcp_subflow_connect() or accept.
3873 : : */
3874 [ + + ]: 1200 : if (!list_empty(&subflow->node)) {
3875 : 588 : spin_lock_bh(&msk->fallback_lock);
3876 [ - + - + ]: 588 : if (!msk->allow_subflows) {
[ - + ]
3877 : 0 : spin_unlock_bh(&msk->fallback_lock);
3878 : 0 : return false;
3879 : : }
3880 : 588 : mptcp_subflow_joined(msk, ssk);
3881 : 588 : spin_unlock_bh(&msk->fallback_lock);
3882 : 588 : mptcp_propagate_sndbuf(parent, ssk);
3883 : 588 : return true;
3884 : : }
3885 : :
3886 [ - + ]: 612 : if (!mptcp_pm_allow_new_subflow(msk)) {
3887 [ # # ]: 0 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_JOINREJECTED);
3888 : 0 : goto err_prohibited;
3889 : : }
3890 : :
3891 : : /* If we can't acquire msk socket lock here, let the release callback
3892 : : * handle it
3893 : : */
3894 : 612 : mptcp_data_lock(parent);
3895 [ + + ]: 612 : if (!sock_owned_by_user(parent)) {
3896 : 594 : ret = __mptcp_finish_join(msk, ssk);
3897 [ + - ]: 594 : if (ret) {
3898 : 594 : sock_hold(ssk);
3899 : 594 : list_add_tail(&subflow->node, &msk->conn_list);
3900 : 594 : mptcp_sock_check_graft(parent, ssk);
3901 : : }
3902 : : } else {
3903 : 18 : sock_hold(ssk);
3904 [ - + ]: 18 : list_add_tail(&subflow->node, &msk->join_list);
3905 [ - + - - : 18 : __set_bit(MPTCP_FLUSH_JOIN_LIST, &msk->cb_flags);
- - ]
3906 : :
3907 : : /* In case of later failures, __mptcp_flush_join_list() will
3908 : : * properly orphan the ssk via mptcp_close_ssk().
3909 : : */
3910 : 18 : mptcp_sock_check_graft(parent, ssk);
3911 : : }
3912 : 612 : mptcp_data_unlock(parent);
3913 : :
3914 [ - + ]: 612 : if (!ret) {
3915 : 0 : err_prohibited:
3916 : 0 : subflow->reset_reason = MPTCP_RST_EPROHIBIT;
3917 : 0 : return false;
3918 : : }
3919 : :
3920 : : return true;
3921 : : }
3922 : :
3923 : 1967 : static void mptcp_shutdown(struct sock *sk, int how)
3924 : : {
3925 [ - + - - ]: 1967 : pr_debug("sk=%p, how=%d\n", sk, how);
3926 : :
3927 [ + - + + ]: 1967 : if ((how & SEND_SHUTDOWN) && mptcp_close_state(sk))
3928 : 1820 : __mptcp_wr_shutdown(sk);
3929 : 1967 : }
3930 : :
3931 : 16 : static int mptcp_ioctl_outq(const struct mptcp_sock *msk, u64 v)
3932 : : {
3933 : 16 : const struct sock *sk = (void *)msk;
3934 : 16 : u64 delta;
3935 : :
3936 [ + - ]: 16 : if (sk->sk_state == TCP_LISTEN)
3937 : : return -EINVAL;
3938 : :
3939 [ - + + - ]: 16 : if ((1 << sk->sk_state) & (TCPF_SYN_SENT | TCPF_SYN_RECV))
[ + - ]
3940 : : return 0;
3941 : :
3942 : 16 : delta = msk->write_seq - v;
3943 [ + + + + ]: 16 : if (__mptcp_check_fallback(msk) && msk->first) {
3944 [ - + ]: 16 : struct tcp_sock *tp = tcp_sk(msk->first);
3945 : :
3946 : : /* the first subflow is disconnected after close - see
3947 : : * __mptcp_close_ssk(). tcp_disconnect() moves the write_seq
3948 : : * so ignore that status, too.
3949 : : */
3950 [ - + - + ]: 16 : if (!((1 << msk->first->sk_state) &
[ + - ]
3951 : : (TCPF_SYN_SENT | TCPF_SYN_RECV | TCPF_CLOSE)))
3952 : 16 : delta += READ_ONCE(tp->write_seq) - tp->snd_una;
3953 : : }
3954 : 16 : if (delta > INT_MAX)
3955 : : delta = INT_MAX;
3956 : :
3957 : 16 : return (int)delta;
3958 : : }
3959 : :
3960 : 16 : static int mptcp_ioctl(struct sock *sk, int cmd, int *karg)
3961 : : {
3962 [ - + ]: 16 : struct mptcp_sock *msk = mptcp_sk(sk);
3963 : 16 : bool slow;
3964 : :
3965 [ - + + - ]: 16 : switch (cmd) {
3966 : 0 : case SIOCINQ:
3967 [ # # ]: 0 : if (sk->sk_state == TCP_LISTEN)
3968 : : return -EINVAL;
3969 : :
3970 : 0 : lock_sock(sk);
3971 [ # # ]: 0 : if (mptcp_move_skbs(sk))
3972 : 0 : mptcp_cleanup_rbuf(msk, 0);
3973 : 0 : *karg = mptcp_inq_hint(sk);
3974 : 0 : release_sock(sk);
3975 : 0 : break;
3976 : 4 : case SIOCOUTQ:
3977 : 8 : slow = lock_sock_fast(sk);
3978 : 8 : *karg = mptcp_ioctl_outq(msk, READ_ONCE(msk->snd_una));
3979 : 8 : unlock_sock_fast(sk, slow);
3980 : 8 : break;
3981 : 4 : case SIOCOUTQNSD:
3982 : 8 : slow = lock_sock_fast(sk);
3983 : 8 : *karg = mptcp_ioctl_outq(msk, msk->snd_nxt);
3984 : 8 : unlock_sock_fast(sk, slow);
3985 : 8 : break;
3986 : : default:
3987 : : return -ENOIOCTLCMD;
3988 : : }
3989 : :
3990 : : return 0;
3991 : : }
3992 : :
3993 : 1718 : static int mptcp_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
3994 : : int addr_len)
3995 : : {
3996 : 1718 : struct mptcp_subflow_context *subflow;
3997 [ - + ]: 1718 : struct mptcp_sock *msk = mptcp_sk(sk);
3998 : 1718 : int err = -EINVAL;
3999 : 1718 : struct sock *ssk;
4000 : :
4001 : 1718 : ssk = __mptcp_nmpc_sk(msk);
4002 [ - + ]: 1718 : if (IS_ERR(ssk))
4003 : 0 : return PTR_ERR(ssk);
4004 : :
4005 : 1718 : mptcp_set_state(sk, TCP_SYN_SENT);
4006 [ + - ]: 1718 : subflow = mptcp_subflow_ctx(ssk);
4007 : : #ifdef CONFIG_TCP_MD5SIG
4008 : : /* no MPTCP if MD5SIG is enabled on this socket or we may run out of
4009 : : * TCP option space.
4010 : : */
4011 : : if (rcu_access_pointer(tcp_sk(ssk)->md5sig_info))
4012 : : mptcp_early_fallback(msk, subflow, MPTCP_MIB_MD5SIGFALLBACK);
4013 : : #endif
4014 [ + - ]: 1718 : if (subflow->request_mptcp) {
4015 [ + + ]: 1718 : if (mptcp_active_should_disable(sk))
4016 : 6 : mptcp_early_fallback(msk, subflow,
4017 : : MPTCP_MIB_MPCAPABLEACTIVEDISABLED);
4018 [ - + ]: 1712 : else if (mptcp_token_new_connect(ssk) < 0)
4019 : 0 : mptcp_early_fallback(msk, subflow,
4020 : : MPTCP_MIB_TOKENFALLBACKINIT);
4021 : : }
4022 : :
4023 : 1718 : WRITE_ONCE(msk->write_seq, subflow->idsn);
4024 : 1718 : WRITE_ONCE(msk->snd_nxt, subflow->idsn);
4025 : 1718 : WRITE_ONCE(msk->snd_una, subflow->idsn);
4026 [ + + ]: 1718 : if (likely(!__mptcp_check_fallback(msk)))
4027 [ + - ]: 1712 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPCAPABLEACTIVE);
4028 : :
4029 : : /* if reaching here via the fastopen/sendmsg path, the caller already
4030 : : * acquired the subflow socket lock, too.
4031 : : */
4032 [ + + ]: 1718 : if (!msk->fastopening)
4033 : 1648 : lock_sock(ssk);
4034 : :
4035 : : /* the following mirrors closely a very small chunk of code from
4036 : : * __inet_stream_connect()
4037 : : */
4038 [ - + ]: 1718 : if (ssk->sk_state != TCP_CLOSE)
4039 : 0 : goto out;
4040 : :
4041 [ + - - + : 1718 : if (BPF_CGROUP_PRE_CONNECT_ENABLED(ssk)) {
- - ]
4042 : 0 : err = ssk->sk_prot->pre_connect(ssk, uaddr, addr_len);
4043 [ - - ]: 0 : if (err)
4044 : 0 : goto out;
4045 : : }
4046 : :
4047 : 1718 : err = ssk->sk_prot->connect(ssk, uaddr, addr_len);
4048 [ - + ]: 1718 : if (err < 0)
4049 : 0 : goto out;
4050 : :
4051 [ + + ]: 1718 : inet_assign_bit(DEFER_CONNECT, sk, inet_test_bit(DEFER_CONNECT, ssk));
4052 : :
4053 : 1718 : out:
4054 [ + + ]: 1718 : if (!msk->fastopening)
4055 : 1648 : release_sock(ssk);
4056 : :
4057 : : /* on successful connect, the msk state will be moved to established by
4058 : : * subflow_finish_connect()
4059 : : */
4060 [ - + ]: 1718 : if (unlikely(err)) {
4061 : : /* avoid leaving a dangling token in an unconnected socket */
4062 : 0 : mptcp_token_destroy(msk);
4063 : 0 : mptcp_set_state(sk, TCP_CLOSE);
4064 : 0 : return err;
4065 : : }
4066 : :
4067 : 1718 : mptcp_copy_inaddrs(sk, ssk);
4068 : 1718 : return 0;
4069 : : }
4070 : :
4071 : : static struct proto mptcp_prot = {
4072 : : .name = "MPTCP",
4073 : : .owner = THIS_MODULE,
4074 : : .init = mptcp_init_sock,
4075 : : .connect = mptcp_connect,
4076 : : .disconnect = mptcp_disconnect,
4077 : : .close = mptcp_close,
4078 : : .setsockopt = mptcp_setsockopt,
4079 : : .getsockopt = mptcp_getsockopt,
4080 : : .shutdown = mptcp_shutdown,
4081 : : .destroy = mptcp_destroy,
4082 : : .sendmsg = mptcp_sendmsg,
4083 : : .ioctl = mptcp_ioctl,
4084 : : .recvmsg = mptcp_recvmsg,
4085 : : .release_cb = mptcp_release_cb,
4086 : : .hash = mptcp_hash,
4087 : : .unhash = mptcp_unhash,
4088 : : .get_port = mptcp_get_port,
4089 : : .stream_memory_free = mptcp_stream_memory_free,
4090 : : .sockets_allocated = &mptcp_sockets_allocated,
4091 : :
4092 : : .memory_allocated = &net_aligned_data.tcp_memory_allocated,
4093 : : .per_cpu_fw_alloc = &tcp_memory_per_cpu_fw_alloc,
4094 : :
4095 : : .memory_pressure = &tcp_memory_pressure,
4096 : : .sysctl_wmem_offset = offsetof(struct net, ipv4.sysctl_tcp_wmem),
4097 : : .sysctl_rmem_offset = offsetof(struct net, ipv4.sysctl_tcp_rmem),
4098 : : .sysctl_mem = sysctl_tcp_mem,
4099 : : .obj_size = sizeof(struct mptcp_sock),
4100 : : .slab_flags = SLAB_TYPESAFE_BY_RCU,
4101 : : .no_autobind = true,
4102 : : };
4103 : :
4104 : 1732 : static int mptcp_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int addr_len)
4105 : : {
4106 [ - + ]: 1732 : struct mptcp_sock *msk = mptcp_sk(sock->sk);
4107 : 1732 : struct sock *ssk, *sk = sock->sk;
4108 : 1732 : int err = -EINVAL;
4109 : :
4110 : 1732 : lock_sock(sk);
4111 : 1732 : ssk = __mptcp_nmpc_sk(msk);
4112 [ - + ]: 1732 : if (IS_ERR(ssk)) {
4113 : 0 : err = PTR_ERR(ssk);
4114 : 0 : goto unlock;
4115 : : }
4116 : :
4117 [ + + ]: 1732 : if (sk->sk_family == AF_INET)
4118 : 896 : err = inet_bind_sk(ssk, uaddr, addr_len);
4119 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
4120 [ + - ]: 836 : else if (sk->sk_family == AF_INET6)
4121 : 836 : err = inet6_bind_sk(ssk, uaddr, addr_len);
4122 : : #endif
4123 [ + + ]: 1732 : if (!err)
4124 : 1730 : mptcp_copy_inaddrs(sk, ssk);
4125 : :
4126 : 2 : unlock:
4127 : 1732 : release_sock(sk);
4128 : 1732 : return err;
4129 : : }
4130 : :
4131 : 1730 : static int mptcp_listen(struct socket *sock, int backlog)
4132 : : {
4133 [ - + ]: 1730 : struct mptcp_sock *msk = mptcp_sk(sock->sk);
4134 : 1730 : struct sock *sk = sock->sk;
4135 : 1730 : struct sock *ssk;
4136 : 1730 : int err;
4137 : :
4138 [ - + - - ]: 1730 : pr_debug("msk=%p\n", msk);
4139 : :
4140 : 1730 : lock_sock(sk);
4141 : :
4142 : 1730 : err = -EINVAL;
4143 [ + - - + ]: 1730 : if (sock->state != SS_UNCONNECTED || sock->type != SOCK_STREAM)
4144 : 0 : goto unlock;
4145 : :
4146 : 1730 : ssk = __mptcp_nmpc_sk(msk);
4147 [ - + ]: 1730 : if (IS_ERR(ssk)) {
4148 : 0 : err = PTR_ERR(ssk);
4149 : 0 : goto unlock;
4150 : : }
4151 : :
4152 : 1730 : mptcp_set_state(sk, TCP_LISTEN);
4153 : 1730 : sock_set_flag(sk, SOCK_RCU_FREE);
4154 : :
4155 : 1730 : lock_sock(ssk);
4156 : 1730 : err = __inet_listen_sk(ssk, backlog);
4157 : 1730 : release_sock(ssk);
4158 : 1730 : mptcp_set_state(sk, inet_sk_state_load(ssk));
4159 : :
4160 [ - + ]: 1730 : if (!err) {
4161 : 1730 : sock_prot_inuse_add(sock_net(sk), sk->sk_prot, 1);
4162 : 1730 : mptcp_copy_inaddrs(sk, ssk);
4163 : 1730 : mptcp_event_pm_listener(ssk, MPTCP_EVENT_LISTENER_CREATED);
4164 : : }
4165 : :
4166 : 0 : unlock:
4167 : 1730 : release_sock(sk);
4168 : 1730 : return err;
4169 : : }
4170 : :
4171 : 1574 : static void mptcp_graft_subflows(struct sock *sk)
4172 : : {
4173 : 1574 : struct mptcp_subflow_context *subflow;
4174 [ - + ]: 1574 : struct mptcp_sock *msk = mptcp_sk(sk);
4175 : :
4176 [ + + ]: 1574 : if (mem_cgroup_sockets_enabled) {
4177 : 6 : LIST_HEAD(join_list);
4178 : :
4179 : : /* Subflows joining after __inet_accept() will get the
4180 : : * mem CG properly initialized at mptcp_finish_join() time,
4181 : : * but subflows pending in join_list need explicit
4182 : : * initialization before flushing `backlog_unaccounted`
4183 : : * or MPTCP can later unexpectedly observe unaccounted memory.
4184 : : */
4185 : 6 : mptcp_data_lock(sk);
4186 [ - + ]: 6 : list_splice_init(&msk->join_list, &join_list);
4187 : 6 : mptcp_data_unlock(sk);
4188 : :
4189 : 6 : __mptcp_flush_join_list(sk, &join_list);
4190 : : }
4191 : :
4192 [ + + ]: 3200 : mptcp_for_each_subflow(msk, subflow) {
4193 : 1626 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
4194 : :
4195 : 1626 : lock_sock(ssk);
4196 : :
4197 : : /* Set ssk->sk_socket of accept()ed flows to mptcp socket.
4198 : : * This is needed so NOSPACE flag can be set from tcp stack.
4199 : : */
4200 [ + - ]: 1626 : if (!ssk->sk_socket)
4201 : 1626 : mptcp_sock_graft(ssk, sk->sk_socket);
4202 : :
4203 [ + + ]: 1626 : if (!mem_cgroup_sk_enabled(sk))
4204 : 1620 : goto unlock;
4205 : :
4206 : 6 : __mptcp_inherit_cgrp_data(sk, ssk);
4207 : 6 : __mptcp_inherit_memcg(sk, ssk, GFP_KERNEL);
4208 : :
4209 : 1626 : unlock:
4210 : 1626 : release_sock(ssk);
4211 : : }
4212 : :
4213 [ + + ]: 1574 : if (mem_cgroup_sk_enabled(sk)) {
4214 : 6 : gfp_t gfp = GFP_KERNEL | __GFP_NOFAIL;
4215 : 6 : int amt;
4216 : :
4217 : : /* Account the backlog memory; prior accept() is aware of
4218 : : * fwd and rmem only.
4219 : : */
4220 : 6 : mptcp_data_lock(sk);
4221 : 12 : amt = sk_mem_pages(sk->sk_forward_alloc +
4222 : 9 : msk->backlog_unaccounted +
4223 : 6 : atomic_read(&sk->sk_rmem_alloc)) -
4224 : 9 : sk_mem_pages(sk->sk_forward_alloc +
4225 : 6 : atomic_read(&sk->sk_rmem_alloc));
4226 : 6 : msk->backlog_unaccounted = 0;
4227 : 6 : mptcp_data_unlock(sk);
4228 : :
4229 [ - + ]: 6 : if (amt)
4230 : 0 : mem_cgroup_sk_charge(sk, amt, gfp);
4231 : : }
4232 : 1574 : }
4233 : :
4234 : 1758 : static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
4235 : : struct proto_accept_arg *arg)
4236 : : {
4237 [ - + ]: 1758 : struct mptcp_sock *msk = mptcp_sk(sock->sk);
4238 : 1758 : struct sock *ssk, *newsk;
4239 : :
4240 [ - + - - ]: 1758 : pr_debug("msk=%p\n", msk);
4241 : :
4242 : : /* Buggy applications can call accept on socket states other then LISTEN
4243 : : * but no need to allocate the first subflow just to error out.
4244 : : */
4245 : 1758 : ssk = READ_ONCE(msk->first);
4246 [ + - ]: 1758 : if (!ssk)
4247 : : return -EINVAL;
4248 : :
4249 [ - + - - ]: 1758 : pr_debug("ssk=%p, listener=%p\n", ssk, mptcp_subflow_ctx(ssk));
4250 : 1758 : newsk = inet_csk_accept(ssk, arg);
4251 [ + + ]: 1758 : if (!newsk)
4252 : 6 : return arg->err;
4253 : :
4254 [ - + - - : 1752 : pr_debug("newsk=%p, subflow is mptcp=%d\n", newsk, sk_is_mptcp(newsk));
- - ]
[ - + - - ]
4255 [ - + + + ]: 1752 : if (sk_is_mptcp(newsk)) {
[ + + ]
4256 : 1574 : struct mptcp_subflow_context *subflow;
4257 : 1574 : struct sock *new_mptcp_sock;
4258 : :
4259 [ - + ]: 1574 : subflow = mptcp_subflow_ctx(newsk);
4260 : 1574 : new_mptcp_sock = subflow->conn;
4261 : :
4262 : : /* is_mptcp should be false if subflow->conn is missing, see
4263 : : * subflow_syn_recv_sock()
4264 : : */
4265 [ - + ]: 1574 : if (WARN_ON_ONCE(!new_mptcp_sock)) {
4266 [ # # ]: 0 : tcp_sk(newsk)->is_mptcp = 0;
4267 : 0 : goto tcpfallback;
4268 : : }
4269 : :
4270 : 1574 : newsk = new_mptcp_sock;
4271 [ + - ]: 1574 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_MPCAPABLEPASSIVEACK);
4272 : :
4273 [ - + ]: 1574 : newsk->sk_kern_sock = arg->kern;
4274 : 1574 : lock_sock(newsk);
4275 : 1574 : __inet_accept(sock, newsock, newsk);
4276 : :
4277 : 1574 : set_bit(SOCK_CUSTOM_SOCKOPT, &newsock->flags);
4278 [ - + ]: 1574 : msk = mptcp_sk(newsk);
4279 : 1574 : msk->in_accept_queue = 0;
4280 : :
4281 : 1574 : mptcp_graft_subflows(newsk);
4282 : 1574 : mptcp_rps_record_subflows(msk);
4283 [ + + ]: 1574 : __mptcp_propagate_sndbuf(newsk, mptcp_subflow_tcp_sock(subflow));
4284 : :
4285 : : /* Do late cleanup for the first subflow as necessary. Also
4286 : : * deal with bad peers not doing a complete shutdown.
4287 : : */
4288 [ + + ]: 1574 : if (unlikely(inet_sk_state_load(msk->first) == TCP_CLOSE)) {
4289 [ + - ]: 6 : if (unlikely(list_is_singular(&msk->conn_list)))
4290 : 6 : mptcp_set_state(newsk, TCP_CLOSE);
4291 : 6 : mptcp_close_ssk(newsk, msk->first,
4292 : 6 : mptcp_subflow_ctx(msk->first));
4293 : : }
4294 : : } else {
4295 : 178 : tcpfallback:
4296 [ - + ]: 178 : newsk->sk_kern_sock = arg->kern;
4297 : 178 : lock_sock(newsk);
4298 : 178 : __inet_accept(sock, newsock, newsk);
4299 : : /* we are being invoked after accepting a non-mp-capable
4300 : : * flow: sk is a tcp_sk, not an mptcp one.
4301 : : *
4302 : : * Hand the socket over to tcp so all further socket ops
4303 : : * bypass mptcp.
4304 : : */
4305 : 178 : WRITE_ONCE(newsock->sk->sk_socket->ops,
4306 : : mptcp_fallback_tcp_ops(newsock->sk));
4307 : : }
4308 : 1752 : release_sock(newsk);
4309 : :
4310 : 1752 : return 0;
4311 : : }
4312 : :
4313 : 623484 : static __poll_t mptcp_check_writeable(struct mptcp_sock *msk)
4314 : : {
4315 : 623484 : struct sock *sk = (struct sock *)msk;
4316 : :
4317 [ + + ]: 623484 : if (__mptcp_stream_is_writeable(sk, 1))
4318 : : return EPOLLOUT | EPOLLWRNORM;
4319 : :
4320 : 204387 : set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
4321 : 204387 : smp_mb__after_atomic(); /* NOSPACE is changed by mptcp_write_space() */
4322 [ + + ]: 204387 : if (__mptcp_stream_is_writeable(sk, 1))
4323 : : return EPOLLOUT | EPOLLWRNORM;
4324 : :
4325 : : return 0;
4326 : : }
4327 : :
4328 : 1288433 : static __poll_t mptcp_poll(struct file *file, struct socket *sock,
4329 : : struct poll_table_struct *wait)
4330 : : {
4331 : 1288433 : struct sock *sk = sock->sk;
4332 : 1288433 : struct mptcp_sock *msk;
4333 : 1288433 : __poll_t mask = 0;
4334 : 1288433 : u8 shutdown;
4335 : 1288433 : int state;
4336 : :
4337 [ - + ]: 1288433 : msk = mptcp_sk(sk);
4338 : 1288433 : sock_poll_wait(file, sock, wait);
4339 : :
4340 : 1288433 : state = inet_sk_state_load(sk);
4341 [ - + - - ]: 1288433 : pr_debug("msk=%p state=%d flags=%lx\n", msk, state, msk->flags);
4342 [ + + ]: 1288433 : if (state == TCP_LISTEN) {
4343 : 2764 : struct sock *ssk = READ_ONCE(msk->first);
4344 : :
4345 [ - + ]: 2764 : if (WARN_ON_ONCE(!ssk))
4346 : 0 : return 0;
4347 : :
4348 [ + + ]: 4154 : return inet_csk_listen_poll(ssk);
4349 : : }
4350 : :
4351 : 1285669 : shutdown = READ_ONCE(sk->sk_shutdown);
4352 [ + + ]: 1285669 : if (shutdown == SHUTDOWN_MASK || state == TCP_CLOSE)
4353 : 2585 : mask |= EPOLLHUP;
4354 [ + + ]: 1285669 : if (shutdown & RCV_SHUTDOWN)
4355 : 248220 : mask |= EPOLLIN | EPOLLRDNORM | EPOLLRDHUP;
4356 : :
4357 [ + - ]: 1285669 : if (state != TCP_SYN_SENT && state != TCP_SYN_RECV) {
4358 : 1285669 : mask |= mptcp_check_readable(sk);
4359 [ + + ]: 1285669 : if (shutdown & SEND_SHUTDOWN)
4360 : 662185 : mask |= EPOLLOUT | EPOLLWRNORM;
4361 : : else
4362 : 623484 : mask |= mptcp_check_writeable(msk);
4363 [ # # # # ]: 0 : } else if (state == TCP_SYN_SENT &&
[ # # ]
4364 [ # # ]: 0 : inet_test_bit(DEFER_CONNECT, sk)) {
4365 : : /* cf tcp_poll() note about TFO */
4366 : 0 : mask |= EPOLLOUT | EPOLLWRNORM;
4367 : : }
4368 : :
4369 : : /* This barrier is coupled with smp_wmb() in __mptcp_error_report() */
4370 : 1285669 : smp_rmb();
4371 [ + + ]: 1285669 : if (READ_ONCE(sk->sk_err))
4372 : 10 : mask |= EPOLLERR;
4373 : :
4374 : : return mask;
4375 : : }
4376 : :
4377 : 707282 : static struct sk_buff *mptcp_recv_skb(struct sock *sk, u32 *off)
4378 : : {
4379 [ - + ]: 707282 : struct mptcp_sock *msk = mptcp_sk(sk);
4380 : 707282 : struct sk_buff *skb;
4381 : 707282 : u32 offset;
4382 : :
4383 [ + + ]: 707282 : if (!list_empty(&msk->backlog_list))
4384 : 880 : mptcp_move_skbs(sk);
4385 : :
4386 [ + + + - ]: 707282 : while ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) {
4387 : 166064 : offset = MPTCP_SKB_CB(skb)->offset;
4388 [ + - ]: 166064 : if (offset < skb->len) {
4389 : 166064 : *off = offset;
4390 : 166064 : return skb;
4391 : : }
4392 : 0 : mptcp_eat_recv_skb(sk, skb);
4393 : : }
4394 : : return NULL;
4395 : : }
4396 : :
4397 : : /*
4398 : : * Note:
4399 : : * - It is assumed that the socket was locked by the caller.
4400 : : */
4401 : 396674 : static int __mptcp_read_sock(struct sock *sk, read_descriptor_t *desc,
4402 : : sk_read_actor_t recv_actor, bool noack)
4403 : : {
4404 [ - + ]: 396674 : struct mptcp_sock *msk = mptcp_sk(sk);
4405 : 396674 : struct sk_buff *skb;
4406 : 396674 : int copied = 0;
4407 : 396674 : u32 offset;
4408 : :
4409 : 396674 : msk_owned_by_me(msk);
4410 : :
4411 [ + - ]: 396674 : if (sk->sk_state == TCP_LISTEN)
4412 : : return -ENOTCONN;
4413 [ + + ]: 551731 : while ((skb = mptcp_recv_skb(sk, &offset)) != NULL) {
4414 : 162048 : u32 data_len = skb->len - offset;
4415 : 162048 : int count;
4416 : 162048 : u32 size;
4417 : :
4418 : 162048 : size = min_t(size_t, data_len, INT_MAX);
4419 : 162048 : count = recv_actor(desc, skb, offset, size);
4420 [ + + ]: 162048 : if (count <= 0) {
4421 [ + + ]: 869 : if (!copied)
4422 : 837 : copied = count;
4423 : : break;
4424 : : }
4425 : :
4426 : 161179 : copied += count;
4427 : :
4428 : 161179 : msk->bytes_consumed += count;
4429 [ + + ]: 161179 : if (count < data_len) {
4430 : 3651 : MPTCP_SKB_CB(skb)->offset += count;
4431 : 3651 : MPTCP_SKB_CB(skb)->map_seq += count;
4432 : 3651 : break;
4433 : : }
4434 : :
4435 : 157528 : mptcp_eat_recv_skb(sk, skb);
4436 [ + + ]: 157528 : if (!desc->count)
4437 : : break;
4438 : : }
4439 : :
4440 [ - + ]: 396674 : if (noack)
4441 : 0 : goto out;
4442 : :
4443 : 396674 : mptcp_rcv_space_adjust(msk, copied);
4444 : :
4445 [ + + ]: 396674 : if (copied > 0) {
4446 : 155551 : mptcp_recv_skb(sk, &offset);
4447 : 155551 : mptcp_cleanup_rbuf(msk, copied);
4448 : : }
4449 : 241123 : out:
4450 : : return copied;
4451 : : }
4452 : :
4453 : 0 : static int mptcp_read_sock(struct sock *sk, read_descriptor_t *desc,
4454 : : sk_read_actor_t recv_actor)
4455 : : {
4456 : 0 : return __mptcp_read_sock(sk, desc, recv_actor, false);
4457 : : }
4458 : :
4459 : 396674 : static int __mptcp_splice_read(struct sock *sk, struct tcp_splice_state *tss)
4460 : : {
4461 : : /* Store TCP splice context information in read_descriptor_t. */
4462 : 396674 : read_descriptor_t rd_desc = {
4463 : : .arg.data = tss,
4464 : 396674 : .count = tss->len,
4465 : : };
4466 : :
4467 : 396674 : return mptcp_read_sock(sk, &rd_desc, tcp_splice_data_recv);
4468 : : }
4469 : :
4470 : : /**
4471 : : * mptcp_splice_read - splice data from MPTCP socket to a pipe
4472 : : * @sock: socket to splice from
4473 : : * @ppos: position (not valid)
4474 : : * @pipe: pipe to splice to
4475 : : * @len: number of bytes to splice
4476 : : * @flags: splice modifier flags
4477 : : *
4478 : : * Description:
4479 : : * Will read pages from given socket and fill them into a pipe.
4480 : : *
4481 : : * Return:
4482 : : * Amount of bytes that have been spliced.
4483 : : *
4484 : : **/
4485 : 145299 : static ssize_t mptcp_splice_read(struct socket *sock, loff_t *ppos,
4486 : : struct pipe_inode_info *pipe, size_t len,
4487 : : unsigned int flags)
4488 : : {
4489 : 145299 : struct tcp_splice_state tss = {
4490 : : .pipe = pipe,
4491 : : .len = len,
4492 : : .flags = flags,
4493 : : };
4494 : 145299 : struct sock *sk = sock->sk;
4495 : 145299 : ssize_t spliced = 0;
4496 : 145299 : int ret = 0;
4497 : 145299 : long timeo;
4498 : :
4499 : : /*
4500 : : * We can't seek on a socket input
4501 : : */
4502 [ + - ]: 145299 : if (unlikely(*ppos))
4503 : : return -ESPIPE;
4504 : :
4505 : 145299 : lock_sock(sk);
4506 : :
4507 [ - + ]: 145299 : mptcp_rps_record_subflows(mptcp_sk(sk));
4508 : :
4509 [ + - ]: 145299 : timeo = sock_rcvtimeo(sk, sock->file->f_flags & O_NONBLOCK);
4510 [ + - ]: 396674 : while (tss.len) {
4511 : 396674 : ret = __mptcp_splice_read(sk, &tss);
4512 [ + + ]: 396674 : if (ret < 0) {
4513 : : break;
4514 [ + + ]: 395837 : } else if (!ret) {
4515 [ + + ]: 240286 : if (spliced)
4516 : : break;
4517 [ + - ]: 101509 : if (sock_flag(sk, SOCK_DONE))
4518 : : break;
4519 [ - + ]: 101509 : if (sk->sk_err) {
4520 : 0 : ret = sock_error(sk);
4521 : 0 : break;
4522 : : }
4523 [ + + ]: 101509 : if (sk->sk_shutdown & RCV_SHUTDOWN)
4524 : : break;
4525 [ + - ]: 101269 : if (sk->sk_state == TCP_CLOSE) {
4526 : : /*
4527 : : * This occurs when user tries to read
4528 : : * from never connected socket.
4529 : : */
4530 : : ret = -ENOTCONN;
4531 : : break;
4532 : : }
4533 [ + - ]: 101269 : if (!timeo) {
4534 : : ret = -EAGAIN;
4535 : : break;
4536 : : }
4537 : : /* if __mptcp_splice_read() got nothing while we have
4538 : : * an skb in receive queue, we do not want to loop.
4539 : : * This might happen with URG data.
4540 : : */
4541 [ + - ]: 101269 : if (!skb_queue_empty(&sk->sk_receive_queue))
4542 : : break;
4543 : 101269 : ret = sk_wait_data(sk, &timeo, NULL);
4544 [ + - ]: 101269 : if (ret < 0)
4545 : : break;
4546 [ - + ]: 101269 : if (signal_pending(current)) {
4547 [ # # ]: 0 : ret = sock_intr_errno(timeo);
4548 : : break;
4549 : : }
4550 : 101269 : continue;
4551 : : }
4552 : 155551 : tss.len -= ret;
4553 : 155551 : spliced += ret;
4554 : :
4555 [ + + - + ]: 155551 : if (!tss.len || !timeo)
4556 : : break;
4557 : 150325 : release_sock(sk);
4558 : 150325 : lock_sock(sk);
4559 : :
4560 [ + + ]: 150325 : if (tcp_recv_should_stop(sk))
4561 : : break;
4562 : : }
4563 : :
4564 : 145299 : release_sock(sk);
4565 : :
4566 [ + + ]: 145299 : if (spliced)
4567 : : return spliced;
4568 : :
4569 : 240 : return ret;
4570 : : }
4571 : :
4572 : : static const struct proto_ops mptcp_stream_ops = {
4573 : : .family = PF_INET,
4574 : : .owner = THIS_MODULE,
4575 : : .release = inet_release,
4576 : : .bind = mptcp_bind,
4577 : : .connect = inet_stream_connect,
4578 : : .socketpair = sock_no_socketpair,
4579 : : .accept = mptcp_stream_accept,
4580 : : .getname = inet_getname,
4581 : : .poll = mptcp_poll,
4582 : : .ioctl = inet_ioctl,
4583 : : .gettstamp = sock_gettstamp,
4584 : : .listen = mptcp_listen,
4585 : : .shutdown = inet_shutdown,
4586 : : .setsockopt = sock_common_setsockopt,
4587 : : .getsockopt = sock_common_getsockopt,
4588 : : .sendmsg = inet_sendmsg,
4589 : : .recvmsg = inet_recvmsg,
4590 : : .mmap = sock_no_mmap,
4591 : : .set_rcvlowat = mptcp_set_rcvlowat,
4592 : : .read_sock = mptcp_read_sock,
4593 : : .splice_read = mptcp_splice_read,
4594 : : };
4595 : :
4596 : : static struct inet_protosw mptcp_protosw = {
4597 : : .type = SOCK_STREAM,
4598 : : .protocol = IPPROTO_MPTCP,
4599 : : .prot = &mptcp_prot,
4600 : : .ops = &mptcp_stream_ops,
4601 : : .flags = INET_PROTOSW_ICSK,
4602 : : };
4603 : :
4604 : 37342 : static int mptcp_napi_poll(struct napi_struct *napi, int budget)
4605 : : {
4606 : 37342 : struct mptcp_delegated_action *delegated;
4607 : 37342 : struct mptcp_subflow_context *subflow;
4608 : 37342 : int work_done = 0;
4609 : :
4610 : 37342 : delegated = container_of(napi, struct mptcp_delegated_action, napi);
4611 [ + + ]: 76195 : while ((subflow = mptcp_subflow_delegated_next(delegated)) != NULL) {
4612 : 38853 : struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
4613 : :
4614 : 38853 : bh_lock_sock_nested(ssk);
4615 [ + + ]: 38853 : if (!sock_owned_by_user(ssk)) {
4616 : 25480 : mptcp_subflow_process_delegated(ssk, xchg(&subflow->delegated_status, 0));
4617 : : } else {
4618 : : /* tcp_release_cb_override already processed
4619 : : * the action or will do at next release_sock().
4620 : : * In both case must dequeue the subflow here - on the same
4621 : : * CPU that scheduled it.
4622 : : */
4623 : 13373 : smp_wmb();
4624 : 13373 : clear_bit(MPTCP_DELEGATE_SCHEDULED, &subflow->delegated_status);
4625 : : }
4626 : 38853 : bh_unlock_sock(ssk);
4627 : 38853 : sock_put(ssk);
4628 : :
4629 [ + - ]: 38853 : if (++work_done == budget)
4630 : : return budget;
4631 : : }
4632 : :
4633 : : /* always provide a 0 'work_done' argument, so that napi_complete_done
4634 : : * will not try accessing the NULL napi->dev ptr
4635 : : */
4636 : 37342 : napi_complete_done(napi, 0);
4637 : 37342 : return work_done;
4638 : : }
4639 : :
4640 : 6 : void __init mptcp_proto_init(void)
4641 : : {
4642 : 6 : struct mptcp_delegated_action *delegated;
4643 : 6 : int cpu;
4644 : :
4645 : 6 : mptcp_prot.h.hashinfo = tcp_prot.h.hashinfo;
4646 : :
4647 [ - + ]: 6 : if (percpu_counter_init(&mptcp_sockets_allocated, 0, GFP_KERNEL))
4648 : 0 : panic("Failed to allocate MPTCP pcpu counter\n");
4649 : :
4650 : 6 : mptcp_napi_dev = alloc_netdev_dummy(0);
4651 [ - + ]: 6 : if (!mptcp_napi_dev)
4652 : 0 : panic("Failed to allocate MPTCP dummy netdev\n");
4653 [ + - + - ]: 54 : for_each_possible_cpu(cpu) {
4654 : 24 : delegated = per_cpu_ptr(&mptcp_delegated_actions, cpu);
4655 : 24 : INIT_LIST_HEAD(&delegated->head);
4656 : 24 : netif_napi_add_tx(mptcp_napi_dev, &delegated->napi,
4657 : : mptcp_napi_poll);
4658 : 24 : napi_enable(&delegated->napi);
4659 : : }
4660 : :
4661 : 6 : mptcp_subflow_init();
4662 : 6 : mptcp_pm_init();
4663 : 6 : mptcp_sched_init();
4664 : 6 : mptcp_token_init();
4665 : :
4666 [ - + ]: 6 : if (proto_register(&mptcp_prot, 1) != 0)
4667 : 0 : panic("Failed to register MPTCP proto.\n");
4668 : :
4669 : 6 : inet_register_protosw(&mptcp_protosw);
4670 : :
4671 : 6 : BUILD_BUG_ON(sizeof(struct mptcp_skb_cb) > sizeof_field(struct sk_buff, cb));
4672 : :
4673 : : /* struct mptcp_data_frag: 'overhead' corresponds to the alignment
4674 : : * (ALIGN(1, sizeof(long)) - 1, so 8-1) + the struct's size
4675 : : */
4676 : 6 : BUILD_BUG_ON(ALIGN(1, sizeof(long)) - 1 + sizeof(struct mptcp_data_frag)
4677 : : > U8_MAX);
4678 : 6 : }
4679 : :
4680 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
4681 : : static const struct proto_ops mptcp_v6_stream_ops = {
4682 : : .family = PF_INET6,
4683 : : .owner = THIS_MODULE,
4684 : : .release = inet6_release,
4685 : : .bind = mptcp_bind,
4686 : : .connect = inet_stream_connect,
4687 : : .socketpair = sock_no_socketpair,
4688 : : .accept = mptcp_stream_accept,
4689 : : .getname = inet6_getname,
4690 : : .poll = mptcp_poll,
4691 : : .ioctl = inet6_ioctl,
4692 : : .gettstamp = sock_gettstamp,
4693 : : .listen = mptcp_listen,
4694 : : .shutdown = inet_shutdown,
4695 : : .setsockopt = sock_common_setsockopt,
4696 : : .getsockopt = sock_common_getsockopt,
4697 : : .sendmsg = inet6_sendmsg,
4698 : : .recvmsg = inet6_recvmsg,
4699 : : .mmap = sock_no_mmap,
4700 : : #ifdef CONFIG_COMPAT
4701 : : .compat_ioctl = inet6_compat_ioctl,
4702 : : #endif
4703 : : .set_rcvlowat = mptcp_set_rcvlowat,
4704 : : .read_sock = mptcp_read_sock,
4705 : : .splice_read = mptcp_splice_read,
4706 : : };
4707 : :
4708 : : static struct proto mptcp_v6_prot;
4709 : :
4710 : : static struct inet_protosw mptcp_v6_protosw = {
4711 : : .type = SOCK_STREAM,
4712 : : .protocol = IPPROTO_MPTCP,
4713 : : .prot = &mptcp_v6_prot,
4714 : : .ops = &mptcp_v6_stream_ops,
4715 : : .flags = INET_PROTOSW_ICSK,
4716 : : };
4717 : :
4718 : 6 : int __init mptcp_proto_v6_init(void)
4719 : : {
4720 : 6 : int err;
4721 : :
4722 : 6 : mptcp_subflow_v6_init();
4723 : :
4724 : 6 : mptcp_v6_prot = mptcp_prot;
4725 : 6 : strscpy(mptcp_v6_prot.name, "MPTCPv6", sizeof(mptcp_v6_prot.name));
4726 : 6 : mptcp_v6_prot.slab = NULL;
4727 : 6 : mptcp_v6_prot.obj_size = sizeof(struct mptcp6_sock);
4728 : 6 : mptcp_v6_prot.ipv6_pinfo_offset = offsetof(struct mptcp6_sock, np);
4729 : :
4730 : 6 : err = proto_register(&mptcp_v6_prot, 1);
4731 [ + - ]: 6 : if (err)
4732 : : return err;
4733 : :
4734 : 6 : err = inet6_register_protosw(&mptcp_v6_protosw);
4735 [ - + ]: 6 : if (err)
4736 : 0 : proto_unregister(&mptcp_v6_prot);
4737 : :
4738 : : return err;
4739 : : }
4740 : : #endif
|