Commit 73286734c1b0d009fd317c2a74e173cb22233dad
Committed by
David S. Miller
1 parent
5cf2a548bc
ethtool: add LINKINFO_NTF notification
Send ETHTOOL_MSG_LINKINFO_NTF notification message whenever device link settings are modified using ETHTOOL_MSG_LINKINFO_SET netlink message or ETHTOOL_SLINKSETTINGS or ETHTOOL_SSET ioctl commands. The notification message has the same format as reply to LINKINFO_GET request. ETHTOOL_MSG_LINKINFO_SET netlink request only triggers the notification if there is a change but the ioctl command handlers do not check if there is an actual change and trigger the notification whenever the commands are executed. As all work is done by ethnl_default_notify() handler and callback functions introduced to handle LINKINFO_GET requests, all that remains is adding entries for ETHTOOL_MSG_LINKINFO_NTF into ethnl_notify_handlers and ethnl_default_notify_ops lookup tables and calls to ethtool_notify() where needed. Signed-off-by: Michal Kubecek <mkubecek@suse.cz> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 5 changed files with 16 additions and 2 deletions Side-by-side Diff
Documentation/networking/ethtool-netlink.rst
... | ... | @@ -189,6 +189,7 @@ |
189 | 189 | ===================================== ================================ |
190 | 190 | ``ETHTOOL_MSG_STRSET_GET_REPLY`` string set contents |
191 | 191 | ``ETHTOOL_MSG_LINKINFO_GET_REPLY`` link settings |
192 | + ``ETHTOOL_MSG_LINKINFO_NTF`` link settings notification | |
192 | 193 | ===================================== ================================ |
193 | 194 | |
194 | 195 | ``GET`` requests are sent by userspace applications to retrieve device |
include/uapi/linux/ethtool_netlink.h
net/ethtool/ioctl.c
... | ... | @@ -26,6 +26,7 @@ |
26 | 26 | #include <net/devlink.h> |
27 | 27 | #include <net/xdp_sock.h> |
28 | 28 | #include <net/flow_offload.h> |
29 | +#include <linux/ethtool_netlink.h> | |
29 | 30 | |
30 | 31 | #include "common.h" |
31 | 32 | |
... | ... | @@ -571,7 +572,10 @@ |
571 | 572 | != link_ksettings.base.link_mode_masks_nwords) |
572 | 573 | return -EINVAL; |
573 | 574 | |
574 | - return dev->ethtool_ops->set_link_ksettings(dev, &link_ksettings); | |
575 | + err = dev->ethtool_ops->set_link_ksettings(dev, &link_ksettings); | |
576 | + if (err >= 0) | |
577 | + ethtool_notify(dev, ETHTOOL_MSG_LINKINFO_NTF, NULL); | |
578 | + return err; | |
575 | 579 | } |
576 | 580 | |
577 | 581 | /* Query device for its ethtool_cmd settings. |
... | ... | @@ -620,6 +624,7 @@ |
620 | 624 | { |
621 | 625 | struct ethtool_link_ksettings link_ksettings; |
622 | 626 | struct ethtool_cmd cmd; |
627 | + int ret; | |
623 | 628 | |
624 | 629 | ASSERT_RTNL(); |
625 | 630 | |
... | ... | @@ -632,7 +637,10 @@ |
632 | 637 | return -EINVAL; |
633 | 638 | link_ksettings.base.link_mode_masks_nwords = |
634 | 639 | __ETHTOOL_LINK_MODE_MASK_NU32; |
635 | - return dev->ethtool_ops->set_link_ksettings(dev, &link_ksettings); | |
640 | + ret = dev->ethtool_ops->set_link_ksettings(dev, &link_ksettings); | |
641 | + if (ret >= 0) | |
642 | + ethtool_notify(dev, ETHTOOL_MSG_LINKINFO_NTF, NULL); | |
643 | + return ret; | |
636 | 644 | } |
637 | 645 | |
638 | 646 | static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev, |
net/ethtool/linkinfo.c
... | ... | @@ -155,6 +155,8 @@ |
155 | 155 | ret = dev->ethtool_ops->set_link_ksettings(dev, &ksettings); |
156 | 156 | if (ret < 0) |
157 | 157 | GENL_SET_ERR_MSG(info, "link settings update failed"); |
158 | + else | |
159 | + ethtool_notify(dev, ETHTOOL_MSG_LINKINFO_NTF, NULL); | |
158 | 160 | |
159 | 161 | out_ops: |
160 | 162 | ethnl_ops_complete(dev); |
net/ethtool/netlink.c
... | ... | @@ -509,6 +509,7 @@ |
509 | 509 | |
510 | 510 | static const struct ethnl_request_ops * |
511 | 511 | ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX + 1] = { |
512 | + [ETHTOOL_MSG_LINKINFO_NTF] = ðnl_linkinfo_request_ops, | |
512 | 513 | }; |
513 | 514 | |
514 | 515 | /* default notification handler */ |
... | ... | @@ -589,6 +590,7 @@ |
589 | 590 | const void *data); |
590 | 591 | |
591 | 592 | static const ethnl_notify_handler_t ethnl_notify_handlers[] = { |
593 | + [ETHTOOL_MSG_LINKINFO_NTF] = ethnl_default_notify, | |
592 | 594 | }; |
593 | 595 | |
594 | 596 | void ethtool_notify(struct net_device *dev, unsigned int cmd, const void *data) |