Skip to content

Commit f265d79

Browse files
mkubecekdavem330
authored andcommitted
ethtool: set device private flags with PRIVFLAGS_SET request
Implement PRIVFLAGS_SET netlink request to set private flags of a network device. These are traditionally set with ETHTOOL_SPFLAGS ioctl request. Signed-off-by: Michal Kubecek <mkubecek@suse.cz> Reviewed-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e16c338 commit f265d79

5 files changed

Lines changed: 97 additions & 1 deletion

File tree

‎Documentation/networking/ethtool-netlink.rst‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ Userspace to kernel:
192192
``ETHTOOL_MSG_FEATURES_GET`` get device features
193193
``ETHTOOL_MSG_FEATURES_SET`` set device features
194194
``ETHTOOL_MSG_PRIVFLAGS_GET`` get private flags
195+
``ETHTOOL_MSG_PRIVFLAGS_SET`` set private flags
195196
===================================== ================================
196197

197198
Kernel to userspace:
@@ -211,6 +212,7 @@ Kernel to userspace:
211212
``ETHTOOL_MSG_FEATURES_SET_REPLY`` optional reply to FEATURES_SET
212213
``ETHTOOL_MSG_FEATURES_NTF`` netdev features notification
213214
``ETHTOOL_MSG_PRIVFLAGS_GET_REPLY`` private flags
215+
``ETHTOOL_MSG_PRIVFLAGS_NTF`` private flags
214216
===================================== =================================
215217

216218
``GET`` requests are sent by userspace applications to retrieve device
@@ -626,6 +628,23 @@ response uses all private flags supported by the device as mask so that client
626628
gets the full information without having to fetch the string set with names.
627629

628630

631+
PRIVFLAGS_SET
632+
=============
633+
634+
Sets or modifies values of device private flags like ``ETHTOOL_SPFLAGS``
635+
ioctl request.
636+
637+
Request contents:
638+
639+
==================================== ====== ==========================
640+
``ETHTOOL_A_PRIVFLAGS_HEADER`` nested request header
641+
``ETHTOOL_A_PRIVFLAGS_FLAGS`` bitset private flags
642+
==================================== ====== ==========================
643+
644+
``ETHTOOL_A_PRIVFLAGS_FLAGS`` can either set the whole set of private flags or
645+
modify only values of some of them.
646+
647+
629648
Request translation
630649
===================
631650

@@ -676,7 +695,7 @@ have their netlink replacement yet.
676695
``ETHTOOL_GFLAGS`` ``ETHTOOL_MSG_FEATURES_GET``
677696
``ETHTOOL_SFLAGS`` ``ETHTOOL_MSG_FEATURES_SET``
678697
``ETHTOOL_GPFLAGS`` ``ETHTOOL_MSG_PRIVFLAGS_GET``
679-
``ETHTOOL_SPFLAGS`` n/a
698+
``ETHTOOL_SPFLAGS`` ``ETHTOOL_MSG_PRIVFLAGS_SET``
680699
``ETHTOOL_GRXFH`` n/a
681700
``ETHTOOL_SRXFH`` n/a
682701
``ETHTOOL_GGRO`` ``ETHTOOL_MSG_FEATURES_GET``

‎include/uapi/linux/ethtool_netlink.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ enum {
2727
ETHTOOL_MSG_FEATURES_GET,
2828
ETHTOOL_MSG_FEATURES_SET,
2929
ETHTOOL_MSG_PRIVFLAGS_GET,
30+
ETHTOOL_MSG_PRIVFLAGS_SET,
3031

3132
/* add new constants above here */
3233
__ETHTOOL_MSG_USER_CNT,

‎net/ethtool/netlink.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,11 @@ static const struct genl_ops ethtool_genl_ops[] = {
741741
.dumpit = ethnl_default_dumpit,
742742
.done = ethnl_default_done,
743743
},
744+
{
745+
.cmd = ETHTOOL_MSG_PRIVFLAGS_SET,
746+
.flags = GENL_UNS_ADMIN_PERM,
747+
.doit = ethnl_set_privflags,
748+
},
744749
};
745750

