blob: 5f454c8de6a4de07996578538d98bfd8ad45b950 [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
David Ahern89d35522018-10-07 20:16:27 -070018#define NETLINK_F_STRICT_CHK 0x80
Andrey Vagin457c79e2017-04-03 18:13:32 -070019
Andrey Vagin0f29c762013-03-21 20:33:47 +040020#define NLGRPSZ(x) (ALIGN(x, sizeof(unsigned long) * 8) / 8)
21#define NLGRPLONGS(x) (NLGRPSZ(x)/sizeof(unsigned long))
22
23struct netlink_sock {
24 /* struct sock has to be the first member of netlink_sock */
25 struct sock sk;
26 u32 portid;
27 u32 dst_portid;
28 u32 dst_group;
29 u32 flags;
30 u32 subscriptions;
31 u32 ngroups;
32 unsigned long *groups;
33 unsigned long state;
Eric Dumazet9063e212014-03-07 12:02:33 -080034 size_t max_recvmsg_len;
Andrey Vagin0f29c762013-03-21 20:33:47 +040035 wait_queue_head_t wait;
Herbert Xuda314c92015-09-22 11:38:56 +080036 bool bound;
Pravin B Shelar16b304f2013-08-15 15:31:06 -070037 bool cb_running;
Jason A. Donenfeld06428402017-11-09 13:04:44 +090038 int dump_done_errno;
Pravin B Shelar16b304f2013-08-15 15:31:06 -070039 struct netlink_callback cb;
Andrey Vagin0f29c762013-03-21 20:33:47 +040040 struct mutex *cb_mutex;
41 struct mutex cb_def_mutex;
42 void (*netlink_rcv)(struct sk_buff *skb);
Johannes Berg023e2cf2014-12-23 21:00:06 +010043 int (*netlink_bind)(struct net *net, int group);
44 void (*netlink_unbind)(struct net *net, int group);
Andrey Vagin0f29c762013-03-21 20:33:47 +040045 struct module *module;
Thomas Grafe3416942014-08-02 11:47:45 +020046
47 struct rhash_head node;
Thomas Graf21e49022015-01-02 23:00:22 +010048 struct rcu_head rcu;
Herbert Xu707693c2016-11-28 19:22:12 +080049 struct work_struct work;
Andrey Vagin0f29c762013-03-21 20:33:47 +040050};
51
52static inline struct netlink_sock *nlk_sk(struct sock *sk)
53{
54 return container_of(sk, struct netlink_sock, sk);
55}
56
Andrey Vagin0f29c762013-03-21 20:33:47 +040057struct netlink_table {
Thomas Grafe3416942014-08-02 11:47:45 +020058 struct rhashtable hash;
Andrey Vagin0f29c762013-03-21 20:33:47 +040059 struct hlist_head mc_list;
60 struct listeners __rcu *listeners;
61 unsigned int flags;
62 unsigned int groups;
63 struct mutex *cb_mutex;
64 struct module *module;
Johannes Berg023e2cf2014-12-23 21:00:06 +010065 int (*bind)(struct net *net, int group);
66 void (*unbind)(struct net *net, int group);
Gao fengda12c902013-06-06 14:49:11 +080067 bool (*compare)(struct net *net, struct sock *sock);
Andrey Vagin0f29c762013-03-21 20:33:47 +040068 int registered;
69};
70
71extern struct netlink_table *nl_table;
72extern rwlock_t nl_table_lock;
Andrey Vagin0f29c762013-03-21 20:33:47 +040073
74#endif