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