af_netlink.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. size_t max_recvmsg_len;
  29. wait_queue_head_t wait;
  30. bool cb_running;
  31. struct netlink_callback cb;
  32. struct mutex *cb_mutex;
  33. struct mutex cb_def_mutex;
  34. void (*netlink_rcv)(struct sk_buff *skb);
  35. void (*netlink_bind)(int group);
  36. struct module *module;
  37. #ifdef CONFIG_NETLINK_MMAP
  38. struct mutex pg_vec_lock;
  39. struct netlink_ring rx_ring;
  40. struct netlink_ring tx_ring;
  41. atomic_t mapped;
  42. #endif /* CONFIG_NETLINK_MMAP */
  43. };
  44. static inline struct netlink_sock *nlk_sk(struct sock *sk)
  45. {
  46. return container_of(sk, struct netlink_sock, sk);
  47. }
  48. struct nl_portid_hash {
  49. struct hlist_head *table;
  50. unsigned long rehash_time;
  51. unsigned int mask;
  52. unsigned int shift;
  53. unsigned int entries;
  54. unsigned int max_shift;
  55. u32 rnd;
  56. };
  57. struct netlink_table {
  58. struct nl_portid_hash hash;
  59. struct hlist_head mc_list;
  60. struct listeners __rcu *listeners;
  61. unsigned int flags;
  62. unsigned int groups;
  63. struct mutex *cb_mutex;
  64. struct module *module;
  65. void (*bind)(int group);
  66. bool (*compare)(struct net *net, struct sock *sock);
  67. int registered;
  68. };
  69. extern struct netlink_table *nl_table;
  70. extern rwlock_t nl_table_lock;
  71. #endif