af_netlink.h 1.8 KB

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