blob: fddebc6174697a311be8aa06d1e30ed90135d41b [file] [log] [blame]
Pavel Emelyanovd3664772011-12-06 07:58:03 +00001#ifndef __SOCK_DIAG_H__
2#define __SOCK_DIAG_H__
Pavel Emelyanove7c466e2011-12-15 02:42:42 +00003
Craig Gallekeb4cb002015-06-15 11:26:18 -04004#include <linux/netlink.h>
Nicolas Dichtele8d96122013-04-25 06:53:54 +00005#include <linux/user_namespace.h>
Craig Gallekeb4cb002015-06-15 11:26:18 -04006#include <net/net_namespace.h>
7#include <net/sock.h>
David Howells607ca462012-10-13 10:46:48 +01008#include <uapi/linux/sock_diag.h>
Pavel Emelyanove7c466e2011-12-15 02:42:42 +00009
Pavel Emelyanove6fe2372011-12-30 00:52:21 +000010struct sk_buff;
11struct nlmsghdr;
Pavel Emelyanov5d2e5f22011-12-30 00:53:13 +000012struct sock;
Pavel Emelyanove6fe2372011-12-30 00:52:21 +000013
Pavel Emelyanovd3664772011-12-06 07:58:03 +000014struct sock_diag_handler {
15 __u8 family;
16 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
Craig Gallekeb4cb002015-06-15 11:26:18 -040017 int (*get_info)(struct sk_buff *skb, struct sock *sk);
Pavel Emelyanovd3664772011-12-06 07:58:03 +000018};
19
Shan Wei8dcf01f2012-04-24 18:21:07 +000020int sock_diag_register(const struct sock_diag_handler *h);
21void sock_diag_unregister(const struct sock_diag_handler *h);
Pavel Emelyanovd3664772011-12-06 07:58:03 +000022
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
Eric Dumazet33cf7c92015-03-11 18:53:14 -070026int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie);
27void sock_diag_save_cookie(struct sock *sk, __u32 *cookie);
Pavel Emelyanovf65c1b52011-12-15 02:43:44 +000028
Pavel Emelyanov5d2e5f22011-12-30 00:53:13 +000029int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attr);
Eric W. Biedermana53b72c2014-04-23 14:26:25 -070030int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
Nicolas Dichtele8d96122013-04-25 06:53:54 +000031 struct sk_buff *skb, int attrtype);
Pavel Emelyanov5d2e5f22011-12-30 00:53:13 +000032
Craig Gallekeb4cb002015-06-15 11:26:18 -040033static 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
Pavel Emelyanovd3664772011-12-06 07:58:03 +000071#endif