af_netlink.h 1.5 KB

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