Skip to content

Commit

Permalink
ethtool: set message mask with DEBUG_SET request
Browse files Browse the repository at this point in the history
Implement DEBUG_SET netlink request to set debugging settings for a device.
At the moment, only message mask corresponding to message level as set by
ETHTOOL_SMSGLVL ioctl request can be set. (It is called message level in
ioctl interface but almost all drivers interpret it as a bit mask.)

Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
mkubecek authored and davem330 committed Jan 27, 2020
1 parent 6a94b8c commit e54d04e
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
20 changes: 19 additions & 1 deletion Documentation/networking/ethtool-netlink.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ Userspace to kernel:
``ETHTOOL_MSG_LINKMODES_SET`` set link modes info
``ETHTOOL_MSG_LINKSTATE_GET`` get link state
``ETHTOOL_MSG_DEBUG_GET`` get debugging settings
``ETHTOOL_MSG_DEBUG_SET`` set debugging settings
===================================== ================================

Kernel to userspace:
Expand Down Expand Up @@ -455,6 +456,23 @@ interface follows its actual use in practice.
devices supporting the request).


DEBUG_SET
=========

Set or update debugging settings of a device. At the moment, only message mask
is supported.

Request contents:

==================================== ====== ==========================
``ETHTOOL_A_DEBUG_HEADER`` nested request header
``ETHTOOL_A_DEBUG_MSGMASK`` bitset message mask
==================================== ====== ==========================

``ETHTOOL_A_DEBUG_MSGMASK`` bit set allows setting or modifying mask of
enabled debugging message types for the device.


Request translation
===================

Expand All @@ -474,7 +492,7 @@ have their netlink replacement yet.
``ETHTOOL_GWOL`` n/a
``ETHTOOL_SWOL`` n/a
``ETHTOOL_GMSGLVL`` ``ETHTOOL_MSG_DEBUG_GET``
``ETHTOOL_SMSGLVL`` n/a
``ETHTOOL_SMSGLVL`` ``ETHTOOL_MSG_DEBUG_SET``
``ETHTOOL_NWAY_RST`` n/a
``ETHTOOL_GLINK`` ``ETHTOOL_MSG_LINKSTATE_GET``
``ETHTOOL_GEEPROM`` n/a
Expand Down
1 change: 1 addition & 0 deletions include/uapi/linux/ethtool_netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum {
ETHTOOL_MSG_LINKMODES_SET,
ETHTOOL_MSG_LINKSTATE_GET,
ETHTOOL_MSG_DEBUG_GET,
ETHTOOL_MSG_DEBUG_SET,

/* add new constants above here */
__ETHTOOL_MSG_USER_CNT,
Expand Down
53 changes: 53 additions & 0 deletions net/ethtool/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,56 @@ const struct ethnl_request_ops ethnl_debug_request_ops = {
.reply_size = debug_reply_size,
.fill_reply = debug_fill_reply,
};

/* DEBUG_SET */

static const struct nla_policy
debug_set_policy[ETHTOOL_A_DEBUG_MAX + 1] = {
[ETHTOOL_A_DEBUG_UNSPEC] = { .type = NLA_REJECT },
[ETHTOOL_A_DEBUG_HEADER] = { .type = NLA_NESTED },
[ETHTOOL_A_DEBUG_MSGMASK] = { .type = NLA_NESTED },
};

int ethnl_set_debug(struct sk_buff *skb, struct genl_info *info)
{
struct nlattr *tb[ETHTOOL_A_DEBUG_MAX + 1];
struct ethnl_req_info req_info = {};
struct net_device *dev;
bool mod = false;
u32 msg_mask;
int ret;

ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb,
ETHTOOL_A_DEBUG_MAX, debug_set_policy,
info->extack);
if (ret < 0)
return ret;
ret = ethnl_parse_header(&req_info, tb[ETHTOOL_A_DEBUG_HEADER],
genl_info_net(info), info->extack, true);
if (ret < 0)
return ret;
dev = req_info.dev;
if (!dev->ethtool_ops->get_msglevel || !dev->ethtool_ops->set_msglevel)
return -EOPNOTSUPP;

rtnl_lock();
ret = ethnl_ops_begin(dev);
if (ret < 0)
goto out_rtnl;

msg_mask = dev->ethtool_ops->get_msglevel(dev);
ret = ethnl_update_bitset32(&msg_mask, NETIF_MSG_CLASS_COUNT,
tb[ETHTOOL_A_DEBUG_MSGMASK],
netif_msg_class_names, info->extack, &mod);
if (ret < 0 || !mod)
goto out_ops;

dev->ethtool_ops->set_msglevel(dev, msg_mask);

out_ops:
ethnl_ops_complete(dev);
out_rtnl:
rtnl_unlock();
dev_put(dev);
return ret;
}
5 changes: 5 additions & 0 deletions net/ethtool/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,11 @@ static const struct genl_ops ethtool_genl_ops[] = {
.dumpit = ethnl_default_dumpit,
.done = ethnl_default_done,
},
{
.cmd = ETHTOOL_MSG_DEBUG_SET,
.flags = GENL_UNS_ADMIN_PERM,
.doit = ethnl_set_debug,
},
};

static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
Expand Down
1 change: 1 addition & 0 deletions net/ethtool/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,5 +338,6 @@ extern const struct ethnl_request_ops ethnl_debug_request_ops;

int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info);
int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info);
int ethnl_set_debug(struct sk_buff *skb, struct genl_info *info);

#endif /* _NET_ETHTOOL_NETLINK_H */

0 comments on commit e54d04e

Please sign in to comment.