kconfig: fix memory leak when EOF is encountered in quotation
[linux/fpc-iii.git] / net / tipc / diag.c
blob73137f4aeb68f95677e34a3b2d5e823565024483
1 /*
2 * net/tipc/diag.c: TIPC socket diag
4 * Copyright (c) 2018, Ericsson AB
5 * All rights reserved.
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.
36 #include "core.h"
37 #include "socket.h"
38 #include <linux/sock_diag.h>
39 #include <linux/tipc_sockets_diag.h>
41 static u64 __tipc_diag_gen_cookie(struct sock *sk)
43 u32 res[2];
45 sock_diag_save_cookie(sk, res);
46 return *((u64 *)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);
54 struct nlmsghdr *nlh;
55 int err;
57 nlh = nlmsg_put_answer(skb, cb, SOCK_DIAG_BY_FAMILY, 0,
58 NLM_F_MULTI);
59 if (!nlh)
60 return -EMSGSIZE;
62 err = tipc_sk_fill_sock_diag(skb, cb, tsk, req->tidiag_states,
63 __tipc_diag_gen_cookie);
64 if (err)
65 return err;
67 nlmsg_end(skb, nlh);
68 return 0;
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,
77 struct nlmsghdr *h)
79 int hdrlen = sizeof(struct tipc_sock_diag_req);
80 struct net *net = sock_net(skb->sk);
82 if (nlmsg_len(h) < hdrlen)
83 return -EINVAL;
85 if (h->nlmsg_flags & NLM_F_DUMP) {
86 struct netlink_dump_control c = {
87 .start = tipc_dump_start,
88 .dump = tipc_diag_dump,
89 .done = tipc_dump_done,
91 netlink_dump_start(net->diag_nlsk, skb, h, &c);
92 return 0;
94 return -EOPNOTSUPP;
97 static const struct sock_diag_handler tipc_sock_diag_handler = {
98 .family = AF_TIPC,
99 .dump = tipc_sock_diag_handler_dump,
102 static int __init tipc_diag_init(void)
104 return sock_diag_register(&tipc_sock_diag_handler);
107 static void __exit tipc_diag_exit(void)
109 sock_diag_unregister(&tipc_sock_diag_handler);
112 module_init(tipc_diag_init);
113 module_exit(tipc_diag_exit);
115 MODULE_LICENSE("Dual BSD/GPL");
116 MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, AF_TIPC);