Skip to content

Commit 2b4a899

Browse files
mkubecekdavem330
authored andcommitted
ethtool: introduce ethtool netlink interface
Basic genetlink and init infrastructure for the netlink interface, register genetlink family "ethtool". Add CONFIG_ETHTOOL_NETLINK Kconfig option to make the build optional. Add initial overall interface description into Documentation/networking/ethtool-netlink.rst, further patches will add more detailed information. Signed-off-by: Michal Kubecek <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 356b23c commit 2b4a899

File tree

8 files changed

+318
-1
lines changed

8 files changed

+318
-1
lines changed
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
=============================
2+
Netlink interface for ethtool
3+
=============================
4+
5+
6+
Basic information
7+
=================
8+
9+
Netlink interface for ethtool uses generic netlink family ``ethtool``
10+
(userspace application should use macros ``ETHTOOL_GENL_NAME`` and
11+
``ETHTOOL_GENL_VERSION`` defined in ``<linux/ethtool_netlink.h>`` uapi
12+
header). This family does not use a specific header, all information in
13+
requests and replies is passed using netlink attributes.
14+
15+
The ethtool netlink interface uses extended ACK for error and warning
16+
reporting, userspace application developers are encouraged to make these
17+
messages available to user in a suitable way.
18+
19+
Requests can be divided into three categories: "get" (retrieving information),
20+
"set" (setting parameters) and "action" (invoking an action).
21+
22+
All "set" and "action" type requests require admin privileges
23+
(``CAP_NET_ADMIN`` in the namespace). Most "get" type requests are allowed for
24+
anyone but there are exceptions (where the response contains sensitive
25+
information). In some cases, the request as such is allowed for anyone but
26+
unprivileged users have attributes with sensitive information (e.g.
27+
wake-on-lan password) omitted.
28+
29+
30+
Conventions
31+
===========
32+
33+
Attributes which represent a boolean value usually use NLA_U8 type so that we
34+
can distinguish three states: "on", "off" and "not present" (meaning the
35+
information is not available in "get" requests or value is not to be changed
36+
in "set" requests). For these attributes, the "true" value should be passed as
37+
number 1 but any non-zero value should be understood as "true" by recipient.
38+
In the tables below, "bool" denotes NLA_U8 attributes interpreted in this way.
39+
40+
In the message structure descriptions below, if an attribute name is suffixed
41+
with "+", parent nest can contain multiple attributes of the same type. This
42+
implements an array of entries.
43+
44+
45+
Request header
46+
==============
47+
48+
Each request or reply message contains a nested attribute with common header.
49+
Structure of this header is
50+
51+
============================== ====== =============================
52+
``ETHTOOL_A_HEADER_DEV_INDEX`` u32 device ifindex
53+
``ETHTOOL_A_HEADER_DEV_NAME`` string device name
54+
``ETHTOOL_A_HEADER_FLAGS`` u32 flags common for all requests
55+
============================== ====== =============================
56+
57+
``ETHTOOL_A_HEADER_DEV_INDEX`` and ``ETHTOOL_A_HEADER_DEV_NAME`` identify the
58+
device message relates to. One of them is sufficient in requests, if both are
59+
used, they must identify the same device. Some requests, e.g. global string
60+
sets, do not require device identification. Most ``GET`` requests also allow
61+
dump requests without device identification to query the same information for
62+
all devices providing it (each device in a separate message).
63+
64+
``ETHTOOL_A_HEADER_FLAGS`` is a bitmap of request flags common for all request
65+
types. The interpretation of these flags is the same for all request types but
66+
the flags may not apply to requests. Recognized flags are:
67+
68+
================================= ===================================
69+
``ETHTOOL_FLAG_COMPACT_BITSETS`` use compact format bitsets in reply
70+
``ETHTOOL_FLAG_OMIT_REPLY`` omit optional reply (_SET and _ACT)
71+
================================= ===================================
72+
73+
New request flags should follow the general idea that if the flag is not set,
74+
the behaviour is backward compatible, i.e. requests from old clients not aware
75+
of the flag should be interpreted the way the client expects. A client must
76+
not set flags it does not understand.
77+
78+
79+
List of message types
80+
=====================
81+
82+
All constants identifying message types use ``ETHTOOL_CMD_`` prefix and suffix
83+
according to message purpose:
84+
85+
============== ======================================
86+
``_GET`` userspace request to retrieve data
87+
``_SET`` userspace request to set data
88+
``_ACT`` userspace request to perform an action
89+
``_GET_REPLY`` kernel reply to a ``GET`` request
90+
``_SET_REPLY`` kernel reply to a ``SET`` request
91+
``_ACT_REPLY`` kernel reply to an ``ACT`` request
92+
``_NTF`` kernel notification
93+
============== ======================================
94+
95+
``GET`` requests are sent by userspace applications to retrieve device
96+
information. They usually do not contain any message specific attributes.
97+
Kernel replies with corresponding "GET_REPLY" message. For most types, ``GET``
98+
request with ``NLM_F_DUMP`` and no device identification can be used to query
99+
the information for all devices supporting the request.
100+
101+
If the data can be also modified, corresponding ``SET`` message with the same
102+
layout as corresponding ``GET_REPLY`` is used to request changes. Only
103+
attributes where a change is requested are included in such request (also, not
104+
all attributes may be changed). Replies to most ``SET`` request consist only
105+
of error code and extack; if kernel provides additional data, it is sent in
106+
the form of corresponding ``SET_REPLY`` message which can be suppressed by
107+
setting ``ETHTOOL_FLAG_OMIT_REPLY`` flag in request header.
108+
109+
Data modification also triggers sending a ``NTF`` message with a notification.
110+
These usually bear only a subset of attributes which was affected by the
111+
change. The same notification is issued if the data is modified using other
112+
means (mostly ioctl ethtool interface). Unlike notifications from ethtool
113+
netlink code which are only sent if something actually changed, notifications
114+
triggered by ioctl interface may be sent even if the request did not actually
115+
change any data.
116+
117+
``ACT`` messages request kernel (driver) to perform a specific action. If some
118+
information is reported by kernel (which can be suppressed by setting
119+
``ETHTOOL_FLAG_OMIT_REPLY`` flag in request header), the reply takes form of
120+
an ``ACT_REPLY`` message. Performing an action also triggers a notification
121+
(``NTF`` message).
122+
123+
Later sections describe the format and semantics of these messages.
124+
125+
126+
Request translation
127+
===================
128+
129+
The following table maps ioctl commands to netlink commands providing their
130+
functionality. Entries with "n/a" in right column are commands which do not
131+
have their netlink replacement yet.
132+
133+
=================================== =====================================
134+
ioctl command netlink command
135+
=================================== =====================================
136+
``ETHTOOL_GSET`` n/a
137+
``ETHTOOL_SSET`` n/a
138+
``ETHTOOL_GDRVINFO`` n/a
139+
``ETHTOOL_GREGS`` n/a
140+
``ETHTOOL_GWOL`` n/a
141+
``ETHTOOL_SWOL`` n/a
142+
``ETHTOOL_GMSGLVL`` n/a
143+
``ETHTOOL_SMSGLVL`` n/a
144+
``ETHTOOL_NWAY_RST`` n/a
145+
``ETHTOOL_GLINK`` n/a
146+
``ETHTOOL_GEEPROM`` n/a
147+
``ETHTOOL_SEEPROM`` n/a
148+
``ETHTOOL_GCOALESCE`` n/a
149+
``ETHTOOL_SCOALESCE`` n/a
150+
``ETHTOOL_GRINGPARAM`` n/a
151+
``ETHTOOL_SRINGPARAM`` n/a
152+
``ETHTOOL_GPAUSEPARAM`` n/a
153+
``ETHTOOL_SPAUSEPARAM`` n/a
154+
``ETHTOOL_GRXCSUM`` n/a
155+
``ETHTOOL_SRXCSUM`` n/a
156+
``ETHTOOL_GTXCSUM`` n/a
157+
``ETHTOOL_STXCSUM`` n/a
158+
``ETHTOOL_GSG`` n/a
159+
``ETHTOOL_SSG`` n/a
160+
``ETHTOOL_TEST`` n/a
161+
``ETHTOOL_GSTRINGS`` n/a
162+
``ETHTOOL_PHYS_ID`` n/a
163+
``ETHTOOL_GSTATS`` n/a
164+
``ETHTOOL_GTSO`` n/a
165+
``ETHTOOL_STSO`` n/a
166+
``ETHTOOL_GPERMADDR`` rtnetlink ``RTM_GETLINK``
167+
``ETHTOOL_GUFO`` n/a
168+
``ETHTOOL_SUFO`` n/a
169+
``ETHTOOL_GGSO`` n/a
170+
``ETHTOOL_SGSO`` n/a
171+
``ETHTOOL_GFLAGS`` n/a
172+
``ETHTOOL_SFLAGS`` n/a
173+
``ETHTOOL_GPFLAGS`` n/a
174+
``ETHTOOL_SPFLAGS`` n/a
175+
``ETHTOOL_GRXFH`` n/a
176+
``ETHTOOL_SRXFH`` n/a
177+
``ETHTOOL_GGRO`` n/a
178+
``ETHTOOL_SGRO`` n/a
179+
``ETHTOOL_GRXRINGS`` n/a
180+
``ETHTOOL_GRXCLSRLCNT`` n/a
181+
``ETHTOOL_GRXCLSRULE`` n/a
182+
``ETHTOOL_GRXCLSRLALL`` n/a
183+
``ETHTOOL_SRXCLSRLDEL`` n/a
184+
``ETHTOOL_SRXCLSRLINS`` n/a
185+
``ETHTOOL_FLASHDEV`` n/a
186+
``ETHTOOL_RESET`` n/a
187+
``ETHTOOL_SRXNTUPLE`` n/a
188+
``ETHTOOL_GRXNTUPLE`` n/a
189+
``ETHTOOL_GSSET_INFO`` n/a
190+
``ETHTOOL_GRXFHINDIR`` n/a
191+
``ETHTOOL_SRXFHINDIR`` n/a
192+
``ETHTOOL_GFEATURES`` n/a
193+
``ETHTOOL_SFEATURES`` n/a
194+
``ETHTOOL_GCHANNELS`` n/a
195+
``ETHTOOL_SCHANNELS`` n/a
196+
``ETHTOOL_SET_DUMP`` n/a
197+
``ETHTOOL_GET_DUMP_FLAG`` n/a
198+
``ETHTOOL_GET_DUMP_DATA`` n/a
199+
``ETHTOOL_GET_TS_INFO`` n/a
200+
``ETHTOOL_GMODULEINFO`` n/a
201+
``ETHTOOL_GMODULEEEPROM`` n/a
202+
``ETHTOOL_GEEE`` n/a
203+
``ETHTOOL_SEEE`` n/a
204+
``ETHTOOL_GRSSH`` n/a
205+
``ETHTOOL_SRSSH`` n/a
206+
``ETHTOOL_GTUNABLE`` n/a
207+
``ETHTOOL_STUNABLE`` n/a
208+
``ETHTOOL_GPHYSTATS`` n/a
209+
``ETHTOOL_PERQUEUE`` n/a
210+
``ETHTOOL_GLINKSETTINGS`` n/a
211+
``ETHTOOL_SLINKSETTINGS`` n/a
212+
``ETHTOOL_PHY_GTUNABLE`` n/a
213+
``ETHTOOL_PHY_STUNABLE`` n/a
214+
``ETHTOOL_GFECPARAM`` n/a
215+
``ETHTOOL_SFECPARAM`` n/a
216+
=================================== =====================================

