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 	void		(*dump)(struct sk_buff *skb,
12 				struct netlink_callback *cb,
13 				const struct inet_diag_req_v2 *r,
14 				struct nlattr *bc);
15 
16 	int		(*dump_one)(struct sk_buff *in_skb,
17 				    const struct nlmsghdr *nlh,
18 				    const struct inet_diag_req_v2 *req);
19 
20 	void		(*idiag_get_info)(struct sock *sk,
21 					  struct inet_diag_msg *r,
22 					  void *info);
23 
24 	int		(*idiag_get_aux)(struct sock *sk,
25 					 bool net_admin,
26 					 struct sk_buff *skb);
27 
28 	size_t		(*idiag_get_aux_size)(struct sock *sk,
29 					      bool net_admin);
30 
31 	int		(*destroy)(struct sk_buff *in_skb,
32 				   const struct inet_diag_req_v2 *req);
33 
34 	__u16		idiag_type;
35 	__u16		idiag_info_size;
36 };
37 
38 struct inet_connection_sock;
39 int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
40 		      struct sk_buff *skb, const struct inet_diag_req_v2 *req,
41 		      struct user_namespace *user_ns,
42 		      u32 pid, u32 seq, u16 nlmsg_flags,
43 		      const struct nlmsghdr *unlh, bool net_admin);
44 void inet_diag_dump_icsk(struct inet_hashinfo *h, struct sk_buff *skb,
45 			 struct netlink_callback *cb,
46 			 const struct inet_diag_req_v2 *r,
47 			 struct nlattr *bc);
48 int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo,
49 			    struct sk_buff *in_skb, const struct nlmsghdr *nlh,
50 			    const struct inet_diag_req_v2 *req);
51 
52 struct sock *inet_diag_find_one_icsk(struct net *net,
53 				     struct inet_hashinfo *hashinfo,
54 				     const struct inet_diag_req_v2 *req);
55 
56 int inet_diag_bc_sk(const struct nlattr *_bc, struct sock *sk);
57 
58 void inet_diag_msg_common_fill(struct inet_diag_msg *r, struct sock *sk);
59 
inet_diag_msg_attrs_size(void)60 static inline size_t inet_diag_msg_attrs_size(void)
61 {
62 	return	  nla_total_size(1)  /* INET_DIAG_SHUTDOWN */
63 		+ nla_total_size(1)  /* INET_DIAG_TOS */
64 #if IS_ENABLED(CONFIG_IPV6)
65 		+ nla_total_size(1)  /* INET_DIAG_TCLASS */
66 		+ nla_total_size(1)  /* INET_DIAG_SKV6ONLY */
67 #endif
68 		+ nla_total_size(4)  /* INET_DIAG_MARK */
69 		+ nla_total_size(4); /* INET_DIAG_CLASS_ID */
70 }
71 int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
72 			     struct inet_diag_msg *r, int ext,
73 			     struct user_namespace *user_ns, bool net_admin);
74 
75 extern int  inet_diag_register(const struct inet_diag_handler *handler);
76 extern void inet_diag_unregister(const struct inet_diag_handler *handler);
77 #endif /* _INET_DIAG_H_ */
78