1*0f29c768SAndrey Vagin #ifndef _AF_NETLINK_H 2*0f29c768SAndrey Vagin #define _AF_NETLINK_H 3*0f29c768SAndrey Vagin 4*0f29c768SAndrey Vagin #include <net/sock.h> 5*0f29c768SAndrey Vagin 6*0f29c768SAndrey Vagin #define NLGRPSZ(x) (ALIGN(x, sizeof(unsigned long) * 8) / 8) 7*0f29c768SAndrey Vagin #define NLGRPLONGS(x) (NLGRPSZ(x)/sizeof(unsigned long)) 8*0f29c768SAndrey Vagin 9*0f29c768SAndrey Vagin struct netlink_sock { 10*0f29c768SAndrey Vagin /* struct sock has to be the first member of netlink_sock */ 11*0f29c768SAndrey Vagin struct sock sk; 12*0f29c768SAndrey Vagin u32 portid; 13*0f29c768SAndrey Vagin u32 dst_portid; 14*0f29c768SAndrey Vagin u32 dst_group; 15*0f29c768SAndrey Vagin u32 flags; 16*0f29c768SAndrey Vagin u32 subscriptions; 17*0f29c768SAndrey Vagin u32 ngroups; 18*0f29c768SAndrey Vagin unsigned long *groups; 19*0f29c768SAndrey Vagin unsigned long state; 20*0f29c768SAndrey Vagin wait_queue_head_t wait; 21*0f29c768SAndrey Vagin struct netlink_callback *cb; 22*0f29c768SAndrey Vagin struct mutex *cb_mutex; 23*0f29c768SAndrey Vagin struct mutex cb_def_mutex; 24*0f29c768SAndrey Vagin void (*netlink_rcv)(struct sk_buff *skb); 25*0f29c768SAndrey Vagin void (*netlink_bind)(int group); 26*0f29c768SAndrey Vagin struct module *module; 27*0f29c768SAndrey Vagin }; 28*0f29c768SAndrey Vagin 29*0f29c768SAndrey Vagin static inline struct netlink_sock *nlk_sk(struct sock *sk) 30*0f29c768SAndrey Vagin { 31*0f29c768SAndrey Vagin return container_of(sk, struct netlink_sock, sk); 32*0f29c768SAndrey Vagin } 33*0f29c768SAndrey Vagin 34*0f29c768SAndrey Vagin struct nl_portid_hash { 35*0f29c768SAndrey Vagin struct hlist_head *table; 36*0f29c768SAndrey Vagin unsigned long rehash_time; 37*0f29c768SAndrey Vagin 38*0f29c768SAndrey Vagin unsigned int mask; 39*0f29c768SAndrey Vagin unsigned int shift; 40*0f29c768SAndrey Vagin 41*0f29c768SAndrey Vagin unsigned int entries; 42*0f29c768SAndrey Vagin unsigned int max_shift; 43*0f29c768SAndrey Vagin 44*0f29c768SAndrey Vagin u32 rnd; 45*0f29c768SAndrey Vagin }; 46*0f29c768SAndrey Vagin 47*0f29c768SAndrey Vagin struct netlink_table { 48*0f29c768SAndrey Vagin struct nl_portid_hash hash; 49*0f29c768SAndrey Vagin struct hlist_head mc_list; 50*0f29c768SAndrey Vagin struct listeners __rcu *listeners; 51*0f29c768SAndrey Vagin unsigned int flags; 52*0f29c768SAndrey Vagin unsigned int groups; 53*0f29c768SAndrey Vagin struct mutex *cb_mutex; 54*0f29c768SAndrey Vagin struct module *module; 55*0f29c768SAndrey Vagin void (*bind)(int group); 56*0f29c768SAndrey Vagin int registered; 57*0f29c768SAndrey Vagin }; 58*0f29c768SAndrey Vagin 59*0f29c768SAndrey Vagin extern struct netlink_table *nl_table; 60*0f29c768SAndrey Vagin extern rwlock_t nl_table_lock; 61*0f29c768SAndrey Vagin 62*0f29c768SAndrey Vagin #endif 63