Documentation/networking/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Contents:
1616
devlink-info-versions
1717
devlink-trap
1818
devlink-trap-netdevsim
19+
ethtool-netlink
1920
ieee802154
2021
j1939
2122
kapi

include/linux/ethtool_netlink.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
3+
#ifndef _LINUX_ETHTOOL_NETLINK_H_
4+
#define _LINUX_ETHTOOL_NETLINK_H_
5+
6+
#include <uapi/linux/ethtool_netlink.h>
7+
#include <linux/ethtool.h>
8+
9+
#endif /* _LINUX_ETHTOOL_NETLINK_H_ */

include/uapi/linux/ethtool_netlink.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
2+
/*
3+
* include/uapi/linux/ethtool_netlink.h - netlink interface for ethtool
4+
*
5+
* See Documentation/networking/ethtool-netlink.txt in kernel source tree for
6+
* doucumentation of the interface.
7+
*/
8+
9+
#ifndef _UAPI_LINUX_ETHTOOL_NETLINK_H_
10+
#define _UAPI_LINUX_ETHTOOL_NETLINK_H_
11+
12+
#include <linux/ethtool.h>
13+
14+
/* message types - userspace to kernel */
15+
enum {
16+
ETHTOOL_MSG_USER_NONE,
17+
18+
/* add new constants above here */
19+
__ETHTOOL_MSG_USER_CNT,
20+
ETHTOOL_MSG_USER_MAX = __ETHTOOL_MSG_USER_CNT - 1
21+
};
22+
23+
/* message types - kernel to userspace */
24+
enum {
25+
ETHTOOL_MSG_KERNEL_NONE,
26+
27+
/* add new constants above here */
28+
__ETHTOOL_MSG_KERNEL_CNT,
29+
ETHTOOL_MSG_KERNEL_MAX = __ETHTOOL_MSG_KERNEL_CNT - 1
30+
};
31+
32+
/* generic netlink info */
33+
#define ETHTOOL_GENL_NAME "ethtool"
34+
#define ETHTOOL_GENL_VERSION 1
35+
36+
#endif /* _UAPI_LINUX_ETHTOOL_NETLINK_H_ */

