mptcp: sockopt: make sync_socket_options propagate SOCK_KEEPOPEN
Subsystems (3)
PATCH v2 1/1 mptcp: sockopt: make sync_socket_options propagate SOCK_KEEPOPEN
Users reported a scenario where MPTCP connections that were configured with SO_KEEPALIVE prior to connect would fail to enable their keepalives if MTPCP fell back to TCP mode.
After investigating, this affects keepalives for any connection where sync_socket_options is called on a socket that is in the closed or listening state. Joins are handled properly. For connects, sync_socket_options is called when the socket is still in the closed state. The tcp_set_keepalive() function does not act on sockets that are closed or listening, hence keepalive is not immediately enabled. Since the SO_KEEPOPEN flag is absent, it is not enabled later in the connect sequence via tcp_finish_connect. Setting the keepalive via sockopt after connect does work, but would not address any subsequently created flows.
Fortunately, the fix here is straight-forward: set SOCK_KEEPOPEN on the subflow when calling sync_socket_options.
The fix was valdidated both by using tcpdump to observe keepalive packets not being sent before the fix, and being sent after the fix. It was also possible to observe via ss that the keepalive timer was not enabled on these sockets before the fix, but was enabled afterwards.
---
v2:
- Ensure local variable declarations are in reverse-Christmas-tree style. (Feedback from Geliang Tang)
- Use keep_open instead of kaval; make type bool instead of int. (Feedback from Matthieu Baerts)
---
net/mptcp/sockopt.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
net/mptcp/sockopt.c +5 -6
@@ -1532,13 +1532,12 @@ static void sync_socket_options(struct mptcp_sock *msk, struct sock *ssk) {static const unsigned int tx_rx_locks =SOCK_RCVBUF_LOCK |SOCK_SNDBUF_LOCK ;struct sock *sk = (struct sock *)msk; +bool keep_open; -if (ssk->sk_prot->keepalive) { -if (sock_flag (sk,SOCK_KEEPOPEN )) - ssk->sk_prot->keepalive (ssk,1 ); -else - ssk->sk_prot->keepalive (ssk,0 ); - } + keep_open =sock_flag (sk,SOCK_KEEPOPEN ); +if (ssk->sk_prot->keepalive) + ssk->sk_prot->keepalive (ssk, keep_open); +sock_valbool_flag (ssk,SOCK_KEEPOPEN , keep_open); ssk->sk_priority = sk->sk_priority; ssk->sk_bound_dev_if = sk->sk_bound_dev_if;
base-commit: 319f7385f22c85618235ab0169b80092fa3c7696
Signature · 1 line
2.43.0
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 15 lines · On Mon, 8 Sep 2025 11:16:01 -0700 you wrote:
Users reported a scenario where MPTCP connections that were configured with
SO_KEEPALIVEprior to connect would fail to enable their keepalives if MTPCP fell back to TCP mode.After investigating, this affects keepalives for any connection where
sync_socket_optionsis called on a socket that is in the closed or listening state. Joins are handled properly. For connects,sync_socket_optionsis called when the socket is still in the closed state. Thetcp_set_keepalive()function does not act on sockets that are closed or listening, hence keepalive is not immediately enabled. Since theSO_KEEPOPENflag is absent, it is not enabled later in the connect sequence viatcp_finish_connect. Setting the keepalive via sockopt after connect does work, but would not address any subsequently created flows.
Quoted 1 line
[...]
Here is the summary with links:
- [net,v2] mptcp: sockopt: make sync_socket_options propagate SOCK_KEEPOPEN
https://git.kernel.org/netdev/net/c/648de37416b3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html