Commit | Line | Data |
---|---|---|
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 |
10 | struct sk_buff; |
11 | struct nlmsghdr; | |
5d2e5f27 | 12 | struct sock; |
e6fe2371 | 13 | |
d366477a PE |
14 | struct 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 |
21 | int sock_diag_register(const struct sock_diag_handler *h); |
22 | void sock_diag_unregister(const struct sock_diag_handler *h); | |
d366477a PE |
23 | |
24 | void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh)); | |
25 | void sock_diag_unregister_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh)); | |
26 | ||
33cf7c90 ED |
27 | int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie); |
28 | void sock_diag_save_cookie(struct sock *sk, __u32 *cookie); | |
f65c1b53 | 29 | |
5d2e5f27 | 30 | int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attr); |
a53b72c8 | 31 | int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk, |
e8d9612c | 32 | struct sk_buff *skb, int attrtype); |
5d2e5f27 | 33 | |
eb4cb008 CG |
34 | static inline |
35 | enum sknetlink_groups sock_diag_destroy_group(const struct sock *sk) | |
36 | { | |
37 | switch (sk->sk_family) { | |
38 | case AF_INET: | |
9a0fee2b WB |
39 | if (sk->sk_type == SOCK_RAW) |
40 | return SKNLGRP_NONE; | |
41 | ||
eb4cb008 CG |
42 | switch (sk->sk_protocol) { |
43 | case IPPROTO_TCP: | |
44 | return SKNLGRP_INET_TCP_DESTROY; | |
45 | case IPPROTO_UDP: | |
46 | return SKNLGRP_INET_UDP_DESTROY; | |
47 | default: | |
48 | return SKNLGRP_NONE; | |
49 | } | |
50 | case AF_INET6: | |
9a0fee2b WB |
51 | if (sk->sk_type == SOCK_RAW) |
52 | return SKNLGRP_NONE; | |
53 | ||
eb4cb008 CG |
54 | switch (sk->sk_protocol) { |
55 | case IPPROTO_TCP: | |
56 | return SKNLGRP_INET6_TCP_DESTROY; | |
57 | case IPPROTO_UDP: | |
58 | return SKNLGRP_INET6_UDP_DESTROY; | |
59 | default: | |
60 | return SKNLGRP_NONE; | |
61 | } | |
62 | default: | |
63 | return SKNLGRP_NONE; | |
64 | } | |
65 | } | |
66 | ||
67 | static inline | |
68 | bool sock_diag_has_destroy_listeners(const struct sock *sk) | |
69 | { | |
70 | const struct net *n = sock_net(sk); | |
71 | const enum sknetlink_groups group = sock_diag_destroy_group(sk); | |
72 | ||
73 | return group != SKNLGRP_NONE && n->diag_nlsk && | |
74 | netlink_has_listeners(n->diag_nlsk, group); | |
75 | } | |
76 | void sock_diag_broadcast_destroy(struct sock *sk); | |
77 | ||
64be0aed | 78 | int sock_diag_destroy(struct sock *sk, int err); |
d366477a | 79 | #endif |