Commit | Line | Data |
---|---|---|
bfb3e5dd RA |
1 | /* |
2 | * Copyright (c) 2014, Ericsson AB | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions are met: | |
7 | * | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. Neither the names of the copyright holders nor the names of its | |
14 | * contributors may be used to endorse or promote products derived from | |
15 | * this software without specific prior written permission. | |
16 | * | |
17 | * Alternatively, this software may be distributed under the terms of the | |
18 | * GNU General Public License ("GPL") version 2 as published by the Free | |
19 | * Software Foundation. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
25 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
31 | * POSSIBILITY OF SUCH DAMAGE. | |
32 | */ | |
33 | ||
34 | #include "core.h" | |
35 | #include "config.h" | |
36 | #include <net/genetlink.h> | |
37 | #include <linux/tipc_config.h> | |
38 | ||
39 | static int handle_cmd(struct sk_buff *skb, struct genl_info *info) | |
40 | { | |
41 | struct net *net = genl_info_net(info); | |
42 | struct sk_buff *rep_buf; | |
43 | struct nlmsghdr *rep_nlh; | |
44 | struct nlmsghdr *req_nlh = info->nlhdr; | |
45 | struct tipc_genlmsghdr *req_userhdr = info->userhdr; | |
46 | int hdr_space = nlmsg_total_size(GENL_HDRLEN + TIPC_GENL_HDRLEN); | |
47 | u16 cmd; | |
48 | ||
49 | if ((req_userhdr->cmd & 0xC000) && | |
50 | (!netlink_net_capable(skb, CAP_NET_ADMIN))) | |
51 | cmd = TIPC_CMD_NOT_NET_ADMIN; | |
52 | else | |
53 | cmd = req_userhdr->cmd; | |
54 | ||
55 | rep_buf = tipc_cfg_do_cmd(net, req_userhdr->dest, cmd, | |
56 | nlmsg_data(req_nlh) + GENL_HDRLEN + | |
57 | TIPC_GENL_HDRLEN, | |
58 | nlmsg_attrlen(req_nlh, GENL_HDRLEN + | |
59 | TIPC_GENL_HDRLEN), hdr_space); | |
60 | ||
61 | if (rep_buf) { | |
62 | skb_push(rep_buf, hdr_space); | |
63 | rep_nlh = nlmsg_hdr(rep_buf); | |
64 | memcpy(rep_nlh, req_nlh, hdr_space); | |
65 | rep_nlh->nlmsg_len = rep_buf->len; | |
66 | genlmsg_unicast(net, rep_buf, NETLINK_CB(skb).portid); | |
67 | } | |
68 | ||
69 | return 0; | |
70 | } | |
71 | ||
72 | static struct genl_family tipc_genl_compat_family = { | |
73 | .id = GENL_ID_GENERATE, | |
74 | .name = TIPC_GENL_NAME, | |
75 | .version = TIPC_GENL_VERSION, | |
76 | .hdrsize = TIPC_GENL_HDRLEN, | |
77 | .maxattr = 0, | |
78 | .netnsok = true, | |
79 | }; | |
80 | ||
81 | static struct genl_ops tipc_genl_compat_ops[] = { | |
82 | { | |
83 | .cmd = TIPC_GENL_CMD, | |
84 | .doit = handle_cmd, | |
85 | }, | |
86 | }; | |
87 | ||
88 | int tipc_netlink_compat_start(void) | |
89 | { | |
90 | int res; | |
91 | ||
92 | res = genl_register_family_with_ops(&tipc_genl_compat_family, | |
93 | tipc_genl_compat_ops); | |
94 | if (res) { | |
95 | pr_err("Failed to register legacy compat interface\n"); | |
96 | return res; | |
97 | } | |
98 | ||
99 | return 0; | |
100 | } | |
101 | ||
102 | void tipc_netlink_compat_stop(void) | |
103 | { | |
104 | genl_unregister_family(&tipc_genl_compat_family); | |
105 | } |