more sockopts for ephemeral ports
Subsystems (3)
v3 cover more sockopts for ephemeral ports
Support useful sockopts that allow fine control over ephemeral port usage.
v3:
- Change patch 2/3 with regards to commit d9f28735af87 ("Use READ/WRITE_ONCE() for IP local_port_range.")
- Drop Mat's Reviewed-By tag in patch 2/3 because of changes
v2:
- Add patch 1/3 with function name change (Mat)
- Fixup checkpatch errors in patch 2/3 (Mat)
Maxim Galaganov (3):
mptcp: rename mptcp_setsockopt_sol_ip_set_transparent()
mptcp: sockopt: support IP_LOCAL_PORT_RANGE and
IP_BIND_ADDRESS_NO_PORT
selftests/net: add MPTCP coverage for IP_LOCAL_PORT_RANGE
net/mptcp/sockopt.c | 27 ++++++++++++++++--- .../selftests/net/ip_local_port_range.c | 12 +++++++++ 2 files changed, 35 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.0
PATCH v3 1/3 mptcp: rename mptcp_setsockopt_sol_ip_set_transparent()
Next patch extends this function so that it's not specific to IP_TRANSPARENT. Change function name to mptcp_setsockopt_sol_ip_set().
--- net/mptcp/sockopt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/mptcp/sockopt.c +3 -3
@@ -683,8 +683,8 @@ static int mptcp_setsockopt_sol_tcp_nodelay(struct mptcp_sock *msk, sockptr_t opreturn 0 ; } -static int mptcp_setsockopt_sol_ip_set_transparent (struct mptcp_sock *msk,int optname, -sockptr_t optval,unsigned int optlen) +static int mptcp_setsockopt_sol_ip_set (struct mptcp_sock *msk,int optname, +sockptr_t optval,unsigned int optlen) {struct sock *sk = (struct sock *)msk;struct sock *ssk;
@@ -755,7 +755,7 @@ static int mptcp_setsockopt_v4(struct mptcp_sock *msk, int optname,switch (optname) {case IP_FREEBIND :case IP_TRANSPARENT : -return mptcp_setsockopt_sol_ip_set_transparent (msk, optname, optval, optlen); +return mptcp_setsockopt_sol_ip_set (msk, optname, optval, optlen);case IP_TOS :return mptcp_setsockopt_v4_set_tos (msk, optname, optval, optlen); }
Signature · 1 line
2.43.0
PATCH v3 2/3 mptcp: sockopt: support IP_LOCAL_PORT_RANGE and IP_BIND_ADDRESS_NO_PORT
In reply to Maxim GalaganovSupport for IP_BIND_ADDRESS_NO_PORT sockopt was introduced in [1]. Recently [2] allowed its value to be accessed without locking the socket.
Support for (newer) IP_LOCAL_PORT_RANGE sockopt was introduced in [3]. In the same series a selftest was added in [4]. This selftest also covers the IP_BIND_ADDRESS_NO_PORT sockopt.
This patch enables getsockopt()/setsockopt() on MPTCP sockets for these socket options, syncing set values to subflows in sync_socket_options(). Ephemeral port range is synced to subflows, enabling NAT usecase described in [3].
[1] commit 90c337da1524 ("inet: add IP_BIND_ADDRESS_NO_PORT to overcome bind(0) limitations")
[2] commit ca571e2eb7eb ("inet: move inet->bind_address_no_port to inet->inet_flags")
[3] commit 91d0b78c5177 ("inet: Add IP_LOCAL_PORT_RANGE socket option")
[4] commit ae5439658cce ("selftests/net: Cover the IP_LOCAL_PORT_RANGE socket option")
--- net/mptcp/sockopt.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
net/mptcp/sockopt.c +20 -1
@@ -440,6 +440,8 @@ static bool mptcp_supported_sockopt(int level, int optname)/* should work fine */ case IP_FREEBIND :case IP_TRANSPARENT : +case IP_BIND_ADDRESS_NO_PORT : +case IP_LOCAL_PORT_RANGE :/* the following are control cmsg related */ case IP_PKTINFO :
@@ -455,7 +457,6 @@ static bool mptcp_supported_sockopt(int level, int optname)/* common stuff that need some love */ case IP_TOS :case IP_TTL : -case IP_BIND_ADDRESS_NO_PORT :case IP_MTU_DISCOVER :case IP_RECVERR :
@@ -710,6 +711,14 @@ static int mptcp_setsockopt_sol_ip_set(struct mptcp_sock *msk, int optname,inet_assign_bit (TRANSPARENT , ssk,inet_test_bit (TRANSPARENT , sk));break ; +case IP_BIND_ADDRESS_NO_PORT : +inet_assign_bit (BIND_ADDRESS_NO_PORT , ssk, +inet_test_bit (BIND_ADDRESS_NO_PORT , sk)); +break ; +case IP_LOCAL_PORT_RANGE : +WRITE_ONCE (inet_sk (ssk)->local_port_range, +READ_ONCE (inet_sk (sk)->local_port_range)); +break ;default :release_sock (sk);WARN_ON_ONCE (1 );
@@ -755,6 +764,8 @@ static int mptcp_setsockopt_v4(struct mptcp_sock *msk, int optname,switch (optname) {case IP_FREEBIND :case IP_TRANSPARENT : +case IP_BIND_ADDRESS_NO_PORT : +case IP_LOCAL_PORT_RANGE :return mptcp_setsockopt_sol_ip_set (msk, optname, optval, optlen);case IP_TOS :return mptcp_setsockopt_v4_set_tos (msk, optname, optval, optlen);
@@ -1350,6 +1361,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_BIND_ADDRESS_NO_PORT : +return mptcp_put_int_option (msk, optval, optlen, +inet_test_bit (BIND_ADDRESS_NO_PORT , sk)); +case IP_LOCAL_PORT_RANGE : +return mptcp_put_int_option (msk, optval, optlen, +READ_ONCE (inet_sk (sk)->local_port_range)); }return -EOPNOTSUPP ;
@@ -1450,6 +1467,8 @@ static void sync_socket_options(struct mptcp_sock *msk, struct sock *ssk)inet_assign_bit (TRANSPARENT , ssk,inet_test_bit (TRANSPARENT , sk));inet_assign_bit (FREEBIND , ssk,inet_test_bit (FREEBIND , sk)); +inet_assign_bit (BIND_ADDRESS_NO_PORT , ssk,inet_test_bit (BIND_ADDRESS_NO_PORT , sk)); +WRITE_ONCE (inet_sk (ssk)->local_port_range,READ_ONCE (inet_sk (sk)->local_port_range)); }void mptcp_sockopt_sync_locked (struct mptcp_sock *msk,struct sock *ssk)
Signature · 1 line
2.43.0
Re: [PATCH v3 mptcp-next 2/3] mptcp: sockopt: support IP_LOCAL_PORT_RANGE and IP_BIND_ADDRESS_NO_PORT
Quoted 21 lines · Maxim Galaganov
Support for
IP_BIND_ADDRESS_NO_PORTsockopt was introduced in [1]. Recently [2] allowed its value to be accessed without locking the socket.Support for (newer)
IP_LOCAL_PORT_RANGEsockopt was introduced in [3]. In the same series a selftest was added in [4]. This selftest also covers theIP_BIND_ADDRESS_NO_PORTsockopt.This patch enables getsockopt()/setsockopt() on MPTCP sockets for these socket options, syncing set values to subflows in
sync_socket_options(). Ephemeral port range is synced to subflows, enabling NAT usecase described in [3].[1] commit
90c337da1524("inet: addIP_BIND_ADDRESS_NO_PORTto overcome bind(0) limitations")
[2] commitca571e2eb7eb("inet: moveinet->bind_address_no_porttoinet->inet_flags")
[3] commit91d0b78c5177("inet: AddIP_LOCAL_PORT_RANGEsocket option")
[4] commitae5439658cce("selftests/net: Cover theIP_LOCAL_PORT_RANGEsocket option")
Quoted 1 line
Signed-off-by Maxim Galaganov <[email protected]>
v3 looks good, thanks Maxim!
Quoted 75 lines
---
net/mptcp/sockopt.c| 21 ++++++++++++++++++++-1 file changed, 20 insertions(+), 1 deletion(-)net/mptcp/sockopt.c +20
-1@@ -440,6 +440,8 @@ static bool mptcp_supported_sockopt(int level, int optname)/* should work fine */ case IP_FREEBIND :case IP_TRANSPARENT : +case IP_BIND_ADDRESS_NO_PORT : +case IP_LOCAL_PORT_RANGE :/* the following are control cmsg related */ case IP_PKTINFO :@@ -455,7 +457,6 @@ static bool mptcp_supported_sockopt(int level, int optname)/* common stuff that need some love */ case IP_TOS :case IP_TTL : -case IP_BIND_ADDRESS_NO_PORT :case IP_MTU_DISCOVER :case IP_RECVERR :@@ -710,6 +711,14 @@ static int mptcp_setsockopt_sol_ip_set(struct mptcp_sock *msk, int optname,inet_assign_bit (TRANSPARENT , ssk,inet_test_bit (TRANSPARENT , sk));break ; +case IP_BIND_ADDRESS_NO_PORT : +inet_assign_bit (BIND_ADDRESS_NO_PORT , ssk, +inet_test_bit (BIND_ADDRESS_NO_PORT , sk)); +break ; +case IP_LOCAL_PORT_RANGE : +WRITE_ONCE (inet_sk (ssk)->local_port_range, +READ_ONCE (inet_sk (sk)->local_port_range)); +break ;default :release_sock (sk);WARN_ON_ONCE (1 );@@ -755,6 +764,8 @@ static int mptcp_setsockopt_v4(struct mptcp_sock *msk, int optname,switch (optname) {case IP_FREEBIND :case IP_TRANSPARENT : +case IP_BIND_ADDRESS_NO_PORT : +case IP_LOCAL_PORT_RANGE :return mptcp_setsockopt_sol_ip_set (msk, optname, optval, optlen);case IP_TOS :return mptcp_setsockopt_v4_set_tos (msk, optname, optval, optlen);@@ -1350,6 +1361,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_BIND_ADDRESS_NO_PORT : +return mptcp_put_int_option (msk, optval, optlen, +inet_test_bit (BIND_ADDRESS_NO_PORT , sk)); +case IP_LOCAL_PORT_RANGE : +return mptcp_put_int_option (msk, optval, optlen, +READ_ONCE (inet_sk (sk)->local_port_range)); }return -EOPNOTSUPP ;@@ -1450,6 +1467,8 @@ static void sync_socket_options(struct mptcp_sock *msk, struct sock *ssk)inet_assign_bit (TRANSPARENT , ssk,inet_test_bit (TRANSPARENT , sk));inet_assign_bit (FREEBIND , ssk,inet_test_bit (FREEBIND , sk)); +inet_assign_bit (BIND_ADDRESS_NO_PORT , ssk,inet_test_bit (BIND_ADDRESS_NO_PORT , sk)); +WRITE_ONCE (inet_sk (ssk)->local_port_range,READ_ONCE (inet_sk (sk)->local_port_range)); }void mptcp_sockopt_sync_locked (struct mptcp_sock *msk,struct sock *ssk)Signature · 1 line
2.43.0
PATCH v3 3/3 selftests/net: add MPTCP coverage for IP_LOCAL_PORT_RANGE
In reply to Maxim GalaganovSince previous commit, MPTCP has support for IP_BIND_ADDRESS_NO_PORT and IP_LOCAL_PORT_RANGE sockopts.
Add ip4_mptcp and ip6_mptcp fixture variants to ip_local_port_range selftest to provide selftest coverage for these sockopts.
--- tools/testing/selftests/net/ip_local_port_range.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
tools/testing/selftests/net/ip_local_port_range.c +12 -0
@@ -146,6 +146,12 @@ FIXTURE_VARIANT_ADD(ip_local_port_range, ip4_stcp) { .so_protocol = IPPROTO_SCTP, }; +FIXTURE_VARIANT_ADD(ip_local_port_range, ip4_mptcp) { + .so_domain = AF_INET, + .so_type = SOCK_STREAM, + .so_protocol =IPPROTO_MPTCP , +}; + FIXTURE_VARIANT_ADD(ip_local_port_range, ip6_tcp) { .so_domain =AF_INET6 , .so_type = SOCK_STREAM,
@@ -164,6 +170,12 @@ FIXTURE_VARIANT_ADD(ip_local_port_range, ip6_stcp) { .so_protocol = IPPROTO_SCTP, }; +FIXTURE_VARIANT_ADD(ip_local_port_range, ip6_mptcp) { + .so_domain = AF_INET6, + .so_type = SOCK_STREAM, + .so_protocol =IPPROTO_MPTCP , +}; + TEST_F(ip_local_port_range, invalid_option_value) {__u16 val16;
Signature · 1 line
2.43.0
Re: selftests/net: add MPTCP coverage for IP_LOCAL_PORT_RANGE: Tests Results
Hi Maxim,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join):
- Unstable: 1 failed test(s): packetdrill_fastclose 🔴:
- Task: https://cirrus-ci.com/task/5814574327267328
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5814574327267328/summary/summary.txt
- KVM Validation: debug (except selftest_mptcp_join):
- Unstable: 1 failed test(s): packetdrill_fastclose 🔴:
- Task: https://cirrus-ci.com/task/6377524280688640
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6377524280688640/summary/summary.txt
- KVM Validation: normal (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5251624373846016
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5251624373846016/summary/summary.txt
- KVM Validation: debug (only selftest_mptcp_join):
- Unstable: 1 failed test(s): selftest_mptcp_join 🔴:
- Task: https://cirrus-ci.com/task/4970149397135360
- Summary: https://api.cirrus-ci.com/v1/artifact/task/4970149397135360/summary/summary.txt
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/36ace3f14b75
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-debugFor 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)
Re: selftests/net: add MPTCP coverage for IP_LOCAL_PORT_RANGE: Tests Results
In reply to Maxim GalaganovHi Maxim,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join):
- Unstable: 1 failed test(s): packetdrill_fastclose 🔴:
- Task: https://cirrus-ci.com/task/6679698382520320
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6679698382520320/summary/summary.txt
- KVM Validation: normal (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/4639004801368064
- Summary: https://api.cirrus-ci.com/v1/artifact/task/4639004801368064/summary/summary.txt
- KVM Validation: debug (except selftest_mptcp_join):
- Unstable: 1 failed test(s): packetdrill_fastclose 🔴:
- Task: https://cirrus-ci.com/task/5764904708210688
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5764904708210688/summary/summary.txt
- KVM Validation: debug (only selftest_mptcp_join):
- Unstable: 1 failed test(s): selftest_mptcp_join 🔴:
- Task: https://cirrus-ci.com/task/5201954754789376
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5201954754789376/summary/summary.txt
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/8c7bf89c57a8
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-debugFor 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)
Re: selftests/net: add MPTCP coverage for IP_LOCAL_PORT_RANGE: Tests Results
In reply to Maxim GalaganovHi Maxim,
Thank you for your modifications, that's great!
Our CI did some validations and here is its report:
- KVM Validation: normal (except selftest_mptcp_join):
- Unstable: 1 failed test(s): selftest_simult_flows 🔴:
- Task: https://cirrus-ci.com/task/6183200901300224
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6183200901300224/summary/summary.txt
- KVM Validation: normal (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5620250947878912
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5620250947878912/summary/summary.txt
- KVM Validation: debug (except selftest_mptcp_join):
- Unstable: 1 failed test(s): packetdrill_regressions 🔴:
- Task: https://cirrus-ci.com/task/6746150854721536
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6746150854721536/summary/summary.txt
- KVM Validation: debug (only selftest_mptcp_join):
- Unstable: 1 failed test(s): selftest_mptcp_join 🔴:
- Task: https://cirrus-ci.com/task/4520739320102912
- Summary: https://api.cirrus-ci.com/v1/artifact/task/4520739320102912/summary/summary.txt
Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/b039ca39ebf1
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-debugFor 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)
Matthieu Baerts
maintainerHi Maxim, Mat,
Quoted 7 lines · Maxim Galaganov
Support useful sockopts that allow fine control over ephemeral port usage.
v3:
- Change patch 2/3 with regards to commitd9f28735af87("Use READ/WRITE_ONCE() for IPlocal_port_range.")
- Drop Mat's Reviewed-By tag in patch 2/3 because of changes
Thank you for the patches and the reviews!
Please note that 'b4' is telling me that your emails are not properly signed by your SMTP server:
BADSIG: DKIM/internet.ru
That's not blocking here, but it could be a sign someone is trying to forge the sender address.
These patches have been added in our tree: feat. for net-next.
New patches for t/upstream:
- 250382904050: mptcp: rename mptcp_setsockopt_sol_ip_set_transparent()
- be6fee83fad1: mptcp: sockopt: support IP_LOCAL_PORT_RANGE and IP_BIND_ADDRESS_NO_PORT
- 5df30926310b: selftests/net: add MPTCP coverage for IP_LOCAL_PORT_RANGE
- Results: e2b8a59f008f..84d8fb414b2a (export)
Tests are now in progress:
https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20231215T134806
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.
Quoted 13 lines · Matthieu Baerts
Hi Maxim, Mat,
Quoted 7 lines · Maxim Galaganov
Support useful sockopts that allow fine control over ephemeral port usage.
v3:
- Change patch 2/3 with regards to commitd9f28735af87("Use READ/WRITE_ONCE() for IPlocal_port_range.")
- Drop Mat's Reviewed-By tag in patch 2/3 because of changesThank you for the patches and the reviews!
Quoted 7 lines
Please note that 'b4' is telling me that your emails are not properly signed by your SMTP server:
BADSIG: DKIM/internet.ru
That's not blocking here, but it could be a sign someone is trying to forge the sender address.
This is because of DKIM expiration (DKIM-Signature header contains t= and x= tags, that make signature invalid after some time). It is reasonably effective to prevent DKIM replay attacks, also can be done by rotating DKIM selectors (gmail does that, IIRC).
Running b4 with -d flag tells:
DKIM: x= value is past (b'1702386232')
Otherwise header and body hashes should verify OK here..
Quoted 16 lines
These patches have been added in our tree: feat. for net-next.
New patches for t/upstream:
- 250382904050: mptcp: renamemptcp_setsockopt_sol_ip_set_transparent()
-be6fee83fad1: mptcp: sockopt: supportIP_LOCAL_PORT_RANGEandIP_BIND_ADDRESS_NO_PORT
-5df30926310b: selftests/net: add MPTCP coverage forIP_LOCAL_PORT_RANGE
- Results:e2b8a59f008f..84d8fb414b2a(export)Tests are now in progress:
https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20231215T134806
Cheers,
Matt
Matthieu Baerts
maintainerHi Maxim,
Quoted 27 lines · Maxim Galaganov
Quoted 13 lines · Matthieu Baerts
Hi Maxim, Mat,
Quoted 7 lines · Maxim Galaganov
Support useful sockopts that allow fine control over ephemeral port usage.
v3:
- Change patch 2/3 with regards to commitd9f28735af87("Use READ/WRITE_ONCE() for IPlocal_port_range.")
- Drop Mat's Reviewed-By tag in patch 2/3 because of changesThank you for the patches and the reviews!
Quoted 7 lines
Please note that 'b4' is telling me that your emails are not properly signed by your SMTP server:
BADSIG: DKIM/internet.ru
That's not blocking here, but it could be a sign someone is trying to forge the sender address.
This is because of DKIM expiration (DKIM-Signature header contains t= and x= tags, that make signature invalid after some time). It is reasonably effective to prevent DKIM replay attacks, also can be done by rotating DKIM selectors (gmail does that, IIRC).
Quoted 4 lines
Running b4 with -d flag tells:
DKIM: x= value is past (b'1702386232')Otherwise header and body hashes should verify OK here..
Thank you for having checked that! I already saw that before [1], but I forgot about that!
[1]
https://lore.kernel.org/tools/[email protected]/
Cheers,
Matt
Signature · 1 line
Sponsored by the NGI0 Core fund.