mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-01 10:42:11 +00:00
sock: Introduce sk_set_prio_allowed helper function
Simplify priority setting permissions with the 'sk_set_prio_allowed' function, centralizing the validation logic. This change is made in anticipation of a second caller in a following patch. No functional changes. Reviewed-by: Willem de Bruijn <willemb@google.com> Reviewed-by: Eric Dumazet <edumazet@google.com> Suggested-by: Willem de Bruijn <willemb@google.com> Signed-off-by: Anna Emese Nyiri <annaemesenyiri@gmail.com> Link: https://patch.msgid.link/20241213084457.45120-2-annaemesenyiri@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
4fe205539c
commit
77ec16be75
@ -454,6 +454,13 @@ static int sock_set_timeout(long *timeo_p, sockptr_t optval, int optlen,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool sk_set_prio_allowed(const struct sock *sk, int val)
|
||||||
|
{
|
||||||
|
return ((val >= TC_PRIO_BESTEFFORT && val <= TC_PRIO_INTERACTIVE) ||
|
||||||
|
sockopt_ns_capable(sock_net(sk)->user_ns, CAP_NET_RAW) ||
|
||||||
|
sockopt_ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN));
|
||||||
|
}
|
||||||
|
|
||||||
static bool sock_needs_netstamp(const struct sock *sk)
|
static bool sock_needs_netstamp(const struct sock *sk)
|
||||||
{
|
{
|
||||||
switch (sk->sk_family) {
|
switch (sk->sk_family) {
|
||||||
@ -1193,9 +1200,7 @@ int sk_setsockopt(struct sock *sk, int level, int optname,
|
|||||||
/* handle options which do not require locking the socket. */
|
/* handle options which do not require locking the socket. */
|
||||||
switch (optname) {
|
switch (optname) {
|
||||||
case SO_PRIORITY:
|
case SO_PRIORITY:
|
||||||
if ((val >= 0 && val <= 6) ||
|
if (sk_set_prio_allowed(sk, val)) {
|
||||||
sockopt_ns_capable(sock_net(sk)->user_ns, CAP_NET_RAW) ||
|
|
||||||
sockopt_ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN)) {
|
|
||||||
sock_set_priority(sk, val);
|
sock_set_priority(sk, val);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user