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);
20 int sock_diag_register(const struct sock_diag_handler *h);
21 void sock_diag_unregister(const struct sock_diag_handler *h);
23 void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
24 void sock_diag_unregister_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
26 int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie);
27 void sock_diag_save_cookie(struct sock *sk, __u32 *cookie);
29 int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attr);
30 int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
31 struct sk_buff *skb, int attrtype);
34 enum sknetlink_groups sock_diag_destroy_group(const struct sock *sk)
36 switch (sk->sk_family) {
38 if (sk->sk_type == SOCK_RAW)
41 switch (sk->sk_protocol) {
43 return SKNLGRP_INET_TCP_DESTROY;
45 return SKNLGRP_INET_UDP_DESTROY;
50 if (sk->sk_type == SOCK_RAW)
53 switch (sk->sk_protocol) {
55 return SKNLGRP_INET6_TCP_DESTROY;
57 return SKNLGRP_INET6_UDP_DESTROY;
67 bool sock_diag_has_destroy_listeners(const struct sock *sk)
69 const struct net *n = sock_net(sk);
70 const enum sknetlink_groups group = sock_diag_destroy_group(sk);
72 return group != SKNLGRP_NONE && n->diag_nlsk &&
73 netlink_has_listeners(n->diag_nlsk, group);
75 void sock_diag_broadcast_destroy(struct sock *sk);