diff mbox series

[RFC,mptcp-next,v13,1/7] mptcp: add __mptcp_pre_connect() helper

Message ID 20221001031502.29152-2-dmytro@shytyi.net (mailing list archive)
State Superseded, archived
Delegated to: Paolo Abeni
Headers show
Series mptcp: Fast Open Mechanism | expand

Checks

Context Check Description
matttbe/checkpatch warning total: 0 errors, 3 warnings, 0 checks, 54 lines checked
matttbe/build success Build and static analysis OK
matttbe/KVM_Validation__normal warning Unstable: 2 failed test(s): selftest_mptcp_join selftest_mptfo
matttbe/KVM_Validation__debug warning Unstable: 2 failed test(s): packetdrill_add_addr selftest_mptfo

Commit Message

Dmytro Shytyi Oct. 1, 2022, 3:14 a.m. UTC
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 <dmytro@shytyi.net>
---
 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 mbox series

Patch

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) &