]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/sock_diag.h
UBUNTU: SAUCE: LSM stacking: procfs: add smack subdir to attrs
[mirror_ubuntu-artful-kernel.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
91b8270f 27u64 sock_gen_cookie(struct sock *sk);
33cf7c90
ED
28int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie);
29void sock_diag_save_cookie(struct sock *sk, __u32 *cookie);
f65c1b53 30
5d2e5f27 31int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attr);
a53b72c8 32int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
e8d9612c 33 struct sk_buff *skb, int attrtype);
5d2e5f27 34
eb4cb008
CG
35static inline
36enum sknetlink_groups sock_diag_destroy_group(const struct sock *sk)
37{
38 switch (sk->sk_family) {
39 case AF_INET:
9a0fee2b
WB
40 if (sk->sk_type == SOCK_RAW)
41 return SKNLGRP_NONE;
42
eb4cb008
CG
43 switch (sk->sk_protocol) {
44 case IPPROTO_TCP:
45 return SKNLGRP_INET_TCP_DESTROY;
46 case IPPROTO_UDP:
47 return SKNLGRP_INET_UDP_DESTROY;
48 default:
49 return SKNLGRP_NONE;
50 }
51 case AF_INET6:
9a0fee2b
WB
52 if (sk->sk_type == SOCK_RAW)
53 return SKNLGRP_NONE;
54
eb4cb008
CG
55 switch (sk->sk_protocol) {
56 case IPPROTO_TCP:
57 return SKNLGRP_INET6_TCP_DESTROY;
58 case IPPROTO_UDP:
59 return SKNLGRP_INET6_UDP_DESTROY;
60 default:
61 return SKNLGRP_NONE;
62 }
63 default:
64 return SKNLGRP_NONE;
65 }
66}
67
68static inline
69bool sock_diag_has_destroy_listeners(const struct sock *sk)
70{
71 const struct net *n = sock_net(sk);
72 const enum sknetlink_groups group = sock_diag_destroy_group(sk);
73
74 return group != SKNLGRP_NONE && n->diag_nlsk &&
75 netlink_has_listeners(n->diag_nlsk, group);
76}
77void sock_diag_broadcast_destroy(struct sock *sk);
78
64be0aed 79int sock_diag_destroy(struct sock *sk, int err);
d366477a 80#endif