af_netlink.h 1.8 KB

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