1 // SPDX-License-Identifier: GPL-2.0-only 2 3 #include <net/sock.h> 4 #include <linux/ethtool_netlink.h> 5 #include "netlink.h" 6 7 static struct genl_family ethtool_genl_family; 8 9 static bool ethnl_ok __read_mostly; 10 static u32 ethnl_bcast_seq; 11 12 static const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_MAX + 1] = { 13 [ETHTOOL_A_HEADER_UNSPEC] = { .type = NLA_REJECT }, 14 [ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 }, 15 [ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING, 16 .len = ALTIFNAMSIZ - 1 }, 17 [ETHTOOL_A_HEADER_FLAGS] = { .type = NLA_U32 }, 18 }; 19 20 /** 21 * ethnl_parse_header() - parse request header 22 * @req_info: structure to put results into 23 * @header: nest attribute with request header 24 * @net: request netns 25 * @extack: netlink extack for error reporting 26 * @require_dev: fail if no device identified in header 27 * 28 * Parse request header in nested attribute @nest and puts results into 29 * the structure pointed to by @req_info. Extack from @info is used for error 30 * reporting. If req_info->dev is not null on return, reference to it has 31 * been taken. If error is returned, *req_info is null initialized and no 32 * reference is held. 33 * 34 * Return: 0 on success or negative error code 35 */ 36 int ethnl_parse_header(struct ethnl_req_info *req_info, 37 const struct nlattr *header, struct net *net, 38 struct netlink_ext_ack *extack, bool require_dev) 39 { 40 struct nlattr *tb[ETHTOOL_A_HEADER_MAX + 1]; 41 const struct nlattr *devname_attr; 42 struct net_device *dev = NULL; 43 int ret; 44 45 if (!header) { 46 NL_SET_ERR_MSG(extack, "request header missing"); 47 return -EINVAL; 48 } 49 ret = nla_parse_nested(tb, ETHTOOL_A_HEADER_MAX, header, 50 ethnl_header_policy, extack); 51 if (ret < 0) 52 return ret; 53 devname_attr = tb[ETHTOOL_A_HEADER_DEV_NAME]; 54 55 if (tb[ETHTOOL_A_HEADER_DEV_INDEX]) { 56 u32 ifindex = nla_get_u32(tb[ETHTOOL_A_HEADER_DEV_INDEX]); 57 58 dev = dev_get_by_index(net, ifindex); 59 if (!dev) { 60 NL_SET_ERR_MSG_ATTR(extack, 61 tb[ETHTOOL_A_HEADER_DEV_INDEX], 62 "no device matches ifindex"); 63 return -ENODEV; 64 } 65 /* if both ifindex and ifname are passed, they must match */ 66 if (devname_attr && 67 strncmp(dev->name, nla_data(devname_attr), IFNAMSIZ)) { 68 dev_put(dev); 69 NL_SET_ERR_MSG_ATTR(extack, header, 70 "ifindex and name do not match"); 71 return -ENODEV; 72 } 73 } else if (devname_attr) { 74 dev = dev_get_by_name(net, nla_data(devname_attr)); 75 if (!dev) { 76 NL_SET_ERR_MSG_ATTR(extack, devname_attr, 77 "no device matches name"); 78 return -ENODEV; 79 } 80 } else if (require_dev) { 81 NL_SET_ERR_MSG_ATTR(extack, header, 82 "neither ifindex nor name specified"); 83 return -EINVAL; 84 } 85 86 if (dev && !netif_device_present(dev)) { 87 dev_put(dev); 88 NL_SET_ERR_MSG(extack, "device not present"); 89 return -ENODEV; 90 } 91 92 req_info->dev = dev; 93 if (tb[ETHTOOL_A_HEADER_FLAGS]) 94 req_info->flags = nla_get_u32(tb[ETHTOOL_A_HEADER_FLAGS]); 95 96 return 0; 97 } 98 99 /** 100 * ethnl_fill_reply_header() - Put common header into a reply message 101 * @skb: skb with the message 102 * @dev: network device to describe in header 103 * @attrtype: attribute type to use for the nest 104 * 105 * Create a nested attribute with attributes describing given network device. 106 * 107 * Return: 0 on success, error value (-EMSGSIZE only) on error 108 */ 109 int ethnl_fill_reply_header(struct sk_buff *skb, struct net_device *dev, 110 u16 attrtype) 111 { 112 struct nlattr *nest; 113 114 if (!dev) 115 return 0; 116 nest = nla_nest_start(skb, attrtype); 117 if (!nest) 118 return -EMSGSIZE; 119 120 if (nla_put_u32(skb, ETHTOOL_A_HEADER_DEV_INDEX, (u32)dev->ifindex) || 121 nla_put_string(skb, ETHTOOL_A_HEADER_DEV_NAME, dev->name)) 122 goto nla_put_failure; 123 /* If more attributes are put into reply header, ethnl_header_size() 124 * must be updated to account for them. 125 */ 126 127 nla_nest_end(skb, nest); 128 return 0; 129 130 nla_put_failure: 131 nla_nest_cancel(skb, nest); 132 return -EMSGSIZE; 133 } 134 135 /** 136 * ethnl_reply_init() - Create skb for a reply and fill device identification 137 * @payload: payload length (without netlink and genetlink header) 138 * @dev: device the reply is about (may be null) 139 * @cmd: ETHTOOL_MSG_* message type for reply 140 * @info: genetlink info of the received packet we respond to 141 * @ehdrp: place to store payload pointer returned by genlmsg_new() 142 * 143 * Return: pointer to allocated skb on success, NULL on error 144 */ 145 struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd, 146 u16 hdr_attrtype, struct genl_info *info, 147 void **ehdrp) 148 { 149 struct sk_buff *skb; 150 151 skb = genlmsg_new(payload, GFP_KERNEL); 152 if (!skb) 153 goto err; 154 *ehdrp = genlmsg_put_reply(skb, info, ðtool_genl_family, 0, cmd); 155 if (!*ehdrp) 156 goto err_free; 157 158 if (dev) { 159 int ret; 160 161 ret = ethnl_fill_reply_header(skb, dev, hdr_attrtype); 162 if (ret < 0) 163 goto err_free; 164 } 165 return skb; 166 167 err_free: 168 nlmsg_free(skb); 169 err: 170 if (info) 171 GENL_SET_ERR_MSG(info, "failed to setup reply message"); 172 return NULL; 173 } 174 175 static void *ethnl_bcastmsg_put(struct sk_buff *skb, u8 cmd) 176 { 177 return genlmsg_put(skb, 0, ++ethnl_bcast_seq, ðtool_genl_family, 0, 178 cmd); 179 } 180 181 static int ethnl_multicast(struct sk_buff *skb, struct net_device *dev) 182 { 183 return genlmsg_multicast_netns(ðtool_genl_family, dev_net(dev), skb, 184 0, ETHNL_MCGRP_MONITOR, GFP_KERNEL); 185 } 186 187 /* GET request helpers */ 188 189 /** 190 * struct ethnl_dump_ctx - context structure for generic dumpit() callback 191 * @ops: request ops of currently processed message type 192 * @req_info: parsed request header of processed request 193 * @pos_hash: saved iteration position - hashbucket 194 * @pos_idx: saved iteration position - index 195 * 196 * These parameters are kept in struct netlink_callback as context preserved 197 * between iterations. They are initialized by ethnl_default_start() and used 198 * in ethnl_default_dumpit() and ethnl_default_done(). 199 */ 200 struct ethnl_dump_ctx { 201 const struct ethnl_request_ops *ops; 202 struct ethnl_req_info *req_info; 203 struct ethnl_reply_data *reply_data; 204 int pos_hash; 205 int pos_idx; 206 }; 207 208 static const struct ethnl_request_ops * 209 ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { 210 [ETHTOOL_MSG_STRSET_GET] = ðnl_strset_request_ops, 211 [ETHTOOL_MSG_LINKINFO_GET] = ðnl_linkinfo_request_ops, 212 [ETHTOOL_MSG_LINKMODES_GET] = ðnl_linkmodes_request_ops, 213 [ETHTOOL_MSG_LINKSTATE_GET] = ðnl_linkstate_request_ops, 214 }; 215 216 static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb) 217 { 218 return (struct ethnl_dump_ctx *)cb->ctx; 219 } 220 221 /** 222 * ethnl_default_parse() - Parse request message 223 * @req_info: pointer to structure to put data into 224 * @nlhdr: pointer to request message header 225 * @net: request netns 226 * @request_ops: struct request_ops for request type 227 * @extack: netlink extack for error reporting 228 * @require_dev: fail if no device identified in header 229 * 230 * Parse universal request header and call request specific ->parse_request() 231 * callback (if defined) to parse the rest of the message. 232 * 233 * Return: 0 on success or negative error code 234 */ 235 static int ethnl_default_parse(struct ethnl_req_info *req_info, 236 const struct nlmsghdr *nlhdr, struct net *net, 237 const struct ethnl_request_ops *request_ops, 238 struct netlink_ext_ack *extack, bool require_dev) 239 { 240 struct nlattr **tb; 241 int ret; 242 243 tb = kmalloc_array(request_ops->max_attr + 1, sizeof(tb[0]), 244 GFP_KERNEL); 245 if (!tb) 246 return -ENOMEM; 247 248 ret = nlmsg_parse(nlhdr, GENL_HDRLEN, tb, request_ops->max_attr, 249 request_ops->request_policy, extack); 250 if (ret < 0) 251 goto out; 252 ret = ethnl_parse_header(req_info, tb[request_ops->hdr_attr], net, 253 extack, require_dev); 254 if (ret < 0) 255 goto out; 256 257 if (request_ops->parse_request) { 258 ret = request_ops->parse_request(req_info, tb, extack); 259 if (ret < 0) 260 goto out; 261 } 262 263 ret = 0; 264 out: 265 kfree(tb); 266 return ret; 267 } 268 269 /** 270 * ethnl_init_reply_data() - Initialize reply data for GET request 271 * @req_info: pointer to embedded struct ethnl_req_info 272 * @ops: instance of struct ethnl_request_ops describing the layout 273 * @dev: network device to initialize the reply for 274 * 275 * Fills the reply data part with zeros and sets the dev member. Must be called 276 * before calling the ->fill_reply() callback (for each iteration when handling 277 * dump requests). 278 */ 279 static void ethnl_init_reply_data(struct ethnl_reply_data *reply_data, 280 const struct ethnl_request_ops *ops, 281 struct net_device *dev) 282 { 283 memset(reply_data, 0, ops->reply_data_size); 284 reply_data->dev = dev; 285 } 286 287 /* default ->doit() handler for GET type requests */ 288 static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info) 289 { 290 struct ethnl_reply_data *reply_data = NULL; 291 struct ethnl_req_info *req_info = NULL; 292 const u8 cmd = info->genlhdr->cmd; 293 const struct ethnl_request_ops *ops; 294 struct sk_buff *rskb; 295 void *reply_payload; 296 int reply_len; 297 int ret; 298 299 ops = ethnl_default_requests[cmd]; 300 if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", cmd)) 301 return -EOPNOTSUPP; 302 req_info = kzalloc(ops->req_info_size, GFP_KERNEL); 303 if (!req_info) 304 return -ENOMEM; 305 reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL); 306 if (!reply_data) { 307 kfree(req_info); 308 return -ENOMEM; 309 } 310 311 ret = ethnl_default_parse(req_info, info->nlhdr, genl_info_net(info), ops, 312 info->extack, !ops->allow_nodev_do); 313 if (ret < 0) 314 goto err_dev; 315 ethnl_init_reply_data(reply_data, ops, req_info->dev); 316 317 rtnl_lock(); 318 ret = ops->prepare_data(req_info, reply_data, info); 319 rtnl_unlock(); 320 if (ret < 0) 321 goto err_cleanup; 322 ret = ops->reply_size(req_info, reply_data); 323 if (ret < 0) 324 goto err_cleanup; 325 reply_len = ret; 326 ret = -ENOMEM; 327 rskb = ethnl_reply_init(reply_len, req_info->dev, ops->reply_cmd, 328 ops->hdr_attr, info, &reply_payload); 329 if (!rskb) 330 goto err_cleanup; 331 ret = ops->fill_reply(rskb, req_info, reply_data); 332 if (ret < 0) 333 goto err_msg; 334 if (ops->cleanup_data) 335 ops->cleanup_data(reply_data); 336 337 genlmsg_end(rskb, reply_payload); 338 if (req_info->dev) 339 dev_put(req_info->dev); 340 kfree(reply_data); 341 kfree(req_info); 342 return genlmsg_reply(rskb, info); 343 344 err_msg: 345 WARN_ONCE(ret == -EMSGSIZE, "calculated message payload length (%d) not sufficient\n", reply_len); 346 nlmsg_free(rskb); 347 err_cleanup: 348 if (ops->cleanup_data) 349 ops->cleanup_data(reply_data); 350 err_dev: 351 if (req_info->dev) 352 dev_put(req_info->dev); 353 kfree(reply_data); 354 kfree(req_info); 355 return ret; 356 } 357 358 static int ethnl_default_dump_one(struct sk_buff *skb, struct net_device *dev, 359 const struct ethnl_dump_ctx *ctx) 360 { 361 int ret; 362 363 ethnl_init_reply_data(ctx->reply_data, ctx->ops, dev); 364 rtnl_lock(); 365 ret = ctx->ops->prepare_data(ctx->req_info, ctx->reply_data, NULL); 366 rtnl_unlock(); 367 if (ret < 0) 368 goto out; 369 ret = ethnl_fill_reply_header(skb, dev, ctx->ops->hdr_attr); 370 if (ret < 0) 371 goto out; 372 ret = ctx->ops->fill_reply(skb, ctx->req_info, ctx->reply_data); 373 374 out: 375 if (ctx->ops->cleanup_data) 376 ctx->ops->cleanup_data(ctx->reply_data); 377 ctx->reply_data->dev = NULL; 378 return ret; 379 } 380 381 /* Default ->dumpit() handler for GET requests. Device iteration copied from 382 * rtnl_dump_ifinfo(); we have to be more careful about device hashtable 383 * persistence as we cannot guarantee to hold RTNL lock through the whole 384 * function as rtnetnlink does. 385 */ 386 static int ethnl_default_dumpit(struct sk_buff *skb, 387 struct netlink_callback *cb) 388 { 389 struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb); 390 struct net *net = sock_net(skb->sk); 391 int s_idx = ctx->pos_idx; 392 int h, idx = 0; 393 int ret = 0; 394 void *ehdr; 395 396 rtnl_lock(); 397 for (h = ctx->pos_hash; h < NETDEV_HASHENTRIES; h++, s_idx = 0) { 398 struct hlist_head *head; 399 struct net_device *dev; 400 unsigned int seq; 401 402 head = &net->dev_index_head[h]; 403 404 restart_chain: 405 seq = net->dev_base_seq; 406 cb->seq = seq; 407 idx = 0; 408 hlist_for_each_entry(dev, head, index_hlist) { 409 if (idx < s_idx) 410 goto cont; 411 dev_hold(dev); 412 rtnl_unlock(); 413 414 ehdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, 415 cb->nlh->nlmsg_seq, 416 ðtool_genl_family, 0, 417 ctx->ops->reply_cmd); 418 if (!ehdr) { 419 dev_put(dev); 420 ret = -EMSGSIZE; 421 goto out; 422 } 423 ret = ethnl_default_dump_one(skb, dev, ctx); 424 dev_put(dev); 425 if (ret < 0) { 426 genlmsg_cancel(skb, ehdr); 427 if (ret == -EOPNOTSUPP) 428 goto lock_and_cont; 429 if (likely(skb->len)) 430 ret = skb->len; 431 goto out; 432 } 433 genlmsg_end(skb, ehdr); 434 lock_and_cont: 435 rtnl_lock(); 436 if (net->dev_base_seq != seq) { 437 s_idx = idx + 1; 438 goto restart_chain; 439 } 440 cont: 441 idx++; 442 } 443 444 } 445 rtnl_unlock(); 446 447 out: 448 ctx->pos_hash = h; 449 ctx->pos_idx = idx; 450 nl_dump_check_consistent(cb, nlmsg_hdr(skb)); 451 452 return ret; 453 } 454 455 /* generic ->start() handler for GET requests */ 456 static int ethnl_default_start(struct netlink_callback *cb) 457 { 458 struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb); 459 struct ethnl_reply_data *reply_data; 460 const struct ethnl_request_ops *ops; 461 struct ethnl_req_info *req_info; 462 struct genlmsghdr *ghdr; 463 int ret; 464 465 BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx)); 466 467 ghdr = nlmsg_data(cb->nlh); 468 ops = ethnl_default_requests[ghdr->cmd]; 469 if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", ghdr->cmd)) 470 return -EOPNOTSUPP; 471 req_info = kzalloc(ops->req_info_size, GFP_KERNEL); 472 if (!req_info) 473 return -ENOMEM; 474 reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL); 475 if (!reply_data) { 476 ret = -ENOMEM; 477 goto free_req_info; 478 } 479 480 ret = ethnl_default_parse(req_info, cb->nlh, sock_net(cb->skb->sk), ops, 481 cb->extack, false); 482 if (req_info->dev) { 483 /* We ignore device specification in dump requests but as the 484 * same parser as for non-dump (doit) requests is used, it 485 * would take reference to the device if it finds one 486 */ 487 dev_put(req_info->dev); 488 req_info->dev = NULL; 489 } 490 if (ret < 0) 491 goto free_reply_data; 492 493 ctx->ops = ops; 494 ctx->req_info = req_info; 495 ctx->reply_data = reply_data; 496 ctx->pos_hash = 0; 497 ctx->pos_idx = 0; 498 499 return 0; 500 501 free_reply_data: 502 kfree(reply_data); 503 free_req_info: 504 kfree(req_info); 505 506 return ret; 507 } 508 509 /* default ->done() handler for GET requests */ 510 static int ethnl_default_done(struct netlink_callback *cb) 511 { 512 struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb); 513 514 kfree(ctx->reply_data); 515 kfree(ctx->req_info); 516 517 return 0; 518 } 519 520 static const struct ethnl_request_ops * 521 ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX + 1] = { 522 [ETHTOOL_MSG_LINKINFO_NTF] = ðnl_linkinfo_request_ops, 523 [ETHTOOL_MSG_LINKMODES_NTF] = ðnl_linkmodes_request_ops, 524 }; 525 526 /* default notification handler */ 527 static void ethnl_default_notify(struct net_device *dev, unsigned int cmd, 528 const void *data) 529 { 530 struct ethnl_reply_data *reply_data; 531 const struct ethnl_request_ops *ops; 532 struct ethnl_req_info *req_info; 533 struct sk_buff *skb; 534 void *reply_payload; 535 int reply_len; 536 int ret; 537 538 if (WARN_ONCE(cmd > ETHTOOL_MSG_KERNEL_MAX || 539 !ethnl_default_notify_ops[cmd], 540 "unexpected notification type %u\n", cmd)) 541 return; 542 ops = ethnl_default_notify_ops[cmd]; 543 req_info = kzalloc(ops->req_info_size, GFP_KERNEL); 544 if (!req_info) 545 return; 546 reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL); 547 if (!reply_data) { 548 kfree(req_info); 549 return; 550 } 551 552 req_info->dev = dev; 553 req_info->flags |= ETHTOOL_FLAG_COMPACT_BITSETS; 554 555 ethnl_init_reply_data(reply_data, ops, dev); 556 ret = ops->prepare_data(req_info, reply_data, NULL); 557 if (ret < 0) 558 goto err_cleanup; 559 ret = ops->reply_size(req_info, reply_data); 560 if (ret < 0) 561 goto err_cleanup; 562 reply_len = ret; 563 ret = -ENOMEM; 564 skb = genlmsg_new(reply_len, GFP_KERNEL); 565 if (!skb) 566 goto err_cleanup; 567 reply_payload = ethnl_bcastmsg_put(skb, cmd); 568 if (!reply_payload) 569 goto err_skb; 570 ret = ethnl_fill_reply_header(skb, dev, ops->hdr_attr); 571 if (ret < 0) 572 goto err_msg; 573 ret = ops->fill_reply(skb, req_info, reply_data); 574 if (ret < 0) 575 goto err_msg; 576 if (ops->cleanup_data) 577 ops->cleanup_data(reply_data); 578 579 genlmsg_end(skb, reply_payload); 580 kfree(reply_data); 581 kfree(req_info); 582 ethnl_multicast(skb, dev); 583 return; 584 585 err_msg: 586 WARN_ONCE(ret == -EMSGSIZE, 587 "calculated message payload length (%d) not sufficient\n", 588 reply_len); 589 err_skb: 590 nlmsg_free(skb); 591 err_cleanup: 592 if (ops->cleanup_data) 593 ops->cleanup_data(reply_data); 594 kfree(reply_data); 595 kfree(req_info); 596 return; 597 } 598 599 /* notifications */ 600 601 typedef void (*ethnl_notify_handler_t)(struct net_device *dev, unsigned int cmd, 602 const void *data); 603 604 static const ethnl_notify_handler_t ethnl_notify_handlers[] = { 605 [ETHTOOL_MSG_LINKINFO_NTF] = ethnl_default_notify, 606 [ETHTOOL_MSG_LINKMODES_NTF] = ethnl_default_notify, 607 }; 608 609 void ethtool_notify(struct net_device *dev, unsigned int cmd, const void *data) 610 { 611 if (unlikely(!ethnl_ok)) 612 return; 613 ASSERT_RTNL(); 614 615 if (likely(cmd < ARRAY_SIZE(ethnl_notify_handlers) && 616 ethnl_notify_handlers[cmd])) 617 ethnl_notify_handlers[cmd](dev, cmd, data); 618 else 619 WARN_ONCE(1, "notification %u not implemented (dev=%s)\n", 620 cmd, netdev_name(dev)); 621 } 622 EXPORT_SYMBOL(ethtool_notify); 623 624 /* genetlink setup */ 625 626 static const struct genl_ops ethtool_genl_ops[] = { 627 { 628 .cmd = ETHTOOL_MSG_STRSET_GET, 629 .doit = ethnl_default_doit, 630 .start = ethnl_default_start, 631 .dumpit = ethnl_default_dumpit, 632 .done = ethnl_default_done, 633 }, 634 { 635 .cmd = ETHTOOL_MSG_LINKINFO_GET, 636 .doit = ethnl_default_doit, 637 .start = ethnl_default_start, 638 .dumpit = ethnl_default_dumpit, 639 .done = ethnl_default_done, 640 }, 641 { 642 .cmd = ETHTOOL_MSG_LINKINFO_SET, 643 .flags = GENL_UNS_ADMIN_PERM, 644 .doit = ethnl_set_linkinfo, 645 }, 646 { 647 .cmd = ETHTOOL_MSG_LINKMODES_GET, 648 .doit = ethnl_default_doit, 649 .start = ethnl_default_start, 650 .dumpit = ethnl_default_dumpit, 651 .done = ethnl_default_done, 652 }, 653 { 654 .cmd = ETHTOOL_MSG_LINKMODES_SET, 655 .flags = GENL_UNS_ADMIN_PERM, 656 .doit = ethnl_set_linkmodes, 657 }, 658 { 659 .cmd = ETHTOOL_MSG_LINKSTATE_GET, 660 .doit = ethnl_default_doit, 661 .start = ethnl_default_start, 662 .dumpit = ethnl_default_dumpit, 663 .done = ethnl_default_done, 664 }, 665 }; 666 667 static const struct genl_multicast_group ethtool_nl_mcgrps[] = { 668 [ETHNL_MCGRP_MONITOR] = { .name = ETHTOOL_MCGRP_MONITOR_NAME }, 669 }; 670 671 static struct genl_family ethtool_genl_family = { 672 .name = ETHTOOL_GENL_NAME, 673 .version = ETHTOOL_GENL_VERSION, 674 .netnsok = true, 675 .parallel_ops = true, 676 .ops = ethtool_genl_ops, 677 .n_ops = ARRAY_SIZE(ethtool_genl_ops), 678 .mcgrps = ethtool_nl_mcgrps, 679 .n_mcgrps = ARRAY_SIZE(ethtool_nl_mcgrps), 680 }; 681 682 /* module setup */ 683 684 static int __init ethnl_init(void) 685 { 686 int ret; 687 688 ret = genl_register_family(ðtool_genl_family); 689 if (WARN(ret < 0, "ethtool: genetlink family registration failed")) 690 return ret; 691 ethnl_ok = true; 692 693 return 0; 694 } 695 696 subsys_initcall(ethnl_init); 697