Skip to content

Commit db038b1

Browse files
committed
Merge branch 'ethtool-netlink-interface-part-2'
Michal Kubecek says: ==================== ethtool netlink interface, part 2 This shorter series adds support for getting and setting of wake-on-lan settings and message mask (originally message level). Together with the code already in net-next, this will allow full implementation of "ethtool <dev>" and "ethtool -s <dev> ...". Older versions of the ethtool netlink series allowed getting WoL settings by unprivileged users and only filtered out the password but this was a source of controversy so for now, ETHTOOL_MSG_WOL_GET request always requires CAP_NET_ADMIN as ETHTOOL_GWOL ioctl request does. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 82bc2e4 + 67bffa7 commit db038b1

File tree

13 files changed

+592
-34
lines changed

13 files changed

+592
-34
lines changed

Documentation/networking/ethtool-netlink.rst

Lines changed: 104 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,18 +185,26 @@ Userspace to kernel:
185185
``ETHTOOL_MSG_LINKMODES_GET`` get link modes info
186186
``ETHTOOL_MSG_LINKMODES_SET`` set link modes info
187187
``ETHTOOL_MSG_LINKSTATE_GET`` get link state
188+
``ETHTOOL_MSG_DEBUG_GET`` get debugging settings
189+
``ETHTOOL_MSG_DEBUG_SET`` set debugging settings
190+
``ETHTOOL_MSG_WOL_GET`` get wake-on-lan settings
191+
``ETHTOOL_MSG_WOL_SET`` set wake-on-lan settings
188192
===================================== ================================
189193

190194
Kernel to userspace:
191195

192-
===================================== ================================
196+
===================================== =================================
193197
``ETHTOOL_MSG_STRSET_GET_REPLY`` string set contents
194198
``ETHTOOL_MSG_LINKINFO_GET_REPLY`` link settings
195199
``ETHTOOL_MSG_LINKINFO_NTF`` link settings notification
196200
``ETHTOOL_MSG_LINKMODES_GET_REPLY`` link modes info
197201
``ETHTOOL_MSG_LINKMODES_NTF`` link modes notification
198202
``ETHTOOL_MSG_LINKSTATE_GET_REPLY`` link state info
199-
===================================== ================================
203+
``ETHTOOL_MSG_DEBUG_GET_REPLY`` debugging settings
204+
``ETHTOOL_MSG_DEBUG_NTF`` debugging settings notification
205+
``ETHTOOL_MSG_WOL_GET_REPLY`` wake-on-lan settings
206+
``ETHTOOL_MSG_WOL_NTF`` wake-on-lan settings notification
207+
===================================== =================================
200208

201209
``GET`` requests are sent by userspace applications to retrieve device
202210
information. They usually do not contain any message specific attributes.
@@ -423,6 +431,96 @@ define their own handler.
423431
devices supporting the request).
424432

425433

