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