Richard Alpe | bfb3e5d | 2015-02-09 09:50:03 +0100 | [diff] [blame] | 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" |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 35 | #include "bearer.h" |
Richard Alpe | f2b3b2d | 2015-02-09 09:50:06 +0100 | [diff] [blame] | 36 | #include "link.h" |
Richard Alpe | 44a8ae9 | 2015-02-09 09:50:10 +0100 | [diff] [blame] | 37 | #include "name_table.h" |
Richard Alpe | 487d2a3 | 2015-02-09 09:50:11 +0100 | [diff] [blame] | 38 | #include "socket.h" |
Richard Alpe | 4b28cb5 | 2015-02-09 09:50:13 +0100 | [diff] [blame] | 39 | #include "node.h" |
Richard Alpe | 964f950 | 2015-02-09 09:50:15 +0100 | [diff] [blame] | 40 | #include "net.h" |
Richard Alpe | bfb3e5d | 2015-02-09 09:50:03 +0100 | [diff] [blame] | 41 | #include <net/genetlink.h> |
| 42 | #include <linux/tipc_config.h> |
| 43 | |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 44 | /* The legacy API had an artificial message length limit called |
| 45 | * ULTRA_STRING_MAX_LEN. |
| 46 | */ |
| 47 | #define ULTRA_STRING_MAX_LEN 32768 |
| 48 | |
| 49 | #define TIPC_SKB_MAX TLV_SPACE(ULTRA_STRING_MAX_LEN) |
| 50 | |
| 51 | #define REPLY_TRUNCATED "<truncated>\n" |
| 52 | |
| 53 | struct tipc_nl_compat_msg { |
| 54 | u16 cmd; |
Richard Alpe | f2b3b2d | 2015-02-09 09:50:06 +0100 | [diff] [blame] | 55 | int rep_type; |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 56 | int rep_size; |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 57 | int req_type; |
Taras Kondratiuk | 4da5f00 | 2019-07-29 22:15:07 +0000 | [diff] [blame] | 58 | int req_size; |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 59 | struct net *net; |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 60 | struct sk_buff *rep; |
| 61 | struct tlv_desc *req; |
| 62 | struct sock *dst_sk; |
| 63 | }; |
| 64 | |
| 65 | struct tipc_nl_compat_cmd_dump { |
Richard Alpe | 44a8ae9 | 2015-02-09 09:50:10 +0100 | [diff] [blame] | 66 | int (*header)(struct tipc_nl_compat_msg *); |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 67 | int (*dumpit)(struct sk_buff *, struct netlink_callback *); |
| 68 | int (*format)(struct tipc_nl_compat_msg *msg, struct nlattr **attrs); |
| 69 | }; |
| 70 | |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 71 | struct tipc_nl_compat_cmd_doit { |
| 72 | int (*doit)(struct sk_buff *skb, struct genl_info *info); |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 73 | int (*transcode)(struct tipc_nl_compat_cmd_doit *cmd, |
| 74 | struct sk_buff *skb, struct tipc_nl_compat_msg *msg); |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 75 | }; |
| 76 | |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 77 | static int tipc_skb_tailroom(struct sk_buff *skb) |
| 78 | { |
| 79 | int tailroom; |
| 80 | int limit; |
| 81 | |
| 82 | tailroom = skb_tailroom(skb); |
| 83 | limit = TIPC_SKB_MAX - skb->len; |
| 84 | |
| 85 | if (tailroom < limit) |
| 86 | return tailroom; |
| 87 | |
| 88 | return limit; |
| 89 | } |
| 90 | |
Ying Xue | 8b66fee | 2019-01-14 17:22:25 +0800 | [diff] [blame] | 91 | static inline int TLV_GET_DATA_LEN(struct tlv_desc *tlv) |
| 92 | { |
| 93 | return TLV_GET_LEN(tlv) - TLV_SPACE(0); |
| 94 | } |
| 95 | |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 96 | static int tipc_add_tlv(struct sk_buff *skb, u16 type, void *data, u16 len) |
| 97 | { |
| 98 | struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(skb); |
| 99 | |
| 100 | if (tipc_skb_tailroom(skb) < TLV_SPACE(len)) |
| 101 | return -EMSGSIZE; |
| 102 | |
| 103 | skb_put(skb, TLV_SPACE(len)); |
| 104 | tlv->tlv_type = htons(type); |
| 105 | tlv->tlv_len = htons(TLV_LENGTH(len)); |
| 106 | if (len && data) |
| 107 | memcpy(TLV_DATA(tlv), data, len); |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
Richard Alpe | f2b3b2d | 2015-02-09 09:50:06 +0100 | [diff] [blame] | 112 | static void tipc_tlv_init(struct sk_buff *skb, u16 type) |
| 113 | { |
| 114 | struct tlv_desc *tlv = (struct tlv_desc *)skb->data; |
| 115 | |
| 116 | TLV_SET_LEN(tlv, 0); |
| 117 | TLV_SET_TYPE(tlv, type); |
| 118 | skb_put(skb, sizeof(struct tlv_desc)); |
| 119 | } |
| 120 | |
Andrew Lunn | 79b1119 | 2020-10-28 01:38:49 +0100 | [diff] [blame] | 121 | static __printf(2, 3) int tipc_tlv_sprintf(struct sk_buff *skb, |
| 122 | const char *fmt, ...) |
Richard Alpe | f2b3b2d | 2015-02-09 09:50:06 +0100 | [diff] [blame] | 123 | { |
| 124 | int n; |
| 125 | u16 len; |
| 126 | u32 rem; |
| 127 | char *buf; |
| 128 | struct tlv_desc *tlv; |
| 129 | va_list args; |
| 130 | |
| 131 | rem = tipc_skb_tailroom(skb); |
| 132 | |
| 133 | tlv = (struct tlv_desc *)skb->data; |
| 134 | len = TLV_GET_LEN(tlv); |
| 135 | buf = TLV_DATA(tlv) + len; |
| 136 | |
| 137 | va_start(args, fmt); |
| 138 | n = vscnprintf(buf, rem, fmt, args); |
| 139 | va_end(args); |
| 140 | |
| 141 | TLV_SET_LEN(tlv, n + len); |
| 142 | skb_put(skb, n); |
| 143 | |
| 144 | return n; |
| 145 | } |
| 146 | |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 147 | static struct sk_buff *tipc_tlv_alloc(int size) |
| 148 | { |
| 149 | int hdr_len; |
| 150 | struct sk_buff *buf; |
| 151 | |
| 152 | size = TLV_SPACE(size); |
| 153 | hdr_len = nlmsg_total_size(GENL_HDRLEN + TIPC_GENL_HDRLEN); |
| 154 | |
| 155 | buf = alloc_skb(hdr_len + size, GFP_KERNEL); |
| 156 | if (!buf) |
| 157 | return NULL; |
| 158 | |
| 159 | skb_reserve(buf, hdr_len); |
| 160 | |
| 161 | return buf; |
| 162 | } |
| 163 | |
| 164 | static struct sk_buff *tipc_get_err_tlv(char *str) |
| 165 | { |
| 166 | int str_len = strlen(str) + 1; |
| 167 | struct sk_buff *buf; |
| 168 | |
| 169 | buf = tipc_tlv_alloc(TLV_SPACE(str_len)); |
| 170 | if (buf) |
| 171 | tipc_add_tlv(buf, TIPC_TLV_ERROR_STRING, str, str_len); |
| 172 | |
| 173 | return buf; |
| 174 | } |
| 175 | |
Ying Xue | 8b66fee | 2019-01-14 17:22:25 +0800 | [diff] [blame] | 176 | static inline bool string_is_valid(char *s, int len) |
| 177 | { |
| 178 | return memchr(s, '\0', len) ? true : false; |
| 179 | } |
| 180 | |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 181 | static int __tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd, |
| 182 | struct tipc_nl_compat_msg *msg, |
| 183 | struct sk_buff *arg) |
| 184 | { |
Jiri Pirko | 6ea6776 | 2019-10-08 13:01:51 +0200 | [diff] [blame] | 185 | struct genl_dumpit_info info; |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 186 | int len = 0; |
| 187 | int err; |
| 188 | struct sk_buff *buf; |
| 189 | struct nlmsghdr *nlmsg; |
| 190 | struct netlink_callback cb; |
Jiri Pirko | c6c0861 | 2019-10-05 20:04:40 +0200 | [diff] [blame] | 191 | struct nlattr **attrbuf; |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 192 | |
| 193 | memset(&cb, 0, sizeof(cb)); |
| 194 | cb.nlh = (struct nlmsghdr *)arg->data; |
| 195 | cb.skb = arg; |
Jiri Pirko | 6ea6776 | 2019-10-08 13:01:51 +0200 | [diff] [blame] | 196 | cb.data = &info; |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 197 | |
| 198 | buf = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 199 | if (!buf) |
| 200 | return -ENOMEM; |
| 201 | |
| 202 | buf->sk = msg->dst_sk; |
Cong Wang | 12a78b0 | 2018-09-11 15:12:17 -0700 | [diff] [blame] | 203 | if (__tipc_dump_start(&cb, msg->net)) { |
| 204 | kfree_skb(buf); |
| 205 | return -ENOMEM; |
| 206 | } |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 207 | |
Ying Xue | a7869e5 | 2020-01-04 10:48:36 +0800 | [diff] [blame] | 208 | attrbuf = kcalloc(tipc_genl_family.maxattr + 1, |
| 209 | sizeof(struct nlattr *), GFP_KERNEL); |
Jiri Pirko | c6c0861 | 2019-10-05 20:04:40 +0200 | [diff] [blame] | 210 | if (!attrbuf) { |
| 211 | err = -ENOMEM; |
| 212 | goto err_out; |
| 213 | } |
| 214 | |
Jiri Pirko | 6ea6776 | 2019-10-08 13:01:51 +0200 | [diff] [blame] | 215 | info.attrs = attrbuf; |
Jiri Pirko | 6ea6776 | 2019-10-08 13:01:51 +0200 | [diff] [blame] | 216 | |
Hoang Le | c32c928 | 2020-12-15 10:31:51 +0700 | [diff] [blame] | 217 | if (nlmsg_len(cb.nlh) > 0) { |
| 218 | err = nlmsg_parse_deprecated(cb.nlh, GENL_HDRLEN, attrbuf, |
| 219 | tipc_genl_family.maxattr, |
| 220 | tipc_genl_family.policy, NULL); |
| 221 | if (err) |
| 222 | goto err_out; |
| 223 | } |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 224 | do { |
| 225 | int rem; |
| 226 | |
| 227 | len = (*cmd->dumpit)(buf, &cb); |
| 228 | |
| 229 | nlmsg_for_each_msg(nlmsg, nlmsg_hdr(buf), len, rem) { |
Jiri Pirko | c6c0861 | 2019-10-05 20:04:40 +0200 | [diff] [blame] | 230 | err = nlmsg_parse_deprecated(nlmsg, GENL_HDRLEN, |
| 231 | attrbuf, |
| 232 | tipc_genl_family.maxattr, |
| 233 | tipc_genl_family.policy, |
| 234 | NULL); |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 235 | if (err) |
| 236 | goto err_out; |
| 237 | |
Jiri Pirko | c6c0861 | 2019-10-05 20:04:40 +0200 | [diff] [blame] | 238 | err = (*cmd->format)(msg, attrbuf); |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 239 | if (err) |
| 240 | goto err_out; |
| 241 | |
| 242 | if (tipc_skb_tailroom(msg->rep) <= 1) { |
| 243 | err = -EMSGSIZE; |
| 244 | goto err_out; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | skb_reset_tail_pointer(buf); |
| 249 | buf->len = 0; |
| 250 | |
| 251 | } while (len); |
| 252 | |
| 253 | err = 0; |
| 254 | |
| 255 | err_out: |
Jiri Pirko | c6c0861 | 2019-10-05 20:04:40 +0200 | [diff] [blame] | 256 | kfree(attrbuf); |
Cong Wang | 8f5c5fc | 2018-09-04 14:54:55 -0700 | [diff] [blame] | 257 | tipc_dump_done(&cb); |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 258 | kfree_skb(buf); |
| 259 | |
| 260 | if (err == -EMSGSIZE) { |
| 261 | /* The legacy API only considered messages filling |
| 262 | * "ULTRA_STRING_MAX_LEN" to be truncated. |
| 263 | */ |
| 264 | if ((TIPC_SKB_MAX - msg->rep->len) <= 1) { |
| 265 | char *tail = skb_tail_pointer(msg->rep); |
| 266 | |
| 267 | if (*tail != '\0') |
| 268 | sprintf(tail - sizeof(REPLY_TRUNCATED) - 1, |
| 269 | REPLY_TRUNCATED); |
| 270 | } |
| 271 | |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | return err; |
| 276 | } |
| 277 | |
| 278 | static int tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd, |
| 279 | struct tipc_nl_compat_msg *msg) |
| 280 | { |
Cong Wang | 47733f9 | 2020-08-15 16:29:15 -0700 | [diff] [blame] | 281 | struct nlmsghdr *nlh; |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 282 | struct sk_buff *arg; |
Cong Wang | 47733f9 | 2020-08-15 16:29:15 -0700 | [diff] [blame] | 283 | int err; |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 284 | |
Taras Kondratiuk | 4da5f00 | 2019-07-29 22:15:07 +0000 | [diff] [blame] | 285 | if (msg->req_type && (!msg->req_size || |
| 286 | !TLV_CHECK_TYPE(msg->req, msg->req_type))) |
Richard Alpe | f2b3b2d | 2015-02-09 09:50:06 +0100 | [diff] [blame] | 287 | return -EINVAL; |
| 288 | |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 289 | msg->rep = tipc_tlv_alloc(msg->rep_size); |
| 290 | if (!msg->rep) |
| 291 | return -ENOMEM; |
| 292 | |
Richard Alpe | f2b3b2d | 2015-02-09 09:50:06 +0100 | [diff] [blame] | 293 | if (msg->rep_type) |
| 294 | tipc_tlv_init(msg->rep, msg->rep_type); |
| 295 | |
Xin Long | 2ac695d1 | 2019-03-31 22:50:10 +0800 | [diff] [blame] | 296 | if (cmd->header) { |
| 297 | err = (*cmd->header)(msg); |
| 298 | if (err) { |
| 299 | kfree_skb(msg->rep); |
| 300 | msg->rep = NULL; |
| 301 | return err; |
| 302 | } |
| 303 | } |
Richard Alpe | 44a8ae9 | 2015-02-09 09:50:10 +0100 | [diff] [blame] | 304 | |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 305 | arg = nlmsg_new(0, GFP_KERNEL); |
| 306 | if (!arg) { |
| 307 | kfree_skb(msg->rep); |
Eric Dumazet | 5bfd37b | 2017-08-16 09:41:54 -0700 | [diff] [blame] | 308 | msg->rep = NULL; |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 309 | return -ENOMEM; |
| 310 | } |
| 311 | |
Cong Wang | 47733f9 | 2020-08-15 16:29:15 -0700 | [diff] [blame] | 312 | nlh = nlmsg_put(arg, 0, 0, tipc_genl_family.id, 0, NLM_F_MULTI); |
| 313 | if (!nlh) { |
| 314 | kfree_skb(arg); |
| 315 | kfree_skb(msg->rep); |
| 316 | msg->rep = NULL; |
| 317 | return -EMSGSIZE; |
| 318 | } |
| 319 | nlmsg_end(arg, nlh); |
| 320 | |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 321 | err = __tipc_nl_compat_dumpit(cmd, msg, arg); |
Eric Dumazet | 5bfd37b | 2017-08-16 09:41:54 -0700 | [diff] [blame] | 322 | if (err) { |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 323 | kfree_skb(msg->rep); |
Eric Dumazet | 5bfd37b | 2017-08-16 09:41:54 -0700 | [diff] [blame] | 324 | msg->rep = NULL; |
| 325 | } |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 326 | kfree_skb(arg); |
| 327 | |
| 328 | return err; |
| 329 | } |
| 330 | |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 331 | static int __tipc_nl_compat_doit(struct tipc_nl_compat_cmd_doit *cmd, |
| 332 | struct tipc_nl_compat_msg *msg) |
| 333 | { |
| 334 | int err; |
| 335 | struct sk_buff *doit_buf; |
| 336 | struct sk_buff *trans_buf; |
| 337 | struct nlattr **attrbuf; |
| 338 | struct genl_info info; |
| 339 | |
| 340 | trans_buf = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); |
| 341 | if (!trans_buf) |
| 342 | return -ENOMEM; |
| 343 | |
Kees Cook | 6da2ec5 | 2018-06-12 13:55:00 -0700 | [diff] [blame] | 344 | attrbuf = kmalloc_array(tipc_genl_family.maxattr + 1, |
| 345 | sizeof(struct nlattr *), |
| 346 | GFP_KERNEL); |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 347 | if (!attrbuf) { |
| 348 | err = -ENOMEM; |
| 349 | goto trans_out; |
| 350 | } |
| 351 | |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 352 | doit_buf = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL); |
| 353 | if (!doit_buf) { |
| 354 | err = -ENOMEM; |
Ying Xue | e5d1a1e | 2018-02-14 13:37:58 +0800 | [diff] [blame] | 355 | goto attrbuf_out; |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 356 | } |
| 357 | |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 358 | memset(&info, 0, sizeof(info)); |
| 359 | info.attrs = attrbuf; |
| 360 | |
Ying Xue | ed4ffdf | 2018-02-14 13:38:04 +0800 | [diff] [blame] | 361 | rtnl_lock(); |
Ying Xue | e5d1a1e | 2018-02-14 13:37:58 +0800 | [diff] [blame] | 362 | err = (*cmd->transcode)(cmd, trans_buf, msg); |
| 363 | if (err) |
| 364 | goto doit_out; |
| 365 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 366 | err = nla_parse_deprecated(attrbuf, tipc_genl_family.maxattr, |
| 367 | (const struct nlattr *)trans_buf->data, |
| 368 | trans_buf->len, NULL, NULL); |
Ying Xue | e5d1a1e | 2018-02-14 13:37:58 +0800 | [diff] [blame] | 369 | if (err) |
| 370 | goto doit_out; |
| 371 | |
| 372 | doit_buf->sk = msg->dst_sk; |
| 373 | |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 374 | err = (*cmd->doit)(doit_buf, &info); |
Ying Xue | e5d1a1e | 2018-02-14 13:37:58 +0800 | [diff] [blame] | 375 | doit_out: |
Ying Xue | ed4ffdf | 2018-02-14 13:38:04 +0800 | [diff] [blame] | 376 | rtnl_unlock(); |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 377 | |
| 378 | kfree_skb(doit_buf); |
Ying Xue | e5d1a1e | 2018-02-14 13:37:58 +0800 | [diff] [blame] | 379 | attrbuf_out: |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 380 | kfree(attrbuf); |
| 381 | trans_out: |
| 382 | kfree_skb(trans_buf); |
| 383 | |
| 384 | return err; |
| 385 | } |
| 386 | |
| 387 | static int tipc_nl_compat_doit(struct tipc_nl_compat_cmd_doit *cmd, |
| 388 | struct tipc_nl_compat_msg *msg) |
| 389 | { |
| 390 | int err; |
| 391 | |
Taras Kondratiuk | 4da5f00 | 2019-07-29 22:15:07 +0000 | [diff] [blame] | 392 | if (msg->req_type && (!msg->req_size || |
| 393 | !TLV_CHECK_TYPE(msg->req, msg->req_type))) |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 394 | return -EINVAL; |
| 395 | |
| 396 | err = __tipc_nl_compat_doit(cmd, msg); |
| 397 | if (err) |
| 398 | return err; |
| 399 | |
| 400 | /* The legacy API considered an empty message a success message */ |
| 401 | msg->rep = tipc_tlv_alloc(0); |
| 402 | if (!msg->rep) |
| 403 | return -ENOMEM; |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 408 | static int tipc_nl_compat_bearer_dump(struct tipc_nl_compat_msg *msg, |
| 409 | struct nlattr **attrs) |
| 410 | { |
| 411 | struct nlattr *bearer[TIPC_NLA_BEARER_MAX + 1]; |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 412 | int err; |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 413 | |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 414 | if (!attrs[TIPC_NLA_BEARER]) |
| 415 | return -EINVAL; |
| 416 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 417 | err = nla_parse_nested_deprecated(bearer, TIPC_NLA_BEARER_MAX, |
| 418 | attrs[TIPC_NLA_BEARER], NULL, NULL); |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 419 | if (err) |
| 420 | return err; |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 421 | |
| 422 | return tipc_add_tlv(msg->rep, TIPC_TLV_BEARER_NAME, |
| 423 | nla_data(bearer[TIPC_NLA_BEARER_NAME]), |
| 424 | nla_len(bearer[TIPC_NLA_BEARER_NAME])); |
| 425 | } |
| 426 | |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 427 | static int tipc_nl_compat_bearer_enable(struct tipc_nl_compat_cmd_doit *cmd, |
| 428 | struct sk_buff *skb, |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 429 | struct tipc_nl_compat_msg *msg) |
| 430 | { |
| 431 | struct nlattr *prop; |
| 432 | struct nlattr *bearer; |
| 433 | struct tipc_bearer_config *b; |
Ying Xue | 0762216 | 2019-01-14 17:22:26 +0800 | [diff] [blame] | 434 | int len; |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 435 | |
| 436 | b = (struct tipc_bearer_config *)TLV_DATA(msg->req); |
| 437 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 438 | bearer = nla_nest_start_noflag(skb, TIPC_NLA_BEARER); |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 439 | if (!bearer) |
| 440 | return -EMSGSIZE; |
| 441 | |
Xin Long | 6f07e5f | 2019-03-31 22:50:08 +0800 | [diff] [blame] | 442 | len = TLV_GET_DATA_LEN(msg->req); |
| 443 | len -= offsetof(struct tipc_bearer_config, name); |
| 444 | if (len <= 0) |
| 445 | return -EINVAL; |
| 446 | |
| 447 | len = min_t(int, len, TIPC_MAX_BEARER_NAME); |
Ying Xue | 0762216 | 2019-01-14 17:22:26 +0800 | [diff] [blame] | 448 | if (!string_is_valid(b->name, len)) |
| 449 | return -EINVAL; |
| 450 | |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 451 | if (nla_put_string(skb, TIPC_NLA_BEARER_NAME, b->name)) |
| 452 | return -EMSGSIZE; |
| 453 | |
| 454 | if (nla_put_u32(skb, TIPC_NLA_BEARER_DOMAIN, ntohl(b->disc_domain))) |
| 455 | return -EMSGSIZE; |
| 456 | |
| 457 | if (ntohl(b->priority) <= TIPC_MAX_LINK_PRI) { |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 458 | prop = nla_nest_start_noflag(skb, TIPC_NLA_BEARER_PROP); |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 459 | if (!prop) |
| 460 | return -EMSGSIZE; |
| 461 | if (nla_put_u32(skb, TIPC_NLA_PROP_PRIO, ntohl(b->priority))) |
| 462 | return -EMSGSIZE; |
| 463 | nla_nest_end(skb, prop); |
| 464 | } |
| 465 | nla_nest_end(skb, bearer); |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 470 | static int tipc_nl_compat_bearer_disable(struct tipc_nl_compat_cmd_doit *cmd, |
| 471 | struct sk_buff *skb, |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 472 | struct tipc_nl_compat_msg *msg) |
| 473 | { |
| 474 | char *name; |
| 475 | struct nlattr *bearer; |
Ying Xue | 0762216 | 2019-01-14 17:22:26 +0800 | [diff] [blame] | 476 | int len; |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 477 | |
| 478 | name = (char *)TLV_DATA(msg->req); |
| 479 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 480 | bearer = nla_nest_start_noflag(skb, TIPC_NLA_BEARER); |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 481 | if (!bearer) |
| 482 | return -EMSGSIZE; |
| 483 | |
Xin Long | 4f07b80 | 2019-06-25 00:28:19 +0800 | [diff] [blame] | 484 | len = TLV_GET_DATA_LEN(msg->req); |
| 485 | if (len <= 0) |
| 486 | return -EINVAL; |
| 487 | |
| 488 | len = min_t(int, len, TIPC_MAX_BEARER_NAME); |
Ying Xue | 0762216 | 2019-01-14 17:22:26 +0800 | [diff] [blame] | 489 | if (!string_is_valid(name, len)) |
| 490 | return -EINVAL; |
| 491 | |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 492 | if (nla_put_string(skb, TIPC_NLA_BEARER_NAME, name)) |
| 493 | return -EMSGSIZE; |
| 494 | |
| 495 | nla_nest_end(skb, bearer); |
| 496 | |
| 497 | return 0; |
| 498 | } |
| 499 | |
Richard Alpe | f2b3b2d | 2015-02-09 09:50:06 +0100 | [diff] [blame] | 500 | static inline u32 perc(u32 count, u32 total) |
| 501 | { |
| 502 | return (count * 100 + (total / 2)) / total; |
| 503 | } |
| 504 | |
| 505 | static void __fill_bc_link_stat(struct tipc_nl_compat_msg *msg, |
| 506 | struct nlattr *prop[], struct nlattr *stats[]) |
| 507 | { |
| 508 | tipc_tlv_sprintf(msg->rep, " Window:%u packets\n", |
| 509 | nla_get_u32(prop[TIPC_NLA_PROP_WIN])); |
| 510 | |
| 511 | tipc_tlv_sprintf(msg->rep, |
| 512 | " RX packets:%u fragments:%u/%u bundles:%u/%u\n", |
| 513 | nla_get_u32(stats[TIPC_NLA_STATS_RX_INFO]), |
| 514 | nla_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTS]), |
| 515 | nla_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTED]), |
| 516 | nla_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLES]), |
| 517 | nla_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLED])); |
| 518 | |
| 519 | tipc_tlv_sprintf(msg->rep, |
| 520 | " TX packets:%u fragments:%u/%u bundles:%u/%u\n", |
| 521 | nla_get_u32(stats[TIPC_NLA_STATS_TX_INFO]), |
| 522 | nla_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTS]), |
| 523 | nla_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTED]), |
| 524 | nla_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLES]), |
| 525 | nla_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLED])); |
| 526 | |
| 527 | tipc_tlv_sprintf(msg->rep, " RX naks:%u defs:%u dups:%u\n", |
| 528 | nla_get_u32(stats[TIPC_NLA_STATS_RX_NACKS]), |
| 529 | nla_get_u32(stats[TIPC_NLA_STATS_RX_DEFERRED]), |
| 530 | nla_get_u32(stats[TIPC_NLA_STATS_DUPLICATES])); |
| 531 | |
| 532 | tipc_tlv_sprintf(msg->rep, " TX naks:%u acks:%u dups:%u\n", |
| 533 | nla_get_u32(stats[TIPC_NLA_STATS_TX_NACKS]), |
| 534 | nla_get_u32(stats[TIPC_NLA_STATS_TX_ACKS]), |
| 535 | nla_get_u32(stats[TIPC_NLA_STATS_RETRANSMITTED])); |
| 536 | |
| 537 | tipc_tlv_sprintf(msg->rep, |
| 538 | " Congestion link:%u Send queue max:%u avg:%u", |
| 539 | nla_get_u32(stats[TIPC_NLA_STATS_LINK_CONGS]), |
| 540 | nla_get_u32(stats[TIPC_NLA_STATS_MAX_QUEUE]), |
| 541 | nla_get_u32(stats[TIPC_NLA_STATS_AVG_QUEUE])); |
| 542 | } |
| 543 | |
| 544 | static int tipc_nl_compat_link_stat_dump(struct tipc_nl_compat_msg *msg, |
| 545 | struct nlattr **attrs) |
| 546 | { |
| 547 | char *name; |
| 548 | struct nlattr *link[TIPC_NLA_LINK_MAX + 1]; |
| 549 | struct nlattr *prop[TIPC_NLA_PROP_MAX + 1]; |
| 550 | struct nlattr *stats[TIPC_NLA_STATS_MAX + 1]; |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 551 | int err; |
Ying Xue | 0762216 | 2019-01-14 17:22:26 +0800 | [diff] [blame] | 552 | int len; |
Richard Alpe | f2b3b2d | 2015-02-09 09:50:06 +0100 | [diff] [blame] | 553 | |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 554 | if (!attrs[TIPC_NLA_LINK]) |
| 555 | return -EINVAL; |
Richard Alpe | f2b3b2d | 2015-02-09 09:50:06 +0100 | [diff] [blame] | 556 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 557 | err = nla_parse_nested_deprecated(link, TIPC_NLA_LINK_MAX, |
| 558 | attrs[TIPC_NLA_LINK], NULL, NULL); |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 559 | if (err) |
| 560 | return err; |
Richard Alpe | f2b3b2d | 2015-02-09 09:50:06 +0100 | [diff] [blame] | 561 | |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 562 | if (!link[TIPC_NLA_LINK_PROP]) |
| 563 | return -EINVAL; |
| 564 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 565 | err = nla_parse_nested_deprecated(prop, TIPC_NLA_PROP_MAX, |
| 566 | link[TIPC_NLA_LINK_PROP], NULL, |
| 567 | NULL); |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 568 | if (err) |
| 569 | return err; |
| 570 | |
| 571 | if (!link[TIPC_NLA_LINK_STATS]) |
| 572 | return -EINVAL; |
| 573 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 574 | err = nla_parse_nested_deprecated(stats, TIPC_NLA_STATS_MAX, |
| 575 | link[TIPC_NLA_LINK_STATS], NULL, |
| 576 | NULL); |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 577 | if (err) |
| 578 | return err; |
Richard Alpe | f2b3b2d | 2015-02-09 09:50:06 +0100 | [diff] [blame] | 579 | |
| 580 | name = (char *)TLV_DATA(msg->req); |
Ying Xue | 0762216 | 2019-01-14 17:22:26 +0800 | [diff] [blame] | 581 | |
Xin Long | 4f07b80 | 2019-06-25 00:28:19 +0800 | [diff] [blame] | 582 | len = TLV_GET_DATA_LEN(msg->req); |
| 583 | if (len <= 0) |
| 584 | return -EINVAL; |
| 585 | |
John Rutherford | fd567ac | 2019-11-26 13:52:55 +1100 | [diff] [blame] | 586 | len = min_t(int, len, TIPC_MAX_LINK_NAME); |
Ying Xue | 0762216 | 2019-01-14 17:22:26 +0800 | [diff] [blame] | 587 | if (!string_is_valid(name, len)) |
| 588 | return -EINVAL; |
| 589 | |
Richard Alpe | f2b3b2d | 2015-02-09 09:50:06 +0100 | [diff] [blame] | 590 | if (strcmp(name, nla_data(link[TIPC_NLA_LINK_NAME])) != 0) |
| 591 | return 0; |
| 592 | |
| 593 | tipc_tlv_sprintf(msg->rep, "\nLink <%s>\n", |
Andrew Lunn | b3b7e64 | 2020-10-28 01:43:33 +0100 | [diff] [blame] | 594 | (char *)nla_data(link[TIPC_NLA_LINK_NAME])); |
Richard Alpe | f2b3b2d | 2015-02-09 09:50:06 +0100 | [diff] [blame] | 595 | |
| 596 | if (link[TIPC_NLA_LINK_BROADCAST]) { |
| 597 | __fill_bc_link_stat(msg, prop, stats); |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | if (link[TIPC_NLA_LINK_ACTIVE]) |
| 602 | tipc_tlv_sprintf(msg->rep, " ACTIVE"); |
| 603 | else if (link[TIPC_NLA_LINK_UP]) |
| 604 | tipc_tlv_sprintf(msg->rep, " STANDBY"); |
| 605 | else |
| 606 | tipc_tlv_sprintf(msg->rep, " DEFUNCT"); |
| 607 | |
| 608 | tipc_tlv_sprintf(msg->rep, " MTU:%u Priority:%u", |
| 609 | nla_get_u32(link[TIPC_NLA_LINK_MTU]), |
| 610 | nla_get_u32(prop[TIPC_NLA_PROP_PRIO])); |
| 611 | |
| 612 | tipc_tlv_sprintf(msg->rep, " Tolerance:%u ms Window:%u packets\n", |
| 613 | nla_get_u32(prop[TIPC_NLA_PROP_TOL]), |
| 614 | nla_get_u32(prop[TIPC_NLA_PROP_WIN])); |
| 615 | |
| 616 | tipc_tlv_sprintf(msg->rep, |
| 617 | " RX packets:%u fragments:%u/%u bundles:%u/%u\n", |
| 618 | nla_get_u32(link[TIPC_NLA_LINK_RX]) - |
| 619 | nla_get_u32(stats[TIPC_NLA_STATS_RX_INFO]), |
| 620 | nla_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTS]), |
| 621 | nla_get_u32(stats[TIPC_NLA_STATS_RX_FRAGMENTED]), |
| 622 | nla_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLES]), |
| 623 | nla_get_u32(stats[TIPC_NLA_STATS_RX_BUNDLED])); |
| 624 | |
| 625 | tipc_tlv_sprintf(msg->rep, |
| 626 | " TX packets:%u fragments:%u/%u bundles:%u/%u\n", |
| 627 | nla_get_u32(link[TIPC_NLA_LINK_TX]) - |
| 628 | nla_get_u32(stats[TIPC_NLA_STATS_TX_INFO]), |
| 629 | nla_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTS]), |
| 630 | nla_get_u32(stats[TIPC_NLA_STATS_TX_FRAGMENTED]), |
| 631 | nla_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLES]), |
| 632 | nla_get_u32(stats[TIPC_NLA_STATS_TX_BUNDLED])); |
| 633 | |
| 634 | tipc_tlv_sprintf(msg->rep, |
| 635 | " TX profile sample:%u packets average:%u octets\n", |
| 636 | nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_CNT]), |
| 637 | nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_TOT]) / |
| 638 | nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])); |
| 639 | |
| 640 | tipc_tlv_sprintf(msg->rep, |
| 641 | " 0-64:%u%% -256:%u%% -1024:%u%% -4096:%u%% ", |
| 642 | perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P0]), |
| 643 | nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])), |
| 644 | perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P1]), |
| 645 | nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])), |
| 646 | perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P2]), |
| 647 | nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])), |
| 648 | perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P3]), |
| 649 | nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT]))); |
| 650 | |
| 651 | tipc_tlv_sprintf(msg->rep, "-16384:%u%% -32768:%u%% -66000:%u%%\n", |
| 652 | perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P4]), |
| 653 | nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])), |
| 654 | perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P5]), |
| 655 | nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT])), |
| 656 | perc(nla_get_u32(stats[TIPC_NLA_STATS_MSG_LEN_P6]), |
| 657 | nla_get_u32(stats[TIPC_NLA_STATS_MSG_PROF_TOT]))); |
| 658 | |
| 659 | tipc_tlv_sprintf(msg->rep, |
| 660 | " RX states:%u probes:%u naks:%u defs:%u dups:%u\n", |
| 661 | nla_get_u32(stats[TIPC_NLA_STATS_RX_STATES]), |
| 662 | nla_get_u32(stats[TIPC_NLA_STATS_RX_PROBES]), |
| 663 | nla_get_u32(stats[TIPC_NLA_STATS_RX_NACKS]), |
| 664 | nla_get_u32(stats[TIPC_NLA_STATS_RX_DEFERRED]), |
| 665 | nla_get_u32(stats[TIPC_NLA_STATS_DUPLICATES])); |
| 666 | |
| 667 | tipc_tlv_sprintf(msg->rep, |
| 668 | " TX states:%u probes:%u naks:%u acks:%u dups:%u\n", |
| 669 | nla_get_u32(stats[TIPC_NLA_STATS_TX_STATES]), |
| 670 | nla_get_u32(stats[TIPC_NLA_STATS_TX_PROBES]), |
| 671 | nla_get_u32(stats[TIPC_NLA_STATS_TX_NACKS]), |
| 672 | nla_get_u32(stats[TIPC_NLA_STATS_TX_ACKS]), |
| 673 | nla_get_u32(stats[TIPC_NLA_STATS_RETRANSMITTED])); |
| 674 | |
| 675 | tipc_tlv_sprintf(msg->rep, |
| 676 | " Congestion link:%u Send queue max:%u avg:%u", |
| 677 | nla_get_u32(stats[TIPC_NLA_STATS_LINK_CONGS]), |
| 678 | nla_get_u32(stats[TIPC_NLA_STATS_MAX_QUEUE]), |
| 679 | nla_get_u32(stats[TIPC_NLA_STATS_AVG_QUEUE])); |
| 680 | |
| 681 | return 0; |
| 682 | } |
| 683 | |
Richard Alpe | 357ebdb | 2015-02-09 09:50:07 +0100 | [diff] [blame] | 684 | static int tipc_nl_compat_link_dump(struct tipc_nl_compat_msg *msg, |
| 685 | struct nlattr **attrs) |
| 686 | { |
| 687 | struct nlattr *link[TIPC_NLA_LINK_MAX + 1]; |
| 688 | struct tipc_link_info link_info; |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 689 | int err; |
Richard Alpe | 357ebdb | 2015-02-09 09:50:07 +0100 | [diff] [blame] | 690 | |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 691 | if (!attrs[TIPC_NLA_LINK]) |
| 692 | return -EINVAL; |
| 693 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 694 | err = nla_parse_nested_deprecated(link, TIPC_NLA_LINK_MAX, |
| 695 | attrs[TIPC_NLA_LINK], NULL, NULL); |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 696 | if (err) |
| 697 | return err; |
Richard Alpe | 357ebdb | 2015-02-09 09:50:07 +0100 | [diff] [blame] | 698 | |
Hoang Le | 1980d37 | 2021-03-11 10:33:22 +0700 | [diff] [blame] | 699 | link_info.dest = htonl(nla_get_flag(link[TIPC_NLA_LINK_DEST])); |
Richard Alpe | 357ebdb | 2015-02-09 09:50:07 +0100 | [diff] [blame] | 700 | link_info.up = htonl(nla_get_flag(link[TIPC_NLA_LINK_UP])); |
Francis Laniel | 872f690 | 2020-11-15 18:08:06 +0100 | [diff] [blame] | 701 | nla_strscpy(link_info.str, link[TIPC_NLA_LINK_NAME], |
Kangjie Lu | 5d2be14 | 2016-06-02 04:04:56 -0400 | [diff] [blame] | 702 | TIPC_MAX_LINK_NAME); |
Richard Alpe | 357ebdb | 2015-02-09 09:50:07 +0100 | [diff] [blame] | 703 | |
| 704 | return tipc_add_tlv(msg->rep, TIPC_TLV_LINK_INFO, |
| 705 | &link_info, sizeof(link_info)); |
| 706 | } |
| 707 | |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 708 | static int __tipc_add_link_prop(struct sk_buff *skb, |
| 709 | struct tipc_nl_compat_msg *msg, |
| 710 | struct tipc_link_config *lc) |
Richard Alpe | 37e2d48 | 2015-02-09 09:50:08 +0100 | [diff] [blame] | 711 | { |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 712 | switch (msg->cmd) { |
| 713 | case TIPC_CMD_SET_LINK_PRI: |
| 714 | return nla_put_u32(skb, TIPC_NLA_PROP_PRIO, ntohl(lc->value)); |
| 715 | case TIPC_CMD_SET_LINK_TOL: |
| 716 | return nla_put_u32(skb, TIPC_NLA_PROP_TOL, ntohl(lc->value)); |
| 717 | case TIPC_CMD_SET_LINK_WINDOW: |
| 718 | return nla_put_u32(skb, TIPC_NLA_PROP_WIN, ntohl(lc->value)); |
| 719 | } |
| 720 | |
| 721 | return -EINVAL; |
| 722 | } |
| 723 | |
| 724 | static int tipc_nl_compat_media_set(struct sk_buff *skb, |
| 725 | struct tipc_nl_compat_msg *msg) |
| 726 | { |
Richard Alpe | 37e2d48 | 2015-02-09 09:50:08 +0100 | [diff] [blame] | 727 | struct nlattr *prop; |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 728 | struct nlattr *media; |
| 729 | struct tipc_link_config *lc; |
| 730 | |
| 731 | lc = (struct tipc_link_config *)TLV_DATA(msg->req); |
| 732 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 733 | media = nla_nest_start_noflag(skb, TIPC_NLA_MEDIA); |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 734 | if (!media) |
| 735 | return -EMSGSIZE; |
| 736 | |
| 737 | if (nla_put_string(skb, TIPC_NLA_MEDIA_NAME, lc->name)) |
| 738 | return -EMSGSIZE; |
| 739 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 740 | prop = nla_nest_start_noflag(skb, TIPC_NLA_MEDIA_PROP); |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 741 | if (!prop) |
| 742 | return -EMSGSIZE; |
| 743 | |
| 744 | __tipc_add_link_prop(skb, msg, lc); |
| 745 | nla_nest_end(skb, prop); |
| 746 | nla_nest_end(skb, media); |
| 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | static int tipc_nl_compat_bearer_set(struct sk_buff *skb, |
| 752 | struct tipc_nl_compat_msg *msg) |
| 753 | { |
| 754 | struct nlattr *prop; |
| 755 | struct nlattr *bearer; |
| 756 | struct tipc_link_config *lc; |
| 757 | |
| 758 | lc = (struct tipc_link_config *)TLV_DATA(msg->req); |
| 759 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 760 | bearer = nla_nest_start_noflag(skb, TIPC_NLA_BEARER); |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 761 | if (!bearer) |
| 762 | return -EMSGSIZE; |
| 763 | |
| 764 | if (nla_put_string(skb, TIPC_NLA_BEARER_NAME, lc->name)) |
| 765 | return -EMSGSIZE; |
| 766 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 767 | prop = nla_nest_start_noflag(skb, TIPC_NLA_BEARER_PROP); |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 768 | if (!prop) |
| 769 | return -EMSGSIZE; |
| 770 | |
| 771 | __tipc_add_link_prop(skb, msg, lc); |
| 772 | nla_nest_end(skb, prop); |
| 773 | nla_nest_end(skb, bearer); |
| 774 | |
| 775 | return 0; |
| 776 | } |
| 777 | |
| 778 | static int __tipc_nl_compat_link_set(struct sk_buff *skb, |
| 779 | struct tipc_nl_compat_msg *msg) |
| 780 | { |
| 781 | struct nlattr *prop; |
| 782 | struct nlattr *link; |
Richard Alpe | 37e2d48 | 2015-02-09 09:50:08 +0100 | [diff] [blame] | 783 | struct tipc_link_config *lc; |
| 784 | |
| 785 | lc = (struct tipc_link_config *)TLV_DATA(msg->req); |
| 786 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 787 | link = nla_nest_start_noflag(skb, TIPC_NLA_LINK); |
Richard Alpe | 37e2d48 | 2015-02-09 09:50:08 +0100 | [diff] [blame] | 788 | if (!link) |
| 789 | return -EMSGSIZE; |
| 790 | |
| 791 | if (nla_put_string(skb, TIPC_NLA_LINK_NAME, lc->name)) |
| 792 | return -EMSGSIZE; |
| 793 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 794 | prop = nla_nest_start_noflag(skb, TIPC_NLA_LINK_PROP); |
Richard Alpe | 37e2d48 | 2015-02-09 09:50:08 +0100 | [diff] [blame] | 795 | if (!prop) |
| 796 | return -EMSGSIZE; |
| 797 | |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 798 | __tipc_add_link_prop(skb, msg, lc); |
Richard Alpe | 37e2d48 | 2015-02-09 09:50:08 +0100 | [diff] [blame] | 799 | nla_nest_end(skb, prop); |
| 800 | nla_nest_end(skb, link); |
| 801 | |
| 802 | return 0; |
| 803 | } |
| 804 | |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 805 | static int tipc_nl_compat_link_set(struct tipc_nl_compat_cmd_doit *cmd, |
| 806 | struct sk_buff *skb, |
| 807 | struct tipc_nl_compat_msg *msg) |
| 808 | { |
| 809 | struct tipc_link_config *lc; |
| 810 | struct tipc_bearer *bearer; |
| 811 | struct tipc_media *media; |
Ying Xue | edf5ff0 | 2019-01-14 17:22:27 +0800 | [diff] [blame] | 812 | int len; |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 813 | |
| 814 | lc = (struct tipc_link_config *)TLV_DATA(msg->req); |
| 815 | |
Xin Long | 8c63bf9 | 2019-03-31 22:50:09 +0800 | [diff] [blame] | 816 | len = TLV_GET_DATA_LEN(msg->req); |
| 817 | len -= offsetof(struct tipc_link_config, name); |
| 818 | if (len <= 0) |
| 819 | return -EINVAL; |
| 820 | |
| 821 | len = min_t(int, len, TIPC_MAX_LINK_NAME); |
Ying Xue | edf5ff0 | 2019-01-14 17:22:27 +0800 | [diff] [blame] | 822 | if (!string_is_valid(lc->name, len)) |
| 823 | return -EINVAL; |
| 824 | |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 825 | media = tipc_media_find(lc->name); |
| 826 | if (media) { |
Ying Xue | ed4ffdf | 2018-02-14 13:38:04 +0800 | [diff] [blame] | 827 | cmd->doit = &__tipc_nl_media_set; |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 828 | return tipc_nl_compat_media_set(skb, msg); |
| 829 | } |
| 830 | |
| 831 | bearer = tipc_bearer_find(msg->net, lc->name); |
| 832 | if (bearer) { |
Ying Xue | ed4ffdf | 2018-02-14 13:38:04 +0800 | [diff] [blame] | 833 | cmd->doit = &__tipc_nl_bearer_set; |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 834 | return tipc_nl_compat_bearer_set(skb, msg); |
| 835 | } |
| 836 | |
| 837 | return __tipc_nl_compat_link_set(skb, msg); |
| 838 | } |
| 839 | |
| 840 | static int tipc_nl_compat_link_reset_stats(struct tipc_nl_compat_cmd_doit *cmd, |
| 841 | struct sk_buff *skb, |
Richard Alpe | 1817877 | 2015-02-09 09:50:09 +0100 | [diff] [blame] | 842 | struct tipc_nl_compat_msg *msg) |
| 843 | { |
| 844 | char *name; |
| 845 | struct nlattr *link; |
Ying Xue | 8b66fee | 2019-01-14 17:22:25 +0800 | [diff] [blame] | 846 | int len; |
Richard Alpe | 1817877 | 2015-02-09 09:50:09 +0100 | [diff] [blame] | 847 | |
| 848 | name = (char *)TLV_DATA(msg->req); |
| 849 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 850 | link = nla_nest_start_noflag(skb, TIPC_NLA_LINK); |
Richard Alpe | 1817877 | 2015-02-09 09:50:09 +0100 | [diff] [blame] | 851 | if (!link) |
| 852 | return -EMSGSIZE; |
| 853 | |
Xin Long | 4f07b80 | 2019-06-25 00:28:19 +0800 | [diff] [blame] | 854 | len = TLV_GET_DATA_LEN(msg->req); |
| 855 | if (len <= 0) |
| 856 | return -EINVAL; |
| 857 | |
John Rutherford | fd567ac | 2019-11-26 13:52:55 +1100 | [diff] [blame] | 858 | len = min_t(int, len, TIPC_MAX_LINK_NAME); |
Ying Xue | 8b66fee | 2019-01-14 17:22:25 +0800 | [diff] [blame] | 859 | if (!string_is_valid(name, len)) |
| 860 | return -EINVAL; |
| 861 | |
Richard Alpe | 1817877 | 2015-02-09 09:50:09 +0100 | [diff] [blame] | 862 | if (nla_put_string(skb, TIPC_NLA_LINK_NAME, name)) |
| 863 | return -EMSGSIZE; |
| 864 | |
| 865 | nla_nest_end(skb, link); |
| 866 | |
| 867 | return 0; |
| 868 | } |
| 869 | |
Richard Alpe | 44a8ae9 | 2015-02-09 09:50:10 +0100 | [diff] [blame] | 870 | static int tipc_nl_compat_name_table_dump_header(struct tipc_nl_compat_msg *msg) |
| 871 | { |
| 872 | int i; |
| 873 | u32 depth; |
| 874 | struct tipc_name_table_query *ntq; |
| 875 | static const char * const header[] = { |
| 876 | "Type ", |
| 877 | "Lower Upper ", |
| 878 | "Port Identity ", |
| 879 | "Publication Scope" |
| 880 | }; |
| 881 | |
| 882 | ntq = (struct tipc_name_table_query *)TLV_DATA(msg->req); |
Ying Xue | 974cb0e | 2019-01-14 17:22:28 +0800 | [diff] [blame] | 883 | if (TLV_GET_DATA_LEN(msg->req) < sizeof(struct tipc_name_table_query)) |
| 884 | return -EINVAL; |
Richard Alpe | 44a8ae9 | 2015-02-09 09:50:10 +0100 | [diff] [blame] | 885 | |
| 886 | depth = ntohl(ntq->depth); |
| 887 | |
| 888 | if (depth > 4) |
| 889 | depth = 4; |
| 890 | for (i = 0; i < depth; i++) |
| 891 | tipc_tlv_sprintf(msg->rep, header[i]); |
| 892 | tipc_tlv_sprintf(msg->rep, "\n"); |
| 893 | |
| 894 | return 0; |
| 895 | } |
| 896 | |
| 897 | static int tipc_nl_compat_name_table_dump(struct tipc_nl_compat_msg *msg, |
| 898 | struct nlattr **attrs) |
| 899 | { |
| 900 | char port_str[27]; |
| 901 | struct tipc_name_table_query *ntq; |
| 902 | struct nlattr *nt[TIPC_NLA_NAME_TABLE_MAX + 1]; |
| 903 | struct nlattr *publ[TIPC_NLA_PUBL_MAX + 1]; |
| 904 | u32 node, depth, type, lowbound, upbound; |
| 905 | static const char * const scope_str[] = {"", " zone", " cluster", |
| 906 | " node"}; |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 907 | int err; |
Richard Alpe | 44a8ae9 | 2015-02-09 09:50:10 +0100 | [diff] [blame] | 908 | |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 909 | if (!attrs[TIPC_NLA_NAME_TABLE]) |
| 910 | return -EINVAL; |
Richard Alpe | 44a8ae9 | 2015-02-09 09:50:10 +0100 | [diff] [blame] | 911 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 912 | err = nla_parse_nested_deprecated(nt, TIPC_NLA_NAME_TABLE_MAX, |
| 913 | attrs[TIPC_NLA_NAME_TABLE], NULL, |
| 914 | NULL); |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 915 | if (err) |
| 916 | return err; |
| 917 | |
| 918 | if (!nt[TIPC_NLA_NAME_TABLE_PUBL]) |
| 919 | return -EINVAL; |
| 920 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 921 | err = nla_parse_nested_deprecated(publ, TIPC_NLA_PUBL_MAX, |
| 922 | nt[TIPC_NLA_NAME_TABLE_PUBL], NULL, |
| 923 | NULL); |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 924 | if (err) |
| 925 | return err; |
Richard Alpe | 44a8ae9 | 2015-02-09 09:50:10 +0100 | [diff] [blame] | 926 | |
| 927 | ntq = (struct tipc_name_table_query *)TLV_DATA(msg->req); |
| 928 | |
| 929 | depth = ntohl(ntq->depth); |
| 930 | type = ntohl(ntq->type); |
| 931 | lowbound = ntohl(ntq->lowbound); |
| 932 | upbound = ntohl(ntq->upbound); |
| 933 | |
| 934 | if (!(depth & TIPC_NTQ_ALLTYPES) && |
| 935 | (type != nla_get_u32(publ[TIPC_NLA_PUBL_TYPE]))) |
| 936 | return 0; |
| 937 | if (lowbound && (lowbound > nla_get_u32(publ[TIPC_NLA_PUBL_UPPER]))) |
| 938 | return 0; |
| 939 | if (upbound && (upbound < nla_get_u32(publ[TIPC_NLA_PUBL_LOWER]))) |
| 940 | return 0; |
| 941 | |
| 942 | tipc_tlv_sprintf(msg->rep, "%-10u ", |
| 943 | nla_get_u32(publ[TIPC_NLA_PUBL_TYPE])); |
| 944 | |
| 945 | if (depth == 1) |
| 946 | goto out; |
| 947 | |
| 948 | tipc_tlv_sprintf(msg->rep, "%-10u %-10u ", |
| 949 | nla_get_u32(publ[TIPC_NLA_PUBL_LOWER]), |
| 950 | nla_get_u32(publ[TIPC_NLA_PUBL_UPPER])); |
| 951 | |
| 952 | if (depth == 2) |
| 953 | goto out; |
| 954 | |
| 955 | node = nla_get_u32(publ[TIPC_NLA_PUBL_NODE]); |
| 956 | sprintf(port_str, "<%u.%u.%u:%u>", tipc_zone(node), tipc_cluster(node), |
| 957 | tipc_node(node), nla_get_u32(publ[TIPC_NLA_PUBL_REF])); |
| 958 | tipc_tlv_sprintf(msg->rep, "%-26s ", port_str); |
| 959 | |
| 960 | if (depth == 3) |
| 961 | goto out; |
| 962 | |
| 963 | tipc_tlv_sprintf(msg->rep, "%-10u %s", |
Richard Alpe | 03aaaa9 | 2016-05-17 16:57:37 +0200 | [diff] [blame] | 964 | nla_get_u32(publ[TIPC_NLA_PUBL_KEY]), |
Richard Alpe | 44a8ae9 | 2015-02-09 09:50:10 +0100 | [diff] [blame] | 965 | scope_str[nla_get_u32(publ[TIPC_NLA_PUBL_SCOPE])]); |
| 966 | out: |
| 967 | tipc_tlv_sprintf(msg->rep, "\n"); |
| 968 | |
| 969 | return 0; |
| 970 | } |
| 971 | |
Richard Alpe | 487d2a3 | 2015-02-09 09:50:11 +0100 | [diff] [blame] | 972 | static int __tipc_nl_compat_publ_dump(struct tipc_nl_compat_msg *msg, |
| 973 | struct nlattr **attrs) |
| 974 | { |
| 975 | u32 type, lower, upper; |
| 976 | struct nlattr *publ[TIPC_NLA_PUBL_MAX + 1]; |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 977 | int err; |
Richard Alpe | 487d2a3 | 2015-02-09 09:50:11 +0100 | [diff] [blame] | 978 | |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 979 | if (!attrs[TIPC_NLA_PUBL]) |
| 980 | return -EINVAL; |
| 981 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 982 | err = nla_parse_nested_deprecated(publ, TIPC_NLA_PUBL_MAX, |
| 983 | attrs[TIPC_NLA_PUBL], NULL, NULL); |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 984 | if (err) |
| 985 | return err; |
Richard Alpe | 487d2a3 | 2015-02-09 09:50:11 +0100 | [diff] [blame] | 986 | |
| 987 | type = nla_get_u32(publ[TIPC_NLA_PUBL_TYPE]); |
| 988 | lower = nla_get_u32(publ[TIPC_NLA_PUBL_LOWER]); |
| 989 | upper = nla_get_u32(publ[TIPC_NLA_PUBL_UPPER]); |
| 990 | |
| 991 | if (lower == upper) |
| 992 | tipc_tlv_sprintf(msg->rep, " {%u,%u}", type, lower); |
| 993 | else |
| 994 | tipc_tlv_sprintf(msg->rep, " {%u,%u,%u}", type, lower, upper); |
| 995 | |
| 996 | return 0; |
| 997 | } |
| 998 | |
| 999 | static int tipc_nl_compat_publ_dump(struct tipc_nl_compat_msg *msg, u32 sock) |
| 1000 | { |
| 1001 | int err; |
| 1002 | void *hdr; |
| 1003 | struct nlattr *nest; |
| 1004 | struct sk_buff *args; |
| 1005 | struct tipc_nl_compat_cmd_dump dump; |
| 1006 | |
| 1007 | args = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 1008 | if (!args) |
| 1009 | return -ENOMEM; |
| 1010 | |
| 1011 | hdr = genlmsg_put(args, 0, 0, &tipc_genl_family, NLM_F_MULTI, |
| 1012 | TIPC_NL_PUBL_GET); |
Gustavo A. R. Silva | f87d8ad | 2019-01-05 10:52:23 -0600 | [diff] [blame] | 1013 | if (!hdr) { |
| 1014 | kfree_skb(args); |
Kangjie Lu | 46273cf | 2018-12-26 00:09:04 -0600 | [diff] [blame] | 1015 | return -EMSGSIZE; |
Gustavo A. R. Silva | f87d8ad | 2019-01-05 10:52:23 -0600 | [diff] [blame] | 1016 | } |
Richard Alpe | 487d2a3 | 2015-02-09 09:50:11 +0100 | [diff] [blame] | 1017 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1018 | nest = nla_nest_start_noflag(args, TIPC_NLA_SOCK); |
Richard Alpe | 487d2a3 | 2015-02-09 09:50:11 +0100 | [diff] [blame] | 1019 | if (!nest) { |
| 1020 | kfree_skb(args); |
| 1021 | return -EMSGSIZE; |
| 1022 | } |
| 1023 | |
| 1024 | if (nla_put_u32(args, TIPC_NLA_SOCK_REF, sock)) { |
| 1025 | kfree_skb(args); |
| 1026 | return -EMSGSIZE; |
| 1027 | } |
| 1028 | |
| 1029 | nla_nest_end(args, nest); |
| 1030 | genlmsg_end(args, hdr); |
| 1031 | |
| 1032 | dump.dumpit = tipc_nl_publ_dump; |
| 1033 | dump.format = __tipc_nl_compat_publ_dump; |
| 1034 | |
| 1035 | err = __tipc_nl_compat_dumpit(&dump, msg, args); |
| 1036 | |
| 1037 | kfree_skb(args); |
| 1038 | |
| 1039 | return err; |
| 1040 | } |
| 1041 | |
| 1042 | static int tipc_nl_compat_sk_dump(struct tipc_nl_compat_msg *msg, |
| 1043 | struct nlattr **attrs) |
| 1044 | { |
| 1045 | int err; |
| 1046 | u32 sock_ref; |
| 1047 | struct nlattr *sock[TIPC_NLA_SOCK_MAX + 1]; |
| 1048 | |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 1049 | if (!attrs[TIPC_NLA_SOCK]) |
| 1050 | return -EINVAL; |
| 1051 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1052 | err = nla_parse_nested_deprecated(sock, TIPC_NLA_SOCK_MAX, |
| 1053 | attrs[TIPC_NLA_SOCK], NULL, NULL); |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 1054 | if (err) |
| 1055 | return err; |
Richard Alpe | 487d2a3 | 2015-02-09 09:50:11 +0100 | [diff] [blame] | 1056 | |
| 1057 | sock_ref = nla_get_u32(sock[TIPC_NLA_SOCK_REF]); |
| 1058 | tipc_tlv_sprintf(msg->rep, "%u:", sock_ref); |
| 1059 | |
| 1060 | if (sock[TIPC_NLA_SOCK_CON]) { |
| 1061 | u32 node; |
| 1062 | struct nlattr *con[TIPC_NLA_CON_MAX + 1]; |
| 1063 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1064 | err = nla_parse_nested_deprecated(con, TIPC_NLA_CON_MAX, |
| 1065 | sock[TIPC_NLA_SOCK_CON], |
| 1066 | NULL, NULL); |
Aditya Pakki | 89dfd00 | 2018-12-23 18:54:53 -0600 | [diff] [blame] | 1067 | |
| 1068 | if (err) |
| 1069 | return err; |
Richard Alpe | 487d2a3 | 2015-02-09 09:50:11 +0100 | [diff] [blame] | 1070 | |
| 1071 | node = nla_get_u32(con[TIPC_NLA_CON_NODE]); |
| 1072 | tipc_tlv_sprintf(msg->rep, " connected to <%u.%u.%u:%u>", |
| 1073 | tipc_zone(node), |
| 1074 | tipc_cluster(node), |
| 1075 | tipc_node(node), |
| 1076 | nla_get_u32(con[TIPC_NLA_CON_SOCK])); |
| 1077 | |
| 1078 | if (con[TIPC_NLA_CON_FLAG]) |
| 1079 | tipc_tlv_sprintf(msg->rep, " via {%u,%u}\n", |
| 1080 | nla_get_u32(con[TIPC_NLA_CON_TYPE]), |
| 1081 | nla_get_u32(con[TIPC_NLA_CON_INST])); |
| 1082 | else |
| 1083 | tipc_tlv_sprintf(msg->rep, "\n"); |
| 1084 | } else if (sock[TIPC_NLA_SOCK_HAS_PUBL]) { |
| 1085 | tipc_tlv_sprintf(msg->rep, " bound to"); |
| 1086 | |
| 1087 | err = tipc_nl_compat_publ_dump(msg, sock_ref); |
| 1088 | if (err) |
| 1089 | return err; |
| 1090 | } |
| 1091 | tipc_tlv_sprintf(msg->rep, "\n"); |
| 1092 | |
| 1093 | return 0; |
| 1094 | } |
| 1095 | |
Richard Alpe | 5bfc335 | 2015-02-09 09:50:12 +0100 | [diff] [blame] | 1096 | static int tipc_nl_compat_media_dump(struct tipc_nl_compat_msg *msg, |
| 1097 | struct nlattr **attrs) |
| 1098 | { |
| 1099 | struct nlattr *media[TIPC_NLA_MEDIA_MAX + 1]; |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 1100 | int err; |
Richard Alpe | 5bfc335 | 2015-02-09 09:50:12 +0100 | [diff] [blame] | 1101 | |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 1102 | if (!attrs[TIPC_NLA_MEDIA]) |
| 1103 | return -EINVAL; |
| 1104 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1105 | err = nla_parse_nested_deprecated(media, TIPC_NLA_MEDIA_MAX, |
| 1106 | attrs[TIPC_NLA_MEDIA], NULL, NULL); |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 1107 | if (err) |
| 1108 | return err; |
Richard Alpe | 5bfc335 | 2015-02-09 09:50:12 +0100 | [diff] [blame] | 1109 | |
| 1110 | return tipc_add_tlv(msg->rep, TIPC_TLV_MEDIA_NAME, |
| 1111 | nla_data(media[TIPC_NLA_MEDIA_NAME]), |
| 1112 | nla_len(media[TIPC_NLA_MEDIA_NAME])); |
| 1113 | } |
| 1114 | |
Richard Alpe | 4b28cb5 | 2015-02-09 09:50:13 +0100 | [diff] [blame] | 1115 | static int tipc_nl_compat_node_dump(struct tipc_nl_compat_msg *msg, |
| 1116 | struct nlattr **attrs) |
| 1117 | { |
| 1118 | struct tipc_node_info node_info; |
| 1119 | struct nlattr *node[TIPC_NLA_NODE_MAX + 1]; |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 1120 | int err; |
Richard Alpe | 4b28cb5 | 2015-02-09 09:50:13 +0100 | [diff] [blame] | 1121 | |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 1122 | if (!attrs[TIPC_NLA_NODE]) |
| 1123 | return -EINVAL; |
| 1124 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1125 | err = nla_parse_nested_deprecated(node, TIPC_NLA_NODE_MAX, |
| 1126 | attrs[TIPC_NLA_NODE], NULL, NULL); |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 1127 | if (err) |
| 1128 | return err; |
Richard Alpe | 4b28cb5 | 2015-02-09 09:50:13 +0100 | [diff] [blame] | 1129 | |
| 1130 | node_info.addr = htonl(nla_get_u32(node[TIPC_NLA_NODE_ADDR])); |
| 1131 | node_info.up = htonl(nla_get_flag(node[TIPC_NLA_NODE_UP])); |
| 1132 | |
| 1133 | return tipc_add_tlv(msg->rep, TIPC_TLV_NODE_INFO, &node_info, |
| 1134 | sizeof(node_info)); |
| 1135 | } |
| 1136 | |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 1137 | static int tipc_nl_compat_net_set(struct tipc_nl_compat_cmd_doit *cmd, |
| 1138 | struct sk_buff *skb, |
Richard Alpe | d7cc75d | 2015-02-09 09:50:14 +0100 | [diff] [blame] | 1139 | struct tipc_nl_compat_msg *msg) |
| 1140 | { |
| 1141 | u32 val; |
| 1142 | struct nlattr *net; |
| 1143 | |
| 1144 | val = ntohl(*(__be32 *)TLV_DATA(msg->req)); |
| 1145 | |
Michal Kubecek | ae0be8d | 2019-04-26 11:13:06 +0200 | [diff] [blame] | 1146 | net = nla_nest_start_noflag(skb, TIPC_NLA_NET); |
Richard Alpe | d7cc75d | 2015-02-09 09:50:14 +0100 | [diff] [blame] | 1147 | if (!net) |
| 1148 | return -EMSGSIZE; |
| 1149 | |
Richard Alpe | 964f950 | 2015-02-09 09:50:15 +0100 | [diff] [blame] | 1150 | if (msg->cmd == TIPC_CMD_SET_NODE_ADDR) { |
| 1151 | if (nla_put_u32(skb, TIPC_NLA_NET_ADDR, val)) |
| 1152 | return -EMSGSIZE; |
| 1153 | } else if (msg->cmd == TIPC_CMD_SET_NETID) { |
| 1154 | if (nla_put_u32(skb, TIPC_NLA_NET_ID, val)) |
| 1155 | return -EMSGSIZE; |
| 1156 | } |
Richard Alpe | d7cc75d | 2015-02-09 09:50:14 +0100 | [diff] [blame] | 1157 | nla_nest_end(skb, net); |
| 1158 | |
| 1159 | return 0; |
| 1160 | } |
| 1161 | |
Richard Alpe | 3c26181 | 2015-02-09 09:50:16 +0100 | [diff] [blame] | 1162 | static int tipc_nl_compat_net_dump(struct tipc_nl_compat_msg *msg, |
| 1163 | struct nlattr **attrs) |
| 1164 | { |
| 1165 | __be32 id; |
| 1166 | struct nlattr *net[TIPC_NLA_NET_MAX + 1]; |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 1167 | int err; |
Richard Alpe | 3c26181 | 2015-02-09 09:50:16 +0100 | [diff] [blame] | 1168 | |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 1169 | if (!attrs[TIPC_NLA_NET]) |
| 1170 | return -EINVAL; |
| 1171 | |
Johannes Berg | 8cb0817 | 2019-04-26 14:07:28 +0200 | [diff] [blame] | 1172 | err = nla_parse_nested_deprecated(net, TIPC_NLA_NET_MAX, |
| 1173 | attrs[TIPC_NLA_NET], NULL, NULL); |
Baozeng Ding | 297f7d2 | 2016-05-24 22:33:24 +0800 | [diff] [blame] | 1174 | if (err) |
| 1175 | return err; |
| 1176 | |
Richard Alpe | 3c26181 | 2015-02-09 09:50:16 +0100 | [diff] [blame] | 1177 | id = htonl(nla_get_u32(net[TIPC_NLA_NET_ID])); |
| 1178 | |
| 1179 | return tipc_add_tlv(msg->rep, TIPC_TLV_UNSIGNED, &id, sizeof(id)); |
| 1180 | } |
| 1181 | |
Richard Alpe | 5a81a63 | 2015-02-09 09:50:17 +0100 | [diff] [blame] | 1182 | static int tipc_cmd_show_stats_compat(struct tipc_nl_compat_msg *msg) |
| 1183 | { |
| 1184 | msg->rep = tipc_tlv_alloc(ULTRA_STRING_MAX_LEN); |
| 1185 | if (!msg->rep) |
| 1186 | return -ENOMEM; |
| 1187 | |
| 1188 | tipc_tlv_init(msg->rep, TIPC_TLV_ULTRA_STRING); |
| 1189 | tipc_tlv_sprintf(msg->rep, "TIPC version " TIPC_MOD_VER "\n"); |
| 1190 | |
| 1191 | return 0; |
| 1192 | } |
| 1193 | |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 1194 | static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg) |
| 1195 | { |
| 1196 | struct tipc_nl_compat_cmd_dump dump; |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 1197 | struct tipc_nl_compat_cmd_doit doit; |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 1198 | |
| 1199 | memset(&dump, 0, sizeof(dump)); |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 1200 | memset(&doit, 0, sizeof(doit)); |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 1201 | |
| 1202 | switch (msg->cmd) { |
Richard Alpe | 22ae7cf | 2015-02-09 09:50:18 +0100 | [diff] [blame] | 1203 | case TIPC_CMD_NOOP: |
| 1204 | msg->rep = tipc_tlv_alloc(0); |
| 1205 | if (!msg->rep) |
| 1206 | return -ENOMEM; |
| 1207 | return 0; |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 1208 | case TIPC_CMD_GET_BEARER_NAMES: |
| 1209 | msg->rep_size = MAX_BEARERS * TLV_SPACE(TIPC_MAX_BEARER_NAME); |
| 1210 | dump.dumpit = tipc_nl_bearer_dump; |
| 1211 | dump.format = tipc_nl_compat_bearer_dump; |
| 1212 | return tipc_nl_compat_dumpit(&dump, msg); |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 1213 | case TIPC_CMD_ENABLE_BEARER: |
| 1214 | msg->req_type = TIPC_TLV_BEARER_CONFIG; |
Ying Xue | ed4ffdf | 2018-02-14 13:38:04 +0800 | [diff] [blame] | 1215 | doit.doit = __tipc_nl_bearer_enable; |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 1216 | doit.transcode = tipc_nl_compat_bearer_enable; |
| 1217 | return tipc_nl_compat_doit(&doit, msg); |
| 1218 | case TIPC_CMD_DISABLE_BEARER: |
| 1219 | msg->req_type = TIPC_TLV_BEARER_NAME; |
Ying Xue | ed4ffdf | 2018-02-14 13:38:04 +0800 | [diff] [blame] | 1220 | doit.doit = __tipc_nl_bearer_disable; |
Richard Alpe | 9ab1546 | 2015-02-09 09:50:05 +0100 | [diff] [blame] | 1221 | doit.transcode = tipc_nl_compat_bearer_disable; |
| 1222 | return tipc_nl_compat_doit(&doit, msg); |
Richard Alpe | f2b3b2d | 2015-02-09 09:50:06 +0100 | [diff] [blame] | 1223 | case TIPC_CMD_SHOW_LINK_STATS: |
| 1224 | msg->req_type = TIPC_TLV_LINK_NAME; |
| 1225 | msg->rep_size = ULTRA_STRING_MAX_LEN; |
| 1226 | msg->rep_type = TIPC_TLV_ULTRA_STRING; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 1227 | dump.dumpit = tipc_nl_node_dump_link; |
Richard Alpe | f2b3b2d | 2015-02-09 09:50:06 +0100 | [diff] [blame] | 1228 | dump.format = tipc_nl_compat_link_stat_dump; |
| 1229 | return tipc_nl_compat_dumpit(&dump, msg); |
Richard Alpe | 357ebdb | 2015-02-09 09:50:07 +0100 | [diff] [blame] | 1230 | case TIPC_CMD_GET_LINKS: |
| 1231 | msg->req_type = TIPC_TLV_NET_ADDR; |
| 1232 | msg->rep_size = ULTRA_STRING_MAX_LEN; |
Jon Paul Maloy | 38206d5 | 2015-11-19 14:30:46 -0500 | [diff] [blame] | 1233 | dump.dumpit = tipc_nl_node_dump_link; |
Richard Alpe | 357ebdb | 2015-02-09 09:50:07 +0100 | [diff] [blame] | 1234 | dump.format = tipc_nl_compat_link_dump; |
| 1235 | return tipc_nl_compat_dumpit(&dump, msg); |
Richard Alpe | 37e2d48 | 2015-02-09 09:50:08 +0100 | [diff] [blame] | 1236 | case TIPC_CMD_SET_LINK_TOL: |
| 1237 | case TIPC_CMD_SET_LINK_PRI: |
| 1238 | case TIPC_CMD_SET_LINK_WINDOW: |
| 1239 | msg->req_type = TIPC_TLV_LINK_CONFIG; |
Jon Paul Maloy | 5be9c08 | 2015-11-19 14:30:45 -0500 | [diff] [blame] | 1240 | doit.doit = tipc_nl_node_set_link; |
Richard Alpe | 37e2d48 | 2015-02-09 09:50:08 +0100 | [diff] [blame] | 1241 | doit.transcode = tipc_nl_compat_link_set; |
| 1242 | return tipc_nl_compat_doit(&doit, msg); |
Richard Alpe | 1817877 | 2015-02-09 09:50:09 +0100 | [diff] [blame] | 1243 | case TIPC_CMD_RESET_LINK_STATS: |
| 1244 | msg->req_type = TIPC_TLV_LINK_NAME; |
Jon Paul Maloy | 5be9c08 | 2015-11-19 14:30:45 -0500 | [diff] [blame] | 1245 | doit.doit = tipc_nl_node_reset_link_stats; |
Richard Alpe | 1817877 | 2015-02-09 09:50:09 +0100 | [diff] [blame] | 1246 | doit.transcode = tipc_nl_compat_link_reset_stats; |
| 1247 | return tipc_nl_compat_doit(&doit, msg); |
Richard Alpe | 44a8ae9 | 2015-02-09 09:50:10 +0100 | [diff] [blame] | 1248 | case TIPC_CMD_SHOW_NAME_TABLE: |
| 1249 | msg->req_type = TIPC_TLV_NAME_TBL_QUERY; |
| 1250 | msg->rep_size = ULTRA_STRING_MAX_LEN; |
| 1251 | msg->rep_type = TIPC_TLV_ULTRA_STRING; |
| 1252 | dump.header = tipc_nl_compat_name_table_dump_header; |
| 1253 | dump.dumpit = tipc_nl_name_table_dump; |
| 1254 | dump.format = tipc_nl_compat_name_table_dump; |
| 1255 | return tipc_nl_compat_dumpit(&dump, msg); |
Richard Alpe | 487d2a3 | 2015-02-09 09:50:11 +0100 | [diff] [blame] | 1256 | case TIPC_CMD_SHOW_PORTS: |
| 1257 | msg->rep_size = ULTRA_STRING_MAX_LEN; |
| 1258 | msg->rep_type = TIPC_TLV_ULTRA_STRING; |
| 1259 | dump.dumpit = tipc_nl_sk_dump; |
| 1260 | dump.format = tipc_nl_compat_sk_dump; |
| 1261 | return tipc_nl_compat_dumpit(&dump, msg); |
Richard Alpe | 5bfc335 | 2015-02-09 09:50:12 +0100 | [diff] [blame] | 1262 | case TIPC_CMD_GET_MEDIA_NAMES: |
| 1263 | msg->rep_size = MAX_MEDIA * TLV_SPACE(TIPC_MAX_MEDIA_NAME); |
| 1264 | dump.dumpit = tipc_nl_media_dump; |
| 1265 | dump.format = tipc_nl_compat_media_dump; |
| 1266 | return tipc_nl_compat_dumpit(&dump, msg); |
Richard Alpe | 4b28cb5 | 2015-02-09 09:50:13 +0100 | [diff] [blame] | 1267 | case TIPC_CMD_GET_NODES: |
| 1268 | msg->rep_size = ULTRA_STRING_MAX_LEN; |
| 1269 | dump.dumpit = tipc_nl_node_dump; |
| 1270 | dump.format = tipc_nl_compat_node_dump; |
| 1271 | return tipc_nl_compat_dumpit(&dump, msg); |
Richard Alpe | d7cc75d | 2015-02-09 09:50:14 +0100 | [diff] [blame] | 1272 | case TIPC_CMD_SET_NODE_ADDR: |
| 1273 | msg->req_type = TIPC_TLV_NET_ADDR; |
Ying Xue | ed4ffdf | 2018-02-14 13:38:04 +0800 | [diff] [blame] | 1274 | doit.doit = __tipc_nl_net_set; |
Richard Alpe | d7cc75d | 2015-02-09 09:50:14 +0100 | [diff] [blame] | 1275 | doit.transcode = tipc_nl_compat_net_set; |
| 1276 | return tipc_nl_compat_doit(&doit, msg); |
Richard Alpe | 964f950 | 2015-02-09 09:50:15 +0100 | [diff] [blame] | 1277 | case TIPC_CMD_SET_NETID: |
| 1278 | msg->req_type = TIPC_TLV_UNSIGNED; |
Ying Xue | ed4ffdf | 2018-02-14 13:38:04 +0800 | [diff] [blame] | 1279 | doit.doit = __tipc_nl_net_set; |
Richard Alpe | 964f950 | 2015-02-09 09:50:15 +0100 | [diff] [blame] | 1280 | doit.transcode = tipc_nl_compat_net_set; |
| 1281 | return tipc_nl_compat_doit(&doit, msg); |
Richard Alpe | 3c26181 | 2015-02-09 09:50:16 +0100 | [diff] [blame] | 1282 | case TIPC_CMD_GET_NETID: |
| 1283 | msg->rep_size = sizeof(u32); |
| 1284 | dump.dumpit = tipc_nl_net_dump; |
| 1285 | dump.format = tipc_nl_compat_net_dump; |
| 1286 | return tipc_nl_compat_dumpit(&dump, msg); |
Richard Alpe | 5a81a63 | 2015-02-09 09:50:17 +0100 | [diff] [blame] | 1287 | case TIPC_CMD_SHOW_STATS: |
| 1288 | return tipc_cmd_show_stats_compat(msg); |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | return -EOPNOTSUPP; |
| 1292 | } |
| 1293 | |
| 1294 | static int tipc_nl_compat_recv(struct sk_buff *skb, struct genl_info *info) |
| 1295 | { |
| 1296 | int err; |
| 1297 | int len; |
| 1298 | struct tipc_nl_compat_msg msg; |
| 1299 | struct nlmsghdr *req_nlh; |
| 1300 | struct nlmsghdr *rep_nlh; |
| 1301 | struct tipc_genlmsghdr *req_userhdr = info->userhdr; |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 1302 | |
| 1303 | memset(&msg, 0, sizeof(msg)); |
| 1304 | |
| 1305 | req_nlh = (struct nlmsghdr *)skb->data; |
| 1306 | msg.req = nlmsg_data(req_nlh) + GENL_HDRLEN + TIPC_GENL_HDRLEN; |
| 1307 | msg.cmd = req_userhdr->cmd; |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 1308 | msg.net = genl_info_net(info); |
Florian Westphal | 619b174 | 2016-02-24 17:20:17 +0100 | [diff] [blame] | 1309 | msg.dst_sk = skb->sk; |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 1310 | |
| 1311 | if ((msg.cmd & 0xC000) && (!netlink_net_capable(skb, CAP_NET_ADMIN))) { |
| 1312 | msg.rep = tipc_get_err_tlv(TIPC_CFG_NOT_NET_ADMIN); |
| 1313 | err = -EACCES; |
| 1314 | goto send; |
| 1315 | } |
| 1316 | |
Taras Kondratiuk | 4da5f00 | 2019-07-29 22:15:07 +0000 | [diff] [blame] | 1317 | msg.req_size = nlmsg_attrlen(req_nlh, GENL_HDRLEN + TIPC_GENL_HDRLEN); |
| 1318 | if (msg.req_size && !TLV_OK(msg.req, msg.req_size)) { |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 1319 | msg.rep = tipc_get_err_tlv(TIPC_CFG_NOT_SUPPORTED); |
| 1320 | err = -EOPNOTSUPP; |
| 1321 | goto send; |
| 1322 | } |
| 1323 | |
| 1324 | err = tipc_nl_compat_handle(&msg); |
Richard Alpe | b063bc5 | 2015-05-06 13:58:56 +0200 | [diff] [blame] | 1325 | if ((err == -EOPNOTSUPP) || (err == -EPERM)) |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 1326 | msg.rep = tipc_get_err_tlv(TIPC_CFG_NOT_SUPPORTED); |
| 1327 | else if (err == -EINVAL) |
| 1328 | msg.rep = tipc_get_err_tlv(TIPC_CFG_TLV_ERROR); |
| 1329 | send: |
| 1330 | if (!msg.rep) |
| 1331 | return err; |
| 1332 | |
| 1333 | len = nlmsg_total_size(GENL_HDRLEN + TIPC_GENL_HDRLEN); |
| 1334 | skb_push(msg.rep, len); |
| 1335 | rep_nlh = nlmsg_hdr(msg.rep); |
| 1336 | memcpy(rep_nlh, info->nlhdr, len); |
| 1337 | rep_nlh->nlmsg_len = msg.rep->len; |
Richard Alpe | c3d6fb8 | 2015-05-06 13:58:54 +0200 | [diff] [blame] | 1338 | genlmsg_unicast(msg.net, msg.rep, NETLINK_CB(skb).portid); |
Richard Alpe | d0796d1 | 2015-02-09 09:50:04 +0100 | [diff] [blame] | 1339 | |
| 1340 | return err; |
| 1341 | } |
| 1342 | |
Jakub Kicinski | 66a9b92 | 2020-10-02 14:49:54 -0700 | [diff] [blame] | 1343 | static const struct genl_small_ops tipc_genl_compat_ops[] = { |
Richard Alpe | bfb3e5d | 2015-02-09 09:50:03 +0100 | [diff] [blame] | 1344 | { |
| 1345 | .cmd = TIPC_GENL_CMD, |
Johannes Berg | ef6243a | 2019-04-26 14:07:31 +0200 | [diff] [blame] | 1346 | .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, |
Richard Alpe | 22ae7cf | 2015-02-09 09:50:18 +0100 | [diff] [blame] | 1347 | .doit = tipc_nl_compat_recv, |
Richard Alpe | bfb3e5d | 2015-02-09 09:50:03 +0100 | [diff] [blame] | 1348 | }, |
| 1349 | }; |
| 1350 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 1351 | static struct genl_family tipc_genl_compat_family __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 1352 | .name = TIPC_GENL_NAME, |
| 1353 | .version = TIPC_GENL_VERSION, |
| 1354 | .hdrsize = TIPC_GENL_HDRLEN, |
| 1355 | .maxattr = 0, |
| 1356 | .netnsok = true, |
| 1357 | .module = THIS_MODULE, |
Jakub Kicinski | 66a9b92 | 2020-10-02 14:49:54 -0700 | [diff] [blame] | 1358 | .small_ops = tipc_genl_compat_ops, |
| 1359 | .n_small_ops = ARRAY_SIZE(tipc_genl_compat_ops), |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 1360 | }; |
| 1361 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 1362 | int __init tipc_netlink_compat_start(void) |
Richard Alpe | bfb3e5d | 2015-02-09 09:50:03 +0100 | [diff] [blame] | 1363 | { |
| 1364 | int res; |
| 1365 | |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 1366 | res = genl_register_family(&tipc_genl_compat_family); |
Richard Alpe | bfb3e5d | 2015-02-09 09:50:03 +0100 | [diff] [blame] | 1367 | if (res) { |
| 1368 | pr_err("Failed to register legacy compat interface\n"); |
| 1369 | return res; |
| 1370 | } |
| 1371 | |
| 1372 | return 0; |
| 1373 | } |
| 1374 | |
| 1375 | void tipc_netlink_compat_stop(void) |
| 1376 | { |
| 1377 | genl_unregister_family(&tipc_genl_compat_family); |
| 1378 | } |