ipv4: add ip_sock_set_tos
Add a helper to directly set the IP_TOS sockopt from kernel space without going through a fake uaccess. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
480aeb9639
commit
6ebf71bab9
@@ -560,6 +560,26 @@ out:
|
||||
return err;
|
||||
}
|
||||
|
||||
static void __ip_sock_set_tos(struct sock *sk, int val)
|
||||
{
|
||||
if (sk->sk_type == SOCK_STREAM) {
|
||||
val &= ~INET_ECN_MASK;
|
||||
val |= inet_sk(sk)->tos & INET_ECN_MASK;
|
||||
}
|
||||
if (inet_sk(sk)->tos != val) {
|
||||
inet_sk(sk)->tos = val;
|
||||
sk->sk_priority = rt_tos2priority(val);
|
||||
sk_dst_reset(sk);
|
||||
}
|
||||
}
|
||||
|
||||
void ip_sock_set_tos(struct sock *sk, int val)
|
||||
{
|
||||
lock_sock(sk);
|
||||
__ip_sock_set_tos(sk, val);
|
||||
release_sock(sk);
|
||||
}
|
||||
EXPORT_SYMBOL(ip_sock_set_tos);
|
||||
|
||||
/*
|
||||
* Socket option code for IP. This is the end of the line after any
|
||||
@@ -823,15 +843,7 @@ static int do_ip_setsockopt(struct sock *sk, int level,
|
||||
inet->cmsg_flags &= ~IP_CMSG_RECVFRAGSIZE;
|
||||
break;
|
||||
case IP_TOS: /* This sets both TOS and Precedence */
|
||||
if (sk->sk_type == SOCK_STREAM) {
|
||||
val &= ~INET_ECN_MASK;
|
||||
val |= inet->tos & INET_ECN_MASK;
|
||||
}
|
||||
if (inet->tos != val) {
|
||||
inet->tos = val;
|
||||
sk->sk_priority = rt_tos2priority(val);
|
||||
sk_dst_reset(sk);
|
||||
}
|
||||
__ip_sock_set_tos(sk, val);
|
||||
break;
|
||||
case IP_TTL:
|
||||
if (optlen < 1)
|
||||
|
Reference in New Issue
Block a user