xref: /openbmc/linux/net/netlink/af_netlink.h (revision 0642840b8bb008528dbdf929cec9f65ac4231ad0)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
20f29c768SAndrey Vagin #ifndef _AF_NETLINK_H
30f29c768SAndrey Vagin #define _AF_NETLINK_H
40f29c768SAndrey Vagin 
5e341694eSThomas Graf #include <linux/rhashtable.h>
6ee1c2442SJohannes Berg #include <linux/atomic.h>
7707693c8SHerbert Xu #include <linux/workqueue.h>
80f29c768SAndrey Vagin #include <net/sock.h>
90f29c768SAndrey Vagin 
10457c79e5SAndrey Vagin /* flags */
11457c79e5SAndrey Vagin #define NETLINK_F_KERNEL_SOCKET		0x1
12457c79e5SAndrey Vagin #define NETLINK_F_RECV_PKTINFO		0x2
13457c79e5SAndrey Vagin #define NETLINK_F_BROADCAST_SEND_ERROR	0x4
14457c79e5SAndrey Vagin #define NETLINK_F_RECV_NO_ENOBUFS	0x8
15457c79e5SAndrey Vagin #define NETLINK_F_LISTEN_ALL_NSID	0x10
16457c79e5SAndrey Vagin #define NETLINK_F_CAP_ACK		0x20
172d4bc933SJohannes Berg #define NETLINK_F_EXT_ACK		0x40
18457c79e5SAndrey Vagin 
190f29c768SAndrey Vagin #define NLGRPSZ(x)	(ALIGN(x, sizeof(unsigned long) * 8) / 8)
200f29c768SAndrey Vagin #define NLGRPLONGS(x)	(NLGRPSZ(x)/sizeof(unsigned long))
210f29c768SAndrey Vagin 
220f29c768SAndrey Vagin struct netlink_sock {
230f29c768SAndrey Vagin 	/* struct sock has to be the first member of netlink_sock */
240f29c768SAndrey Vagin 	struct sock		sk;
250f29c768SAndrey Vagin 	u32			portid;
260f29c768SAndrey Vagin 	u32			dst_portid;
270f29c768SAndrey Vagin 	u32			dst_group;
280f29c768SAndrey Vagin 	u32			flags;
290f29c768SAndrey Vagin 	u32			subscriptions;
300f29c768SAndrey Vagin 	u32			ngroups;
310f29c768SAndrey Vagin 	unsigned long		*groups;
320f29c768SAndrey Vagin 	unsigned long		state;
339063e21fSEric Dumazet 	size_t			max_recvmsg_len;
340f29c768SAndrey Vagin 	wait_queue_head_t	wait;
35da314c99SHerbert Xu 	bool			bound;
3616b304f3SPravin B Shelar 	bool			cb_running;
37*0642840bSJason A. Donenfeld 	int			dump_done_errno;
3816b304f3SPravin B Shelar 	struct netlink_callback	cb;
390f29c768SAndrey Vagin 	struct mutex		*cb_mutex;
400f29c768SAndrey Vagin 	struct mutex		cb_def_mutex;
410f29c768SAndrey Vagin 	void			(*netlink_rcv)(struct sk_buff *skb);
42023e2cfaSJohannes Berg 	int			(*netlink_bind)(struct net *net, int group);
43023e2cfaSJohannes Berg 	void			(*netlink_unbind)(struct net *net, int group);
440f29c768SAndrey Vagin 	struct module		*module;
45e341694eSThomas Graf 
46e341694eSThomas Graf 	struct rhash_head	node;
4721e4902aSThomas Graf 	struct rcu_head		rcu;
48707693c8SHerbert Xu 	struct work_struct	work;
490f29c768SAndrey Vagin };
500f29c768SAndrey Vagin 
510f29c768SAndrey Vagin static inline struct netlink_sock *nlk_sk(struct sock *sk)
520f29c768SAndrey Vagin {
530f29c768SAndrey Vagin 	return container_of(sk, struct netlink_sock, sk);
540f29c768SAndrey Vagin }
550f29c768SAndrey Vagin 
560f29c768SAndrey Vagin struct netlink_table {
57e341694eSThomas Graf 	struct rhashtable	hash;
580f29c768SAndrey Vagin 	struct hlist_head	mc_list;
590f29c768SAndrey Vagin 	struct listeners __rcu	*listeners;
600f29c768SAndrey Vagin 	unsigned int		flags;
610f29c768SAndrey Vagin 	unsigned int		groups;
620f29c768SAndrey Vagin 	struct mutex		*cb_mutex;
630f29c768SAndrey Vagin 	struct module		*module;
64023e2cfaSJohannes Berg 	int			(*bind)(struct net *net, int group);
65023e2cfaSJohannes Berg 	void			(*unbind)(struct net *net, int group);
66da12c90eSGao feng 	bool			(*compare)(struct net *net, struct sock *sock);
670f29c768SAndrey Vagin 	int			registered;
680f29c768SAndrey Vagin };
690f29c768SAndrey Vagin 
700f29c768SAndrey Vagin extern struct netlink_table *nl_table;
710f29c768SAndrey Vagin extern rwlock_t nl_table_lock;
720f29c768SAndrey Vagin 
730f29c768SAndrey Vagin #endif
74