Upgrade to 4.4.50-rt62
[kvmfornfv.git] / kernel / include / linux / sock_diag.h
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
10 struct sk_buff;
11 struct nlmsghdr;
12 struct sock;
13
14 struct 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
20 int sock_diag_register(const struct sock_diag_handler *h);
21 void sock_diag_unregister(const struct sock_diag_handler *h);
22
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));
25
26 int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie);
27 void sock_diag_save_cookie(struct sock *sk, __u32 *cookie);
28
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);
32
33 static inline
34 enum sknetlink_groups sock_diag_destroy_group(const struct sock *sk)
35 {
36         switch (sk->sk_family) {
37         case AF_INET:
38                 if (sk->sk_type == SOCK_RAW)
39                         return SKNLGRP_NONE;
40
41                 switch (sk->sk_protocol) {
42                 case IPPROTO_TCP:
43                         return SKNLGRP_INET_TCP_DESTROY;
44                 case IPPROTO_UDP:
45                         return SKNLGRP_INET_UDP_DESTROY;
46                 default:
47                         return SKNLGRP_NONE;
48                 }
49         case AF_INET6:
50                 if (sk->sk_type == SOCK_RAW)
51                         return SKNLGRP_NONE;
52
53                 switch (sk->sk_protocol) {
54                 case IPPROTO_TCP:
55                         return SKNLGRP_INET6_TCP_DESTROY;
56                 case IPPROTO_UDP:
57                         return SKNLGRP_INET6_UDP_DESTROY;
58                 default:
59                         return SKNLGRP_NONE;
60                 }
61         default:
62                 return SKNLGRP_NONE;
63         }
64 }
65
66 static inline
67 bool sock_diag_has_destroy_listeners(const struct sock *sk)
68 {
69         const struct net *n = sock_net(sk);
70         const enum sknetlink_groups group = sock_diag_destroy_group(sk);
71
72         return group != SKNLGRP_NONE && n->diag_nlsk &&
73                 netlink_has_listeners(n->diag_nlsk, group);
74 }
75 void sock_diag_broadcast_destroy(struct sock *sk);
76
77 #endif