mptcp: Fast Open: Initiator
Subsystems (3)
v11 cover mptcp: Fast Open: Initiator
These patches focus on the Initiator side.
These patches implement: sendto(..., ..., ..., MSG_FASTOPEN, ..., ...); We would like to credit Paulo Abeni, Mat Martineau, Matthieu Baerts and Benjamin Hesmans for advices and ideas that improved these patches. Without this collaboration this state of work would not be presented.
Origins of these patches were in the root of discovery of the possibility to _reuse the TCP FASTOPEN option in the linux upstream MPTCP_ (First commit was sent to the mailing list on 22 OCT 2021: see https://lore.kernel.org/mptcp/
[email protected]/').
Dmytro Shytyi (4):
mptcp: add mptcp_setsockopt_fastopen
mptcp: add mptcp_stream_connect to *.h
mptcp: add mptcp_subflow_conn_sock()
mptcp: reuse tcp_sendmsg_fastopen()
include/net/mptcp.h | 9 +++++++++ include/net/tcp.h | 3 +++ net/ipv4/tcp.c | 21 ++++++++++++++++----- net/mptcp/Makefile | 2 +- net/mptcp/fastopen.c | 37 +++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.c | 35 +++++++++++++++++++++++++++++++---- net/mptcp/protocol.h | 5 +++++ net/mptcp/sockopt.c | 3 +++ 8 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 net/mptcp/fastopen.c
Signature · 1 line
2.25.1
RFC PATCH v11 1/4 mptcp: add mptcp_setsockopt_fastopen
Add set MPTFO socket option for MPTCP. This option is needed for the listen socket to accept MPTFO.
--- net/mptcp/Makefile | 2 +- net/mptcp/fastopen.c | 37 +++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 5 +++++ net/mptcp/sockopt.c | 3 +++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 net/mptcp/fastopen.c
net/mptcp/Makefile +1 -1
@@ -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
net/mptcp/fastopen.c new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 +* MPTCP Fast Open Mechanism. Copyright (c) 2021-2022, Dmytro SHYTYI +*/ + +#include "protocol.h" + +int mptcp_setsockopt_sol_tcp_fastopen (struct mptcp_sock *msk,sockptr_t optval, +unsigned int optlen) +{ +struct sock *sk = (struct sock *)msk; +struct net *net =sock_net (sk); +struct socket *ssock; +struct sock *ssk; +int val; +int ret; + + ret =0 ; + +if (copy_from_sockptr (&val, optval,sizeof (val))) +return -EFAULT ; + + ssock =__mptcp_nmpc_socket (msk); + ssk = ssock->sk; + net =sock_net (ssk); +lock_sock (ssk); + +if (val >=0 && ((1 << ssk->sk_state) & (TCPF_CLOSE |TCPF_LISTEN ))) { +tcp_fastopen_init_key_once (net); +fastopen_queue_tune (ssk, val); + }else { + ret = -EINVAL ; + } + +release_sock (ssk); + +return ret; +}
net/mptcp/protocol.h +5 -0
@@ -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 +int mptcp_setsockopt_sol_tcp_fastopen (struct mptcp_sock *msk,sockptr_t optval, +unsigned int optlen); +// Fast Open Mechanism functions end +static inline bool mptcp_pm_should_add_signal (struct mptcp_sock *msk) { return READ_ONCE(msk->pm.addr_signal) &
net/mptcp/sockopt.c +3 -0
@@ -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 :return true; }
@@ -796,6 +797,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 : +return mptcp_setsockopt_sol_tcp_fastopen (msk, optval, optlen); }return -EOPNOTSUPP ;
Signature · 1 line
2.25.1
Paolo Abeni
maintainerRe: [RFC PATCH mptcp-next v11 1/4] mptcp: add mptcp_setsockopt_fastopen
Quoted 51 lines · Dmytro Shytyi
Add set MPTFO socket option for MPTCP. This option is needed for the listen socket to accept MPTFO.
Signed-off-by Dmytro Shytyi <[email protected]>--- net/mptcp/Makefile | 2 +- net/mptcp/fastopen.c | 37 +++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 5 +++++ net/mptcp/sockopt.c | 3 +++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 net/mptcp/fastopen.cnet/mptcp/Makefile +1
-1@@ -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.onet/mptcp/fastopen.c new file +19
-0@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 +* MPTCP Fast Open Mechanism. Copyright (c) 2021-2022, Dmytro SHYTYI +*/ + +#include "protocol.h" + +int mptcp_setsockopt_sol_tcp_fastopen (struct mptcp_sock *msk,sockptr_t optval, +unsigned int optlen) +{ +struct sock *sk = (struct sock *)msk; +struct net *net =sock_net (sk); +struct socket *ssock; +struct sock *ssk; +int val; +int ret; + + ret =0 ; + +if (copy_from_sockptr (&val, optval,sizeof (val)))
net/mptcp/fastopen.c line 29
Quoted 10 lines
net/mptcp/fastopen.c new file +10
-0+return -EFAULT ; + + ssock =__mptcp_nmpc_socket (msk); + ssk = ssock->sk; + net =sock_net (ssk); +lock_sock (ssk); + +if (val >=0 && ((1 << ssk->sk_state) & (TCPF_CLOSE |TCPF_LISTEN ))) { +tcp_fastopen_init_key_once (net); +fastopen_queue_tune (ssk, val);
Instead you could directly call:
return tcp_setsockopt(ssock->sk, SOL_TCP, TCP_FASTOPEN, optval, optlen);
Side note, we could add a generic helper to invoke tcp_setsockopt() on the mpc subflow, on the give tcp socket option, and reuse such helper
for: TCP_FASTOPEN, TCP_FASTOPEN_CONNECT, TCP_DEFER_ACCEPT... but that can/should be done later.
Cheers,
Paolo
Re: [RFC PATCH mptcp-next v11 1/4] mptcp: add mptcp_setsockopt_fastopen
Hi Dmytro, Paolo,
Quoted 25 lines · Paolo Abeni
Quoted 24 lines · Dmytro Shytyi
Add set MPTFO socket option for MPTCP. This option is needed for the listen socket to accept MPTFO.
Signed-off-by Dmytro Shytyi <[email protected]>--- net/mptcp/Makefile | 2 +- net/mptcp/fastopen.c | 37 +++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 5 +++++ net/mptcp/sockopt.c | 3 +++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 net/mptcp/fastopen.cnet/mptcp/Makefile +1
-1@@ -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
Quoted 16 lines
Quoted 8 lines
net/mptcp/Makefile +0
-0obj-$(CONFIG_SYN_COOKIES) += syncookies.o obj-$(CONFIG_INET_MPTCP_DIAG) += mptcp_diag.onet/mptcp/fastopen.c new file +0
-0net/mptcp/fastopen.c line 8
Quoted 8 lines
net/mptcp/fastopen.c new file +8
-0@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 +* MPTCP Fast Open Mechanism. Copyright (c) 2021-2022, Dmytro SHYTYI +*/ + +#include "protocol.h" + +int mptcp_setsockopt_sol_tcp_fastopen (struct mptcp_sock *msk,sockptr_t optval, +unsigned int optlen)
I think we should keep everything related to the sockoptions in net/mptcp/sockopt.c, no?
Quoted 6 lines
Quoted 6 lines
net/mptcp/fastopen.c new file +6
-0+{ +struct sock *sk = (struct sock *)msk; +struct net *net =sock_net (sk); +struct socket *ssock; +struct sock *ssk; +int val;
Quoted 8 lines
net/mptcp/fastopen.c line 22
Quoted 8 lines
net/mptcp/fastopen.c new file +8
-0+int ret; + + ret =0 ; + +if (copy_from_sockptr (&val, optval,sizeof (val))) +return -EFAULT ; + + ssock =__mptcp_nmpc_socket (msk);
'ssock' could be NULL if the setsockopt() is called once the connection has been established.
Quoted 11 lines
net/mptcp/fastopen.c line 29
Quoted 7 lines
net/mptcp/fastopen.c new file +7
-0+ ssk = ssock->sk; + net =sock_net (ssk); +lock_sock (ssk); + +if (val >=0 && ((1 << ssk->sk_state) & (TCPF_CLOSE |TCPF_LISTEN ))) { +tcp_fastopen_init_key_once (net); +fastopen_queue_tune (ssk, val);Instead you could directly call:
return tcp_setsockopt(ssock->sk, SOL_TCP, TCP_FASTOPEN, optval, optlen);
I agree, similar to TCP_FASTOPEN_CONNECT
Quoted 2 lines
Side note, we could add a generic helper to invoke
tcp_setsockopt()on the mpc subflow, on the give tcp socket option, and reuse such helper
Indeed. I was already looking at doing that when implementing TCP_FASTOPEN_NO_COOKIE. I can share a patch for this other sockopt and then you can re-use the new helper for this TCP_FASTOPEN.
Quoted 2 lines
for:
TCP_FASTOPEN,TCP_FASTOPEN_CONNECT,TCP_DEFER_ACCEPT... but that can/should be done later.
Note that for TCP_DEFER_ACCEPT, this is a special case because apparently, the setsockopt doesn't fail even if a connection has already been accepted.
@Dmytro: Two last things about the patch:
- you also need to support the 'read' side (getsockopt())
- if I'm not mistaken, this TCP_FASTOPEN option is only needed for the listener side, not for the sender, no?
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net
Re: [RFC PATCH mptcp-next v11 1/4] mptcp: add mptcp_setsockopt_fastopen
Hello Paolo, Matthieu,
Quoted 37 lines · Matthieu Baerts
Hi Dmytro, Paolo,
Quoted 34 lines · Paolo Abeni
Quoted 33 lines · Dmytro Shytyi
Add set MPTFO socket option for MPTCP. This option is needed for the listen socket to accept MPTFO.
Signed-off-by Dmytro Shytyi <[email protected]>--- net/mptcp/Makefile | 2 +- net/mptcp/fastopen.c | 37 +++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 5 +++++ net/mptcp/sockopt.c | 3 +++ 4 files changed, 46 insertions(+), 1 deletion(-)create mode 100644
net/mptcp/fastopen.cnet/mptcp/Makefile +1
-1@@ -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.onet/mptcp/fastopen.c new file +2
-0@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 +* MPTCP Fast Open Mechanism. Copyright (c) 2021-2022, Dmytro SHYTYI
Quoted 8 lines
Quoted 6 lines
net/mptcp/fastopen.c line 8
Quoted 6 lines
net/mptcp/fastopen.c new file +6
-0+*/ + +#include "protocol.h" + +int mptcp_setsockopt_sol_tcp_fastopen (struct mptcp_sock *msk,sockptr_t optval, +unsigned int optlen)I think we should keep everything related to the sockoptions in
net/mptcp/sockopt.c, no?
I have multiple functions that are related to fastopen in fastopen.c. Probably it is not a bad idea to to keep all fastopen details in one file?
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/mptcp/fastopen.c new file +8
-0+{ +struct sock *sk = (struct sock *)msk; +struct net *net =sock_net (sk); +struct socket *ssock; +struct sock *ssk; +int val; +int ret; +
Quoted 8 lines
Quoted 6 lines
net/mptcp/fastopen.c line 22
Quoted 6 lines
net/mptcp/fastopen.c new file +6
-0+ ret =0 ; + +if (copy_from_sockptr (&val, optval,sizeof (val))) +return -EFAULT ; + + ssock =__mptcp_nmpc_socket (msk);'ssock' could be NULL if the
setsockopt()is called once the connection has been established.
Thanks, in this case need to return error.
Quoted 9 lines
Quoted 9 lines
net/mptcp/fastopen.c line 29
Quoted 7 lines
net/mptcp/fastopen.c new file +7
-0+ ssk = ssock->sk; + net =sock_net (ssk); +lock_sock (ssk); + +if (val >=0 && ((1 << ssk->sk_state) & (TCPF_CLOSE |TCPF_LISTEN ))) { +tcp_fastopen_init_key_once (net); +fastopen_queue_tune (ssk, val);Instead you could directly call:
Quoted 3 lines
Quoted 1 line
return tcp_setsockopt(ssock->sk, SOL_TCP, TCP_FASTOPEN, optval, optlen);I agree, similar to
TCP_FASTOPEN_CONNECT
Indeed this is done here, when pass TCP_FASTOPEN (tcp.c - net/ipv4/tcp.c - Linux source code (v5.19.11) - Bootlin <https://elixir.bootlin.com/linux/latest/source/net/ipv4/tcp.c#L3636>)
So we could use directly as you both suggested.
Quoted 19 lines
Quoted 2 lines
Side note, we could add a generic helper to invoke
tcp_setsockopt()on the mpc subflow, on the give tcp socket option, and reuse such helperIndeed. I was already looking at doing that when implementing
TCP_FASTOPEN_NO_COOKIE. I can share a patch for this other sockopt and then you can re-use the new helper for thisTCP_FASTOPEN.Quoted 2 lines
for:
TCP_FASTOPEN,TCP_FASTOPEN_CONNECT,TCP_DEFER_ACCEPT... but that can/should be done later.Note that for
TCP_DEFER_ACCEPT, this is a special case because apparently, the setsockopt doesn't fail even if a connection has already been accepted.@Dmytro: Two last things about the patch:
- you also need to support the 'read' side (getsockopt())
- if I'm not mistaken, thisTCP_FASTOPENoption is only needed for the listener side, not for the sender, no?Cheers,
Matt
Re: [RFC PATCH mptcp-next v11 1/4] mptcp: add mptcp_setsockopt_fastopen
Hi Dmytro,
Quoted 50 lines · Dmytro Shytyi
Hello Paolo, Matthieu,
Quoted 37 lines · Matthieu Baerts
Hi Dmytro, Paolo,
Quoted 34 lines · Paolo Abeni
Quoted 33 lines · Dmytro Shytyi
Add set MPTFO socket option for MPTCP. This option is needed for the listen socket to accept MPTFO.
Signed-off-by Dmytro Shytyi <[email protected]>---
net/mptcp/Makefile | 2 +-
net/mptcp/fastopen.c| 37 +++++++++++++++++++++++++++++++++++++net/mptcp/protocol.h| 5 +++++
net/mptcp/sockopt.c | 3 +++4 files changed, 46 insertions(+), 1 deletion(-)create mode 100644
net/mptcp/fastopen.cnet/mptcp/Makefile +0
-0@@ -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.onet/mptcp/fastopen.c new file +3
-0@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 +* MPTCP Fast Open Mechanism. Copyright (c) 2021-2022, Dmytro SHYTYI +*/ Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
net/mptcp/fastopen.c new file +4
-0+ +#include "protocol.h" + +int mptcp_setsockopt_sol_tcp_fastopen(struct mptcp_sock *msk,
sockptr_toptval,
+ unsigned int optlen)I think we should keep everything related to the sockoptions in
net/mptcp/sockopt.c, no?
Quoted 2 lines
I have multiple functions that are related to fastopen in
fastopen.c. Probably it is not a bad idea to to keep all fastopen details in one file?
We already have a file dedicated to all socket options. I don't think we should have an exception for TFO, especially if there is nothing specific to TFO thanks to tcp_setsockopt().
Also, you can use the new mptcp_setsockopt_first_sf_only() helper I sent a few minutes ago on the ML. For TCP_FASTOPEN sockopt, you now need a commit similar to "mptcp: add TCP_FASTOPEN_NO_COOKIE support" by just adding "TCP_FASTOPEN" in three different places in sockopt.c, see:
https://lore.kernel.org/mptcp/[email protected]/T/
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net
Re: [RFC PATCH mptcp-next v11 1/4] mptcp: add mptcp_setsockopt_fastopen
Hello,
Quoted 52 lines · Matthieu Baerts
Hi Dmytro,
Quoted 49 lines · Dmytro Shytyi
Hello Paolo, Matthieu,
Quoted 45 lines · Matthieu Baerts
Hi Dmytro, Paolo,
Quoted 32 lines · Paolo Abeni
Quoted 31 lines · Dmytro Shytyi
Add set MPTFO socket option for MPTCP. This option is needed for the listen socket to accept MPTFO.
Signed-off-by Dmytro Shytyi <[email protected]>--- net/mptcp/Makefile | 2 +- net/mptcp/fastopen.c | 37 +++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 5 +++++ net/mptcp/sockopt.c | 3 +++ 4 files changed, 46 insertions(+), 1 deletion(-)create mode 100644
net/mptcp/fastopen.cnet/mptcp/Makefile +1
-1@@ -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.onet/mptcp/fastopen.c new file +1
-0@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 Quoted 8 lines
Quoted 8 lines
net/mptcp/fastopen.c new file +6
-0+* MPTCP Fast Open Mechanism. Copyright (c) 2021-2022, Dmytro SHYTYI +*/ + +#include "protocol.h" + +int mptcp_setsockopt_sol_tcp_fastopen(struct mptcp_sock *msk,
sockptr_toptval,
+ unsigned int optlen)I think we should keep everything related to the sockoptions in
net/mptcp/sockopt.c, no?
Quoted 5 lines
Quoted 2 lines
I have multiple functions that are related to fastopen in
fastopen.c. Probably it is not a bad idea to to keep all fastopen details in one file?We already have a file dedicated to all socket options. I don't think we should have an exception for TFO, especially if there is nothing specific to TFO thanks to
tcp_setsockopt().
Okay.
Quoted 7 lines
Also, you can use the new
mptcp_setsockopt_first_sf_only()helper I sent a few minutes ago on the ML. ForTCP_FASTOPENsockopt, you now need a commit similar to "mptcp: addTCP_FASTOPEN_NO_COOKIEsupport" by just adding "TCP_FASTOPEN" in three different places insockopt.c, see:
Thanks!
Quoted 2 lines
Cheers,
Matt
RFC PATCH v11 2/4 mptcp: add mptcp_stream_connect to *.h
In reply to Dmytro ShytyiIn the following patches we will call mptcp_stream_connect() from function tcp_sendmsg_fastopen() in file "net/ipv4/tcp.c", thus make such symbol visible.
--- include/net/mptcp.h | 8 ++++++++ net/mptcp/protocol.c | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-)
include/net/mptcp.h +8 -0
@@ -150,6 +150,7 @@ void mptcp_write_options(struct tcphdr *th, __be32 *ptr, struct tcp_sock *tp, struct mptcp_out_options *opts);void mptcp_diag_fill_info (struct mptcp_sock *msk,struct mptcp_info *info); +int mptcp_stream_connect (struct socket *sock,struct sockaddr *uaddr,int addr_len,int flags);/* move the skb extension owership, with the assumption that 'to' is * newly allocated
@@ -286,6 +287,13 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,static inline void mptcp_space (const struct sock *ssk,int *s,int *fs) { }static inline void mptcp_seq_show (struct seq_file *seq) { } +static inline int mptcp_stream_connect (struct socket *sock, +struct sockaddr *uaddr, +int addr_len, +int flags) +{ + +} static inline int mptcp_subflow_init_cookie_req(struct request_sock *req, const struct sock *sk_listener,
net/mptcp/protocol.c +2 -2
@@ -3543,8 +3543,8 @@ static void mptcp_subflow_early_fallback(struct mptcp_sock *msk,__mptcp_do_fallback (msk); } -static int mptcp_stream_connect (struct socket *sock,struct sockaddr *uaddr, -int addr_len,int flags) +int mptcp_stream_connect (struct socket *sock,struct sockaddr *uaddr, +int addr_len,int flags) {struct mptcp_sock *msk =mptcp_sk (sock->sk);struct mptcp_subflow_context *subflow;
Signature · 1 line
2.25.1
RFC PATCH v11 3/4 mptcp: add mptcp_subflow_conn_sock()
In reply to Dmytro ShytyiIn the following patches we will call mptcp_subflow_conn_sock() from tcp_sendmsg_fastopen() in file "net/ipv4/tcp.c", thus make such symbol visible.
--- include/net/mptcp.h | 1 + net/ipv4/tcp.c | 15 +++++++++++++-- net/mptcp/protocol.c | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-)
include/net/mptcp.h +1 -0
@@ -151,6 +151,7 @@ void mptcp_write_options(struct tcphdr *th, __be32 *ptr, struct tcp_sock *tp,void mptcp_diag_fill_info (struct mptcp_sock *msk,struct mptcp_info *info);int mptcp_stream_connect (struct socket *sock,struct sockaddr *uaddr,int addr_len,int flags); +struct sock *mptcp_subflow_conn_sock (struct sock *sk);/* move the skb extension owership, with the assumption that 'to' is * newly allocated
net/ipv4/tcp.c +13 -2
@@ -1197,8 +1197,19 @@ static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, } } flags = (msg->msg_flags &MSG_DONTWAIT ) ?O_NONBLOCK :0 ; - err =__inet_stream_connect (sk->sk_socket, uaddr, - msg->msg_namelen, flags,1 ); +if (!sk_is_mptcp (sk)) { + err =__inet_stream_connect (sk->sk_socket, uaddr, + msg->msg_namelen, flags,1 ); + }else { +struct sock *parent =mptcp_subflow_conn_sock (sk); + +release_sock (sk); +release_sock (parent); + err =mptcp_stream_connect (sk->sk_socket, uaddr, + msg->msg_namelen, msg->msg_flags); +lock_sock (parent); +lock_sock (sk); + }/* fastopen_req could already be freed in __inet_stream_connect * if the connection times out or gets rst */
net/mptcp/protocol.c +6 -0
@@ -58,6 +58,12 @@ static void __mptcp_check_send_data_fin(struct sock *sk); DEFINE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions);static struct net_device mptcp_napi_dev; +struct sock * +mptcp_subflow_conn_sock (struct sock *sk) +{ +return ((mptcp_subflow_ctx (sk))->conn); +} +/* If msk has an initial subflow socket, and the MP_CAPABLE handshake has not * completed yet or has failed, return the subflow socket. * Otherwise return NULL.
Signature · 1 line
2.25.1
Re: [RFC PATCH mptcp-next v11 3/4] mptcp: add mptcp_subflow_conn_sock()
Hi Dmytro,
Quoted 3 lines · Dmytro Shytyi
In the following patches we will call
mptcp_subflow_conn_sock()fromtcp_sendmsg_fastopen()in file "net/ipv4/tcp.c", thus make such symbol visible.
The patch description and title don't seem to be correct. You are doing more than that here.
net/ipv4/tcp.c static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, · line 1202
Quoted 13 lines
net/ipv4/tcp.c +3
-2@@ -1197,8 +1197,19 @@ static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, } } flags = (msg->msg_flags &MSG_DONTWAIT ) ?O_NONBLOCK :0 ; - err =__inet_stream_connect (sk->sk_socket, uaddr, - msg->msg_namelen, flags,1 ); +if (!sk_is_mptcp (sk)) { + err =__inet_stream_connect (sk->sk_socket, uaddr, + msg->msg_namelen, flags,1 );
Do you think it could be possible not to modify tcp_sendmsg_fastopen() but instead implement '.connect' callback in 'mptcp_prot'?
net/ipv4/tcp.c static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, · line 1207
Quoted 5 lines
net/ipv4/tcp.c +5
-0+ }else { +struct sock *parent =mptcp_subflow_conn_sock (sk); + +release_sock (sk); +release_sock (parent);
It looks strange to release sockets because, I guess, they are going to be re-lock just after. It certainly means you want to call a (new) function which is not doing this locking bit, no?
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net
Re: [RFC PATCH mptcp-next v11 3/4] mptcp: add mptcp_subflow_conn_sock()
Hello Matthieu,
Quoted 8 lines · Matthieu Baerts
Hi Dmytro,
Quoted 3 lines · Dmytro Shytyi
In the following patches we will call
mptcp_subflow_conn_sock()fromtcp_sendmsg_fastopen()in file "net/ipv4/tcp.c", thus make such symbol visible.The patch description and title don't seem to be correct. You are doing more than that here.
Thanks, I deleted this patch in next version.
Quoted 17 lines
net/ipv4/tcp.c static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, · line 1202
Quoted 13 lines
net/ipv4/tcp.c +3
-2@@ -1197,8 +1197,19 @@ static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, } } flags = (msg->msg_flags &MSG_DONTWAIT ) ?O_NONBLOCK :0 ; - err =__inet_stream_connect (sk->sk_socket, uaddr, - msg->msg_namelen, flags,1 ); +if (!sk_is_mptcp (sk)) { + err =__inet_stream_connect (sk->sk_socket, uaddr, + msg->msg_namelen, flags,1 );Do you think it could be possible not to modify
tcp_sendmsg_fastopen()but instead implement '.connect' callback in 'mptcp_prot'?
Quoted 8 lines
net/ipv4/tcp.c static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, · line 1207
Quoted 5 lines
net/ipv4/tcp.c +5
-0+ }else { +struct sock *parent =mptcp_subflow_conn_sock (sk); + +release_sock (sk); +release_sock (parent);It looks strange to release sockets because, I guess, they are going to be re-lock just after. It certainly means you want to call a (new) function which is not doing this locking bit, no?
No need to address this question, as I deleted this patch in new version.
Quoted 2 lines
Cheers,
Matt\
Thanks.
Dmytro.
RFC PATCH v11 4/4 mptcp: reuse tcp_sendmsg_fastopen()
In reply to Dmytro ShytyiIn the following patches we will reuse modified tcp_sendmsg_fastopen(). We call it from mptcp_sendmsg().
--- include/net/tcp.h | 3 +++ net/ipv4/tcp.c | 6 +++--- net/mptcp/protocol.c | 25 +++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-)
include/net/tcp.h +3 -0
@@ -1755,6 +1755,9 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb,struct request_sock *req, struct tcp_fastopen_cookie *foc, const struct dst_entry *dst); +int tcp_sendmsg_fastopen (struct sock *sk,struct msghdr *msg, +int *copied,size_t size, +struct ubuf_info *uarg);void tcp_fastopen_init_key_once (struct net *net);bool tcp_fastopen_cookie_check (struct sock *sk,u16 *mss,struct tcp_fastopen_cookie *cookie);
net/ipv4/tcp.c +3 -3
@@ -1162,9 +1162,9 @@ 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);
net/mptcp/protocol.c +23 -2
@@ -1679,9 +1679,30 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)long timeo;/* we don't support FASTOPEN yet */ -if (msg->msg_flags &MSG_FASTOPEN ) -return -EOPNOTSUPP ; +if (msg->msg_flags &MSG_FASTOPEN ) { +struct socket *ssock; +struct sock *ssk; +lock_sock (sk); + + ssock =__mptcp_nmpc_socket (msk); + ssk = ssock->sk; + +lock_sock (ssk); + +if (ssock) { +int copied_syn_fastopen =0 ; + + ret =tcp_sendmsg_fastopen (ssk, msg, &copied_syn_fastopen, len,NULL ); + copied += copied_syn_fastopen; +if (ret) { +release_sock (ssk); + goto do_error; + } + } +release_sock (ssock->sk); +release_sock (sk); + }/* silently ignore everything else */ msg->msg_flags &=MSG_MORE |MSG_DONTWAIT |MSG_NOSIGNAL ;
Signature · 1 line
2.25.1
Paolo Abeni
maintainerRe: [RFC PATCH mptcp-next v11 4/4] mptcp: reuse tcp_sendmsg_fastopen()
Hello,
Quoted 68 lines · Dmytro Shytyi
In the following patches we will reuse modified
tcp_sendmsg_fastopen(). We call it frommptcp_sendmsg().Signed-of-by Benjamin Hesmans <[email protected]>Signed-off-by Dmytro Shytyi <[email protected]>--- include/net/tcp.h | 3 +++ net/ipv4/tcp.c | 6 +++--- net/mptcp/protocol.c | 25 +++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-)include/net/tcp.h +3
-0@@ -1755,6 +1755,9 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb,struct request_sock *req, struct tcp_fastopen_cookie *foc, const struct dst_entry *dst); +int tcp_sendmsg_fastopen (struct sock *sk,struct msghdr *msg, +int *copied,size_t size, +struct ubuf_info *uarg);void tcp_fastopen_init_key_once (struct net *net);bool tcp_fastopen_cookie_check (struct sock *sk,u16 *mss,struct tcp_fastopen_cookie *cookie);net/ipv4/tcp.c +3
-3@@ -1162,9 +1162,9 @@ 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);net/mptcp/protocol.c +15
-2@@ -1679,9 +1679,30 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)long timeo;/* we don't support FASTOPEN yet */ -if (msg->msg_flags &MSG_FASTOPEN ) -return -EOPNOTSUPP ; +if (msg->msg_flags &MSG_FASTOPEN ) { +struct socket *ssock; +struct sock *ssk; +lock_sock (sk); + + ssock =__mptcp_nmpc_socket (msk); + ssk = ssock->sk; + +lock_sock (ssk); + +if (ssock) { +int copied_syn_fastopen =0 ; + + ret =tcp_sendmsg_fastopen (ssk, msg, &copied_syn_fastopen, len,NULL ); + copied += copied_syn_fastopen;
net/mptcp/protocol.c static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) · line 1707
Quoted 10 lines
net/mptcp/protocol.c +8
-0+if (ret) { +release_sock (ssk); + goto do_error; + } + } +release_sock (ssock->sk); +release_sock (sk); + }/* silently ignore everything else */ msg->msg_flags &=MSG_MORE |MSG_DONTWAIT |MSG_NOSIGNAL ;
the above/previous patches duplicate quit a bit of code. Instead the following should be enough (replacing patches 2, 3, 4 here):
---
net/mptcp/protocol.c +3 -6
@@ -1673,17 +1673,14 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)int ret =0 ;long timeo; -/* we don't support FASTOPEN yet */ -if (msg->msg_flags &MSG_FASTOPEN ) -return -EOPNOTSUPP ; -/* silently ignore everything else */ - msg->msg_flags &=MSG_MORE |MSG_DONTWAIT |MSG_NOSIGNAL ; + msg->msg_flags &=MSG_MORE |MSG_DONTWAIT |MSG_NOSIGNAL |MSG_FASTOPEN ;lock_sock (sk); ssock =__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 )) {struct sock *ssk = ssock->sk;int copied_syn =0 ;
Re: [RFC PATCH mptcp-next v11 4/4] mptcp: reuse tcp_sendmsg_fastopen()
Hello,
Quoted 75 lines · Paolo Abeni
Hello,
Quoted 72 lines · Dmytro Shytyi
In the following patches we will reuse modified
tcp_sendmsg_fastopen(). We call it frommptcp_sendmsg().Signed-of-by Benjamin Hesmans <[email protected]>Signed-off-by Dmytro Shytyi <[email protected]>--- include/net/tcp.h | 3 +++ net/ipv4/tcp.c | 6 +++--- net/mptcp/protocol.c | 25 +++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-)include/net/tcp.h +3
-0@@ -1755,6 +1755,9 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb,struct request_sock *req, struct tcp_fastopen_cookie *foc, const struct dst_entry *dst); +int tcp_sendmsg_fastopen (struct sock *sk,struct msghdr *msg, +int *copied,size_t size, +struct ubuf_info *uarg);void tcp_fastopen_init_key_once (struct net *net);bool tcp_fastopen_cookie_check (struct sock *sk,u16 *mss,struct tcp_fastopen_cookie *cookie);net/ipv4/tcp.c +3
-3@@ -1162,9 +1162,9 @@ 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);net/mptcp/protocol.c +19
-2@@ -1679,9 +1679,30 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)long timeo;/* we don't support FASTOPEN yet */ -if (msg->msg_flags &MSG_FASTOPEN ) -return -EOPNOTSUPP ; +if (msg->msg_flags &MSG_FASTOPEN ) { +struct socket *ssock; +struct sock *ssk; +lock_sock (sk); + + ssock =__mptcp_nmpc_socket (msk); + ssk = ssock->sk; + +lock_sock (ssk); + +if (ssock) { +int copied_syn_fastopen =0 ; + + ret =tcp_sendmsg_fastopen (ssk, msg, &copied_syn_fastopen, len,NULL ); + copied += copied_syn_fastopen; +if (ret) { +release_sock (ssk); + goto do_error; + }
Quoted 8 lines
net/mptcp/protocol.c static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) · line 1707
Quoted 6 lines
net/mptcp/protocol.c +4
-0+ } +release_sock (ssock->sk); +release_sock (sk); + }/* silently ignore everything else */ msg->msg_flags &=MSG_MORE |MSG_DONTWAIT |MSG_NOSIGNAL ;the above/previous patches duplicate quit a bit of code. Instead the following should be enough (replacing patches 2, 3, 4 here):
Indeed. You are right. We could use this and seems like it works :)
Quoted 28 lines
---
net/mptcp/protocol.c +3
-6@@ -1673,17 +1673,14 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)int ret =0 ;long timeo; -/* we don't support FASTOPEN yet */ -if (msg->msg_flags &MSG_FASTOPEN ) -return -EOPNOTSUPP ; -/* silently ignore everything else */ - msg->msg_flags &=MSG_MORE |MSG_DONTWAIT |MSG_NOSIGNAL ; + msg->msg_flags &=MSG_MORE |MSG_DONTWAIT |MSG_NOSIGNAL |MSG_FASTOPEN ;lock_sock (sk); ssock =__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 )) {struct sock *ssk = ssock->sk;int copied_syn =0 ;
Paolo Abeni
maintainerQuoted 18 lines · Dmytro Shytyi
These patches focus on the Initiator side.
These patches implement:sendto(..., ..., ..., MSG_FASTOPEN, ..., ...); We would like to credit Paulo Abeni, Mat Martineau, Matthieu Baerts and Benjamin Hesmans for advices and ideas that improved these patches. Without this collaboration this state of work would not be presented.Origins of these patches were in the root of discovery of the possibility to
_reusethe TCP FASTOPEN option in the linux upstreamMPTCP_(First commit was sent to the mailing list on 22 OCT 2021: see https://lore.kernel.org/mptcp/
[email protected]/').Dmytro Shytyi (4):
mptcp: addmptcp_setsockopt_fastopen
mptcp: addmptcp_stream_connectto *.h
mptcp: addmptcp_subflow_conn_sock()
mptcp: reusetcp_sendmsg_fastopen()
Quoted 11 lines
include/net/mptcp.h | 9 +++++++++ include/net/tcp.h | 3 +++ net/ipv4/tcp.c | 21 ++++++++++++++++----- net/mptcp/Makefile | 2 +- net/mptcp/fastopen.c | 37 +++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.c | 35 +++++++++++++++++++++++++++++++---- net/mptcp/protocol.h | 5 +++++ net/mptcp/sockopt.c | 3 +++ 8 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 net/mptcp/fastopen.c
Plase, on the next iteration include the rx-path-related patches (e.g. patches 4, 5 and 6 from v9, updated with the relevant feedback).
Thanks,
Paolo
Hello Paolo,
I added the patches 4,5,6 from v9 and fixes based on the feedback. Will be present in the next version.
Quoted 38 lines · Paolo Abeni
Quoted 27 lines · Dmytro Shytyi
These patches focus on the Initiator side.
These patches implement:sendto(..., ..., ..., MSG_FASTOPEN, ..., ...); We would like to credit Paulo Abeni, Mat Martineau, Matthieu Baerts and Benjamin Hesmans for advices and ideas that improved these patches. Without this collaboration this state of work would not be presented.Origins of these patches were in the root of discovery of the possibility to
_reusethe TCP FASTOPEN option in the linux upstreamMPTCP_(First commit was sent to the mailing list on 22 OCT 2021: see https://lore.kernel.org/mptcp/
[email protected]/').Dmytro Shytyi (4):
mptcp: addmptcp_setsockopt_fastopen
mptcp: addmptcp_stream_connectto *.h
mptcp: addmptcp_subflow_conn_sock()
mptcp: reusetcp_sendmsg_fastopen()include/net/mptcp.h | 9 +++++++++ include/net/tcp.h | 3 +++ net/ipv4/tcp.c | 21 ++++++++++++++++----- net/mptcp/Makefile | 2 +- net/mptcp/fastopen.c | 37 +++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.c | 35 +++++++++++++++++++++++++++++++---- net/mptcp/protocol.h | 5 +++++ net/mptcp/sockopt.c | 3 +++ 8 files changed, 105 insertions(+), 10 deletions(-)Quoted 2 lines
create mode 100644
net/mptcp/fastopen.cPlase, on the next iteration include the rx-path-related patches (e.g. patches 4, 5 and 6 from v9, updated with the relevant feedback).
Thanks,
Paolo