mptcp.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/4] mptcp: MPTCP support for TCP_FASTOPEN_CONNECT
@ 2022-09-26 23:27 Mat Martineau
  2022-09-26 23:27 ` [PATCH net-next 1/4] mptcp: add TCP_FASTOPEN_CONNECT socket option Mat Martineau
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Mat Martineau @ 2022-09-26 23:27 UTC (permalink / raw)
  To: netdev
  Cc: Mat Martineau, davem, kuba, pabeni, edumazet, dmytro,
	benjamin.hesmans, matthieu.baerts, mptcp

RFC 8684 appendix B describes how to use TCP Fast Open with MPTCP. This
series allows TFO use with MPTCP using the TCP_FASTOPEN_CONNECT socket
option. The scope here is limited to the initiator of the connection -
support for MSG_FASTOPEN and the listener side of the connection will be
in a separate series. The preexisting TCP fastopen code does most of the
work, so these changes mostly involve plumbing MPTCP through to those
TCP functions.

Patch 1 changes the MPTCP socket option code to pass the
TCP_FASTOPEN_CONNECT option through to the initial unconnected subflow.

Patch 2 exports the existing tcp_sendmsg_fastopen() function from tcp.c

Patch 3 adds the call to tcp_sendmsg_fastopen() from the MPTCP send
function.

Patch 4 modifies mptcp_poll() to handle the deferred TFO connection.


Benjamin Hesmans (3):
  mptcp: add TCP_FASTOPEN_CONNECT socket option
  tcp: export tcp_sendmsg_fastopen
  mptcp: poll allow write call before actual connect

Dmytro Shytyi (1):
  mptcp: handle defer connect in mptcp_sendmsg

 include/net/tcp.h    |  2 ++
 net/ipv4/tcp.c       |  5 ++---
 net/mptcp/protocol.c | 26 ++++++++++++++++++++++++++
 net/mptcp/sockopt.c  | 19 ++++++++++++++++++-
 4 files changed, 48 insertions(+), 4 deletions(-)


base-commit: 4991931223e3b909aa4931face285e4658927824
-- 
2.37.3


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net-next 1/4] mptcp: add TCP_FASTOPEN_CONNECT socket option
  2022-09-26 23:27 [PATCH net-next 0/4] mptcp: MPTCP support for TCP_FASTOPEN_CONNECT Mat Martineau
@ 2022-09-26 23:27 ` Mat Martineau
  2022-09-26 23:27 ` [PATCH net-next 2/4] tcp: export tcp_sendmsg_fastopen Mat Martineau
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Mat Martineau @ 2022-09-26 23:27 UTC (permalink / raw)
  To: netdev
  Cc: Benjamin Hesmans, davem, kuba, pabeni, edumazet, dmytro,
	matthieu.baerts, mptcp, Mat Martineau

From: Benjamin Hesmans <benjamin.hesmans@tessares.net>

Set the option for the first subflow only. For the other subflows TFO
can't be used because a mapping would be needed to cover the data in the
SYN.

Acked-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Benjamin Hesmans <benjamin.hesmans@tessares.net>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
---
 net/mptcp/sockopt.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index 423d3826ca1e..c7cb68c725b2 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -559,6 +559,7 @@ static bool mptcp_supported_sockopt(int level, int optname)
 		case TCP_NOTSENT_LOWAT:
 		case TCP_TX_DELAY:
 		case TCP_INQ:
+		case TCP_FASTOPEN_CONNECT:
 			return true;
 		}
 
@@ -567,7 +568,7 @@ static bool mptcp_supported_sockopt(int level, int optname)
 		/* 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 TCP_FASTOPEN_CONNECT, TCP_FASTOPEN_NO_COOKIE,
+		/* TCP_FASTOPEN_KEY, TCP_FASTOPEN, TCP_FASTOPEN_NO_COOKIE,
 		 * are not supported fastopen is currently unsupported
 		 */
 	}
@@ -768,6 +769,19 @@ static int mptcp_setsockopt_sol_tcp_defer(struct mptcp_sock *msk, sockptr_t optv
 	return tcp_setsockopt(listener->sk, SOL_TCP, TCP_DEFER_ACCEPT, optval, optlen);
 }
 
+static int mptcp_setsockopt_sol_tcp_fastopen_connect(struct mptcp_sock *msk, sockptr_t optval,
+						     unsigned int optlen)
+{
+	struct socket *sock;
+
+	/* Limit to first subflow */
+	sock = __mptcp_nmpc_socket(msk);
+	if (!sock)
+		return -EINVAL;
+
+	return tcp_setsockopt(sock->sk, SOL_TCP, TCP_FASTOPEN_CONNECT, optval, optlen);
+}
+
 static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
 				    sockptr_t optval, unsigned int optlen)
 {
@@ -796,6 +810,8 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
 		return mptcp_setsockopt_sol_tcp_nodelay(msk, optval, optlen);
 	case TCP_DEFER_ACCEPT:
 		return mptcp_setsockopt_sol_tcp_defer(msk, optval, optlen);
+	case TCP_FASTOPEN_CONNECT:
+		return mptcp_setsockopt_sol_tcp_fastopen_connect(msk, optval, optlen);
 	}
 
 	return -EOPNOTSUPP;
@@ -1157,6 +1173,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_CONNECT:
 		return mptcp_getsockopt_first_sf_only(msk, SOL_TCP, optname,
 						      optval, optlen);
 	case TCP_INQ:
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 2/4] tcp: export tcp_sendmsg_fastopen
  2022-09-26 23:27 [PATCH net-next 0/4] mptcp: MPTCP support for TCP_FASTOPEN_CONNECT Mat Martineau
  2022-09-26 23:27 ` [PATCH net-next 1/4] mptcp: add TCP_FASTOPEN_CONNECT socket option Mat Martineau
