Merge tag 'nfsd-4.3' of git://linux-nfs.org/~bfields/linux
[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);
d366477a
PE
18};
19
8dcf01fc
SW
20int sock_diag_register(const struct sock_diag_handler *h);
21void sock_diag_unregister(const struct sock_diag_handler *h);
d366477a
PE
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
33cf7c90
ED
26int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie);
27void sock_diag_save_cookie(struct sock *sk, __u32 *cookie);
f65c1b53 28
5d2e5f27 29int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attr);
a53b72c8 30int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
e8d9612c 31 struct sk_buff *skb, int attrtype);
5d2e5f27 32
eb4cb008
CG
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
d366477a 71#endif