Commit a5ef058d authored by Paolo Abeni's avatar Paolo Abeni Committed by David S. Miller

net: introduce and use custom sockopt socket flag

We will soon introduce custom setsockopt for UDP sockets, too.
Instead of doing even more complex arbitrary checks inside
sock_use_custom_sol_socket(), add a new socket flag and set it
for the relevant socket types (currently only MPTCP).
Reviewed-by: default avatarMatthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Reviewed-by: default avatarEric Dumazet <edumazet@google.com>
Acked-by: default avatarKuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ea5ed0f0
...@@ -41,6 +41,7 @@ struct net; ...@@ -41,6 +41,7 @@ struct net;
#define SOCK_NOSPACE 2 #define SOCK_NOSPACE 2
#define SOCK_PASSCRED 3 #define SOCK_PASSCRED 3
#define SOCK_PASSSEC 4 #define SOCK_PASSSEC 4
#define SOCK_CUSTOM_SOCKOPT 5
#ifndef ARCH_HAS_SOCKET_TYPES #ifndef ARCH_HAS_SOCKET_TYPES
/** /**
......
...@@ -2708,6 +2708,8 @@ static int mptcp_init_sock(struct sock *sk) ...@@ -2708,6 +2708,8 @@ static int mptcp_init_sock(struct sock *sk)
if (ret) if (ret)
return ret; return ret;
set_bit(SOCK_CUSTOM_SOCKOPT, &sk->sk_socket->flags);
/* fetch the ca name; do it outside __mptcp_init_sock(), so that clone will /* fetch the ca name; do it outside __mptcp_init_sock(), so that clone will
* propagate the correct value * propagate the correct value
*/ */
...@@ -3684,6 +3686,8 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock, ...@@ -3684,6 +3686,8 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
struct mptcp_subflow_context *subflow; struct mptcp_subflow_context *subflow;
struct sock *newsk = newsock->sk; struct sock *newsk = newsock->sk;
set_bit(SOCK_CUSTOM_SOCKOPT, &newsock->flags);
lock_sock(newsk); lock_sock(newsk);
/* PM/worker can now acquire the first subflow socket /* PM/worker can now acquire the first subflow socket
......
...@@ -2199,13 +2199,7 @@ SYSCALL_DEFINE4(recv, int, fd, void __user *, ubuf, size_t, size, ...@@ -2199,13 +2199,7 @@ SYSCALL_DEFINE4(recv, int, fd, void __user *, ubuf, size_t, size,
static bool sock_use_custom_sol_socket(const struct socket *sock) static bool sock_use_custom_sol_socket(const struct socket *sock)
{ {
const struct sock *sk = sock->sk; return test_bit(SOCK_CUSTOM_SOCKOPT, &sock->flags);
/* 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);
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment