Merge branch 'work.uaccess' into for-linus
[cascardo/linux.git] / net / netlink / af_netlink.h
1 #ifndef _AF_NETLINK_H
2 #define _AF_NETLINK_H
3
4 #include <linux/rhashtable.h>
5 #include <linux/atomic.h>
6 #include <net/sock.h>
7
8 #define NLGRPSZ(x)      (ALIGN(x, sizeof(unsigned long) * 8) / 8)
9 #define NLGRPLONGS(x)   (NLGRPSZ(x)/sizeof(unsigned long))
10
11 struct netlink_sock {
12         /* struct sock has to be the first member of netlink_sock */
13         struct sock             sk;
14         u32                     portid;
15         u32                     dst_portid;
16         u32                     dst_group;
17         u32                     flags;
18         u32                     subscriptions;
19         u32                     ngroups;
20         unsigned long           *groups;
21         unsigned long           state;
22         size_t                  max_recvmsg_len;
23         wait_queue_head_t       wait;
24         bool                    bound;
25         bool                    cb_running;
26         struct netlink_callback cb;
27         struct mutex            *cb_mutex;
28         struct mutex            cb_def_mutex;
29         void                    (*netlink_rcv)(struct sk_buff *skb);
30         int                     (*netlink_bind)(struct net *net, int group);
31         void                    (*netlink_unbind)(struct net *net, int group);
32         struct module           *module;
33
34         struct rhash_head       node;
35         struct rcu_head         rcu;
36 };
37
38 static inline struct netlink_sock *nlk_sk(struct sock *sk)
39 {
40         return container_of(sk, struct netlink_sock, sk);
41 }
42
43 struct netlink_table {
44         struct rhashtable       hash;
45         struct hlist_head       mc_list;
46         struct listeners __rcu  *listeners;
47         unsigned int            flags;
48         unsigned int            groups;
49         struct mutex            *cb_mutex;
50         struct module           *module;
51         int                     (*bind)(struct net *net, int group);
52         void                    (*unbind)(struct net *net, int group);
53         bool                    (*compare)(struct net *net, struct sock *sock);
54         int                     registered;
55 };
56
57 extern struct netlink_table *nl_table;
58 extern rwlock_t nl_table_lock;
59
60 #endif