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 NLGRPSZ(x) (ALIGN(x, sizeof(unsigned long) * 8) / 8)
  17. #define NLGRPLONGS(x) (NLGRPSZ(x)/sizeof(unsigned long))
  18. struct netlink_sock {
  19. /* struct sock has to be the first member of netlink_sock */
  20. struct sock sk;
  21. u32 portid;
  22. u32 dst_portid;
  23. u32 dst_group;
  24. u32 flags;
  25. u32 subscriptions;
  26. u32 ngroups;
  27. unsigned long *groups;
  28. unsigned long state;
  29. size_t max_recvmsg_len;
  30. wait_queue_head_t wait;
  31. bool bound;
  32. bool cb_running;
  33. int dump_done_errno;
  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. struct work_struct work;
  44. };
  45. static inline struct netlink_sock *nlk_sk(struct sock *sk)
  46. {
  47. return container_of(sk, struct netlink_sock, sk);
  48. }
  49. struct netlink_table {
  50. struct rhashtable hash;
  51. struct hlist_head mc_list;
  52. struct listeners __rcu *listeners;
  53. unsigned int flags;
  54. unsigned int groups;
  55. struct mutex *cb_mutex;
  56. struct module *module;
  57. int (*bind)(struct net *net, int group);
  58. void (*unbind)(struct net *net, int group);
  59. bool (*compare)(struct net *net, struct sock *sock);
  60. int registered;
  61. };
  62. extern struct netlink_table *nl_table;
  63. extern rwlock_t nl_table_lock;
  64. #endif