af_netlink.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_sock {
  10. /* struct sock has to be the first member of netlink_sock */
  11. struct sock sk;
  12. u32 portid;
  13. u32 dst_portid;
  14. u32 dst_group;
  15. u32 flags;
  16. u32 subscriptions;
  17. u32 ngroups;
  18. unsigned long *groups;
  19. unsigned long state;
  20. size_t max_recvmsg_len;
  21. wait_queue_head_t wait;
  22. bool bound;
  23. bool cb_running;
  24. struct netlink_callback cb;
  25. struct mutex *cb_mutex;
  26. struct mutex cb_def_mutex;
  27. void (*netlink_rcv)(struct sk_buff *skb);
  28. int (*netlink_bind)(struct net *net, int group);
  29. void (*netlink_unbind)(struct net *net, int group);
  30. struct module *module;
  31. struct rhash_head node;
  32. struct rcu_head rcu;
  33. struct work_struct work;
  34. };
  35. static inline struct netlink_sock *nlk_sk(struct sock *sk)
  36. {
  37. return container_of(sk, struct netlink_sock, sk);
  38. }
  39. struct netlink_table {
  40. struct rhashtable hash;
  41. struct hlist_head mc_list;
  42. struct listeners __rcu *listeners;
  43. unsigned int flags;
  44. unsigned int groups;
  45. struct mutex *cb_mutex;
  46. struct module *module;
  47. int (*bind)(struct net *net, int group);
  48. void (*unbind)(struct net *net, int group);
  49. bool (*compare)(struct net *net, struct sock *sock);
  50. int registered;
  51. };
  52. extern struct netlink_table *nl_table;
  53. extern rwlock_t nl_table_lock;
  54. #endif