xref: /openbmc/linux/net/netlink/af_netlink.h (revision ee1c244219fd652964710a6cc3e4f922e86aa492)
10f29c768SAndrey Vagin #ifndef _AF_NETLINK_H
20f29c768SAndrey Vagin #define _AF_NETLINK_H
30f29c768SAndrey Vagin 
4e341694eSThomas Graf #include <linux/rhashtable.h>
5*ee1c2442SJohannes Berg #include <linux/atomic.h>
60f29c768SAndrey Vagin #include <net/sock.h>
70f29c768SAndrey Vagin 
80f29c768SAndrey Vagin #define NLGRPSZ(x)	(ALIGN(x, sizeof(unsigned long) * 8) / 8)
90f29c768SAndrey Vagin #define NLGRPLONGS(x)	(NLGRPSZ(x)/sizeof(unsigned long))
100f29c768SAndrey Vagin 
11ccdfcc39SPatrick McHardy struct netlink_ring {
12ccdfcc39SPatrick McHardy 	void			**pg_vec;
13ccdfcc39SPatrick McHardy 	unsigned int		head;
14ccdfcc39SPatrick McHardy 	unsigned int		frames_per_block;
15ccdfcc39SPatrick McHardy 	unsigned int		frame_size;
16ccdfcc39SPatrick McHardy 	unsigned int		frame_max;
17ccdfcc39SPatrick McHardy 
18ccdfcc39SPatrick McHardy 	unsigned int		pg_vec_order;
19ccdfcc39SPatrick McHardy 	unsigned int		pg_vec_pages;
20ccdfcc39SPatrick McHardy 	unsigned int		pg_vec_len;
21ccdfcc39SPatrick McHardy 
22ccdfcc39SPatrick McHardy 	atomic_t		pending;
23ccdfcc39SPatrick McHardy };
24ccdfcc39SPatrick McHardy 
250f29c768SAndrey Vagin struct netlink_sock {
260f29c768SAndrey Vagin 	/* struct sock has to be the first member of netlink_sock */
270f29c768SAndrey Vagin 	struct sock		sk;
280f29c768SAndrey Vagin 	u32			portid;
290f29c768SAndrey Vagin 	u32			dst_portid;
300f29c768SAndrey Vagin 	u32			dst_group;
310f29c768SAndrey Vagin 	u32			flags;
320f29c768SAndrey Vagin 	u32			subscriptions;
330f29c768SAndrey Vagin 	u32			ngroups;
340f29c768SAndrey Vagin 	unsigned long		*groups;
350f29c768SAndrey Vagin 	unsigned long		state;
369063e21fSEric Dumazet 	size_t			max_recvmsg_len;
370f29c768SAndrey Vagin 	wait_queue_head_t	wait;
3816b304f3SPravin B Shelar 	bool			cb_running;
3916b304f3SPravin B Shelar 	struct netlink_callback	cb;
400f29c768SAndrey Vagin 	struct mutex		*cb_mutex;
410f29c768SAndrey Vagin 	struct mutex		cb_def_mutex;
420f29c768SAndrey Vagin 	void			(*netlink_rcv)(struct sk_buff *skb);
43023e2cfaSJohannes Berg 	int			(*netlink_bind)(struct net *net, int group);
44023e2cfaSJohannes Berg 	void			(*netlink_unbind)(struct net *net, int group);
450f29c768SAndrey Vagin 	struct module		*module;
46ccdfcc39SPatrick McHardy #ifdef CONFIG_NETLINK_MMAP
47ccdfcc39SPatrick McHardy 	struct mutex		pg_vec_lock;
48ccdfcc39SPatrick McHardy 	struct netlink_ring	rx_ring;
49ccdfcc39SPatrick McHardy 	struct netlink_ring	tx_ring;
50ccdfcc39SPatrick McHardy 	atomic_t		mapped;
51ccdfcc39SPatrick McHardy #endif /* CONFIG_NETLINK_MMAP */
52e341694eSThomas Graf 
53e341694eSThomas Graf 	struct rhash_head	node;
540f29c768SAndrey Vagin };
550f29c768SAndrey Vagin 
560f29c768SAndrey Vagin static inline struct netlink_sock *nlk_sk(struct sock *sk)
570f29c768SAndrey Vagin {
580f29c768SAndrey Vagin 	return container_of(sk, struct netlink_sock, sk);
590f29c768SAndrey Vagin }
600f29c768SAndrey Vagin 
610f29c768SAndrey Vagin struct netlink_table {
62e341694eSThomas Graf 	struct rhashtable	hash;
630f29c768SAndrey Vagin 	struct hlist_head	mc_list;
640f29c768SAndrey Vagin 	struct listeners __rcu	*listeners;
650f29c768SAndrey Vagin 	unsigned int		flags;
660f29c768SAndrey Vagin 	unsigned int		groups;
670f29c768SAndrey Vagin 	struct mutex		*cb_mutex;
680f29c768SAndrey Vagin 	struct module		*module;
69023e2cfaSJohannes Berg 	int			(*bind)(struct net *net, int group);
70023e2cfaSJohannes Berg 	void			(*unbind)(struct net *net, int group);
71da12c90eSGao feng 	bool			(*compare)(struct net *net, struct sock *sock);
720f29c768SAndrey Vagin 	int			registered;
730f29c768SAndrey Vagin };
740f29c768SAndrey Vagin 
750f29c768SAndrey Vagin extern struct netlink_table *nl_table;
760f29c768SAndrey Vagin extern rwlock_t nl_table_lock;
776c8f7e70SThomas Graf extern struct mutex nl_sk_hash_lock;
780f29c768SAndrey Vagin 
790f29c768SAndrey Vagin #endif
80