1*b2441318SGreg 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; 3716b304f3SPravin B Shelar struct netlink_callback cb; 380f29c768SAndrey Vagin struct mutex *cb_mutex; 390f29c768SAndrey Vagin struct mutex cb_def_mutex; 400f29c768SAndrey Vagin void (*netlink_rcv)(struct sk_buff *skb); 41023e2cfaSJohannes Berg int (*netlink_bind)(struct net *net, int group); 42023e2cfaSJohannes Berg void (*netlink_unbind)(struct net *net, int group); 430f29c768SAndrey Vagin struct module *module; 44e341694eSThomas Graf 45e341694eSThomas Graf struct rhash_head node; 4621e4902aSThomas Graf struct rcu_head rcu; 47707693c8SHerbert Xu struct work_struct work; 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 netlink_table { 56e341694eSThomas Graf struct rhashtable hash; 570f29c768SAndrey Vagin struct hlist_head mc_list; 580f29c768SAndrey Vagin struct listeners __rcu *listeners; 590f29c768SAndrey Vagin unsigned int flags; 600f29c768SAndrey Vagin unsigned int groups; 610f29c768SAndrey Vagin struct mutex *cb_mutex; 620f29c768SAndrey Vagin struct module *module; 63023e2cfaSJohannes Berg int (*bind)(struct net *net, int group); 64023e2cfaSJohannes Berg void (*unbind)(struct net *net, int group); 65da12c90eSGao feng bool (*compare)(struct net *net, struct sock *sock); 660f29c768SAndrey Vagin int registered; 670f29c768SAndrey Vagin }; 680f29c768SAndrey Vagin 690f29c768SAndrey Vagin extern struct netlink_table *nl_table; 700f29c768SAndrey Vagin extern rwlock_t nl_table_lock; 710f29c768SAndrey Vagin 720f29c768SAndrey Vagin #endif 73