tcp: Restrict SO_TXREHASH to TCP socket.
sk->sk_txrehash is only used for TCP. Let's restrict SO_TXREHASH to TCP to reflect this. Later, we will make sk_txrehash a part of the union for other protocol families. Note that we need to modify BPF selftest not to get/set SO_TEREHASH for non-TCP sockets. Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Reviewed-by: Willem de Bruijn <willemb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
committed by
David S. Miller
parent
38b95d588f
commit
ae4f2f59e1
@@ -1276,6 +1276,8 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
|
||||
return 0;
|
||||
}
|
||||
case SO_TXREHASH:
|
||||
if (!sk_is_tcp(sk))
|
||||
return -EOPNOTSUPP;
|
||||
if (val < -1 || val > 1)
|
||||
return -EINVAL;
|
||||
if ((u8)val == SOCK_TXREHASH_DEFAULT)
|
||||
@@ -2102,6 +2104,9 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
|
||||
break;
|
||||
|
||||
case SO_TXREHASH:
|
||||
if (!sk_is_tcp(sk))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
/* Paired with WRITE_ONCE() in sk_setsockopt() */
|
||||
v.val = READ_ONCE(sk->sk_txrehash);
|
||||
break;
|
||||
|
||||
@@ -83,6 +83,14 @@ struct loop_ctx {
|
||||
struct sock *sk;
|
||||
};
|
||||
|
||||
static bool sk_is_tcp(struct sock *sk)
|
||||
{
|
||||
return (sk->__sk_common.skc_family == AF_INET ||
|
||||
sk->__sk_common.skc_family == AF_INET6) &&
|
||||
sk->sk_type == SOCK_STREAM &&
|
||||
sk->sk_protocol == IPPROTO_TCP;
|
||||
}
|
||||
|
||||
static int bpf_test_sockopt_flip(void *ctx, struct sock *sk,
|
||||
const struct sockopt_test *t,
|
||||
int level)
|
||||
@@ -91,6 +99,9 @@ static int bpf_test_sockopt_flip(void *ctx, struct sock *sk,
|
||||
|
||||
opt = t->opt;
|
||||
|
||||
if (opt == SO_TXREHASH && !sk_is_tcp(sk))
|
||||
return 0;
|
||||
|
||||
if (bpf_getsockopt(ctx, level, opt, &old, sizeof(old)))
|
||||
return 1;
|
||||
/* kernel initialized txrehash to 255 */
|
||||
|
||||
Reference in New Issue
Block a user