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 <crypto/sha2.h>
13 : : #include <crypto/utils.h>
14 : : #include <net/sock.h>
15 : : #include <net/inet_common.h>
16 : : #include <net/inet_hashtables.h>
17 : : #include <net/protocol.h>
18 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
19 : : #include <net/ip6_route.h>
20 : : #include <net/transp_v6.h>
21 : : #endif
22 : : #include <net/mptcp.h>
23 : :
24 : : #include "protocol.h"
25 : : #include "mib.h"
26 : :
27 : : #include <trace/events/mptcp.h>
28 : : #include <trace/events/sock.h>
29 : :
30 : : static void mptcp_subflow_ops_undo_override(struct sock *ssk);
31 : :
32 : 0 : static void SUBFLOW_REQ_INC_STATS(struct request_sock *req,
33 : : enum linux_mptcp_mib_field field)
34 : : {
35 [ - - - - : 78 : MPTCP_INC_STATS(sock_net(req_to_sk(req)), field);
- - - - -
- - - - -
- - - ]
36 : : }
37 : :
38 : 2648 : static void subflow_req_destructor(struct request_sock *req)
39 : : {
40 : 2648 : struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
41 : :
42 [ - - ]: 2648 : pr_debug("subflow_req=%p\n", subflow_req);
43 : :
44 [ + ]: 2648 : if (subflow_req->msk)
45 : 48 : sock_put((struct sock *)subflow_req->msk);
46 : :
47 : 2648 : mptcp_token_destroy_request(req);
48 : 2648 : }
49 : :
50 : 12 : void mptcp_subflow_reqsk_clone(struct request_sock *req,
51 : : struct request_sock *new_req)
52 : : {
53 : 12 : struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
54 : 12 : struct mptcp_subflow_request_sock *new_subflow_req;
55 : 12 : struct mptcp_sock *msk;
56 : :
57 : 12 : new_subflow_req = mptcp_subflow_rsk(new_req);
58 [ - + - - : 12 : RCU_LOCKDEP_WARN(!rcu_read_lock_any_held(),
- ]
59 : : "MPTCP reqsk clone called without RCU");
60 : :
61 : : /* A non-NULL ->msk means the request owns one reference. The clone
62 : : * copied only the pointer, while the original request can concurrently
63 : : * transfer its reference to the child. Acquire a reference for the
64 : : * clone, then verify that the original request still owns the same msk.
65 : : * MPTCP sockets use SLAB_TYPESAFE_BY_RCU and all clone callers run in
66 : : * an RCU read-side critical section, keeping the memory stable here.
67 : : */
68 : 12 : msk = READ_ONCE(subflow_req->msk);
69 [ + ][ + ]: 12 : if (msk) {
70 : 6 : struct sock *sk = (struct sock *)msk;
71 : :
72 [ - ][ - ]: 6 : if (!refcount_inc_not_zero_acquire(&sk->sk_refcnt)) {
73 : : msk = NULL;
74 [ + ][ + ]: 6 : } else if (READ_ONCE(subflow_req->msk) != msk) {
75 : 0 : sock_put(sk);
76 : 0 : msk = NULL;
77 : : }
78 : : }
79 : :
80 : 12 : new_subflow_req->msk = msk;
81 : :
82 : 12 : mptcp_token_move_request(req, new_req);
83 : 12 : }
84 : :
85 : 2586 : static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2,
86 : : void *hmac)
87 : : {
88 : 2586 : u8 msg[8];
89 : :
90 : 2586 : put_unaligned_be32(nonce1, &msg[0]);
91 : 2586 : put_unaligned_be32(nonce2, &msg[4]);
92 : :
93 : 2586 : mptcp_crypto_hmac_sha(key1, key2, msg, 8, hmac);
94 : 2586 : }
95 : :
96 : 678 : static bool mptcp_can_accept_new_subflow(const struct mptcp_sock *msk)
97 : : {
98 [ - + ][ - + ]: 678 : return mptcp_is_fully_established((void *)msk) &&
[ - ][ - ]
99 [ + ][ + ]: 68 : ((mptcp_pm_is_userspace(msk) &&
[ + - ][ + - ]
100 : 26 : mptcp_userspace_pm_active(msk)) ||
101 [ + + ][ + ]: 656 : READ_ONCE(msk->pm.accept_subflow));
102 : : }
103 : :
104 : : /* validate received token and create truncated hmac and nonce for SYN-ACK */
105 : 670 : static void subflow_req_create_thmac(struct mptcp_subflow_request_sock *subflow_req)
106 : : {
107 : 670 : struct mptcp_sock *msk = subflow_req->msk;
108 : 670 : u8 hmac[SHA256_DIGEST_SIZE];
109 : :
110 : 670 : subflow_req->local_nonce = get_random_u32();
111 : :
112 : 670 : subflow_generate_hmac(READ_ONCE(msk->local_key),
113 : 670 : READ_ONCE(msk->remote_key),
114 : : subflow_req->local_nonce,
115 : : subflow_req->remote_nonce, hmac);
116 : :
117 : 670 : subflow_req->thmac = get_unaligned_be64(hmac);
118 : 670 : }
119 : :
120 : 676 : static struct mptcp_sock *subflow_token_join_request(struct request_sock *req)
121 : : {
122 : 676 : struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
123 : 676 : struct mptcp_sock *msk;
124 : 676 : int local_id;
125 : :
126 : 676 : msk = mptcp_token_get_sock(sock_net(req_to_sk(req)), subflow_req->token);
127 [ + ][ + ]: 676 : if (!msk) {
128 [ - ]: 6 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINNOTOKEN);
129 : 6 : return NULL;
130 : : }
131 : :
132 : 670 : local_id = mptcp_pm_get_local_id(msk, (struct sock_common *)req);
133 [ + ][ + ]: 670 : if (local_id < 0) {
134 [ # ]: 0 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_MPJOINNOIDFOUND);
135 : 0 : sock_put((struct sock *)msk);
136 : 0 : return NULL;
137 : : }
138 : 670 : subflow_req->local_id = local_id;
139 : 670 : subflow_req->request_bkup = mptcp_pm_is_backup(msk, (struct sock_common *)req);
140 : :
141 : 670 : return msk;
142 : : }
143 : :
144 : 2636 : static void subflow_init_req(struct request_sock *req, const struct sock *sk_listener)
145 : : {
146 : 2636 : struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
147 : :
148 : 2636 : subflow_req->mp_capable = 0;
149 : 2636 : subflow_req->mp_join = 0;
150 : 2636 : subflow_req->csum_reqd = mptcp_is_checksum_enabled(sock_net(sk_listener));
151 : 2636 : subflow_req->allow_join_id0 = mptcp_allow_join_id0(sock_net(sk_listener));
152 : 2636 : subflow_req->msk = NULL;
153 : 2636 : mptcp_token_init_request(req);
154 : :
155 : : /* read by tcp_check_req() even after migration to a TCP listener */
156 : 2636 : tcp_rsk(req)->drop_req = false;
157 : 2636 : }
158 : :
159 : 84 : static bool subflow_use_different_sport(struct mptcp_sock *msk, const struct sock *sk)
160 : : {
161 : 1318 : return inet_sk(sk)->inet_sport != inet_sk((struct sock *)msk)->inet_sport;
162 : : }
163 : :
164 : 18 : static void subflow_add_reset_reason(struct sk_buff *skb, u8 reason)
165 : : {
166 : 18 : struct mptcp_ext *mpext = skb_ext_add(skb, SKB_EXT_MPTCP);
167 : :
168 [ - ]: 18 : if (mpext) {
169 : 18 : memset(mpext, 0, sizeof(*mpext));
170 : 18 : mpext->reset_reason = reason;
171 : : }
172 : 18 : }
173 : :
174 : 2 : static int subflow_reset_req_endp(struct request_sock *req, struct sk_buff *skb)
175 : : {
176 [ - ]: 2 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_MPCAPABLEENDPATTEMPT);
177 : 2 : subflow_add_reset_reason(skb, MPTCP_RST_EPROHIBIT);
178 : 2 : return -EPERM;
179 : : }
180 : :
181 : : /* Init mptcp request socket.
182 : : *
183 : : * Returns an error code if a JOIN has failed and a TCP reset
184 : : * should be sent.
185 : : */
186 : 2564 : static int subflow_check_req(struct request_sock *req,
187 : : const struct sock *sk_listener,
188 : : struct sk_buff *skb)
189 : : {
190 [ - ]: 2564 : struct mptcp_subflow_context *listener = mptcp_subflow_ctx(sk_listener);
191 : 2564 : struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
192 : 2564 : struct mptcp_options_received mp_opt;
193 : 2564 : bool opt_mp_capable, opt_mp_join;
194 : :
195 [ - - ]: 2564 : pr_debug("subflow_req=%p, listener=%p\n", subflow_req, listener);
196 : :
197 : : #ifdef CONFIG_TCP_MD5SIG
198 : : /* no MPTCP if MD5SIG is enabled on this socket or we may run out of
199 : : * TCP option space.
200 : : */
201 : : if (rcu_access_pointer(tcp_sk(sk_listener)->md5sig_info)) {
202 : : MPTCP_INC_STATS(sock_net(sk_listener), MPTCP_MIB_MD5SIGRESET);
203 : : subflow_add_reset_reason(skb, MPTCP_RST_EMPTCP);
204 : : return -EINVAL;
205 : : }
206 : : #endif
207 : :
208 : 2564 : mptcp_get_options(skb, &mp_opt);
209 : :
210 : 2564 : opt_mp_capable = !!(mp_opt.suboptions & OPTION_MPTCP_MPC_SYN);
211 : 2564 : opt_mp_join = !!(mp_opt.suboptions & OPTION_MPTCP_MPJ_SYN);
212 [ + ][ + ]: 2564 : if (opt_mp_capable) {
213 [ - ]: 1728 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_MPCAPABLEPASSIVE);
214 : :
215 [ + + ][ + ]: 1728 : if (unlikely(listener->pm_listener))
216 : 2 : return subflow_reset_req_endp(req, skb);
217 [ + ][ + ]: 836 : } else if (opt_mp_join) {
218 [ - ]: 676 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINSYNRX);
219 : :
220 [ + ][ + ]: 676 : if (mp_opt.backup)
221 [ - ]: 42 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINSYNBACKUPRX);
222 [ + + ][ + ]: 160 : } else if (unlikely(listener->pm_listener)) {
223 : 0 : return subflow_reset_req_endp(req, skb);
224 : : }
225 : :
226 [ + - ][ + - ]: 2562 : if (opt_mp_capable && listener->request_mptcp) {
227 : 1726 : int err, retries = MPTCP_TOKEN_MAX_RETRIES;
228 : :
229 : 1726 : subflow_req->ssn_offset = TCP_SKB_CB(skb)->seq;
230 : : again:
231 : 1726 : do {
232 : 1726 : get_random_bytes(&subflow_req->local_key, sizeof(subflow_req->local_key));
233 [ - ][ - ]: 1726 : } while (subflow_req->local_key == 0);
234 : :
235 [ + ][ + ]: 1726 : if (unlikely(req->syncookie)) {
236 : 52 : mptcp_crypto_key_sha(subflow_req->local_key,
237 : : &subflow_req->token,
238 : : &subflow_req->idsn);
239 [ + ][ + ]: 52 : if (mptcp_token_exists(subflow_req->token)) {
240 [ # ][ # ]: 0 : if (retries-- > 0)
241 : 0 : goto again;
242 [ # ]: 0 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_TOKENFALLBACKINIT);
243 : : } else {
244 : 52 : subflow_req->mp_capable = 1;
245 : : }
246 : 52 : return 0;
247 : : }
248 : :
249 : 1674 : err = mptcp_token_new_request(req);
250 [ - ][ - ]: 1674 : if (err == 0)
251 : 1674 : subflow_req->mp_capable = 1;
252 [ # ][ # ]: 0 : else if (retries-- > 0)
253 : 0 : goto again;
254 : : else
255 [ # ]: 0 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_TOKENFALLBACKINIT);
256 : :
257 [ + - ][ + - ]: 836 : } else if (opt_mp_join && listener->request_mptcp) {
258 : 676 : subflow_req->ssn_offset = TCP_SKB_CB(skb)->seq;
259 : 676 : subflow_req->mp_join = 1;
260 : 676 : subflow_req->backup = mp_opt.backup;
261 : 676 : subflow_req->remote_id = mp_opt.join_id;
262 : 676 : subflow_req->token = mp_opt.token;
263 : 676 : subflow_req->remote_nonce = mp_opt.nonce;
264 : 676 : subflow_req->msk = subflow_token_join_request(req);
265 : :
266 : : /* Can't fall back to TCP in this case. */
267 [ + ][ + ]: 676 : if (!subflow_req->msk) {
268 : 6 : subflow_add_reset_reason(skb, MPTCP_RST_EMPTCP);
269 : 6 : return -EPERM;
270 : : }
271 : :
272 [ + ][ + ]: 670 : if (subflow_use_different_sport(subflow_req->msk, sk_listener)) {
273 [ - - ][ - - ]: 26 : pr_debug("syn inet_sport=%d %d\n",
274 : : ntohs(inet_sk(sk_listener)->inet_sport),
275 : : ntohs(inet_sk((struct sock *)subflow_req->msk)->inet_sport));
276 [ + ][ + ]: 26 : if (!mptcp_pm_announced_has_ssk(subflow_req->msk, sk_listener)) {
277 [ # ]: 0 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_MISMATCHPORTSYNRX);
278 : 0 : subflow_add_reset_reason(skb, MPTCP_RST_EPROHIBIT);
279 : 0 : return -EPERM;
280 : : }
281 [ - ]: 26 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINPORTSYNRX);
282 : : }
283 : :
284 : 670 : subflow_req_create_thmac(subflow_req);
285 : :
286 [ + ][ + ]: 670 : if (unlikely(req->syncookie)) {
287 [ + ][ + ]: 22 : if (!mptcp_can_accept_new_subflow(subflow_req->msk)) {
288 [ - ]: 2 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINREJECTED);
289 : 2 : subflow_add_reset_reason(skb, MPTCP_RST_EPROHIBIT);
290 : 2 : return -EPERM;
291 : : }
292 : :
293 : 20 : subflow_init_req_cookie_join_save(subflow_req, skb);
294 : : }
295 : :
296 [ - - ][ - - ]: 668 : pr_debug("token=%u, remote_nonce=%u msk=%p\n", subflow_req->token,
297 : : subflow_req->remote_nonce, subflow_req->msk);
298 : : }
299 : :
300 : : return 0;
301 : : }
302 : :
303 : 72 : int mptcp_subflow_init_cookie_req(struct request_sock *req,
304 : : const struct sock *sk_listener,
305 : : struct sk_buff *skb)
306 : : {
307 : 72 : struct mptcp_subflow_context *listener = mptcp_subflow_ctx(sk_listener);
308 : 72 : struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
309 : 72 : struct mptcp_options_received mp_opt;
310 : 72 : bool opt_mp_capable, opt_mp_join;
311 : 72 : int err;
312 : :
313 : 72 : subflow_init_req(req, sk_listener);
314 : 72 : mptcp_get_options(skb, &mp_opt);
315 : :
316 : 72 : opt_mp_capable = !!(mp_opt.suboptions & OPTION_MPTCP_MPC_ACK);
317 : 72 : opt_mp_join = !!(mp_opt.suboptions & OPTION_MPTCP_MPJ_ACK);
318 : :
319 : : /* PM listeners only take MP_JOIN, like in subflow_check_req() */
320 [ + + - ]: 72 : if (unlikely(listener->pm_listener) && !opt_mp_join)
[ + - ]
321 : 0 : return subflow_reset_req_endp(req, skb);
322 : :
323 [ + - ][ + - ]: 72 : if (opt_mp_capable && listener->request_mptcp) {
324 [ - ][ - ]: 52 : if (mp_opt.sndr_key == 0)
325 : : return -EINVAL;
326 : :
327 : 52 : subflow_req->local_key = mp_opt.rcvr_key;
328 : 52 : err = mptcp_token_new_request(req);
329 [ - ][ - ]: 52 : if (err)
330 : : return err;
331 : :
332 : 52 : subflow_req->mp_capable = 1;
333 : 52 : subflow_req->ssn_offset = TCP_SKB_CB(skb)->seq - 1;
334 [ + - ][ + - ]: 20 : } else if (opt_mp_join && listener->request_mptcp) {
335 [ - ][ - ]: 20 : if (!mptcp_token_join_cookie_init_state(subflow_req, skb))
336 : : return -EINVAL;
337 : :
338 : 20 : subflow_req->mp_join = 1;
339 : 20 : subflow_req->ssn_offset = TCP_SKB_CB(skb)->seq - 1;
340 : : }
341 : :
342 : : return 0;
343 : : }
344 : : EXPORT_SYMBOL_GPL(mptcp_subflow_init_cookie_req);
345 : :
346 : 16 : static enum sk_rst_reason mptcp_get_rst_reason(const struct sk_buff *skb)
347 : : {
348 [ - ]: 16 : const struct mptcp_ext *mpext = mptcp_get_ext(skb);
349 : :
350 [ - ]: 16 : if (!mpext)
351 : : return SK_RST_REASON_NOT_SPECIFIED;
352 : :
353 [ - ]: 16 : return sk_rst_convert_mptcp_reason(mpext->reset_reason);
354 : : }
355 : :
356 : 1980 : static struct dst_entry *subflow_v4_route_req(const struct sock *sk,
357 : : struct sk_buff *skb,
358 : : struct flowi *fl,
359 : : struct request_sock *req,
360 : : u32 tw_isn)
361 : : {
362 : 1980 : struct dst_entry *dst;
363 : 1980 : int err;
364 : :
365 : 1980 : tcp_rsk(req)->is_mptcp = 1;
366 : 1980 : subflow_init_req(req, sk);
367 : :
368 : 1980 : dst = tcp_request_sock_ipv4_ops.route_req(sk, skb, fl, req, tw_isn);
369 [ + ]: 1980 : if (!dst)
370 : : return NULL;
371 : :
372 : 1980 : err = subflow_check_req(req, sk, skb);
373 [ + ][ + ]: 1980 : if (err == 0)
374 : : return dst;
375 : :
376 : 8 : dst_release(dst);
377 [ + ]: 8 : if (!req->syncookie)
378 : 6 : tcp_request_sock_ops.send_reset(sk, skb,
379 : : mptcp_get_rst_reason(skb));
380 : : return NULL;
381 : : }
382 : :
383 : 2556 : static void subflow_prep_synack(const struct sock *sk, struct request_sock *req,
384 : : struct tcp_fastopen_cookie *foc,
385 : : enum tcp_synack_type synack_type)
386 : : {
387 [ + ]: 2556 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
388 : 2556 : struct inet_request_sock *ireq = inet_rsk(req);
389 : :
390 : : /* MP_JOIN cannot use TFO, do not send a cookie in the SYN/ACK */
391 [ + + ]: 2556 : if (foc && mptcp_subflow_rsk(req)->mp_join)
392 : 668 : foc->len = -1;
393 : :
394 : : /* clear tstamp_ok, as needed depending on cookie */
395 [ + ]: 2554 : if (foc && foc->len > -1)
396 : 38 : ireq->tstamp_ok = 0;
397 : :
398 [ + ]: 2556 : if (synack_type == TCP_SYNACK_FASTOPEN)
399 : 56 : mptcp_fastopen_subflow_synack_set_params(subflow, req);
400 : 2556 : }
401 : :
402 : 1972 : static int subflow_v4_send_synack(const struct sock *sk, struct dst_entry *dst,
403 : : struct flowi *fl,
404 : : struct request_sock *req,
405 : : struct tcp_fastopen_cookie *foc,
406 : : enum tcp_synack_type synack_type,
407 : : struct sk_buff *syn_skb)
408 : : {
409 : 1972 : subflow_prep_synack(sk, req, foc, synack_type);
410 : :
411 : 1972 : return tcp_request_sock_ipv4_ops.send_synack(sk, dst, fl, req, foc,
412 : : synack_type, syn_skb);
413 : : }
414 : :
415 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
416 : 584 : static int subflow_v6_send_synack(const struct sock *sk, struct dst_entry *dst,
417 : : struct flowi *fl,
418 : : struct request_sock *req,
419 : : struct tcp_fastopen_cookie *foc,
420 : : enum tcp_synack_type synack_type,
421 : : struct sk_buff *syn_skb)
422 : : {
423 : 584 : subflow_prep_synack(sk, req, foc, synack_type);
424 : :
425 : 584 : return tcp_request_sock_ipv6_ops.send_synack(sk, dst, fl, req, foc,
426 : : synack_type, syn_skb);
427 : : }
428 : :
429 : 584 : static struct dst_entry *subflow_v6_route_req(const struct sock *sk,
430 : : struct sk_buff *skb,
431 : : struct flowi *fl,
432 : : struct request_sock *req,
433 : : u32 tw_isn)
434 : : {
435 : 584 : struct dst_entry *dst;
436 : 584 : int err;
437 : :
438 : 584 : tcp_rsk(req)->is_mptcp = 1;
439 : 584 : subflow_init_req(req, sk);
440 : :
441 : 584 : dst = tcp_request_sock_ipv6_ops.route_req(sk, skb, fl, req, tw_isn);
442 [ + ]: 584 : if (!dst)
443 : : return NULL;
444 : :
445 : 584 : err = subflow_check_req(req, sk, skb);
446 [ + ][ + ]: 584 : if (err == 0)
447 : : return dst;
448 : :
449 : 2 : dst_release(dst);
450 [ - ]: 2 : if (!req->syncookie)
451 : 2 : tcp6_request_sock_ops.send_reset(sk, skb,
452 : : mptcp_get_rst_reason(skb));
453 : : return NULL;
454 : : }
455 : : #endif
456 : :
457 : : /* validate received truncated hmac and create hmac for third ACK */
458 : 630 : static bool subflow_thmac_valid(struct mptcp_subflow_context *subflow,
459 : : u64 thmac)
460 : : {
461 : 630 : u8 hmac[SHA256_DIGEST_SIZE];
462 : 630 : u64 expected_thmac;
463 : :
464 : 630 : subflow_generate_hmac(subflow->remote_key, subflow->local_key,
465 : : subflow->remote_nonce, subflow->local_nonce,
466 : : hmac);
467 : :
468 [ - ]: 630 : expected_thmac = get_unaligned_be64(hmac);
469 [ - - ]: 630 : pr_debug("subflow=%p, token=%u, expected_thmac=%llu, thmac=%llu\n",
470 : : subflow, subflow->token, expected_thmac, thmac);
471 : :
472 : 630 : return expected_thmac == thmac;
473 : : }
474 : :
475 : 10 : void mptcp_subflow_reset(struct sock *ssk)
476 : : {
477 [ - ][ - ]: 10 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
478 : 10 : struct sock *sk = subflow->conn;
479 : :
480 : : /* mptcp_mp_fail_no_response() can reach here on an already closed
481 : : * socket
482 : : */
483 [ - ][ - ]: 10 : if (ssk->sk_state == TCP_CLOSE)
484 : : return;
485 : :
486 : : /* must hold: tcp_done() could drop last reference on parent */
487 : 10 : sock_hold(sk);
488 : :
489 : 10 : subflow->resetting = 1;
490 : :
491 : : /* No need to delay the actual close for to-be discarded data. */
492 : 10 : __skb_queue_purge(&ssk->sk_receive_queue);
493 : 10 : mptcp_send_active_reset_reason(ssk);
494 : 10 : tcp_done(ssk);
495 [ + - ][ + - ]: 15 : if (!test_and_set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &mptcp_sk(sk)->flags))
496 : 10 : mptcp_schedule_work(sk);
497 : :
498 : 10 : sock_put(sk);
499 : : }
500 : :
501 : 42 : static bool subflow_use_different_dport(struct mptcp_sock *msk, const struct sock *sk)
502 : : {
503 : 630 : return inet_sk(sk)->inet_dport != inet_sk((struct sock *)msk)->inet_dport;
504 : : }
505 : :
506 : 1700 : void __mptcp_sync_state(struct sock *sk, int state)
507 : : {
508 : 1700 : struct mptcp_subflow_context *subflow;
509 [ + ]: 1700 : struct mptcp_sock *msk = mptcp_sk(sk);
510 : 1700 : struct sock *ssk = msk->first;
511 : :
512 [ + ]: 1700 : subflow = mptcp_subflow_ctx(ssk);
513 [ + ]: 1700 : __mptcp_propagate_sndbuf(sk, ssk);
514 : :
515 [ - ]: 1700 : if (sk->sk_state == TCP_SYN_SENT) {
516 : : /* subflow->idsn is always available is TCP_SYN_SENT state,
517 : : * even for the FASTOPEN scenarios
518 : : */
519 : 1700 : WRITE_ONCE(msk->write_seq, subflow->idsn + 1);
520 : 1700 : WRITE_ONCE(msk->snd_nxt, msk->write_seq);
521 : 1700 : mptcp_set_state(sk, state);
522 : 1700 : sk->sk_state_change(sk);
523 : : }
524 : 1700 : }
525 : :
526 : 5274 : static void subflow_set_remote_key(struct mptcp_sock *msk,
527 : : struct mptcp_subflow_context *subflow,
528 : : const struct mptcp_options_received *mp_opt)
529 : : {
530 : : /* active MPC subflow will reach here multiple times:
531 : : * at subflow_finish_connect() time and at 4th ack time
532 : : */
533 [ + ][ + ]: 5274 : if (subflow->remote_key_valid)
534 : : return;
535 : :
536 : 3204 : subflow->remote_key_valid = 1;
537 : 3204 : subflow->remote_key = mp_opt->sndr_key;
538 : 3204 : mptcp_crypto_key_sha(subflow->remote_key, NULL, &subflow->iasn);
539 : 3204 : subflow->iasn++;
540 : :
541 : : /* for fallback's sake */
542 : 3204 : subflow->map_seq = subflow->iasn;
543 : 3204 : subflow->dsn_base = subflow->iasn;
544 : 3204 : subflow->dsn_end = subflow->iasn;
545 : :
546 : 3204 : WRITE_ONCE(msk->remote_key, subflow->remote_key);
547 : 3204 : WRITE_ONCE(msk->ack_seq, subflow->iasn);
548 : 3204 : WRITE_ONCE(msk->can_ack, true);
549 : 3204 : atomic64_set(&msk->rcv_wnd_sent, subflow->iasn);
550 : : }
551 : :
552 : 1700 : static void mptcp_propagate_state(struct sock *sk, struct sock *ssk,
553 : : struct mptcp_subflow_context *subflow,
554 : : const struct mptcp_options_received *mp_opt)
555 : : {
556 [ + ]: 1700 : struct mptcp_sock *msk = mptcp_sk(sk);
557 : :
558 : 1700 : mptcp_data_lock(sk);
559 [ + ]: 1700 : if (mp_opt) {
560 : : /* Options are available only in the non fallback cases
561 : : * avoid updating rx path fields otherwise
562 : : */
563 : 1520 : WRITE_ONCE(msk->snd_una, subflow->idsn + 1);
564 [ + ]: 1520 : WRITE_ONCE(msk->wnd_end, subflow->idsn + 1 + tcp_sk(ssk)->snd_wnd);
565 : 1520 : subflow_set_remote_key(msk, subflow, mp_opt);
566 : : }
567 : :
568 [ + ][ + ]: 1700 : if (!sock_owned_by_user(sk)) {
569 : 476 : __mptcp_sync_state(sk, ssk->sk_state);
570 : : } else {
571 : 1224 : msk->pending_state = ssk->sk_state;
572 [ + - - ]: 1224 : __set_bit(MPTCP_SYNC_STATE, &msk->cb_flags);
[ + - - ]
573 : : }
574 : 1700 : mptcp_data_unlock(sk);
575 : 1700 : }
576 : :
577 : 50105 : static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)
578 : : {
579 : 50105 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
580 : 50105 : struct mptcp_options_received mp_opt;
581 : 50105 : struct sock *parent = subflow->conn;
582 : 50105 : struct mptcp_sock *msk;
583 : :
584 : 50105 : subflow->icsk_af_ops->sk_rx_dst_set(sk, skb);
585 : :
586 : : /* be sure no special action on any packet other than syn-ack */
587 [ + ][ + ]: 50105 : if (subflow->conn_finished)
588 : 50103 : return;
589 : :
590 [ + ]: 2332 : msk = mptcp_sk(parent);
591 : 2332 : subflow->rel_write_seq = 1;
592 [ + ]: 2332 : subflow->opt_ack_seq = tcp_sk(sk)->snd_una;
593 : 2332 : subflow->conn_finished = 1;
594 : 2332 : subflow->ssn_offset = TCP_SKB_CB(skb)->seq;
595 [ - - ]: 2332 : pr_debug("subflow=%p synack seq=%x\n", subflow, subflow->ssn_offset);
596 : :
597 : 2332 : mptcp_get_options(skb, &mp_opt);
598 [ + ][ + ]: 2332 : if (subflow->request_mptcp) {
599 [ + ][ + ]: 1670 : if (!(mp_opt.suboptions & OPTION_MPTCP_MPC_SYNACK)) {
600 [ + ][ + ]: 150 : if (!mptcp_try_fallback(sk,
601 : : MPTCP_MIB_MPCAPABLEACTIVEFALLBACK)) {
602 [ # ][ # ]: 0 : MPTCP_INC_STATS(sock_net(sk),
603 : : MPTCP_MIB_FALLBACKFAILED);
604 : 0 : goto do_reset;
605 : : }
606 : :
607 : 150 : goto fallback;
608 : : }
609 : :
610 [ + ][ + ]: 1520 : if (mp_opt.suboptions & OPTION_MPTCP_CSUMREQD)
611 : 116 : WRITE_ONCE(msk->csum_enabled, true);
612 [ + ][ + ]: 1520 : if (mp_opt.deny_join_id0)
613 : 8 : WRITE_ONCE(msk->pm.remote_deny_join_id0, true);
614 : 1520 : subflow->mp_capable = 1;
615 [ - ][ - ]: 1520 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPCAPABLEACTIVEACK);
616 : 1520 : mptcp_finish_connect(sk);
617 : 1520 : mptcp_active_enable(parent);
618 : 1520 : mptcp_propagate_state(parent, sk, subflow, &mp_opt);
619 [ + ][ + ]: 662 : } else if (subflow->request_join) {
620 : 632 : u8 hmac[SHA256_DIGEST_SIZE];
621 : :
622 [ + ][ + ]: 632 : if (!(mp_opt.suboptions & OPTION_MPTCP_MPJ_SYNACK)) {
623 [ - ][ # ]: 2 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPJOINSYNACKNOMPJOIN);
624 : 2 : subflow->reset_reason = MPTCP_RST_EMPTCP;
625 : 2 : goto do_reset;
626 : : }
627 : :
628 : 630 : subflow->backup = mp_opt.backup;
629 : 630 : subflow->remote_nonce = mp_opt.nonce;
630 : 630 : WRITE_ONCE(subflow->remote_id, mp_opt.join_id);
631 [ - - ][ - - ]: 630 : pr_debug("subflow=%p, thmac=%llu, remote_nonce=%u backup=%d\n",
632 : : subflow, mp_opt.thmac, subflow->remote_nonce,
633 : : subflow->backup);
634 : :
635 [ + ][ + ]: 630 : if (!subflow_thmac_valid(subflow, mp_opt.thmac)) {
636 [ # ][ # ]: 0 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_JOINSYNACKMAC);
637 : 0 : subflow->reset_reason = MPTCP_RST_EMPTCP;
638 : 0 : goto do_reset;
639 : : }
640 : :
641 [ + ][ + ]: 630 : if (!mptcp_finish_join(sk))
642 : 0 : goto do_reset;
643 : :
644 : 630 : subflow_generate_hmac(subflow->local_key, subflow->remote_key,
645 : : subflow->local_nonce,
646 : : subflow->remote_nonce,
647 : : hmac);
648 : 630 : memcpy(subflow->hmac, hmac, MPTCPOPT_HMAC_LEN);
649 : :
650 : 630 : subflow->mp_join = 1;
651 [ - ][ - ]: 630 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_JOINSYNACKRX);
652 : :
653 [ + ][ + ]: 630 : if (subflow->backup)
654 [ - ][ # ]: 30 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_JOINSYNACKBACKUPRX);
655 : :
656 [ + ][ + ]: 630 : if (subflow_use_different_dport(msk, sk)) {
657 [ - - ][ - - ]: 26 : pr_debug("synack inet_dport=%d %d\n",
658 : : ntohs(inet_sk(sk)->inet_dport),
659 : : ntohs(inet_sk(parent)->inet_dport));
660 [ - ][ - ]: 68 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_JOINPORTSYNACKRX);
661 : : }
662 [ - ][ - ]: 30 : } else if (mptcp_check_fallback(sk)) {
663 : : /* It looks like MPTCP is blocked, while TCP is not */
664 [ + ][ + ]: 30 : if (subflow->mpc_drop)
665 : 18 : mptcp_active_disable(parent);
666 : 12 : fallback:
667 : 180 : mptcp_propagate_state(parent, sk, subflow, NULL);
668 : : }
669 : : return;
670 : :
671 : 2 : do_reset:
672 : 2 : subflow->reset_transient = 0;
673 : 2 : mptcp_subflow_reset(sk);
674 : : }
675 : :
676 : 1507 : static void subflow_set_local_id(struct mptcp_subflow_context *subflow, int local_id)
677 : : {
678 [ + ]: 1435 : WARN_ON_ONCE(local_id < 0 || local_id > 255);
679 : 3149 : WRITE_ONCE(subflow->local_id, local_id);
680 : 3149 : }
681 : :
682 : 11912 : static int subflow_chk_local_id(struct sock *sk)
683 : : {
684 [ + ]: 11912 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
685 [ + ]: 11912 : struct mptcp_sock *msk = mptcp_sk(subflow->conn);
686 : 11912 : int err;
687 : :
688 [ + ]: 11912 : if (likely(subflow->local_id >= 0))
689 : : return 0;
690 : :
691 : 323 : err = mptcp_pm_get_local_id(msk, (struct sock_common *)sk);
692 [ - ]: 323 : if (err < 0)
693 : : return err;
694 : :
695 : 323 : subflow_set_local_id(subflow, err);
696 : 323 : subflow->request_bkup = mptcp_pm_is_backup(msk, (struct sock_common *)sk);
697 : :
698 : 323 : return 0;
699 : : }
700 : :
701 : 8810 : static int subflow_rebuild_header(struct sock *sk)
702 : : {
703 : 8810 : int err = subflow_chk_local_id(sk);
704 : :
705 [ - ]: 8810 : if (unlikely(err < 0))
706 : : return err;
707 : :
708 : 8810 : return inet_sk_rebuild_header(sk);
709 : : }
710 : :
711 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
712 : 3102 : static int subflow_v6_rebuild_header(struct sock *sk)
713 : : {
714 : 3102 : int err = subflow_chk_local_id(sk);
715 : :
716 [ - ]: 3102 : if (unlikely(err < 0))
717 : : return err;
718 : :
719 : 3102 : return inet6_sk_rebuild_header(sk);
720 : : }
721 : : #endif
722 : :
723 : : static struct request_sock_ops mptcp_subflow_v4_request_sock_ops __ro_after_init;
724 : : static struct tcp_request_sock_ops subflow_request_sock_ipv4_ops __ro_after_init;
725 : :
726 : 1980 : static int subflow_v4_conn_request(struct sock *sk, struct sk_buff *skb)
727 : : {
728 [ - ]: 1980 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
729 : :
730 [ - - ]: 1980 : pr_debug("subflow=%p\n", subflow);
731 : :
732 : : /* Never answer to SYNs sent to broadcast or multicast */
733 [ + ][ + ]: 1980 : if (skb_rtable(skb)->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST))
734 : 0 : goto drop;
735 : :
736 : 1980 : return tcp_conn_request(&mptcp_subflow_v4_request_sock_ops,
737 : : &subflow_request_sock_ipv4_ops,
738 : : sk, skb);
739 : 0 : drop:
740 : 0 : tcp_listendrop(sk);
741 : 0 : return 0;
742 : : }
743 : :
744 : 2040 : static void subflow_v4_req_destructor(struct request_sock *req)
745 : : {
746 : 2040 : subflow_req_destructor(req);
747 : 2040 : tcp_request_sock_ops.destructor(req);
748 : 2040 : }
749 : :
750 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
751 : : static struct request_sock_ops mptcp_subflow_v6_request_sock_ops __ro_after_init;
752 : : static struct tcp_request_sock_ops subflow_request_sock_ipv6_ops __ro_after_init;
753 : : static struct inet_connection_sock_af_ops subflow_v6_specific __ro_after_init;
754 : : static struct inet_connection_sock_af_ops subflow_v6m_specific __ro_after_init;
755 : : static struct proto tcpv6_prot_override __ro_after_init;
756 : :
757 : 1446 : static int subflow_v6_conn_request(struct sock *sk, struct sk_buff *skb)
758 : : {
759 [ - ]: 1446 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
760 : :
761 [ - - ]: 1446 : pr_debug("subflow=%p\n", subflow);
762 : :
763 [ + ]: 1446 : if (skb->protocol == htons(ETH_P_IP))
764 : 862 : return subflow_v4_conn_request(sk, skb);
765 : :
766 [ + ][ + ]: 584 : if (!ipv6_unicast_destination(skb))
767 : 0 : goto drop;
768 : :
769 [ + ][ + ]: 584 : if (ipv6_addr_v4mapped(&ipv6_hdr(skb)->saddr)) {
770 : 0 : __IP6_INC_STATS(sock_net(sk), NULL, IPSTATS_MIB_INHDRERRORS);
771 : 0 : return 0;
772 : : }
773 : :
774 : 584 : return tcp_conn_request(&mptcp_subflow_v6_request_sock_ops,
775 : : &subflow_request_sock_ipv6_ops, sk, skb);
776 : :
777 : 0 : drop:
778 : 0 : tcp_listendrop(sk);
779 : 0 : return 0; /* don't send reset */
780 : : }
781 : :
782 : 608 : static void subflow_v6_req_destructor(struct request_sock *req)
783 : : {
784 : 608 : subflow_req_destructor(req);
785 : 608 : tcp6_request_sock_ops.destructor(req);
786 : 608 : }
787 : : #endif
788 : :
789 : 72 : struct request_sock *mptcp_subflow_reqsk_alloc(const struct request_sock_ops *ops,
790 : : struct sock *sk_listener,
791 : : bool attach_listener)
792 : : {
793 [ + ]: 72 : if (ops->family == AF_INET)
794 : : ops = &mptcp_subflow_v4_request_sock_ops;
795 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
796 [ - ]: 20 : else if (ops->family == AF_INET6)
797 : 20 : ops = &mptcp_subflow_v6_request_sock_ops;
798 : : #endif
799 : :
800 : 72 : return inet_reqsk_alloc(ops, sk_listener, attach_listener);
801 : : }
802 : : EXPORT_SYMBOL(mptcp_subflow_reqsk_alloc);
803 : :
804 : : /* validate hmac received in third ACK */
805 : 656 : static bool subflow_hmac_valid(const struct mptcp_subflow_request_sock *subflow_req,
806 : : const struct mptcp_options_received *mp_opt)
807 : : {
808 : 656 : struct mptcp_sock *msk = subflow_req->msk;
809 : 656 : u8 hmac[SHA256_DIGEST_SIZE];
810 : :
811 : 656 : subflow_generate_hmac(READ_ONCE(msk->remote_key),
812 : 656 : READ_ONCE(msk->local_key),
813 : 656 : subflow_req->remote_nonce,
814 : 656 : subflow_req->local_nonce, hmac);
815 : :
816 : 656 : return !crypto_memneq(hmac, mp_opt->hmac, MPTCPOPT_HMAC_LEN);
817 : : }
818 : :
819 : 228 : static void subflow_ulp_fallback(struct sock *sk,
820 : : struct mptcp_subflow_context *old_ctx)
821 : : {
822 : 228 : struct inet_connection_sock *icsk = inet_csk(sk);
823 : :
824 [ + ]: 228 : mptcp_subflow_tcp_fallback(sk, old_ctx);
825 : 228 : icsk->icsk_ulp_ops = NULL;
826 : 228 : rcu_assign_pointer(icsk->icsk_ulp_data, NULL);
827 [ + ]: 228 : tcp_sk(sk)->is_mptcp = 0;
828 : :
829 : 264 : mptcp_subflow_ops_undo_override(sk);
830 : 228 : }
831 : :
832 : 228 : void mptcp_subflow_drop_ctx(struct sock *ssk)
833 : : {
834 [ + ][ + ]: 228 : struct mptcp_subflow_context *ctx = mptcp_subflow_ctx(ssk);
835 : :
836 [ + ][ + ]: 228 : if (!ctx)
837 : : return;
838 : :
839 [ - ]: 68 : list_del(&mptcp_subflow_ctx(ssk)->node);
840 [ - ][ - ]: 68 : if (inet_csk(ssk)->icsk_ulp_ops) {
841 : 68 : subflow_ulp_fallback(ssk, ctx);
842 [ + ][ + ]: 68 : if (ctx->conn)
843 : 42 : sock_put(ctx->conn);
844 : : }
845 : :
846 : 68 : mptcp_subflow_free_ctx(ctx);
847 : : }
848 : :
849 : 3754 : void __mptcp_subflow_fully_established(struct mptcp_sock *msk,
850 : : struct mptcp_subflow_context *subflow,
851 : : const struct mptcp_options_received *mp_opt)
852 : : {
853 : 3754 : subflow_set_remote_key(msk, subflow, mp_opt);
854 : 3754 : WRITE_ONCE(subflow->fully_established, true);
855 : 3754 : WRITE_ONCE(msk->fully_established, true);
856 : 3754 : }
857 : :
858 : : /* Children of a kernel listener need a netns ref for their timers */
859 : 2530 : static bool subflow_child_get_net(struct sock *child)
860 : : {
861 [ + ]: 2530 : struct net *net = sock_net(child);
862 : :
863 [ + ][ + ]: 2530 : if (likely(child->sk_net_refcnt))
864 : : return true;
865 : :
866 [ - ][ - ]: 22 : if (!maybe_get_net(net))
867 : : return false;
868 : :
869 : 22 : __sk_net_refcnt_upgrade(child, GFP_ATOMIC);
870 : 22 : put_net(net);
871 : 22 : return true;
872 : : }
873 : :
874 : 2530 : static struct sock *subflow_syn_recv_sock(const struct sock *sk,
875 : : struct sk_buff *skb,
876 : : struct request_sock *req,
877 : : struct dst_entry *dst,
878 : : struct request_sock *req_unhash,
879 : : bool *own_req,
880 : : void (*opt_child_init)(struct sock *newsk,
881 : : const struct sock *sk))
882 : : {
883 [ - ]: 2530 : struct mptcp_subflow_context *listener = mptcp_subflow_ctx(sk);
884 : 2530 : struct mptcp_subflow_request_sock *subflow_req;
885 : 2530 : struct mptcp_options_received mp_opt;
886 : 2530 : bool fallback, fallback_is_fatal;
887 : 2530 : enum sk_rst_reason reason;
888 : 2530 : struct mptcp_sock *owner;
889 : 2530 : struct sock *child;
890 : :
891 [ - - ]: 2530 : pr_debug("listener=%p, req=%p, conn=%p\n", listener, req, listener->conn);
892 : :
893 : : /* After child creation we must look for MPC even when options
894 : : * are not parsed
895 : : */
896 : 2530 : mp_opt.suboptions = 0;
897 : :
898 : : /* hopefully temporary handling for MP_JOIN+syncookie */
899 : 2530 : subflow_req = mptcp_subflow_rsk(req);
900 [ + - + ]: 2530 : fallback_is_fatal = tcp_rsk(req)->is_mptcp && subflow_req->mp_join;
[ - + ]
901 [ + ]: 2530 : fallback = !tcp_rsk(req)->is_mptcp;
902 [ + ][ + ]: 2530 : if (fallback)
903 : 0 : goto create_child;
904 : :
905 : : /* if the sk is MP_CAPABLE, we try to fetch the client key */
906 [ + ][ + ]: 2530 : if (subflow_req->mp_capable) {
907 : : /* we can receive and accept an in-window, out-of-order pkt,
908 : : * which may not carry the MP_CAPABLE opt even on mptcp enabled
909 : : * paths: always try to extract the peer key, and fallback
910 : : * for packets missing it.
911 : : * Even OoO DSS packets coming legitly after dropped or
912 : : * reordered MPC will cause fallback, but we don't have other
913 : : * options.
914 : : */
915 : 1714 : mptcp_get_options(skb, &mp_opt);
916 [ + + ][ + + ]: 1714 : if (!(mp_opt.suboptions &
917 : : (OPTION_MPTCP_MPC_SYN | OPTION_MPTCP_MPC_ACK)))
918 : 0 : fallback = true;
919 : :
920 [ + ][ + ]: 816 : } else if (subflow_req->mp_join) {
921 : : /* a SYN skb here comes from TFO, which MP_JOIN cannot use: just
922 : : * fall back to the regular path.
923 : : */
924 [ - ][ - ]: 656 : if ((TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_SYN | TCPHDR_ACK)) ==
925 : : TCPHDR_SYN)
926 : : return NULL;
927 : :
928 : 656 : mptcp_get_options(skb, &mp_opt);
929 [ - ][ - ]: 656 : if (!(mp_opt.suboptions & OPTION_MPTCP_MPJ_ACK))
930 : 0 : fallback = true;
931 : : }
932 : :
933 : 322 : create_child:
934 : 2530 : child = listener->icsk_af_ops->syn_recv_sock(sk, skb, req, dst,
935 : : req_unhash, own_req, opt_child_init);
936 : :
937 [ - + - ]: 2530 : if (child && *own_req) {
[ - - ]
938 : 2530 : struct mptcp_subflow_context *ctx = mptcp_subflow_ctx(child);
939 : :
940 : 2530 : tcp_rsk(req)->drop_req = false;
941 : :
942 [ + ][ + ]: 2530 : if (!subflow_child_get_net(child)) {
943 : 0 : subflow_add_reset_reason(skb, MPTCP_RST_EUNSPEC);
944 : 0 : goto dispose_child;
945 : : }
946 : :
947 : : /* we need to fallback on ctx allocation failure and on pre-reqs
948 : : * checking above. In the latter scenario we additionally need
949 : : * to reset the context to non MPTCP status.
950 : : */
951 [ + ][ + ]: 2530 : if (!ctx || fallback) {
952 [ + ][ + ]: 178 : if (fallback_is_fatal) {
953 [ # ][ # ]: 0 : if (!ctx)
954 [ # ][ # ]: 0 : MPTCP_INC_STATS(sock_net(sk),
955 : : MPTCP_MIB_MPJOINACKNOCTX);
956 : : else
957 [ # ][ # ]: 0 : MPTCP_INC_STATS(sock_net(sk),
958 : : MPTCP_MIB_MPJOINACKNOMPJOIN);
959 : 0 : subflow_add_reset_reason(skb, MPTCP_RST_EMPTCP);
960 : 0 : goto dispose_child;
961 : : }
962 : 178 : goto fallback;
963 : : }
964 : :
965 : : /* ssk inherits options of listener sk */
966 : 2352 : ctx->setsockopt_seq = listener->setsockopt_seq;
967 : :
968 [ + ][ + ]: 2352 : if (ctx->mp_capable) {
969 : 1696 : ctx->conn = mptcp_sk_clone_init(listener->conn, &mp_opt, child, req);
970 [ + ][ + ]: 1696 : if (!ctx->conn) {
971 : 0 : fallback = true;
972 : 0 : goto fallback;
973 : : }
974 : :
975 : 1696 : ctx->subflow_id = 1;
976 [ + ][ + ]: 1696 : owner = mptcp_sk(ctx->conn);
977 : :
978 [ + ][ + ]: 1696 : if (mp_opt.deny_join_id0)
979 : 10 : WRITE_ONCE(owner->pm.remote_deny_join_id0, true);
980 : :
981 : 1696 : mptcp_pm_new_connection(owner, child, 1);
982 : :
983 : : /* with OoO packets we can reach here without ingress
984 : : * mpc option
985 : : */
986 [ + ][ + ]: 1696 : if (mp_opt.suboptions & OPTION_MPTCP_MPC_ACK) {
987 : 1640 : mptcp_pm_fully_established(owner, child);
988 : 1640 : ctx->pm_notified = 1;
989 : : }
990 [ - ][ - ]: 656 : } else if (ctx->mp_join) {
991 : 656 : owner = subflow_req->msk;
992 [ + ][ + ]: 656 : if (!owner) {
993 : 0 : subflow_add_reset_reason(skb, MPTCP_RST_EPROHIBIT);
994 : 0 : goto dispose_child;
995 : : }
996 : :
997 [ + ][ + ]: 656 : if (!subflow_hmac_valid(subflow_req, &mp_opt)) {
998 [ # ]: 0 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINACKMAC);
999 : 0 : subflow_add_reset_reason(skb, MPTCP_RST_EMPTCP);
1000 : 0 : goto dispose_child;
1001 : : }
1002 : :
1003 [ + ][ + ]: 656 : if (!mptcp_can_accept_new_subflow(owner)) {
1004 [ - ]: 8 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINREJECTED);
1005 : 8 : subflow_add_reset_reason(skb, MPTCP_RST_EPROHIBIT);
1006 : 8 : goto dispose_child;
1007 : : }
1008 : :
1009 : : /* move the msk reference ownership to the subflow */
1010 : 648 : WRITE_ONCE(subflow_req->msk, NULL);
1011 : 648 : ctx->conn = (struct sock *)owner;
1012 : :
1013 [ + ][ + ]: 648 : if (subflow_use_different_sport(owner, sk)) {
1014 [ - - ][ - - ]: 26 : pr_debug("ack inet_sport=%d %d\n",
1015 : : ntohs(inet_sk(sk)->inet_sport),
1016 : : ntohs(inet_sk((struct sock *)owner)->inet_sport));
1017 [ + ][ + ]: 26 : if (!mptcp_pm_announced_has_ssk(owner, sk)) {
1018 [ # ]: 0 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_MISMATCHPORTACKRX);
1019 : 0 : subflow_add_reset_reason(skb, MPTCP_RST_EPROHIBIT);
1020 : 0 : goto dispose_child;
1021 : : }
1022 [ - ]: 26 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINPORTACKRX);
1023 : : }
1024 : :
1025 [ + ][ + ]: 648 : if (!mptcp_finish_join(child)) {
1026 : 0 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(child);
1027 : :
1028 : 0 : subflow_add_reset_reason(skb, subflow->reset_reason);
1029 : 0 : goto dispose_child;
1030 : : }
1031 : :
1032 [ - ]: 648 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_JOINACKRX);
1033 : 648 : tcp_rsk(req)->drop_req = true;
1034 : : }
1035 : : }
1036 : :
1037 : : /* check for expected invariant - should never trigger, just help
1038 : : * catching earlier subtle bugs
1039 : : */
1040 [ + - + + : 2344 : WARN_ON_ONCE(child && *own_req && tcp_sk(child)->is_mptcp &&
- - + ][ -
+ - - + ]
1041 : : (!mptcp_subflow_ctx(child) ||
1042 : : !mptcp_subflow_ctx(child)->conn));
1043 : 2344 : return child;
1044 : :
1045 : 8 : dispose_child:
1046 : 8 : mptcp_subflow_drop_ctx(child);
1047 : 8 : tcp_rsk(req)->drop_req = true;
1048 : 8 : inet_csk_prepare_for_destroy_sock(child);
1049 : 8 : tcp_done(child);
1050 : 8 : reason = mptcp_get_rst_reason(skb);
1051 : 8 : req->rsk_ops->send_reset(sk, skb, reason);
1052 : :
1053 : : /* The last child reference will be released by the caller */
1054 : 8 : return child;
1055 : :
1056 : 12 : fallback:
1057 [ + + ][ + + ]: 178 : if (fallback)
1058 [ - ]: 18 : SUBFLOW_REQ_INC_STATS(req, MPTCP_MIB_MPCAPABLEPASSIVEFALLBACK);
1059 : 178 : mptcp_subflow_drop_ctx(child);
1060 : 178 : return child;
1061 : : }
1062 : :
1063 : : static struct inet_connection_sock_af_ops subflow_specific __ro_after_init;
1064 : : static struct proto tcp_prot_override __ro_after_init;
1065 : :
1066 : : enum mapping_status {
1067 : : MAPPING_OK,
1068 : : MAPPING_INVALID,
1069 : : MAPPING_EMPTY,
1070 : : MAPPING_DATA_FIN,
1071 : : MAPPING_DUMMY,
1072 : : MAPPING_BAD_CSUM,
1073 : : MAPPING_NODSS
1074 : : };
1075 : :
1076 : 0 : static void dbg_bad_map(struct mptcp_subflow_context *subflow, u32 ssn)
1077 : : {
1078 [ # # ]: 0 : pr_debug("Bad mapping: ssn=%d map_seq=%d map_data_len=%d\n",
1079 : : ssn, subflow->map_subflow_seq, subflow->map_data_len);
1080 : 0 : }
1081 : :
1082 : 0 : static bool skb_is_fully_mapped(struct sock *ssk, struct sk_buff *skb)
1083 : : {
1084 [ # ]: 0 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1085 : 0 : unsigned int skb_consumed;
1086 : :
1087 [ # ]: 0 : skb_consumed = tcp_sk(ssk)->copied_seq - TCP_SKB_CB(skb)->seq;
1088 [ # ]: 0 : if (unlikely(skb_consumed >= skb->len)) {
1089 : 0 : DEBUG_NET_WARN_ON_ONCE(1);
1090 : 0 : return true;
1091 : : }
1092 : :
1093 : 0 : return skb->len - skb_consumed <= subflow->map_data_len -
1094 : 0 : mptcp_subflow_get_map_offset(subflow);
1095 : : }
1096 : :
1097 : 808441 : static bool validate_mapping(struct sock *ssk, struct sk_buff *skb)
1098 : : {
1099 [ + ]: 808441 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1100 [ + ]: 808441 : u32 ssn = tcp_sk(ssk)->copied_seq - subflow->ssn_offset;
1101 : :
1102 [ + ]: 808441 : if (unlikely(before(ssn, subflow->map_subflow_seq))) {
1103 : : /* Mapping covers data later in the subflow stream,
1104 : : * currently unsupported.
1105 : : */
1106 : 0 : dbg_bad_map(subflow, ssn);
1107 : 0 : return false;
1108 : : }
1109 [ + ]: 808441 : if (unlikely(!before(ssn, subflow->map_subflow_seq +
1110 : : subflow->map_data_len))) {
1111 : : /* Mapping does covers past subflow data, invalid */
1112 : 0 : dbg_bad_map(subflow, ssn);
1113 : 0 : return false;
1114 : : }
1115 : : return true;
1116 : : }
1117 : :
1118 : 1624901 : static enum mapping_status validate_data_csum(struct sock *ssk, struct sk_buff *skb,
1119 : : bool csum_reqd)
1120 : : {
1121 [ + ]: 1624901 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1122 : 1624901 : u32 offset, seq, delta;
1123 : 1624901 : __sum16 csum;
1124 : 1624901 : int len;
1125 : :
1126 [ + ]: 1624901 : if (!csum_reqd)
1127 : : return MAPPING_OK;
1128 : :
1129 : : /* mapping already validated on previous traversal */
1130 [ + ]: 274072 : if (subflow->map_csum_len == subflow->map_data_len)
1131 : : return MAPPING_OK;
1132 : :
1133 : : /* traverse the receive queue, ensuring it contains a full
1134 : : * DSS mapping and accumulating the related csum.
1135 : : * Preserve the accoumlate csum across multiple calls, to compute
1136 : : * the csum only once
1137 : : */
1138 : 274063 : delta = subflow->map_data_len - subflow->map_csum_len;
1139 : 493550 : for (;;) {
1140 [ + ]: 493550 : seq = tcp_sk(ssk)->copied_seq + subflow->map_csum_len;
1141 : 493550 : offset = seq - TCP_SKB_CB(skb)->seq;
1142 : :
1143 : : /* if the current skb has not been accounted yet, csum its contents
1144 : : * up to the amount covered by the current DSS
1145 : : */
1146 [ + ]: 493550 : if (offset < skb->len) {
1147 : 274578 : __wsum csum;
1148 : :
1149 : 274578 : len = min(skb->len - offset, delta);
1150 : 274578 : csum = skb_checksum(skb, offset, len, 0);
1151 : 549156 : subflow->map_data_csum = csum_block_add(subflow->map_data_csum, csum,
1152 [ + ]: 274578 : subflow->map_csum_len);
1153 : :
1154 : 274578 : delta -= len;
1155 : 274578 : subflow->map_csum_len += len;
1156 : : }
1157 [ + ]: 493550 : if (delta == 0)
1158 : : break;
1159 : :
1160 [ + ]: 394250 : if (skb_queue_is_last(&ssk->sk_receive_queue, skb)) {
1161 : : /* if this subflow is closed, the partial mapping
1162 : : * will be never completed; flush the pending skbs, so
1163 : : * that subflow_sched_work_if_closed() can kick in
1164 : : */
1165 [ - + ]: 174763 : if (unlikely(ssk->sk_state == TCP_CLOSE))
1166 [ # # ]: 0 : while ((skb = skb_peek(&ssk->sk_receive_queue)))
1167 : 0 : sk_eat_skb(ssk, skb);
1168 : :
1169 : : /* not enough data to validate the csum */
1170 : 174763 : return MAPPING_EMPTY;
1171 : : }
1172 : :
1173 : : /* the DSS mapping for next skbs will be validated later,
1174 : : * when a get_mapping_status call will process such skb
1175 : : */
1176 : : skb = skb->next;
1177 : : }
1178 : :
1179 : : /* note that 'map_data_len' accounts only for the carried data, does
1180 : : * not include the eventual seq increment due to the data fin,
1181 : : * while the pseudo header requires the original DSS data len,
1182 : : * including that
1183 : : */
1184 : 99300 : csum = __mptcp_make_csum(subflow->map_seq,
1185 : : subflow->map_subflow_seq,
1186 : 99300 : subflow->map_data_len + subflow->map_data_fin,
1187 : : subflow->map_data_csum);
1188 [ + ][ + ]: 99300 : if (unlikely(csum)) {
1189 [ - ][ # ]: 4 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_DATACSUMERR);
1190 : 4 : return MAPPING_BAD_CSUM;
1191 : : }
1192 : :
1193 : 99296 : subflow->valid_csum_seen = 1;
1194 : 99296 : return MAPPING_OK;
1195 : : }
1196 : :
1197 : 3106740 : static enum mapping_status get_mapping_status(struct sock *ssk,
1198 : : struct mptcp_sock *msk)
1199 : : {
1200 [ + ]: 3106740 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1201 [ + ]: 3106740 : bool csum_reqd = READ_ONCE(msk->csum_enabled);
1202 : 3106740 : struct mptcp_ext *mpext;
1203 : 3106740 : struct sk_buff *skb;
1204 : 3106740 : u16 data_len;
1205 : 3106740 : u64 map_seq;
1206 : :
1207 [ + ][ + ]: 3106818 : skb = skb_peek(&ssk->sk_receive_queue);
1208 [ + ][ + ]: 1643041 : if (!skb)
1209 : : return MAPPING_EMPTY;
1210 : :
1211 [ + ][ + ]: 1643041 : if (mptcp_check_fallback(ssk))
1212 : : return MAPPING_DUMMY;
1213 : :
1214 [ + ]: 1627515 : mpext = mptcp_get_ext(skb);
1215 [ + + ][ - + ]: 1550529 : if (!mpext || !mpext->use_map) {
1216 [ + + ][ + + ]: 178266 : if (!subflow->map_valid && !skb->len) {
1217 : : /* the TCP stack deliver 0 len FIN pkt to the receive
1218 : : * queue, that is the only 0len pkts ever expected here,
1219 : : * and we can admit no mapping only for 0 len pkts
1220 : : */
1221 [ + ][ + ]: 2582 : if (!(TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN))
1222 : 0 : WARN_ONCE(1, "0len seq %d:%d flags %x",
1223 : : TCP_SKB_CB(skb)->seq,
1224 : : TCP_SKB_CB(skb)->end_seq,
1225 : : TCP_SKB_CB(skb)->tcp_flags);
1226 : 2582 : sk_eat_skb(ssk, skb);
1227 : 2582 : return MAPPING_EMPTY;
1228 : : }
1229 : :
1230 : : /* If the required DSS has likely been dropped by a middlebox */
1231 [ + ][ + ]: 175684 : if (!subflow->map_valid)
1232 : : return MAPPING_NODSS;
1233 : :
1234 : 175666 : goto validate_seq;
1235 : : }
1236 : :
1237 : 1449249 : trace_get_mapping_status(mpext);
1238 : :
1239 : 1449249 : data_len = mpext->data_len;
1240 [ + ][ + ]: 1449249 : if (data_len == 0) {
1241 [ - - ][ - - ]: 2 : pr_debug("infinite mapping received\n");
1242 [ - ][ # ]: 2 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_INFINITEMAPRX);
1243 : 2 : return MAPPING_INVALID;
1244 : : }
1245 : :
1246 [ + ][ + ]: 1449247 : if (mpext->data_fin == 1) {
1247 : 2063 : u64 data_fin_seq;
1248 : :
1249 [ + ][ + ]: 2063 : if (data_len == 1) {
1250 : 12 : bool updated = mptcp_update_rcv_data_fin(msk, mpext->data_seq,
1251 : 12 : mpext->dsn64);
1252 [ - - ][ - - ]: 12 : pr_debug("DATA_FIN with no payload seq=%llu\n", mpext->data_seq);
1253 : : /* The current mapping, if any, can be old: not moved */
1254 [ + ][ + ]: 12 : if (updated)
1255 : 6 : mptcp_schedule_work((struct sock *)msk);
1256 : :
1257 [ + ][ + ]: 12 : if (subflow->map_valid) {
1258 : : /* A DATA_FIN might arrive in a DSS
1259 : : * option before the previous mapping
1260 : : * has been fully consumed. Continue
1261 : : * handling the existing mapping.
1262 : : */
1263 : 0 : skb_ext_del(skb, SKB_EXT_MPTCP);
1264 : 0 : return MAPPING_OK;
1265 : : }
1266 : :
1267 : : return MAPPING_DATA_FIN;
1268 : : }
1269 : :
1270 : 2051 : data_fin_seq = mpext->data_seq + data_len - 1;
1271 : :
1272 : : /* If mpext->data_seq is a 32-bit value, data_fin_seq must also
1273 : : * be limited to 32 bits.
1274 : : */
1275 [ + ][ + ]: 2051 : if (!mpext->dsn64)
1276 : 0 : data_fin_seq &= GENMASK_ULL(31, 0);
1277 : :
1278 : : /* The mapped data can be old, and then not moved to the msk */
1279 [ + ][ + ]: 2051 : if (mptcp_update_rcv_data_fin(msk, data_fin_seq, mpext->dsn64))
1280 : 25 : mptcp_schedule_work((struct sock *)msk);
1281 [ - - ][ - - ]: 2051 : pr_debug("DATA_FIN with mapping seq=%llu dsn64=%d\n",
1282 : : data_fin_seq, mpext->dsn64);
1283 : :
1284 : : /* Adjust for DATA_FIN using 1 byte of sequence space */
1285 : 2051 : data_len--;
1286 : : }
1287 : :
1288 [ + ][ + ]: 1449235 : map_seq = mptcp_expand_seq(READ_ONCE(msk->ack_seq), mpext->data_seq, mpext->dsn64);
1289 [ + ][ + ]: 1449235 : WRITE_ONCE(mptcp_sk(subflow->conn)->use_64bit_ack, !!mpext->dsn64);
1290 : :
1291 [ + ][ + ]: 1449235 : if (subflow->map_valid) {
1292 : : /* Allow replacing only with an identical map */
1293 [ - ][ - ]: 816460 : if (subflow->map_seq == map_seq &&
1294 [ - ][ - ]: 816460 : subflow->map_subflow_seq == mpext->subflow_seq &&
1295 [ - ][ - ]: 816460 : subflow->map_data_len == data_len &&
1296 [ - ][ - ]: 816460 : subflow->map_csum_reqd == mpext->csum_reqd) {
1297 : 816460 : skb_ext_del(skb, SKB_EXT_MPTCP);
1298 : 816460 : goto validate_csum;
1299 : : }
1300 : :
1301 : : /* If this skb data are fully covered by the current mapping,
1302 : : * the new map would need caching, which is not supported
1303 : : */
1304 [ # ][ # ]: 0 : if (skb_is_fully_mapped(ssk, skb)) {
1305 [ # ][ # ]: 0 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_DSSNOMATCH);
1306 : 0 : return MAPPING_INVALID;
1307 : : }
1308 : :
1309 : : /* will validate the next map after consuming the current one */
1310 : 0 : goto validate_csum;
1311 : : }
1312 : :
1313 : 632775 : subflow->map_seq = map_seq;
1314 : 632775 : subflow->map_subflow_seq = mpext->subflow_seq;
1315 : 632775 : subflow->map_data_len = data_len;
1316 : 632775 : subflow->map_valid = 1;
1317 : 632775 : subflow->map_data_fin = mpext->data_fin;
1318 : 632775 : subflow->mpc_map = mpext->mpc_map;
1319 : 632775 : subflow->map_csum_reqd = mpext->csum_reqd;
1320 : 632775 : subflow->map_csum_len = 0;
1321 [ - ][ - ]: 632775 : subflow->map_data_csum = csum_unfold(mpext->csum);
1322 : :
1323 : : /* Cfr RFC 8684 Section 3.3.0 */
1324 [ - ][ - ]: 632775 : if (unlikely(subflow->map_csum_reqd != csum_reqd))
1325 : : return MAPPING_INVALID;
1326 : :
1327 [ - - ][ - - ]: 632775 : pr_debug("new map seq=%llu subflow_seq=%u data_len=%u csum=%d:%u\n",
1328 : : subflow->map_seq, subflow->map_subflow_seq,
1329 : : subflow->map_data_len, subflow->map_csum_reqd,
1330 : : subflow->map_data_csum);
1331 : :
1332 : 808441 : validate_seq:
1333 : : /* we revalidate valid mapping on new skb, because we must ensure
1334 : : * the current skb is completely covered by the available mapping
1335 : : */
1336 [ + ][ + ]: 808441 : if (!validate_mapping(ssk, skb)) {
1337 [ # ][ # ]: 0 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_DSSTCPMISMATCH);
1338 : 0 : return MAPPING_INVALID;
1339 : : }
1340 : :
1341 : 808441 : skb_ext_del(skb, SKB_EXT_MPTCP);
1342 : :
1343 : 1624901 : validate_csum:
1344 : 1624901 : return validate_data_csum(ssk, skb, csum_reqd);
1345 : : }
1346 : :
1347 : 14558 : static void mptcp_subflow_discard_data(struct sock *ssk, struct sk_buff *skb,
1348 : : u64 limit)
1349 : : {
1350 [ + ]: 14558 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1351 : 14558 : bool fin = TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN;
1352 [ + ]: 14558 : struct tcp_sock *tp = tcp_sk(ssk);
1353 : 14558 : u32 offset, incr, avail_len;
1354 : :
1355 : 14558 : offset = tp->copied_seq - TCP_SKB_CB(skb)->seq;
1356 [ + + ]: 14558 : if (WARN_ON_ONCE(offset > skb->len))
1357 : 0 : goto out;
1358 : :
1359 : 14558 : avail_len = skb->len - offset;
1360 [ + ]: 14558 : incr = limit >= avail_len ? avail_len + fin : limit;
1361 : :
1362 [ - - ]: 14558 : pr_debug("discarding=%d len=%d offset=%d seq=%d\n", incr, skb->len,
1363 : : offset, subflow->map_subflow_seq);
1364 [ - ][ - ]: 14558 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_DUPDATA);
1365 [ + ][ + ]: 14558 : tcp_sk(ssk)->copied_seq += incr;
1366 : :
1367 : 14558 : out:
1368 [ + + ][ + + ]: 14558 : if (!before(tcp_sk(ssk)->copied_seq, TCP_SKB_CB(skb)->end_seq))
1369 : 13654 : sk_eat_skb(ssk, skb);
1370 [ + ][ + ]: 14558 : if (mptcp_subflow_get_map_offset(subflow) >= subflow->map_data_len)
1371 : 12064 : subflow->map_valid = 0;
1372 : 14558 : }
1373 : :
1374 : 0 : static bool subflow_is_done(const struct sock *sk)
1375 : : {
1376 [ + - ]: 806 : return sk->sk_shutdown & RCV_SHUTDOWN || sk->sk_state == TCP_CLOSE;
1377 : : }
1378 : :
1379 : : /* sched mptcp worker for subflow cleanup if no more data is pending */
1380 : 1652605 : static void subflow_sched_work_if_closed(struct mptcp_sock *msk, struct sock *ssk)
1381 : : {
1382 [ + ]: 1652605 : const struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1383 : 1652605 : struct sock *sk = (struct sock *)msk;
1384 : :
1385 [ + + + ]: 1657486 : if (likely(ssk->sk_state != TCP_CLOSE &&
1386 : : (ssk->sk_state != TCP_CLOSE_WAIT ||
1387 : : inet_sk_state_load(sk) != TCP_ESTABLISHED)))
1388 : 1643105 : return;
1389 : :
1390 [ + ][ + ]: 9500 : if (!skb_queue_empty(&ssk->sk_receive_queue))
1391 : : return;
1392 : :
1393 : : /* when the fallback subflow closes the rx side, trigger a 'dummy'
1394 : : * ingress data fin, so that the msk state will follow along
1395 : : */
1396 [ + ]: 9482 : if (__mptcp_check_fallback(msk) && subflow_is_done(ssk) &&
1397 [ - + ]: 1612 : msk->first == ssk &&
1398 : 806 : mptcp_update_rcv_data_fin(msk, subflow->map_seq +
1399 : 806 : subflow->map_data_len, true))
1400 : 184 : mptcp_schedule_work(sk);
1401 : :
1402 : : /* after the 'dummy' data fin: mptcp_close_ssk() checks it */
1403 [ + ][ + ]: 13887 : if (!test_and_set_bit(MPTCP_WORK_CLOSE_SUBFLOW, &msk->flags))
1404 : 2363 : mptcp_schedule_work(sk);
1405 : : }
1406 : :
1407 : 4 : static bool mptcp_subflow_fail(struct mptcp_sock *msk, struct sock *ssk)
1408 : : {
1409 : 4 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1410 : 4 : unsigned long fail_tout;
1411 : :
1412 : : /* we are really failing, prevent any later subflow join */
1413 : 4 : spin_lock_bh(&msk->fallback_lock);
1414 [ + + ][ + ]: 4 : if (!msk->allow_infinite_fallback) {
1415 : 2 : spin_unlock_bh(&msk->fallback_lock);
1416 : 2 : return false;
1417 : : }
1418 : 2 : msk->allow_subflows = false;
1419 : 2 : spin_unlock_bh(&msk->fallback_lock);
1420 : :
1421 : : /* graceful failure can happen only on the MPC subflow */
1422 [ + - ][ + - ]: 2 : if (WARN_ON_ONCE(ssk != READ_ONCE(msk->first)))
1423 : : return false;
1424 : :
1425 : : /* since the close timeout take precedence on the fail one,
1426 : : * no need to start the latter when the first is already set
1427 : : */
1428 [ + ][ + ]: 2 : if (sock_flag((struct sock *)msk, SOCK_DEAD))
1429 : : return true;
1430 : :
1431 : : /* we don't need extreme accuracy here, use a zero fail_tout as special
1432 : : * value meaning no fail timeout at all;
1433 : : */
1434 : 2 : fail_tout = jiffies + TCP_RTO_MAX;
1435 : 2 : if (!fail_tout)
1436 : : fail_tout = 1;
1437 : 2 : WRITE_ONCE(subflow->fail_tout, fail_tout);
1438 : 2 : tcp_send_ack(ssk);
1439 : :
1440 : 2 : mptcp_reset_tout_timer(msk, subflow->fail_tout);
1441 : 2 : return true;
1442 : : }
1443 : :
1444 : : /* Fallback: dummy maps go on from the last valid one, unless it is old */
1445 : 1450136 : static void subflow_update_dsn_base(struct mptcp_subflow_context *subflow)
1446 : : {
1447 : 1450136 : u32 end = subflow->map_seq + subflow->map_data_len;
1448 : :
1449 : 1450136 : subflow->dsn_base = subflow->map_seq - subflow->map_subflow_seq + 1;
1450 [ + ]: 1450136 : subflow->map_old = before(end, subflow->dsn_end);
1451 [ + ]: 1450136 : if (!subflow->map_old)
1452 : 1344715 : subflow->dsn_end = end;
1453 : 1450136 : }
1454 : :
1455 : 3168518 : static bool subflow_check_data_avail(struct sock *ssk)
1456 : : {
1457 [ + ]: 3168518 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1458 : 3168518 : enum mapping_status status;
1459 : 3168518 : struct mptcp_sock *msk;
1460 : 3168518 : struct sk_buff *skb;
1461 : :
1462 [ + + ]: 3168518 : if (!skb_peek(&ssk->sk_receive_queue))
1463 : 1450054 : WRITE_ONCE(subflow->data_avail, false);
1464 [ + + ][ + ]: 3168518 : if (subflow->data_avail)
1465 : : return true;
1466 : :
1467 [ + ][ + ]: 3092182 : msk = mptcp_sk(subflow->conn);
1468 : 3121298 : for (;;) {
1469 : 3106740 : u64 ack_seq;
1470 : 3106740 : u64 old_ack;
1471 : :
1472 : 3106740 : status = get_mapping_status(ssk, msk);
1473 [ + ][ + ]: 4573021 : trace_subflow_check_data_avail(status, skb_peek(&ssk->sk_receive_queue));
1474 [ + + ][ + + ]: 3106740 : if (unlikely(status == MAPPING_INVALID || status == MAPPING_DUMMY ||
1475 : : status == MAPPING_BAD_CSUM || status == MAPPING_NODSS))
1476 : 15550 : goto fallback;
1477 : :
1478 [ + ][ + ]: 3091190 : if (status != MAPPING_OK)
1479 : 1641056 : goto no_data;
1480 : :
1481 [ - ][ - ]: 1450134 : skb = skb_peek(&ssk->sk_receive_queue);
1482 [ + ][ + ]: 1450134 : if (WARN_ON_ONCE(!skb))
1483 : 0 : goto no_data;
1484 : :
1485 [ + + ][ + ]: 1450134 : if (unlikely(!READ_ONCE(msk->can_ack)))
1486 : 0 : goto fallback;
1487 : :
1488 : 1450134 : subflow_update_dsn_base(subflow);
1489 : :
1490 : 1450134 : old_ack = READ_ONCE(msk->ack_seq);
1491 : 1450134 : ack_seq = mptcp_subflow_get_mapped_dsn(subflow);
1492 [ - - ][ - - ]: 1450134 : pr_debug("msk ack_seq=%llx subflow ack_seq=%llx\n", old_ack,
1493 : : ack_seq);
1494 [ + ][ + ]: 1450134 : if (unlikely(before64(ack_seq, old_ack))) {
1495 : 14558 : mptcp_subflow_discard_data(ssk, skb, old_ack - ack_seq);
1496 : 14558 : continue;
1497 : : }
1498 : :
1499 : 1435576 : WRITE_ONCE(subflow->data_avail, true);
1500 : 1435576 : break;
1501 : : }
1502 : 1435576 : return true;
1503 : :
1504 : 1641056 : no_data:
1505 : 1641056 : subflow_sched_work_if_closed(msk, ssk);
1506 : 1641056 : return false;
1507 : :
1508 : 15550 : fallback:
1509 [ + ][ + ]: 15550 : if (!__mptcp_check_fallback(msk)) {
1510 : : /* RFC 8684 section 3.7. */
1511 [ + ][ + ]: 24 : if (status == MAPPING_BAD_CSUM &&
1512 [ + - ][ + - ]: 4 : (subflow->mp_join || subflow->valid_csum_seen)) {
1513 : 4 : subflow->send_mp_fail = 1;
1514 : :
1515 [ + ][ + ]: 4 : if (!mptcp_subflow_fail(msk, ssk)) {
1516 : 2 : subflow->reset_transient = 0;
1517 : 2 : subflow->reset_reason = MPTCP_RST_EMIDDLEBOX;
1518 : 2 : goto reset;
1519 : : }
1520 : 2 : subflow_update_dsn_base(subflow);
1521 : 2 : WRITE_ONCE(subflow->data_avail, true);
1522 : 2 : return true;
1523 : : }
1524 : :
1525 [ + ][ + ]: 20 : if (!mptcp_try_fallback(ssk, MPTCP_MIB_DSSFALLBACK)) {
1526 : : /* fatal protocol error, reset the subflow and let the
1527 : : * worker close it
1528 : : */
1529 : 12 : subflow->reset_transient = 0;
1530 [ - ][ # ]: 12 : MPTCP_INC_STATS(sock_net(ssk), MPTCP_MIB_DSSRESET);
1531 : 12 : subflow->reset_reason = status == MAPPING_NODSS ?
1532 [ + ][ + ]: 12 : MPTCP_RST_EMIDDLEBOX :
1533 : : MPTCP_RST_EMPTCP;
1534 : :
1535 : 14 : reset:
1536 : 14 : WRITE_ONCE(ssk->sk_err, EBADMSG);
1537 : 14 : tcp_set_state(ssk, TCP_CLOSE);
1538 [ + + ][ + + ]: 30 : while ((skb = skb_peek(&ssk->sk_receive_queue)))
1539 : 16 : sk_eat_skb(ssk, skb);
1540 : 14 : mptcp_send_active_reset_reason(ssk);
1541 : 14 : WRITE_ONCE(subflow->data_avail, false);
1542 : 14 : subflow_sched_work_if_closed(msk, ssk);
1543 : 14 : return false;
1544 : : }
1545 : : }
1546 : :
1547 [ + ][ + ]: 15534 : skb = skb_peek(&ssk->sk_receive_queue);
1548 : 15534 : subflow->map_valid = 1;
1549 : 15534 : subflow->map_data_len = skb->len;
1550 : 15534 : subflow->map_subflow_seq = TCP_SKB_CB(skb)->seq - subflow->ssn_offset;
1551 : 31068 : subflow->map_seq = __mptcp_expand_seq(subflow->map_seq,
1552 : 15534 : subflow->dsn_base +
1553 : 15534 : subflow->map_subflow_seq - 1);
1554 : 15534 : WRITE_ONCE(subflow->data_avail, true);
1555 : 15534 : return true;
1556 : : }
1557 : :
1558 : 3168518 : bool mptcp_subflow_data_available(struct sock *sk)
1559 : : {
1560 [ + ]: 3168518 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
1561 : :
1562 : : /* check if current mapping is still valid */
1563 [ + ]: 3168518 : if (subflow->map_valid &&
1564 [ + ]: 2518666 : mptcp_subflow_get_map_offset(subflow) >= subflow->map_data_len) {
1565 : 636239 : subflow->map_valid = 0;
1566 : 636239 : WRITE_ONCE(subflow->data_avail, false);
1567 : :
1568 [ - - ]: 636239 : pr_debug("Done with mapping: seq=%u data_len=%u\n",
1569 : : subflow->map_subflow_seq,
1570 : : subflow->map_data_len);
1571 : : }
1572 : :
1573 : 3168518 : return subflow_check_data_avail(sk);
1574 : : }
1575 : :
1576 : : /* If ssk has an mptcp parent socket, use the mptcp rcvbuf occupancy,
1577 : : * not the ssk one.
1578 : : *
1579 : : * In mptcp, rwin is about the mptcp-level connection data.
1580 : : *
1581 : : * Data that is still on the ssk rx queue can thus be ignored,
1582 : : * as far as mptcp peer is concerned that data is still inflight.
1583 : : * DSS ACK is updated when skb is moved to the mptcp rx queue.
1584 : : */
1585 : 3140950 : void mptcp_space(const struct sock *ssk, int *space, int *full_space)
1586 : : {
1587 : 3140950 : const struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
1588 : 3140950 : const struct sock *sk = subflow->conn;
1589 : :
1590 : 3140950 : *space = __mptcp_space(sk);
1591 : 3140950 : *full_space = mptcp_win_from_space(sk, READ_ONCE(sk->sk_rcvbuf));
1592 : 3140950 : }
1593 : :
1594 : 3056 : static void subflow_error_report(struct sock *ssk)
1595 : : {
1596 [ + ][ + ]: 3056 : struct sock *sk = mptcp_subflow_ctx(ssk)->conn;
1597 : :
1598 : : /* bail early if this is a no-op, so that we avoid introducing a
1599 : : * problematic lockdep dependency between TCP accept queue lock
1600 : : * and msk socket spinlock
1601 : : */
1602 [ + ][ + ]: 3056 : if (!sk->sk_socket)
1603 : : return;
1604 : :
1605 : 1162 : mptcp_data_lock(sk);
1606 [ + ][ + ]: 1162 : if (!sock_owned_by_user(sk))
1607 : 400 : __mptcp_error_report(sk);
1608 : : else
1609 [ + ][ + ]: 762 : __set_bit(MPTCP_ERROR_REPORT, &mptcp_sk(sk)->cb_flags);
1610 : 1162 : mptcp_data_unlock(sk);
1611 : : }
1612 : :
1613 : 1632057 : static void subflow_data_ready(struct sock *sk)
1614 : : {
1615 : 1632057 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
1616 [ + ]: 1632057 : u16 state = 1 << inet_sk_state_load(sk);
1617 : 1632057 : struct sock *parent = subflow->conn;
1618 : 1632057 : struct mptcp_sock *msk;
1619 : :
1620 : 1632057 : trace_sk_data_ready(sk);
1621 : :
1622 [ + ][ + ]: 1632057 : msk = mptcp_sk(parent);
1623 [ + ][ + ]: 1632057 : if (state & TCPF_LISTEN) {
1624 : : /* MPJ subflow are removed from accept queue before reaching here,
1625 : : * avoid stray wakeups
1626 : : */
1627 [ + ][ + ]: 2522 : if (reqsk_queue_empty(&inet_csk(sk)->icsk_accept_queue))
1628 : : return;
1629 : :
1630 : 1933 : parent->sk_data_ready(parent);
1631 : 1933 : return;
1632 : : }
1633 : :
1634 [ + + + - ]: 1629535 : WARN_ON_ONCE(!__mptcp_check_fallback(msk) && !subflow->mp_capable &&
[ + + + - ]
1635 : : !subflow->mp_join && !(state & TCPF_CLOSE));
1636 : :
1637 [ + ][ + ]: 1629535 : if (mptcp_subflow_data_available(sk)) {
1638 : 1438584 : mptcp_data_ready(parent, sk);
1639 : :
1640 : : /* subflow-level lowat test are not relevant.
1641 : : * respect the msk-level threshold eventually mandating an immediate ack
1642 : : */
1643 [ + ][ + ]: 1438584 : if (mptcp_data_avail(msk) < parent->sk_rcvlowat &&
1644 [ + + + ]: 387521 : (tcp_sk(sk)->rcv_nxt - tcp_sk(sk)->rcv_wup) > inet_csk(sk)->icsk_ack.rcv_mss)
[ + + + ]
1645 : 202834 : inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_NOW;
1646 [ + ][ + ]: 190951 : } else if (unlikely(READ_ONCE(sk->sk_err))) {
1647 : 14 : subflow_error_report(sk);
1648 : : }
1649 : : }
1650 : :
1651 : 980134 : static void subflow_write_space(struct sock *ssk)
1652 : : {
1653 : 980134 : struct sock *sk = mptcp_subflow_ctx(ssk)->conn;
1654 : :
1655 : 980134 : mptcp_propagate_sndbuf(sk, ssk);
1656 : 980134 : mptcp_write_space(sk);
1657 : 980134 : }
1658 : :
1659 : : static const struct inet_connection_sock_af_ops *
1660 : 0 : subflow_default_af_ops(struct sock *sk)
1661 : : {
1662 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1663 [ # ]: 0 : if (sk->sk_family == AF_INET6)
1664 : 0 : return &subflow_v6_specific;
1665 : : #endif
1666 : : return &subflow_specific;
1667 : : }
1668 : :
1669 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1670 : 964 : void mptcpv6_handle_mapped(struct sock *sk, bool mapped)
1671 : : {
1672 [ + ]: 964 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
1673 : 964 : struct inet_connection_sock *icsk = inet_csk(sk);
1674 : 964 : const struct inet_connection_sock_af_ops *target;
1675 : :
1676 [ + ]: 964 : target = mapped ? &subflow_v6m_specific : subflow_default_af_ops(sk);
1677 : :
1678 [ - - ]: 964 : pr_debug("subflow=%p family=%d ops=%p target=%p mapped=%d\n",
1679 : : subflow, sk->sk_family, icsk->icsk_af_ops, target, mapped);
1680 : :
1681 [ - ]: 964 : if (likely(icsk->icsk_af_ops == target))
1682 : : return;
1683 : :
1684 : 964 : subflow->icsk_af_ops = icsk->icsk_af_ops;
1685 : 964 : icsk->icsk_af_ops = target;
1686 : : }
1687 : : #endif
1688 : :
1689 : 1494 : void mptcp_info2sockaddr(const struct mptcp_addr_info *info,
1690 : : struct sockaddr_storage *addr,
1691 : : unsigned short family)
1692 : : {
1693 : 1494 : memset(addr, 0, sizeof(*addr));
1694 : 1494 : addr->ss_family = family;
1695 [ + ]: 1494 : if (addr->ss_family == AF_INET) {
1696 : 1324 : struct sockaddr_in *in_addr = (struct sockaddr_in *)addr;
1697 : :
1698 [ + ]: 1324 : if (info->family == AF_INET)
1699 : 1300 : in_addr->sin_addr = info->addr;
1700 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1701 [ - ]: 24 : else if (ipv6_addr_v4mapped(&info->addr6))
1702 : 24 : in_addr->sin_addr.s_addr = info->addr6.s6_addr32[3];
1703 : : #endif
1704 : 1324 : in_addr->sin_port = info->port;
1705 : : }
1706 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1707 [ - ]: 170 : else if (addr->ss_family == AF_INET6) {
1708 : 170 : struct sockaddr_in6 *in6_addr = (struct sockaddr_in6 *)addr;
1709 : :
1710 [ + ]: 170 : if (info->family == AF_INET)
1711 [ + ]: 2 : ipv6_addr_set_v4mapped(info->addr.s_addr,
1712 : : &in6_addr->sin6_addr);
1713 : : else
1714 : 168 : in6_addr->sin6_addr = info->addr6;
1715 : 170 : in6_addr->sin6_port = info->port;
1716 : : }
1717 : : #endif
1718 : 1494 : }
1719 : :
1720 : 768 : int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_pm_local *local,
1721 : : const struct mptcp_addr_info *remote)
1722 : : {
1723 [ + ]: 768 : struct mptcp_sock *msk = mptcp_sk(sk);
1724 : 768 : struct mptcp_subflow_context *subflow;
1725 : 768 : int local_id = local->addr.id;
1726 : 768 : struct sockaddr_storage addr;
1727 : 768 : int remote_id = remote->id;
1728 : 768 : int err = -ENOTCONN;
1729 : 768 : struct socket *sf;
1730 : 768 : struct sock *ssk;
1731 : 768 : u32 remote_token;
1732 : 768 : int addrlen;
1733 : :
1734 : : /* The userspace PM sent the request too early? */
1735 [ + ]: 768 : if (!mptcp_is_fully_established(sk))
1736 : 0 : goto err_out;
1737 : :
1738 : 768 : err = mptcp_subflow_create_socket(sk, local->addr.family, &sf);
1739 [ + ][ + ]: 768 : if (err) {
1740 [ - ][ - ]: 47 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_JOINSYNTXCREATSKERR);
1741 [ - - ][ - - ]: 47 : pr_debug("msk=%p local=%d remote=%d create sock error: %d\n",
1742 : : msk, local_id, remote_id, err);
1743 : 47 : goto err_out;
1744 : : }
1745 : :
1746 : 721 : ssk = sf->sk;
1747 : 721 : subflow = mptcp_subflow_ctx(ssk);
1748 : 721 : do {
1749 : 721 : subflow->local_nonce = get_random_u32();
1750 [ - ][ - ]: 721 : } while (!subflow->local_nonce);
1751 : :
1752 : : /* if 'IPADDRANY', the ID will be set later, after the routing */
1753 [ + ][ + ]: 721 : if (local->addr.family == AF_INET) {
1754 [ + + ][ + + ]: 647 : if (!local->addr.addr.s_addr)
1755 : : local_id = -1;
1756 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1757 [ + ][ + ]: 74 : } else if (sk->sk_family == AF_INET6) {
1758 [ + ][ + ]: 72 : if (ipv6_addr_any(&local->addr.addr6))
1759 : : local_id = -1;
1760 : : #endif
1761 : : }
1762 : :
1763 : 456 : if (local_id >= 0)
1764 : 456 : subflow_set_local_id(subflow, local_id);
1765 : :
1766 : 721 : subflow->remote_key_valid = 1;
1767 : 721 : subflow->remote_key = READ_ONCE(msk->remote_key);
1768 : 721 : subflow->local_key = READ_ONCE(msk->local_key);
1769 : 721 : subflow->token = msk->token;
1770 : 721 : mptcp_info2sockaddr(&local->addr, &addr, ssk->sk_family);
1771 : :
1772 : 721 : addrlen = sizeof(struct sockaddr_in);
1773 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1774 [ + ][ + ]: 721 : if (addr.ss_family == AF_INET6)
1775 : 74 : addrlen = sizeof(struct sockaddr_in6);
1776 : : #endif
1777 : 721 : ssk->sk_bound_dev_if = local->ifindex;
1778 : 721 : err = kernel_bind(sf, (struct sockaddr_unsized *)&addr, addrlen);
1779 [ + ][ + ]: 721 : if (err) {
1780 [ - ][ # ]: 4 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_JOINSYNTXBINDERR);
1781 [ - - ][ - - ]: 4 : pr_debug("msk=%p local=%d remote=%d bind error: %d\n",
1782 : : msk, local_id, remote_id, err);
1783 : 4 : goto failed;
1784 : : }
1785 : :
1786 : 717 : mptcp_crypto_key_sha(subflow->remote_key, &remote_token, NULL);
1787 [ - - ][ - - ]: 717 : pr_debug("msk=%p remote_token=%u local_id=%d remote_id=%d\n", msk,
1788 : : remote_token, local_id, remote_id);
1789 : 717 : subflow->remote_token = remote_token;
1790 : 717 : WRITE_ONCE(subflow->remote_id, remote_id);
1791 : 717 : subflow->request_join = 1;
1792 : 717 : subflow->request_bkup = !!(local->flags & MPTCP_PM_ADDR_FLAG_BACKUP);
1793 : 717 : subflow->subflow_id = msk->subflow_id++;
1794 : 717 : mptcp_info2sockaddr(remote, &addr, ssk->sk_family);
1795 : :
1796 : 717 : sock_hold(ssk);
1797 : 717 : list_add_tail(&subflow->node, &msk->conn_list);
1798 : 717 : err = kernel_connect(sf, (struct sockaddr_unsized *)&addr, addrlen, O_NONBLOCK);
1799 [ + ][ + ]: 717 : if (err && err != -EINPROGRESS) {
1800 [ - ][ # ]: 28 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_JOINSYNTXCONNECTERR);
1801 [ - - ][ - - ]: 28 : pr_debug("msk=%p local=%d remote=%d connect error: %d\n",
1802 : : msk, local_id, remote_id, err);
1803 : 28 : goto failed_unlink;
1804 : : }
1805 : :
1806 [ - ][ - ]: 689 : MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_JOINSYNTX);
1807 : :
1808 : : /* discard the subflow socket */
1809 : 689 : mptcp_sock_graft(ssk, sk->sk_socket);
1810 : 689 : iput(SOCK_INODE(sf));
1811 : 689 : mptcp_stop_tout_timer(sk);
1812 : 689 : return 0;
1813 : :
1814 : 0 : failed_unlink:
1815 : 28 : list_del(&subflow->node);
1816 : 28 : sock_put(mptcp_subflow_tcp_sock(subflow));
1817 : :
1818 : 32 : failed:
1819 : 32 : subflow->disposable = 1;
1820 : 32 : sock_release(sf);
1821 : :
1822 : 79 : err_out:
1823 : : /* we account subflows before the creation, and this failures will not
1824 : : * be caught by sk_state_change()
1825 : : */
1826 : 79 : mptcp_pm_close_subflow(msk);
1827 : 79 : return err;
1828 : : }
1829 : :
1830 : 584 : void __mptcp_inherit_memcg(struct sock *sk, struct sock *ssk, gfp_t gfp)
1831 : : {
1832 : : /* Only if the msk has been accepted already (and not orphaned).*/
1833 [ + - ]: 584 : if (!mem_cgroup_sockets_enabled || !sk->sk_socket)
1834 : : return;
1835 : :
1836 : 36 : mem_cgroup_sk_inherit(sk, ssk);
1837 : 36 : __sk_charge(ssk, gfp);
1838 : : }
1839 : :
1840 : 4933 : void __mptcp_inherit_cgrp_data(struct sock *sk, struct sock *ssk)
1841 : : {
1842 : : #ifdef CONFIG_SOCK_CGROUP_DATA
1843 : 4933 : struct sock_cgroup_data *sk_cd = &sk->sk_cgrp_data,
1844 : 4933 : *ssk_cd = &ssk->sk_cgrp_data;
1845 : :
1846 : : /* only the additional subflows created by kworkers have to be modified */
1847 [ + ]: 4933 : if (cgroup_id(sock_cgroup_ptr(sk_cd)) !=
1848 [ + ]: 264 : cgroup_id(sock_cgroup_ptr(ssk_cd))) {
1849 : 42 : cgroup_sk_free(ssk_cd);
1850 : 42 : *ssk_cd = *sk_cd;
1851 : 42 : cgroup_sk_clone(sk_cd);
1852 : : }
1853 : : #endif /* CONFIG_SOCK_CGROUP_DATA */
1854 : 4933 : }
1855 : :
1856 : 4307 : static void mptcp_attach_cgroup(struct sock *parent, struct sock *child)
1857 : : {
1858 : 4307 : __mptcp_inherit_cgrp_data(parent, child);
1859 [ + ]: 4307 : if (mem_cgroup_sockets_enabled)
1860 : 180 : mem_cgroup_sk_inherit(parent, child);
1861 : 4307 : }
1862 : :
1863 : 186 : static void mptcp_subflow_ops_override(struct sock *ssk)
1864 : : {
1865 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1866 : 4307 : if (ssk->sk_prot == &tcpv6_prot)
1867 : 1532 : ssk->sk_prot = &tcpv6_prot_override;
1868 : : else
1869 : : #endif
1870 : 2775 : ssk->sk_prot = &tcp_prot_override;
1871 : : }
1872 : :
1873 : 312 : static void mptcp_subflow_ops_undo_override(struct sock *ssk)
1874 : : {
1875 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
1876 [ + ]: 228 : if (ssk->sk_prot == &tcpv6_prot_override)
1877 : 2893 : ssk->sk_prot = &tcpv6_prot;
1878 : : else
1879 : : #endif
1880 : 3035 : ssk->sk_prot = &tcp_prot;
1881 : : }
1882 : :
1883 : 4354 : int mptcp_subflow_create_socket(struct sock *sk, unsigned short family,
1884 : : struct socket **new_sock)
1885 : : {
1886 : 4354 : struct mptcp_subflow_context *subflow;
1887 [ - ][ + ]: 4354 : struct net *net = sock_net(sk);
1888 : 4354 : struct socket *sf;
1889 : 4354 : int err;
1890 : :
1891 : : /* un-accepted server sockets can reach here - on bad configuration
1892 : : * bail early to avoid greater trouble later
1893 : : */
1894 [ + ][ - ][ + ]: 4354 : if (unlikely(!sk->sk_socket))
[ + ]
1895 : : return -EINVAL;
1896 : :
1897 : 4307 : err = sock_create_kern(net, family, SOCK_STREAM, IPPROTO_TCP, &sf);
1898 [ - ][ - ][ - ]: 4307 : if (err)
[ - ]
1899 : : return err;
1900 : :
1901 : 4307 : lock_sock_nested(sf->sk, SINGLE_DEPTH_NESTING);
1902 : :
1903 : 4307 : err = security_mptcp_add_subflow(sk, sf->sk);
1904 [ + ][ + ]: 4307 : if (err)
1905 : 0 : goto err_free;
1906 : :
1907 : : /* the newly created socket has to be in the same cgroup as its parent */
1908 : 4307 : mptcp_attach_cgroup(sk, sf->sk);
1909 : :
1910 : : /* kernel sockets do not by default acquire net ref, but TCP timer
1911 : : * needs it.
1912 : : * Update ns_tracker to current stack trace and refcounted tracker.
1913 : : * Not for a kernel msk, e.g. a PM listener: it would pin the netns.
1914 : : */
1915 [ + ][ + ][ - ]: 4307 : if (sk->sk_net_refcnt)
[ - ]
1916 : 4251 : sk_net_refcnt_upgrade(sf->sk);
1917 : 4307 : err = tcp_set_ulp(sf->sk, "mptcp");
1918 [ + ][ + ][ + ]: 4307 : if (err)
[ + ]
1919 : 0 : goto err_free;
1920 : :
1921 [ + ][ + ][ + ]: 4307 : mptcp_sockopt_sync_locked(mptcp_sk(sk), sf->sk);
1922 : 4307 : release_sock(sf->sk);
1923 : :
1924 : : /* the newly created socket really belongs to the owning MPTCP
1925 : : * socket, even if for additional subflows the allocation is performed
1926 : : * by a kernel workqueue. Adjust inode references, so that the
1927 : : * procfs/diag interfaces really show this one belonging to the correct
1928 : : * user.
1929 : : */
1930 : 4307 : SOCK_INODE(sf)->i_ino = SOCK_INODE(sk->sk_socket)->i_ino;
1931 : 4307 : SOCK_INODE(sf)->i_uid = SOCK_INODE(sk->sk_socket)->i_uid;
1932 : 4307 : SOCK_INODE(sf)->i_gid = SOCK_INODE(sk->sk_socket)->i_gid;
1933 : :
1934 [ - ][ - ][ - ]: 4307 : subflow = mptcp_subflow_ctx(sf->sk);
1935 [ - - ][ - - ]: 4307 : pr_debug("subflow=%p\n", subflow);
[ - - ]
1936 : :
1937 : 4307 : *new_sock = sf;
1938 : 4307 : sock_hold(sk);
1939 : 4307 : subflow->conn = sk;
1940 [ + ][ + ][ + ]: 4307 : mptcp_subflow_ops_override(sf->sk);
1941 : :
1942 : : return 0;
1943 : :
1944 : 0 : err_free:
1945 : 0 : release_sock(sf->sk);
1946 : 0 : sock_release(sf);
1947 : 0 : return err;
1948 : : }
1949 : :
1950 : 6677 : static struct mptcp_subflow_context *subflow_create_ctx(struct sock *sk,
1951 : : gfp_t priority)
1952 : : {
1953 : 6677 : struct inet_connection_sock *icsk = inet_csk(sk);
1954 : 6677 : struct mptcp_subflow_context *ctx;
1955 : :
1956 : 6677 : ctx = kzalloc_obj(*ctx, priority);
1957 [ - ]: 6677 : if (!ctx)
1958 : : return NULL;
1959 : :
1960 : 6677 : rcu_assign_pointer(icsk->icsk_ulp_data, ctx);
1961 [ - ]: 6677 : INIT_LIST_HEAD(&ctx->node);
1962 : 6677 : INIT_LIST_HEAD(&ctx->delegated_node);
1963 : :
1964 [ - - ]: 6677 : pr_debug("subflow=%p\n", ctx);
1965 : :
1966 : 6677 : ctx->tcp_sock = sk;
1967 : 6677 : WRITE_ONCE(ctx->local_id, -1);
1968 : :
1969 : 6677 : return ctx;
1970 : : }
1971 : :
1972 : 11547 : static void __subflow_state_change(struct sock *sk)
1973 : : {
1974 : 11547 : struct socket_wq *wq;
1975 : :
1976 : 11547 : rcu_read_lock();
1977 [ - + - - : 11547 : wq = rcu_dereference(sk->sk_wq);
- ]
1978 [ + ][ + ]: 11547 : if (skwq_has_sleeper(wq))
1979 : 1869 : wake_up_interruptible_all(&wq->wait);
1980 : 11547 : rcu_read_unlock();
1981 : 11547 : }
1982 : :
1983 : 11547 : static void subflow_state_change(struct sock *sk)
1984 : : {
1985 : 11547 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
1986 : 11547 : struct sock *parent = subflow->conn;
1987 : :
1988 : 11547 : __subflow_state_change(sk);
1989 : :
1990 : : /* Rx queue processing is unneeded, error reporting will take place at
1991 : : * __mptcp_close_ssk() time and subflow reset can't happen in case of
1992 : : * fallback: subflow_sched_work_if_closed() would be a no-op.
1993 : : */
1994 [ + ]: 11547 : if (subflow->resetting)
1995 : : return;
1996 : :
1997 : : /* as recvmsg() does not acquire the subflow socket for ssk selection
1998 : : * a fin packet carrying a DSS can be unnoticed if we don't trigger
1999 : : * the data available machinery here.
2000 : : */
2001 [ + ]: 11535 : if (mptcp_subflow_data_available(sk))
2002 : 160 : mptcp_data_ready(parent, sk);
2003 [ + ]: 11375 : else if (unlikely(READ_ONCE(sk->sk_err)))
2004 : 574 : subflow_error_report(sk);
2005 : :
2006 [ + ]: 11535 : subflow_sched_work_if_closed(mptcp_sk(parent), sk);
2007 : : }
2008 : :
2009 : 1890 : void mptcp_subflow_queue_clean(struct sock *listener_sk, struct sock *listener_ssk)
2010 : : {
2011 : 1890 : struct request_sock_queue *queue = &inet_csk(listener_ssk)->icsk_accept_queue;
2012 : 1890 : struct request_sock *req, *head, *tail;
2013 : 1890 : struct mptcp_subflow_context *subflow;
2014 : 1890 : struct sock *sk, *ssk;
2015 : :
2016 : : /* Due to lock dependencies no relevant lock can be acquired under rskq_lock.
2017 : : * Splice the req list, so that accept() can not reach the pending ssk after
2018 : : * the listener socket is released below.
2019 : : */
2020 : 1890 : spin_lock_bh(&queue->rskq_lock);
2021 : 1890 : head = queue->rskq_accept_head;
2022 : 1890 : tail = queue->rskq_accept_tail;
2023 : 1890 : queue->rskq_accept_head = NULL;
2024 : 1890 : queue->rskq_accept_tail = NULL;
2025 : 1890 : spin_unlock_bh(&queue->rskq_lock);
2026 : :
2027 [ + ][ + ]: 1890 : if (!head)
2028 : : return;
2029 : :
2030 : : /* can't acquire the msk socket lock under the subflow one,
2031 : : * or will cause ABBA deadlock
2032 : : */
2033 : 42 : release_sock(listener_ssk);
2034 : :
2035 [ + ][ + ]: 126 : for (req = head; req; req = req->dl_next) {
2036 : 42 : ssk = req->sk;
2037 [ + + ][ + ]: 42 : if (!sk_is_mptcp(ssk))
2038 : 0 : continue;
2039 : :
2040 [ - ][ - ]: 42 : subflow = mptcp_subflow_ctx(ssk);
2041 [ - + ][ - + ]: 42 : if (!subflow || !subflow->conn)
2042 : 0 : continue;
2043 : :
2044 : 42 : sk = subflow->conn;
2045 : 42 : sock_hold(sk);
2046 : :
2047 : 42 : lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
2048 : 42 : __mptcp_unaccepted_force_close(sk);
2049 : 42 : release_sock(sk);
2050 : :
2051 : : /* lockdep will report a false positive ABBA deadlock
2052 : : * between cancel_work_sync and the listener socket.
2053 : : * The involved locks belong to different sockets WRT
2054 : : * the existing AB chain.
2055 : : * Using a per socket key is problematic as key
2056 : : * deregistration requires process context and must be
2057 : : * performed at socket disposal time, in atomic
2058 : : * context.
2059 : : * Just tell lockdep to consider the listener socket
2060 : : * released here.
2061 : : */
2062 : 42 : mutex_release(&listener_sk->sk_lock.dep_map, _RET_IP_);
2063 : 42 : mptcp_cancel_work(sk);
2064 : 42 : mutex_acquire(&listener_sk->sk_lock.dep_map, 0, 0, _RET_IP_);
2065 : :
2066 : 42 : sock_put(sk);
2067 : : }
2068 : :
2069 : : /* we are still under the listener msk socket lock */
2070 : 42 : lock_sock_nested(listener_ssk, SINGLE_DEPTH_NESTING);
2071 : :
2072 : : /* restore the listener queue, to let the TCP code clean it up */
2073 : 42 : spin_lock_bh(&queue->rskq_lock);
2074 [ + ][ + ]: 42 : WARN_ON_ONCE(queue->rskq_accept_head);
2075 : 42 : queue->rskq_accept_head = head;
2076 : 42 : queue->rskq_accept_tail = tail;
2077 : 42 : spin_unlock_bh(&queue->rskq_lock);
2078 : : }
2079 : :
2080 : 5081 : static int subflow_ulp_init(struct sock *sk)
2081 : : {
2082 : 5081 : struct inet_connection_sock *icsk = inet_csk(sk);
2083 : 5081 : struct mptcp_subflow_context *ctx;
2084 [ + ]: 5081 : struct tcp_sock *tp = tcp_sk(sk);
2085 : 5081 : int err = 0;
2086 : :
2087 : : /* disallow attaching ULP to a socket unless it has been
2088 : : * created with sock_create_kern()
2089 : : */
2090 [ + ]: 5081 : if (!sk->sk_kern_sock) {
2091 : 774 : err = -EOPNOTSUPP;
2092 : 774 : goto out;
2093 : : }
2094 : :
2095 : 4307 : ctx = subflow_create_ctx(sk, GFP_KERNEL);
2096 [ + ]: 4307 : if (!ctx) {
2097 : 0 : err = -ENOMEM;
2098 : 0 : goto out;
2099 : : }
2100 : :
2101 [ - - ]: 4307 : pr_debug("subflow=%p, family=%d\n", ctx, sk->sk_family);
2102 : :
2103 : 4307 : tp->is_mptcp = 1;
2104 : : /* Subflows share the MPTCP socket, and thus its SOCK_NOSPACE bit,
2105 : : * which tcp_check_space() can not mirror. Pin the mirror so that
2106 : : * __tcp_check_space() always tests the shared bit.
2107 : : */
2108 : 4307 : tp->tcp_nospace = 1;
2109 : 4307 : ctx->icsk_af_ops = icsk->icsk_af_ops;
2110 [ + ]: 4307 : icsk->icsk_af_ops = subflow_default_af_ops(sk);
2111 : 4307 : ctx->tcp_state_change = sk->sk_state_change;
2112 : 4307 : ctx->tcp_error_report = sk->sk_error_report;
2113 : :
2114 [ + ]: 4307 : WARN_ON_ONCE(sk->sk_data_ready != sock_def_readable);
2115 [ + ]: 4307 : WARN_ON_ONCE(sk->sk_write_space != sk_stream_write_space);
2116 : :
2117 : 4307 : sk->sk_data_ready = subflow_data_ready;
2118 : 4307 : sk->sk_write_space = subflow_write_space;
2119 : 4307 : sk->sk_state_change = subflow_state_change;
2120 : 4307 : sk->sk_error_report = subflow_error_report;
2121 : 5081 : out:
2122 : 5081 : return err;
2123 : : }
2124 : :
2125 : 6519 : static void subflow_ulp_release(struct sock *ssk)
2126 : : {
2127 [ - ][ - ]: 6519 : struct mptcp_subflow_context *ctx = mptcp_subflow_ctx(ssk);
2128 : 6519 : bool release = true;
2129 : 6519 : struct sock *sk;
2130 : :
2131 [ - ][ - ]: 6519 : if (!ctx)
2132 : : return;
2133 : :
2134 : 6519 : sk = ctx->conn;
2135 [ - ][ - ]: 6519 : if (sk) {
2136 : : /* if the msk has been orphaned, keep the ctx
2137 : : * alive, will be freed by __mptcp_close_ssk(),
2138 : : * when the subflow is still unaccepted
2139 : : */
2140 [ + - ][ + - ]: 6519 : release = ctx->disposable || list_empty(&ctx->node);
2141 : :
2142 : : /* inet_child_forget() does not call sk_state_change(),
2143 : : * explicitly trigger the socket close machinery
2144 : : */
2145 [ # ][ # ]: 0 : if (!release && !test_and_set_bit(MPTCP_WORK_CLOSE_SUBFLOW,
2146 [ # ]: 0 : &mptcp_sk(sk)->flags))
2147 : 0 : mptcp_schedule_work(sk);
2148 : 6519 : sock_put(sk);
2149 : : }
2150 : :
2151 [ + ][ + ]: 6519 : mptcp_subflow_ops_undo_override(ssk);
2152 [ - ][ - ]: 6519 : if (release)
2153 : 6519 : mptcp_subflow_free_ctx(ctx);
2154 : : }
2155 : :
2156 : 2530 : static void subflow_ulp_clone(const struct request_sock *req,
2157 : : struct sock *newsk,
2158 : : const gfp_t priority)
2159 : : {
2160 : 2530 : struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
2161 [ + ][ - ]: 2530 : struct mptcp_subflow_context *old_ctx = mptcp_subflow_ctx(newsk);
2162 : 2530 : struct mptcp_subflow_context *new_ctx;
2163 : :
2164 [ + - ][ - ]: 2530 : if (!tcp_rsk(req)->is_mptcp ||
2165 [ + + ][ + + ]: 2530 : (!subflow_req->mp_capable && !subflow_req->mp_join)) {
2166 : 160 : subflow_ulp_fallback(newsk, old_ctx);
2167 : 160 : return;
2168 : : }
2169 : :
2170 : 2370 : new_ctx = subflow_create_ctx(newsk, priority);
2171 [ + ][ + ]: 2370 : if (!new_ctx) {
2172 : 0 : subflow_ulp_fallback(newsk, old_ctx);
2173 : 0 : return;
2174 : : }
2175 : :
2176 : 2370 : new_ctx->conn_finished = 1;
2177 : 2370 : new_ctx->icsk_af_ops = old_ctx->icsk_af_ops;
2178 : 2370 : new_ctx->tcp_state_change = old_ctx->tcp_state_change;
2179 : 2370 : new_ctx->tcp_error_report = old_ctx->tcp_error_report;
2180 : 2370 : new_ctx->rel_write_seq = 1;
2181 : 2370 : new_ctx->opt_ack_seq = tcp_rsk(req)->snt_isn + 1;
2182 : :
2183 [ + ][ + ]: 2370 : if (subflow_req->mp_capable) {
2184 : : /* see comments in subflow_syn_recv_sock(), MPTCP connection
2185 : : * is fully established only after we receive the remote key
2186 : : */
2187 : 1714 : new_ctx->mp_capable = 1;
2188 : 1714 : new_ctx->local_key = subflow_req->local_key;
2189 : 1714 : new_ctx->token = subflow_req->token;
2190 : 1714 : new_ctx->ssn_offset = subflow_req->ssn_offset;
2191 : 1714 : new_ctx->idsn = subflow_req->idsn;
2192 : :
2193 : : /* this is the first subflow, id is always 0 */
2194 : 1714 : subflow_set_local_id(new_ctx, 0);
2195 [ - ][ - ]: 656 : } else if (subflow_req->mp_join) {
2196 : 656 : new_ctx->ssn_offset = subflow_req->ssn_offset;
2197 : 656 : new_ctx->mp_join = 1;
2198 : 656 : WRITE_ONCE(new_ctx->fully_established, true);
2199 : 656 : new_ctx->remote_key_valid = 1;
2200 : 656 : new_ctx->backup = subflow_req->backup;
2201 : 656 : new_ctx->request_bkup = subflow_req->request_bkup;
2202 : 656 : WRITE_ONCE(new_ctx->remote_id, subflow_req->remote_id);
2203 : 656 : new_ctx->token = subflow_req->token;
2204 : :
2205 : : /* the subflow req id is valid, fetched via subflow_check_req()
2206 : : * and subflow_token_join_request()
2207 : : */
2208 : 656 : subflow_set_local_id(new_ctx, subflow_req->local_id);
2209 : : }
2210 : : }
2211 : :
2212 : 800356 : static void tcp_release_cb_override(struct sock *ssk)
2213 : : {
2214 : 800356 : struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(ssk);
2215 : 800356 : long status;
2216 : :
2217 : : /* process and clear all the pending actions, but leave the subflow into
2218 : : * the napi queue. To respect locking, only the same CPU that originated
2219 : : * the action can touch the list. mptcp_napi_poll will take care of it.
2220 : : */
2221 [ + - ][ + - ]: 800356 : status = set_mask_bits(&subflow->delegated_status, MPTCP_DELEGATE_ACTIONS_MASK, 0);
2222 [ + ][ + ]: 800356 : if (status)
2223 : 5848 : mptcp_subflow_process_delegated(ssk, status);
2224 : :
2225 : 800356 : tcp_release_cb(ssk);
2226 : 800356 : }
2227 : :
2228 : 0 : static int tcp_abort_override(struct sock *ssk, int err)
2229 : : {
2230 : : /* closing a listener subflow requires a great deal of care.
2231 : : * keep it simple and just prevent such operation
2232 : : */
2233 [ # ]: 0 : if (inet_sk_state_load(ssk) == TCP_LISTEN)
2234 : : return -EINVAL;
2235 : :
2236 : 0 : return tcp_abort(ssk, err);
2237 : : }
2238 : :
2239 : : static struct tcp_ulp_ops subflow_ulp_ops __read_mostly = {
2240 : : .name = "mptcp",
2241 : : .owner = THIS_MODULE,
2242 : : .init = subflow_ulp_init,
2243 : : .release = subflow_ulp_release,
2244 : : .clone = subflow_ulp_clone,
2245 : : };
2246 : :
2247 : 12 : static int subflow_ops_init(struct request_sock_ops *subflow_ops)
2248 : : {
2249 : 12 : subflow_ops->obj_size = sizeof(struct mptcp_subflow_request_sock);
2250 : :
2251 : 12 : subflow_ops->slab = kmem_cache_create(subflow_ops->slab_name,
2252 : : subflow_ops->obj_size, 0,
2253 : : SLAB_ACCOUNT |
2254 : : SLAB_TYPESAFE_BY_RCU,
2255 : : NULL);
2256 [ + ]: 12 : if (!subflow_ops->slab)
2257 : 0 : return -ENOMEM;
2258 : :
2259 : : return 0;
2260 : : }
2261 : :
2262 : 6 : void __init mptcp_subflow_init(void)
2263 : : {
2264 : 6 : mptcp_subflow_v4_request_sock_ops = tcp_request_sock_ops;
2265 : 6 : mptcp_subflow_v4_request_sock_ops.slab_name = "request_sock_subflow_v4";
2266 : 6 : mptcp_subflow_v4_request_sock_ops.destructor = subflow_v4_req_destructor;
2267 : :
2268 [ + ]: 6 : if (subflow_ops_init(&mptcp_subflow_v4_request_sock_ops) != 0)
2269 : 0 : panic("MPTCP: failed to init subflow v4 request sock ops\n");
2270 : :
2271 : 6 : subflow_request_sock_ipv4_ops = tcp_request_sock_ipv4_ops;
2272 : 6 : subflow_request_sock_ipv4_ops.route_req = subflow_v4_route_req;
2273 : 6 : subflow_request_sock_ipv4_ops.send_synack = subflow_v4_send_synack;
2274 : :
2275 : 6 : subflow_specific = ipv4_specific;
2276 : 6 : subflow_specific.conn_request = subflow_v4_conn_request;
2277 : 6 : subflow_specific.syn_recv_sock = subflow_syn_recv_sock;
2278 : 6 : subflow_specific.sk_rx_dst_set = subflow_finish_connect;
2279 : 6 : subflow_specific.rebuild_header = subflow_rebuild_header;
2280 : :
2281 : 6 : tcp_prot_override = tcp_prot;
2282 : 6 : tcp_prot_override.release_cb = tcp_release_cb_override;
2283 : 6 : tcp_prot_override.diag_destroy = tcp_abort_override;
2284 : : #ifdef CONFIG_BPF_SYSCALL
2285 : : /* Disable sockmap processing for subflows */
2286 : 6 : tcp_prot_override.psock_update_sk_prot = NULL;
2287 : : #endif
2288 : :
2289 : 6 : mptcp_diag_subflow_init(&subflow_ulp_ops);
2290 : :
2291 [ + ]: 6 : if (tcp_register_ulp(&subflow_ulp_ops) != 0)
2292 : 0 : panic("MPTCP: failed to register subflows to ULP\n");
2293 : 6 : }
2294 : :
2295 : : #if IS_ENABLED(CONFIG_MPTCP_IPV6)
2296 : 6 : void __init mptcp_subflow_v6_init(void)
2297 : : {
2298 : : /* In struct mptcp_subflow_request_sock, we assume the TCP request sock
2299 : : * structures for v4 and v6 have the same size. It should not changed in
2300 : : * the future but better to make sure to be warned if it is no longer
2301 : : * the case.
2302 : : */
2303 : 6 : BUILD_BUG_ON(sizeof(struct tcp_request_sock) != sizeof(struct tcp6_request_sock));
2304 : :
2305 : 6 : mptcp_subflow_v6_request_sock_ops = tcp6_request_sock_ops;
2306 : 6 : mptcp_subflow_v6_request_sock_ops.slab_name = "request_sock_subflow_v6";
2307 : 6 : mptcp_subflow_v6_request_sock_ops.destructor = subflow_v6_req_destructor;
2308 : :
2309 [ + ]: 6 : if (subflow_ops_init(&mptcp_subflow_v6_request_sock_ops) != 0)
2310 : 0 : panic("MPTCP: failed to init subflow v6 request sock ops\n");
2311 : :
2312 : 6 : subflow_request_sock_ipv6_ops = tcp_request_sock_ipv6_ops;
2313 : 6 : subflow_request_sock_ipv6_ops.route_req = subflow_v6_route_req;
2314 : 6 : subflow_request_sock_ipv6_ops.send_synack = subflow_v6_send_synack;
2315 : :
2316 : 6 : subflow_v6_specific = ipv6_specific;
2317 : 6 : subflow_v6_specific.conn_request = subflow_v6_conn_request;
2318 : 6 : subflow_v6_specific.syn_recv_sock = subflow_syn_recv_sock;
2319 : 6 : subflow_v6_specific.sk_rx_dst_set = subflow_finish_connect;
2320 : 6 : subflow_v6_specific.rebuild_header = subflow_v6_rebuild_header;
2321 : :
2322 : 6 : subflow_v6m_specific = subflow_v6_specific;
2323 : 6 : subflow_v6m_specific.queue_xmit = ipv4_specific.queue_xmit;
2324 : 6 : subflow_v6m_specific.net_header_len = ipv4_specific.net_header_len;
2325 : 6 : subflow_v6m_specific.mtu_reduced = ipv4_specific.mtu_reduced;
2326 : 6 : subflow_v6m_specific.rebuild_header = subflow_rebuild_header;
2327 : :
2328 : 6 : tcpv6_prot_override = tcpv6_prot;
2329 : 6 : tcpv6_prot_override.release_cb = tcp_release_cb_override;
2330 : 6 : tcpv6_prot_override.diag_destroy = tcp_abort_override;
2331 : : #ifdef CONFIG_BPF_SYSCALL
2332 : : /* Disable sockmap processing for subflows */
2333 : 6 : tcpv6_prot_override.psock_update_sk_prot = NULL;
2334 : : #endif
2335 : 6 : }
2336 : : #endif
|