From patchwork Fri Nov 25 22:29:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 26154 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp4325837wrr; Fri, 25 Nov 2022 14:32:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf76PSOL6GtOBfYtuCjRCCsi7EvldYhcyfAM+/8ceVYAFLeo3kt4wRH88izxGB867zUAZM/7 X-Received: by 2002:a17:902:d4c5:b0:189:5e92:d457 with SMTP id o5-20020a170902d4c500b001895e92d457mr7906540plg.166.1669415527346; Fri, 25 Nov 2022 14:32:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669415527; cv=none; d=google.com; s=arc-20160816; b=EWycL+BLG+XtirbXmWFbt6Vq9dP1AO0gL5IHhbpPT17hYm2YwRUinqQSQTHRnzWWfv kIrqoEwO/QQLQmganVTbiX2kHCqaQvPmM+RWth3wJEHh/FCL4Y39+Pyl0GfVFufzi7AS h900hgsyUA2hjiVcgHU+24BPTuqLX0kjOk0ToS9yfWmagbIVF8JCGvo2REQeBOfTx+tf 6hA7by1UDJMjG0H6DlgDr+m+IoUnJmMO/NVYGTPKuJgBWfRTNrrVqtIcULJUTcDuW8ri pu/ilFKF5dsGF10fGnypyWqoBEbHYLiZEBv/+0z1SSEimtKn5NSOEWrH8Z0vZEWzoSmd RNgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3+iaKMj6vM07FzBDqChWLVnPYDyo0Nn9qPkX/3MkG3E=; b=zxqatL0rv76akx+g/SV+CT2YVyEeV0ID7mhpmcNmUzpZGMBWrfSqBYwP6vO7r20Egh 3iXy+zbT1qbuuToKwi4nyK/UFp85jNhtZQDFD1+itr1Tu+P7A5ZvnHZadcxx0Y4ZGJV3 icOiqPauruKTvu0ptQ1A6NdjwET+/NC4MYK0zruW5eU4hm5a5OfSNpndZcUlmb8jdg5L AoehzmC34e/KQHFYR+mi2/XwBOg/Dru0v8BksogbNXnOvhrtNWybZCPO8jet76K2t33l Hbg8YMk6Rnv2kv+Je8Cp8TfINOoatKDhaB2dkvLpAytxox32OT/NtMMIba16ydJuvl0R WyHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tessares.net header.s=google header.b=6OgZaR2n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tessares.net Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 31-20020a63125f000000b004774b5b58cesi3521817pgs.876.2022.11.25.14.31.51; Fri, 25 Nov 2022 14:32:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@tessares.net header.s=google header.b=6OgZaR2n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tessares.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230012AbiKYWao (ORCPT + 99 others); Fri, 25 Nov 2022 17:30:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbiKYWah (ORCPT ); Fri, 25 Nov 2022 17:30:37 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D11B303DA for ; Fri, 25 Nov 2022 14:30:26 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id e13so8043655edj.7 for ; Fri, 25 Nov 2022 14:30:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares.net; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3+iaKMj6vM07FzBDqChWLVnPYDyo0Nn9qPkX/3MkG3E=; b=6OgZaR2nQdc6rEQXwfoAcYKQhdg7Ctyin9pg3pUVi2fxz/fg46y/29DSKmXnC43RY6 LP9LxxRlU/YIhVE1bRT6pZTQGaykUSH3onQrR6AeXDRGYy09+qNbGDzN5PJq8ioQndez fGoOi1zucvr8SwkugTzkQH2Tw/dLOm3t4fIurw9gI/ubbkcE4N6CagOPWNYa/6hAwTuM i7GawJpEG4l+uye6o50ERLfTygP5guTbLWQ0vTLzrZ/6H+LZI/X6KopvjzPeO5/1GhBr jTSgZlPIG7Rrprl3S69/QhN/KfjYeza0ILtxBluWs+lJgQqd7NFSagmid+nM310JkmC5 gvNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3+iaKMj6vM07FzBDqChWLVnPYDyo0Nn9qPkX/3MkG3E=; b=bLyvFHEcYHDjTOLpswXaBAupctgnGDenneFt2o39Glk+cm1Zhfu0+m89/QoZvwbx9V QvJDYi5WojtMBe9O+UcmrwwxSWzSUzRMgsMJLVIJpZrzFfvi7ew5WLGZaebiY6mH3qlN C2uC9pk66IizbCK4Sp7EkFOBt6ShydXnj38SMajRoDQcW49T1W7yGOo/QIjHN3mL/AHL XBLyGaYxLJAuF+hnyAvpcvSFUIAC0RXy+ACLQfHukJoU7NzrQnS3CwEfvlcC4E7mjV/N E/gZ5orSEFbEP4vLxWr1qnncWtCGpEIA0Zg8S70JVm8+YPqunbMVfc0iS/oKw5O1vjze sivA== X-Gm-Message-State: ANoB5pmplQRFFPBP+hvM/OKZqTFaxJrOutJXzNuu2pBCvOk18OtoUuVn 1xBxxumJih4VNL1qUzmyaMgCuw== X-Received: by 2002:aa7:c7c4:0:b0:467:4a80:719b with SMTP id o4-20020aa7c7c4000000b004674a80719bmr20818257eds.174.1669415425720; Fri, 25 Nov 2022 14:30:25 -0800 (PST) Received: from vdi08.nix.tessares.net (static.219.156.76.144.clients.your-server.de. [144.76.156.219]) by smtp.gmail.com with ESMTPSA id q1-20020a056402248100b0046267f8150csm2254612eda.19.2022.11.25.14.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 14:30:25 -0800 (PST) From: Matthieu Baerts To: Mat Martineau , Matthieu Baerts , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Dmytro Shytyi , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev Subject: [PATCH net-next 4/8] mptcp: implement delayed seq generation for passive fastopen Date: Fri, 25 Nov 2022 23:29:50 +0100 Message-Id: <20221125222958.958636-5-matthieu.baerts@tessares.net> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221125222958.958636-1-matthieu.baerts@tessares.net> References: <20221125222958.958636-1-matthieu.baerts@tessares.net> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=7192; i=matthieu.baerts@tessares.net; h=from:subject; bh=LzNK76T2xhDCrjtYhvmmyVzad5gtt3rl6eOeAbZ4HpY=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBjgUHPfkkPLmIR4DfOXhjCycprC2hlqfrj+njIAVPu IT0uQ7OJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCY4FBzwAKCRD2t4JPQmmgcz9gD/ 0dgTUCsYbxFNJeyyTZcv7c2uj7NVuPjJJ9R2YGWhkpgAIDRunLfyEKeJ7+3x0fUv6ITA+8UXRJTyP9 toGuj+XeOqk3v6KhcDjP58v42jRN9HdFnjlCPgX+N3zZwfrO4HWs/ix97ajq7GxqgYkyFafwdCxnDp lfMsXHXea7rK3f0/UySE6UdGj6aV0Rr0NgDyVwUF7yMJYeIrjqVVpPN7WE3Id4N9fe13WC3ZPZtfO9 fDfefwfsLocr5Bxhx1oWUnhhs34MyTZPVhHVD2UlOf9xmwWuhf5K3N+iAjR50BHvRBd3nm93MFczUZ IMYxIuqVyTMC1GvNd19RUbsajltR3+B5SpX8LKu46UGRPPPVlRSiNdQj2fCZ4DSWYWiO6APkAKSpnR 4P12Nd6oVx5LI28jgEpRfl1KqKtNLORG/19RaAlpRCXLzNM6r9jm6y0b+yrT+zga0gihOwup1d9ClL ip05Ftw0Tqa0pHXEajObG97+3W5clw5YUl7Hj5615zp2CG78IxuWFn29BTYpu3sOwFEybz6HIUNLWX RALDryaVLMOiCYZ9Nmw/8wplMXRtn5efaZ1aGGkPpvdRTfjOAR0tu2v52/Y5Ceqm1vJR+mwnXZiwmx 66afhU1E0cM4PGgqHoyz/Vwo1TS4ICWDKynqjC9jXE5k5larSEpcPWKkqNCQ== X-Developer-Key: i=matthieu.baerts@tessares.net; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750509055926063701?= X-GMAIL-MSGID: =?utf-8?q?1750509055926063701?= From: Dmytro Shytyi With fastopen in place, the first subflow socket is created before the MPC handshake completes, and we need to properly initialize the sequence numbers at MPC ACK reception. Co-developed-by: Paolo Abeni Signed-off-by: Paolo Abeni Co-developed-by: Matthieu Baerts Signed-off-by: Matthieu Baerts Signed-off-by: Dmytro Shytyi Signed-off-by: Matthieu Baerts --- net/mptcp/Makefile | 2 +- net/mptcp/fastopen.c | 28 ++++++++++++++++++++++++++++ net/mptcp/options.c | 9 ++++++--- net/mptcp/protocol.c | 9 --------- net/mptcp/protocol.h | 16 +++++++++++++++- net/mptcp/subflow.c | 5 ++++- 6 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 net/mptcp/fastopen.c diff --git a/net/mptcp/Makefile b/net/mptcp/Makefile index 6e7df47c9584..a3829ce548f9 100644 --- a/net/mptcp/Makefile +++ b/net/mptcp/Makefile @@ -2,7 +2,7 @@ obj-$(CONFIG_MPTCP) += mptcp.o mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o \ - mib.o pm_netlink.o sockopt.o pm_userspace.o + mib.o pm_netlink.o sockopt.o pm_userspace.o fastopen.o obj-$(CONFIG_SYN_COOKIES) += syncookies.o obj-$(CONFIG_INET_MPTCP_DIAG) += mptcp_diag.o diff --git a/net/mptcp/fastopen.c b/net/mptcp/fastopen.c new file mode 100644 index 000000000000..19c332af0834 --- /dev/null +++ b/net/mptcp/fastopen.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0 +/* MPTCP Fast Open Mechanism + * + * Copyright (c) 2021-2022, Dmytro SHYTYI + */ + +#include "protocol.h" + +void mptcp_fastopen_gen_msk_ackseq(struct mptcp_sock *msk, struct mptcp_subflow_context *subflow, + const struct mptcp_options_received *mp_opt) +{ + struct sock *sk = (struct sock *)msk; + struct sk_buff *skb; + + mptcp_data_lock(sk); + skb = skb_peek_tail(&sk->sk_receive_queue); + if (skb) { + WARN_ON_ONCE(MPTCP_SKB_CB(skb)->end_seq); + pr_debug("msk %p moving seq %llx -> %llx end_seq %llx -> %llx", sk, + MPTCP_SKB_CB(skb)->map_seq, MPTCP_SKB_CB(skb)->map_seq + msk->ack_seq, + MPTCP_SKB_CB(skb)->end_seq, MPTCP_SKB_CB(skb)->end_seq + msk->ack_seq); + MPTCP_SKB_CB(skb)->map_seq += msk->ack_seq; + MPTCP_SKB_CB(skb)->end_seq += msk->ack_seq; + } + + pr_debug("msk=%p ack_seq=%llx", msk, msk->ack_seq); + mptcp_data_unlock(sk); +} diff --git a/net/mptcp/options.c b/net/mptcp/options.c index ae076468fcb9..5ded85e2c374 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -939,7 +939,7 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk, subflow->mp_join && (mp_opt->suboptions & OPTIONS_MPTCP_MPJ) && !subflow->request_join) tcp_send_ack(ssk); - goto fully_established; + goto check_notify; } /* we must process OoO packets before the first subflow is fully @@ -950,6 +950,8 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk, if (TCP_SKB_CB(skb)->seq != subflow->ssn_offset + 1) { if (subflow->mp_join) goto reset; + if (subflow->is_mptfo && mp_opt->suboptions & OPTION_MPTCP_MPC_ACK) + goto set_fully_established; return subflow->mp_capable; } @@ -961,7 +963,7 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk, */ subflow->fully_established = 1; WRITE_ONCE(msk->fully_established, true); - goto fully_established; + goto check_notify; } /* If the first established packet does not contain MP_CAPABLE + data @@ -980,11 +982,12 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk, if (mp_opt->deny_join_id0) WRITE_ONCE(msk->pm.remote_deny_join_id0, true); +set_fully_established: if (unlikely(!READ_ONCE(msk->pm.server_side))) pr_warn_once("bogus mpc option on established client sk"); mptcp_subflow_fully_established(subflow, mp_opt); -fully_established: +check_notify: /* if the subflow is not already linked into the conn_list, we can't * notify the PM: this subflow is still on the listener queue * and the PM possibly acquiring the subflow lock could race with diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 00de7f4fce10..a12ee763e52c 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -36,15 +36,6 @@ struct mptcp6_sock { }; #endif -struct mptcp_skb_cb { - u64 map_seq; - u64 end_seq; - u32 offset; - u8 has_rxtstamp:1; -}; - -#define MPTCP_SKB_CB(__skb) ((struct mptcp_skb_cb *)&((__skb)->cb[0])) - enum { MPTCP_CMSG_TS = BIT(0), MPTCP_CMSG_INQ = BIT(1), diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index b5abea3d1a9c..618ac85abaaf 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -126,6 +126,15 @@ #define MPTCP_CONNECTED 6 #define MPTCP_RESET_SCHEDULER 7 +struct mptcp_skb_cb { + u64 map_seq; + u64 end_seq; + u32 offset; + u8 has_rxtstamp:1; +}; + +#define MPTCP_SKB_CB(__skb) ((struct mptcp_skb_cb *)&((__skb)->cb[0])) + static inline bool before64(__u64 seq1, __u64 seq2) { return (__s64)(seq1 - seq2) < 0; @@ -471,7 +480,9 @@ struct mptcp_subflow_context { disposable : 1, /* ctx can be free at ulp release time */ stale : 1, /* unable to snd/rcv data, do not use for xmit */ local_id_valid : 1, /* local_id is correctly initialized */ - valid_csum_seen : 1; /* at least one csum validated */ + valid_csum_seen : 1, /* at least one csum validated */ + is_mptfo : 1, /* subflow is doing TFO */ + __unused : 8; enum mptcp_data_avail data_avail; u32 remote_nonce; u64 thmac; @@ -829,6 +840,9 @@ void mptcp_event_addr_announced(const struct sock *ssk, const struct mptcp_addr_ void mptcp_event_addr_removed(const struct mptcp_sock *msk, u8 id); bool mptcp_userspace_pm_active(const struct mptcp_sock *msk); +void mptcp_fastopen_gen_msk_ackseq(struct mptcp_sock *msk, struct mptcp_subflow_context *subflow, + const struct mptcp_options_received *mp_opt); + static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk) { return READ_ONCE(msk->pm.addr_signal) & diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 470e12ce0950..21cf26edb79a 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -664,6 +664,9 @@ void mptcp_subflow_fully_established(struct mptcp_subflow_context *subflow, subflow_set_remote_key(msk, subflow, mp_opt); subflow->fully_established = 1; WRITE_ONCE(msk->fully_established, true); + + if (subflow->is_mptfo) + mptcp_fastopen_gen_msk_ackseq(msk, subflow, mp_opt); } static struct sock *subflow_syn_recv_sock(const struct sock *sk, @@ -779,7 +782,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, /* with OoO packets we can reach here without ingress * mpc option */ - if (mp_opt.suboptions & OPTIONS_MPTCP_MPC) + if (mp_opt.suboptions & OPTION_MPTCP_MPC_ACK) mptcp_subflow_fully_established(ctx, &mp_opt); } else if (ctx->mp_join) { struct mptcp_sock *owner;