blob: ea4600aea6b0bebeb42addbe92cd38164654df90 [file] [log] [blame]
Kyle Swenson8d8f6542021-03-15 11:02:55 -06001#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
12struct 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
26struct 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
49 struct rhash_head node;
50 struct rcu_head rcu;
51 struct work_struct work;
52};
53
54static inline struct netlink_sock *nlk_sk(struct sock *sk)
55{
56 return container_of(sk, struct netlink_sock, sk);
57}
58
59struct netlink_table {
60 struct rhashtable hash;
61 struct hlist_head mc_list;
62 struct listeners __rcu *listeners;
63 unsigned int flags;
64 unsigned int groups;
65 struct mutex *cb_mutex;
66 struct module *module;
67 int (*bind)(struct net *net, int group);
68 void (*unbind)(struct net *net, int group);
69 bool (*compare)(struct net *net, struct sock *sock);
70 int registered;
71};
72
73extern struct netlink_table *nl_table;
74extern rwlock_t nl_table_lock;
75
76#endif