1 // SPDX-License-Identifier: GPL-2.0-only
4 #include <linux/ethtool_netlink.h>
7 static struct genl_family ethtool_genl_family;
9 static bool ethnl_ok __read_mostly;
10 static u32 ethnl_bcast_seq;
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 },
21 * ethnl_parse_header_dev_get() - parse request header
22 * @req_info: structure to put results into
23 * @header: nest attribute with request header
25 * @extack: netlink extack for error reporting
26 * @require_dev: fail if no device identified in header
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
34 * Return: 0 on success or negative error code
36 int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,
37 const struct nlattr *header, struct net *net,
38 struct netlink_ext_ack *extack, bool require_dev)
40 struct nlattr *tb[ETHTOOL_A_HEADER_MAX + 1];
41 const struct nlattr *devname_attr;
42 struct net_device *dev = NULL;
47 NL_SET_ERR_MSG(extack, "request header missing");
50 ret = nla_parse_nested(tb, ETHTOOL_A_HEADER_MAX, header,
51 ethnl_header_policy, extack);
54 if (tb[ETHTOOL_A_HEADER_FLAGS]) {
55 flags = nla_get_u32(tb[ETHTOOL_A_HEADER_FLAGS]);
56 if (flags & ~ETHTOOL_FLAG_ALL) {
57 NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_HEADER_FLAGS],
58 "unrecognized request flags");
59 nl_set_extack_cookie_u32(extack, ETHTOOL_FLAG_ALL);
64 devname_attr = tb[ETHTOOL_A_HEADER_DEV_NAME];
65 if (tb[ETHTOOL_A_HEADER_DEV_INDEX]) {
66 u32 ifindex = nla_get_u32(tb[ETHTOOL_A_HEADER_DEV_INDEX]);
68 dev = dev_get_by_index(net, ifindex);
70 NL_SET_ERR_MSG_ATTR(extack,
71 tb[ETHTOOL_A_HEADER_DEV_INDEX],
72 "no device matches ifindex");
75 /* if both ifindex and ifname are passed, they must match */
77 strncmp(dev->name, nla_data(devname_attr), IFNAMSIZ)) {
79 NL_SET_ERR_MSG_ATTR(extack, header,
80 "ifindex and name do not match");
83 } else if (devname_attr) {
84 dev = dev_get_by_name(net, nla_data(devname_attr));
86 NL_SET_ERR_MSG_ATTR(extack, devname_attr,
87 "no device matches name");
90 } else if (require_dev) {
91 NL_SET_ERR_MSG_ATTR(extack, header,
92 "neither ifindex nor name specified");
96 if (dev && !netif_device_present(dev)) {
98 NL_SET_ERR_MSG(extack, "device not present");
103 req_info->flags = flags;
108 * ethnl_fill_reply_header() - Put common header into a reply message
109 * @skb: skb with the message
110 * @dev: network device to describe in header
111 * @attrtype: attribute type to use for the nest
113 * Create a nested attribute with attributes describing given network device.
115 * Return: 0 on success, error value (-EMSGSIZE only) on error
117 int ethnl_fill_reply_header(struct sk_buff *skb, struct net_device *dev,
124 nest = nla_nest_start(skb, attrtype);
128 if (nla_put_u32(skb, ETHTOOL_A_HEADER_DEV_INDEX, (u32)dev->ifindex) ||
129 nla_put_string(skb, ETHTOOL_A_HEADER_DEV_NAME, dev->name))
130 goto nla_put_failure;
131 /* If more attributes are put into reply header, ethnl_header_size()
132 * must be updated to account for them.
135 nla_nest_end(skb, nest);
139 nla_nest_cancel(skb, nest);
144 * ethnl_reply_init() - Create skb for a reply and fill device identification
145 * @payload: payload length (without netlink and genetlink header)
146 * @dev: device the reply is about (may be null)
147 * @cmd: ETHTOOL_MSG_* message type for reply
148 * @hdr_attrtype: attribute type for common header
149 * @info: genetlink info of the received packet we respond to
150 * @ehdrp: place to store payload pointer returned by genlmsg_new()
152 * Return: pointer to allocated skb on success, NULL on error
154 struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd,
155 u16 hdr_attrtype, struct genl_info *info,
160 skb = genlmsg_new(payload, GFP_KERNEL);
163 *ehdrp = genlmsg_put_reply(skb, info, ðtool_genl_family, 0, cmd);
170 ret = ethnl_fill_reply_header(skb, dev, hdr_attrtype);
180 GENL_SET_ERR_MSG(info, "failed to setup reply message");
184 static void *ethnl_bcastmsg_put(struct sk_buff *skb, u8 cmd)
186 return genlmsg_put(skb, 0, ++ethnl_bcast_seq, ðtool_genl_family, 0,
190 static int ethnl_multicast(struct sk_buff *skb, struct net_device *dev)
192 return genlmsg_multicast_netns(ðtool_genl_family, dev_net(dev), skb,
193 0, ETHNL_MCGRP_MONITOR, GFP_KERNEL);
196 /* GET request helpers */
199 * struct ethnl_dump_ctx - context structure for generic dumpit() callback
200 * @ops: request ops of currently processed message type
201 * @req_info: parsed request header of processed request
202 * @reply_data: data needed to compose the reply
203 * @pos_hash: saved iteration position - hashbucket
204 * @pos_idx: saved iteration position - index
206 * These parameters are kept in struct netlink_callback as context preserved
207 * between iterations. They are initialized by ethnl_default_start() and used
208 * in ethnl_default_dumpit() and ethnl_default_done().
210 struct ethnl_dump_ctx {
211 const struct ethnl_request_ops *ops;
212 struct ethnl_req_info *req_info;
213 struct ethnl_reply_data *reply_data;
218 static const struct ethnl_request_ops *
219 ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = {
220 [ETHTOOL_MSG_STRSET_GET] = ðnl_strset_request_ops,
221 [ETHTOOL_MSG_LINKINFO_GET] = ðnl_linkinfo_request_ops,
222 [ETHTOOL_MSG_LINKMODES_GET] = ðnl_linkmodes_request_ops,
223 [ETHTOOL_MSG_LINKSTATE_GET] = ðnl_linkstate_request_ops,
224 [ETHTOOL_MSG_DEBUG_GET] = ðnl_debug_request_ops,
225 [ETHTOOL_MSG_WOL_GET] = ðnl_wol_request_ops,
226 [ETHTOOL_MSG_FEATURES_GET] = ðnl_features_request_ops,
227 [ETHTOOL_MSG_PRIVFLAGS_GET] = ðnl_privflags_request_ops,
228 [ETHTOOL_MSG_RINGS_GET] = ðnl_rings_request_ops,
229 [ETHTOOL_MSG_CHANNELS_GET] = ðnl_channels_request_ops,
230 [ETHTOOL_MSG_COALESCE_GET] = ðnl_coalesce_request_ops,
231 [ETHTOOL_MSG_PAUSE_GET] = ðnl_pause_request_ops,
232 [ETHTOOL_MSG_EEE_GET] = ðnl_eee_request_ops,
235 static struct ethnl_dump_ctx *ethnl_dump_context(struct netlink_callback *cb)
237 return (struct ethnl_dump_ctx *)cb->ctx;
241 * ethnl_default_parse() - Parse request message
242 * @req_info: pointer to structure to put data into
243 * @nlhdr: pointer to request message header
244 * @net: request netns
245 * @request_ops: struct request_ops for request type
246 * @extack: netlink extack for error reporting
247 * @require_dev: fail if no device identified in header
249 * Parse universal request header and call request specific ->parse_request()
250 * callback (if defined) to parse the rest of the message.
252 * Return: 0 on success or negative error code
254 static int ethnl_default_parse(struct ethnl_req_info *req_info,
255 const struct nlmsghdr *nlhdr, struct net *net,
256 const struct ethnl_request_ops *request_ops,
257 struct netlink_ext_ack *extack, bool require_dev)
262 tb = kmalloc_array(request_ops->max_attr + 1, sizeof(tb[0]),
267 ret = nlmsg_parse(nlhdr, GENL_HDRLEN, tb, request_ops->max_attr,
268 request_ops->request_policy, extack);
271 ret = ethnl_parse_header_dev_get(req_info, tb[request_ops->hdr_attr],
272 net, extack, require_dev);
276 if (request_ops->parse_request) {
277 ret = request_ops->parse_request(req_info, tb, extack);
289 * ethnl_init_reply_data() - Initialize reply data for GET request
290 * @reply_data: pointer to embedded struct ethnl_reply_data
291 * @ops: instance of struct ethnl_request_ops describing the layout
292 * @dev: network device to initialize the reply for
294 * Fills the reply data part with zeros and sets the dev member. Must be called
295 * before calling the ->fill_reply() callback (for each iteration when handling
298 static void ethnl_init_reply_data(struct ethnl_reply_data *reply_data,
299 const struct ethnl_request_ops *ops,
300 struct net_device *dev)
302 memset(reply_data, 0, ops->reply_data_size);
303 reply_data->dev = dev;
306 /* default ->doit() handler for GET type requests */
307 static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info)
309 struct ethnl_reply_data *reply_data = NULL;
310 struct ethnl_req_info *req_info = NULL;
311 const u8 cmd = info->genlhdr->cmd;
312 const struct ethnl_request_ops *ops;
313 struct sk_buff *rskb;
318 ops = ethnl_default_requests[cmd];
319 if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", cmd))
321 req_info = kzalloc(ops->req_info_size, GFP_KERNEL);
324 reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL);
330 ret = ethnl_default_parse(req_info, info->nlhdr, genl_info_net(info), ops,
331 info->extack, !ops->allow_nodev_do);
334 ethnl_init_reply_data(reply_data, ops, req_info->dev);
337 ret = ops->prepare_data(req_info, reply_data, info);
341 ret = ops->reply_size(req_info, reply_data);
346 rskb = ethnl_reply_init(reply_len, req_info->dev, ops->reply_cmd,
347 ops->hdr_attr, info, &reply_payload);
350 ret = ops->fill_reply(rskb, req_info, reply_data);
353 if (ops->cleanup_data)
354 ops->cleanup_data(reply_data);
356 genlmsg_end(rskb, reply_payload);
358 dev_put(req_info->dev);
361 return genlmsg_reply(rskb, info);
364 WARN_ONCE(ret == -EMSGSIZE, "calculated message payload length (%d) not sufficient\n", reply_len);
367 if (ops->cleanup_data)
368 ops->cleanup_data(reply_data);
371 dev_put(req_info->dev);
377 static int ethnl_default_dump_one(struct sk_buff *skb, struct net_device *dev,
378 const struct ethnl_dump_ctx *ctx)
382 ethnl_init_reply_data(ctx->reply_data, ctx->ops, dev);
384 ret = ctx->ops->prepare_data(ctx->req_info, ctx->reply_data, NULL);
388 ret = ethnl_fill_reply_header(skb, dev, ctx->ops->hdr_attr);
391 ret = ctx->ops->fill_reply(skb, ctx->req_info, ctx->reply_data);
394 if (ctx->ops->cleanup_data)
395 ctx->ops->cleanup_data(ctx->reply_data);
396 ctx->reply_data->dev = NULL;
400 /* Default ->dumpit() handler for GET requests. Device iteration copied from
401 * rtnl_dump_ifinfo(); we have to be more careful about device hashtable
402 * persistence as we cannot guarantee to hold RTNL lock through the whole
403 * function as rtnetnlink does.
405 static int ethnl_default_dumpit(struct sk_buff *skb,
406 struct netlink_callback *cb)
408 struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb);
409 struct net *net = sock_net(skb->sk);
410 int s_idx = ctx->pos_idx;
416 for (h = ctx->pos_hash; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
417 struct hlist_head *head;
418 struct net_device *dev;
421 head = &net->dev_index_head[h];
424 seq = net->dev_base_seq;
427 hlist_for_each_entry(dev, head, index_hlist) {
433 ehdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid,
435 ðtool_genl_family, 0,
436 ctx->ops->reply_cmd);
442 ret = ethnl_default_dump_one(skb, dev, ctx);
445 genlmsg_cancel(skb, ehdr);
446 if (ret == -EOPNOTSUPP)
448 if (likely(skb->len))
452 genlmsg_end(skb, ehdr);
455 if (net->dev_base_seq != seq) {
469 nl_dump_check_consistent(cb, nlmsg_hdr(skb));
474 /* generic ->start() handler for GET requests */
475 static int ethnl_default_start(struct netlink_callback *cb)
477 struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb);
478 struct ethnl_reply_data *reply_data;
479 const struct ethnl_request_ops *ops;
480 struct ethnl_req_info *req_info;
481 struct genlmsghdr *ghdr;
484 BUILD_BUG_ON(sizeof(*ctx) > sizeof(cb->ctx));
486 ghdr = nlmsg_data(cb->nlh);
487 ops = ethnl_default_requests[ghdr->cmd];
488 if (WARN_ONCE(!ops, "cmd %u has no ethnl_request_ops\n", ghdr->cmd))
490 req_info = kzalloc(ops->req_info_size, GFP_KERNEL);
493 reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL);
499 ret = ethnl_default_parse(req_info, cb->nlh, sock_net(cb->skb->sk), ops,
502 /* We ignore device specification in dump requests but as the
503 * same parser as for non-dump (doit) requests is used, it
504 * would take reference to the device if it finds one
506 dev_put(req_info->dev);
507 req_info->dev = NULL;
510 goto free_reply_data;
513 ctx->req_info = req_info;
514 ctx->reply_data = reply_data;
528 /* default ->done() handler for GET requests */
529 static int ethnl_default_done(struct netlink_callback *cb)
531 struct ethnl_dump_ctx *ctx = ethnl_dump_context(cb);
533 kfree(ctx->reply_data);
534 kfree(ctx->req_info);
539 static const struct ethnl_request_ops *
540 ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX + 1] = {
541 [ETHTOOL_MSG_LINKINFO_NTF] = ðnl_linkinfo_request_ops,
542 [ETHTOOL_MSG_LINKMODES_NTF] = ðnl_linkmodes_request_ops,
543 [ETHTOOL_MSG_DEBUG_NTF] = ðnl_debug_request_ops,
544 [ETHTOOL_MSG_WOL_NTF] = ðnl_wol_request_ops,
545 [ETHTOOL_MSG_FEATURES_NTF] = ðnl_features_request_ops,
546 [ETHTOOL_MSG_PRIVFLAGS_NTF] = ðnl_privflags_request_ops,
547 [ETHTOOL_MSG_RINGS_NTF] = ðnl_rings_request_ops,
548 [ETHTOOL_MSG_CHANNELS_NTF] = ðnl_channels_request_ops,
549 [ETHTOOL_MSG_COALESCE_NTF] = ðnl_coalesce_request_ops,
550 [ETHTOOL_MSG_PAUSE_NTF] = ðnl_pause_request_ops,
553 /* default notification handler */
554 static void ethnl_default_notify(struct net_device *dev, unsigned int cmd,
557 struct ethnl_reply_data *reply_data;
558 const struct ethnl_request_ops *ops;
559 struct ethnl_req_info *req_info;
565 if (WARN_ONCE(cmd > ETHTOOL_MSG_KERNEL_MAX ||
566 !ethnl_default_notify_ops[cmd],
567 "unexpected notification type %u\n", cmd))
569 ops = ethnl_default_notify_ops[cmd];
570 req_info = kzalloc(ops->req_info_size, GFP_KERNEL);
573 reply_data = kmalloc(ops->reply_data_size, GFP_KERNEL);
580 req_info->flags |= ETHTOOL_FLAG_COMPACT_BITSETS;
582 ethnl_init_reply_data(reply_data, ops, dev);
583 ret = ops->prepare_data(req_info, reply_data, NULL);
586 ret = ops->reply_size(req_info, reply_data);
591 skb = genlmsg_new(reply_len, GFP_KERNEL);
594 reply_payload = ethnl_bcastmsg_put(skb, cmd);
597 ret = ethnl_fill_reply_header(skb, dev, ops->hdr_attr);
600 ret = ops->fill_reply(skb, req_info, reply_data);
603 if (ops->cleanup_data)
604 ops->cleanup_data(reply_data);
606 genlmsg_end(skb, reply_payload);
609 ethnl_multicast(skb, dev);
613 WARN_ONCE(ret == -EMSGSIZE,
614 "calculated message payload length (%d) not sufficient\n",
619 if (ops->cleanup_data)
620 ops->cleanup_data(reply_data);
628 typedef void (*ethnl_notify_handler_t)(struct net_device *dev, unsigned int cmd,
631 static const ethnl_notify_handler_t ethnl_notify_handlers[] = {
632 [ETHTOOL_MSG_LINKINFO_NTF] = ethnl_default_notify,
633 [ETHTOOL_MSG_LINKMODES_NTF] = ethnl_default_notify,
634 [ETHTOOL_MSG_DEBUG_NTF] = ethnl_default_notify,
635 [ETHTOOL_MSG_WOL_NTF] = ethnl_default_notify,
636 [ETHTOOL_MSG_FEATURES_NTF] = ethnl_default_notify,
637 [ETHTOOL_MSG_PRIVFLAGS_NTF] = ethnl_default_notify,
638 [ETHTOOL_MSG_RINGS_NTF] = ethnl_default_notify,
639 [ETHTOOL_MSG_CHANNELS_NTF] = ethnl_default_notify,
640 [ETHTOOL_MSG_COALESCE_NTF] = ethnl_default_notify,
641 [ETHTOOL_MSG_PAUSE_NTF] = ethnl_default_notify,
644 void ethtool_notify(struct net_device *dev, unsigned int cmd, const void *data)
646 if (unlikely(!ethnl_ok))
650 if (likely(cmd < ARRAY_SIZE(ethnl_notify_handlers) &&
651 ethnl_notify_handlers[cmd]))
652 ethnl_notify_handlers[cmd](dev, cmd, data);
654 WARN_ONCE(1, "notification %u not implemented (dev=%s)\n",
655 cmd, netdev_name(dev));
657 EXPORT_SYMBOL(ethtool_notify);
659 static void ethnl_notify_features(struct netdev_notifier_info *info)
661 struct net_device *dev = netdev_notifier_info_to_dev(info);
663 ethtool_notify(dev, ETHTOOL_MSG_FEATURES_NTF, NULL);
666 static int ethnl_netdev_event(struct notifier_block *this, unsigned long event,
670 case NETDEV_FEAT_CHANGE:
671 ethnl_notify_features(ptr);
678 static struct notifier_block ethnl_netdev_notifier = {
679 .notifier_call = ethnl_netdev_event,
682 /* genetlink setup */
684 static const struct genl_ops ethtool_genl_ops[] = {
686 .cmd = ETHTOOL_MSG_STRSET_GET,
687 .doit = ethnl_default_doit,
688 .start = ethnl_default_start,
689 .dumpit = ethnl_default_dumpit,
690 .done = ethnl_default_done,
693 .cmd = ETHTOOL_MSG_LINKINFO_GET,
694 .doit = ethnl_default_doit,
695 .start = ethnl_default_start,
696 .dumpit = ethnl_default_dumpit,
697 .done = ethnl_default_done,
700 .cmd = ETHTOOL_MSG_LINKINFO_SET,
701 .flags = GENL_UNS_ADMIN_PERM,
702 .doit = ethnl_set_linkinfo,
705 .cmd = ETHTOOL_MSG_LINKMODES_GET,
706 .doit = ethnl_default_doit,
707 .start = ethnl_default_start,
708 .dumpit = ethnl_default_dumpit,
709 .done = ethnl_default_done,
712 .cmd = ETHTOOL_MSG_LINKMODES_SET,
713 .flags = GENL_UNS_ADMIN_PERM,
714 .doit = ethnl_set_linkmodes,
717 .cmd = ETHTOOL_MSG_LINKSTATE_GET,
718 .doit = ethnl_default_doit,
719 .start = ethnl_default_start,
720 .dumpit = ethnl_default_dumpit,
721 .done = ethnl_default_done,
724 .cmd = ETHTOOL_MSG_DEBUG_GET,
725 .doit = ethnl_default_doit,
726 .start = ethnl_default_start,
727 .dumpit = ethnl_default_dumpit,
728 .done = ethnl_default_done,
731 .cmd = ETHTOOL_MSG_DEBUG_SET,
732 .flags = GENL_UNS_ADMIN_PERM,
733 .doit = ethnl_set_debug,
736 .cmd = ETHTOOL_MSG_WOL_GET,
737 .flags = GENL_UNS_ADMIN_PERM,
738 .doit = ethnl_default_doit,
739 .start = ethnl_default_start,
740 .dumpit = ethnl_default_dumpit,
741 .done = ethnl_default_done,
744 .cmd = ETHTOOL_MSG_WOL_SET,
745 .flags = GENL_UNS_ADMIN_PERM,
746 .doit = ethnl_set_wol,
749 .cmd = ETHTOOL_MSG_FEATURES_GET,
750 .doit = ethnl_default_doit,
751 .start = ethnl_default_start,
752 .dumpit = ethnl_default_dumpit,
753 .done = ethnl_default_done,
756 .cmd = ETHTOOL_MSG_FEATURES_SET,
757 .flags = GENL_UNS_ADMIN_PERM,
758 .doit = ethnl_set_features,
761 .cmd = ETHTOOL_MSG_PRIVFLAGS_GET,
762 .doit = ethnl_default_doit,
763 .start = ethnl_default_start,
764 .dumpit = ethnl_default_dumpit,
765 .done = ethnl_default_done,
768 .cmd = ETHTOOL_MSG_PRIVFLAGS_SET,
769 .flags = GENL_UNS_ADMIN_PERM,
770 .doit = ethnl_set_privflags,
773 .cmd = ETHTOOL_MSG_RINGS_GET,
774 .doit = ethnl_default_doit,
775 .start = ethnl_default_start,
776 .dumpit = ethnl_default_dumpit,
777 .done = ethnl_default_done,
780 .cmd = ETHTOOL_MSG_RINGS_SET,
781 .flags = GENL_UNS_ADMIN_PERM,
782 .doit = ethnl_set_rings,
785 .cmd = ETHTOOL_MSG_CHANNELS_GET,
786 .doit = ethnl_default_doit,
787 .start = ethnl_default_start,
788 .dumpit = ethnl_default_dumpit,
789 .done = ethnl_default_done,
792 .cmd = ETHTOOL_MSG_CHANNELS_SET,
793 .flags = GENL_UNS_ADMIN_PERM,
794 .doit = ethnl_set_channels,
797 .cmd = ETHTOOL_MSG_COALESCE_GET,
798 .doit = ethnl_default_doit,
799 .start = ethnl_default_start,
800 .dumpit = ethnl_default_dumpit,
801 .done = ethnl_default_done,
804 .cmd = ETHTOOL_MSG_COALESCE_SET,
805 .flags = GENL_UNS_ADMIN_PERM,
806 .doit = ethnl_set_coalesce,
809 .cmd = ETHTOOL_MSG_PAUSE_GET,
810 .doit = ethnl_default_doit,
811 .start = ethnl_default_start,
812 .dumpit = ethnl_default_dumpit,
813 .done = ethnl_default_done,
816 .cmd = ETHTOOL_MSG_PAUSE_SET,
817 .flags = GENL_UNS_ADMIN_PERM,
818 .doit = ethnl_set_pause,
821 .cmd = ETHTOOL_MSG_EEE_GET,
822 .doit = ethnl_default_doit,
823 .start = ethnl_default_start,
824 .dumpit = ethnl_default_dumpit,
825 .done = ethnl_default_done,
828 .cmd = ETHTOOL_MSG_EEE_SET,
829 .flags = GENL_UNS_ADMIN_PERM,
830 .doit = ethnl_set_eee,
834 static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
835 [ETHNL_MCGRP_MONITOR] = { .name = ETHTOOL_MCGRP_MONITOR_NAME },
838 static struct genl_family ethtool_genl_family = {
839 .name = ETHTOOL_GENL_NAME,
840 .version = ETHTOOL_GENL_VERSION,
842 .parallel_ops = true,
843 .ops = ethtool_genl_ops,
844 .n_ops = ARRAY_SIZE(ethtool_genl_ops),
845 .mcgrps = ethtool_nl_mcgrps,
846 .n_mcgrps = ARRAY_SIZE(ethtool_nl_mcgrps),
851 static int __init ethnl_init(void)
855 ret = genl_register_family(ðtool_genl_family);
856 if (WARN(ret < 0, "ethtool: genetlink family registration failed"))
860 ret = register_netdevice_notifier(ðnl_netdev_notifier);
861 WARN(ret < 0, "ethtool: net device notifier registration failed");
865 subsys_initcall(ethnl_init);