net/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,14 @@ config FAILOVER
449449
migration of VMs with direct attached VFs by failing over to the
450450
paravirtual datapath when the VF is unplugged.
451451

452+
config ETHTOOL_NETLINK
453+
bool "Netlink interface for ethtool"
454+
default y
455+
help
456+
An alternative userspace interface for ethtool based on generic
457+
netlink. It provides better extensibility and some new features,
458+
e.g. notification messages.
459+
452460
endif # if NET
453461

454462
# Used by archs to tell that they support BPF JIT compiler plus which flavour.

net/ethtool/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22

3-
obj-y += ioctl.o common.o
3+
obj-y += ioctl.o common.o
4+
5+
obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o
6+
7+
ethtool_nl-y := netlink.o

net/ethtool/netlink.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
3+
#include <linux/ethtool_netlink.h>
4+
#include "netlink.h"
5+
6+
/* genetlink setup */
7+
8+
static const struct genl_ops ethtool_genl_ops[] = {
9+
};
10+
11+
static struct genl_family ethtool_genl_family = {
12+
.name = ETHTOOL_GENL_NAME,
13+
.version = ETHTOOL_GENL_VERSION,
14+
.netnsok = true,
15+
.parallel_ops = true,
16+
.ops = ethtool_genl_ops,
17+
.n_ops = ARRAY_SIZE(ethtool_genl_ops),
18+
};
19+
20+
/* module setup */
21+
22+
static int __init ethnl_init(void)
23+
{
24+
int ret;
25+
26+
ret = genl_register_family(&ethtool_genl_family);
27+
if (WARN(ret < 0, "ethtool: genetlink family registration failed"))
28+
return ret;
29+
30+
return 0;
31+
}
32+
33+
subsys_initcall(ethnl_init);

net/ethtool/netlink.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
3+
#ifndef _NET_ETHTOOL_NETLINK_H
4+
#define _NET_ETHTOOL_NETLINK_H
5+
6+
#include <linux/ethtool_netlink.h>
7+
#include <linux/netdevice.h>
8+
#include <net/genetlink.h>
9+
10+
#endif /* _NET_ETHTOOL_NETLINK_H */

0 commit comments

Comments
 (0)