setsockopt: allow reuseport and ip6only
Subsystems (3)
Florian Westphal
v3 cover setsockopt: allow reuseport and ip6only
3rd iteration. I've incorporated feedback from Mat, so for options other than reuseport/reuseaddr the generic handler gets called instead of returning -EOPNOTSUPP.
I've tested that ssh restart works on a a modified kernel that enables mptcp for all IPPROTO_TCP sockets.
Florian Westphal
PATCH v3 1/3 net: use mptcp setsockopt function for SOL_SOCKET on mptcp sockets
setsockopt(mptcp_fd, SOL_SOCKET, ...)... appears to work (returns 0), but it has no effect -- this is because the MPTCP layer never has a chance to copy the settings to the subflow socket.
Skip the generic handling for the mptcp case and instead call the mptcp specific handler instead for SOL_SOCKET too.
Next patch adds more specific handling for SOL_SOCKET to mptcp.
--- net/mptcp/protocol.c | 3 +++ net/socket.c | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +3 -0
@@ -1609,6 +1609,9 @@ static int mptcp_setsockopt(struct sock *sk, int level, int optname,pr_debug ("msk=%p" , msk); +if (level ==SOL_SOCKET ) +return sock_setsockopt (sk->sk_socket, level, optname, optval, optlen); +/* @@ the meaning of setsockopt() when the socket is connected and * there are multiple subflows is not yet defined. It is up to the * MPTCP-level socket to configure the subflows until the subflow
net/socket.c +12 -1
@@ -2091,6 +2091,17 @@ SYSCALL_DEFINE4(recv, int, fd, void __user *, ubuf, size_t, size,return __sys_recvfrom (fd, ubuf, size, flags,NULL ,NULL ); } +static bool sock_use_custom_sol_socket (const struct socket *sock) +{ +const struct sock *sk = sock->sk; + +/* Use sock->ops->setsockopt() for MPTCP */ +return IS_ENABLED (CONFIG_MPTCP ) && + sk->sk_protocol ==IPPROTO_MPTCP && + sk->sk_type ==SOCK_STREAM && + (sk->sk_family ==AF_INET || sk->sk_family ==AF_INET6 ); +} +/* * Set a socket option. Because we don't know the option lengths we have * to pass the user mode parameter for the protocols to sort out.
@@ -2129,7 +2140,7 @@ static int __sys_setsockopt(int fd, int level, int optname, optval = (char __user __force *)kernel_optval; } -if (level ==SOL_SOCKET ) +if (level ==SOL_SOCKET && !sock_use_custom_sol_socket (sock)) err =sock_setsockopt (sock, level, optname, optval, optlen);
Signature · 1 line
2.26.2
Florian Westphal
PATCH v3 2/3 mptcp: add REUSEADDR/REUSEPORT support
In reply to Florian WestphalThis will e.g. make 'sshd restart' work when MPTCP is used, as we will now set this option on the listener socket instead of only the mptcp socket (where it has no effect).
We still need to copy the setting to the master socket so that a subsequent getsockopt() returns the expected value.
--- net/mptcp/protocol.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-)
net/mptcp/protocol.c +33 -1
@@ -1601,6 +1601,37 @@ static void mptcp_destroy(struct sock *sk)sk_sockets_allocated_dec (sk); } +static int mptcp_setsockopt_sol_socket (struct mptcp_sock *msk,int optname, +char __user *optval,unsigned int optlen) +{ +struct sock *sk = (struct sock *)msk; +struct socket *ssock; +int ret; + +switch (optname) { +case SO_REUSEPORT : +case SO_REUSEADDR : +lock_sock (sk); + ssock =__mptcp_nmpc_socket (msk); +if (!ssock) { +release_sock (sk); +return -EINVAL ; + } + + ret =sock_setsockopt (ssock,SOL_SOCKET , optname, optval, optlen); +if (ret ==0 ) { +if (optname ==SO_REUSEPORT ) + sk->sk_reuseport = ssock->sk->sk_reuseport; +else if (optname ==SO_REUSEADDR ) + sk->sk_reuse = ssock->sk->sk_reuse; + } +release_sock (sk); +return ret; + } + +return sock_setsockopt (sk->sk_socket,SOL_SOCKET , optname, optval, optlen); +} +static int mptcp_setsockopt (struct sock *sk,int level,int optname,char __user *optval,unsigned int optlen) {
@@ -1610,7 +1641,8 @@ static int mptcp_setsockopt(struct sock *sk, int level, int optname,pr_debug ("msk=%p" , msk);if (level ==SOL_SOCKET ) -return sock_setsockopt (sk->sk_socket, level, optname, optval, optlen); +return mptcp_setsockopt_sol_socket (msk, optname, + optval, optlen);/* @@ the meaning of setsockopt() when the socket is connected and * there are multiple subflows is not yet defined. It is up to the
Signature · 1 line
2.26.2
Florian Westphal
PATCH v3 3/3 mptcp: support IPV6_V6ONLY setsockopt
In reply to Florian WestphalWithout this, Opensshd fails to open an ipv6 socket listening socket:
error: setsockopt IPV6_V6ONLY: Operation not supported
error: Bind to port 22 on :: failed: Address already in use.
Opensshd opens an ipv4 and and ipv6 listening socket, but because IPV6_V6ONLY setsockopt fails, the port number is already in use.
--- net/mptcp/protocol.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
net/mptcp/protocol.c +30 -0
@@ -1632,6 +1632,33 @@ static int mptcp_setsockopt_sol_socket(struct mptcp_sock *msk, int optname,return sock_setsockopt (sk->sk_socket,SOL_SOCKET , optname, optval, optlen); } +static int mptcp_setsockopt_v6 (struct mptcp_sock *msk,int optname, +char __user *optval,unsigned int optlen) +{ +struct sock *sk = (struct sock *)msk; +int ret = -EOPNOTSUPP ; +struct socket *ssock; + +switch (optname) { +case IPV6_V6ONLY : +lock_sock (sk); + ssock =__mptcp_nmpc_socket (msk); +if (!ssock) { +release_sock (sk); +return -EINVAL ; + } + + ret =tcp_setsockopt (ssock->sk,SOL_IPV6 , optname, optval, optlen); +if (ret ==0 ) + sk->sk_ipv6only = ssock->sk->sk_ipv6only; + +release_sock (sk); +break ; + } + +return ret; +} +static int mptcp_setsockopt (struct sock *sk,int level,int optname,char __user *optval,unsigned int optlen) {
@@ -1657,6 +1684,9 @@ static int mptcp_setsockopt(struct sock *sk, int level, int optname,return tcp_setsockopt (ssock->sk, level, optname, optval, optlen); +if (level ==SOL_IPV6 ) +return mptcp_setsockopt_v6 (msk, optname, optval, optlen); +return -EOPNOTSUPP ; }
Signature · 1 line
2.26.2
Mat Martineau
Quoted 6 lines · Florian Westphal
3rd iteration. I've incorporated feedback from Mat, so for options other than reuseport/reuseaddr the generic handler gets called instead of returning
-EOPNOTSUPP.I've tested that ssh restart works on a a modified kernel that enables mptcp for all
IPPROTO_TCPsockets.
Thanks for the v3 updates, changes look good. Should the patches go to the mptcp repo for some more test coverage or are you intending to post for net-next soon?
--
Mat Martineau
Intel
Florian Westphal
Quoted 7 lines · Mat Martineau
Quoted 4 lines · Florian Westphal
3rd iteration. I've incorporated feedback from Mat, so for options other than reuseport/reuseaddr the generic handler gets called instead of returning
-EOPNOTSUPP.
Quoted 6 lines
Quoted 2 lines
I've tested that ssh restart works on a a modified kernel that enables mptcp for all
IPPROTO_TCPsockets.Thanks for the v3 updates, changes look good. Should the patches go to the mptcp repo for some more test coverage or are you intending to post for net-next soon?
The former, they depend on Paolos fallback refactoring which isn't in net-next yet afaics.
Paolo Abeni
Quoted 10 lines · Florian Westphal
Quoted 9 lines · Mat Martineau
Quoted 6 lines · Florian Westphal
3rd iteration. I've incorporated feedback from Mat, so for options other than reuseport/reuseaddr the generic handler gets called instead of returning
-EOPNOTSUPP.I've tested that ssh restart works on a a modified kernel that enables mptcp for all
IPPROTO_TCPsockets.
Quoted 6 lines
Quoted 3 lines
Thanks for the v3 updates, changes look good. Should the patches go to the mptcp repo for some more test coverage or are you intending to post for net-next soon?
The former, they depend on Paolos fallback refactoring which isn't in net-next yet afaics.
I'd like to spool the token refactor first, which in turn will cause conflict without "mptcp: drop MP_JOIN request sock on syn cookies" - currently on -net only.
I'll ask Dave for a -net -> -net-next merge, so we can start spooling stuff.
Cheers,
Paolo
Matthieu Baerts
Hi Florian, Mat, Paolo,
Quoted 18 lines · Paolo Abeni
Quoted 10 lines · Florian Westphal
Quoted 9 lines · Mat Martineau
Quoted 6 lines · Florian Westphal
3rd iteration. I've incorporated feedback from Mat, so for options other than reuseport/reuseaddr the generic handler gets called instead of returning
-EOPNOTSUPP.I've tested that ssh restart works on a a modified kernel that enables mptcp for all
IPPROTO_TCPsockets.Quoted 6 lines
Quoted 3 lines
Thanks for the v3 updates, changes look good. Should the patches go to the mptcp repo for some more test coverage or are you intending to post for net-next soon?
The former, they depend on Paolos fallback refactoring which isn't in net-next yet afaics.
Quoted 6 lines
I'd like to spool the token refactor first, which in turn will cause conflict without "mptcp: drop
MP_JOINrequest sock on syn cookies" - currently on -net only.I'll ask Dave for a -net -> -net-next merge, so we can start spooling stuff.
Thank you for the patches and the reviews!
I just added the patches at the end of the series.
- 5433a4ffa2d6: net: use mptcp setsockopt function for SOL_SOCKET on mptcp sockets
- 681584082eab: mptcp: add REUSEADDR/REUSEPORT support
- cffa48f64125: mptcp: support IPV6_V6ONLY setsockopt
Tests + export are in progress.
Cheers,
Matt
Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions www.tessares.net