mptcp: TCP_MD5SIG support
Subsystems (2)
Geliang Tang
reviewerv3 cover mptcp: TCP_MD5SIG support
From: Geliang Tang <[email protected]>
v3:
- limit the use of these options for listened and closed state.
- check the return value of __mptcp_try_fallback().
v2:
- trigger fallback to TCP.
- check CONFIG_TCP_MD5SIG.
- update MD5 comment.
- drop selftests, packetdrill tests will be added later.
This series introduces support for TCP_MD5SIG socket options in MPTCP along with code improvements:
Patch 1: Refactors TCP_MAXSEG getsockopt handling to improve code consistency
Patch 2: Adds setsockopt support for TCP_MD5SIG/TCP_MD5SIG_EXT (first subflow only)
Geliang Tang (2):
mptcp: Handle TCP_MAXSEG getsockopt in common case
mptcp: setsockopt support for TCP_MD5SIG
net/mptcp/sockopt.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH v3 1/2 mptcp: Handle TCP_MAXSEG getsockopt in common case
From: Geliang Tang <[email protected]>
This patch simplifies MPTCP's TCP_MAXSEG getsockopt handling by moving it to the common case where other TCP options are processed. Previously it was handled separately after the main switch statement.
The change:
- Moves TCP_MAXSEG case into the main switch block
- Removes redundant separate handling
- Maintains identical functionality
This improves code consistency without altering behavior.
--- net/mptcp/sockopt.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
net/mptcp/sockopt.c +1 -3
@@ -1433,6 +1433,7 @@ static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname,case TCP_FASTOPEN_CONNECT :case TCP_FASTOPEN_KEY :case TCP_FASTOPEN_NO_COOKIE : +case TCP_MAXSEG :return mptcp_getsockopt_first_sf_only (msk,SOL_TCP , optname, optval, optlen);case TCP_INQ :
@@ -1457,9 +1458,6 @@ static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname,return mptcp_put_int_option (msk, optval, optlen, msk->notsent_lowat);case TCP_IS_MPTCP :return mptcp_put_int_option (msk, optval, optlen,1 ); -case TCP_MAXSEG : -return mptcp_getsockopt_first_sf_only (msk,SOL_TCP , optname, - optval, optlen); }return -EOPNOTSUPP ; }
Signature · 1 line
2.48.1
Geliang Tang
reviewerPATCH v3 2/2 mptcp: setsockopt support for TCP_MD5SIG
In reply to Geliang TangFrom: Geliang Tang <[email protected]>
Supporting TCP_MD5 socket option is required when MPTCP is used by default when creating a socket, to keep the same behaviour as with TCP. TCP_MD5 is not compatible with MPTCP, and it will cause a fallback to TCP at the connection request, if MPTCP was requested. This then fixes a "regression" compared to TCP.
This patch adds setsockopt support for TCP_MD5SIG and TCP_MD5SIG_EXT options. The implementation:
- Allow setting these options (getsockopt remains unsupported)
- Apply them only to the first subflow
- Trigger fallback to TCP to maintain MD5 compatibility
Note that getsockopt for these options remains unsupported, consistent with TCP.
--- net/mptcp/sockopt.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
net/mptcp/sockopt.c +17 -2
@@ -13,6 +13,7 @@#include <net/tcp.h> #include <net/mptcp.h> #include "protocol.h" +#include "mib.h" #define MIN_INFO_OPTLEN_SIZE 16#define MIN_FULL_INFO_OPTLEN_SIZE 40
@@ -596,11 +597,12 @@ static bool mptcp_supported_sockopt(int level, int optname)case TCP_FASTOPEN_CONNECT :case TCP_FASTOPEN_KEY :case TCP_FASTOPEN_NO_COOKIE : +/* MD5 will force a fallback to TCP: OK to set while not connected */ +case TCP_MD5SIG : +case TCP_MD5SIG_EXT :return true; } -/* TCP_MD5SIG, TCP_MD5SIG_EXT are not supported, MD5 is not compatible with MPTCP */ -/* TCP_REPAIR, TCP_REPAIR_QUEUE, TCP_QUEUE_SEQ, TCP_REPAIR_OPTIONS, * TCP_REPAIR_WINDOW are not supported, better avoid this mess */
@@ -865,6 +867,19 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,case TCP_FASTOPEN_NO_COOKIE :return mptcp_setsockopt_first_sf_only (msk,SOL_TCP , optname, optval, optlen); +#ifdef CONFIG_TCP_MD5SIG +case TCP_MD5SIG : +case TCP_MD5SIG_EXT : +if (!((1 << sk->sk_state) & (TCPF_CLOSE |TCPF_LISTEN ))) +return -EINVAL ; + ret =mptcp_setsockopt_first_sf_only (msk,SOL_TCP , optname, + optval, optlen); +if (ret) +return ret; +if (!__mptcp_try_fallback (msk,MPTCP_MIB_MD5SIGFALLBACK )) +return -EINVAL ; +return 0 ; +#endif } ret =mptcp_get_int_option (msk, optval, optlen, &val);
Signature · 1 line
2.48.1
Matthieu Baerts
maintainerRe: [PATCH mptcp-next v3 2/2] mptcp: setsockopt support for TCP_MD5SIG
Hi Geliang,
Quoted 52 lines · Geliang Tang
From: Geliang Tang <[email protected]>
Supporting
TCP_MD5socket option is required when MPTCP is used by default when creating a socket, to keep the same behaviour as with TCP.TCP_MD5is not compatible with MPTCP, and it will cause a fallback to TCP at the connection request, if MPTCP was requested. This then fixes a "regression" compared to TCP.This patch adds setsockopt support for
TCP_MD5SIGandTCP_MD5SIG_EXToptions. The implementation:
- Allow setting these options (getsockopt remains unsupported)
- Apply them only to the first subflow
- Trigger fallback to TCP to maintain MD5 compatibilityNote that getsockopt for these options remains unsupported, consistent with TCP.
Fixes d9e4c1291810 ("mptcp: only admit explicitly supported sockopt")Signed-off-by Geliang Tang <[email protected]>--- net/mptcp/sockopt.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)net/mptcp/sockopt.c +4
-2@@ -13,6 +13,7 @@#include <net/tcp.h> #include <net/mptcp.h> #include "protocol.h" +#include "mib.h" #define MIN_INFO_OPTLEN_SIZE 16#define MIN_FULL_INFO_OPTLEN_SIZE 40@@ -596,11 +597,12 @@ static bool mptcp_supported_sockopt(int level, int optname)case TCP_FASTOPEN_CONNECT :case TCP_FASTOPEN_KEY :case TCP_FASTOPEN_NO_COOKIE : +/* MD5 will force a fallback to TCP: OK to set while not connected */ +case TCP_MD5SIG : +case TCP_MD5SIG_EXT :return true; } -/* TCP_MD5SIG, TCP_MD5SIG_EXT are not supported, MD5 is not compatible with MPTCP */ -/* TCP_REPAIR, TCP_REPAIR_QUEUE, TCP_QUEUE_SEQ, TCP_REPAIR_OPTIONS, * TCP_REPAIR_WINDOW are not supported, better avoid this mess */
net/mptcp/sockopt.c static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, · line 870
Quoted 4 lines
net/mptcp/sockopt.c +1
-0@@ -865,6 +867,19 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,case TCP_FASTOPEN_NO_COOKIE :return mptcp_setsockopt_first_sf_only (msk,SOL_TCP , optname, optval, optlen); +#ifdef CONFIG_TCP_MD5SIG
Do we need this? mptcp_setsockopt_first_sf_only() should return an error coming from tcp_setsockopt() if TCP_MD5SIG(_EXT) is not supported, no?
net/mptcp/sockopt.c static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, · line 874
Quoted 4 lines
net/mptcp/sockopt.c +4
-0+case TCP_MD5SIG : +case TCP_MD5SIG_EXT : +if (!((1 << sk->sk_state) & (TCPF_CLOSE |TCPF_LISTEN ))) +return -EINVAL ;
If I'm not mistaken, this check is not needed, because the same check will be done in mptcp_setsockopt_first_sf_only(): it should only change something on the first sufblow, before the connection, no?
net/mptcp/sockopt.c static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, · line 880
Quoted 6 lines
net/mptcp/sockopt.c +6
-0+ ret =mptcp_setsockopt_first_sf_only (msk,SOL_TCP , optname, + optval, optlen); +if (ret) +return ret; +if (!__mptcp_try_fallback (msk,MPTCP_MIB_MD5SIGFALLBACK )) +return -EINVAL ;
If the fallback is done before the connection, it should not fail. Maybe use WARN_ON_ONCE(!__mptcp_try_fallback(msk, <MIB>)) instead?
if (ret == 0)
WARN_ON_ONCE(!__mptcp_try_fallback(msk, <MIB>))
return ret;
net/mptcp/sockopt.c static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, · line 885
Quoted 5 lines
net/mptcp/sockopt.c +2
-0+return 0 ; +#endif } ret =mptcp_get_int_option (msk, optval, optlen, &val);
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.