2 * net/tipc/diag.c: TIPC socket diag
4 * Copyright (c) 2018, Ericsson AB
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the names of the copyright holders nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * Alternatively, this software may be distributed under the terms of the
20 * GNU General Public License ("GPL") version 2 as published by the Free
21 * Software Foundation.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "ASIS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
38 #include <linux/sock_diag.h>
39 #include <linux/tipc_sockets_diag.h>
41 static u64
__tipc_diag_gen_cookie(struct sock
*sk
)
45 sock_diag_save_cookie(sk
, res
);
49 static int __tipc_add_sock_diag(struct sk_buff
*skb
,
50 struct netlink_callback
*cb
,
51 struct tipc_sock
*tsk
)
53 struct tipc_sock_diag_req
*req
= nlmsg_data(cb
->nlh
);
57 nlh
= nlmsg_put_answer(skb
, cb
, SOCK_DIAG_BY_FAMILY
, 0,
62 err
= tipc_sk_fill_sock_diag(skb
, cb
, tsk
, req
->tidiag_states
,
63 __tipc_diag_gen_cookie
);
71 static int tipc_diag_dump(struct sk_buff
*skb
, struct netlink_callback
*cb
)
73 return tipc_nl_sk_walk(skb
, cb
, __tipc_add_sock_diag
);
76 static int tipc_sock_diag_handler_dump(struct sk_buff
*skb
,
79 int hdrlen
= sizeof(struct tipc_sock_diag_req
);
80 struct net
*net
= sock_net(skb
->sk
);
82 if (nlmsg_len(h
) < hdrlen
)
85 if (h
->nlmsg_flags
& NLM_F_DUMP
) {
86 struct netlink_dump_control c
= {
87 .dump
= tipc_diag_dump
,
89 netlink_dump_start(net
->diag_nlsk
, skb
, h
, &c
);
95 static const struct sock_diag_handler tipc_sock_diag_handler
= {
97 .dump
= tipc_sock_diag_handler_dump
,
100 static int __init
tipc_diag_init(void)
102 return sock_diag_register(&tipc_sock_diag_handler
);
105 static void __exit
tipc_diag_exit(void)
107 sock_diag_unregister(&tipc_sock_diag_handler
);
110 module_init(tipc_diag_init
);
111 module_exit(tipc_diag_exit
);
113 MODULE_LICENSE("Dual BSD/GPL");
114 MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK
, NETLINK_SOCK_DIAG
, AF_TIPC
);