af_netlink.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. /* flags */
  8. #define NETLINK_F_KERNEL_SOCKET 0x1
  9. #define NETLINK_F_RECV_PKTINFO 0x2
  10. #define NETLINK_F_BROADCAST_SEND_ERROR 0x4
  11. #define NETLINK_F_RECV_NO_ENOBUFS 0x8
  12. #define NETLINK_F_LISTEN_ALL_NSID 0x10
  13. #define NETLINK_F_CAP_ACK 0x20
  14. #define NETLINK_F_EXT_ACK 0x40
  15. #define NLGRPSZ(x) (ALIGN(x, sizeof(unsigned long) * 8) / 8)
  16. #define NLGRPLONGS(x) (NLGRPSZ(x)/sizeof(unsigned long))
  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 bound;
  31. bool cb_running;
  32. struct netlink_callback cb;
  33. struct mutex *cb_mutex;
  34. struct mutex cb_def_mutex;
  35. void (*netlink_rcv)(struct sk_buff *skb);
  36. int (*netlink_bind)(struct net *net, int group);
  37. void (*netlink_unbind)(struct net *net, int group);
  38. struct module *module;
  39. struct rhash_head node;
  40. struct rcu_head rcu;
  41. struct work_struct work;
  42. };
  43. static inline struct netlink_sock *nlk_sk(struct sock *sk)
  44. {
  45. return container_of(sk, struct netlink_sock, sk);
  46. }
  47. struct netlink_table {
  48. struct rhashtable hash;
  49. struct hlist_head mc_list;
  50. struct listeners __rcu *listeners;
  51. unsigned int flags;
  52. unsigned int groups;
  53. struct mutex *cb_mutex;
  54. struct module *module;
  55. int (*bind)(struct net *net, int group);
  56. void (*unbind)(struct net *net, int group);
  57. bool (*compare)(struct net *net, struct sock *sock);
  58. int registered;
  59. };
  60. extern struct netlink_table *nl_table;
  61. extern rwlock_t nl_table_lock;
  62. #endif