af_netlink.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <net/sock.h>
  7. /* flags */
  8. enum {
  9. NETLINK_F_KERNEL_SOCKET,
  10. NETLINK_F_RECV_PKTINFO,
  11. NETLINK_F_BROADCAST_SEND_ERROR,
  12. NETLINK_F_RECV_NO_ENOBUFS,
  13. NETLINK_F_LISTEN_ALL_NSID,
  14. NETLINK_F_CAP_ACK,
  15. NETLINK_F_EXT_ACK,
  16. NETLINK_F_STRICT_CHK,
  17. };
  18. #define NLGRPSZ(x) (ALIGN(x, sizeof(unsigned long) * 8) / 8)
  19. #define NLGRPLONGS(x) (NLGRPSZ(x)/sizeof(unsigned long))
  20. struct netlink_sock {
  21. /* struct sock has to be the first member of netlink_sock */
  22. struct sock sk;
  23. unsigned long flags;
  24. u32 portid;
  25. u32 dst_portid;
  26. u32 dst_group;
  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 nl_cb_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. void (*netlink_release)(struct sock *sk,
  42. unsigned long *groups);
  43. struct module *module;
  44. struct rhash_head node;
  45. struct rcu_head rcu;
  46. };
  47. static inline struct netlink_sock *nlk_sk(struct sock *sk)
  48. {
  49. return container_of(sk, struct netlink_sock, sk);
  50. }
  51. #define nlk_test_bit(nr, sk) test_bit(NETLINK_F_##nr, &nlk_sk(sk)->flags)
  52. struct netlink_table {
  53. struct rhashtable hash;
  54. struct hlist_head mc_list;
  55. struct listeners __rcu *listeners;
  56. unsigned int flags;
  57. unsigned int groups;
  58. struct mutex *cb_mutex;
  59. struct module *module;
  60. int (*bind)(struct net *net, int group);
  61. void (*unbind)(struct net *net, int group);
  62. void (*release)(struct sock *sk,
  63. unsigned long *groups);
  64. int registered;
  65. };
  66. extern struct netlink_table *nl_table;
  67. extern rwlock_t nl_table_lock;
  68. #endif