Merge tag 'perf-tools-fixes-for-v6.9-2024-04-19' of git://git.kernel.org/pub/scm...
[linux-2.6-block.git] / include / linux / sock_diag.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
d366477a
PE
2#ifndef __SOCK_DIAG_H__
3#define __SOCK_DIAG_H__
e7c466e5 4
eb4cb008 5#include <linux/netlink.h>
e8d9612c 6#include <linux/user_namespace.h>
eb4cb008
CG
7#include <net/net_namespace.h>
8#include <net/sock.h>
607ca46e 9#include <uapi/linux/sock_diag.h>
e7c466e5 10
e6fe2371
PE
11struct sk_buff;
12struct nlmsghdr;
5d2e5f27 13struct sock;
e6fe2371 14
d366477a 15struct sock_diag_handler {
114b4bb1 16 struct module *owner;
d366477a
PE
17 __u8 family;
18 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
eb4cb008 19 int (*get_info)(struct sk_buff *skb, struct sock *sk);
64be0aed 20 int (*destroy)(struct sk_buff *skb, struct nlmsghdr *nlh);
d366477a
PE
21};
22
8dcf01fc
SW
23int sock_diag_register(const struct sock_diag_handler *h);
24void sock_diag_unregister(const struct sock_diag_handler *h);
d366477a 25
86e8921d
ED
26struct sock_diag_inet_compat {
27 struct module *owner;
28 int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh);
29};
30
31void sock_diag_register_inet_compat(const struct sock_diag_inet_compat *ptr);
32void sock_diag_unregister_inet_compat(const struct sock_diag_inet_compat *ptr);
d366477a 33
92acdc58
DB
34u64 __sock_gen_cookie(struct sock *sk);
35
36static inline u64 sock_gen_cookie(struct sock *sk)
37{
38 u64 cookie;
39
40 preempt_disable();
41 cookie = __sock_gen_cookie(sk);
42 preempt_enable();
43
44 return cookie;
45}
46
33cf7c90
ED
47int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie);
48void sock_diag_save_cookie(struct sock *sk, __u32 *cookie);
f65c1b53 49
5d2e5f27 50int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attr);
a53b72c8 51int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
e8d9612c 52 struct sk_buff *skb, int attrtype);
5d2e5f27 53
eb4cb008
CG
54static inline
55enum sknetlink_groups sock_diag_destroy_group(const struct sock *sk)
56{
57 switch (sk->sk_family) {
58 case AF_INET:
9a0fee2b
WB
59 if (sk->sk_type == SOCK_RAW)
60 return SKNLGRP_NONE;
61
eb4cb008
CG
62 switch (sk->sk_protocol) {
63 case IPPROTO_TCP:
64 return SKNLGRP_INET_TCP_DESTROY;
65 case IPPROTO_UDP:
66 return SKNLGRP_INET_UDP_DESTROY;
67 default:
68 return SKNLGRP_NONE;
69 }
70 case AF_INET6:
9a0fee2b
WB
71 if (sk->sk_type == SOCK_RAW)
72 return SKNLGRP_NONE;
73
eb4cb008
CG
74 switch (sk->sk_protocol) {
75 case IPPROTO_TCP:
76 return SKNLGRP_INET6_TCP_DESTROY;
77 case IPPROTO_UDP:
78 return SKNLGRP_INET6_UDP_DESTROY;
79 default:
80 return SKNLGRP_NONE;
81 }
82 default:
83 return SKNLGRP_NONE;
84 }
85}
86
87static inline
88bool sock_diag_has_destroy_listeners(const struct sock *sk)
89{
90 const struct net *n = sock_net(sk);
91 const enum sknetlink_groups group = sock_diag_destroy_group(sk);
92
93 return group != SKNLGRP_NONE && n->diag_nlsk &&
94 netlink_has_listeners(n->diag_nlsk, group);
95}
96void sock_diag_broadcast_destroy(struct sock *sk);
97
64be0aed 98int sock_diag_destroy(struct sock *sk, int err);
d366477a 99#endif