746751
static const struct genl_multicast_group ethtool_nl_mcgrps[] = {

‎net/ethtool/netlink.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,5 +345,6 @@ int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info);
345345
int ethnl_set_debug(struct sk_buff *skb, struct genl_info *info);
346346
int ethnl_set_wol(struct sk_buff *skb, struct genl_info *info);
347347
int ethnl_set_features(struct sk_buff *skb, struct genl_info *info);
348+
int ethnl_set_privflags(struct sk_buff *skb, struct genl_info *info);
348349

349350
#endif /* _NET_ETHTOOL_NETLINK_H */

‎net/ethtool/privflags.c‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,73 @@ const struct ethnl_request_ops ethnl_privflags_request_ops = {
134134
.fill_reply = privflags_fill_reply,
135135
.cleanup_data = privflags_cleanup_data,
136136
};
137+
138+
/* PRIVFLAGS_SET */
139+
140+
static const struct nla_policy
141+
privflags_set_policy[ETHTOOL_A_PRIVFLAGS_MAX + 1] = {
142+
[ETHTOOL_A_PRIVFLAGS_UNSPEC] = { .type = NLA_REJECT },
143+
[ETHTOOL_A_PRIVFLAGS_HEADER] = { .type = NLA_NESTED },
144+
[ETHTOOL_A_PRIVFLAGS_FLAGS] = { .type = NLA_NESTED },
145+
};
146+
147+
int ethnl_set_privflags(struct sk_buff *skb, struct genl_info *info)
148+
{
149+
struct nlattr *tb[ETHTOOL_A_PRIVFLAGS_MAX + 1];
150+
const char (*names)[ETH_GSTRING_LEN] = NULL;
151+
struct ethnl_req_info req_info = {};
152+
const struct ethtool_ops *ops;
153+
struct net_device *dev;
154+
unsigned int nflags;
155+
bool mod = false;
156+
bool compact;
157+
u32 flags;
158+
int ret;
159+
160+
ret = nlmsg_parse(info->nlhdr, GENL_HDRLEN, tb,
161+
ETHTOOL_A_PRIVFLAGS_MAX, privflags_set_policy,
162+
info->extack);
163+
if (ret < 0)
164+
return ret;
165+
if (!tb[ETHTOOL_A_PRIVFLAGS_FLAGS])
166+
return -EINVAL;
167+
ret = ethnl_bitset_is_compact(tb[ETHTOOL_A_PRIVFLAGS_FLAGS], &compact);
168+
if (ret < 0)
169+
return ret;
170+
ret = ethnl_parse_header_dev_get(&req_info,
171+
tb[ETHTOOL_A_PRIVFLAGS_HEADER],
172+
genl_info_net(info), info->extack,
173+
true);
174+
if (ret < 0)
175+
return ret;
176+
dev = req_info.dev;
177+
ops = dev->ethtool_ops;
178+
if (!ops->get_priv_flags || !ops->set_priv_flags ||
179+
!ops->get_sset_count || !ops->get_strings)
180+
return -EOPNOTSUPP;
181+
182+
rtnl_lock();
183+
ret = ethnl_ops_begin(dev);
184+
if (ret < 0)
185+
goto out_rtnl;
186+
ret = ethnl_get_priv_flags_info(dev, &nflags, compact ? NULL : &names);
187+
if (ret < 0)
188+
goto out_ops;
189+
flags = ops->get_priv_flags(dev);
190+
191+
ret = ethnl_update_bitset32(&flags, nflags,
192+
tb[ETHTOOL_A_PRIVFLAGS_FLAGS], names,
193+
info->extack, &mod);
194+
if (ret < 0 || !mod)
195+
goto out_free;
196+
ret = ops->set_priv_flags(dev, flags);
197+
198+
out_free:
199+
kfree(names);
200+
out_ops:
201+
ethnl_ops_complete(dev);
202+
out_rtnl:
203+
rtnl_unlock();
204+
dev_put(dev);
205+
return ret;
206+
}

0 commit comments

Comments
 (0)