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
{
18 int (*dump
)(struct sk_buff
*skb
, struct nlmsghdr
*nlh
);
19 int (*get_info
)(struct sk_buff
*skb
, struct sock
*sk
);
20 int (*destroy
)(struct sk_buff
*skb
, struct nlmsghdr
*nlh
);
23 int sock_diag_register(const struct sock_diag_handler
*h
);
24 void sock_diag_unregister(const struct sock_diag_handler
*h
);
26 struct sock_diag_inet_compat
{
28 int (*fn
)(struct sk_buff
*skb
, struct nlmsghdr
*nlh
);
31 void sock_diag_register_inet_compat(const struct sock_diag_inet_compat
*ptr
);
32 void sock_diag_unregister_inet_compat(const struct sock_diag_inet_compat
*ptr
);
34 u64
__sock_gen_cookie(struct sock
*sk
);
36 static inline u64
sock_gen_cookie(struct sock
*sk
)
41 cookie
= __sock_gen_cookie(sk
);
47 int sock_diag_check_cookie(struct sock
*sk
, const __u32
*cookie
);
48 void sock_diag_save_cookie(struct sock
*sk
, __u32
*cookie
);
50 int sock_diag_put_meminfo(struct sock
*sk
, struct sk_buff
*skb
, int attr
);
51 int sock_diag_put_filterinfo(bool may_report_filterinfo
, struct sock
*sk
,
52 struct sk_buff
*skb
, int attrtype
);
55 enum sknetlink_groups
sock_diag_destroy_group(const struct sock
*sk
)
57 switch (sk
->sk_family
) {
59 if (sk
->sk_type
== SOCK_RAW
)
62 switch (sk
->sk_protocol
) {
64 return SKNLGRP_INET_TCP_DESTROY
;
66 return SKNLGRP_INET_UDP_DESTROY
;
71 if (sk
->sk_type
== SOCK_RAW
)
74 switch (sk
->sk_protocol
) {
76 return SKNLGRP_INET6_TCP_DESTROY
;
78 return SKNLGRP_INET6_UDP_DESTROY
;
88 bool sock_diag_has_destroy_listeners(const struct sock
*sk
)
90 const struct net
*n
= sock_net(sk
);
91 const enum sknetlink_groups group
= sock_diag_destroy_group(sk
);
93 return group
!= SKNLGRP_NONE
&& n
->diag_nlsk
&&
94 netlink_has_listeners(n
->diag_nlsk
, group
);
96 void sock_diag_broadcast_destroy(struct sock
*sk
);
98 int sock_diag_destroy(struct sock
*sk
, int err
);