inet_diag.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _INET_DIAG_H_
  3. #define _INET_DIAG_H_ 1
  4. #include <net/netlink.h>
  5. #include <uapi/linux/inet_diag.h>
  6. struct inet_hashinfo;
  7. struct inet_diag_handler {
  8. void (*dump)(struct sk_buff *skb,
  9. struct netlink_callback *cb,
  10. const struct inet_diag_req_v2 *r);
  11. int (*dump_one)(struct netlink_callback *cb,
  12. const struct inet_diag_req_v2 *req);
  13. void (*idiag_get_info)(struct sock *sk,
  14. struct inet_diag_msg *r,
  15. void *info);
  16. int (*idiag_get_aux)(struct sock *sk,
  17. bool net_admin,
  18. struct sk_buff *skb);
  19. size_t (*idiag_get_aux_size)(struct sock *sk,
  20. bool net_admin);
  21. int (*destroy)(struct sk_buff *in_skb,
  22. const struct inet_diag_req_v2 *req);
  23. __u16 idiag_type;
  24. __u16 idiag_info_size;
  25. };
  26. struct bpf_sk_storage_diag;
  27. struct inet_diag_dump_data {
  28. struct nlattr *req_nlas[__INET_DIAG_REQ_MAX];
  29. #define inet_diag_nla_bc req_nlas[INET_DIAG_REQ_BYTECODE]
  30. #define inet_diag_nla_bpf_stgs req_nlas[INET_DIAG_REQ_SK_BPF_STORAGES]
  31. struct bpf_sk_storage_diag *bpf_stg_diag;
  32. };
  33. struct inet_connection_sock;
  34. int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
  35. struct sk_buff *skb, struct netlink_callback *cb,
  36. const struct inet_diag_req_v2 *req,
  37. u16 nlmsg_flags, bool net_admin);
  38. void inet_diag_dump_icsk(struct inet_hashinfo *h, struct sk_buff *skb,
  39. struct netlink_callback *cb,
  40. const struct inet_diag_req_v2 *r);
  41. int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo,
  42. struct netlink_callback *cb,
  43. const struct inet_diag_req_v2 *req);
  44. struct sock *inet_diag_find_one_icsk(struct net *net,
  45. struct inet_hashinfo *hashinfo,
  46. const struct inet_diag_req_v2 *req);
  47. int inet_diag_bc_sk(const struct nlattr *_bc, struct sock *sk);
  48. void inet_diag_msg_common_fill(struct inet_diag_msg *r, struct sock *sk);
  49. static inline size_t inet_diag_msg_attrs_size(void)
  50. {
  51. return nla_total_size(1) /* INET_DIAG_SHUTDOWN */
  52. + nla_total_size(1) /* INET_DIAG_TOS */
  53. #if IS_ENABLED(CONFIG_IPV6)
  54. + nla_total_size(1) /* INET_DIAG_TCLASS */
  55. + nla_total_size(1) /* INET_DIAG_SKV6ONLY */
  56. #endif
  57. + nla_total_size(4) /* INET_DIAG_MARK */
  58. + nla_total_size(4) /* INET_DIAG_CLASS_ID */
  59. #ifdef CONFIG_SOCK_CGROUP_DATA
  60. + nla_total_size_64bit(sizeof(u64)) /* INET_DIAG_CGROUP_ID */
  61. #endif
  62. + nla_total_size(sizeof(struct inet_diag_sockopt))
  63. /* INET_DIAG_SOCKOPT */
  64. ;
  65. }
  66. int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
  67. struct inet_diag_msg *r, int ext,
  68. struct user_namespace *user_ns, bool net_admin);
  69. extern int inet_diag_register(const struct inet_diag_handler *handler);
  70. extern void inet_diag_unregister(const struct inet_diag_handler *handler);
  71. #endif /* _INET_DIAG_H_ */