Upgrade to 4.4.50-rt62
[kvmfornfv.git] / kernel / 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         struct netlink_callback cb;
42         struct mutex            *cb_mutex;
43         struct mutex            cb_def_mutex;
44         void                    (*netlink_rcv)(struct sk_buff *skb);
45         int                     (*netlink_bind)(struct net *net, int group);
46         void                    (*netlink_unbind)(struct net *net, int group);
47         struct module           *module;
48 #ifdef CONFIG_NETLINK_MMAP
49         struct mutex            pg_vec_lock;
50         struct netlink_ring     rx_ring;
51         struct netlink_ring     tx_ring;
52         atomic_t                mapped;
53 #endif /* CONFIG_NETLINK_MMAP */
54
55         struct rhash_head       node;
56         struct rcu_head         rcu;
57         struct work_struct      work;
58 };
59
60 static inline struct netlink_sock *nlk_sk(struct sock *sk)
61 {
62         return container_of(sk, struct netlink_sock, sk);
63 }
64
65 static inline bool netlink_skb_is_mmaped(const struct sk_buff *skb)
66 {
67 #ifdef CONFIG_NETLINK_MMAP
68         return NETLINK_CB(skb).flags & NETLINK_SKB_MMAPED;
69 #else
70         return false;
71 #endif /* CONFIG_NETLINK_MMAP */
72 }
73
74 struct netlink_table {
75         struct rhashtable       hash;
76         struct hlist_head       mc_list;
77         struct listeners __rcu  *listeners;
78         unsigned int            flags;
79         unsigned int            groups;
80         struct mutex            *cb_mutex;
81         struct module           *module;
82         int                     (*bind)(struct net *net, int group);
83         void                    (*unbind)(struct net *net, int group);
84         bool                    (*compare)(struct net *net, struct sock *sock);
85         int                     registered;
86 };
87
88 extern struct netlink_table *nl_table;
89 extern rwlock_t nl_table_lock;
90
91 #endif