GNU Linux-libre 4.4.288-gnu1
[releases.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 <linux/workqueue.h>
7 #include <net/sock.h>
8
9 #define NLGRPSZ(x)      (ALIGN(x, sizeof(unsigned long) * 8) / 8)
10 #define NLGRPLONGS(x)   (NLGRPSZ(x)/sizeof(unsigned long))
11
12 struct netlink_ring {
13         void                    **pg_vec;
14         unsigned int            head;
15         unsigned int            frames_per_block;
16         unsigned int            frame_size;
17         unsigned int            frame_max;
18
19         unsigned int            pg_vec_order;
20         unsigned int            pg_vec_pages;
21         unsigned int            pg_vec_len;
22
23         atomic_t                pending;
24 };
25
26 struct netlink_sock {
27         /* struct sock has to be the first member of netlink_sock */
28         struct sock             sk;
29         u32                     portid;
30         u32                     dst_portid;
31         u32                     dst_group;
32         u32                     flags;
33         u32                     subscriptions;
34         u32                     ngroups;
35         unsigned long           *groups;
36         unsigned long           state;
37         size_t                  max_recvmsg_len;
38         wait_queue_head_t       wait;
39         bool                    bound;
40         bool                    cb_running;
41         int                     dump_done_errno;
42         struct netlink_callback cb;
43         struct mutex            *cb_mutex;
44         struct mutex            cb_def_mutex;
45         void                    (*netlink_rcv)(struct sk_buff *skb);
46         int                     (*netlink_bind)(struct net *net, int group);
47         void                    (*netlink_unbind)(struct net *net, int group);
48         struct module           *module;
49
50         struct rhash_head       node;
51         struct rcu_head         rcu;
52         struct work_struct      work;
53 };
54
55 static inline struct netlink_sock *nlk_sk(struct sock *sk)
56 {
57         return container_of(sk, struct netlink_sock, sk);
58 }
59
60 struct netlink_table {
61         struct rhashtable       hash;
62         struct hlist_head       mc_list;
63         struct listeners __rcu  *listeners;
64         unsigned int            flags;
65         unsigned int            groups;
66         struct mutex            *cb_mutex;
67         struct module           *module;
68         int                     (*bind)(struct net *net, int group);
69         void                    (*unbind)(struct net *net, int group);
70         bool                    (*compare)(struct net *net, struct sock *sock);
71         int                     registered;
72 };
73
74 extern struct netlink_table *nl_table;
75 extern rwlock_t nl_table_lock;
76
77 #endif