From nobody Sat Dec 21 15:13:20 2024 Received: from sender11-of-o51.zoho.eu (sender11-of-o51.zoho.eu [31.186.226.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2AED291C for ; Sun, 6 Nov 2022 15:24:45 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1667748272; cv=none; d=zohomail.eu; s=zohoarc; b=iMRKhJDGSF+0ztG9gaqJnbe/p2sKgM6XO3j+uGU1PzqWYR5t5W5i3xW4AvCBO+Ou67dfc2OA5zLEqkFdNGzbz4odjds/pmwXn5FPTj/yFA9NFgd2O69E0QPGleEV8JyFf4Ukh3I3QTjGKUUdZ0geCZKIITruBGWgE9L5/4UjBJM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1667748272; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=47KsXtqvgfdp5fHSeNYVlFXhTzq+vd4zu9jynPaG38k=; b=AI6S1QZ0B0d1DGLfQCSUHqJTOH7g5g5dygs7K2/imoB3egwP7BjGBVCuVjcohtOdU5s48NfytqnBGZgbReTcjHEcjVkLdGTEg5VH0IWUfnWXhvsG0dIaYclq5QuBV7BSvOrMS++Vxymf3LssyZc2MhebJzmWnPbKi5Crrh0A0gk= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=shytyi.net; spf=pass smtp.mailfrom=dmytro@shytyi.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1667748272; s=hs; d=shytyi.net; i=dmytro@shytyi.net; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=47KsXtqvgfdp5fHSeNYVlFXhTzq+vd4zu9jynPaG38k=; b=PNX7rIdE20eOFdXuKB6TR41IQ2qyOInj6MtcS8P85aBmvSPEmMl66z7Co1ml2xkC lTjnFLUOiupUXWkHsYRPTtuo86pA7D15Opg3+xduwCvn8LkvjJRb3QZPNDNZfFtMQcM LTM/AKKavZPwn9UKT7Y336Z8IXcRZvUYbkkzoalw= Received: from localhost.localdomain (vps-940813d4.vps.ovh.net [198.244.188.50]) by mx.zoho.eu with SMTPS id 1667748270672261.0089987436238; Sun, 6 Nov 2022 16:24:30 +0100 (CET) From: Dmytro Shytyi To: mptcp@lists.linux.dev Cc: Dmytro Shytyi , Benjamin Hesmans Message-ID: <20221106152411.655-2-dmytro@shytyi.net> Subject: [RFC PATCH mptcp-next v15 1/5] mptcp: introduce MSG_FASTOPEN flag Date: Sun, 6 Nov 2022 15:24:07 +0000 X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221106152411.655-1-dmytro@shytyi.net> References: <20221106152411.655-1-dmytro@shytyi.net> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" In the following patches we will analyse the MSG_FASTOPEN flag in the mptcp_sendmsg() and invoke the MPTFO. Signed-of-by: Benjamin Hesmans Signed-off-by: Dmytro Shytyi --- net/mptcp/protocol.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 3196d2a350f9..f4247218fd1b 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1704,17 +1704,14 @@ static int mptcp_sendmsg(struct sock *sk, struct ms= ghdr *msg, size_t len) int ret =3D 0; long timeo; =20 - /* we don't support FASTOPEN yet */ - if (msg->msg_flags & MSG_FASTOPEN) - return -EOPNOTSUPP; - /* silently ignore everything else */ - msg->msg_flags &=3D MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL; + msg->msg_flags &=3D MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL | MSG_FASTOPEN; =20 lock_sock(sk); =20 ssock =3D __mptcp_nmpc_socket(msk); - if (unlikely(ssock && inet_sk(ssock->sk)->defer_connect)) { + if (unlikely(ssock && (inet_sk(ssock->sk)->defer_connect || + msg->msg_flags & MSG_FASTOPEN))) { int copied_syn =3D 0; =20 ret =3D mptcp_sendmsg_fastopen(sk, ssock->sk, msg, len, &copied_syn); --=20 2.34.1 From nobody Sat Dec 21 15:13:20 2024 Received: from sender11-of-o51.zoho.eu (sender11-of-o51.zoho.eu [31.186.226.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD2442914 for ; Sun, 6 Nov 2022 15:24:44 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1667748272; cv=none; d=zohomail.eu; s=zohoarc; b=Soi33S8OBihtLkZa0PirQmJzPcBxgChSJ8iHm8CkfhjQs2t7XB8X29zu3306kjPpZ1feGtCHAXUoThAXGphNUW9xqsrXb4D0ErXR/Hg/N1NHToWwqVx0tOjyv5dtNQ8MH5UdQVINy65OLcFv85KUqgYW6pzMHxqiiMMFbLLVGoA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1667748272; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=908YXaLxbhrp0YVOiwCzAOurj4MBAAbzN8J7brMbQkE=; b=TtMh8mFheJI/46BTDidVOhk1nxyh+JuQSTMfYDh0LxpXoNReIbfLXBJzXySiz07twp7FiVKzWml65aglJhXSy8o5JwCfoAX0c9m08jxsRVlc5vB4ehJAw4jTqYrju2H2KqHgzW/xLtUZwIeVpsAZ3jTt/MrJUF1GfqnOL/E/ORk= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=shytyi.net; spf=pass smtp.mailfrom=dmytro@shytyi.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1667748272; s=hs; d=shytyi.net; i=dmytro@shytyi.net; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=908YXaLxbhrp0YVOiwCzAOurj4MBAAbzN8J7brMbQkE=; b=HVnMZJDR2V+nkbAsJXvU+vevnlyBcY1qbrLJKHTEnkhkuVbTQyON5z7xa7jkKn1b xI11azyZZinNyQo3IvF68Q3Bp+vEqPr0X/4+MGEnmofSaT4YGcUR8Maj2Tx2Ac+vAeD TkSNxiaSPnT6A6V8ox0uXa/OGHyyfApehK03yfq8= Received: from localhost.localdomain (vps-940813d4.vps.ovh.net [198.244.188.50]) by mx.zoho.eu with SMTPS id 1667748271052935.1242226072404; Sun, 6 Nov 2022 16:24:31 +0100 (CET) From: Dmytro Shytyi To: mptcp@lists.linux.dev Cc: Dmytro Shytyi Message-ID: <20221106152411.655-3-dmytro@shytyi.net> Subject: [RFC PATCH mptcp-next v15 2/5] mptcp: implement delayed seq generation for passive fastopen Date: Sun, 6 Nov 2022 15:24:08 +0000 X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221106152411.655-1-dmytro@shytyi.net> References: <20221106152411.655-1-dmytro@shytyi.net> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: Dmytro Shytyi --- net/mptcp/Makefile | 2 +- net/mptcp/fastopen.c | 19 +++++++++++++++++++ net/mptcp/options.c | 5 +++++ net/mptcp/protocol.h | 6 ++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 net/mptcp/fastopen.c diff --git a/net/mptcp/Makefile b/net/mptcp/Makefile index 8a7f68efa35f..c42ad8609876 100644 --- a/net/mptcp/Makefile +++ b/net/mptcp/Makefile @@ -2,7 +2,7 @@ obj-$(CONFIG_MPTCP) +=3D mptcp.o =20 mptcp-y :=3D protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o d= iag.o \ - mib.o pm_netlink.o sockopt.o pm_userspace.o sched.o + mib.o pm_netlink.o sockopt.o pm_userspace.o sched.o fastopen.o =20 obj-$(CONFIG_SYN_COOKIES) +=3D syncookies.o obj-$(CONFIG_INET_MPTCP_DIAG) +=3D mptcp_diag.o diff --git a/net/mptcp/fastopen.c b/net/mptcp/fastopen.c new file mode 100644 index 000000000000..d6fb45e6be4f --- /dev/null +++ b/net/mptcp/fastopen.c @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 + * MPTCP Fast Open Mechanism. Copyright (c) 2021-2022, Dmytro SHYTYI + */ + +#include "protocol.h" + +void mptcp_gen_msk_ackseq_fastopen(struct mptcp_sock *msk, struct mptcp_su= bflow_context *subflow, + struct mptcp_options_received mp_opt) +{ + u64 ack_seq; + + WRITE_ONCE(msk->can_ack, true); + WRITE_ONCE(msk->remote_key, mp_opt.sndr_key); + mptcp_crypto_key_sha(msk->remote_key, NULL, &ack_seq); + ack_seq++; + WRITE_ONCE(msk->ack_seq, ack_seq); + pr_debug("ack_seq=3D%llu sndr_key=3D%llu", msk->ack_seq, mp_opt.sndr_key); + atomic64_set(&msk->rcv_wnd_sent, ack_seq); +} diff --git a/net/mptcp/options.c b/net/mptcp/options.c index 30d289044e71..0b6c4535750c 100644 --- a/net/mptcp/options.c +++ b/net/mptcp/options.c @@ -1208,6 +1208,11 @@ bool mptcp_incoming_options(struct sock *sk, struct = sk_buff *skb) mpext->dsn64 =3D 1; mpext->mpc_map =3D 1; mpext->data_fin =3D 0; + + if (msk->is_mptfo) { + mptcp_gen_msk_ackseq_fastopen(msk, subflow, mp_opt); + mpext->data_seq =3D READ_ONCE(msk->ack_seq); + } } else { mpext->data_seq =3D mp_opt.data_seq; mpext->subflow_seq =3D mp_opt.subflow_seq; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 2358a4083eb3..f4b6f817ec46 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -282,6 +282,7 @@ struct mptcp_sock { bool use_64bit_ack; /* Set when we received a 64-bit DSN */ bool csum_enabled; bool allow_infinite_fallback; + bool is_mptfo; u8 mpc_endpoint_id; u8 recvmsg_inq:1, cork:1, @@ -841,6 +842,11 @@ 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); =20 +// Fast Open Mechanism functions begin +void mptcp_gen_msk_ackseq_fastopen(struct mptcp_sock *msk, struct mptcp_su= bflow_context *subflow, + struct mptcp_options_received mp_opt); +// Fast Open Mechanism functions end + static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk) { return READ_ONCE(msk->pm.addr_signal) & --=20 2.34.1 From nobody Sat Dec 21 15:13:20 2024 Received: from sender11-of-o51.zoho.eu (sender11-of-o51.zoho.eu [31.186.226.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEDBB2916 for ; Sun, 6 Nov 2022 15:24:44 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1667748272; cv=none; d=zohomail.eu; s=zohoarc; b=dwUSmQwTDcXjqUtBRNwXZplV5+Tiq7RiFeqBuiuS3f2+SM2Sfrp4cQDp9KdF9yfub2MTTNaIZsqPEyhnQCj67Joi64qpRZlKlAQ+NfmX0OHErlgqqcBXyPyB7kWFpA937EzkJ2g4Wj/y4hnIPP5oEQSNyUcacGIPXsv6utglU74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1667748272; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=uBHnCaTPkCl9ptAXn/bUliRp2mKgDTipt1hXqdKTF7I=; b=iG5bMCY0bfqLz1zlEI/EILtTeXvlAPGESdZVZcGn0NxSjbKBRPRhEC4CpGNL8yXQOwEVIAoIG44U+Mx5UcgTPtvJPJWQ8SlIQyDznrkKQGmhUMnRf/MODHRkazxzh7K235lP8HFBWx0aGyzKjhSPQuMLIOe1KqbyAMvU99VrKzE= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=shytyi.net; spf=pass smtp.mailfrom=dmytro@shytyi.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1667748272; s=hs; d=shytyi.net; i=dmytro@shytyi.net; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=uBHnCaTPkCl9ptAXn/bUliRp2mKgDTipt1hXqdKTF7I=; b=TIvyYeo2wYAzIg3bKQZyLevzUmj5kzuLBe/fGIq3nLrDdS+cQYqWem4lU9wJ2Oft hv6HsT6+ea5RtdmvNjGA+dgUc1ycEQZ4c+nlZT/aXh5wNJ4n5k39AMdoPtCwgFkGl/B xMMG3zPu2xsW9zqnOMLsSITpC1Y0NmQ9Dr12K6vI= Received: from localhost.localdomain (vps-940813d4.vps.ovh.net [198.244.188.50]) by mx.zoho.eu with SMTPS id 1667748271351834.3852447482699; Sun, 6 Nov 2022 16:24:31 +0100 (CET) From: Dmytro Shytyi To: mptcp@lists.linux.dev Cc: Dmytro Shytyi Message-ID: <20221106152411.655-4-dmytro@shytyi.net> Subject: [RFC PATCH mptcp-next v15 3/5] mptcp: add subflow_v(4,6)_send_synack() Date: Sun, 6 Nov 2022 15:24:09 +0000 X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221106152411.655-1-dmytro@shytyi.net> References: <20221106152411.655-1-dmytro@shytyi.net> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" In this patch we add skb to the msk, dequeue it from sk, remove TSs and do skb mapping. Signed-off-by: Dmytro Shytyi --- net/mptcp/fastopen.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.c | 11 +---------- net/mptcp/protocol.h | 12 +++++++++++ net/mptcp/subflow.c | 42 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 10 deletions(-) diff --git a/net/mptcp/fastopen.c b/net/mptcp/fastopen.c index d6fb45e6be4f..2a36a83cd846 100644 --- a/net/mptcp/fastopen.c +++ b/net/mptcp/fastopen.c @@ -4,6 +4,53 @@ =20 #include "protocol.h" =20 +void subflow_fastopen_send_synack_set_params(struct mptcp_subflow_context = *subflow, + struct request_sock *req) +{ + struct tcp_request_sock *treq =3D tcp_rsk(req); + struct sock *ssk =3D subflow->tcp_sock; + struct sock *sk =3D subflow->conn; + struct mptcp_sock *msk; + struct sk_buff *skb; + struct tcp_sock *tp; + u32 offset; + + msk =3D mptcp_sk(sk); + tp =3D tcp_sk(ssk); + + /* mark subflow/msk as "mptfo" */ + msk->is_mptfo =3D 1; + + skb =3D skb_peek(&ssk->sk_receive_queue); + + /* dequeue the skb from sk receive queue */ + __skb_unlink(skb, &ssk->sk_receive_queue); + skb_ext_reset(skb); + skb_orphan(skb); + + /* set the skb mapping */ + tp->copied_seq +=3D tp->rcv_nxt - treq->rcv_isn - 1; + subflow->map_seq =3D mptcp_subflow_get_mapped_dsn(subflow); + subflow->ssn_offset =3D tp->copied_seq - 1; + + /* initialize MPTCP_CB */ + offset =3D tp->copied_seq - TCP_SKB_CB(skb)->seq; + MPTCP_SKB_CB(skb)->map_seq =3D mptcp_subflow_get_mapped_dsn(subflow); + MPTCP_SKB_CB(skb)->end_seq =3D MPTCP_SKB_CB(skb)->map_seq + + (skb->len - offset); + MPTCP_SKB_CB(skb)->offset =3D offset; + MPTCP_SKB_CB(skb)->has_rxtstamp =3D TCP_SKB_CB(skb)->has_rxtstamp; + + mptcp_data_lock(sk); + + mptcp_set_owner_r(skb, sk); + __skb_queue_tail(&msk->receive_queue, skb); + + (sk)->sk_data_ready(sk); + + mptcp_data_unlock(sk); +} + void mptcp_gen_msk_ackseq_fastopen(struct mptcp_sock *msk, struct mptcp_su= bflow_context *subflow, struct mptcp_options_received mp_opt) { diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index f4247218fd1b..bf04f4161070 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -36,15 +36,6 @@ struct mptcp6_sock { }; #endif =20 -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 =3D BIT(0), MPTCP_CMSG_INQ =3D BIT(1), @@ -200,7 +191,7 @@ static void mptcp_rfree(struct sk_buff *skb) mptcp_rmem_uncharge(sk, len); } =20 -static void mptcp_set_owner_r(struct sk_buff *skb, struct sock *sk) +void mptcp_set_owner_r(struct sk_buff *skb, struct sock *sk) { skb_orphan(skb); skb->sk =3D sk; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index f4b6f817ec46..b3dfd0dacde5 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -126,6 +126,15 @@ #define MPTCP_CONNECTED 6 #define MPTCP_RESET_SCHEDULER 7 =20 +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; @@ -845,6 +854,9 @@ bool mptcp_userspace_pm_active(const struct mptcp_sock = *msk); // Fast Open Mechanism functions begin void mptcp_gen_msk_ackseq_fastopen(struct mptcp_sock *msk, struct mptcp_su= bflow_context *subflow, struct mptcp_options_received mp_opt); +void mptcp_set_owner_r(struct sk_buff *skb, struct sock *sk); +void subflow_fastopen_send_synack_set_params(struct mptcp_subflow_context = *subflow, + struct request_sock *req); // Fast Open Mechanism functions end =20 static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk) diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 02a54d59697b..5e28b02822e4 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -307,7 +307,47 @@ static struct dst_entry *subflow_v4_route_req(const st= ruct sock *sk, return NULL; } =20 +static int subflow_v4_send_synack(const struct sock *sk, struct dst_entry = *dst, + struct flowi *fl, + struct request_sock *req, + struct tcp_fastopen_cookie *foc, + enum tcp_synack_type synack_type, + struct sk_buff *syn_skb) +{ + struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(sk); + struct inet_request_sock *ireq =3D inet_rsk(req); + + /* clear tstamp_ok, as needed depending on cookie */ + if (foc && foc->len > -1) + ireq->tstamp_ok =3D 0; + + if (synack_type =3D=3D TCP_SYNACK_FASTOPEN) + subflow_fastopen_send_synack_set_params(subflow, req); + + return tcp_request_sock_ipv4_ops.send_synack(sk, dst, fl, req, foc, synac= k_type, syn_skb); +} + #if IS_ENABLED(CONFIG_MPTCP_IPV6) +static int subflow_v6_send_synack(const struct sock *sk, struct dst_entry = *dst, + struct flowi *fl, + struct request_sock *req, + struct tcp_fastopen_cookie *foc, + enum tcp_synack_type synack_type, + struct sk_buff *syn_skb) +{ + struct mptcp_subflow_context *subflow =3D mptcp_subflow_ctx(sk); + struct inet_request_sock *ireq =3D inet_rsk(req); + + /* clear tstamp_ok, as needed depending on cookie */ + if (foc && foc->len > -1) + ireq->tstamp_ok =3D 0; + + if (synack_type =3D=3D TCP_SYNACK_FASTOPEN) + subflow_fastopen_send_synack_set_params(subflow, req); + + return tcp_request_sock_ipv6_ops.send_synack(sk, dst, fl, req, foc, synac= k_type, syn_skb); +} + static struct dst_entry *subflow_v6_route_req(const struct sock *sk, struct sk_buff *skb, struct flowi *fl, @@ -1927,6 +1967,7 @@ void __init mptcp_subflow_init(void) =20 subflow_request_sock_ipv4_ops =3D tcp_request_sock_ipv4_ops; subflow_request_sock_ipv4_ops.route_req =3D subflow_v4_route_req; + subflow_request_sock_ipv4_ops.send_synack =3D subflow_v4_send_synack; =20 subflow_specific =3D ipv4_specific; subflow_specific.conn_request =3D subflow_v4_conn_request; @@ -1940,6 +1981,7 @@ void __init mptcp_subflow_init(void) #if IS_ENABLED(CONFIG_MPTCP_IPV6) subflow_request_sock_ipv6_ops =3D tcp_request_sock_ipv6_ops; subflow_request_sock_ipv6_ops.route_req =3D subflow_v6_route_req; + subflow_request_sock_ipv6_ops.send_synack =3D subflow_v6_send_synack; =20 subflow_v6_specific =3D ipv6_specific; subflow_v6_specific.conn_request =3D subflow_v6_conn_request; --=20 2.34.1 From nobody Sat Dec 21 15:13:20 2024 Received: from sender11-of-o51.zoho.eu (sender11-of-o51.zoho.eu [31.186.226.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F07F028EC for ; Sun, 6 Nov 2022 15:24:43 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1667748272; cv=none; d=zohomail.eu; s=zohoarc; b=YKtHnP8ze+sP19l2GLjZWlSmy6oj19Z3hMZTrpur2u9sSJ8qJEYKxEiRqTCdBmyiDp4tTymRDeLtleanLVnDjPDA6eajVhICwrVax7ZrrUw/yfW4QE9GK+v3zgtF2+Wm9nl9P6TXK8iH/9X3UIWQvITCX2SBFci2r5E2hy932+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1667748272; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=pNu48RZme7ExKQiNWIIrnxNBbaEyThENQeRocKx8Nq8=; b=NLGrL7cgIZlfCkFHErt2P/pZcofy10pPrCC3X4Bq2YylV5OraM+g2o+bLqKF6S4jcJ7AUMurOmULFTX6PKKyN0YTrsH2XGWVkOTrK7OeXZq+LTC+c+NpIQ0su7QUC6dcyF2jNGKg9JlQzyAh27N8wCIkUBzbcM1j3+kz86inCGw= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=shytyi.net; spf=pass smtp.mailfrom=dmytro@shytyi.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1667748272; s=hs; d=shytyi.net; i=dmytro@shytyi.net; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=pNu48RZme7ExKQiNWIIrnxNBbaEyThENQeRocKx8Nq8=; b=KbQxGfAJPRaXCQFmbAmW9g5zd4fyi79o0VUJ3K9Ot5eJoLweRNr1VzaAbBLuqvSa 81LM8ygIYeZu5+QOuuX/IvB3ZiIRzl8VHY9kkLKHfj01jsAnb1IX5bXO73z5CQFI7fP 3PtzQas88tSmuqgQlhHW1dGnHllIijQ6Yc0ie67o= Received: from localhost.localdomain (vps-940813d4.vps.ovh.net [198.244.188.50]) by mx.zoho.eu with SMTPS id 1667748271700597.0738033975198; Sun, 6 Nov 2022 16:24:31 +0100 (CET) From: Dmytro Shytyi To: mptcp@lists.linux.dev Cc: Dmytro Shytyi Message-ID: <20221106152411.655-5-dmytro@shytyi.net> Subject: [RFC PATCH mptcp-next v15 4/5] mptcp: add TCP_FASTOPEN sock option Date: Sun, 6 Nov 2022 15:24:10 +0000 X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221106152411.655-1-dmytro@shytyi.net> References: <20221106152411.655-1-dmytro@shytyi.net> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" We add the TCP_FASTOPEN socket option in this patch that is going to be set by the listener side. Signed-off-by: Dmytro Shytyi --- net/mptcp/sockopt.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index f85e9bbfe86f..7f6977295256 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -559,6 +559,7 @@ static bool mptcp_supported_sockopt(int level, int optn= ame) case TCP_NOTSENT_LOWAT: case TCP_TX_DELAY: case TCP_INQ: + case TCP_FASTOPEN: case TCP_FASTOPEN_CONNECT: case TCP_FASTOPEN_NO_COOKIE: return true; @@ -569,7 +570,7 @@ static bool mptcp_supported_sockopt(int level, int optn= ame) /* TCP_REPAIR, TCP_REPAIR_QUEUE, TCP_QUEUE_SEQ, TCP_REPAIR_OPTIONS, * TCP_REPAIR_WINDOW are not supported, better avoid this mess */ - /* TCP_FASTOPEN_KEY, TCP_FASTOPEN are not supported because + /* TCP_FASTOPEN_KEY is not supported because * fastopen for the listener side is currently unsupported */ } @@ -801,6 +802,7 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *= msk, int optname, /* See tcp.c: TCP_DEFER_ACCEPT does not fail */ mptcp_setsockopt_first_sf_only(msk, SOL_TCP, optname, optval, optlen); return 0; + case TCP_FASTOPEN: case TCP_FASTOPEN_CONNECT: case TCP_FASTOPEN_NO_COOKIE: return mptcp_setsockopt_first_sf_only(msk, SOL_TCP, optname, @@ -1166,6 +1168,7 @@ static int mptcp_getsockopt_sol_tcp(struct mptcp_sock= *msk, int optname, case TCP_INFO: case TCP_CC_INFO: case TCP_DEFER_ACCEPT: + case TCP_FASTOPEN: case TCP_FASTOPEN_CONNECT: case TCP_FASTOPEN_NO_COOKIE: return mptcp_getsockopt_first_sf_only(msk, SOL_TCP, optname, --=20 2.34.1 From nobody Sat Dec 21 15:13:20 2024 Received: from sender11-of-o51.zoho.eu (sender11-of-o51.zoho.eu [31.186.226.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7ED4F28EC for ; Sun, 6 Nov 2022 15:24:46 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1667748274; cv=none; d=zohomail.eu; s=zohoarc; b=ZAa/N68Tsi3gP2MtJpLIqPf3e4OxImpOJOJOEJZp9HXfHdAsoAIrjXoO55VMVVVt/9t7wA0VDZ9gNScnvMY8Utx/iqxurwwTMlAz81titANBoIZ2OfYHiCJZQsZC9vQgIjW15HiAqGj/HMg03dKZ/dLGhrYeJYoDeTPZGBAHJDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1667748274; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=J3HXM8Itg6QZp4idplxxdPXA4VyuWF3eP1i47bCh7rk=; b=fAmwU2V5nLRI/RaA+S9y7jqimlTrs+pMKaOtyA2pNV/sgUQp4Mn43ruPZUeWBZqQ9JfRbL5QAc1P+3Kr8aXBgbrmQM2Y7rjQC2GwA1vOTYNmX2BnjmfxUoXcPUf2e4N1bC5uc+rddXDeDAoPzrlBQsjUhO070EMcbKHfQtDmJ70= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=shytyi.net; spf=pass smtp.mailfrom=dmytro@shytyi.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1667748274; s=hs; d=shytyi.net; i=dmytro@shytyi.net; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=J3HXM8Itg6QZp4idplxxdPXA4VyuWF3eP1i47bCh7rk=; b=MgHEZk9uDvDrjH8buZPFZdShImy51eIw4ILn/DMx7MN5jk6YUBqyjLRSyy02y4bo 9sHFh3f9iFnrnnpDzcPb/JPEbCk3Q4JbexstiTSjmth94XHvkIhk1Rv0pnIyfpWCh6C 7/Tt0soFHpKVLe3/TUzM9NCqMCKUEAgW2HBCDt2w= Received: from localhost.localdomain (vps-940813d4.vps.ovh.net [198.244.188.50]) by mx.zoho.eu with SMTPS id 1667748272011923.596557633137; Sun, 6 Nov 2022 16:24:32 +0100 (CET) From: Dmytro Shytyi To: mptcp@lists.linux.dev Cc: Dmytro Shytyi Message-ID: <20221106152411.655-6-dmytro@shytyi.net> Subject: [RFC PATCH mptcp-next v15 5/5] selftests: mptcp: mptfo Initiator/Listener Date: Sun, 6 Nov 2022 15:24:11 +0000 X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221106152411.655-1-dmytro@shytyi.net> References: <20221106152411.655-1-dmytro@shytyi.net> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" This patch adds the selftests support for mptfo in mptcp_connect.c We introduce mptfo option, that sets "TCP_FASTOPEN" + "MSG_FASTOPEN" We call sendto() instead of connect(). Signed-off-by: Dmytro Shytyi --- .../selftests/net/mptcp/mptcp_connect.c | 121 +++++++++++++----- .../selftests/net/mptcp/mptcp_connect.sh | 21 +++ 2 files changed, 113 insertions(+), 29 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.c b/tools/test= ing/selftests/net/mptcp/mptcp_connect.c index e54653ea2ed4..4bc855159c52 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.c +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.c @@ -26,11 +26,13 @@ =20 #include #include +#include =20 -#include #include #include =20 + + extern int optind; =20 #ifndef IPPROTO_MPTCP @@ -83,6 +85,7 @@ struct cfg_cmsg_types { =20 struct cfg_sockopt_types { unsigned int transparent:1; + unsigned int mptfo:1; }; =20 struct tcp_inq_state { @@ -232,6 +235,14 @@ static void set_transparent(int fd, int pf) } } =20 +static void set_mptfo(int fd, int pf) +{ + int qlen =3D 25; + + if (setsockopt(fd, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen)) =3D=3D -1) + perror("TCP_FASTOPEN"); +} + static int do_ulp_so(int sock, const char *name) { return setsockopt(sock, IPPROTO_TCP, TCP_ULP, name, strlen(name)); @@ -300,6 +311,9 @@ static int sock_listen_mptcp(const char * const listena= ddr, if (cfg_sockopt_types.transparent) set_transparent(sock, pf); =20 + if (cfg_sockopt_types.mptfo) + set_mptfo(sock, pf); + if (bind(sock, a->ai_addr, a->ai_addrlen) =3D=3D 0) break; /* success */ =20 @@ -330,13 +344,18 @@ static int sock_listen_mptcp(const char * const liste= naddr, =20 static int sock_connect_mptcp(const char * const remoteaddr, const char * const port, int proto, - struct addrinfo **peer) + struct addrinfo **peer, + int infd, + unsigned int *woff) { struct addrinfo hints =3D { .ai_protocol =3D IPPROTO_TCP, .ai_socktype =3D SOCK_STREAM, }; struct addrinfo *a, *addr; + unsigned int wlen =3D 0; + int syn_copied =3D 0; + char wbuf[8192]; int sock =3D -1; =20 hints.ai_family =3D pf; @@ -354,14 +373,33 @@ static int sock_connect_mptcp(const char * const remo= teaddr, if (cfg_mark) set_mark(sock, cfg_mark); =20 - if (connect(sock, a->ai_addr, a->ai_addrlen) =3D=3D 0) { - *peer =3D a; - break; /* success */ - } + if (cfg_sockopt_types.mptfo) { + if (wlen =3D=3D 0) + wlen =3D read(infd, wbuf, sizeof(wbuf)); =20 - perror("connect()"); - close(sock); - sock =3D -1; + syn_copied =3D sendto(sock, wbuf, wlen, MSG_FASTOPEN, + a->ai_addr, a->ai_addrlen); + if (syn_copied) { + *woff =3D wlen; + *peer =3D a; + break; /* success */ + } + } else { + if (connect(sock, a->ai_addr, a->ai_addrlen) =3D=3D 0) { + *peer =3D a; + break; /* success */ + } + } + if (cfg_sockopt_types.mptfo) { + perror("sendto()"); + close(sock); + sock =3D -1; + } else { + + perror("connect()"); + close(sock); + sock =3D -1; + } } =20 freeaddrinfo(addr); @@ -571,13 +609,14 @@ static void shut_wr(int fd) shutdown(fd, SHUT_WR); } =20 -static int copyfd_io_poll(int infd, int peerfd, int outfd, bool *in_closed= _after_out) +static int copyfd_io_poll(int infd, int peerfd, int outfd, + bool *in_closed_after_out, unsigned int woff) { struct pollfd fds =3D { .fd =3D peerfd, .events =3D POLLIN | POLLOUT, }; - unsigned int woff =3D 0, wlen =3D 0, total_wlen =3D 0, total_rlen =3D 0; + unsigned int wlen =3D 0, total_wlen =3D 0, total_rlen =3D 0; char wbuf[8192]; =20 set_nonblock(peerfd, true); @@ -839,7 +878,7 @@ static int copyfd_io_sendfile(int infd, int peerfd, int= outfd, return err; } =20 -static int copyfd_io(int infd, int peerfd, int outfd, bool close_peerfd) +static int copyfd_io(int infd, int peerfd, int outfd, bool close_peerfd, u= nsigned int woff) { bool in_closed_after_out =3D false; struct timespec start, end; @@ -851,7 +890,7 @@ static int copyfd_io(int infd, int peerfd, int outfd, b= ool close_peerfd) =20 switch (cfg_mode) { case CFG_MODE_POLL: - ret =3D copyfd_io_poll(infd, peerfd, outfd, &in_closed_after_out); + ret =3D copyfd_io_poll(infd, peerfd, outfd, &in_closed_after_out, woff); break; =20 case CFG_MODE_MMAP: @@ -1033,7 +1072,7 @@ int main_loop_s(int listensock) =20 SOCK_TEST_TCPULP(remotesock, 0); =20 - copyfd_io(fd, remotesock, 1, true); + copyfd_io(fd, remotesock, 1, true, 0); } else { perror("accept"); return 1; @@ -1130,6 +1169,11 @@ static void parse_setsock_options(const char *name) return; } =20 + if (strncmp(name, "MPTFO", len) =3D=3D 0) { + cfg_sockopt_types.mptfo =3D 1; + return; + } + fprintf(stderr, "Unrecognized setsockopt option %s\n", name); exit(1); } @@ -1168,23 +1212,25 @@ int main_loop(void) { int fd, ret, fd_in =3D 0; struct addrinfo *peer; + unsigned int woff =3D 0; =20 - /* listener is ready. */ - fd =3D sock_connect_mptcp(cfg_host, cfg_port, cfg_sock_proto, &peer); - if (fd < 0) - return 2; - + if (!cfg_sockopt_types.mptfo) { + /* listener is ready. */ + fd =3D sock_connect_mptcp(cfg_host, cfg_port, cfg_sock_proto, &peer, 0, = 0); + if (fd < 0) + return 2; again: - check_getpeername_connect(fd); + check_getpeername_connect(fd); =20 - SOCK_TEST_TCPULP(fd, cfg_sock_proto); + SOCK_TEST_TCPULP(fd, cfg_sock_proto); =20 - if (cfg_rcvbuf) - set_rcvbuf(fd, cfg_rcvbuf); - if (cfg_sndbuf) - set_sndbuf(fd, cfg_sndbuf); - if (cfg_cmsg_types.cmsg_enabled) - apply_cmsg_types(fd, &cfg_cmsg_types); + if (cfg_rcvbuf) + set_rcvbuf(fd, cfg_rcvbuf); + if (cfg_sndbuf) + set_sndbuf(fd, cfg_sndbuf); + if (cfg_cmsg_types.cmsg_enabled) + apply_cmsg_types(fd, &cfg_cmsg_types); + } =20 if (cfg_input) { fd_in =3D open(cfg_input, O_RDONLY); @@ -1192,8 +1238,25 @@ int main_loop(void) xerror("can't open %s:%d", cfg_input, errno); } =20 - /* close the client socket open only if we are not going to reconnect */ - ret =3D copyfd_io(fd_in, fd, 1, 0); + if (cfg_sockopt_types.mptfo) { + /* sendto() instead of connect */ + fd =3D sock_connect_mptcp(cfg_host, cfg_port, cfg_sock_proto, &peer, fd_= in, &woff); + if (fd < 0) + return 2; + + check_getpeername_connect(fd); + + SOCK_TEST_TCPULP(fd, cfg_sock_proto); + + if (cfg_rcvbuf) + set_rcvbuf(fd, cfg_rcvbuf); + if (cfg_sndbuf) + set_sndbuf(fd, cfg_sndbuf); + if (cfg_cmsg_types.cmsg_enabled) + apply_cmsg_types(fd, &cfg_cmsg_types); + } + + ret =3D copyfd_io(fd_in, fd, 1, 0, 0); if (ret) return ret; =20 diff --git a/tools/testing/selftests/net/mptcp/mptcp_connect.sh b/tools/tes= ting/selftests/net/mptcp/mptcp_connect.sh index 621af6895f4d..60198b91a530 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_connect.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_connect.sh @@ -762,6 +762,23 @@ run_tests_peekmode() run_tests_lo "$ns1" "$ns1" dead:beef:1::1 1 "-P ${peekmode}" } =20 +run_tests_mptfo() +{ + echo "INFO: with MPTFO start" + ip netns exec "$ns1" sysctl -q net.ipv4.tcp_fastopen=3D2 + ip netns exec "$ns2" sysctl -q net.ipv4.tcp_fastopen=3D1 + + run_tests_lo "$ns1" "$ns2" 10.0.1.1 0 "-o MPTFO" + run_tests_lo "$ns1" "$ns2" 10.0.1.1 0 "-o MPTFO" + + run_tests_lo "$ns1" "$ns2" dead:beef:1::1 0 "-o MPTFO" + run_tests_lo "$ns1" "$ns2" dead:beef:1::1 0 "-o MPTFO" + + ip netns exec "$ns1" sysctl -q net.ipv4.tcp_fastopen=3D0 + ip netns exec "$ns2" sysctl -q net.ipv4.tcp_fastopen=3D0 + echo "INFO: with MPTFO end" +} + run_tests_disconnect() { local peekmode=3D"$1" @@ -901,6 +918,10 @@ run_tests_peekmode "saveWithPeek" run_tests_peekmode "saveAfterPeek" stop_if_error "Tests with peek mode have failed" =20 +# MPTFO (MultiPath TCP Fatopen tests) +run_tests_mptfo +stop_if_error "Tests with MPTFO have failed" + # connect to ns4 ip address, ns2 should intercept/proxy run_test_transparent 10.0.3.1 "tproxy ipv4" run_test_transparent dead:beef:3::1 "tproxy ipv6" --=20 2.34.1