Skip to contentSkip to conversation

mptcp: sockopt: fix missing get options

PATCH In review Matthieu Baerts (NGI0) 3 participants 7 messages Mar 4, 2025 – Mar 5, 2025

Subsystems (2)
lore
Share & tools
lore

Matthieu Baerts (NGI0)

author maintainer
#0 lore raw

cover mptcp: sockopt: fix missing get options

When adding a socket option support in MPTCP, both the get and set parts are supposed to be implemented.

A few socket options had the 'set' part implemented, but not the 'get' part, while everything was in place to expose it, just the last step was missing. It looks like this was not intentional, and the 'get' support should have been present from the beginning, hence the 'Fixes' tags.

---
Matthieu Baerts (NGI0) (2):
mptcp: sockopt: fix getting IPV6_V6ONLY
mptcp: sockopt: fix getting freebind & transparent

 net/mptcp/sockopt.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

---
base-commit: b084c48057bbf45fbedc06d7a9d4ec417992fb1e
change-id: 20250303-mptcp-sockopt-missing-get-356e26dc6955

Best regards,

Signature · 1 line
Matthieu Baerts (NGI0) <[email protected]>
author maintainer
#1 lore raw

PATCH 1/2 mptcp: sockopt: fix getting IPV6_V6ONLY

When adding a socket option support in MPTCP, both the get and set parts are supposed to be implemented.

IPV6_V6ONLY support for the setsockopt part has been added a while ago, but it looks like the get part got forgotten. It should have been present as a way to verify a setting has been set as expected, and not to act differently from TCP or any other socket types.

Not supporting this getsockopt(IPV6_V6ONLY) blocks some apps which want to check the default value, before doing extra actions. On Linux, the default value is 0, but this can be changed with the net.ipv6.bindv6only sysctl knob. On Windows, it is set to 1 by default. So supporting the get part, like for all other socket options, is important.

Everything was in place to expose it, just the last step was missing. Only new code is added to cover this specific getsockopt(), that seems safe.

Fixes c9b95a135987 ("mptcp: support IPV6_V6ONLY setsockopt")
---
 net/mptcp/sockopt.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
net/mptcp/sockopt.c +16 -0
index 505445a9598fafa1cde6d8f4a1a8635c3e778051..4b99eb796855e4578d14df90f9d1cc3f1cd5b8c7 100644
@@ -1430,6 +1430,20 @@ static int mptcp_getsockopt_v4(struct mptcp_sock *msk, int optname,
 	return -EOPNOTSUPP;
 }
 
