1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __SOCK_DIAG_H__
3 #define __SOCK_DIAG_H__
5 #include <linux/netlink.h>
6 #include <linux/user_namespace.h>
7 #include <net/net_namespace.h>
9 #include <uapi/linux/sock_diag.h>
15 struct sock_diag_handler
{
17 int (*dump
)(struct sk_buff
*skb
, struct nlmsghdr
*nlh
);
18 int (*get_info
)(struct sk_buff
*skb
, struct sock
*sk
);
19 int (*destroy
)(struct sk_buff
*skb
, struct nlmsghdr
*nlh
);
22 int sock_diag_register(const struct sock_diag_handler
*h
);
23 void sock_diag_unregister(const struct sock_diag_handler
*h
);
25 void sock_diag_register_inet_compat(int (*fn
)(struct sk_buff
*skb
, struct nlmsghdr
*nlh
));
26 void sock_diag_unregister_inet_compat(int (*fn
)(struct sk_buff
*skb
, struct nlmsghdr
*nlh
));
28 u64
sock_gen_cookie(struct sock
*sk
);
29 int sock_diag_check_cookie(struct sock
*sk
, const __u32
*cookie
);
30 void sock_diag_save_cookie(struct sock
*sk
, __u32
*cookie
);
32 int sock_diag_put_meminfo(struct sock
*sk
, struct sk_buff
*skb
, int attr
);
33 int sock_diag_put_filterinfo(bool may_report_filterinfo
, struct sock
*sk
,
34 struct sk_buff
*skb
, int attrtype
);
37 enum sknetlink_groups
sock_diag_destroy_group(const struct sock
*sk
)
39 switch (sk
->sk_family
) {
41 if (sk
->sk_type
== SOCK_RAW
)
44 switch (sk
->sk_protocol
) {
46 return SKNLGRP_INET_TCP_DESTROY
;
48 return SKNLGRP_INET_UDP_DESTROY
;
53 if (sk
->sk_type
== SOCK_RAW
)
56 switch (sk
->sk_protocol
) {
58 return SKNLGRP_INET6_TCP_DESTROY
;
60 return SKNLGRP_INET6_UDP_DESTROY
;
70 bool sock_diag_has_destroy_listeners(const struct sock
*sk
)
72 const struct net
*n
= sock_net(sk
);
73 const enum sknetlink_groups group
= sock_diag_destroy_group(sk
);
75 return group
!= SKNLGRP_NONE
&& n
->diag_nlsk
&&
76 netlink_has_listeners(n
->diag_nlsk
, group
);
78 void sock_diag_broadcast_destroy(struct sock
*sk
);
80 int sock_diag_destroy(struct sock
*sk
, int err
);