Skip to content

Commit 8345a93

Browse files
kmjohansengregkh
authored andcommitted
mptcp: sockopt: make sync_socket_options propagate SOCK_KEEPOPEN
commit 648de37 upstream. 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. Fixes: 1b3e7ed ("mptcp: setsockopt: handle SO_KEEPALIVE and SO_PRIORITY") Cc: stable@vger.kernel.org Signed-off-by: Krister Johansen <kjlx@templeofstupid.com> Reviewed-by: Geliang Tang <geliang@kernel.org> Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org> Link: https://patch.msgid.link/aL8dYfPZrwedCIh9@templeofstupid.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e69f61b commit 8345a93

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

net/mptcp/sockopt.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,13 +1471,12 @@ static void sync_socket_options(struct mptcp_sock *msk, struct sock *ssk)
14711471
{
14721472
static const unsigned int tx_rx_locks = SOCK_RCVBUF_LOCK | SOCK_SNDBUF_LOCK;
14731473
struct sock *sk = (struct sock *)msk;
1474+
bool keep_open;
14741475

1475-
if (ssk->sk_prot->keepalive) {
1476-
if (sock_flag(sk, SOCK_KEEPOPEN))
1477-
ssk->sk_prot->keepalive(ssk, 1);
1478-
else
1479-
ssk->sk_prot->keepalive(ssk, 0);
1480-
}
1476+
keep_open = sock_flag(sk, SOCK_KEEPOPEN);
1477+
if (ssk->sk_prot->keepalive)
1478+
ssk->sk_prot->keepalive(ssk, keep_open);
1479+
sock_valbool_flag(ssk, SOCK_KEEPOPEN, keep_open);
14811480

14821481
ssk->sk_priority = sk->sk_priority;
14831482
ssk->sk_bound_dev_if = sk->sk_bound_dev_if;

0 commit comments

Comments
 (0)