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 */ 118fe08d70SEric Dumazet enum { 128fe08d70SEric Dumazet NETLINK_F_KERNEL_SOCKET, 138fe08d70SEric Dumazet NETLINK_F_RECV_PKTINFO, 148fe08d70SEric Dumazet NETLINK_F_BROADCAST_SEND_ERROR, 158fe08d70SEric Dumazet NETLINK_F_RECV_NO_ENOBUFS, 168fe08d70SEric Dumazet NETLINK_F_LISTEN_ALL_NSID, 178fe08d70SEric Dumazet NETLINK_F_CAP_ACK, 188fe08d70SEric Dumazet NETLINK_F_EXT_ACK, 198fe08d70SEric Dumazet NETLINK_F_STRICT_CHK, 208fe08d70SEric Dumazet }; 21457c79e5SAndrey Vagin 220f29c768SAndrey Vagin #define NLGRPSZ(x) (ALIGN(x, sizeof(unsigned long) * 8) / 8) 230f29c768SAndrey Vagin #define NLGRPLONGS(x) (NLGRPSZ(x)/sizeof(unsigned long)) 240f29c768SAndrey Vagin 250f29c768SAndrey Vagin struct netlink_sock { 260f29c768SAndrey Vagin /* struct sock has to be the first member of netlink_sock */ 270f29c768SAndrey Vagin struct sock sk; 288fe08d70SEric Dumazet unsigned long flags; 290f29c768SAndrey Vagin u32 portid; 300f29c768SAndrey Vagin u32 dst_portid; 310f29c768SAndrey Vagin u32 dst_group; 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; 38da314c99SHerbert Xu bool bound; 3916b304f3SPravin B Shelar bool cb_running; 400642840bSJason A. Donenfeld int dump_done_errno; 4116b304f3SPravin B Shelar struct netlink_callback cb; 42*c8c76f15SEric Dumazet struct mutex nl_cb_mutex; 43*c8c76f15SEric Dumazet 44*c8c76f15SEric Dumazet struct mutex *dump_cb_mutex; 450f29c768SAndrey Vagin void (*netlink_rcv)(struct sk_buff *skb); 46023e2cfaSJohannes Berg int (*netlink_bind)(struct net *net, int group); 47023e2cfaSJohannes Berg void (*netlink_unbind)(struct net *net, int group); 48a4c9a56eSAnjali Kulkarni void (*netlink_release)(struct sock *sk, 49a4c9a56eSAnjali Kulkarni unsigned long *groups); 500f29c768SAndrey Vagin struct module *module; 51e341694eSThomas Graf 52e341694eSThomas Graf struct rhash_head node; 5321e4902aSThomas Graf struct rcu_head rcu; 54707693c8SHerbert Xu struct work_struct work; 550f29c768SAndrey Vagin }; 560f29c768SAndrey Vagin 570f29c768SAndrey Vagin static inline struct netlink_sock *nlk_sk(struct sock *sk) 580f29c768SAndrey Vagin { 590f29c768SAndrey Vagin return container_of(sk, struct netlink_sock, sk); 600f29c768SAndrey Vagin } 610f29c768SAndrey Vagin 628fe08d70SEric Dumazet #define nlk_test_bit(nr, sk) test_bit(NETLINK_F_##nr, &nlk_sk(sk)->flags) 638fe08d70SEric Dumazet 640f29c768SAndrey Vagin struct netlink_table { 65e341694eSThomas Graf struct rhashtable hash; 660f29c768SAndrey Vagin struct hlist_head mc_list; 670f29c768SAndrey Vagin struct listeners __rcu *listeners; 680f29c768SAndrey Vagin unsigned int flags; 690f29c768SAndrey Vagin unsigned int groups; 700f29c768SAndrey Vagin struct mutex *cb_mutex; 710f29c768SAndrey Vagin struct module *module; 72023e2cfaSJohannes Berg int (*bind)(struct net *net, int group); 73023e2cfaSJohannes Berg void (*unbind)(struct net *net, int group); 74a4c9a56eSAnjali Kulkarni void (*release)(struct sock *sk, 75a4c9a56eSAnjali Kulkarni unsigned long *groups); 760f29c768SAndrey Vagin int registered; 770f29c768SAndrey Vagin }; 780f29c768SAndrey Vagin 790f29c768SAndrey Vagin extern struct netlink_table *nl_table; 800f29c768SAndrey Vagin extern rwlock_t nl_table_lock; 810f29c768SAndrey Vagin 820f29c768SAndrey Vagin #endif 83