af_netlink.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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_ring {
  10. void **pg_vec;
  11. unsigned int head;
  12. unsigned int frames_per_block;
  13. unsigned int frame_size;
  14. unsigned int frame_max;
  15. unsigned int pg_vec_order;
  16. unsigned int pg_vec_pages;
  17. unsigned int pg_vec_len;
  18. atomic_t pending;
  19. };
  20. struct netlink_sock {
  21. /* struct sock has to be the first member of netlink_sock */
  22. struct sock sk;
  23. u32 portid;
  24. u32 dst_portid;
  25. u32 dst_group;
  26. u32 flags;
  27. u32 subscriptions;
  28. u32 ngroups;
  29. unsigned long *groups;
  30. unsigned long state;
  31. size_t max_recvmsg_len;
  32. wait_queue_head_t wait;
  33. bool bound;
  34. bool cb_running;
  35. int dump_done_errno;
  36. struct netlink_callback cb;
  37. struct mutex *cb_mutex;
  38. struct mutex cb_def_mutex;
  39. void (*netlink_rcv)(struct sk_buff *skb);
  40. int (*netlink_bind)(struct net *net, int group);
  41. void (*netlink_unbind)(struct net *net, int group);
  42. struct module *module;
  43. struct rhash_head node;
  44. struct rcu_head rcu;
  45. struct work_struct work;
  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)(struct net *net, int group);
  60. void (*unbind)(struct net *net, 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. #endif