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