blob: 962de7b3c023d44e5ab5bc5a62544c181963d9cd [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Andrey Vagin0f29c762013-03-21 20:33:47 +04002#ifndef _AF_NETLINK_H
3#define _AF_NETLINK_H
4
Thomas Grafe3416942014-08-02 11:47:45 +02005#include <linux/rhashtable.h>
Johannes Bergee1c24422015-01-16 11:37:14 +01006#include <linux/atomic.h>
Herbert Xu707693c2016-11-28 19:22:12 +08007#include <linux/workqueue.h>
Andrey Vagin0f29c762013-03-21 20:33:47 +04008#include <net/sock.h>
9
Andrey Vagin457c79e2017-04-03 18:13:32 -070010/* flags */
11#define NETLINK_F_KERNEL_SOCKET 0x1
12#define NETLINK_F_RECV_PKTINFO 0x2
13#define NETLINK_F_BROADCAST_SEND_ERROR 0x4
14#define NETLINK_F_RECV_NO_ENOBUFS 0x8
15#define NETLINK_F_LISTEN_ALL_NSID 0x10
16#define NETLINK_F_CAP_ACK 0x20
Johannes Berg2d4bc932017-04-12 14:34:04 +020017#define NETLINK_F_EXT_ACK 0x40
Andrey Vagin457c79e2017-04-03 18:13:32 -070018
Andrey Vagin0f29c762013-03-21 20:33:47 +040019#define NLGRPSZ(x) (ALIGN(x, sizeof(unsigned long) * 8) / 8)
20#define NLGRPLONGS(x) (NLGRPSZ(x)/sizeof(unsigned long))
21
22struct netlink_sock {
23 /* struct sock has to be the first member of netlink_sock */
24 struct sock sk;
25 u32 portid;
26 u32 dst_portid;
27 u32 dst_group;
28 u32 flags;
29 u32 subscriptions;
30 u32 ngroups;
31 unsigned long *groups;
32 unsigned long state;
Eric Dumazet9063e212014-03-07 12:02:33 -080033 size_t max_recvmsg_len;
Andrey Vagin0f29c762013-03-21 20:33:47 +040034 wait_queue_head_t wait;
Herbert Xuda314c92015-09-22 11:38:56 +080035 bool bound;
Pravin B Shelar16b304f2013-08-15 15:31:06 -070036 bool cb_running;
Jason A. Donenfeld06428402017-11-09 13:04:44 +090037 int dump_done_errno;
Pravin B Shelar16b304f2013-08-15 15:31:06 -070038 struct netlink_callback cb;
Andrey Vagin0f29c762013-03-21 20:33:47 +040039 struct mutex *cb_mutex;
40 struct mutex cb_def_mutex;
41 void (*netlink_rcv)(struct sk_buff *skb);
Johannes Berg023e2cf2014-12-23 21:00:06 +010042 int (*netlink_bind)(struct net *net, int group);
43 void (*netlink_unbind)(struct net *net, int group);
Andrey Vagin0f29c762013-03-21 20:33:47 +040044 struct module *module;
Thomas Grafe3416942014-08-02 11:47:45 +020045
46 struct rhash_head node;
Thomas Graf21e49022015-01-02 23:00:22 +010047 struct rcu_head rcu;
Herbert Xu707693c2016-11-28 19:22:12 +080048 struct work_struct work;
Andrey Vagin0f29c762013-03-21 20:33:47 +040049};
50
51static inline struct netlink_sock *nlk_sk(struct sock *sk)
52{
53 return container_of(sk, struct netlink_sock, sk);
54}
55
Andrey Vagin0f29c762013-03-21 20:33:47 +040056struct netlink_table {
Thomas Grafe3416942014-08-02 11:47:45 +020057 struct rhashtable hash;
Andrey Vagin0f29c762013-03-21 20:33:47 +040058 struct hlist_head mc_list;
59 struct listeners __rcu *listeners;
60 unsigned int flags;
61 unsigned int groups;
62 struct mutex *cb_mutex;
63 struct module *module;
Johannes Berg023e2cf2014-12-23 21:00:06 +010064 int (*bind)(struct net *net, int group);
65 void (*unbind)(struct net *net, int group);
Gao fengda12c902013-06-06 14:49:11 +080066 bool (*compare)(struct net *net, struct sock *sock);
Andrey Vagin0f29c762013-03-21 20:33:47 +040067 int registered;
68};
69
70extern struct netlink_table *nl_table;
71extern rwlock_t nl_table_lock;
Andrey Vagin0f29c762013-03-21 20:33:47 +040072
73#endif