1 // SPDX-License-Identifier: GPL-2.0-only 2 3 #include <net/sock.h> 4 #include <linux/ethtool_netlink.h> 5 #include <linux/pm_runtime.h> 6 #include "netlink.h" 7 #include <linux/phy_link_topology.h> 8 9 static struct genl_family ethtool_genl_family; 10 11 static bool ethnl_ok __read_mostly; 12 static u32 ethnl_bcast_seq; 13 14 #define ETHTOOL_FLAGS_BASIC (ETHTOOL_FLAG_COMPACT_BITSETS | \ 15 ETHTOOL_FLAG_OMIT_REPLY) 16 #define ETHTOOL_FLAGS_STATS (ETHTOOL_FLAGS_BASIC | ETHTOOL_FLAG_STATS) 17 18 const struct nla_policy ethnl_header_policy[] = { 19 [ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 }, 20 [ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING, 21 .len = ALTIFNAMSIZ - 1 }, 22 [ETHTOOL_A_HEADER_FLAGS] = NLA_POLICY_MASK(NLA_U32, 23 ETHTOOL_FLAGS_BASIC), 24 }; 25 26 const struct nla_policy ethnl_header_policy_stats[] = { 27 [ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 }, 28 [ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING, 29 .len = ALTIFNAMSIZ - 1 }, 30 [ETHTOOL_A_HEADER_FLAGS] = NLA_POLICY_MASK(NLA_U32, 31 ETHTOOL_FLAGS_STATS), 32 }; 33 34 const struct nla_policy ethnl_header_policy_phy[] = { 35 [ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 }, 36 [ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING, 37 .len = ALTIFNAMSIZ - 1 }, 38 [ETHTOOL_A_HEADER_FLAGS] = NLA_POLICY_MASK(NLA_U32, 39 ETHTOOL_FLAGS_BASIC), 40 [ETHTOOL_A_HEADER_PHY_INDEX] = NLA_POLICY_MIN(NLA_U32, 1), 41 }; 42 43 const struct nla_policy ethnl_header_policy_phy_stats[] = { 44 [ETHTOOL_A_HEADER_DEV_INDEX] = { .type = NLA_U32 }, 45 [ETHTOOL_A_HEADER_DEV_NAME] = { .type = NLA_NUL_STRING, 46 .len = ALTIFNAMSIZ - 1 }, 47 [ETHTOOL_A_HEADER_FLAGS] = NLA_POLICY_MASK(NLA_U32, 48 ETHTOOL_FLAGS_STATS), 49 [ETHTOOL_A_HEADER_PHY_INDEX] = NLA_POLICY_MIN(NLA_U32, 1), 50 }; 51 52 int ethnl_ops_begin(struct net_device *dev) 53 { 54 int ret; 55 56 if (!dev) 57 return -ENODEV; 58 59 if (dev->dev.parent) 60 pm_runtime_get_sync(dev->dev.parent); 61 62 if (!netif_device_present(dev) || 63 dev->reg_state == NETREG_UNREGISTERING) { 64 ret = -ENODEV; 65 goto err; 66 } 67 68 if (dev->ethtool_ops->begin) { 69 ret = dev->ethtool_ops->begin(dev); 70 if (ret) 71 goto err; 72 } 73 74 return 0; 75 err: 76 if (dev->dev.parent) 77 pm_runtime_put(dev->dev.parent); 78 79 return ret; 80 } 81 82 void ethnl_ops_complete(struct net_device *dev) 83 { 84 if (dev->ethtool_ops->complete) 85 dev->ethtool_ops->complete(dev); 86 87 if (dev->dev.parent) 88 pm_runtime_put(dev->dev.parent); 89 } 90 91 /** 92 * ethnl_parse_header_dev_get() - parse request header 93 * @req_info: structure to put results into 94 * @header: nest attribute with request header 95 * @net: request netns 96 * @extack: netlink extack for error reporting 97 * @require_dev: fail if no device identified in header 98 * 99 * Parse request header in nested attribute @nest and puts results into 100 * the structure pointed to by @req_info. Extack from @info is used for error 101 * reporting. If req_info->dev is not null on return, reference to it has 102 * been taken. If error is returned, *req_info is null initialized and no 103 * reference is held. 104 * 105 * Return: 0 on success or negative error code 106 */ 107 int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info, 108 const struct nlattr *header, struct net *net, 109 struct netlink_ext_ack *extack, bool require_dev) 110 { 111 struct nlattr *tb[ARRAY_SIZE(ethnl_header_policy_phy)]; 112 const struct nlattr *devname_attr; 113 struct phy_device *phydev = NULL; 114 struct net_device *dev = NULL; 115 u32 flags = 0; 116 int ret; 117 118 if (!header) { 119 if (!require_dev) 120 return 0; 121 NL_SET_ERR_MSG(extack, "request header missing"); 122 return -EINVAL; 123 } 124 /* No validation here, command policy should have a nested policy set 125 * for the header, therefore validation should have already been done. 126 */ 127 ret = nla_parse_nested(tb, ARRAY_SIZE(ethnl_header_policy_phy) - 1, header, 128 NULL, extack); 129 if (ret < 0) 130 return ret; 131 if (tb[ETHTOOL_A_HEADER_FLAGS]) 132 flags = nla_get_u32(tb[ETHTOOL_A_HEADER_FLAGS]); 133 134 devname_attr = tb[ETHTOOL_A_HEADER_DEV_NAME]; 135 if (tb[ETHTOOL_A_HEADER_DEV_INDEX]) { 136 u32 ifindex = nla_get_u32(tb[ETHTOOL_A_HEADER_DEV_INDEX]); 137 138 dev = netdev_get_by_index(net, ifindex, &req_info->dev_tracker, 139 GFP_KERNEL); 140 if (!dev) { 141 NL_SET_ERR_MSG_ATTR(extack, 142 tb[ETHTOOL_A_HEADER_DEV_INDEX], 143 "no device matches ifindex"); 144 return -ENODEV; 145 } 146 /* if both ifindex and ifname are passed, they must match */ 147 if (devname_attr && 148 strncmp(dev->name, nla_data(devname_attr), IFNAMSIZ)) { 149 netdev_put(dev, &req_info->dev_tracker); 150 NL_SET_ERR_MSG_ATTR(extack, header, 151 "ifindex and name do not match"); 152 return -ENODEV; 153 } 154 } else if (devname_attr) { 155 dev = netdev_get_by_name(net, nla_data(devname_attr), 156 &req_info->dev_tracker, GFP_KERNEL); 157 if (!dev) { 158 NL_SET_ERR_MSG_ATTR(extack, devname_attr, 159 "no device matches name"); 160 return -ENODEV; 161 } 162 } else if (require_dev) { 163 NL_SET_ERR_MSG_ATTR(extack, header, 164 "neither ifindex nor name specified"); 165 return -EINVAL; 166 } 167 168 if (dev) { 169 if (tb[ETHTOOL_A_HEADER_PHY_INDEX]) { 170 struct nlattr *phy_id; 171 172 phy_id = tb[ETHTOOL_A_HEADER_PHY_INDEX]; 173 phydev = phy_link_topo_get_phy(dev->link_topo, 174 nla_get_u32(phy_id)); 175 if (!phydev) { 176 NL_SET_BAD_ATTR(extack, phy_id); 177 return -ENODEV; 178 } 179 } else { 180 /* If we need a PHY but no phy index is specified, fallback 181 * to dev->phydev 182 */ 183 phydev = dev->phydev; 184 } 185 } else if (tb[ETHTOOL_A_HEADER_PHY_INDEX]) { 186 NL_SET_ERR_MSG_ATTR(extack, header, 187 "can't target a PHY without a netdev"); 188 return -EINVAL; 189 } 190 191 req_info->phydev = phydev; 192 req_info->dev = dev; 193 req_info->flags = flags; 194 return 0; 195 } 196 197 /** 198 * ethnl_fill_reply_header() - Put common header into a reply message 199 * @skb: skb with the message 200 * @dev: network device to describe in header 201 * @attrtype: attribute type to use for the nest 202 * 203 * Create a nested attribute with attributes describing given network device. 204 * 205 * Return: 0 on success, error value (-EMSGSIZE only) on error 206 */ 207 int ethnl_fill_reply_header(struct sk_buff *skb, struct net_device *dev, 208 u16 attrtype) 209 { 210 struct nlattr *nest; 211 212 if (!dev) 213 return 0; 214 nest = nla_nest_start(skb, attrtype); 215 if (!nest) 216 return -EMSGSIZE; 217 218 if (nla_put_u32(skb, ETHTOOL_A_HEADER_DEV_INDEX, (u32)dev->ifindex) || 219 nla_put_string(skb, ETHTOOL_A_HEADER_DEV_NAME, dev->name)) 220 goto nla_put_failure; 221 /* If more attributes are put into reply header, ethnl_header_size() 222 * must be updated to account for them. 223 */ 224 225 nla_nest_end(skb, nest); 226 return 0; 227 228 nla_put_failure: 229 nla_nest_cancel(skb, nest); 230 return -EMSGSIZE; 231 } 232 233 /** 234 * ethnl_reply_init() - Create skb for a reply and fill device identification 235 * @payload: payload length (without netlink and genetlink header) 236 * @dev: device the reply is about (may be null) 237 * @cmd: ETHTOOL_MSG_* message type for reply 238 * @hdr_attrtype: attribute type for common header 239 * @info: genetlink info of the received packet we respond to 240 * @ehdrp: place to store payload pointer returned by genlmsg_new() 241 * 242 * Return: pointer to allocated skb on success, NULL on error 243 */ 244 struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd, 245 u16 hdr_attrtype, struct genl_info *info, 246 void **ehdrp) 247 { 248 struct sk_buff *skb; 249 250 skb = genlmsg_new(payload, GFP_KERNEL); 251 if (!skb) 252 goto err; 253 *ehdrp = genlmsg_put_reply(skb, info, ðtool_genl_family, 0, cmd); 254 if (!*ehdrp) 255 goto err_free; 256 257 if (dev) { 258 int ret; 259 260 ret = ethnl_fill_reply_header(skb, dev, hdr_attrtype); 261 if (ret < 0) 262 goto err_free; 263 } 264 return skb; 265 266 err_free: 267 nlmsg_free(skb); 268 err: 269 if (info) 270 GENL_SET_ERR_MSG(info, "failed to setup reply message"); 271 return NULL; 272 } 273 274 void *ethnl_dump_put(struct sk_buff *skb, struct netlink_callback *cb, u8 cmd) 275 { 276 return genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, 277 ðtool_genl_family, 0, cmd); 278 } 279 280 void *ethnl_bcastmsg_put(struct sk_buff *skb, u8 cmd) 281 { 282 return genlmsg_put(skb, 0, ++ethnl_bcast_seq, ðtool_genl_family, 0, 283 cmd); 284 } 285 286 int ethnl_multicast(struct sk_buff *skb, struct net_device *dev) 287 { 288 return genlmsg_multicast_netns(ðtool_genl_family, dev_net(dev), skb, 289 0, ETHNL_MCGRP_MONITOR, GFP_KERNEL); 290 } 291 292 /* GET request helpers */ 293 294 /** 295 * struct ethnl_dump_ctx - context structure for generic dumpit() callback 296 * @ops: request ops of currently processed message type 297 * @req_info: parsed request header of processed request 298 * @reply_data: data needed to compose the reply 299 * @pos_ifindex: saved iteration position - ifindex 300 * 301 * These parameters are kept in struct netlink_callback as context preserved 302 * between iterations. They are initialized by ethnl_default_start() and used 303 * in ethnl_default_dumpit() and ethnl_default_done(). 304 */ 305 struct ethnl_dump_ctx { 306 const struct ethnl_request_ops *ops; 307 struct ethnl_req_info *req_info; 308 struct ethnl_reply_data *reply_data; 309 unsigned long pos_ifindex; 310 }; 311 312 static const struct ethnl_request_ops * 313 ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { 314 [ETHTOOL_MSG_STRSET_GET] = ðnl_strset_request_ops, 315 [ETHTOOL_MSG_LINKINFO_GET] = ðnl_linkinfo_request_ops, 316 [ETHTOOL_MSG_LINKINFO_SET] = ðnl_linkinfo_request_ops, 317 [ETHTOOL_MSG_LINKMODES_GET] = ðnl_linkmodes_request_ops, 318 [ETHTOOL_MSG_LINKMODES_SET] = ðnl_linkmodes_request_ops, 319 [ETHTOOL_MSG_LINKSTATE_GET] = ðnl_linkstate_request_ops, 320 [ETHTOOL_MSG_DEBUG_GET] = ðnl_debug_request_ops, 321 [ETHTOOL_MSG_DEBUG_SET] = ðnl_debug_request_ops, 322 [ETHTOOL_MSG_WOL_GET] = ðnl_wol_request_ops, 323 [ETHTOOL_MSG_WOL_SET] = ðnl_wol_request_ops, 324 [ETHTOOL_MSG_FEATURES_GET] = ðnl_features_request_ops, 325 [ETHTOOL_MSG_PRIVFLAGS_GET] = ðnl_privflags_request_ops, 326 [ETHTOOL_MSG_PRIVFLAGS_SET] = ðnl_privflags_request_ops, 327 [ETHTOOL_MSG_RINGS_GET] = ðnl_rings_request_ops, 328 [ETHTOOL_MSG_RINGS_SET] = ðnl_rings_request_ops, 329 [ETHTOOL_MSG_CHANNELS_GET] = ðnl_channels_request_ops, 330 [ETHTOOL_MSG_CHANNELS_SET] = ðnl_channels_request_ops, 331 [ETHTOOL_MSG_COALESCE_GET] = ðnl_coalesce_request_ops, 332 [ETHTOOL_MSG_COALESCE_SET] = ðnl_coalesce_request_ops, 333 [ETHTOOL_MSG_PAUSE_GET] = ðnl_pause_request_ops, 334 [ETHTOOL_MSG_PAUSE_SET] = ðnl_pause_request_ops, 335 [ETHTOOL_MSG_EEE_GET] = ðnl_eee_request_ops, 336 [ETHTOOL_MSG_EEE_SET] = ðnl_eee_request_ops, 337 [ETHTOOL_MSG_FEC_GET] = ðnl_fec_request_ops, 338 [ETHTOOL_MSG_FEC_SET] = ðnl_fec_request_ops, 339 [ETHTOOL_MSG_TSINFO_GET] = ðnl_tsinfo_request_ops, 340 [ETHTOOL_MSG_MODULE_EEPROM_GET] = ðnl_module_eeprom_request_ops, 341 [ETHTOOL_MSG_STATS_GET] = ðnl_stats_request_ops, 342 [ETHTOOL_MSG_PHC_VCLOCKS_GET] = ðnl_phc_vclocks_request_ops, 343 [ETHTOOL_MSG_MODULE_GET] = ðnl_module_request_ops, 344 [ETHTOOL_MSG_MODULE_SET] = ðnl_module_request_ops, 345 [ETHTOOL_MSG_PSE_GET] = ðnl_pse_request_ops, 346 [ETHTOOL_MSG_PSE_SET] = ðnl_pse_request_ops, 347 [ETHTOOL_MSG_RSS_GET] = ðnl_rss_request_ops, 348 [ETHTOOL_MSG_PLCA_GET_CFG] = ðnl_plca_cfg_request_ops, 349 [ETHTOOL_MSG_PLCA_SET_CFG] = ðnl_plca_cfg_request_ops, 350 [ETHTOOL_MSG_PLCA_GET_STATUS] = ðnl_plca_status_request_ops, 351 [ETHTOOL_MSG_MM_GET] = ðnl_mm_request_ops, 352 [ETHTOOL_MSG_MM_SET] = ðnl_mm_request_ops, 353 }; 354 355 static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb) 356 { 357 return (struct ethnl_dump_ctx *)cb->ctx; 358 } 359 360 /** 361 * ethnl_default_parse() - Parse request message 362 * @req_info: pointer to structure to put data into 363 * @info: genl_info from the request 364 * @request_ops: struct request_ops for request type 365 * @require_dev: fail if no device identified in header 366 * 367 * Parse universal request header and call request specific ->parse_request() 368 * callback (if defined) to parse the rest of the message. 369 * 370 * Return: 0 on success or negative error code 371 */ 372 static int ethnl_default_parse(struct ethnl_req_info *req_info, 373 const struct genl_info *info, 374 const struct ethnl_request_ops *request_ops, 375 bool require_dev) 376 { 377 struct nlattr **tb = info->attrs; 378 int ret; 379 380 ret = ethnl_parse_header_dev_get(req_info, tb[request_ops->hdr_attr], 381 genl_info_net(info), info->extack, 382 require_dev); 383 if (ret < 0) 384 return ret; 385 386 if (request_ops->parse_request) { 387 ret = request_ops->parse_request(req_info, tb, info->extack); 388 if (ret < 0) 389 return ret; 390 } 391 392 return 0; 393 } 394 395 /** 396 * ethnl_init_reply_data() - Initialize reply data for GET request 397 * @reply_data: pointer to embedded struct ethnl_reply_data 398 * @ops: instance of struct ethnl_request_ops describing the layout 399 * @dev: network device to initialize the reply for 400 * 401 * Fills the reply data part with zeros and sets the dev member. Must be called 402 * before calling the ->fill_reply() callback (for each iteration when handling 403 * dump requests). 404 */ 405 static void ethnl_init_reply_data(struct ethnl_reply_data *reply_data, 406 const struct ethnl_request_ops *ops, 407 struct net_device *dev) 408 { 409 memset(reply_data, 0, ops->reply_data_size); 410 reply_data->dev = dev; 411 } 412 413 /* default ->doit() handler for GET type requests */ 414 static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info) 415 { 416 struct ethnl_reply_data *reply_data = NULL; 417 struct ethnl_req_info *req_info = NULL; 418 const u8 cmd = info->genlhdr->cmd; 419 const struct ethnl_request_ops *ops; 420 int hdr_len, reply_len; 421 struct sk_buff *rskb; 422 void *reply_payload; 423 int ret; 424 425 ops = ethnl_default_requests[cmd]; 426 if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", cmd)) 427 return -EOPNOTSUPP; 428 if (GENL_REQ_ATTR_CHECK(info, ops->hdr_attr)) 429 return -EINVAL; 430 431 req_info = kzalloc(ops->req_info_size, GFP_KERNEL); 432 if (!req_info) 433 return -ENOMEM; 434 reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL); 435 if (!reply_data) { 436 kfree(req_info); 437 return -ENOMEM; 438 } 439 440 ret = ethnl_default_parse(req_info, info, ops, !ops->allow_nodev_do); 441 if (ret < 0) 442 goto err_dev; 443 ethnl_init_reply_data(reply_data, ops, req_info->dev); 444 445 rtnl_lock(); 446 ret = ops->prepare_data(req_info, reply_data, info); 447 rtnl_unlock(); 448 if (ret < 0) 449 goto err_cleanup; 450 ret = ops->reply_size(req_info, reply_data); 451 if (ret < 0) 452 goto err_cleanup; 453 reply_len = ret; 454 ret = -ENOMEM; 455 rskb = ethnl_reply_init(reply_len + ethnl_reply_header_size(), 456 req_info->dev, ops->reply_cmd, 457 ops->hdr_attr, info, &reply_payload); 458 if (!rskb) 459 goto err_cleanup; 460 hdr_len = rskb->len; 461 ret = ops->fill_reply(rskb, req_info, reply_data); 462 if (ret < 0) 463 goto err_msg; 464 WARN_ONCE(rskb->len - hdr_len > reply_len, 465 "ethnl cmd %d: calculated reply length %d, but consumed %d\n", 466 cmd, reply_len, rskb->len - hdr_len); 467 if (ops->cleanup_data) 468 ops->cleanup_data(reply_data); 469 470 genlmsg_end(rskb, reply_payload); 471 netdev_put(req_info->dev, &req_info->dev_tracker); 472 kfree(reply_data); 473 kfree(req_info); 474 return genlmsg_reply(rskb, info); 475 476 err_msg: 477 WARN_ONCE(ret == -EMSGSIZE, "calculated message payload length (%d) not sufficient\n", reply_len); 478 nlmsg_free(rskb); 479 err_cleanup: 480 if (ops->cleanup_data) 481 ops->cleanup_data(reply_data); 482 err_dev: 483 netdev_put(req_info->dev, &req_info->dev_tracker); 484 kfree(reply_data); 485 kfree(req_info); 486 return ret; 487 } 488 489 static int ethnl_default_dump_one(struct sk_buff *skb, struct net_device *dev, 490 const struct ethnl_dump_ctx *ctx, 491 const struct genl_info *info) 492 { 493 void *ehdr; 494 int ret; 495 496 ehdr = genlmsg_put(skb, info->snd_portid, info->snd_seq, 497 ðtool_genl_family, NLM_F_MULTI, 498 ctx->ops->reply_cmd); 499 if (!ehdr) 500 return -EMSGSIZE; 501 502 ethnl_init_reply_data(ctx->reply_data, ctx->ops, dev); 503 rtnl_lock(); 504 ret = ctx->ops->prepare_data(ctx->req_info, ctx->reply_data, info); 505 rtnl_unlock(); 506 if (ret < 0) 507 goto out; 508 ret = ethnl_fill_reply_header(skb, dev, ctx->ops->hdr_attr); 509 if (ret < 0) 510 goto out; 511 ret = ctx->ops->fill_reply(skb, ctx->req_info, ctx->reply_data); 512 513 out: 514 if (ctx->ops->cleanup_data) 515 ctx->ops->cleanup_data(ctx->reply_data); 516 ctx->reply_data->dev = NULL; 517 if (ret < 0) 518 genlmsg_cancel(skb, ehdr); 519 else 520 genlmsg_end(skb, ehdr); 521 return ret; 522 } 523 524 /* Default ->dumpit() handler for GET requests. */ 525 static int ethnl_default_dumpit(struct sk_buff *skb, 526 struct netlink_callback *cb) 527 { 528 struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb); 529 struct net *net = sock_net(skb->sk); 530 struct net_device *dev; 531 int ret = 0; 532 533 rcu_read_lock(); 534 for_each_netdev_dump(net, dev, ctx->pos_ifindex) { 535 dev_hold(dev); 536 rcu_read_unlock(); 537 538 ret = ethnl_default_dump_one(skb, dev, ctx, genl_info_dump(cb)); 539 540 rcu_read_lock(); 541 dev_put(dev); 542 543 if (ret < 0 && ret != -EOPNOTSUPP) { 544 if (likely(skb->len)) 545 ret = skb->len; 546 break; 547 } 548 ret = 0; 549 } 550 rcu_read_unlock(); 551 552 return ret; 553 } 554 555 /* generic ->start() handler for GET requests */ 556 static int ethnl_default_start(struct netlink_callback *cb) 557 { 558 const struct genl_dumpit_info *info = genl_dumpit_info(cb); 559 struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb); 560 struct ethnl_reply_data *reply_data; 561 const struct ethnl_request_ops *ops; 562 struct ethnl_req_info *req_info; 563 struct genlmsghdr *ghdr; 564 int ret; 565 566 BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx)); 567 568 ghdr = nlmsg_data(cb->nlh); 569 ops = ethnl_default_requests[ghdr->cmd]; 570 if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", ghdr->cmd)) 571 return -EOPNOTSUPP; 572 req_info = kzalloc(ops->req_info_size, GFP_KERNEL); 573 if (!req_info) 574 return -ENOMEM; 575 reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL); 576 if (!reply_data) { 577 ret = -ENOMEM; 578 goto free_req_info; 579 } 580 581 ret = ethnl_default_parse(req_info, &info->info, ops, false); 582 if (req_info->dev) { 583 /* We ignore device specification in dump requests but as the 584 * same parser as for non-dump (doit) requests is used, it 585 * would take reference to the device if it finds one 586 */ 587 netdev_put(req_info->dev, &req_info->dev_tracker); 588 req_info->dev = NULL; 589 } 590 if (ret < 0) 591 goto free_reply_data; 592 593 ctx->ops = ops; 594 ctx->req_info = req_info; 595 ctx->reply_data = reply_data; 596 ctx->pos_ifindex = 0; 597 598 return 0; 599 600 free_reply_data: 601 kfree(reply_data); 602 free_req_info: 603 kfree(req_info); 604 605 return ret; 606 } 607 608 /* default ->done() handler for GET requests */ 609 static int ethnl_default_done(struct netlink_callback *cb) 610 { 611 struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb); 612 613 kfree(ctx->reply_data); 614 kfree(ctx->req_info); 615 616 return 0; 617 } 618 619 static int ethnl_default_set_doit(struct sk_buff *skb, struct genl_info *info) 620 { 621 const struct ethnl_request_ops *ops; 622 struct ethnl_req_info req_info = {}; 623 const u8 cmd = info->genlhdr->cmd; 624 int ret; 625 626 ops = ethnl_default_requests[cmd]; 627 if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", cmd)) 628 return -EOPNOTSUPP; 629 if (GENL_REQ_ATTR_CHECK(info, ops->hdr_attr)) 630 return -EINVAL; 631 632 ret = ethnl_parse_header_dev_get(&req_info, info->attrs[ops->hdr_attr], 633 genl_info_net(info), info->extack, 634 true); 635 if (ret < 0) 636 return ret; 637 638 if (ops->set_validate) { 639 ret = ops->set_validate(&req_info, info); 640 /* 0 means nothing to do */ 641 if (ret <= 0) 642 goto out_dev; 643 } 644 645 rtnl_lock(); 646 ret = ethnl_ops_begin(req_info.dev); 647 if (ret < 0) 648 goto out_rtnl; 649 650 ret = ops->set(&req_info, info); 651 if (ret <= 0) 652 goto out_ops; 653 ethtool_notify(req_info.dev, ops->set_ntf_cmd, NULL); 654 655 ret = 0; 656 out_ops: 657 ethnl_ops_complete(req_info.dev); 658 out_rtnl: 659 rtnl_unlock(); 660 out_dev: 661 ethnl_parse_header_dev_put(&req_info); 662 return ret; 663 } 664 665 static const struct ethnl_request_ops * 666 ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX + 1] = { 667 [ETHTOOL_MSG_LINKINFO_NTF] = ðnl_linkinfo_request_ops, 668 [ETHTOOL_MSG_LINKMODES_NTF] = ðnl_linkmodes_request_ops, 669 [ETHTOOL_MSG_DEBUG_NTF] = ðnl_debug_request_ops, 670 [ETHTOOL_MSG_WOL_NTF] = ðnl_wol_request_ops, 671 [ETHTOOL_MSG_FEATURES_NTF] = ðnl_features_request_ops, 672 [ETHTOOL_MSG_PRIVFLAGS_NTF] = ðnl_privflags_request_ops, 673 [ETHTOOL_MSG_RINGS_NTF] = ðnl_rings_request_ops, 674 [ETHTOOL_MSG_CHANNELS_NTF] = ðnl_channels_request_ops, 675 [ETHTOOL_MSG_COALESCE_NTF] = ðnl_coalesce_request_ops, 676 [ETHTOOL_MSG_PAUSE_NTF] = ðnl_pause_request_ops, 677 [ETHTOOL_MSG_EEE_NTF] = ðnl_eee_request_ops, 678 [ETHTOOL_MSG_FEC_NTF] = ðnl_fec_request_ops, 679 [ETHTOOL_MSG_MODULE_NTF] = ðnl_module_request_ops, 680 [ETHTOOL_MSG_PLCA_NTF] = ðnl_plca_cfg_request_ops, 681 [ETHTOOL_MSG_MM_NTF] = ðnl_mm_request_ops, 682 }; 683 684 /* default notification handler */ 685 static void ethnl_default_notify(struct net_device *dev, unsigned int cmd, 686 const void *data) 687 { 688 struct ethnl_reply_data *reply_data; 689 const struct ethnl_request_ops *ops; 690 struct ethnl_req_info *req_info; 691 struct genl_info info; 692 struct sk_buff *skb; 693 void *reply_payload; 694 int reply_len; 695 int ret; 696 697 genl_info_init_ntf(&info, ðtool_genl_family, cmd); 698 699 if (WARN_ONCE(cmd > ETHTOOL_MSG_KERNEL_MAX || 700 !ethnl_default_notify_ops[cmd], 701 "unexpected notification type %u\n", cmd)) 702 return; 703 ops = ethnl_default_notify_ops[cmd]; 704 req_info = kzalloc(ops->req_info_size, GFP_KERNEL); 705 if (!req_info) 706 return; 707 reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL); 708 if (!reply_data) { 709 kfree(req_info); 710 return; 711 } 712 713 req_info->dev = dev; 714 req_info->flags |= ETHTOOL_FLAG_COMPACT_BITSETS; 715 716 ethnl_init_reply_data(reply_data, ops, dev); 717 ret = ops->prepare_data(req_info, reply_data, &info); 718 if (ret < 0) 719 goto err_cleanup; 720 ret = ops->reply_size(req_info, reply_data); 721 if (ret < 0) 722 goto err_cleanup; 723 reply_len = ret + ethnl_reply_header_size(); 724 skb = genlmsg_new(reply_len, GFP_KERNEL); 725 if (!skb) 726 goto err_cleanup; 727 reply_payload = ethnl_bcastmsg_put(skb, cmd); 728 if (!reply_payload) 729 goto err_skb; 730 ret = ethnl_fill_reply_header(skb, dev, ops->hdr_attr); 731 if (ret < 0) 732 goto err_msg; 733 ret = ops->fill_reply(skb, req_info, reply_data); 734 if (ret < 0) 735 goto err_msg; 736 if (ops->cleanup_data) 737 ops->cleanup_data(reply_data); 738 739 genlmsg_end(skb, reply_payload); 740 kfree(reply_data); 741 kfree(req_info); 742 ethnl_multicast(skb, dev); 743 return; 744 745 err_msg: 746 WARN_ONCE(ret == -EMSGSIZE, 747 "calculated message payload length (%d) not sufficient\n", 748 reply_len); 749 err_skb: 750 nlmsg_free(skb); 751 err_cleanup: 752 if (ops->cleanup_data) 753 ops->cleanup_data(reply_data); 754 kfree(reply_data); 755 kfree(req_info); 756 return; 757 } 758 759 /* notifications */ 760 761 typedef void (*ethnl_notify_handler_t)(struct net_device *dev, unsigned int cmd, 762 const void *data); 763 764 static const ethnl_notify_handler_t ethnl_notify_handlers[] = { 765 [ETHTOOL_MSG_LINKINFO_NTF] = ethnl_default_notify, 766 [ETHTOOL_MSG_LINKMODES_NTF] = ethnl_default_notify, 767 [ETHTOOL_MSG_DEBUG_NTF] = ethnl_default_notify, 768 [ETHTOOL_MSG_WOL_NTF] = ethnl_default_notify, 769 [ETHTOOL_MSG_FEATURES_NTF] = ethnl_default_notify, 770 [ETHTOOL_MSG_PRIVFLAGS_NTF] = ethnl_default_notify, 771 [ETHTOOL_MSG_RINGS_NTF] = ethnl_default_notify, 772 [ETHTOOL_MSG_CHANNELS_NTF] = ethnl_default_notify, 773 [ETHTOOL_MSG_COALESCE_NTF] = ethnl_default_notify, 774 [ETHTOOL_MSG_PAUSE_NTF] = ethnl_default_notify, 775 [ETHTOOL_MSG_EEE_NTF] = ethnl_default_notify, 776 [ETHTOOL_MSG_FEC_NTF] = ethnl_default_notify, 777 [ETHTOOL_MSG_MODULE_NTF] = ethnl_default_notify, 778 [ETHTOOL_MSG_PLCA_NTF] = ethnl_default_notify, 779 [ETHTOOL_MSG_MM_NTF] = ethnl_default_notify, 780 }; 781 782 void ethtool_notify(struct net_device *dev, unsigned int cmd, const void *data) 783 { 784 if (unlikely(!ethnl_ok)) 785 return; 786 ASSERT_RTNL(); 787 788 if (likely(cmd < ARRAY_SIZE(ethnl_notify_handlers) && 789 ethnl_notify_handlers[cmd])) 790 ethnl_notify_handlers[cmd](dev, cmd, data); 791 else 792 WARN_ONCE(1, "notification %u not implemented (dev=%s)\n", 793 cmd, netdev_name(dev)); 794 } 795 EXPORT_SYMBOL(ethtool_notify); 796 797 static void ethnl_notify_features(struct netdev_notifier_info *info) 798 { 799 struct net_device *dev = netdev_notifier_info_to_dev(info); 800 801 ethtool_notify(dev, ETHTOOL_MSG_FEATURES_NTF, NULL); 802 } 803 804 static int ethnl_netdev_event(struct notifier_block *this, unsigned long event, 805 void *ptr) 806 { 807 switch (event) { 808 case NETDEV_FEAT_CHANGE: 809 ethnl_notify_features(ptr); 810 break; 811 } 812 813 return NOTIFY_DONE; 814 } 815 816 static struct notifier_block ethnl_netdev_notifier = { 817 .notifier_call = ethnl_netdev_event, 818 }; 819 820 /* genetlink setup */ 821 822 static const struct genl_ops ethtool_genl_ops[] = { 823 { 824 .cmd = ETHTOOL_MSG_STRSET_GET, 825 .doit = ethnl_default_doit, 826 .start = ethnl_default_start, 827 .dumpit = ethnl_default_dumpit, 828 .done = ethnl_default_done, 829 .policy = ethnl_strset_get_policy, 830 .maxattr = ARRAY_SIZE(ethnl_strset_get_policy) - 1, 831 }, 832 { 833 .cmd = ETHTOOL_MSG_LINKINFO_GET, 834 .doit = ethnl_default_doit, 835 .start = ethnl_default_start, 836 .dumpit = ethnl_default_dumpit, 837 .done = ethnl_default_done, 838 .policy = ethnl_linkinfo_get_policy, 839 .maxattr = ARRAY_SIZE(ethnl_linkinfo_get_policy) - 1, 840 }, 841 { 842 .cmd = ETHTOOL_MSG_LINKINFO_SET, 843 .flags = GENL_UNS_ADMIN_PERM, 844 .doit = ethnl_default_set_doit, 845 .policy = ethnl_linkinfo_set_policy, 846 .maxattr = ARRAY_SIZE(ethnl_linkinfo_set_policy) - 1, 847 }, 848 { 849 .cmd = ETHTOOL_MSG_LINKMODES_GET, 850 .doit = ethnl_default_doit, 851 .start = ethnl_default_start, 852 .dumpit = ethnl_default_dumpit, 853 .done = ethnl_default_done, 854 .policy = ethnl_linkmodes_get_policy, 855 .maxattr = ARRAY_SIZE(ethnl_linkmodes_get_policy) - 1, 856 }, 857 { 858 .cmd = ETHTOOL_MSG_LINKMODES_SET, 859 .flags = GENL_UNS_ADMIN_PERM, 860 .doit = ethnl_default_set_doit, 861 .policy = ethnl_linkmodes_set_policy, 862 .maxattr = ARRAY_SIZE(ethnl_linkmodes_set_policy) - 1, 863 }, 864 { 865 .cmd = ETHTOOL_MSG_LINKSTATE_GET, 866 .doit = ethnl_default_doit, 867 .start = ethnl_default_start, 868 .dumpit = ethnl_default_dumpit, 869 .done = ethnl_default_done, 870 .policy = ethnl_linkstate_get_policy, 871 .maxattr = ARRAY_SIZE(ethnl_linkstate_get_policy) - 1, 872 }, 873 { 874 .cmd = ETHTOOL_MSG_DEBUG_GET, 875 .doit = ethnl_default_doit, 876 .start = ethnl_default_start, 877 .dumpit = ethnl_default_dumpit, 878 .done = ethnl_default_done, 879 .policy = ethnl_debug_get_policy, 880 .maxattr = ARRAY_SIZE(ethnl_debug_get_policy) - 1, 881 }, 882 { 883 .cmd = ETHTOOL_MSG_DEBUG_SET, 884 .flags = GENL_UNS_ADMIN_PERM, 885 .doit = ethnl_default_set_doit, 886 .policy = ethnl_debug_set_policy, 887 .maxattr = ARRAY_SIZE(ethnl_debug_set_policy) - 1, 888 }, 889 { 890 .cmd = ETHTOOL_MSG_WOL_GET, 891 .flags = GENL_UNS_ADMIN_PERM, 892 .doit = ethnl_default_doit, 893 .start = ethnl_default_start, 894 .dumpit = ethnl_default_dumpit, 895 .done = ethnl_default_done, 896 .policy = ethnl_wol_get_policy, 897 .maxattr = ARRAY_SIZE(ethnl_wol_get_policy) - 1, 898 }, 899 { 900 .cmd = ETHTOOL_MSG_WOL_SET, 901 .flags = GENL_UNS_ADMIN_PERM, 902 .doit = ethnl_default_set_doit, 903 .policy = ethnl_wol_set_policy, 904 .maxattr = ARRAY_SIZE(ethnl_wol_set_policy) - 1, 905 }, 906 { 907 .cmd = ETHTOOL_MSG_FEATURES_GET, 908 .doit = ethnl_default_doit, 909 .start = ethnl_default_start, 910 .dumpit = ethnl_default_dumpit, 911 .done = ethnl_default_done, 912 .policy = ethnl_features_get_policy, 913 .maxattr = ARRAY_SIZE(ethnl_features_get_policy) - 1, 914 }, 915 { 916 .cmd = ETHTOOL_MSG_FEATURES_SET, 917 .flags = GENL_UNS_ADMIN_PERM, 918 .doit = ethnl_set_features, 919 .policy = ethnl_features_set_policy, 920 .maxattr = ARRAY_SIZE(ethnl_features_set_policy) - 1, 921 }, 922 { 923 .cmd = ETHTOOL_MSG_PRIVFLAGS_GET, 924 .doit = ethnl_default_doit, 925 .start = ethnl_default_start, 926 .dumpit = ethnl_default_dumpit, 927 .done = ethnl_default_done, 928 .policy = ethnl_privflags_get_policy, 929 .maxattr = ARRAY_SIZE(ethnl_privflags_get_policy) - 1, 930 }, 931 { 932 .cmd = ETHTOOL_MSG_PRIVFLAGS_SET, 933 .flags = GENL_UNS_ADMIN_PERM, 934 .doit = ethnl_default_set_doit, 935 .policy = ethnl_privflags_set_policy, 936 .maxattr = ARRAY_SIZE(ethnl_privflags_set_policy) - 1, 937 }, 938 { 939 .cmd = ETHTOOL_MSG_RINGS_GET, 940 .doit = ethnl_default_doit, 941 .start = ethnl_default_start, 942 .dumpit = ethnl_default_dumpit, 943 .done = ethnl_default_done, 944 .policy = ethnl_rings_get_policy, 945 .maxattr = ARRAY_SIZE(ethnl_rings_get_policy) - 1, 946 }, 947 { 948 .cmd = ETHTOOL_MSG_RINGS_SET, 949 .flags = GENL_UNS_ADMIN_PERM, 950 .doit = ethnl_default_set_doit, 951 .policy = ethnl_rings_set_policy, 952 .maxattr = ARRAY_SIZE(ethnl_rings_set_policy) - 1, 953 }, 954 { 955 .cmd = ETHTOOL_MSG_CHANNELS_GET, 956 .doit = ethnl_default_doit, 957 .start = ethnl_default_start, 958 .dumpit = ethnl_default_dumpit, 959 .done = ethnl_default_done, 960 .policy = ethnl_channels_get_policy, 961 .maxattr = ARRAY_SIZE(ethnl_channels_get_policy) - 1, 962 }, 963 { 964 .cmd = ETHTOOL_MSG_CHANNELS_SET, 965 .flags = GENL_UNS_ADMIN_PERM, 966 .doit = ethnl_default_set_doit, 967 .policy = ethnl_channels_set_policy, 968 .maxattr = ARRAY_SIZE(ethnl_channels_set_policy) - 1, 969 }, 970 { 971 .cmd = ETHTOOL_MSG_COALESCE_GET, 972 .doit = ethnl_default_doit, 973 .start = ethnl_default_start, 974 .dumpit = ethnl_default_dumpit, 975 .done = ethnl_default_done, 976 .policy = ethnl_coalesce_get_policy, 977 .maxattr = ARRAY_SIZE(ethnl_coalesce_get_policy) - 1, 978 }, 979 { 980 .cmd = ETHTOOL_MSG_COALESCE_SET, 981 .flags = GENL_UNS_ADMIN_PERM, 982 .doit = ethnl_default_set_doit, 983 .policy = ethnl_coalesce_set_policy, 984 .maxattr = ARRAY_SIZE(ethnl_coalesce_set_policy) - 1, 985 }, 986 { 987 .cmd = ETHTOOL_MSG_PAUSE_GET, 988 .doit = ethnl_default_doit, 989 .start = ethnl_default_start, 990 .dumpit = ethnl_default_dumpit, 991 .done = ethnl_default_done, 992 .policy = ethnl_pause_get_policy, 993 .maxattr = ARRAY_SIZE(ethnl_pause_get_policy) - 1, 994 }, 995 { 996 .cmd = ETHTOOL_MSG_PAUSE_SET, 997 .flags = GENL_UNS_ADMIN_PERM, 998 .doit = ethnl_default_set_doit, 999 .policy = ethnl_pause_set_policy, 1000 .maxattr = ARRAY_SIZE(ethnl_pause_set_policy) - 1, 1001 }, 1002 { 1003 .cmd = ETHTOOL_MSG_EEE_GET, 1004 .doit = ethnl_default_doit, 1005 .start = ethnl_default_start, 1006 .dumpit = ethnl_default_dumpit, 1007 .done = ethnl_default_done, 1008 .policy = ethnl_eee_get_policy, 1009 .maxattr = ARRAY_SIZE(ethnl_eee_get_policy) - 1, 1010 }, 1011 { 1012 .cmd = ETHTOOL_MSG_EEE_SET, 1013 .flags = GENL_UNS_ADMIN_PERM, 1014 .doit = ethnl_default_set_doit, 1015 .policy = ethnl_eee_set_policy, 1016 .maxattr = ARRAY_SIZE(ethnl_eee_set_policy) - 1, 1017 }, 1018 { 1019 .cmd = ETHTOOL_MSG_TSINFO_GET, 1020 .doit = ethnl_default_doit, 1021 .start = ethnl_default_start, 1022 .dumpit = ethnl_default_dumpit, 1023 .done = ethnl_default_done, 1024 .policy = ethnl_tsinfo_get_policy, 1025 .maxattr = ARRAY_SIZE(ethnl_tsinfo_get_policy) - 1, 1026 }, 1027 { 1028 .cmd = ETHTOOL_MSG_CABLE_TEST_ACT, 1029 .flags = GENL_UNS_ADMIN_PERM, 1030 .doit = ethnl_act_cable_test, 1031 .policy = ethnl_cable_test_act_policy, 1032 .maxattr = ARRAY_SIZE(ethnl_cable_test_act_policy) - 1, 1033 }, 1034 { 1035 .cmd = ETHTOOL_MSG_CABLE_TEST_TDR_ACT, 1036 .flags = GENL_UNS_ADMIN_PERM, 1037 .doit = ethnl_act_cable_test_tdr, 1038 .policy = ethnl_cable_test_tdr_act_policy, 1039 .maxattr = ARRAY_SIZE(ethnl_cable_test_tdr_act_policy) - 1, 1040 }, 1041 { 1042 .cmd = ETHTOOL_MSG_TUNNEL_INFO_GET, 1043 .doit = ethnl_tunnel_info_doit, 1044 .start = ethnl_tunnel_info_start, 1045 .dumpit = ethnl_tunnel_info_dumpit, 1046 .policy = ethnl_tunnel_info_get_policy, 1047 .maxattr = ARRAY_SIZE(ethnl_tunnel_info_get_policy) - 1, 1048 }, 1049 { 1050 .cmd = ETHTOOL_MSG_FEC_GET, 1051 .doit = ethnl_default_doit, 1052 .start = ethnl_default_start, 1053 .dumpit = ethnl_default_dumpit, 1054 .done = ethnl_default_done, 1055 .policy = ethnl_fec_get_policy, 1056 .maxattr = ARRAY_SIZE(ethnl_fec_get_policy) - 1, 1057 }, 1058 { 1059 .cmd = ETHTOOL_MSG_FEC_SET, 1060 .flags = GENL_UNS_ADMIN_PERM, 1061 .doit = ethnl_default_set_doit, 1062 .policy = ethnl_fec_set_policy, 1063 .maxattr = ARRAY_SIZE(ethnl_fec_set_policy) - 1, 1064 }, 1065 { 1066 .cmd = ETHTOOL_MSG_MODULE_EEPROM_GET, 1067 .flags = GENL_UNS_ADMIN_PERM, 1068 .doit = ethnl_default_doit, 1069 .start = ethnl_default_start, 1070 .dumpit = ethnl_default_dumpit, 1071 .done = ethnl_default_done, 1072 .policy = ethnl_module_eeprom_get_policy, 1073 .maxattr = ARRAY_SIZE(ethnl_module_eeprom_get_policy) - 1, 1074 }, 1075 { 1076 .cmd = ETHTOOL_MSG_STATS_GET, 1077 .doit = ethnl_default_doit, 1078 .start = ethnl_default_start, 1079 .dumpit = ethnl_default_dumpit, 1080 .done = ethnl_default_done, 1081 .policy = ethnl_stats_get_policy, 1082 .maxattr = ARRAY_SIZE(ethnl_stats_get_policy) - 1, 1083 }, 1084 { 1085 .cmd = ETHTOOL_MSG_PHC_VCLOCKS_GET, 1086 .doit = ethnl_default_doit, 1087 .start = ethnl_default_start, 1088 .dumpit = ethnl_default_dumpit, 1089 .done = ethnl_default_done, 1090 .policy = ethnl_phc_vclocks_get_policy, 1091 .maxattr = ARRAY_SIZE(ethnl_phc_vclocks_get_policy) - 1, 1092 }, 1093 { 1094 .cmd = ETHTOOL_MSG_MODULE_GET, 1095 .doit = ethnl_default_doit, 1096 .start = ethnl_default_start, 1097 .dumpit = ethnl_default_dumpit, 1098 .done = ethnl_default_done, 1099 .policy = ethnl_module_get_policy, 1100 .maxattr = ARRAY_SIZE(ethnl_module_get_policy) - 1, 1101 }, 1102 { 1103 .cmd = ETHTOOL_MSG_MODULE_SET, 1104 .flags = GENL_UNS_ADMIN_PERM, 1105 .doit = ethnl_default_set_doit, 1106 .policy = ethnl_module_set_policy, 1107 .maxattr = ARRAY_SIZE(ethnl_module_set_policy) - 1, 1108 }, 1109 { 1110 .cmd = ETHTOOL_MSG_PSE_GET, 1111 .doit = ethnl_default_doit, 1112 .start = ethnl_default_start, 1113 .dumpit = ethnl_default_dumpit, 1114 .done = ethnl_default_done, 1115 .policy = ethnl_pse_get_policy, 1116 .maxattr = ARRAY_SIZE(ethnl_pse_get_policy) - 1, 1117 }, 1118 { 1119 .cmd = ETHTOOL_MSG_PSE_SET, 1120 .flags = GENL_UNS_ADMIN_PERM, 1121 .doit = ethnl_default_set_doit, 1122 .policy = ethnl_pse_set_policy, 1123 .maxattr = ARRAY_SIZE(ethnl_pse_set_policy) - 1, 1124 }, 1125 { 1126 .cmd = ETHTOOL_MSG_RSS_GET, 1127 .doit = ethnl_default_doit, 1128 .policy = ethnl_rss_get_policy, 1129 .maxattr = ARRAY_SIZE(ethnl_rss_get_policy) - 1, 1130 }, 1131 { 1132 .cmd = ETHTOOL_MSG_PLCA_GET_CFG, 1133 .doit = ethnl_default_doit, 1134 .start = ethnl_default_start, 1135 .dumpit = ethnl_default_dumpit, 1136 .done = ethnl_default_done, 1137 .policy = ethnl_plca_get_cfg_policy, 1138 .maxattr = ARRAY_SIZE(ethnl_plca_get_cfg_policy) - 1, 1139 }, 1140 { 1141 .cmd = ETHTOOL_MSG_PLCA_SET_CFG, 1142 .flags = GENL_UNS_ADMIN_PERM, 1143 .doit = ethnl_default_set_doit, 1144 .policy = ethnl_plca_set_cfg_policy, 1145 .maxattr = ARRAY_SIZE(ethnl_plca_set_cfg_policy) - 1, 1146 }, 1147 { 1148 .cmd = ETHTOOL_MSG_PLCA_GET_STATUS, 1149 .doit = ethnl_default_doit, 1150 .start = ethnl_default_start, 1151 .dumpit = ethnl_default_dumpit, 1152 .done = ethnl_default_done, 1153 .policy = ethnl_plca_get_status_policy, 1154 .maxattr = ARRAY_SIZE(ethnl_plca_get_status_policy) - 1, 1155 }, 1156 { 1157 .cmd = ETHTOOL_MSG_MM_GET, 1158 .doit = ethnl_default_doit, 1159 .start = ethnl_default_start, 1160 .dumpit = ethnl_default_dumpit, 1161 .done = ethnl_default_done, 1162 .policy = ethnl_mm_get_policy, 1163 .maxattr = ARRAY_SIZE(ethnl_mm_get_policy) - 1, 1164 }, 1165 { 1166 .cmd = ETHTOOL_MSG_MM_SET, 1167 .flags = GENL_UNS_ADMIN_PERM, 1168 .doit = ethnl_default_set_doit, 1169 .policy = ethnl_mm_set_policy, 1170 .maxattr = ARRAY_SIZE(ethnl_mm_set_policy) - 1, 1171 }, 1172 }; 1173 1174 static const struct genl_multicast_group ethtool_nl_mcgrps[] = { 1175 [ETHNL_MCGRP_MONITOR] = { .name = ETHTOOL_MCGRP_MONITOR_NAME }, 1176 }; 1177 1178 static struct genl_family ethtool_genl_family __ro_after_init = { 1179 .name = ETHTOOL_GENL_NAME, 1180 .version = ETHTOOL_GENL_VERSION, 1181 .netnsok = true, 1182 .parallel_ops = true, 1183 .ops = ethtool_genl_ops, 1184 .n_ops = ARRAY_SIZE(ethtool_genl_ops), 1185 .resv_start_op = ETHTOOL_MSG_MODULE_GET + 1, 1186 .mcgrps = ethtool_nl_mcgrps, 1187 .n_mcgrps = ARRAY_SIZE(ethtool_nl_mcgrps), 1188 }; 1189 1190 /* module setup */ 1191 1192 static int __init ethnl_init(void) 1193 { 1194 int ret; 1195 1196 ret = genl_register_family(ðtool_genl_family); 1197 if (WARN(ret < 0, "ethtool: genetlink family registration failed")) 1198 return ret; 1199 ethnl_ok = true; 1200 1201 ret = register_netdevice_notifier(ðnl_netdev_notifier); 1202 WARN(ret < 0, "ethtool: net device notifier registration failed"); 1203 return ret; 1204 } 1205 1206 subsys_initcall(ethnl_init); 1207