af_netlink.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef _AF_NETLINK_H
  2. #define _AF_NETLINK_H
  3. #include <linux/rhashtable.h>
  4. #include <linux/atomic.h>
  5. #include <net/sock.h>
  6. #define NLGRPSZ(x) (ALIGN(x, sizeof(unsigned long) * 8) / 8)
  7. #define NLGRPLONGS(x) (NLGRPSZ(x)/sizeof(unsigned long))
  8. struct netlink_sock {
  9. /* struct sock has to be the first member of netlink_sock */
  10. struct sock sk;
  11. u32 portid;
  12. u32 dst_portid;
  13. u32 dst_group;
  14. u32 flags;
  15. u32 subscriptions;
  16. u32 ngroups;
  17. unsigned long *groups;
  18. unsigned long state;
  19. size_t max_recvmsg_len;
  20. wait_queue_head_t wait;
  21. bool bound;
  22. bool cb_running;
  23. struct netlink_callback cb;
  24. struct mutex *cb_mutex;
  25. struct mutex cb_def_mutex;
  26. void (*netlink_rcv)(struct sk_buff *skb);
  27. int (*netlink_bind)(struct net *net, int group);
  28. void (*netlink_unbind)(struct net *net, int group);
  29. struct module *module;
  30. struct rhash_head node;
  31. struct rcu_head rcu;
  32. };
  33. static inline struct netlink_sock *nlk_sk(struct sock *sk)
  34. {
  35. return container_of(sk, struct netlink_sock, sk);
  36. }
  37. struct netlink_table {
  38. struct rhashtable hash;
  39. struct hlist_head mc_list;
  40. struct listeners __rcu *listeners;
  41. unsigned int flags;
  42. unsigned int groups;
  43. struct mutex *cb_mutex;
  44. struct module *module;
  45. int (*bind)(struct net *net, int group);
  46. void (*unbind)(struct net *net, int group);
  47. bool (*compare)(struct net *net, struct sock *sock);
  48. int registered;
  49. };
  50. extern struct netlink_table *nl_table;
  51. extern rwlock_t nl_table_lock;
  52. #endif