af_netlink.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef _AF_NETLINK_H
  2. #define _AF_NETLINK_H
  3. #include <linux/rhashtable.h>
  4. #include <net/sock.h>
  5. #define NLGRPSZ(x) (ALIGN(x, sizeof(unsigned long) * 8) / 8)
  6. #define NLGRPLONGS(x) (NLGRPSZ(x)/sizeof(unsigned long))
  7. struct netlink_ring {
  8. void **pg_vec;
  9. unsigned int head;
  10. unsigned int frames_per_block;
  11. unsigned int frame_size;
  12. unsigned int frame_max;
  13. unsigned int pg_vec_order;
  14. unsigned int pg_vec_pages;
  15. unsigned int pg_vec_len;
  16. atomic_t pending;
  17. };
  18. struct netlink_sock {
  19. /* struct sock has to be the first member of netlink_sock */
  20. struct sock sk;
  21. u32 portid;
  22. u32 dst_portid;
  23. u32 dst_group;
  24. u32 flags;
  25. u32 subscriptions;
  26. u32 ngroups;
  27. unsigned long *groups;
  28. unsigned long state;
  29. size_t max_recvmsg_len;
  30. wait_queue_head_t wait;
  31. bool cb_running;
  32. struct netlink_callback cb;
  33. struct mutex *cb_mutex;
  34. struct mutex cb_def_mutex;
  35. void (*netlink_rcv)(struct sk_buff *skb);
  36. int (*netlink_bind)(int group);
  37. void (*netlink_unbind)(int group);
  38. struct module *module;
  39. #ifdef CONFIG_NETLINK_MMAP
  40. struct mutex pg_vec_lock;
  41. struct netlink_ring rx_ring;
  42. struct netlink_ring tx_ring;
  43. atomic_t mapped;
  44. #endif /* CONFIG_NETLINK_MMAP */
  45. struct rhash_head node;
  46. };
  47. static inline struct netlink_sock *nlk_sk(struct sock *sk)
  48. {
  49. return container_of(sk, struct netlink_sock, sk);
  50. }
  51. struct netlink_table {
  52. struct rhashtable hash;
  53. struct hlist_head mc_list;
  54. struct listeners __rcu *listeners;
  55. unsigned int flags;
  56. unsigned int groups;
  57. struct mutex *cb_mutex;
  58. struct module *module;
  59. int (*bind)(int group);
  60. void (*unbind)(int group);
  61. bool (*compare)(struct net *net, struct sock *sock);
  62. int registered;
  63. };
  64. extern struct netlink_table *nl_table;
  65. extern rwlock_t nl_table_lock;
  66. extern struct mutex nl_sk_hash_lock;
  67. #endif