af_netlink.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _AF_NETLINK_H
  3. #define _AF_NETLINK_H
  4. #include <linux/rhashtable.h>
  5. #include <linux/atomic.h>
  6. #include <linux/workqueue.h>
  7. #include <net/sock.h>
  8. /* flags */
  9. #define NETLINK_F_KERNEL_SOCKET 0x1
  10. #define NETLINK_F_RECV_PKTINFO 0x2
  11. #define NETLINK_F_BROADCAST_SEND_ERROR 0x4
  12. #define NETLINK_F_RECV_NO_ENOBUFS 0x8
  13. #define NETLINK_F_LISTEN_ALL_NSID 0x10
  14. #define NETLINK_F_CAP_ACK 0x20
  15. #define NETLINK_F_EXT_ACK 0x40
  16. #define NETLINK_F_STRICT_CHK 0x80
  17. #define NLGRPSZ(x) (ALIGN(x, sizeof(unsigned long) * 8) / 8)
  18. #define NLGRPLONGS(x) (NLGRPSZ(x)/sizeof(unsigned long))
  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. int dump_done_errno;
  35. struct netlink_callback cb;
  36. struct mutex *cb_mutex;
  37. struct mutex cb_def_mutex;
  38. void (*netlink_rcv)(struct sk_buff *skb);
  39. int (*netlink_bind)(struct net *net, int group);
  40. void (*netlink_unbind)(struct net *net, int group);
  41. struct module *module;
  42. struct rhash_head node;
  43. struct rcu_head rcu;
  44. struct work_struct work;
  45. };
  46. static inline struct netlink_sock *nlk_sk(struct sock *sk)
  47. {
  48. return container_of(sk, struct netlink_sock, sk);
  49. }
  50. struct netlink_table {
  51. struct rhashtable hash;
  52. struct hlist_head mc_list;
  53. struct listeners __rcu *listeners;
  54. unsigned int flags;
  55. unsigned int groups;
  56. struct mutex *cb_mutex;
  57. struct module *module;
  58. int (*bind)(struct net *net, int group);
  59. void (*unbind)(struct net *net, int group);
  60. bool (*compare)(struct net *net, struct sock *sock);
  61. int registered;
  62. };
  63. extern struct netlink_table *nl_table;
  64. extern rwlock_t nl_table_lock;
  65. #endif