1 #ifndef __SOCK_DIAG_H__
2 #define __SOCK_DIAG_H__
4 #include <linux/netlink.h>
5 #include <linux/user_namespace.h>
6 #include <net/net_namespace.h>
8 #include <uapi/linux/sock_diag.h>
14 struct sock_diag_handler {
16 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
17 int (*get_info)(struct sk_buff *skb, struct sock *sk);
18 int (*destroy)(struct sk_buff *skb, struct nlmsghdr *nlh);
21 int sock_diag_register(const struct sock_diag_handler *h);
22 void sock_diag_unregister(const struct sock_diag_handler *h);
24 void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
25 void sock_diag_unregister_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
27 int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie);
28 void sock_diag_save_cookie(struct sock *sk, __u32 *cookie);
30 int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attr);
31 int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
32 struct sk_buff *skb, int attrtype);
35 enum sknetlink_groups sock_diag_destroy_group(const struct sock *sk)
37 switch (sk->sk_family) {
39 if (sk->sk_type == SOCK_RAW)
42 switch (sk->sk_protocol) {
44 return SKNLGRP_INET_TCP_DESTROY;
46 return SKNLGRP_INET_UDP_DESTROY;
51 if (sk->sk_type == SOCK_RAW)
54 switch (sk->sk_protocol) {
56 return SKNLGRP_INET6_TCP_DESTROY;
58 return SKNLGRP_INET6_UDP_DESTROY;
68 bool sock_diag_has_destroy_listeners(const struct sock *sk)
70 const struct net *n = sock_net(sk);
71 const enum sknetlink_groups group = sock_diag_destroy_group(sk);
73 return group != SKNLGRP_NONE && n->diag_nlsk &&
74 netlink_has_listeners(n->diag_nlsk, group);
76 void sock_diag_broadcast_destroy(struct sock *sk);
78 int sock_diag_destroy(struct sock *sk, int err);