434+
DEBUG_GET
435+
=========
436+
437+
Requests debugging settings of a device. At the moment, only message mask is
438+
provided.
439+
440+
Request contents:
441+
442+
==================================== ====== ==========================
443+
``ETHTOOL_A_DEBUG_HEADER`` nested request header
444+
==================================== ====== ==========================
445+
446+
Kernel response contents:
447+
448+
==================================== ====== ==========================
449+
``ETHTOOL_A_DEBUG_HEADER`` nested reply header
450+
``ETHTOOL_A_DEBUG_MSGMASK`` bitset message mask
451+
==================================== ====== ==========================
452+
453+
The message mask (``ETHTOOL_A_DEBUG_MSGMASK``) is equal to message level as
454+
provided by ``ETHTOOL_GMSGLVL`` and set by ``ETHTOOL_SMSGLVL`` in ioctl
455+
interface. While it is called message level there for historical reasons, most
456+
drivers and almost all newer drivers use it as a mask of enabled message
457+
classes (represented by ``NETIF_MSG_*`` constants); therefore netlink
458+
interface follows its actual use in practice.
459+
460+
``DEBUG_GET`` allows dump requests (kernel returns reply messages for all
461+
devices supporting the request).
462+
463+
464+
DEBUG_SET
465+
=========
466+
467+
Set or update debugging settings of a device. At the moment, only message mask
468+
is supported.
469+
470+
Request contents:
471+
472+
==================================== ====== ==========================
473+
``ETHTOOL_A_DEBUG_HEADER`` nested request header
474+
``ETHTOOL_A_DEBUG_MSGMASK`` bitset message mask
475+
==================================== ====== ==========================
476+
477+
``ETHTOOL_A_DEBUG_MSGMASK`` bit set allows setting or modifying mask of
478+
enabled debugging message types for the device.
479+
480+
481+
WOL_GET
482+
=======
483+
484+
Query device wake-on-lan settings. Unlike most "GET" type requests,
485+
``ETHTOOL_MSG_WOL_GET`` requires (netns) ``CAP_NET_ADMIN`` privileges as it
486+
(potentially) provides SecureOn(tm) password which is confidential.
487+
488+
Request contents:
489+
490+
==================================== ====== ==========================
491+
``ETHTOOL_A_WOL_HEADER`` nested request header
492+
==================================== ====== ==========================
493+
494+
Kernel response contents:
495+
496+
==================================== ====== ==========================
497+
``ETHTOOL_A_WOL_HEADER`` nested reply header
498+
``ETHTOOL_A_WOL_MODES`` bitset mask of enabled WoL modes
499+
``ETHTOOL_A_WOL_SOPASS`` binary SecureOn(tm) password
500+
==================================== ====== ==========================
501+
502+
In reply, ``ETHTOOL_A_WOL_MODES`` mask consists of modes supported by the
503+
device, value of modes which are enabled. ``ETHTOOL_A_WOL_SOPASS`` is only
504+
included in reply if ``WAKE_MAGICSECURE`` mode is supported.
505+
506+
507+
WOL_SET
508+
=======
509+
510+
Set or update wake-on-lan settings.
511+
512+
Request contents:
513+
514+
==================================== ====== ==========================
515+
``ETHTOOL_A_WOL_HEADER`` nested request header
516+
``ETHTOOL_A_WOL_MODES`` bitset enabled WoL modes
517+
``ETHTOOL_A_WOL_SOPASS`` binary SecureOn(tm) password
518+
==================================== ====== ==========================
519+
520+
``ETHTOOL_A_WOL_SOPASS`` is only allowed for devices supporting
521+
``WAKE_MAGICSECURE`` mode.
522+
523+
426524
Request translation
427525
===================
428526

@@ -439,10 +537,10 @@ have their netlink replacement yet.
439537
``ETHTOOL_MSG_LINKMODES_SET``
440538
``ETHTOOL_GDRVINFO`` n/a
441539
``ETHTOOL_GREGS`` n/a
442-
``ETHTOOL_GWOL`` n/a
443-
``ETHTOOL_SWOL`` n/a
444-
``ETHTOOL_GMSGLVL`` n/a
445-
``ETHTOOL_SMSGLVL`` n/a
540+
``ETHTOOL_GWOL`` ``ETHTOOL_MSG_WOL_GET``
541+
``ETHTOOL_SWOL`` ``ETHTOOL_MSG_WOL_SET``
542+
``ETHTOOL_GMSGLVL`` ``ETHTOOL_MSG_DEBUG_GET``
543+
``ETHTOOL_SMSGLVL`` ``ETHTOOL_MSG_DEBUG_SET``
446544
``ETHTOOL_NWAY_RST`` n/a
447545
``ETHTOOL_GLINK`` ``ETHTOOL_MSG_LINKSTATE_GET``
448546
``ETHTOOL_GEEPROM`` n/a

