Commit cc3a572f authored by Nicolas Dichtel's avatar Nicolas Dichtel Committed by David S. Miller

netlink: rename private flags and states

These flags and states have the same prefix (NETLINK_) that netlink socket
options. To avoid confusion and to be able to name a flag like a socket
option, let's use an other prefix: NETLINK_[S|F]_.

Note: a comment has been fixed, it was talking about
NETLINK_RECV_NO_ENOBUFS socket option instead of NETLINK_NO_ENOBUFS.
Signed-off-by: default avatarNicolas Dichtel <nicolas.dichtel@6wind.com>
Acked-by: default avatarThomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 95f38411
...@@ -76,17 +76,17 @@ struct listeners { ...@@ -76,17 +76,17 @@ struct listeners {
}; };
/* state bits */ /* state bits */
#define NETLINK_CONGESTED 0x0 #define NETLINK_S_CONGESTED 0x0
/* flags */ /* flags */
#define NETLINK_KERNEL_SOCKET 0x1 #define NETLINK_F_KERNEL_SOCKET 0x1
#define NETLINK_RECV_PKTINFO 0x2 #define NETLINK_F_RECV_PKTINFO 0x2
#define NETLINK_BROADCAST_SEND_ERROR 0x4 #define NETLINK_F_BROADCAST_SEND_ERROR 0x4
#define NETLINK_RECV_NO_ENOBUFS 0x8 #define NETLINK_F_RECV_NO_ENOBUFS 0x8
static inline int netlink_is_kernel(struct sock *sk) static inline int netlink_is_kernel(struct sock *sk)
{ {
return nlk_sk(sk)->flags & NETLINK_KERNEL_SOCKET; return nlk_sk(sk)->flags & NETLINK_F_KERNEL_SOCKET;
} }
struct netlink_table *nl_table; struct netlink_table *nl_table;
...@@ -256,8 +256,9 @@ static void netlink_overrun(struct sock *sk) ...@@ -256,8 +256,9 @@ static void netlink_overrun(struct sock *sk)
{ {
struct netlink_sock *nlk = nlk_sk(sk); struct netlink_sock *nlk = nlk_sk(sk);
if (!(nlk->flags & NETLINK_RECV_NO_ENOBUFS)) { if (!(nlk->flags & NETLINK_F_RECV_NO_ENOBUFS)) {
if (!test_and_set_bit(NETLINK_CONGESTED, &nlk_sk(sk)->state)) { if (!test_and_set_bit(NETLINK_S_CONGESTED,
&nlk_sk(sk)->state)) {
sk->sk_err = ENOBUFS; sk->sk_err = ENOBUFS;
sk->sk_error_report(sk); sk->sk_error_report(sk);
} }
...@@ -270,8 +271,8 @@ static void netlink_rcv_wake(struct sock *sk) ...@@ -270,8 +271,8 @@ static void netlink_rcv_wake(struct sock *sk)
struct netlink_sock *nlk = nlk_sk(sk); struct netlink_sock *nlk = nlk_sk(sk);
if (skb_queue_empty(&sk->sk_receive_queue)) if (skb_queue_empty(&sk->sk_receive_queue))
clear_bit(NETLINK_CONGESTED, &nlk->state); clear_bit(NETLINK_S_CONGESTED, &nlk->state);
if (!test_bit(NETLINK_CONGESTED, &nlk->state)) if (!test_bit(NETLINK_S_CONGESTED, &nlk->state))
wake_up_interruptible(&nlk->wait); wake_up_interruptible(&nlk->wait);
} }
...@@ -1656,7 +1657,7 @@ int netlink_attachskb(struct sock *sk, struct sk_buff *skb, ...@@ -1656,7 +1657,7 @@ int netlink_attachskb(struct sock *sk, struct sk_buff *skb,
nlk = nlk_sk(sk); nlk = nlk_sk(sk);
if ((atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf || if ((atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf ||
test_bit(NETLINK_CONGESTED, &nlk->state)) && test_bit(NETLINK_S_CONGESTED, &nlk->state)) &&
!netlink_skb_is_mmaped(skb)) { !netlink_skb_is_mmaped(skb)) {
DECLARE_WAITQUEUE(wait, current); DECLARE_WAITQUEUE(wait, current);
if (!*timeo) { if (!*timeo) {
...@@ -1671,7 +1672,7 @@ int netlink_attachskb(struct sock *sk, struct sk_buff *skb, ...@@ -1671,7 +1672,7 @@ int netlink_attachskb(struct sock *sk, struct sk_buff *skb,
add_wait_queue(&nlk->wait, &wait); add_wait_queue(&nlk->wait, &wait);
if ((atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf || if ((atomic_read(&sk->sk_rmem_alloc) > sk->sk_rcvbuf ||
test_bit(NETLINK_CONGESTED, &nlk->state)) && test_bit(NETLINK_S_CONGESTED, &nlk->state)) &&
!sock_flag(sk, SOCK_DEAD)) !sock_flag(sk, SOCK_DEAD))
*timeo = schedule_timeout(*timeo); *timeo = schedule_timeout(*timeo);
...@@ -1895,7 +1896,7 @@ static int netlink_broadcast_deliver(struct sock *sk, struct sk_buff *skb) ...@@ -1895,7 +1896,7 @@ static int netlink_broadcast_deliver(struct sock *sk, struct sk_buff *skb)
struct netlink_sock *nlk = nlk_sk(sk); struct netlink_sock *nlk = nlk_sk(sk);
if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf && if (atomic_read(&sk->sk_rmem_alloc) <= sk->sk_rcvbuf &&
!test_bit(NETLINK_CONGESTED, &nlk->state)) { !test_bit(NETLINK_S_CONGESTED, &nlk->state)) {
netlink_skb_set_owner_r(skb, sk); netlink_skb_set_owner_r(skb, sk);
__netlink_sendskb(sk, skb); __netlink_sendskb(sk, skb);
return atomic_read(&sk->sk_rmem_alloc) > (sk->sk_rcvbuf >> 1); return atomic_read(&sk->sk_rmem_alloc) > (sk->sk_rcvbuf >> 1);
...@@ -1956,7 +1957,7 @@ static void do_one_broadcast(struct sock *sk, ...@@ -1956,7 +1957,7 @@ static void do_one_broadcast(struct sock *sk,
netlink_overrun(sk); netlink_overrun(sk);
/* Clone failed. Notify ALL listeners. */ /* Clone failed. Notify ALL listeners. */
p->failure = 1; p->failure = 1;
if (nlk->flags & NETLINK_BROADCAST_SEND_ERROR) if (nlk->flags & NETLINK_F_BROADCAST_SEND_ERROR)
p->delivery_failure = 1; p->delivery_failure = 1;
} else if (p->tx_filter && p->tx_filter(sk, p->skb2, p->tx_data)) { } else if (p->tx_filter && p->tx_filter(sk, p->skb2, p->tx_data)) {
kfree_skb(p->skb2); kfree_skb(p->skb2);
...@@ -1966,7 +1967,7 @@ static void do_one_broadcast(struct sock *sk, ...@@ -1966,7 +1967,7 @@ static void do_one_broadcast(struct sock *sk,
p->skb2 = NULL; p->skb2 = NULL;
} else if ((val = netlink_broadcast_deliver(sk, p->skb2)) < 0) { } else if ((val = netlink_broadcast_deliver(sk, p->skb2)) < 0) {
netlink_overrun(sk); netlink_overrun(sk);
if (nlk->flags & NETLINK_BROADCAST_SEND_ERROR) if (nlk->flags & NETLINK_F_BROADCAST_SEND_ERROR)
p->delivery_failure = 1; p->delivery_failure = 1;
} else { } else {
p->congested |= val; p->congested |= val;
...@@ -2057,7 +2058,7 @@ static int do_one_set_err(struct sock *sk, struct netlink_set_err_data *p) ...@@ -2057,7 +2058,7 @@ static int do_one_set_err(struct sock *sk, struct netlink_set_err_data *p)
!test_bit(p->group - 1, nlk->groups)) !test_bit(p->group - 1, nlk->groups))
goto out; goto out;
if (p->code == ENOBUFS && nlk->flags & NETLINK_RECV_NO_ENOBUFS) { if (p->code == ENOBUFS && nlk->flags & NETLINK_F_RECV_NO_ENOBUFS) {
ret = 1; ret = 1;
goto out; goto out;
} }
...@@ -2076,7 +2077,7 @@ static int do_one_set_err(struct sock *sk, struct netlink_set_err_data *p) ...@@ -2076,7 +2077,7 @@ static int do_one_set_err(struct sock *sk, struct netlink_set_err_data *p)
* @code: error code, must be negative (as usual in kernelspace) * @code: error code, must be negative (as usual in kernelspace)
* *
* This function returns the number of broadcast listeners that have set the * This function returns the number of broadcast listeners that have set the
* NETLINK_RECV_NO_ENOBUFS socket option. * NETLINK_NO_ENOBUFS socket option.
*/ */
int netlink_set_err(struct sock *ssk, u32 portid, u32 group, int code) int netlink_set_err(struct sock *ssk, u32 portid, u32 group, int code)
{ {
...@@ -2136,9 +2137,9 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, ...@@ -2136,9 +2137,9 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname,
switch (optname) { switch (optname) {
case NETLINK_PKTINFO: case NETLINK_PKTINFO:
if (val) if (val)
nlk->flags |= NETLINK_RECV_PKTINFO; nlk->flags |= NETLINK_F_RECV_PKTINFO;
else else
nlk->flags &= ~NETLINK_RECV_PKTINFO; nlk->flags &= ~NETLINK_F_RECV_PKTINFO;
err = 0; err = 0;
break; break;
case NETLINK_ADD_MEMBERSHIP: case NETLINK_ADD_MEMBERSHIP:
...@@ -2167,18 +2168,18 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname, ...@@ -2167,18 +2168,18 @@ static int netlink_setsockopt(struct socket *sock, int level, int optname,
} }
case NETLINK_BROADCAST_ERROR: case NETLINK_BROADCAST_ERROR:
if (val) if (val)
nlk->flags |= NETLINK_BROADCAST_SEND_ERROR; nlk->flags |= NETLINK_F_BROADCAST_SEND_ERROR;
else else
nlk->flags &= ~NETLINK_BROADCAST_SEND_ERROR; nlk->flags &= ~NETLINK_F_BROADCAST_SEND_ERROR;
err = 0; err = 0;
break; break;
case NETLINK_NO_ENOBUFS: case NETLINK_NO_ENOBUFS:
if (val) { if (val) {
nlk->flags |= NETLINK_RECV_NO_ENOBUFS; nlk->flags |= NETLINK_F_RECV_NO_ENOBUFS;
clear_bit(NETLINK_CONGESTED, &nlk->state); clear_bit(NETLINK_S_CONGESTED, &nlk->state);
wake_up_interruptible(&nlk->wait); wake_up_interruptible(&nlk->wait);
} else { } else {
nlk->flags &= ~NETLINK_RECV_NO_ENOBUFS; nlk->flags &= ~NETLINK_F_RECV_NO_ENOBUFS;
} }
err = 0; err = 0;
break; break;
...@@ -2227,7 +2228,7 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname, ...@@ -2227,7 +2228,7 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname,
if (len < sizeof(int)) if (len < sizeof(int))
return -EINVAL; return -EINVAL;
len = sizeof(int); len = sizeof(int);
val = nlk->flags & NETLINK_RECV_PKTINFO ? 1 : 0; val = nlk->flags & NETLINK_F_RECV_PKTINFO ? 1 : 0;
if (put_user(len, optlen) || if (put_user(len, optlen) ||
put_user(val, optval)) put_user(val, optval))
return -EFAULT; return -EFAULT;
...@@ -2237,7 +2238,7 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname, ...@@ -2237,7 +2238,7 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname,
if (len < sizeof(int)) if (len < sizeof(int))
return -EINVAL; return -EINVAL;
len = sizeof(int); len = sizeof(int);
val = nlk->flags & NETLINK_BROADCAST_SEND_ERROR ? 1 : 0; val = nlk->flags & NETLINK_F_BROADCAST_SEND_ERROR ? 1 : 0;
if (put_user(len, optlen) || if (put_user(len, optlen) ||
put_user(val, optval)) put_user(val, optval))
return -EFAULT; return -EFAULT;
...@@ -2247,7 +2248,7 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname, ...@@ -2247,7 +2248,7 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname,
if (len < sizeof(int)) if (len < sizeof(int))
return -EINVAL; return -EINVAL;
len = sizeof(int); len = sizeof(int);
val = nlk->flags & NETLINK_RECV_NO_ENOBUFS ? 1 : 0; val = nlk->flags & NETLINK_F_RECV_NO_ENOBUFS ? 1 : 0;
if (put_user(len, optlen) || if (put_user(len, optlen) ||
put_user(val, optval)) put_user(val, optval))
return -EFAULT; return -EFAULT;
...@@ -2418,7 +2419,7 @@ static int netlink_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, ...@@ -2418,7 +2419,7 @@ static int netlink_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
msg->msg_namelen = sizeof(*addr); msg->msg_namelen = sizeof(*addr);
} }
if (nlk->flags & NETLINK_RECV_PKTINFO) if (nlk->flags & NETLINK_F_RECV_PKTINFO)
netlink_cmsg_recv_pktinfo(msg, skb); netlink_cmsg_recv_pktinfo(msg, skb);
memset(&scm, 0, sizeof(scm)); memset(&scm, 0, sizeof(scm));
...@@ -2502,7 +2503,7 @@ __netlink_kernel_create(struct net *net, int unit, struct module *module, ...@@ -2502,7 +2503,7 @@ __netlink_kernel_create(struct net *net, int unit, struct module *module,
goto out_sock_release; goto out_sock_release;
nlk = nlk_sk(sk); nlk = nlk_sk(sk);
nlk->flags |= NETLINK_KERNEL_SOCKET; nlk->flags |= NETLINK_F_KERNEL_SOCKET;
netlink_table_grab(); netlink_table_grab();
if (!nl_table[unit].registered) { if (!nl_table[unit].registered) {
......
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