+static int mptcp_getsockopt_v6(struct mptcp_sock *msk, int optname,
+			       char __user *optval, int __user *optlen)
+{
+	struct sock *sk = (void *)msk;
+
+	switch (optname) {
+	case IPV6_V6ONLY:
+		return mptcp_put_int_option(msk, optval, optlen,
+					    sk->sk_ipv6only);
+	}
+
+	return -EOPNOTSUPP;
+}
+
 static int mptcp_getsockopt_sol_mptcp(struct mptcp_sock *msk, int optname,
 				      char __user *optval, int __user *optlen)
 {
@@ -1469,6 +1483,8 @@ int mptcp_getsockopt(struct sock *sk, int level, int optname,
 
 	if (level == SOL_IP)
 		return mptcp_getsockopt_v4(msk, optname, optval, option);
+	if (level == SOL_IPV6)
+		return mptcp_getsockopt_v6(msk, optname, optval, option);
 	if (level == SOL_TCP)
 		return mptcp_getsockopt_sol_tcp(msk, optname, optval, option);
 	if (level == SOL_MPTCP)
Signature · 1 line
2.47.1
author maintainer
#2 lore raw

PATCH 2/2 mptcp: sockopt: fix getting freebind & transparent

In reply to Matthieu Baerts (NGI0)

When adding a socket option support in MPTCP, both the get and set parts are supposed to be implemented.

IP(V6)_FREEBIND and IP(V6)_TRANSPARENT support for the setsockopt part has been added a while ago, but it looks like the get part got forgotten. It should have been present as a way to verify a setting has been set as expected, and not to act differently from TCP or any other socket types.

Everything was in place to expose it, just the last step was missing. Only new code is added to cover these specific getsockopt(), that seems safe.

Fixes c9406a23c116 ("mptcp: sockopt: add SOL_IP freebind & transparent options")
---
 net/mptcp/sockopt.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
net/mptcp/sockopt.c +12 -0
index 4b99eb796855e4578d14df90f9d1cc3f1cd5b8c7..3caa0a9d3b3885ce6399570f2d98a2e8f103638d 100644
@@ -1419,6 +1419,12 @@ static int mptcp_getsockopt_v4(struct mptcp_sock *msk, int optname,
 	switch (optname) {
 	case IP_TOS:
 		return mptcp_put_int_option(msk, optval, optlen, READ_ONCE(inet_sk(sk)->tos));
+	case IP_FREEBIND:
+		return mptcp_put_int_option(msk, optval, optlen,
+				inet_test_bit(FREEBIND, sk));
+	case IP_TRANSPARENT:
+		return mptcp_put_int_option(msk, optval, optlen,
+				inet_test_bit(TRANSPARENT, sk));
 	case IP_BIND_ADDRESS_NO_PORT:
 		return mptcp_put_int_option(msk, optval, optlen,
 				inet_test_bit(BIND_ADDRESS_NO_PORT, sk));
@@ -1439,6 +1445,12 @@ static int mptcp_getsockopt_v6(struct mptcp_sock *msk, int optname,
 	case IPV6_V6ONLY:
 		return mptcp_put_int_option(msk, optval, optlen,
 					    sk->sk_ipv6only);
+	case IPV6_TRANSPARENT:
+		return mptcp_put_int_option(msk, optval, optlen,
+					    inet_test_bit(TRANSPARENT, sk));
+	case IPV6_FREEBIND:
+		return mptcp_put_int_option(msk, optval, optlen,
+					    inet_test_bit(FREEBIND, sk));
 	}
 
 	return -EOPNOTSUPP;
Signature · 1 line
2.47.1
#3 lore raw
In reply to Matthieu Baerts (NGI0)

Hi Matthieu,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Unstable: 1 failed test(s): selftest_mptcp_connect 🔴
- KVM Validation: debug: Unstable: 1 failed test(s): packetdrill_mp_join 🔴
- KVM Validation: btf-normal (only bpftest_all): Unstable: 1 failed test(s): bpftest_test_progs-cpuv4_mptcp 🔴
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/13653022673

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/c0b81bfd0e61
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=940005

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

#4 lore raw
In reply to Matthieu Baerts (NGI0)

Hi Matthieu,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal: Unstable: 1 failed test(s): selftest_mptcp_connect 🔴
- KVM Validation: debug: Unstable: 1 failed test(s): selftest_mptcp_connect - Critical: Global Timeout ❌
- KVM Validation: btf-normal (only bpftest_all): Success! ✅
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/13653022673

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/c0b81bfd0e61
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=940005

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)

maintainer Reviewed-by on the v1 series
#5 lore raw
In reply to Matthieu Baerts (NGI0)
Quoted 14 lines · On Tue, 4 Mar 2025, Matthieu Baerts (NGI0) wrote:

When adding a socket option support in MPTCP, both the get and set parts are supposed to be implemented.

A few socket options had the 'set' part implemented, but not the 'get' part, while everything was in place to expose it, just the last step was missing. It looks like this was not intentional, and the 'get' support should have been present from the beginning, hence the 'Fixes' tags.

---
Matthieu Baerts (NGI0) (2):
mptcp: sockopt: fix getting IPV6_V6ONLY
mptcp: sockopt: fix getting freebind & transparent

Quoted 5 lines

net/mptcp/sockopt.c | 28 ++++++++++++++++++++++++++++

1 file changed, 28 insertions(+)

---
base-commit: b084c48057bbf45fbedc06d7a9d4ec417992fb1e
change-id: 20250303-mptcp-sockopt-missing-get-356e26dc6955

Hi Matthieu -

The series looks good to me:

author maintainer
#6 lore raw

Hi Mat,

Quoted 22 lines · Mat Martineau
Quoted 14 lines · On Tue, 4 Mar 2025, Matthieu Baerts (NGI0) wrote:

When adding a socket option support in MPTCP, both the get and set parts are supposed to be implemented.

A few socket options had the 'set' part implemented, but not the 'get' part, while everything was in place to expose it, just the last step was missing. It looks like this was not intentional, and the 'get' support should have been present from the beginning, hence the 'Fixes' tags.

---
Matthieu Baerts (NGI0) (2):
     mptcp: sockopt: fix getting IPV6_V6ONLY
     mptcp: sockopt: fix getting freebind & transparent

Quoted 5 lines

net/mptcp/sockopt.c | 28 ++++++++++++++++++++++++++++

1 file changed, 28 insertions(+)

---
base-commit: b084c48057bbf45fbedc06d7a9d4ec417992fb1e
change-id: 20250303-mptcp-sockopt-missing-get-356e26dc6955

Quoted 5 lines

Hi Matthieu -

The series looks good to me:

Thank you for the review!

Now in our tree (fixes for -net):

New patches for t/upstream-net and t/upstream:
- f5b862898d83: mptcp: sockopt: fix getting IPV6_V6ONLY
- 7e0ad93236c1: mptcp: sockopt: fix getting freebind & transparent
- Results: 74ce8fb51c46..f1d6b77be72d (export-net)
- Results: 0a1c12618a04..318c86579343 (export)

Tests are now in progress:

- export-net:
https://github.com/multipath-tcp/mptcp_net-next/commit/585fa1467b894289fe3c3ad009b203d1de00ad9a/checks
- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/4a4388014f7c410b33a39aac85c1ca6fe1b4907d/checks

Cheers,
Matt

Signature · 1 line
Sponsored by the NGI0 Core fund.