Skip to content

Commit aed8156

Browse files
dlunevdavem330
authored andcommitted
[NET]: unify netlink kernel socket recognition
There are currently two ways to determine whether the netlink socket is a kernel one or a user one. This patch creates a single inline call for this purpose and unifies all the calls in the af_netlink.c No similar calls are found outside af_netlink.c. Signed-off-by: Denis V. Lunev <den@openvz.org> Acked-by: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7ee015e commit aed8156

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

net/netlink/af_netlink.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ static inline struct netlink_sock *nlk_sk(struct sock *sk)
9292
return container_of(sk, struct netlink_sock, sk);
9393
}
9494

95+
static inline int netlink_is_kernel(struct sock *sk)
96+
{
97+
return nlk_sk(sk)->flags & NETLINK_KERNEL_SOCKET;
98+
}
99+
95100
struct nl_pid_hash {
96101
struct hlist_head *table;
97102
unsigned long rehash_time;
@@ -489,7 +494,7 @@ static int netlink_release(struct socket *sock)
489494
module_put(nlk->module);
490495

491496
netlink_table_grab();
492-
if (nlk->flags & NETLINK_KERNEL_SOCKET) {
497+
if (netlink_is_kernel(sk)) {
493498
kfree(nl_table[sk->sk_protocol].listeners);
494499
nl_table[sk->sk_protocol].module = NULL;
495500
nl_table[sk->sk_protocol].registered = 0;
@@ -716,7 +721,7 @@ static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
716721

717722
/* Don't bother queuing skb if kernel socket has no input function */
718723
nlk = nlk_sk(sock);
719-
if ((nlk->pid == 0 && !nlk->data_ready) ||
724+
if ((netlink_is_kernel(sock) && !nlk->data_ready) ||
720725
(sock->sk_state == NETLINK_CONNECTED &&
721726
nlk->dst_pid != nlk_sk(ssk)->pid)) {
722727
sock_put(sock);
@@ -762,7 +767,7 @@ int netlink_attachskb(struct sock *sk, struct sk_buff *skb, int nonblock,
762767
test_bit(0, &nlk->state)) {
763768
DECLARE_WAITQUEUE(wait, current);
764769
if (!timeo) {
765-
if (!ssk || nlk_sk(ssk)->pid == 0)
770+
if (!ssk || netlink_is_kernel(ssk))
766771
netlink_overrun(sk);
767772
sock_put(sk);
768773
kfree_skb(skb);
@@ -861,7 +866,7 @@ int netlink_has_listeners(struct sock *sk, unsigned int group)
861866
int res = 0;
862867
unsigned long *listeners;
863868

864-
BUG_ON(!(nlk_sk(sk)->flags & NETLINK_KERNEL_SOCKET));
869+
BUG_ON(!netlink_is_kernel(sk));
865870

866871
rcu_read_lock();
867872
listeners = rcu_dereference(nl_table[sk->sk_protocol].listeners);

0 commit comments

Comments
 (0)