xref: /openbmc/linux/net/netlink/af_netlink.h (revision 16b304f3404f8e0243d5ee2b70b68767b7b59b2b)
10f29c768SAndrey Vagin #ifndef _AF_NETLINK_H
20f29c768SAndrey Vagin #define _AF_NETLINK_H
30f29c768SAndrey Vagin 
40f29c768SAndrey Vagin #include <net/sock.h>
50f29c768SAndrey Vagin 
60f29c768SAndrey Vagin #define NLGRPSZ(x)	(ALIGN(x, sizeof(unsigned long) * 8) / 8)
70f29c768SAndrey Vagin #define NLGRPLONGS(x)	(NLGRPSZ(x)/sizeof(unsigned long))
80f29c768SAndrey Vagin 
9ccdfcc39SPatrick McHardy struct netlink_ring {
10ccdfcc39SPatrick McHardy 	void			**pg_vec;
11ccdfcc39SPatrick McHardy 	unsigned int		head;
12ccdfcc39SPatrick McHardy 	unsigned int		frames_per_block;
13ccdfcc39SPatrick McHardy 	unsigned int		frame_size;
14ccdfcc39SPatrick McHardy 	unsigned int		frame_max;
15ccdfcc39SPatrick McHardy 
16ccdfcc39SPatrick McHardy 	unsigned int		pg_vec_order;
17ccdfcc39SPatrick McHardy 	unsigned int		pg_vec_pages;
18ccdfcc39SPatrick McHardy 	unsigned int		pg_vec_len;
19ccdfcc39SPatrick McHardy 
20ccdfcc39SPatrick McHardy 	atomic_t		pending;
21ccdfcc39SPatrick McHardy };
22ccdfcc39SPatrick McHardy 
230f29c768SAndrey Vagin struct netlink_sock {
240f29c768SAndrey Vagin 	/* struct sock has to be the first member of netlink_sock */
250f29c768SAndrey Vagin 	struct sock		sk;
260f29c768SAndrey Vagin 	u32			portid;
270f29c768SAndrey Vagin 	u32			dst_portid;
280f29c768SAndrey Vagin 	u32			dst_group;
290f29c768SAndrey Vagin 	u32			flags;
300f29c768SAndrey Vagin 	u32			subscriptions;
310f29c768SAndrey Vagin 	u32			ngroups;
320f29c768SAndrey Vagin 	unsigned long		*groups;
330f29c768SAndrey Vagin 	unsigned long		state;
340f29c768SAndrey Vagin 	wait_queue_head_t	wait;
35*16b304f3SPravin B Shelar 	bool			cb_running;
36*16b304f3SPravin B Shelar 	struct netlink_callback	cb;
370f29c768SAndrey Vagin 	struct mutex		*cb_mutex;
380f29c768SAndrey Vagin 	struct mutex		cb_def_mutex;
390f29c768SAndrey Vagin 	void			(*netlink_rcv)(struct sk_buff *skb);
400f29c768SAndrey Vagin 	void			(*netlink_bind)(int group);
410f29c768SAndrey Vagin 	struct module		*module;
42ccdfcc39SPatrick McHardy #ifdef CONFIG_NETLINK_MMAP
43ccdfcc39SPatrick McHardy 	struct mutex		pg_vec_lock;
44ccdfcc39SPatrick McHardy 	struct netlink_ring	rx_ring;
45ccdfcc39SPatrick McHardy 	struct netlink_ring	tx_ring;
46ccdfcc39SPatrick McHardy 	atomic_t		mapped;
47ccdfcc39SPatrick McHardy #endif /* CONFIG_NETLINK_MMAP */
480f29c768SAndrey Vagin };
490f29c768SAndrey Vagin 
500f29c768SAndrey Vagin static inline struct netlink_sock *nlk_sk(struct sock *sk)
510f29c768SAndrey Vagin {
520f29c768SAndrey Vagin 	return container_of(sk, struct netlink_sock, sk);
530f29c768SAndrey Vagin }
540f29c768SAndrey Vagin 
550f29c768SAndrey Vagin struct nl_portid_hash {
560f29c768SAndrey Vagin 	struct hlist_head	*table;
570f29c768SAndrey Vagin 	unsigned long		rehash_time;
580f29c768SAndrey Vagin 
590f29c768SAndrey Vagin 	unsigned int		mask;
600f29c768SAndrey Vagin 	unsigned int		shift;
610f29c768SAndrey Vagin 
620f29c768SAndrey Vagin 	unsigned int		entries;
630f29c768SAndrey Vagin 	unsigned int		max_shift;
640f29c768SAndrey Vagin 
650f29c768SAndrey Vagin 	u32			rnd;
660f29c768SAndrey Vagin };
670f29c768SAndrey Vagin 
680f29c768SAndrey Vagin struct netlink_table {
690f29c768SAndrey Vagin 	struct nl_portid_hash	hash;
700f29c768SAndrey Vagin 	struct hlist_head	mc_list;
710f29c768SAndrey Vagin 	struct listeners __rcu	*listeners;
720f29c768SAndrey Vagin 	unsigned int		flags;
730f29c768SAndrey Vagin 	unsigned int		groups;
740f29c768SAndrey Vagin 	struct mutex		*cb_mutex;
750f29c768SAndrey Vagin 	struct module		*module;
760f29c768SAndrey Vagin 	void			(*bind)(int group);
77da12c90eSGao feng 	bool			(*compare)(struct net *net, struct sock *sock);
780f29c768SAndrey Vagin 	int			registered;
790f29c768SAndrey Vagin };
800f29c768SAndrey Vagin 
810f29c768SAndrey Vagin extern struct netlink_table *nl_table;
820f29c768SAndrey Vagin extern rwlock_t nl_table_lock;
830f29c768SAndrey Vagin 
840f29c768SAndrey Vagin #endif
85