From patchwork Sat Oct 1 03:14:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Shytyi X-Patchwork-Id: 12996342 X-Patchwork-Delegate: pabeni@redhat.com 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 E1E991FBA for ; Sat, 1 Oct 2022 03:15:20 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1664594117; cv=none; d=zohomail.eu; s=zohoarc; b=cVfTp4a39Zx0k9wQuEXxxuoxb2oc8hx84DeX4yCpI+Vf6ZBbnnQEpxlrEVMF8w4vmgYx3JpnrNXDdM9sv3my7v9L8KjiAEzcaO+RkeBS/i5R5DzBknuPYaLQu5jF2CmqBV8AFOGWYKpE+5eypBGiM3ItJ4Q35v5BQnL7+ANYV2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1664594117; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=VqYP35xY/OK3vntT8aRgm9rT97ft5Aj3fACZNODN0lw=; b=FuBAAN7a9Dbgs9WD1YBfTsNFsrvSZakq4NXY9uBSk/Z4Cjxny73tH+ENtw6372lNtG/2OoeZObXgtYP9hs9ZaZlSUrf364ObRcwjmteitKcA60ntwdNVpEixZFmrBR3/824egu3ACox0OKEpdiDXQpz9EfOq0vlRAv5kcsP7qzI= 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=1664594117; 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=VqYP35xY/OK3vntT8aRgm9rT97ft5Aj3fACZNODN0lw=; b=gbDrJautx83aWqcjXTvzs3BxPbAoBiP4C/htekWN3zE9yVsY2SZXiZRwASRUD9i5 GXyRP4LCBkHLDsDo6d1J0zZ7eiXlMhoEmuJCZ5gjnOufTcaCOumITPLhImMaPEVrCt7 bAXDa0dRatw7i7MwdJyf41Ngi92ipL96CODpLhNM= Received: from localhost.localdomain (243.34.22.93.rev.sfr.net [93.22.34.243]) by mx.zoho.eu with SMTPS id 1664594115870263.49021903953735; Sat, 1 Oct 2022 05:15:15 +0200 (CEST) From: Dmytro Shytyi To: mptcp@lists.linux.dev Cc: Dmytro Shytyi Message-ID: <20221001031502.29152-2-dmytro@shytyi.net> Subject: [RFC PATCH mptcp-next v13 1/7] mptcp: add __mptcp_pre_connect() helper Date: Sat, 1 Oct 2022 03:14:56 +0000 X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221001031502.29152-1-dmytro@shytyi.net> References: <20221001031502.29152-1-dmytro@shytyi.net> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ZohoMailClient: External Set the fastopen_req inside the __mptcp_pre_connect() helper and call it in the mptcp_sendmsg(). Used together with the next patch. Signed-off-by: Dmytro Shytyi --- net/mptcp/Makefile | 2 +- net/mptcp/fastopen.c | 27 +++++++++++++++++++++++++++ net/mptcp/protocol.c | 2 ++ net/mptcp/protocol.h | 5 +++++ 4 files changed, 35 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) += 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 sched.o + mib.o pm_netlink.o sockopt.o pm_userspace.o sched.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..65a6a87c0079 --- /dev/null +++ b/net/mptcp/fastopen.c @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 + * MPTCP Fast Open Mechanism. Copyright (c) 2021-2022, Dmytro SHYTYI + */ + +#include "protocol.h" + +void __mptcp_pre_connect(struct mptcp_sock *msk, struct sock *ssk, + struct msghdr *msg, size_t size) +{ + struct tcp_sock *tp; + struct sk_buff *skb; + struct ubuf_info *uarg; + + lock_sock(ssk); + + tp = tcp_sk(ssk); + + skb = tcp_write_queue_tail(ssk); + uarg = msg_zerocopy_realloc(ssk, size, skb_zcopy(skb)); + tp->fastopen_req = kzalloc(sizeof(*tp->fastopen_req), + ssk->sk_allocation); + tp->fastopen_req->data = msg; + tp->fastopen_req->size = size; + tp->fastopen_req->uarg = uarg; + + release_sock(ssk); +} diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 8feb684408f7..b080237d9d7e 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -1688,6 +1688,8 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) int copied_syn = 0; lock_sock(ssk); + if (msg->msg_flags & MSG_FASTOPEN && sk->sk_state == TCP_CLOSE) + __mptcp_pre_connect(msk, ssk, msg, len); ret = tcp_sendmsg_fastopen(ssk, msg, &copied_syn, len, NULL); copied += copied_syn; diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 93c535440a5c..30c03c70fdeb 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -838,6 +838,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); +// Fast Open Mechanism functions begin +void __mptcp_pre_connect(struct mptcp_sock *msk, struct sock *ssk, + struct msghdr *msg, size_t len); +// Fast Open Mechanism functions end + static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk) { return READ_ONCE(msk->pm.addr_signal) &