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