]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/sock_diag.h
net: rtnetlink: validate IFLA_MTU attribute in rtnl_create_link()
[mirror_ubuntu-bionic-kernel.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
PE
15struct sock_diag_handler {
16 __u8 family;
17 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
eb4cb008 18 int (*get_info)(struct sk_buff *skb, struct sock *sk);
64be0aed 19 int (*destroy)(struct sk_buff *skb, struct nlmsghdr *nlh);
d366477a
PE
20};
21
8dcf01fc
SW
22int sock_diag_register(const struct sock_diag_handler *h);
23void sock_diag_unregister(const struct sock_diag_handler *h);
d366477a
PE
24
25void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
26void sock_diag_unregister_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
27
91b8270f 28u64 sock_gen_cookie(struct sock *sk);
33cf7c90
ED
29int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie);
30void sock_diag_save_cookie(struct sock *sk, __u32 *cookie);
f65c1b53 31
5d2e5f27 32int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attr);
a53b72c8 33int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
e8d9612c 34 struct sk_buff *skb, int attrtype);
5d2e5f27 35
eb4cb008
CG
36static inline
37enum sknetlink_groups sock_diag_destroy_group(const struct sock *sk)
38{
39 switch (sk->sk_family) {
40 case AF_INET:
9a0fee2b
WB
41 if (sk->sk_type == SOCK_RAW)
42 return SKNLGRP_NONE;
43
eb4cb008
CG
44 switch (sk->sk_protocol) {
45 case IPPROTO_TCP:
46 return SKNLGRP_INET_TCP_DESTROY;
47 case IPPROTO_UDP:
48 return SKNLGRP_INET_UDP_DESTROY;
49 default:
50 return SKNLGRP_NONE;
51 }
52 case AF_INET6:
9a0fee2b
WB
53 if (sk->sk_type == SOCK_RAW)
54 return SKNLGRP_NONE;
55
eb4cb008
CG
56 switch (sk->sk_protocol) {
57 case IPPROTO_TCP:
58 return SKNLGRP_INET6_TCP_DESTROY;
59 case IPPROTO_UDP:
60 return SKNLGRP_INET6_UDP_DESTROY;
61 default:
62 return SKNLGRP_NONE;
63 }
64 default:
65 return SKNLGRP_NONE;
66 }
67}
68
69static inline
70bool sock_diag_has_destroy_listeners(const struct sock *sk)
71{
72 const struct net *n = sock_net(sk);
73 const enum sknetlink_groups group = sock_diag_destroy_group(sk);
74
75 return group != SKNLGRP_NONE && n->diag_nlsk &&
76 netlink_has_listeners(n->diag_nlsk, group);
77}
78void sock_diag_broadcast_destroy(struct sock *sk);
79
64be0aed 80int sock_diag_destroy(struct sock *sk, int err);
d366477a 81#endif