@ 2022-09-26 23:27 ` Mat Martineau
  2022-09-26 23:27 ` [PATCH net-next 3/4] mptcp: handle defer connect in mptcp_sendmsg Mat Martineau
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Mat Martineau @ 2022-09-26 23:27 UTC (permalink / raw)
  To: netdev
  Cc: Benjamin Hesmans, davem, kuba, pabeni, edumazet, dmytro,
	matthieu.baerts, mptcp, Mat Martineau

From: Benjamin Hesmans <benjamin.hesmans@tessares.net>

It will be used to support TCP FastOpen with MPTCP in the following
commit.

Acked-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Co-developed-by: Dmytro Shytyi <dmytro@shytyi.net>
Signed-off-by: Dmytro Shytyi <dmytro@shytyi.net>
Signed-off-by: Benjamin Hesmans <benjamin.hesmans@tessares.net>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
---
 include/net/tcp.h | 2 ++
 net/ipv4/tcp.c    | 5 ++---
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/include/net/tcp.h b/include/net/tcp.h
index 27e8d378c70a..4f71cc15ff8e 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -327,6 +327,8 @@ void tcp_remove_empty_skb(struct sock *sk);
 int tcp_v4_tw_remember_stamp(struct inet_timewait_sock *tw);
 int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size);
 int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size);
+int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *copied,
+			 size_t size, struct ubuf_info *uarg);
 int tcp_sendpage(struct sock *sk, struct page *page, int offset, size_t size,
 		 int flags);
 int tcp_sendpage_locked(struct sock *sk, struct page *page, int offset,
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 5702ca9b952d..5237a3f08c94 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1162,9 +1162,8 @@ void tcp_free_fastopen_req(struct tcp_sock *tp)
 	}
 }
 
