af_netlink.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 bound;
  33. bool cb_running;
  34. struct netlink_callback cb;
  35. struct mutex *cb_mutex;
  36. struct mutex cb_def_mutex;
  37. void (*netlink_rcv)(struct sk_buff *skb);
  38. int (*netlink_bind)(struct net *net, int group);
  39. void (*netlink_unbind)(struct net *net, int group);
  40. struct module *module;
  41. struct rhash_head node;
  42. struct rcu_head rcu;
  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 netlink_table {
  49. struct rhashtable hash;
  50. struct hlist_head mc_list;
  51. struct listeners __rcu *listeners;
  52. unsigned int flags;
  53. unsigned int groups;
  54. struct mutex *cb_mutex;
  55. struct module *module;
  56. int (*bind)(struct net *net, int group);
  57. void (*unbind)(struct net *net, int group);
  58. bool (*compare)(struct net *net, struct sock *sock);
  59. int registered;
  60. };
  61. extern struct netlink_table *nl_table;
  62. extern rwlock_t nl_table_lock;
  63. #endif