1#ifndef __SOCK_DIAG_H__
2#define __SOCK_DIAG_H__
3
4#include <linux/netlink.h>
5#include <linux/user_namespace.h>
6#include <net/net_namespace.h>
7#include <net/sock.h>
8#include <uapi/linux/sock_diag.h>
9
10struct sk_buff;
11struct nlmsghdr;
12struct sock;
13
14struct sock_diag_handler {
15	__u8 family;
16	int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
17	int (*get_info)(struct sk_buff *skb, struct sock *sk);
18};
19
20int sock_diag_register(const struct sock_diag_handler *h);
21void sock_diag_unregister(const struct sock_diag_handler *h);
22
23void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
24void sock_diag_unregister_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
25
26int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie);
27void sock_diag_save_cookie(struct sock *sk, __u32 *cookie);
28
29int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attr);
30int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
31			     struct sk_buff *skb, int attrtype);
32
33static inline
34enum sknetlink_groups sock_diag_destroy_group(const struct sock *sk)
35{
36	switch (sk->sk_family) {
37	case AF_INET:
38		switch (sk->sk_protocol) {
39		case IPPROTO_TCP:
40			return SKNLGRP_INET_TCP_DESTROY;
41		case IPPROTO_UDP:
42			return SKNLGRP_INET_UDP_DESTROY;
43		default:
44			return SKNLGRP_NONE;
45		}
46	case AF_INET6:
47		switch (sk->sk_protocol) {
48		case IPPROTO_TCP:
49			return SKNLGRP_INET6_TCP_DESTROY;
50		case IPPROTO_UDP:
51			return SKNLGRP_INET6_UDP_DESTROY;
52		default:
53			return SKNLGRP_NONE;
54		}
55	default:
56		return SKNLGRP_NONE;
57	}
58}
59
60static inline
61bool sock_diag_has_destroy_listeners(const struct sock *sk)
62{
63	const struct net *n = sock_net(sk);
64	const enum sknetlink_groups group = sock_diag_destroy_group(sk);
65
66	return group != SKNLGRP_NONE && n->diag_nlsk &&
67		netlink_has_listeners(n->diag_nlsk, group);
68}
69void sock_diag_broadcast_destroy(struct sock *sk);
70
71#endif
72