Skip to content

Commit 7328673

Browse files
mkubecekdavem330
authored andcommitted
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>
1 parent 5cf2a54 commit 7328673

5 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎Documentation/networking/ethtool-netlink.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ Kernel to userspace:
189189
===================================== ================================
190190
``ETHTOOL_MSG_STRSET_GET_REPLY`` string set contents
191191
``ETHTOOL_MSG_LINKINFO_GET_REPLY`` link settings
192+
``ETHTOOL_MSG_LINKINFO_NTF`` link settings notification
192193
===================================== ================================
193194

194195
``GET`` requests are sent by userspace applications to retrieve device

‎include/uapi/linux/ethtool_netlink.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ enum {
2828
ETHTOOL_MSG_KERNEL_NONE,
2929
ETHTOOL_MSG_STRSET_GET_REPLY,
3030
ETHTOOL_MSG_LINKINFO_GET_REPLY,
31+
ETHTOOL_MSG_LINKINFO_NTF,
3132

3233
/* add new constants above here */
3334
__ETHTOOL_MSG_KERNEL_CNT,

‎net/ethtool/ioctl.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <net/devlink.h>
2727
#include <net/xdp_sock.h>
2828
#include <net/flow_offload.h>
29+
#include <linux/ethtool_netlink.h>
2930

3031
#include "common.h"
3132

@@ -571,7 +572,10 @@ static int ethtool_set_link_ksettings(struct net_device *dev,
571572
!= link_ksettings.base.link_mode_masks_nwords)
572573
return -EINVAL;
573574

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;
575579
}
576580

577581
/* Query device for its ethtool_cmd settings.
@@ -620,6 +624,7 @@ static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
620624
{
621625
struct ethtool_link_ksettings link_ksettings;
622626
struct ethtool_cmd cmd;
627+
int ret;
623628

624629
ASSERT_RTNL();
625630

@@ -632,7 +637,10 @@ static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
632637
return -EINVAL;
633638
link_ksettings.base.link_mode_masks_nwords =
634639
__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;
636644
}
637645

638646
static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,

‎net/ethtool/linkinfo.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info)
155155
ret = dev->ethtool_ops->set_link_ksettings(dev, &ksettings);
156156
if (ret < 0)
157157
GENL_SET_ERR_MSG(info, "link settings update failed");
158+
else
159+
ethtool_notify(dev, ETHTOOL_MSG_LINKINFO_NTF, NULL);
158160

159161
out_ops:
160162
ethnl_ops_complete(dev);

‎net/ethtool/netlink.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ static int ethnl_default_done(struct netlink_callback *cb)
509509

510510
static const struct ethnl_request_ops *
511511
ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX + 1] = {
512+
[ETHTOOL_MSG_LINKINFO_NTF] = &ethnl_linkinfo_request_ops,
512513
};
513514

514515
/* default notification handler */
@@ -589,6 +590,7 @@ typedef void (*ethnl_notify_handler_t)(struct net_device *dev, unsigned int cmd,
589590
const void *data);
590591

591592
static const ethnl_notify_handler_t ethnl_notify_handlers[] = {
593+
[ETHTOOL_MSG_LINKINFO_NTF] = ethnl_default_notify,
592594
};
593595

594596
void ethtool_notify(struct net_device *dev, unsigned int cmd, const void *data)

0 commit comments

Comments
 (0)