Splitting commits for IP_TOS support in setsockopt()
Subsystems (3)
PATCH v4 1/2 Exposing __ip_sock_set_tos() in ip.h
In reply to Poorva SonparoteMaking the static function __ip_sock_set_tos() from net/ipv4/ip_sockglue.c accessible by declaring it in include/net/ip.h
The reason for doing this is to use this function to set IP_TOS value in mptcp_setsockopt() without the lock.
--- include/net/ip.h | 1 + net/ipv4/ip_sockglue.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
include/net/ip.h +1 -0
@@ -789,5 +789,6 @@ int ip_sock_set_mtu_discover(struct sock *sk, int val);void ip_sock_set_pktinfo (struct sock *sk);void ip_sock_set_recverr (struct sock *sk);void ip_sock_set_tos (struct sock *sk,int val); +void __ip_sock_set_tos (struct sock *sk,int val);#endif /* _IP_H */
net/ipv4/ip_sockglue.c +1 -1
@@ -576,7 +576,7 @@ int ip_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)return err; } -static void __ip_sock_set_tos (struct sock *sk,int val) +void __ip_sock_set_tos (struct sock *sk,int val) {if (sk->sk_type ==SOCK_STREAM ) { val &= ~INET_ECN_MASK ;
Signature · 1 line
2.18.2
v4 cover Splitting commits for IP_TOS support in setsockopt()
- patch 1/2 Add Support for IP_TOS for MPTCP setsockopt()
- patch 2/2 Exposing __ip_sock_set_tos() in ip.h
Poorva Sonparote (2):
Exposing __ip_sock_set_tos() in ip.h
Support for IP_TOS for MPTCP setsockopt()
include/net/ip.h | 1 + net/ipv4/ip_sockglue.c | 2 +- net/mptcp/sockopt.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-)
Signature · 1 line
2.18.2
PATCH v4 2/2 Support for IP_TOS for MPTCP setsockopt()
SOL_IP provides a way to configure network layer attributes in a socket. This patch adds support for IP_TOS for setsockopt(.. ,SOL_IP, ..)
https://github.com/multipath-tcp/mptcp_net-next/issues/220
Support for SOL_IP is added in mptcp_setsockopt() and IP_TOS is handled in a private function. The idea here is to take in the value passed for IP_TOS and set it to the current subflow, open subflows as well new subflows that might be created after the initial call to setsockopt(). This sync is done using sync_socket_options(.., ssk) and setting the value of tos using __ip_sock_set_tos(ssk,..).
The patch has been tested using the packetdrill script here -
https://github.com/multipath-tcp/mptcp_net-next/issues/220#issuecomment-947863717
---
Notes:
- fixed formatting errors
- split out the main patch into two commits
1. Support for IP_TOS for MPTCP setsockopt()
2. Exposing __ip_sock_set_tos() in ip.h
- Changed the return value of mptcp_setsockopt_v4_set_tos() as reported by kernel test robot.
Earlier it used to return a variable "ret" which wasn't being used anywhere.
- The patch does not have a kselftest because there's no support for IP_TOS in getsockopt() yet.
net/mptcp/sockopt.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
net/mptcp/sockopt.c +40 -0
@@ -598,6 +598,42 @@ static int mptcp_setsockopt_sol_tcp_congestion(struct mptcp_sock *msk, sockptr_treturn ret; } +static int mptcp_setsockopt_v4_set_tos (struct mptcp_sock *msk,int optname, +sockptr_t optval,unsigned int optlen) +{ +struct mptcp_subflow_context *subflow; +struct sock *sk = (struct sock *)msk; +int err, val; + + err =ip_setsockopt (sk,SOL_IP , optname, optval, optlen); + +if (err !=0 ) +return err; + +lock_sock (sk); +sockopt_seq_inc (msk); + val =inet_sk (sk)->tos; +mptcp_for_each_subflow (msk, subflow) { +struct sock *ssk =mptcp_subflow_tcp_sock (subflow); + +__ip_sock_set_tos (ssk, val); + } +release_sock (sk); + +return err; +} + +static int mptcp_setsockopt_v4 (struct mptcp_sock *msk,int optname, +sockptr_t optval,unsigned int optlen) +{ +switch (optname) { +case IP_TOS : +return mptcp_setsockopt_v4_set_tos (msk, optname, optval, optlen); + } + +return -EOPNOTSUPP ; +} +static int mptcp_setsockopt_sol_tcp (struct mptcp_sock *msk,int optname,sockptr_t optval,unsigned int optlen) {
@@ -637,6 +673,9 @@ int mptcp_setsockopt(struct sock *sk, int level, int optname,if (ssk)return tcp_setsockopt (ssk, level, optname, optval, optlen); +if (level ==SOL_IP ) +return mptcp_setsockopt_v4 (msk, optname, optval, optlen); +if (level ==SOL_IPV6 )return mptcp_setsockopt_v6 (msk, optname, optval, optlen);
@@ -1000,6 +1039,7 @@ static void sync_socket_options(struct mptcp_sock *msk, struct sock *ssk) ssk->sk_priority = sk->sk_priority; ssk->sk_bound_dev_if = sk->sk_bound_dev_if; ssk->sk_incoming_cpu = sk->sk_incoming_cpu; +__ip_sock_set_tos (ssk,inet_sk (sk)->tos);if (sk->sk_userlocks & tx_rx_locks) { ssk->sk_userlocks |= sk->sk_userlocks & tx_rx_locks;
Signature · 1 line
2.18.2
Quoted 14 lines · Poorva Sonparote
- patch 1/2 Add Support for
IP_TOSfor MPTCPsetsockopt()
- patch 2/2 Exposing__ip_sock_set_tos()inip.hPoorva Sonparote (2):
Exposing__ip_sock_set_tos()inip.h
Support forIP_TOSfor MPTCPsetsockopt()include/net/ip.h | 1 + net/ipv4/ip_sockglue.c | 2 +- net/mptcp/sockopt.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-)Signature · 1 line
2.18.2
Hi Poorva -
Thanks! Looks like this is ready for the export branch:
It's not necessary to use getsockopt to implement a test for this, you could also use 'ss --tos' to see the tos value on the mptcp socket and the subflows. Would be good to have a selftest for this before upstreaming.
--
Mat Martineau
Intel
Hi Poorva, Mat,
Quoted 8 lines · Mat Martineau
Quoted 6 lines · Poorva Sonparote
- patch 1/2 Add Support for
IP_TOSfor MPTCPsetsockopt()
- patch 2/2 Exposing__ip_sock_set_tos()inip.hPoorva Sonparote (2):
Exposing__ip_sock_set_tos()inip.h
Support forIP_TOSfor MPTCPsetsockopt()
Thank you for the patches and the reviews!
Quoted 3 lines
Thanks! Looks like this is ready for the export branch:
Reviewed-by Mat Martineau <[email protected]>
Now in our tree (features for net-next) + added prefixes in your patches ("ipv4:" and "mptcp:"):
- f80cd2ae7b35: Exposing __ip_sock_set_tos() in ip.h
- dcb0d4eb4318: Support for IP_TOS for MPTCP setsockopt()
- 758c711752bb: tg:msg: prefix with ipv4 and add Mat's ACK
- 76fecc38fcfb: tg:msg: prefix with mptcp and add Mat's RvB
- Results: 4af534378cb0..a1638f497c0c
Builds and tests are now in progress:
https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20211028T092928
https://github.com/multipath-tcp/mptcp_net-next/actions/workflows/build-validation.yml?query=branch:export
Quoted 3 lines
It's not necessary to use getsockopt to implement a test for this, you could also use 'ss --tos' to see the tos value on the mptcp socket and the subflows. Would be good to have a selftest for this before upstreaming.
Should we add something in the selftests for each "simple" sockopt? I
mean: it can be quite "heavy" to create E2E connections, wait for them to be created and be long enough, check for an output with external tool(s), etc.
For more "complex" sockopts like MPTCP_INFO, it makes sense because it would imply a lot of modifications on packetdrill side.
Should we discuss about that at our weekly meeting?
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net