mptcp: setsockopt: allow reuseport and ip6only
Subsystems (2)
Florian Westphal
cover mptcp: setsockopt: allow reuseport and ip6only
First patch makes reuseport setsockopt work by copying the mptcp sockets setting to the newly created subflow socket.
Second patch makes mptcp accept IPV6_V6ONLY by applying the setsockopt to the initial socket.
First patch addresses:
https://github.com/multipath-tcp/mptcp_net-next/issues/30
Second patch makes sshd work with ipv6 too.
I've tested this with out-of-tree patch that aliases IPPROTO_TCP to IPPROTO_MPTCP, without these patches I see the behaviour Christoph describes in the github issue (restart fails, IPV6_V6only error).
Florian Westphal
PATCH 1/2 mptcp: replay SOL_SOCKET options to subflows
SO_REUSEPORT won't work as expected: the setsockopt will be successful (the mptcp sk has the flag toggled), but it has no effect because the subflow socket isn't aware of this.
Copy the flag(s) from the mptcp socket to the subflow socket to resolve this.
This will e.g. make 'sshd restart' work when MPTCP is used.
--- net/mptcp/protocol.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
net/mptcp/protocol.c +12 -0
@@ -1858,6 +1858,14 @@ static struct proto mptcp_prot = { .no_autobind = true, }; +static void mptcp_copy_setsockopt (struct sock *sk,struct sock *ssk) +{ +#define C (name) ssk->name = sk->name +C (sk_reuse); +C (sk_reuseport); +#undef C +} +static int mptcp_bind (struct socket *sock,struct sockaddr *uaddr,int addr_len) {struct mptcp_sock *msk =mptcp_sk (sock->sk);
@@ -1871,6 +1879,8 @@ static int mptcp_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) goto unlock; } +mptcp_copy_setsockopt (sock->sk, ssock->sk); + err = ssock->ops->bind (ssock, uaddr, addr_len);if (!err)mptcp_copy_inaddrs (sock->sk, ssock->sk);
@@ -1916,6 +1926,7 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr, subflow->request_mptcp =0 ; do_connect: +mptcp_copy_setsockopt (sock->sk, ssock->sk); err = ssock->ops->connect (ssock, uaddr, addr_len, flags); sock->state = ssock->state;
@@ -1985,6 +1996,7 @@ static int mptcp_listen(struct socket *sock, int backlog) }sock_set_flag (sock->sk,SOCK_RCU_FREE ); +mptcp_copy_setsockopt (sock->sk, ssock->sk); err = ssock->ops->listen (ssock, backlog);inet_sk_state_store (sock->sk,inet_sk_state_load (ssock->sk));
Signature · 1 line
2.26.2
Florian Westphal
PATCH 2/2 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 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
net/mptcp/protocol.c +28 -0
@@ -1628,6 +1628,31 @@ static void mptcp_destroy(struct sock *sk)sk_sockets_allocated_dec (sk); } +static int mptcp_setsockopt_v6 (struct mptcp_sock *msk,int level,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_socket_create (msk,MPTCP_SAME_STATE ); +release_sock (sk); +if (!ssock) +return -EINVAL ; + + ret =tcp_setsockopt (ssock->sk, level, optname, optval, optlen); +if (ret ==0 ) + sk->sk_ipv6only = ssock->sk->sk_ipv6only; + +return ret; + } + +return ret; +} +static int mptcp_setsockopt (struct sock *sk,int level,int optname,char __user *optval,unsigned int optlen) {
@@ -1649,6 +1674,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, level, optname, optval, optlen); +return -EOPNOTSUPP ; }
Signature · 1 line
2.26.2