-static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
-				int *copied, size_t size,
-				struct ubuf_info *uarg)
+int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *copied,
+			 size_t size, struct ubuf_info *uarg)
 {
 	struct tcp_sock *tp = tcp_sk(sk);
 	struct inet_sock *inet = inet_sk(sk);
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 3/4] mptcp: handle defer connect in mptcp_sendmsg
  2022-09-26 23:27 [PATCH net-next 0/4] mptcp: MPTCP support for TCP_FASTOPEN_CONNECT Mat Martineau
  2022-09-26 23:27 ` [PATCH net-next 1/4] mptcp: add TCP_FASTOPEN_CONNECT socket option Mat Martineau
  2022-09-26 23:27 ` [PATCH net-next 2/4] tcp: export tcp_sendmsg_fastopen Mat Martineau
@ 2022-09-26 23:27 ` Mat Martineau
  2022-09-26 23:27 ` [PATCH net-next 4/4] mptcp: poll allow write call before actual connect Mat Martineau
  2022-09-29  2:20 ` [PATCH net-next 0/4] mptcp: MPTCP support for TCP_FASTOPEN_CONNECT patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Mat Martineau @ 2022-09-26 23:27 UTC (permalink / raw)
  To: netdev
  Cc: Dmytro Shytyi, davem, kuba, pabeni, edumazet, benjamin.hesmans,
	matthieu.baerts, mptcp, Mat Martineau

From: Dmytro Shytyi <dmytro@shytyi.net>

When TCP_FASTOPEN_CONNECT has been set on the socket before a connect,
the defer flag is set and must be handled when sendmsg is called.

This is similar to what is done in tcp_sendmsg_locked().

Acked-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Co-developed-by: Benjamin Hesmans <benjamin.hesmans@tessares.net>
Signed-off-by: Benjamin Hesmans <benjamin.hesmans@tessares.net>
Signed-off-by: Dmytro Shytyi <dmytro@shytyi.net>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
---
 net/mptcp/protocol.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 866dfad3cde6..fc753896caa0 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -1677,6 +1677,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 {
 	struct mptcp_sock *msk = mptcp_sk(sk);
 	struct page_frag *pfrag;
+	struct socket *ssock;
 	size_t copied = 0;
 	int ret = 0;
 	long timeo;
@@ -1690,6 +1691,27 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 
 	lock_sock(sk);
 
+	ssock = __mptcp_nmpc_socket(msk);
+	if (unlikely(ssock && inet_sk(ssock->sk)->defer_connect)) {
+		struct sock *ssk = ssock->sk;
+		int copied_syn = 0;
+
+		lock_sock(ssk);
+
+		ret = tcp_sendmsg_fastopen(ssk, msg, &copied_syn, len, NULL);
+		copied += copied_syn;
+		if (ret == -EINPROGRESS && copied_syn > 0) {
+			/* reflect the new state on the MPTCP socket */
+			inet_sk_state_store(sk, inet_sk_state_load(ssk));
+			release_sock(ssk);
+			goto out;
+		} else if (ret) {
+			release_sock(ssk);
+			goto out;
+		}
+		release_sock(ssk);
+	}
+
 	timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
 
 	if ((1 << sk->sk_state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) {
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next 4/4] mptcp: poll allow write call before actual connect
  2022-09-26 23:27 [PATCH net-next 0/4] mptcp: MPTCP support for TCP_FASTOPEN_CONNECT Mat Martineau
                   ` (2 preceding siblings ...)
  2022-09-26 23:27 ` [PATCH net-next 3/4] mptcp: handle defer connect in mptcp_sendmsg Mat Martineau
@ 2022-09-26 23:27 ` Mat Martineau
  2022-09-29  2:20 ` [PATCH net-next 0/4] mptcp: MPTCP support for TCP_FASTOPEN_CONNECT patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Mat Martineau @ 2022-09-26 23:27 UTC (permalink / raw)
  To: netdev
  Cc: Benjamin Hesmans, davem, kuba, pabeni, edumazet, dmytro,
	matthieu.baerts, mptcp, Mat Martineau

From: Benjamin Hesmans <benjamin.hesmans@tessares.net>

If fastopen is used, poll must allow a first write that will trigger
the SYN+data

Similar to what is done in tcp_poll().

Acked-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Benjamin Hesmans <benjamin.hesmans@tessares.net>
Signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com>
---
 net/mptcp/protocol.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index fc753896caa0..16c3a6fc347f 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -3548,6 +3548,7 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,
 
 do_connect:
 	err = ssock->ops->connect(ssock, uaddr, addr_len, flags);
+	inet_sk(sock->sk)->defer_connect = inet_sk(ssock->sk)->defer_connect;
 	sock->state = ssock->state;
 
 	/* on successful connect, the msk state will be moved to established by
@@ -3698,6 +3699,9 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock,
 	if (state != TCP_SYN_SENT && state != TCP_SYN_RECV) {
 		mask |= mptcp_check_readable(msk);
 		mask |= mptcp_check_writeable(msk);
+	} else if (state == TCP_SYN_SENT && inet_sk(sk)->defer_connect) {
+		/* cf tcp_poll() note about TFO */
+		mask |= EPOLLOUT | EPOLLWRNORM;
 	}
 	if (sk->sk_shutdown == SHUTDOWN_MASK || state == TCP_CLOSE)
 		mask |= EPOLLHUP;
-- 
2.37.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next 0/4] mptcp: MPTCP support for TCP_FASTOPEN_CONNECT
  2022-09-26 23:27 [PATCH net-next 0/4] mptcp: MPTCP support for TCP_FASTOPEN_CONNECT Mat Martineau
                   ` (3 preceding siblings ...)
  2022-09-26 23:27 ` [PATCH net-next 4/4] mptcp: poll allow write call before actual connect Mat Martineau
@ 2022-09-29  2:20 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-09-29  2:20 UTC (permalink / raw)
  To: Mat Martineau
  Cc: netdev, davem, kuba, pabeni, edumazet, dmytro, benjamin.hesmans,
	matthieu.baerts, mptcp

Hello:

This series was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 26 Sep 2022 16:27:35 -0700 you wrote:
> RFC 8684 appendix B describes how to use TCP Fast Open with MPTCP. This
> series allows TFO use with MPTCP using the TCP_FASTOPEN_CONNECT socket
> option. The scope here is limited to the initiator of the connection -
> support for MSG_FASTOPEN and the listener side of the connection will be
> in a separate series. The preexisting TCP fastopen code does most of the
> work, so these changes mostly involve plumbing MPTCP through to those
> TCP functions.
> 
> [...]

Here is the summary with links:
  - [net-next,1/4] mptcp: add TCP_FASTOPEN_CONNECT socket option
    https://git.kernel.org/netdev/net-next/c/54635bd04701
  - [net-next,2/4] tcp: export tcp_sendmsg_fastopen
    https://git.kernel.org/netdev/net-next/c/3242abeb8da7
  - [net-next,3/4] mptcp: handle defer connect in mptcp_sendmsg
    https://git.kernel.org/netdev/net-next/c/d98a82a6afc7
  - [net-next,4/4] mptcp: poll allow write call before actual connect
    https://git.kernel.org/netdev/net-next/c/a42cf9d18278

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-09-29  2:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-26 23:27 [PATCH net-next 0/4] mptcp: MPTCP support for TCP_FASTOPEN_CONNECT Mat Martineau
2022-09-26 23:27 ` [PATCH net-next 1/4] mptcp: add TCP_FASTOPEN_CONNECT socket option Mat Martineau
2022-09-26 23:27 ` [PATCH net-next 2/4] tcp: export tcp_sendmsg_fastopen Mat Martineau
2022-09-26 23:27 ` [PATCH net-next 3/4] mptcp: handle defer connect in mptcp_sendmsg Mat Martineau
2022-09-26 23:27 ` [PATCH net-next 4/4] mptcp: poll allow write call before actual connect Mat Martineau
2022-09-29  2:20 ` [PATCH net-next 0/4] mptcp: MPTCP support for TCP_FASTOPEN_CONNECT patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).