include/linux/netdevice.h

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3913,22 +3913,48 @@ void netif_device_attach(struct net_device *dev);
39133913
*/
39143914

39153915
enum {
3916-
NETIF_MSG_DRV = 0x0001,
3917-
NETIF_MSG_PROBE = 0x0002,
3918-
NETIF_MSG_LINK = 0x0004,
3919-
NETIF_MSG_TIMER = 0x0008,
3920-
NETIF_MSG_IFDOWN = 0x0010,
3921-
NETIF_MSG_IFUP = 0x0020,
3922-
NETIF_MSG_RX_ERR = 0x0040,
3923-
NETIF_MSG_TX_ERR = 0x0080,
3924-
NETIF_MSG_TX_QUEUED = 0x0100,
3925-
NETIF_MSG_INTR = 0x0200,
3926-
NETIF_MSG_TX_DONE = 0x0400,
3927-
NETIF_MSG_RX_STATUS = 0x0800,
3928-
NETIF_MSG_PKTDATA = 0x1000,
3929-
NETIF_MSG_HW = 0x2000,
3930-
NETIF_MSG_WOL = 0x4000,
3916+
NETIF_MSG_DRV_BIT,
3917+
NETIF_MSG_PROBE_BIT,
3918+
NETIF_MSG_LINK_BIT,
3919+
NETIF_MSG_TIMER_BIT,
3920+
NETIF_MSG_IFDOWN_BIT,
3921+
NETIF_MSG_IFUP_BIT,
3922+
NETIF_MSG_RX_ERR_BIT,
3923+
NETIF_MSG_TX_ERR_BIT,
3924+
NETIF_MSG_TX_QUEUED_BIT,
3925+
NETIF_MSG_INTR_BIT,
3926+
NETIF_MSG_TX_DONE_BIT,
3927+
NETIF_MSG_RX_STATUS_BIT,
3928+
NETIF_MSG_PKTDATA_BIT,
3929+
NETIF_MSG_HW_BIT,
3930+
NETIF_MSG_WOL_BIT,
3931+
3932+
/* When you add a new bit above, update netif_msg_class_names array
3933+
* in net/ethtool/common.c
3934+
*/
3935+
NETIF_MSG_CLASS_COUNT,
39313936
};
3937+
/* Both ethtool_ops interface and internal driver implementation use u32 */
3938+
static_assert(NETIF_MSG_CLASS_COUNT <= 32);
3939+
3940+
#define __NETIF_MSG_BIT(bit) ((u32)1 << (bit))
3941+
#define __NETIF_MSG(name) __NETIF_MSG_BIT(NETIF_MSG_ ## name ## _BIT)
3942+
3943+
#define NETIF_MSG_DRV __NETIF_MSG(DRV)
3944+
#define NETIF_MSG_PROBE __NETIF_MSG(PROBE)
3945+
#define NETIF_MSG_LINK __NETIF_MSG(LINK)
3946+
#define NETIF_MSG_TIMER __NETIF_MSG(TIMER)
3947+
#define NETIF_MSG_IFDOWN __NETIF_MSG(IFDOWN)
3948+
#define NETIF_MSG_IFUP __NETIF_MSG(IFUP)
3949+
#define NETIF_MSG_RX_ERR __NETIF_MSG(RX_ERR)
3950+
#define NETIF_MSG_TX_ERR __NETIF_MSG(TX_ERR)
3951+
#define NETIF_MSG_TX_QUEUED __NETIF_MSG(TX_QUEUED)
3952+
#define NETIF_MSG_INTR __NETIF_MSG(INTR)
3953+
#define NETIF_MSG_TX_DONE __NETIF_MSG(TX_DONE)
3954+
#define NETIF_MSG_RX_STATUS __NETIF_MSG(RX_STATUS)
3955+
#define NETIF_MSG_PKTDATA __NETIF_MSG(PKTDATA)
3956+
#define NETIF_MSG_HW __NETIF_MSG(HW)
3957+
#define NETIF_MSG_WOL __NETIF_MSG(WOL)
39323958

39333959
#define netif_msg_drv(p) ((p)->msg_enable & NETIF_MSG_DRV)
39343960
#define netif_msg_probe(p) ((p)->msg_enable & NETIF_MSG_PROBE)

include/uapi/linux/ethtool.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ struct ethtool_pauseparam {
594594
* @ETH_SS_PHY_STATS: Statistic names, for use with %ETHTOOL_GPHYSTATS
595595
* @ETH_SS_PHY_TUNABLES: PHY tunable names
596596
* @ETH_SS_LINK_MODES: link mode names
597+
* @ETH_SS_MSG_CLASSES: debug message class names
598+
* @ETH_SS_WOL_MODES: wake-on-lan modes
597599
*/
598600
enum ethtool_stringset {
599601
ETH_SS_TEST = 0,
@@ -606,6 +608,8 @@ enum ethtool_stringset {
606608
ETH_SS_PHY_STATS,
607609
ETH_SS_PHY_TUNABLES,
608610
ETH_SS_LINK_MODES,
611+
ETH_SS_MSG_CLASSES,
612+
ETH_SS_WOL_MODES,
609613

610614
/* add new constants above here */
611615
ETH_SS_COUNT
@@ -1693,6 +1697,8 @@ static inline int ethtool_validate_duplex(__u8 duplex)
16931697
#define WAKE_MAGICSECURE (1 << 6) /* only meaningful if WAKE_MAGIC */
16941698
#define WAKE_FILTER (1 << 7)
16951699

1700+
#define WOL_MODE_COUNT 8
1701+
16961702
/* L2-L4 network traffic flow types */
16971703
#define TCP_V4_FLOW 0x01 /* hash or spec (tcp_ip4_spec) */
16981704
#define UDP_V4_FLOW 0x02 /* hash or spec (udp_ip4_spec) */

include/uapi/linux/ethtool_netlink.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ enum {
2020
ETHTOOL_MSG_LINKMODES_GET,
2121
ETHTOOL_MSG_LINKMODES_SET,
2222
ETHTOOL_MSG_LINKSTATE_GET,
23+
ETHTOOL_MSG_DEBUG_GET,
24+
ETHTOOL_MSG_DEBUG_SET,
25+
ETHTOOL_MSG_WOL_GET,
26+
ETHTOOL_MSG_WOL_SET,
2327

2428
/* add new constants above here */
2529
__ETHTOOL_MSG_USER_CNT,
@@ -35,6 +39,10 @@ enum {
3539
ETHTOOL_MSG_LINKMODES_GET_REPLY,
3640
ETHTOOL_MSG_LINKMODES_NTF,
3741
ETHTOOL_MSG_LINKSTATE_GET_REPLY,
42+
ETHTOOL_MSG_DEBUG_GET_REPLY,
43+
ETHTOOL_MSG_DEBUG_NTF,
44+
ETHTOOL_MSG_WOL_GET_REPLY,
45+
ETHTOOL_MSG_WOL_NTF,
3846

3947
/* add new constants above here */
4048
__ETHTOOL_MSG_KERNEL_CNT,
@@ -195,6 +203,31 @@ enum {
195203
ETHTOOL_A_LINKSTATE_MAX = __ETHTOOL_A_LINKSTATE_CNT - 1
196204
};
197205

206+
/* DEBUG */
207+
208+
enum {
209+
ETHTOOL_A_DEBUG_UNSPEC,
210+
ETHTOOL_A_DEBUG_HEADER, /* nest - _A_HEADER_* */
211+
ETHTOOL_A_DEBUG_MSGMASK, /* bitset */
212+
213+
/* add new constants above here */
214+
__ETHTOOL_A_DEBUG_CNT,
215+
ETHTOOL_A_DEBUG_MAX = __ETHTOOL_A_DEBUG_CNT - 1
216+
};
217+
218+
/* WOL */
219+
220+
enum {
221+
ETHTOOL_A_WOL_UNSPEC,
222+
ETHTOOL_A_WOL_HEADER, /* nest - _A_HEADER_* */
223+
ETHTOOL_A_WOL_MODES, /* bitset */
224+
ETHTOOL_A_WOL_SOPASS, /* binary */
225+
226+
/* add new constants above here */
227+
__ETHTOOL_A_WOL_CNT,
228+
ETHTOOL_A_WOL_MAX = __ETHTOOL_A_WOL_CNT - 1
229+
};
230+
198231
/* generic netlink info */
199232
#define ETHTOOL_GENL_NAME "ethtool"
200233
#define ETHTOOL_GENL_VERSION 1

net/ethtool/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ obj-y += ioctl.o common.o
55
obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o
66

77
ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o \
8-
linkstate.o
8+
linkstate.o debug.o wol.o

net/ethtool/common.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,37 @@ const char link_mode_names[][ETH_GSTRING_LEN] = {
171171
};
172172
static_assert(ARRAY_SIZE(link_mode_names) == __ETHTOOL_LINK_MODE_MASK_NBITS);
173173

174+
const char netif_msg_class_names[][ETH_GSTRING_LEN] = {
175+
[NETIF_MSG_DRV_BIT] = "drv",
176+
[NETIF_MSG_PROBE_BIT] = "probe",
177+
[NETIF_MSG_LINK_BIT] = "link",
178+
[NETIF_MSG_TIMER_BIT] = "timer",
179+
[NETIF_MSG_IFDOWN_BIT] = "ifdown",
180+
[NETIF_MSG_IFUP_BIT] = "ifup",
181+
[NETIF_MSG_RX_ERR_BIT] = "rx_err",
182+
[NETIF_MSG_TX_ERR_BIT] = "tx_err",
183+
[NETIF_MSG_TX_QUEUED_BIT] = "tx_queued",
184+
[NETIF_MSG_INTR_BIT] = "intr",
185+
[NETIF_MSG_TX_DONE_BIT] = "tx_done",
186+
[NETIF_MSG_RX_STATUS_BIT] = "rx_status",
187+
[NETIF_MSG_PKTDATA_BIT] = "pktdata",
188+
[NETIF_MSG_HW_BIT] = "hw",
189+
[NETIF_MSG_WOL_BIT] = "wol",
190+
};
191+
static_assert(ARRAY_SIZE(netif_msg_class_names) == NETIF_MSG_CLASS_COUNT);
192+
193+
const char wol_mode_names[][ETH_GSTRING_LEN] = {
194+
[const_ilog2(WAKE_PHY)] = "phy",
195+
[const_ilog2(WAKE_UCAST)] = "ucast",
196+
[const_ilog2(WAKE_MCAST)] = "mcast",
197+
[const_ilog2(WAKE_BCAST)] = "bcast",
198+
[const_ilog2(WAKE_ARP)] = "arp",
199+
[const_ilog2(WAKE_MAGIC)] = "magic",
200+
[const_ilog2(WAKE_MAGICSECURE)] = "magicsecure",
201+
[const_ilog2(WAKE_FILTER)] = "filter",
202+
};
203+
static_assert(ARRAY_SIZE(wol_mode_names) == WOL_MODE_COUNT);
204+
174205
/* return false if legacy contained non-0 deprecated fields
175206
* maxtxpkt/maxrxpkt. rest of ksettings always updated
176207
*/

net/ethtool/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN];
1919
extern const char
2020
phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN];
2121
extern const char link_mode_names[][ETH_GSTRING_LEN];
22+
extern const char netif_msg_class_names[][ETH_GSTRING_LEN];
23+
extern const char wol_mode_names[][ETH_GSTRING_LEN];
2224

2325
int __ethtool_get_link(struct net_device *dev);
2426

0 commit comments

Comments
 (0)