ethtool netlink interface, part 1
Subsystems (4)
v8 cover ethtool netlink interface, part 1
This is first part of netlink based alternative userspace interface for ethtool. It aims to address some long known issues with the ioctl interface, mainly lack of extensibility, raciness, limited error reporting and absence of notifications. The goal is to allow userspace ethtool utility to provide all features it currently does but without using the ioctl interface. However, some features provided by ethtool ioctl API will be available through other netlink interfaces (rtnetlink, devlink) if it's more appropriate.
The interface uses generic netlink family "ethtool" and provides multicast group "monitor" which is used for notifications. Documentation for the interface is in Documentation/networking/ethtool-netlink.rst file. The netlink interface is optional, it is built when CONFIG_ETHTOOL_NETLINK (bool) option is enabled.
There are three types of request messages distinguished by suffix "_GET" (query for information), "_SET" (modify parameters) and "_ACT" (perform an action). Kernel reply messages have name with additional suffix "_REPLY" (e.g. ETHTOOL_MSG_SETTINGS_GET_REPLY). Most "_SET" and "_ACT" message types do not have matching reply type as only some of them need additional reply data beyond numeric error code and extack. Kernel also broadcasts notification messages ("_NTF" suffix) on changes.
Basic concepts:
- make extensions easier not only by allowing new attributes but also by imposing as few artificial limits as possible, e.g. by using arbitrary size bit sets for most bitmap attributes or by not using fixed size strings
- use extack for error reporting and warnings
- send netlink notifications on changes (even if they were done using the ioctl interface) and actions
- avoid the racy read/modify/write cycle between kernel and userspace by sending only attributes which userspace wants to change; there is still a read/modify/write cycle between generic kernel code and ethtool_ops handler in NIC driver but it is only in kernel and under RTNL lock
- reduce the number of name lists that need to be kept in sync between kernel and userspace (e.g. recognized link modes)
- where feasible, allow dump requests to query specific information for all network devices
- as parsing and generating netlink messages is more complicated than simply copying data structures between userspace API and ethtool_ops handlers (which most ioctl commands do), split the code into multiple files in net/ethtool directory; move net/core/ethtool.c also to this directory and rename it to ioctl.c
Main changes between v7 and v8:
- preliminary patches sent as a separate series (already in net-next)
- split notification related changes out of _SET patches
- drop request specific flags from common header
- use FLAG/flag rather than GFLAG/gflag for global flags (as there are only global flags now)
- allow device names up to ALTIFNAMSIZ characters
- rename ETHTOOL_A_BITSET_LIST to ETHTOOL_A_BITSET_NOMASK
- rename ETHTOOL_A_BIT{,S}_* to ETHTOOL_A_BITSET_BIT{,S}_*
- use standard bitset helpers for link modes (rather than in-place conversion)
- use "default" rather than "standard" for unified _GET handlers
- fixed 64-bit big endian bitset code
Main changes between v6 and v7:
- split complex messages into small single purpose ones (drop info and request masks and one level of nesting)
- separate request information and reply data into two structures
- refactor bitset handling (no simultaneous u32/ulong handling but avoid kmalloc() except for long bitmaps on 64-bit big endian architectures)
- use only fixed size strings internally (will be replaced by char * eventually but that will require rewriting also existing ioctl code)
- rework ethnl_update_* helpers to return error code
- rename request flag constants (to ETHTOOL_[GR]FLAG_ prefix)
- convert documentation to rst
Main changes between v5 and v6:
- use ETHTOOL_MSG_ prefix for message types
- replace ETHA_ prefix for netlink attributes by ETHTOOL_A_
- replace ETH_x_IM_y for infomask bits by ETHTOOL_IM_x_y
- split GET reply types from SET requests and notifications
- split kernel and userspace message types into different enums
- remove INFO_GET requests from submitted part
- drop EVENT notifications (use rtnetlink and on-demand string set load)
- reorganize patches to reduce the number of intermitent warnings
- unify request/reply header and its processing
- another nest around strings in a string set for consistency
- more consistent identifier naming
- coding style cleanup
- get rid of some of the helpers
- set bad attribute in extack where applicable
- various bug fixes
- improve documentation and code comments, more kerneldoc comments
- more verbose commit messages
Changes between v4 and v5:
- do not panic on failed initialization, only WARN()
Main changes between RFC v3 and v4:
- use more kerneldoc style comments
- strict attribute policy checking
- use macros for tables of link mode names and parameters
- provide permanent hardware address in rtnetlink
- coding style cleanup
- split too long patches, reorder
- wrap more ETHA_SETTINGS_* attributes in nests
- add also some SET_* implementation into submitted part
Main changes between RFC v2 and RFC v3:
- do not allow building as a module (no netdev notifiers needed)
- drop some obsolete fields
- add permanent hw address, timestamping and private flags support
- rework bitset handling to get rid of variable length arrays
- notify monitor on device renames
- restructure GET_SETTINGS/SET_SETTINGS messages
- split too long patches and submit only first part of the series
Main changes between RFC v1 and RFC v2:
- support dumps for all "get" requests
- provide notifications for changes related to supported request types
- support getting string sets (both global and per device)
- support getting/setting device features
- get rid of family specific header, everything passed as attributes
- split netlink code into multiple files in net/ethtool/ directory
Michal Kubecek (14):
ethtool: introduce ethtool netlink interface
ethtool: helper functions for netlink interface
ethtool: netlink bitset handling
ethtool: support for netlink notifications
ethtool: default handlers for GET requests
ethtool: provide string sets with STRSET_GET request
ethtool: provide link settings with LINKINFO_GET request
ethtool: set link settings with LINKINFO_SET request
ethtool: add default notification handler
ethtool: add LINKINFO_NTF notification
ethtool: provide link mode information with LINKMODES_GET request
ethtool: set link modes related data with LINKMODES_SET request
ethtool: add LINKMODES_NTF notification
ethtool: provide link state with LINKSTATE_GET request
Documentation/networking/ethtool-netlink.rst | 510 +++++++++++++ include/linux/ethtool_netlink.h | 17 + include/linux/netdevice.h | 9 + include/uapi/linux/ethtool.h | 3 + include/uapi/linux/ethtool_netlink.h | 204 +++++ net/Kconfig | 8 + net/ethtool/Makefile | 7 +- net/ethtool/bitset.c | 735 +++++++++++++++++++ net/ethtool/bitset.h | 28 + net/ethtool/common.c | 56 ++ net/ethtool/common.h | 7 + net/ethtool/ioctl.c | 72 +- net/ethtool/linkinfo.c | 167 +++++ net/ethtool/linkmodes.c | 377 ++++++++++ net/ethtool/linkstate.c | 74 ++ net/ethtool/netlink.c | 687 +++++++++++++++++ net/ethtool/netlink.h | 341 +++++++++ net/ethtool/strset.c | 425 +++++++++++ 18 files changed, 3672 insertions(+), 55 deletions(-) create mode 100644 Documentation/networking/ethtool-netlink.rst create mode 100644 include/linux/ethtool_netlink.h create mode 100644 include/uapi/linux/ethtool_netlink.h create mode 100644 net/ethtool/bitset.c create mode 100644 net/ethtool/bitset.h create mode 100644 net/ethtool/linkinfo.c create mode 100644 net/ethtool/linkmodes.c create mode 100644 net/ethtool/linkstate.c create mode 100644 net/ethtool/netlink.c create mode 100644 net/ethtool/netlink.h create mode 100644 net/ethtool/strset.c
Signature · 1 line
2.24.1
PATCH v8 1/14 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.
--- Documentation/networking/ethtool-netlink.rst | 215 +++++++++++++++++++ include/linux/ethtool_netlink.h | 9 + include/uapi/linux/ethtool_netlink.h | 36 ++++ net/Kconfig | 8 + net/ethtool/Makefile | 6 +- net/ethtool/netlink.c | 33 +++ net/ethtool/netlink.h | 10 + 7 files changed, 316 insertions(+), 1 deletion(-) create mode 100644 Documentation/networking/ethtool-netlink.rst create mode 100644 include/linux/ethtool_netlink.h create mode 100644 include/uapi/linux/ethtool_netlink.h create mode 100644 net/ethtool/netlink.c create mode 100644 net/ethtool/netlink.h
Documentation/networking/ethtool-netlink.rst new file +215 -0
@@ -0,0 +1,215 @@ +============================= +Netlink interface for ethtool +============================= + + +Basic information +================= + +Netlink interface for ethtool uses generic netlink family ``ethtool`` +(userspace application should use macros ``ETHTOOL_GENL_NAME`` and +``ETHTOOL_GENL_VERSION`` defined in ``<linux/ethtool_netlink.h>`` uapi +header). This family does not use a specific header, all information in +requests and replies is passed using netlink attributes. + +The ethtool netlink interface uses extended ACK for error and warning +reporting, userspace application developers are encouraged to make these +messages available to user in a suitable way. + +Requests can be divided into three categories: "get" (retrieving information), +"set" (setting parameters) and "action" (invoking an action). + +All "set" and "action" type requests require admin privileges +(``CAP_NET_ADMIN`` in the namespace). Most "get" type requests are allowed for +anyone but there are exceptions (where the response contains sensitive +information). In some cases, the request as such is allowed for anyone but +unprivileged users have attributes with sensitive information (e.g. +wake-on-lan password) omitted. + + +Conventions +=========== + +Attributes which represent a boolean value usually use u8 type so that we can +distinguish three states: "on", "off" and "not present" (meaning the +information is not available in "get" requests or value is not to be changed +in "set" requests). For these attributes, the "true" value should be passed as +number 1 but any non-zero value should be understood as "true" by recipient. + +In the message structure descriptions below, if an attribute name is suffixed +with "+", parent nest can contain multiple attributes of the same type. This +implements an array of entries. + + +Request header +============== + +Each request or reply message contains a nested attribute with common header. +Structure of this header is + + ============================== ====== ============================= + ``ETHTOOL_A_HEADER_DEV_INDEX`` u32 device ifindex + ``ETHTOOL_A_HEADER_DEV_NAME`` string device name + ``ETHTOOL_A_HEADER_FLAGS`` u32 flags common for all requests + ============================== ====== ============================= + +``ETHTOOL_A_HEADER_DEV_INDEX`` and ``ETHTOOL_A_HEADER_DEV_NAME`` identify the +device message relates to. One of them is sufficient in requests, if both are +used, they must identify the same device. Some requests, e.g. global string +sets, do not require device identification. Most ``GET`` requests also allow +dump requests without device identification to query the same information for +all devices providing it (each device in a separate message). + +``ETHTOOL_A_HEADER_FLAGS`` is a bitmap of request flags common for all request +types. The interpretation of these flags is the same for all request types but +the flags may not apply to requests. Recognized flags are: + + ================================= =================================== + ``ETHTOOL_FLAG_COMPACT_BITSETS`` use compact format bitsets in reply + ``ETHTOOL_FLAG_OMIT_REPLY`` omit optional reply (_SET and _ACT) + ================================= =================================== + +New request flags should follow the general idea that if the flag is not set, +the behaviour is backward compatible, i.e. requests from old clients not aware +of the flag should be interpreted the way the client expects. A client must +not set flags it does not understand. + + +List of message types +===================== + +All constants identifying message types use ``ETHTOOL_CMD_`` prefix and suffix +according to message purpose: + + ============== ====================================== + ``_GET`` userspace request to retrieve data + ``_SET`` userspace request to set data + ``_ACT`` userspace request to perform an action + ``_GET_REPLY`` kernel reply to a ``GET`` request + ``_SET_REPLY`` kernel reply to a ``SET`` request + ``_ACT_REPLY`` kernel reply to an ``ACT`` request + ``_NTF`` kernel notification + ============== ====================================== + +``GET`` requests are sent by userspace applications to retrieve device +information. They usually do not contain any message specific attributes. +Kernel replies with corresponding "GET_REPLY" message. For most types, ``GET`` +request with ``NLM_F_DUMP`` and no device identification can be used to query +the information for all devices supporting the request. + +If the data can be also modified, corresponding ``SET`` message with the same +layout as corresponding ``GET_REPLY`` is used to request changes. Only +attributes where a change is requested are included in such request (also, not +all attributes may be changed). Replies to most ``SET`` request consist only +of error code and extack; if kernel provides additional data, it is sent in +the form of corresponding ``SET_REPLY`` message which can be suppressed by +setting ``ETHTOOL_FLAG_OMIT_REPLY`` flag in request header. + +Data modification also triggers sending a ``NTF`` message with a notification. +These usually bear only a subset of attributes which was affected by the +change. The same notification is issued if the data is modified using other +means (mostly ioctl ethtool interface). Unlike notifications from ethtool +netlink code which are only sent if something actually changed, notifications +triggered by ioctl interface may be sent even if the request did not actually +change any data. + +``ACT`` messages request kernel (driver) to perform a specific action. If some +information is reported by kernel (which can be suppressed by setting +``ETHTOOL_FLAG_OMIT_REPLY`` flag in request header), the reply takes form of +an ``ACT_REPLY`` message. Performing an action also triggers a notification +(``NTF`` message). + +Later sections describe the format and semantics of these messages. + + +Request translation +=================== + +The following table maps ioctl commands to netlink commands providing their +functionality. Entries with "n/a" in right column are commands which do not +have their netlink replacement yet. + + =================================== ===================================== + ioctl command netlink command + =================================== ===================================== + ``ETHTOOL_GSET`` n/a + ``ETHTOOL_SSET`` n/a + ``ETHTOOL_GDRVINFO`` n/a + ``ETHTOOL_GREGS`` n/a + ``ETHTOOL_GWOL`` n/a + ``ETHTOOL_SWOL`` n/a + ``ETHTOOL_GMSGLVL`` n/a + ``ETHTOOL_SMSGLVL`` n/a + ``ETHTOOL_NWAY_RST`` n/a + ``ETHTOOL_GLINK`` n/a + ``ETHTOOL_GEEPROM`` n/a + ``ETHTOOL_SEEPROM`` n/a + ``ETHTOOL_GCOALESCE`` n/a + ``ETHTOOL_SCOALESCE`` n/a + ``ETHTOOL_GRINGPARAM`` n/a + ``ETHTOOL_SRINGPARAM`` n/a + ``ETHTOOL_GPAUSEPARAM`` n/a + ``ETHTOOL_SPAUSEPARAM`` n/a + ``ETHTOOL_GRXCSUM`` n/a + ``ETHTOOL_SRXCSUM`` n/a + ``ETHTOOL_GTXCSUM`` n/a + ``ETHTOOL_STXCSUM`` n/a + ``ETHTOOL_GSG`` n/a + ``ETHTOOL_SSG`` n/a + ``ETHTOOL_TEST`` n/a + ``ETHTOOL_GSTRINGS`` n/a + ``ETHTOOL_PHYS_ID`` n/a + ``ETHTOOL_GSTATS`` n/a + ``ETHTOOL_GTSO`` n/a + ``ETHTOOL_STSO`` n/a + ``ETHTOOL_GPERMADDR`` rtnetlink ``RTM_GETLINK`` + ``ETHTOOL_GUFO`` n/a + ``ETHTOOL_SUFO`` n/a + ``ETHTOOL_GGSO`` n/a + ``ETHTOOL_SGSO`` n/a + ``ETHTOOL_GFLAGS`` n/a + ``ETHTOOL_SFLAGS`` n/a + ``ETHTOOL_GPFLAGS`` n/a + ``ETHTOOL_SPFLAGS`` n/a + ``ETHTOOL_GRXFH`` n/a + ``ETHTOOL_SRXFH`` n/a + ``ETHTOOL_GGRO`` n/a + ``ETHTOOL_SGRO`` n/a + ``ETHTOOL_GRXRINGS`` n/a + ``ETHTOOL_GRXCLSRLCNT`` n/a + ``ETHTOOL_GRXCLSRULE`` n/a + ``ETHTOOL_GRXCLSRLALL`` n/a + ``ETHTOOL_SRXCLSRLDEL`` n/a + ``ETHTOOL_SRXCLSRLINS`` n/a + ``ETHTOOL_FLASHDEV`` n/a + ``ETHTOOL_RESET`` n/a + ``ETHTOOL_SRXNTUPLE`` n/a + ``ETHTOOL_GRXNTUPLE`` n/a + ``ETHTOOL_GSSET_INFO`` n/a + ``ETHTOOL_GRXFHINDIR`` n/a + ``ETHTOOL_SRXFHINDIR`` n/a + ``ETHTOOL_GFEATURES`` n/a + ``ETHTOOL_SFEATURES`` n/a + ``ETHTOOL_GCHANNELS`` n/a + ``ETHTOOL_SCHANNELS`` n/a + ``ETHTOOL_SET_DUMP`` n/a + ``ETHTOOL_GET_DUMP_FLAG`` n/a + ``ETHTOOL_GET_DUMP_DATA`` n/a + ``ETHTOOL_GET_TS_INFO`` n/a + ``ETHTOOL_GMODULEINFO`` n/a + ``ETHTOOL_GMODULEEEPROM`` n/a + ``ETHTOOL_GEEE`` n/a + ``ETHTOOL_SEEE`` n/a + ``ETHTOOL_GRSSH`` n/a + ``ETHTOOL_SRSSH`` n/a + ``ETHTOOL_GTUNABLE`` n/a + ``ETHTOOL_STUNABLE`` n/a + ``ETHTOOL_GPHYSTATS`` n/a + ``ETHTOOL_PERQUEUE`` n/a + ``ETHTOOL_GLINKSETTINGS`` n/a + ``ETHTOOL_SLINKSETTINGS`` n/a + ``ETHTOOL_PHY_GTUNABLE`` n/a + ``ETHTOOL_PHY_STUNABLE`` n/a + ``ETHTOOL_GFECPARAM`` n/a + ``ETHTOOL_SFECPARAM`` n/a + =================================== =====================================
include/linux/ethtool_netlink.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _LINUX_ETHTOOL_NETLINK_H_ +#define _LINUX_ETHTOOL_NETLINK_H_ + +#include <uapi/linux/ethtool_netlink.h> +#include <linux/ethtool.h> + +#endif /* _LINUX_ETHTOOL_NETLINK_H_ */
include/uapi/linux/ethtool_netlink.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ +/* +* include/uapi/linux/ethtool_netlink.h - netlink interface for ethtool +* +* See Documentation/networking/ethtool-netlink.txt in kernel source tree for +* doucumentation of the interface. +*/ + +#ifndef _UAPI_LINUX_ETHTOOL_NETLINK_H_ +#define _UAPI_LINUX_ETHTOOL_NETLINK_H_ + +#include <linux/ethtool.h> + +/* message types - userspace to kernel */ +enum { +ETHTOOL_MSG_USER_NONE , + +/* add new constants above here */ + __ETHTOOL_MSG_USER_CNT, +ETHTOOL_MSG_USER_MAX = __ETHTOOL_MSG_USER_CNT -1 +}; + +/* message types - kernel to userspace */ +enum { +ETHTOOL_MSG_KERNEL_NONE , + +/* add new constants above here */ + __ETHTOOL_MSG_KERNEL_CNT, +ETHTOOL_MSG_KERNEL_MAX = __ETHTOOL_MSG_KERNEL_CNT -1 +}; + +/* generic netlink info */ +#define ETHTOOL_GENL_NAME "ethtool" +#define ETHTOOL_GENL_VERSION 1 + +#endif /* _UAPI_LINUX_ETHTOOL_NETLINK_H_ */
net/Kconfig +8 -0
@@ -448,6 +448,14 @@ config FAILOVER migration of VMs with direct attached VFs by failing over to the paravirtual datapath when the VF is unplugged. +config ETHTOOL_NETLINK + bool "Netlink interface for ethtool" + default y + help + An alternative userspace interface for ethtool based on generic + netlink. It provides better extensibility and some new features, + e.g. notification messages. + endif # if NET # Used by archs to tell that they support BPF JIT compiler plus which flavour.
net/ethtool/Makefile +5 -1
@@ -1,3 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y += ioctl.o common.o +obj-y += ioctl.o common.o + +obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o + +ethtool_nl-y := netlink.o
net/ethtool/netlink.c new file +33 -0
@@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <linux/ethtool_netlink.h> +#include "netlink.h" + +/* genetlink setup */ + +static const struct genl_ops ethtool_genl_ops[] = { +}; + +static struct genl_family ethtool_genl_family = { + .name =ETHTOOL_GENL_NAME , + .version =ETHTOOL_GENL_VERSION , + .netnsok = true, + .parallel_ops = true, + .ops = ethtool_genl_ops, + .n_ops =ARRAY_SIZE (ethtool_genl_ops), +}; + +/* module setup */ + +static int __init ethnl_init (void ) +{ +int ret; + + ret =genl_register_family (ðtool_genl_family); +if (WARN (ret <0 ,"ethtool: genetlink family registration failed" )) +return ret; + +return 0 ; +} + +subsys_initcall (ethnl_init);
net/ethtool/netlink.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _NET_ETHTOOL_NETLINK_H +#define _NET_ETHTOOL_NETLINK_H + +#include <linux/ethtool_netlink.h> +#include <linux/netdevice.h> +#include <net/genetlink.h> + +#endif /* _NET_ETHTOOL_NETLINK_H */
Signature · 1 line
2.24.1
Re: [PATCH net-next v8 01/14] ethtool: introduce ethtool netlink interface
Quoted 7 lines · Michal Kubecek
Basic genetlink and init infrastructure for the netlink interface, register genetlink family "ethtool". Add
CONFIG_ETHTOOL_NETLINKKconfigoption to make the build optional. Add initial overall interface description intoDocumentation/networking/ethtool-netlink.rst, further patches will add more detailed information.Signed-off-by Michal Kubecek <[email protected]>
Signature · 1 line
Florian
Re: [PATCH net-next v8 01/14] ethtool: introduce ethtool netlink interface
In reply to Michal KubecekQuoted 7 lines · Michal Kubecek
Basic genetlink and init infrastructure for the netlink interface, register genetlink family "ethtool". Add
CONFIG_ETHTOOL_NETLINKKconfigoption to make the build optional. Add initial overall interface description intoDocumentation/networking/ethtool-netlink.rst, further patches will add more detailed information.Signed-off-by Michal Kubecek <[email protected]>
Andrew
PATCH v8 2/14 ethtool: helper functions for netlink interface
In reply to Michal KubecekAdd common request/reply header definition and helpers to parse request header and fill reply header. Provide ethnl_update_* helpers to update structure members from request attributes (to be used for *_SET requests).
--- include/uapi/linux/ethtool_netlink.h | 21 +++ net/ethtool/netlink.c | 166 ++++++++++++++++++++++ net/ethtool/netlink.h | 205 +++++++++++++++++++++++++++ 3 files changed, 392 insertions(+)
include/uapi/linux/ethtool_netlink.h +21 -0
@@ -29,6 +29,27 @@ enum { ETHTOOL_MSG_KERNEL_MAX = __ETHTOOL_MSG_KERNEL_CNT - 1 }; +/* request header */ + +/* use compact bitsets in reply */ +#define ETHTOOL_FLAG_COMPACT_BITSETS (1 << 0) +/* provide optional reply for SET or ACT requests */ +#define ETHTOOL_FLAG_OMIT_REPLY (1 << 1) + +#define ETHTOOL_FLAG_ALL (ETHTOOL_FLAG_COMPACT_BITSETS | \ + ETHTOOL_FLAG_OMIT_REPLY) + +enum { +ETHTOOL_A_HEADER_UNSPEC , +ETHTOOL_A_HEADER_DEV_INDEX ,/* u32 */ +ETHTOOL_A_HEADER_DEV_NAME ,/* string */ +ETHTOOL_A_HEADER_FLAGS ,/* u32 - ETHTOOL_FLAG_* */ + +/* add new constants above here */ + __ETHTOOL_A_HEADER_CNT, +ETHTOOL_A_HEADER_MAX = __ETHTOOL_A_HEADER_CNT -1 +}; +/* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool"#define ETHTOOL_GENL_VERSION 1
net/ethtool/netlink.c +166 -0
174 lines not on this page · raw message
net/ethtool/netlink.h +205 -0
210 lines not on this page · raw message
Signature · 1 line
2.24.1
Re: [PATCH net-next v8 02/14] ethtool: helper functions for netlink interface
Quoted 6 lines · Michal Kubecek
Add common request/reply header definition and helpers to parse request header and fill reply header. Provide ethnl_update_* helpers to update structure members from request attributes (to be used for
*_SETrequests).Signed-off-by Michal Kubecek <[email protected]>---
[snip]
Quoted 11 lines
+/**
+ *ethnl_update_u32()- update u32 value fromNLA_U32attribute
+ * @dst: value to update
+ * @attr: netlink attribute with new value or null
+ * @mod: pointer to bool for modification tracking
+ *
+ * Copy the u32 value fromNLA_U32netlink attribute @attr into variable
+ * pointed to by @dst; do nothing if @attr is null. Bool pointed to by @mod
+ * is set to true if this function changed the value of *dst, otherwise it
+ * is left as is.
+ */
I would find it more intuitive if an integer was returned: < 0 in case of error, 0 if no change and 1 if something changed.
Quoted 24 lines
net/ethtool/netlink.h +24
-0+static inline void ethnl_update_u32 (u32 *dst,const struct nlattr *attr, +bool *mod) +{ +u32 val; + +if (!attr) +return ; + val =nla_get_u32 (attr); +if (*dst == val) +return ; + + *dst = val; + *mod = true; +} + +/** +* ethnl_update_u8() - update u8 value from NLA_U8 attribute +* @dst: value to update +* @attr: netlink attribute with new value or null +* @mod: pointer to bool for modification tracking +* +* Copy the u8 value from NLA_U8 netlink attribute @attr into variable +* pointed to by @dst; do nothing if @attr is null. Bool pointed to by @mod +* is set to true if this function changed the value of *dst, otherwise it
net/ethtool/netlink.h line 102
Quoted 10 lines
net/ethtool/netlink.h +10
-0+* is left as is. +*/ +static inline void ethnl_update_u8 (u8 *dst,const struct nlattr *attr, +bool *mod) +{ +u8 val; + +if (!attr) +return ; + val =nla_get_u32 (attr);
Should not this be nla_get_u8() here? This sounds like it is going to break on BE machines.
Signature · 1 line
Florian
Re: [PATCH net-next v8 02/14] ethtool: helper functions for netlink interface
Quoted 24 lines · Florian Fainelli
Quoted 6 lines · Michal Kubecek
Add common request/reply header definition and helpers to parse request header and fill reply header. Provide ethnl_update_* helpers to update structure members from request attributes (to be used for
*_SETrequests).Signed-off-by Michal Kubecek <[email protected]>---
[snip]
Quoted 11 lines
+/**
+ *ethnl_update_u32()- update u32 value fromNLA_U32attribute
+ * @dst: value to update
+ * @attr: netlink attribute with new value or null
+ * @mod: pointer to bool for modification tracking
+ *
+ * Copy the u32 value fromNLA_U32netlink attribute @attr into variable
+ * pointed to by @dst; do nothing if @attr is null. Bool pointed to by @mod
+ * is set to true if this function changed the value of *dst, otherwise it
+ * is left as is.
+ */
Quoted 2 lines
I would find it more intuitive if an integer was returned: < 0 in case of error, 0 if no change and 1 if something changed.
This trick allows simpler code on caller side when we update multiple values in a structure - we don't have to check each return value separately (most update helpers cannot fail). It was a suggestion from Jiri Pirko in one of earlier discussions.
Quoted 29 lines
Quoted 29 lines
net/ethtool/netlink.h +29
-0+static inline void ethnl_update_u32 (u32 *dst,const struct nlattr *attr, +bool *mod) +{ +u32 val; + +if (!attr) +return ; + val =nla_get_u32 (attr); +if (*dst == val) +return ; + + *dst = val; + *mod = true; +} + +/** +* ethnl_update_u8() - update u8 value from NLA_U8 attribute +* @dst: value to update +* @attr: netlink attribute with new value or null +* @mod: pointer to bool for modification tracking +* +* Copy the u8 value from NLA_U8 netlink attribute @attr into variable +* pointed to by @dst; do nothing if @attr is null. Bool pointed to by @mod +* is set to true if this function changed the value of *dst, otherwise it +* is left as is. +*/ +static inline void ethnl_update_u8 (u8 *dst,const struct nlattr *attr, +bool *mod) +{
Quoted 8 lines
net/ethtool/netlink.h line 102
Quoted 5 lines
net/ethtool/netlink.h +5
-0+u8 val; + +if (!attr) +return ; + val =nla_get_u32 (attr);Should not this be
nla_get_u8()here? This sounds like it is going to break on BE machines.
Good catch, thank you. I originally wanted to use NLA_U32 for all numeric values (as NLA_U8 and NLA_U16 don't save any space anyway) but then changed those in LINKINFO_GET request to NLA_U8 and forgot to fix the helper function.
I'll fix this in v9.
Michal
PATCH v8 3/14 ethtool: netlink bitset handling
In reply to Michal KubecekThe ethtool netlink code uses common framework for passing arbitrary length bit sets to allow future extensions. A bitset can be a list (only one bitmap) or can consist of value and mask pair (used e.g. when client want to modify only some bits). A bitset can use one of two formats:
verbose (bit by bit) or compact.
Verbose format consists of bitset size (number of bits), list flag and an array of bit nests, telling which bits are part of the list or which bits are in the mask and which of them are to be set. In requests, bits can be identified by index (position) or by name. In replies, kernel provides both index and name. Verbose format is suitable for "one shot" applications like standard ethtool command as it avoids the need to either keep bit names (e.g. link modes) in sync with kernel or having to add an extra roundtrip for string set request (e.g. for private flags).
Compact format uses one (list) or two (value/mask) arrays of 32-bit words to store the bitmap(s). It is more suitable for long running applications (ethtool in monitor mode or network management daemons) which can retrieve the names once and then pass only compact bitmaps to save space.
Userspace requests can use either format; ETHTOOL_FLAG_COMPACT_BITSETS flag in request header tells kernel which format to use in reply. Notifications always use compact format.
As some code uses arrays of unsigned long for internal representation and some arrays of u32 (or even a single u32), two sets of parse/compose helpers are introduced. To avoid code duplication, helpers for unsigned long arrays are implemented as wrappers around helpers for u32 arrays. There are two reasons for this choice: (1) u32 arrays are more frequent in ethtool code and (2) unsigned long array can be always interpreted as an u32 array on little endian 64-bit and all 32-bit architectures while we would need special handling for odd number of u32 words in the opposite direction.
--- Documentation/networking/ethtool-netlink.rst | 75 ++ include/uapi/linux/ethtool_netlink.h | 35 + net/ethtool/Makefile | 2 +- net/ethtool/bitset.c | 735 +++++++++++++++++++ net/ethtool/bitset.h | 28 + 5 files changed, 874 insertions(+), 1 deletion(-) create mode 100644 net/ethtool/bitset.c create mode 100644 net/ethtool/bitset.h
Documentation/networking/ethtool-netlink.rst +75 -0
@@ -75,6 +75,81 @@ of the flag should be interpreted the way the client expects. A client must not set flags it does not understand. +Bit sets +======== + +For short bitmaps of (reasonably) fixed length, standard ``NLA_BITFIELD32`` +type is used. For arbitrary length bitmaps, ethtool netlink uses a nested +attribute with contents of one of two forms: compact (two binary bitmaps +representing bit values and mask of affected bits) and bit-by-bit (list of +bits identified by either index or name). + +A bitset can represent either a value/mask pair (``ETHTOOL_A_BITSET_NOMASK`` +not set) or a single bitmap (``ETHTOOL_A_BITSET_NOMASK`` set). In requests +modifying a bitmap, the former changes the bit set in mask to values set in +value and preserves the rest; the latter sets the bits set in the bitmap and +clears the rest. + +Compact form: nested (bitset) atrribute contents: + + ============================ ====== ============================ + ``ETHTOOL_A_BITSET_NOMASK`` flag no mask, only a list + ``ETHTOOL_A_BITSET_SIZE`` u32 number of significant bits + ``ETHTOOL_A_BITSET_VALUE`` binary bitmap of bit values + ``ETHTOOL_A_BITSET_MASK`` binary bitmap of valid bits + ============================ ====== ============================ + +Value and mask must have length at least ``ETHTOOL_A_BITSET_SIZE`` bits +rounded up to a multiple of 32 bits. They consist of 32-bit words in host byte +order, words ordered from least significant to most significant (i.e. the same +way as bitmaps are passed with ioctl interface). + +For compact form, ``ETHTOOL_A_BITSET_SIZE`` and ``ETHTOOL_A_BITSET_VALUE`` are +mandatory. ``ETHTOOL_A_BITSET_MASK`` attribute is mandatory if +``ETHTOOL_A_BITSET_NOMASK`` is not set (bitset represents a value/mask pair); +if ``ETHTOOL_A_BITSET_NOMASK`` is not set, ``ETHTOOL_A_BITSET_MASK`` is not +allowed (bitset represents a single bitmap. + +Kernel bit set length may differ from userspace length if older application is +used on newer kernel or vice versa. If userspace bitmap is longer, an error is +issued only if the request actually tries to set values of some bits not +recognized by kernel. + +Bit-by-bit form: nested (bitset) attribute contents: + + +------------------------------------+--------+-----------------------------+ + | ``ETHTOOL_A_BITSET_NOMASK`` | flag | no mask, only a list | + +------------------------------------+--------+-----------------------------+ + | ``ETHTOOL_A_BITSET_SIZE`` | u32 | number of significant bits | + +------------------------------------+--------+-----------------------------+ + | ``ETHTOOL_A_BITSET_BITS`` | nested | array of bits | + +-+----------------------------------+--------+-----------------------------+ + | | ``ETHTOOL_A_BITSET_BITS_BIT+`` | nested | one bit | + +-+-+--------------------------------+--------+-----------------------------+ + | | | ``ETHTOOL_A_BITSET_BIT_INDEX`` | u32 | bit index (0 for LSB) | + +-+-+--------------------------------+--------+-----------------------------+ + | | | ``ETHTOOL_A_BITSET_BIT_NAME`` | string | bit name | + +-+-+--------------------------------+--------+-----------------------------+ + | | | ``ETHTOOL_A_BITSET_BIT_VALUE`` | flag | present if bit is set | + +-+-+--------------------------------+--------+-----------------------------+ + +Bit size is optional for bit-by-bit form. ``ETHTOOL_A_BITSET_BITS`` nest can +only contain ``ETHTOOL_A_BITSET_BITS_BIT`` attributes but there can be an +arbitrary number of them. A bit may be identified by its index or by its +name. When used in requests, listed bits are set to 0 or 1 according to +``ETHTOOL_A_BITSET_BIT_VALUE``, the rest is preserved. A request fails if +index exceeds kernel bit length or if name is not recognized. + +When ``ETHTOOL_A_BITSET_NOMASK`` flag is present, bitset is interpreted as +a simple bitmap. ``ETHTOOL_A_BITSET_BIT_VALUE`` attributes are not used in +such case. Such bitset represents a bitmap with listed bits set and the rest +zero. + +In requests, application can use either form. Form used by kernel in reply is +determined by ``ETHTOOL_FLAG_COMPACT_BITSETS`` flag in flags field of request +header. Semantics of value and mask depends on the attribute. + + List of message types =====================
include/uapi/linux/ethtool_netlink.h +35 -0
@@ -50,6 +50,41 @@ enum { ETHTOOL_A_HEADER_MAX = __ETHTOOL_A_HEADER_CNT - 1 }; +/* bit sets */ + +enum { +ETHTOOL_A_BITSET_BIT_UNSPEC , +ETHTOOL_A_BITSET_BIT_INDEX ,/* u32 */ +ETHTOOL_A_BITSET_BIT_NAME ,/* string */ +ETHTOOL_A_BITSET_BIT_VALUE ,/* flag */ + +/* add new constants above here */ + __ETHTOOL_A_BITSET_BIT_CNT, +ETHTOOL_A_BITSET_BIT_MAX = __ETHTOOL_A_BITSET_BIT_CNT -1 +}; + +enum { +ETHTOOL_A_BITSET_BITS_UNSPEC , +ETHTOOL_A_BITSET_BITS_BIT ,/* nest - _A_BITSET_BIT_* */ + +/* add new constants above here */ + __ETHTOOL_A_BITSET_BITS_CNT, +ETHTOOL_A_BITSET_BITS_MAX = __ETHTOOL_A_BITSET_BITS_CNT -1 +}; + +enum { +ETHTOOL_A_BITSET_UNSPEC , +ETHTOOL_A_BITSET_NOMASK ,/* flag */ +ETHTOOL_A_BITSET_SIZE ,/* u32 */ +ETHTOOL_A_BITSET_BITS ,/* nest - _A_BITSET_BITS_* */ +ETHTOOL_A_BITSET_VALUE ,/* binary */ +ETHTOOL_A_BITSET_MASK ,/* binary */ + +/* add new constants above here */ + __ETHTOOL_A_BITSET_CNT, +ETHTOOL_A_BITSET_MAX = __ETHTOOL_A_BITSET_CNT -1 +}; +/* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool"#define ETHTOOL_GENL_VERSION 1
net/ethtool/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-y += ioctl.o common.o obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o -ethtool_nl-y := netlink.o +ethtool_nl-y := netlink.o bitset.o
net/ethtool/bitset.c new file +735 -0
735 lines not on this page · raw message
net/ethtool/bitset.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _NET_ETHTOOL_BITSET_H +#define _NET_ETHTOOL_BITSET_H + +typedef const char (*const ethnl_string_array_t )[ETH_GSTRING_LEN ]; + +int ethnl_bitset_is_compact (const struct nlattr *bitset,bool *compact); +int ethnl_bitset_size (const unsigned long *val,const unsigned long *mask, +unsigned int nbits,ethnl_string_array_t names, +bool compact); +int ethnl_bitset32_size (const u32 *val,const u32 *mask,unsigned int nbits, +ethnl_string_array_t names,bool compact); +int ethnl_put_bitset (struct sk_buff *skb,int attrtype, +const unsigned long *val,const unsigned long *mask, +unsigned int nbits,ethnl_string_array_t names, +bool compact); +int ethnl_put_bitset32 (struct sk_buff *skb,int attrtype,const u32 *val, +const u32 *mask,unsigned int nbits, +ethnl_string_array_t names,bool compact); +int ethnl_update_bitset (unsigned long *bitmap,unsigned int nbits, +const struct nlattr *attr,ethnl_string_array_t names, +struct netlink_ext_ack *extack,bool *mod); +int ethnl_update_bitset32 (u32 *bitmap,unsigned int nbits, +const struct nlattr *attr,ethnl_string_array_t names, +struct netlink_ext_ack *extack,bool *mod); + +#endif /* _NET_ETHTOOL_BITSET_H */
Signature · 1 line
2.24.1
Re: [PATCH net-next v8 03/14] ethtool: netlink bitset handling
Quoted 35 lines · Michal Kubecek
The ethtool netlink code uses common framework for passing arbitrary length bit sets to allow future extensions. A bitset can be a list (only one bitmap) or can consist of value and mask pair (used e.g. when client want to modify only some bits). A bitset can use one of two formats:
verbose (bit by bit) or compact.Verbose format consists of bitset size (number of bits), list flag and an array of bit nests, telling which bits are part of the list or which bits are in the mask and which of them are to be set. In requests, bits can be identified by index (position) or by name. In replies, kernel provides both index and name. Verbose format is suitable for "one shot" applications like standard ethtool command as it avoids the need to either keep bit names (e.g. link modes) in sync with kernel or having to add an extra roundtrip for string set request (e.g. for private flags).
Compact format uses one (list) or two (value/mask) arrays of 32-bit words to store the bitmap(s). It is more suitable for long running applications (ethtool in monitor mode or network management daemons) which can retrieve the names once and then pass only compact bitmaps to save space.
Userspace requests can use either format;
ETHTOOL_FLAG_COMPACT_BITSETSflag in request header tells kernel which format to use in reply. Notifications always use compact format.As some code uses arrays of unsigned long for internal representation and some arrays of u32 (or even a single u32), two sets of parse/compose helpers are introduced. To avoid code duplication, helpers for unsigned long arrays are implemented as wrappers around helpers for u32 arrays. There are two reasons for this choice: (1) u32 arrays are more frequent in ethtool code and (2) unsigned long array can be always interpreted as an u32 array on little endian 64-bit and all 32-bit architectures while we would need special handling for odd number of u32 words in the opposite direction.
Quoted 1 line
Signed-off-by Michal Kubecek <[email protected]>
Signature · 1 line
Florian
PATCH v8 4/14 ethtool: support for netlink notifications
In reply to Michal KubecekAdd infrastructure for ethtool netlink notifications. There is only one multicast group "monitor" which is used to notify userspace about changes and actions performed. Notification messages (types using suffix _NTF) share the format with replies to GET requests.
Notifications are supposed to be broadcasted on every configuration change, whether it is done using the netlink interface or ioctl one. Netlink SET requests only trigger a notification if some data is actually changed.
To trigger an ethtool notification, both ethtool netlink and external code use ethtool_notify() helper. This helper requires RTNL to be held and may sleep. Handlers sending messages for specific notification message types are registered in ethnl_notify_handlers array. As notifications can be triggered from other code, ethnl_ok flag is used to prevent an attempt to send notification before genetlink family is registered.
--- include/linux/ethtool_netlink.h | 5 +++++ include/linux/netdevice.h | 9 ++++++++ include/uapi/linux/ethtool_netlink.h | 2 ++ net/ethtool/netlink.c | 32 ++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+)
include/linux/ethtool_netlink.h +5 -0
@@ -5,5 +5,10 @@#include <uapi/linux/ethtool_netlink.h> #include <linux/ethtool.h> +#include <linux/netdevice.h> + +enum ethtool_multicast_groups { +ETHNL_MCGRP_MONITOR , +};#endif /* _LINUX_ETHTOOL_NETLINK_H_ */
include/linux/netdevice.h +9 -0
@@ -4393,6 +4393,15 @@ struct netdev_notifier_bonding_info {void netdev_bonding_info_change (struct net_device *dev,struct netdev_bonding_info *bonding_info); +#if IS_ENABLED (CONFIG_ETHTOOL_NETLINK ) +void ethtool_notify (struct net_device *dev,unsigned int cmd,const void *data); +#else +static inline void ethtool_notify (struct net_device *dev,unsigned int cmd, +const void *data) +{ +} +#endif +static inline struct sk_buff *skb_gso_segment (struct sk_buff *skb,netdev_features_t features) {
include/uapi/linux/ethtool_netlink.h +2 -0
@@ -89,4 +89,6 @@ enum {#define ETHTOOL_GENL_NAME "ethtool"#define ETHTOOL_GENL_VERSION 1 +#define ETHTOOL_MCGRP_MONITOR_NAME "monitor" +#endif /* _UAPI_LINUX_ETHTOOL_NETLINK_H_ */
net/ethtool/netlink.c +32 -0
@@ -6,6 +6,8 @@static struct genl_family ethtool_genl_family; +static bool ethnl_ok__read_mostly ; +static const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_MAX +1 ] = { [ETHTOOL_A_HEADER_UNSPEC ] = { .type =NLA_REJECT }, [ETHTOOL_A_HEADER_DEV_INDEX ] = { .type =NLA_U32 },
@@ -169,11 +171,38 @@ struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd,return NULL ; } +/* notifications */ + +typedef void (*ethnl_notify_handler_t )(struct net_device *dev,unsigned int cmd, +const void *data); + +static const ethnl_notify_handler_t ethnl_notify_handlers[] = { +}; + +void ethtool_notify (struct net_device *dev,unsigned int cmd,const void *data) +{ +if (unlikely (!ethnl_ok)) +return ; +ASSERT_RTNL (); + +if (likely (cmd <ARRAY_SIZE (ethnl_notify_handlers) && + ethnl_notify_handlers[cmd])) + ethnl_notify_handlers[cmd](dev, cmd, data); +else +WARN_ONCE (1 ,"notification %u not implemented (dev=%s)\n" , + cmd,netdev_name (dev)); +} +EXPORT_SYMBOL (ethtool_notify); +/* genetlink setup */ static const struct genl_ops ethtool_genl_ops[] = { }; +static const struct genl_multicast_group ethtool_nl_mcgrps[] = { + [ETHNL_MCGRP_MONITOR ] = { .name =ETHTOOL_MCGRP_MONITOR_NAME }, +}; +static struct genl_family ethtool_genl_family = { .name =ETHTOOL_GENL_NAME , .version =ETHTOOL_GENL_VERSION ,
@@ -181,6 +210,8 @@ static struct genl_family ethtool_genl_family = { .parallel_ops = true, .ops = ethtool_genl_ops, .n_ops = ARRAY_SIZE(ethtool_genl_ops), + .mcgrps = ethtool_nl_mcgrps, + .n_mcgrps = ARRAY_SIZE(ethtool_nl_mcgrps), };/* module setup */
@@ -192,6 +223,7 @@ static int __init ethnl_init(void) ret =genl_register_family (ðtool_genl_family);if (WARN (ret <0 ,"ethtool: genetlink family registration failed" ))return ret; + ethnl_ok = true;return 0 ; }
Signature · 1 line
2.24.1
Re: [PATCH net-next v8 04/14] ethtool: support for netlink notifications
Quoted 9 lines · Michal Kubecek
Add infrastructure for ethtool netlink notifications. There is only one multicast group "monitor" which is used to notify userspace about changes and actions performed. Notification messages (types using suffix
_NTF) share the format with replies to GET requests.Notifications are supposed to be broadcasted on every configuration change, whether it is done using the netlink interface or ioctl one. Netlink SET requests only trigger a notification if some data is actually changed.
Quoted 8 lines
To trigger an ethtool notification, both ethtool netlink and external code use
ethtool_notify()helper. This helper requires RTNL to be held and may sleep. Handlers sending messages for specific notification message types are registered inethnl_notify_handlersarray. As notifications can be triggered from other code,ethnl_okflag is used to prevent an attempt to send notification before genetlink family is registered.Signed-off-by Michal Kubecek <[email protected]>
Signature · 1 line
Florian
PATCH v8 5/14 ethtool: default handlers for GET requests
In reply to Michal KubecekSignificant part of GET request processing is common for most request types but unfortunately it cannot be easily separated from type specific code as we need to alternate between common actions (parsing common request header, allocating message and filling netlink/genetlink headers etc.) and specific actions (querying the device, composing the reply). The processing also happens in three different situations: "do" request, "dump" request and notification, each doing things in slightly different way.
The request specific code is implemented in four or five callbacks defined in an instance of struct get_request_ops:
parse_request() - parse incoming message
prepare_data() - retrieve data from driver or NIC reply_size() - estimate reply message size fill_reply() - compose reply message cleanup_data() - (optional) clean up additional data
Other members of struct get_request_ops describe the data structure holding information from client request and data used to compose the message. The default handlers ethnl_default_doit(), ethnl_default_dumpit(), ethnl_default_start() and ethnl_default_done() can be then used in genl_ops handler. Notification handler will be introduced in a later patch.
--- net/ethtool/netlink.c | 321 ++++++++++++++++++++++++++++++++++++++++++ net/ethtool/netlink.h | 116 ++++++++++++++- 2 files changed, 436 insertions(+), 1 deletion(-)
net/ethtool/netlink.c +321 -0
@@ -171,6 +171,327 @@ struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd,return NULL ; } +/* GET request helpers */ + +/** +* struct ethnl_dump_ctx - context structure for generic dumpit() callback +* @ops: request ops of currently processed message type +* @req_info: parsed request header of processed request +* @pos_hash: saved iteration position - hashbucket +* @pos_idx: saved iteration position - index +* +* These parameters are kept in struct netlink_callback as context preserved +* between iterations. They are initialized by ethnl_default_start() and used +* in ethnl_default_dumpit() and ethnl_default_done(). +*/ +struct ethnl_dump_ctx { +const struct ethnl_request_ops *ops; +struct ethnl_req_info *req_info; +struct ethnl_reply_data *reply_data; +int pos_hash; +int pos_idx; +}; + +static const struct ethnl_request_ops * +ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { +}; + +static struct ethnl_dump_ctx *ethnl_dump_context (struct netlink_callback *cb) +{ +return (struct ethnl_dump_ctx *)cb->ctx; +} + +/** +* ethnl_default_parse() - Parse request message +* @req_info: pointer to structure to put data into +* @nlhdr: pointer to request message header +* @net: request netns +* @request_ops: struct request_ops for request type +* @extack: netlink extack for error reporting +* @require_dev: fail if no device identified in header +* +* Parse universal request header and call request specific ->parse_request() +* callback (if defined) to parse the rest of the message. +* +* Return: 0 on success or negative error code +*/ +static int ethnl_default_parse (struct ethnl_req_info *req_info, +const struct nlmsghdr *nlhdr,struct net *net, +const struct ethnl_request_ops *request_ops, +struct netlink_ext_ack *extack,bool require_dev) +{ +struct nlattr **tb; +int ret; + + tb =kmalloc_array (request_ops->max_attr +1 ,sizeof (tb[0 ]), +GFP_KERNEL ); +if (!tb) +return -ENOMEM ; + + ret =nlmsg_parse (nlhdr,GENL_HDRLEN , tb, request_ops->max_attr, + request_ops->request_policy, extack); +if (ret <0 ) + goto out; + ret =ethnl_parse_header (req_info, tb[request_ops->hdr_attr], net, + extack, require_dev); +if (ret <0 ) + goto out; + +if (request_ops->parse_request) { + ret = request_ops->parse_request (req_info, tb, extack); +if (ret <0 ) + goto out; + } + + ret =0 ; +out: +kfree (tb); +return ret; +} + +/** +* ethnl_init_reply_data() - Initialize reply data for GET request +* @req_info: pointer to embedded struct ethnl_req_info +* @ops: instance of struct ethnl_request_ops describing the layout +* @dev: network device to initialize the reply for +* +* Fills the reply data part with zeros and sets the dev member. Must be called +* before calling the ->fill_reply() callback (for each iteration when handling +* dump requests). +*/ +static void ethnl_init_reply_data (struct ethnl_reply_data *reply_data, +const struct ethnl_request_ops *ops, +struct net_device *dev) +{ +memset (reply_data,0 , ops->reply_data_size); + reply_data->dev = dev; +} + +/* default ->doit() handler for GET type requests */ +static int ethnl_default_doit (struct sk_buff *skb,struct genl_info *info) +{ +struct ethnl_reply_data *reply_data =NULL ; +struct ethnl_req_info *req_info =NULL ; +const u8 cmd = info->genlhdr->cmd; +const struct ethnl_request_ops *ops; +struct sk_buff *rskb; +void *reply_payload; +int reply_len; +int ret; + + ops = ethnl_default_requests[cmd]; +if (WARN_ONCE (!ops,"cmd %u has no ethnl_request_ops\n" , cmd)) +return -EOPNOTSUPP ; + req_info =kzalloc (ops->req_info_size,GFP_KERNEL ); +if (!req_info) +return -ENOMEM ; + reply_data =kmalloc (ops->reply_data_size,GFP_KERNEL ); +if (!reply_data) { +kfree (req_info); +return -ENOMEM ; + } + + ret =ethnl_default_parse (req_info, info->nlhdr,genl_info_net (info), ops, + info->extack, !ops->allow_nodev_do); +if (ret <0 ) + goto err_dev; +ethnl_init_reply_data (reply_data, ops, req_info->dev); + +rtnl_lock (); + ret = ops->prepare_data (req_info, reply_data, info); +rtnl_unlock (); +if (ret <0 ) + goto err_cleanup; + reply_len = ops->reply_size (req_info, reply_data); +if (ret <0 ) + goto err_cleanup; + ret = -ENOMEM ; + rskb =ethnl_reply_init (reply_len, req_info->dev, ops->reply_cmd, + ops->hdr_attr, info, &reply_payload); +if (!rskb) + goto err_cleanup; + ret = ops->fill_reply (rskb, req_info, reply_data); +if (ret <0 ) + goto err_msg; +if (ops->cleanup_data) + ops->cleanup_data (reply_data); + +genlmsg_end (rskb, reply_payload); +if (req_info->dev) +dev_put (req_info->dev); +kfree (reply_data); +kfree (req_info); +return genlmsg_reply (rskb, info); + +err_msg: +WARN_ONCE (ret == -EMSGSIZE ,"calculated message payload length (%d) not sufficient\n" , reply_len); +nlmsg_free (rskb); +err_cleanup: +if (ops->cleanup_data) + ops->cleanup_data (reply_data); +err_dev: +if (req_info->dev) +dev_put (req_info->dev); +kfree (reply_data); +kfree (req_info); +return ret; +} + +static int ethnl_default_dump_one (struct sk_buff *skb,struct net_device *dev, +const struct ethnl_dump_ctx *ctx) +{ +int ret; + +ethnl_init_reply_data (ctx->reply_data, ctx->ops, dev); +rtnl_lock (); + ret = ctx->ops->prepare_data (ctx->req_info, ctx->reply_data,NULL ); +rtnl_unlock (); +if (ret <0 ) + goto out; + ret =ethnl_fill_reply_header (skb, dev, ctx->ops->hdr_attr); +if (ret <0 ) + goto out; + ret = ctx->ops->fill_reply (skb, ctx->req_info, ctx->reply_data); + +out: +if (ctx->ops->cleanup_data) + ctx->ops->cleanup_data (ctx->reply_data); + ctx->reply_data->dev =NULL ; +return ret; +} + +/* Default ->dumpit() handler for GET requests. Device iteration copied from +* rtnl_dump_ifinfo(); we have to be more careful about device hashtable +* persistence as we cannot guarantee to hold RTNL lock through the whole +* function as rtnetnlink does. +*/ +static int ethnl_default_dumpit (struct sk_buff *skb, +struct netlink_callback *cb) +{ +struct ethnl_dump_ctx *ctx =ethnl_dump_context (cb); +struct net *net =sock_net (skb->sk); +int s_idx = ctx->pos_idx; +int h, idx =0 ; +int ret =0 ; +void *ehdr; + +rtnl_lock (); +for (h = ctx->pos_hash; h <NETDEV_HASHENTRIES ; h++, s_idx =0 ) { +struct hlist_head *head; +struct net_device *dev; +unsigned int seq; + + head = &net->dev_index_head[h]; + +restart_chain: + seq = net->dev_base_seq; + cb->seq = seq; + idx =0 ; +hlist_for_each_entry (dev, head, index_hlist) { +if (idx < s_idx) + goto cont; +dev_hold (dev); +rtnl_unlock (); + + ehdr =genlmsg_put (skb,NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq, + ðtool_genl_family,0 , + ctx->ops->reply_cmd); +if (!ehdr) { +dev_put (dev); + ret = -EMSGSIZE ; + goto out; + } + ret =ethnl_default_dump_one (skb, dev, ctx); +dev_put (dev); +if (ret <0 ) { +genlmsg_cancel (skb, ehdr); +if (ret == -EOPNOTSUPP ) + goto lock_and_cont; +if (likely (skb->len)) + ret = skb->len; + goto out; + } +genlmsg_end (skb, ehdr); +lock_and_cont: +rtnl_lock (); +if (net->dev_base_seq != seq) { + s_idx = idx +1 ; + goto restart_chain; + } +cont: + idx++; + } + + } +rtnl_unlock (); + +out: + ctx->pos_hash = h; + ctx->pos_idx = idx; +nl_dump_check_consistent (cb,nlmsg_hdr (skb)); + +return ret; +} + +/* generic ->start() handler for GET requests */ +static int ethnl_default_start (struct netlink_callback *cb) +{ +struct ethnl_dump_ctx *ctx =ethnl_dump_context (cb); +struct ethnl_reply_data *reply_data; +const struct ethnl_request_ops *ops; +struct ethnl_req_info *req_info; +struct genlmsghdr *ghdr; +int ret; + +BUILD_BUG_ON (sizeof (*ctx) >sizeof (cb->ctx)); + + ghdr =nlmsg_data (cb->nlh); + ops = ethnl_default_requests[ghdr->cmd]; +if (WARN_ONCE (!ops,"cmd %u has no ethnl_request_ops\n" , ghdr->cmd)) +return -EOPNOTSUPP ; + req_info =kzalloc (ops->req_info_size,GFP_KERNEL ); +if (!req_info) +return -ENOMEM ; + reply_data =kmalloc (ops->reply_data_size,GFP_KERNEL ); +if (!reply_data) { +kfree (req_info); +return -ENOMEM ; + } + + ret =ethnl_default_parse (req_info, cb->nlh,sock_net (cb->skb->sk), ops, + cb->extack, false); +if (req_info->dev) { +/* We ignore device specification in dump requests but as the +* same parser as for non-dump (doit) requests is used, it +* would take reference to the device if it finds one +*/ +dev_put (req_info->dev); + req_info->dev =NULL ; + } +if (ret <0 ) +return ret; + + ctx->ops = ops; + ctx->req_info = req_info; + ctx->reply_data = reply_data; + ctx->pos_hash =0 ; + ctx->pos_idx =0 ; + +return 0 ; +} + +/* default ->done() handler for GET requests */ +static int ethnl_default_done (struct netlink_callback *cb) +{ +struct ethnl_dump_ctx *ctx =ethnl_dump_context (cb); + +kfree (ctx->reply_data); +kfree (ctx->req_info); + +return 0 ; +} +/* notifications */ typedef void (*ethnl_notify_handler_t)(struct net_device *dev, unsigned int cmd,
net/ethtool/netlink.h +115 -1
131 lines not on this page · raw message
Signature · 1 line
2.24.1
Re: [PATCH net-next v8 05/14] ethtool: default handlers for GET requests
Quoted 17 lines · Michal Kubecek
Significant part of GET request processing is common for most request types but unfortunately it cannot be easily separated from type specific code as we need to alternate between common actions (parsing common request header, allocating message and filling netlink/genetlink headers etc.) and specific actions (querying the device, composing the reply). The processing also happens in three different situations: "do" request, "dump" request and notification, each doing things in slightly different way.
The request specific code is implemented in four or five callbacks defined in an instance of struct
get_request_ops:
parse_request()- parse incoming messageprepare_data() - retrieve data from driver or NIC reply_size() - estimate reply message size fill_reply() - compose reply message cleanup_data() - (optional) clean up additional data
Quoted 7 lines
Other members of struct
get_request_opsdescribe the data structure holding information from client request and data used to compose the message. The default handlersethnl_default_doit(),ethnl_default_dumpit(),ethnl_default_start()andethnl_default_done()can be then used ingenl_opshandler. Notification handler will be introduced in a later patch.Signed-off-by Michal Kubecek <[email protected]>
Signature · 1 line
Florian
PATCH v8 6/14 ethtool: provide string sets with STRSET_GET request
In reply to Michal KubecekRequests a contents of one or more string sets, i.e. indexed arrays of strings; this information is provided by ETHTOOL_GSSET_INFO and ETHTOOL_GSTRINGS commands of ioctl interface. Unlike ioctl interface, all information can be retrieved with one request and mulitple string sets can be requested at once.
There are three types of requests:
- no NLM_F_DUMP, no device: get "global" stringsets
- no NLM_F_DUMP, with device: get string sets related to the device
- NLM_F_DUMP, no device: get device related string sets for all devices
Client can request either all string sets of given type (global or device related) or only specific sets. With ETHTOOL_A_STRSET_COUNTS flag set, only set sizes (numbers of strings) are returned.
--- Documentation/networking/ethtool-netlink.rst | 75 +++- include/uapi/linux/ethtool.h | 3 + include/uapi/linux/ethtool_netlink.h | 56 +++ net/ethtool/Makefile | 2 +- net/ethtool/netlink.c | 8 + net/ethtool/netlink.h | 4 + net/ethtool/strset.c | 425 +++++++++++++++++++ 7 files changed, 570 insertions(+), 3 deletions(-) create mode 100644 net/ethtool/strset.c
Documentation/networking/ethtool-netlink.rst +73 -2
@@ -166,6 +166,18 @@ according to message purpose: ``_NTF`` kernel notification ============== ====================================== +Userspace to kernel: + + ===================================== ================================ + ``ETHTOOL_MSG_STRSET_GET`` get string set + ===================================== ================================ + +Kernel to userspace: + + ===================================== ================================ + ``ETHTOOL_MSG_STRSET_GET_REPLY`` string set contents + ===================================== ================================ + ``GET`` requests are sent by userspace applications to retrieve device information. They usually do not contain any message specific attributes. Kernel replies with corresponding "GET_REPLY" message. For most types, ``GET``
@@ -197,6 +209,65 @@ an ``ACT_REPLY`` message. Performing an action also triggers a notification Later sections describe the format and semantics of these messages. +STRSET_GET +========== + +Requests contents of a string set as provided by ioctl commands +``ETHTOOL_GSSET_INFO`` and ``ETHTOOL_GSTRINGS.`` String sets are not user +writeable so that the corresponding ``STRSET_SET`` message is only used in +kernel replies. There are two types of string sets: global (independent of +a device, e.g. device feature names) and device specific (e.g. device private +flags). + +Request contents: + + +---------------------------------------+--------+------------------------+ + | ``ETHTOOL_A_STRSET_HEADER`` | nested | request header | + +---------------------------------------+--------+------------------------+ + | ``ETHTOOL_A_STRSET_STRINGSETS`` | nested | string set to request | + +-+-------------------------------------+--------+------------------------+ + | | ``ETHTOOL_A_STRINGSETS_STRINGSET+`` | nested | one string set | + +-+-+-----------------------------------+--------+------------------------+ + | | | ``ETHTOOL_A_STRINGSET_ID`` | u32 | set id | + +-+-+-----------------------------------+--------+------------------------+ + +Kernel response contents: + + +---------------------------------------+--------+-----------------------+ + | ``ETHTOOL_A_STRSET_HEADER`` | nested | reply header | + +---------------------------------------+--------+-----------------------+ + | ``ETHTOOL_A_STRSET_STRINGSETS`` | nested | array of string sets | + +-+-------------------------------------+--------+-----------------------+ + | | ``ETHTOOL_A_STRINGSETS_STRINGSET+`` | nested | one string set | + +-+-+-----------------------------------+--------+-----------------------+ + | | | ``ETHTOOL_A_STRINGSET_ID`` | u32 | set id | + +-+-+-----------------------------------+--------+-----------------------+ + | | | ``ETHTOOL_A_STRINGSET_COUNT`` | u32 | number of strings | + +-+-+-----------------------------------+--------+-----------------------+ + | | | ``ETHTOOL_A_STRINGSET_STRINGS`` | nested | array of strings | + +-+-+-+---------------------------------+--------+-----------------------+ + | | | | ``ETHTOOL_A_STRINGS_STRING+`` | nested | one string | + +-+-+-+-+-------------------------------+--------+-----------------------+ + | | | | | ``ETHTOOL_A_STRING_INDEX`` | u32 | string index | + +-+-+-+-+-------------------------------+--------+-----------------------+ + | | | | | ``ETHTOOL_A_STRING_VALUE`` | string | string value | + +-+-+-+-+-------------------------------+--------+-----------------------+ + | ``ETHTOOL_A_STRSET_COUNTS_ONLY`` | flag | return only counts | + +---------------------------------------+--------+-----------------------+ + +Device identification in request header is optional. Depending on its presence +a and ``NLM_F_DUMP`` flag, there are three type of ``STRSET_GET`` requests: + + - no ``NLM_F_DUMP,`` no device: get "global" stringsets + - no ``NLM_F_DUMP``, with device: get string sets related to the device + - ``NLM_F_DUMP``, no device: get device related string sets for all devices + +If there is no ``ETHTOOL_A_STRSET_STRINGSETS`` array, all string sets of +requested type are returned, otherwise only those specified in the request. +Flag ``ETHTOOL_A_STRSET_COUNTS_ONLY`` tells kernel to only return string +counts of the sets, not the actual strings. + + Request translation ===================
@@ -232,7 +303,7 @@ have their netlink replacement yet. ``ETHTOOL_GSG`` n/a ``ETHTOOL_SSG`` n/a ``ETHTOOL_TEST`` n/a - ``ETHTOOL_GSTRINGS`` n/a + ``ETHTOOL_GSTRINGS`` ``ETHTOOL_MSG_STRSET_GET`` ``ETHTOOL_PHYS_ID`` n/a ``ETHTOOL_GSTATS`` n/a ``ETHTOOL_GTSO`` n/a
@@ -260,7 +331,7 @@ have their netlink replacement yet. ``ETHTOOL_RESET`` n/a ``ETHTOOL_SRXNTUPLE`` n/a ``ETHTOOL_GRXNTUPLE`` n/a - ``ETHTOOL_GSSET_INFO`` n/a + ``ETHTOOL_GSSET_INFO`` ``ETHTOOL_MSG_STRSET_GET`` ``ETHTOOL_GRXFHINDIR`` n/a ``ETHTOOL_SRXFHINDIR`` n/a ``ETHTOOL_GFEATURES`` n/a
include/uapi/linux/ethtool.h +3 -0
@@ -606,6 +606,9 @@ enum ethtool_stringset {ETH_SS_PHY_STATS ,ETH_SS_PHY_TUNABLES ,ETH_SS_LINK_MODES , + +/* add new constants above here */ + ETH_SS_COUNT };/**
include/uapi/linux/ethtool_netlink.h +56 -0
74 lines not on this page · raw message
net/ethtool/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-y += ioctl.o common.o obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o -ethtool_nl-y := netlink.o bitset.o +ethtool_nl-y := netlink.o bitset.o strset.o
net/ethtool/netlink.c +8 -0
@@ -194,6 +194,7 @@ struct ethnl_dump_ctx {static const struct ethnl_request_ops * ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { + [ETHTOOL_MSG_STRSET_GET ] = ðnl_strset_request_ops, };static struct ethnl_dump_ctx *ethnl_dump_context (struct netlink_callback *cb)
@@ -518,6 +519,13 @@ EXPORT_SYMBOL(ethtool_notify);/* genetlink setup */ static const struct genl_ops ethtool_genl_ops[] = { + { + .cmd =ETHTOOL_MSG_STRSET_GET , + .doit = ethnl_default_doit, + .start = ethnl_default_start, + .dumpit = ethnl_default_dumpit, + .done = ethnl_default_done, + }, };static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/netlink.h +4 -0
@@ -326,4 +326,8 @@ struct ethnl_request_ops { void (*cleanup_data)(struct ethnl_reply_data *reply_data); }; +/* request handlers */ + +extern const struct ethnl_request_ops ethnl_strset_request_ops; +#endif /* _NET_ETHTOOL_NETLINK_H */
net/ethtool/strset.c new file +425 -0
425 lines not on this page · raw message
Signature · 1 line
2.24.1
Re: [PATCH net-next v8 06/14] ethtool: provide string sets with STRSET_GET request
Quoted 12 lines · Michal Kubecek
Requests a contents of one or more string sets, i.e. indexed arrays of strings; this information is provided by
ETHTOOL_GSSET_INFOandETHTOOL_GSTRINGScommands of ioctl interface. Unlike ioctl interface, all information can be retrieved with one request and mulitple string sets can be requested at once.There are three types of requests:
- no
NLM_F_DUMP, no device: get "global" stringsets
- noNLM_F_DUMP, with device: get string sets related to the device
-NLM_F_DUMP, no device: get device related string sets for all devices
Quoted 5 lines
Client can request either all string sets of given type (global or device related) or only specific sets. With
ETHTOOL_A_STRSET_COUNTSflag set, only set sizes (numbers of strings) are returned.Signed-off-by Michal Kubecek <[email protected]>
Signature · 1 line
Florian
PATCH v8 7/14 ethtool: provide link settings with LINKINFO_GET request
In reply to Michal KubecekImplement LINKINFO_GET netlink request to get basic link settings provided by ETHTOOL_GLINKSETTINGS and ETHTOOL_GSET ioctl commands.
This request provides settings not directly related to autonegotiation and link mode selection: physical port, phy MDIO address, MDI(-X) status, MDI(-X) control and transceiver.
LINKINFO_GET request can be used with NLM_F_DUMP (without device identification) to request the information for all devices in current network namespace providing the data.
--- Documentation/networking/ethtool-netlink.rst | 37 +++++++- include/uapi/linux/ethtool_netlink.h | 18 ++++ net/ethtool/Makefile | 2 +- net/ethtool/common.c | 48 ++++++++++ net/ethtool/common.h | 4 + net/ethtool/ioctl.c | 48 ---------- net/ethtool/linkinfo.c | 94 ++++++++++++++++++++ net/ethtool/netlink.c | 8 ++ net/ethtool/netlink.h | 1 + 9 files changed, 209 insertions(+), 51 deletions(-) create mode 100644 net/ethtool/linkinfo.c
Documentation/networking/ethtool-netlink.rst +35 -2
@@ -170,12 +170,14 @@ Userspace to kernel: ===================================== ================================ ``ETHTOOL_MSG_STRSET_GET`` get string set + ``ETHTOOL_MSG_LINKINFO_GET`` get link settings ===================================== ================================ Kernel to userspace: ===================================== ================================ ``ETHTOOL_MSG_STRSET_GET_REPLY`` string set contents + ``ETHTOOL_MSG_LINKINFO_GET_REPLY`` link settings ===================================== ================================ ``GET`` requests are sent by userspace applications to retrieve device
@@ -268,6 +270,37 @@ Flag ``ETHTOOL_A_STRSET_COUNTS_ONLY`` tells kernel to only return string counts of the sets, not the actual strings. +LINKINFO_GET +============ + +Requests link settings as provided by ``ETHTOOL_GLINKSETTINGS`` except for +link modes and autonegotiation related information. The request does not use +any attributes. + +Request contents: + + ==================================== ====== ========================== + ``ETHTOOL_A_LINKINFO_HEADER`` nested request header + ==================================== ====== ========================== + +Kernel response contents: + + ==================================== ====== ========================== + ``ETHTOOL_A_LINKINFO_HEADER`` nested reply header + ``ETHTOOL_A_LINKINFO_PORT`` u8 physical port + ``ETHTOOL_A_LINKINFO_PHYADDR`` u8 phy MDIO address + ``ETHTOOL_A_LINKINFO_TP_MDIX`` u8 MDI(-X) status + ``ETHTOOL_A_LINKINFO_TP_MDIX_CTRL`` u8 MDI(-X) control + ``ETHTOOL_A_LINKINFO_TRANSCEIVER`` u8 transceiver + ==================================== ====== ========================== + +Attributes and their values have the same meaning as matching members of the +corresponding ioctl structures. + +``LINKINFO_GET`` allows dump requests (kernel returns reply message for all +devices supporting the request). + + Request translation ===================
@@ -278,7 +311,7 @@ have their netlink replacement yet. =================================== ===================================== ioctl command netlink command =================================== ===================================== - ``ETHTOOL_GSET`` n/a + ``ETHTOOL_GSET`` ``ETHTOOL_MSG_LINKINFO_GET`` ``ETHTOOL_SSET`` n/a ``ETHTOOL_GDRVINFO`` n/a ``ETHTOOL_GREGS`` n/a
@@ -352,7 +385,7 @@ have their netlink replacement yet. ``ETHTOOL_STUNABLE`` n/a ``ETHTOOL_GPHYSTATS`` n/a ``ETHTOOL_PERQUEUE`` n/a - ``ETHTOOL_GLINKSETTINGS`` n/a + ``ETHTOOL_GLINKSETTINGS`` ``ETHTOOL_MSG_LINKINFO_GET`` ``ETHTOOL_SLINKSETTINGS`` n/a ``ETHTOOL_PHY_GTUNABLE`` n/a ``ETHTOOL_PHY_STUNABLE`` n/a
include/uapi/linux/ethtool_netlink.h +18 -0
@@ -15,6 +15,7 @@enum {ETHTOOL_MSG_USER_NONE ,ETHTOOL_MSG_STRSET_GET , +ETHTOOL_MSG_LINKINFO_GET ,/* add new constants above here */ __ETHTOOL_MSG_USER_CNT,
@@ -25,6 +26,7 @@ enum {enum {ETHTOOL_MSG_KERNEL_NONE ,ETHTOOL_MSG_STRSET_GET_REPLY , +ETHTOOL_MSG_LINKINFO_GET_REPLY ,/* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT,
@@ -141,6 +143,22 @@ enum { ETHTOOL_A_STRSET_MAX = __ETHTOOL_A_STRSET_CNT - 1 }; +/* LINKINFO */ + +enum { +ETHTOOL_A_LINKINFO_UNSPEC , +ETHTOOL_A_LINKINFO_HEADER ,/* nest - _A_HEADER_* */ +ETHTOOL_A_LINKINFO_PORT ,/* u8 */ +ETHTOOL_A_LINKINFO_PHYADDR ,/* u8 */ +ETHTOOL_A_LINKINFO_TP_MDIX ,/* u8 */ +ETHTOOL_A_LINKINFO_TP_MDIX_CTRL ,/* u8 */ +ETHTOOL_A_LINKINFO_TRANSCEIVER ,/* u8 */ + +/* add new constants above here */ + __ETHTOOL_A_LINKINFO_CNT, +ETHTOOL_A_LINKINFO_MAX = __ETHTOOL_A_LINKINFO_CNT -1 +}; +/* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool"#define ETHTOOL_GENL_VERSION 1
net/ethtool/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-y += ioctl.o common.o obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o -ethtool_nl-y := netlink.o bitset.o strset.o +ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o
net/ethtool/common.c +48 -0
51 lines not on this page · raw message
net/ethtool/common.h +4 -0
@@ -19,4 +19,8 @@ extern const char phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN ];extern const char link_mode_names[][ETH_GSTRING_LEN ]; +bool convert_legacy_settings_to_link_ksettings ( +struct ethtool_link_ksettings *link_ksettings, +const struct ethtool_cmd *legacy_settings); +#endif /* _ETHTOOL_COMMON_H */
net/ethtool/ioctl.c +0 -48
54 lines not on this page · raw message
net/ethtool/linkinfo.c new file +94 -0
94 lines not on this page · raw message
net/ethtool/netlink.c +8 -0
@@ -195,6 +195,7 @@ struct ethnl_dump_ctx {static const struct ethnl_request_ops * ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_STRSET_GET ] = ðnl_strset_request_ops, + [ETHTOOL_MSG_LINKINFO_GET ] = ðnl_linkinfo_request_ops, };static struct ethnl_dump_ctx *ethnl_dump_context (struct netlink_callback *cb)
@@ -526,6 +527,13 @@ static const struct genl_ops ethtool_genl_ops[] = { .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, }, + { + .cmd = ETHTOOL_MSG_LINKINFO_GET, + .doit = ethnl_default_doit, + .start = ethnl_default_start, + .dumpit = ethnl_default_dumpit, + .done = ethnl_default_done, + }, };static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/netlink.h +1 -0
@@ -329,5 +329,6 @@ struct ethnl_request_ops {/* request handlers */ extern const struct ethnl_request_ops ethnl_strset_request_ops; +extern const struct ethnl_request_ops ethnl_linkinfo_request_ops;#endif /* _NET_ETHTOOL_NETLINK_H */
Signature · 1 line
2.24.1
Re: [PATCH net-next v8 07/14] ethtool: provide link settings with LINKINFO_GET request
Quoted 7 lines · Michal Kubecek
Implement
LINKINFO_GETnetlink request to get basic link settings provided byETHTOOL_GLINKSETTINGSandETHTOOL_GSETioctl commands.This request provides settings not directly related to autonegotiation and link mode selection: physical port, phy MDIO address, MDI(-X) status, MDI(-X) control and transceiver.
Quoted 5 lines
LINKINFO_GETrequest can be used withNLM_F_DUMP(without device identification) to request the information for all devices in current network namespace providing the data.Signed-off-by Michal Kubecek <[email protected]>
Signature · 1 line
Florian
PATCH v8 8/14 ethtool: set link settings with LINKINFO_SET request
In reply to Michal KubecekImplement LINKINFO_SET netlink request to set link settings queried by LINKINFO_GET message.
Only physical port, phy MDIO address and MDI(-X) control can be set, attempt to modify MDI(-X) status and transceiver is rejected.
--- Documentation/networking/ethtool-netlink.rst | 24 ++++++- include/uapi/linux/ethtool_netlink.h | 1 + net/ethtool/linkinfo.c | 71 ++++++++++++++++++++ net/ethtool/netlink.c | 5 ++ net/ethtool/netlink.h | 2 + 5 files changed, 101 insertions(+), 2 deletions(-)
Documentation/networking/ethtool-netlink.rst +22 -2
@@ -171,6 +171,7 @@ Userspace to kernel: ===================================== ================================ ``ETHTOOL_MSG_STRSET_GET`` get string set ``ETHTOOL_MSG_LINKINFO_GET`` get link settings + ``ETHTOOL_MSG_LINKINFO_SET`` set link settings ===================================== ================================ Kernel to userspace:
@@ -301,6 +302,25 @@ corresponding ioctl structures. devices supporting the request). +LINKINFO_SET +============ + +``LINKINFO_SET`` request allows setting some of the attributes reported by +``LINKINFO_GET``. + +Request contents: + + ==================================== ====== ========================== + ``ETHTOOL_A_LINKINFO_HEADER`` nested request header + ``ETHTOOL_A_LINKINFO_PORT`` u8 physical port + ``ETHTOOL_A_LINKINFO_PHYADDR`` u8 phy MDIO address + ``ETHTOOL_A_LINKINFO_TP_MDIX_CTRL`` u8 MDI(-X) control + ==================================== ====== ========================== + +MDI(-X) status and transceiver cannot be set, request with the corresponding +attributes is rejected. + + Request translation ===================
@@ -312,7 +332,7 @@ have their netlink replacement yet. ioctl command netlink command =================================== ===================================== ``ETHTOOL_GSET`` ``ETHTOOL_MSG_LINKINFO_GET`` - ``ETHTOOL_SSET`` n/a + ``ETHTOOL_SSET`` ``ETHTOOL_MSG_LINKINFO_SET`` ``ETHTOOL_GDRVINFO`` n/a ``ETHTOOL_GREGS`` n/a ``ETHTOOL_GWOL`` n/a
@@ -386,7 +406,7 @@ have their netlink replacement yet. ``ETHTOOL_GPHYSTATS`` n/a ``ETHTOOL_PERQUEUE`` n/a ``ETHTOOL_GLINKSETTINGS`` ``ETHTOOL_MSG_LINKINFO_GET`` - ``ETHTOOL_SLINKSETTINGS`` n/a + ``ETHTOOL_SLINKSETTINGS`` ``ETHTOOL_MSG_LINKINFO_SET`` ``ETHTOOL_PHY_GTUNABLE`` n/a ``ETHTOOL_PHY_STUNABLE`` n/a ``ETHTOOL_GFECPARAM`` n/a
include/uapi/linux/ethtool_netlink.h +1 -0
@@ -16,6 +16,7 @@ enum {ETHTOOL_MSG_USER_NONE ,ETHTOOL_MSG_STRSET_GET ,ETHTOOL_MSG_LINKINFO_GET , +ETHTOOL_MSG_LINKINFO_SET ,/* add new constants above here */ __ETHTOOL_MSG_USER_CNT,
net/ethtool/linkinfo.c +71 -0
74 lines not on this page · raw message
net/ethtool/netlink.c +5 -0
@@ -534,6 +534,11 @@ static const struct genl_ops ethtool_genl_ops[] = { .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, }, + { + .cmd = ETHTOOL_MSG_LINKINFO_SET, + .flags = GENL_UNS_ADMIN_PERM, + .doit = ethnl_set_linkinfo, + }, };static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/netlink.h +2 -0
@@ -331,4 +331,6 @@ struct ethnl_request_ops {extern const struct ethnl_request_ops ethnl_strset_request_ops;extern const struct ethnl_request_ops ethnl_linkinfo_request_ops; +int ethnl_set_linkinfo (struct sk_buff *skb,struct genl_info *info); +#endif /* _NET_ETHTOOL_NETLINK_H */
Signature · 1 line
2.24.1
Re: [PATCH net-next v8 08/14] ethtool: set link settings with LINKINFO_SET request
Quoted 7 lines · Michal Kubecek
Implement
LINKINFO_SETnetlink request to set link settings queried byLINKINFO_GETmessage.Only physical port, phy MDIO address and MDI(-X) control can be set, attempt to modify MDI(-X) status and transceiver is rejected.
Signed-off-by Michal Kubecek <[email protected]>
Signature · 1 line
Florian
PATCH v8 9/14 ethtool: add default notification handler
In reply to Michal KubecekThe ethtool netlink notifications have the same format as related GET replies so that if generic GET handling framework is used to process GET requests, its callbacks and instance of struct get_request_ops can be also used to compose corresponding notification message.
Provide function ethnl_std_notify() to be used as notification handler in ethnl_notify_handlers table.
--- net/ethtool/netlink.c | 89 +++++++++++++++++++++++++++++++++++++++++++ net/ethtool/netlink.h | 4 +- 2 files changed, 92 insertions(+), 1 deletion(-)
net/ethtool/netlink.c +89 -0
@@ -7,6 +7,7 @@static struct genl_family ethtool_genl_family;static bool ethnl_ok__read_mostly ; +static u32 ethnl_bcast_seq;static const struct nla_policy ethnl_header_policy[ETHTOOL_A_HEADER_MAX +1 ] = { [ETHTOOL_A_HEADER_UNSPEC ] = { .type =NLA_REJECT },
@@ -171,6 +172,18 @@ struct sk_buff *ethnl_reply_init(size_t payload, struct net_device *dev, u8 cmd,return NULL ; } +static void *ethnl_bcastmsg_put (struct sk_buff *skb,u8 cmd) +{ +return genlmsg_put (skb,0 , ++ethnl_bcast_seq, ðtool_genl_family,0 , + cmd); +} + +static int ethnl_multicast (struct sk_buff *skb,struct net_device *dev) +{ +return genlmsg_multicast_netns (ðtool_genl_family,dev_net (dev), skb, +0 ,ETHNL_MCGRP_MONITOR ,GFP_KERNEL ); +} +/* GET request helpers */ /**
@@ -494,6 +507,82 @@ static int ethnl_default_done(struct netlink_callback *cb)return 0 ; } +static const struct ethnl_request_ops * +ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX +1 ] = { +}; + +/* default notification handler */ +static void ethnl_default_notify (struct net_device *dev,unsigned int cmd, +const void *data) +{ +struct ethnl_reply_data *reply_data; +const struct ethnl_request_ops *ops; +struct ethnl_req_info *req_info; +struct sk_buff *skb; +void *reply_payload; +int reply_len; +int ret; + +if (WARN_ONCE (cmd >ETHTOOL_MSG_KERNEL_MAX || + !ethnl_default_notify_ops[cmd], +"unexpected notification type %u\n" , cmd)) +return ; + ops = ethnl_default_notify_ops[cmd]; + req_info =kzalloc (ops->req_info_size,GFP_KERNEL ); +if (!req_info) +return ; + reply_data =kmalloc (ops->reply_data_size,GFP_KERNEL ); +if (!reply_data) { +kfree (req_info); +return ; + } + + req_info->dev = dev; + req_info->flags |=ETHTOOL_FLAG_COMPACT_BITSETS ; + +ethnl_init_reply_data (reply_data, ops, dev); + ret = ops->prepare_data (req_info, reply_data,NULL ); +if (ret <0 ) + goto err_cleanup; + reply_len = ops->reply_size (req_info, reply_data); +if (ret <0 ) + goto err_cleanup; + ret = -ENOMEM ; + skb =genlmsg_new (reply_len,GFP_KERNEL ); +if (!skb) + goto err_cleanup; + reply_payload =ethnl_bcastmsg_put (skb, cmd); +if (!reply_payload) + goto err_skb; + ret =ethnl_fill_reply_header (skb, dev, ops->hdr_attr); +if (ret <0 ) + goto err_msg; + ret = ops->fill_reply (skb, req_info, reply_data); +if (ret <0 ) + goto err_msg; +if (ops->cleanup_data) + ops->cleanup_data (reply_data); + +genlmsg_end (skb, reply_payload); +kfree (reply_data); +kfree (req_info); +ethnl_multicast (skb, dev); +return ; + +err_msg: +WARN_ONCE (ret == -EMSGSIZE , +"calculated message payload length (%d) not sufficient\n" , + reply_len); +err_skb: +nlmsg_free (skb); +err_cleanup: +if (ops->cleanup_data) + ops->cleanup_data (reply_data); +kfree (reply_data); +kfree (req_info); +return ; +} +/* notifications */ typedef void (*ethnl_notify_handler_t)(struct net_device *dev, unsigned int cmd,
net/ethtool/netlink.h +3 -1
@@ -300,7 +300,9 @@ static inline void ethnl_ops_complete(struct net_device *dev)* unified infrastructure. When used, a pointer to an instance of this * structure is to be added to ðnl_default_requests array and generic * handlers ethnl_default_doit(), ethnl_default_dumpit(), -* ethnl_default_start() and ethnl_default_done() used in @ethtool_genl_ops. +* ethnl_default_start() and ethnl_default_done() used in @ethtool_genl_ops; +* ethnl_default_notify() can be used in @ethnl_notify_handlers to send +* notifications of the corresponding type. */ struct ethnl_request_ops {u8 request_cmd;
Signature · 1 line
2.24.1
Re: [PATCH net-next v8 09/14] ethtool: add default notification handler
Quoted 9 lines · Michal Kubecek
The ethtool netlink notifications have the same format as related GET replies so that if generic GET handling framework is used to process GET requests, its callbacks and instance of struct
get_request_opscan be also used to compose corresponding notification message.Provide function
ethnl_std_notify()to be used as notification handler inethnl_notify_handlerstable.Signed-off-by Michal Kubecek <[email protected]>
Signature · 1 line
Florian
PATCH v8 10/14 ethtool: add LINKINFO_NTF notification
In reply to Michal KubecekSend 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.
--- Documentation/networking/ethtool-netlink.rst | 1 + include/uapi/linux/ethtool_netlink.h | 1 + net/ethtool/ioctl.c | 12 ++++++++++-- net/ethtool/linkinfo.c | 2 ++ net/ethtool/netlink.c | 2 ++ 5 files changed, 16 insertions(+), 2 deletions(-)
Documentation/networking/ethtool-netlink.rst +1 -0
@@ -179,6 +179,7 @@ Kernel to userspace: ===================================== ================================ ``ETHTOOL_MSG_STRSET_GET_REPLY`` string set contents ``ETHTOOL_MSG_LINKINFO_GET_REPLY`` link settings + ``ETHTOOL_MSG_LINKINFO_NTF`` link settings notification ===================================== ================================ ``GET`` requests are sent by userspace applications to retrieve device
include/uapi/linux/ethtool_netlink.h +1 -0
@@ -28,6 +28,7 @@ enum {ETHTOOL_MSG_KERNEL_NONE ,ETHTOOL_MSG_STRSET_GET_REPLY ,ETHTOOL_MSG_LINKINFO_GET_REPLY , +ETHTOOL_MSG_LINKINFO_NTF ,/* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT,
net/ethtool/ioctl.c +10 -2
@@ -26,6 +26,7 @@#include <net/devlink.h> #include <net/xdp_sock.h> #include <net/flow_offload.h> +#include <linux/ethtool_netlink.h> #include "common.h"
@@ -571,7 +572,10 @@ static int ethtool_set_link_ksettings(struct net_device *dev, != link_ksettings.base.link_mode_masks_nwords) return -EINVAL; -return dev->ethtool_ops->set_link_ksettings (dev, &link_ksettings); + err = dev->ethtool_ops->set_link_ksettings (dev, &link_ksettings); +if (err >=0 ) +ethtool_notify (dev,ETHTOOL_MSG_LINKINFO_NTF ,NULL ); +return err; }/* Query device for its ethtool_cmd settings.
@@ -620,6 +624,7 @@ static int ethtool_set_settings(struct net_device *dev, void __user *useraddr) {struct ethtool_link_ksettings link_ksettings;struct ethtool_cmd cmd; +int ret;ASSERT_RTNL ();
@@ -632,7 +637,10 @@ static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)return -EINVAL ; link_ksettings.base.link_mode_masks_nwords = __ETHTOOL_LINK_MODE_MASK_NU32; -return dev->ethtool_ops->set_link_ksettings (dev, &link_ksettings); + ret = dev->ethtool_ops->set_link_ksettings (dev, &link_ksettings); +if (ret >=0 ) +ethtool_notify (dev,ETHTOOL_MSG_LINKINFO_NTF ,NULL ); +return ret; } static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
net/ethtool/linkinfo.c +2 -0
@@ -155,6 +155,8 @@ int ethnl_set_linkinfo(struct sk_buff *skb, struct genl_info *info) ret = dev->ethtool_ops->set_link_ksettings (dev, &ksettings);if (ret <0 )GENL_SET_ERR_MSG (info,"link settings update failed" ); +else +ethtool_notify (dev,ETHTOOL_MSG_LINKINFO_NTF ,NULL ); out_ops:ethnl_ops_complete (dev);
net/ethtool/netlink.c +2 -0
@@ -509,6 +509,7 @@ static int ethnl_default_done(struct netlink_callback *cb)static const struct ethnl_request_ops * ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX +1 ] = { + [ETHTOOL_MSG_LINKINFO_NTF ] = ðnl_linkinfo_request_ops, };/* default notification handler */
@@ -589,6 +590,7 @@ typedef void (*ethnl_notify_handler_t)(struct net_device *dev, unsigned int cmd, const void *data);static const ethnl_notify_handler_t ethnl_notify_handlers[] = { + [ETHTOOL_MSG_LINKINFO_NTF ] = ethnl_default_notify, };void ethtool_notify (struct net_device *dev,unsigned int cmd,const void *data)
Signature · 1 line
2.24.1
Re: [PATCH net-next v8 10/14] ethtool: add LINKINFO_NTF notification
Quoted 10 lines · Michal Kubecek
Send
ETHTOOL_MSG_LINKINFO_NTFnotification message whenever device link settings are modified usingETHTOOL_MSG_LINKINFO_SETnetlink message orETHTOOL_SLINKSETTINGSorETHTOOL_SSETioctl commands.The notification message has the same format as reply to
LINKINFO_GETrequest.ETHTOOL_MSG_LINKINFO_SETnetlink 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.
Quoted 7 lines
As all work is done by
ethnl_default_notify()handler and callback functions introduced to handleLINKINFO_GETrequests, all that remains is adding entries forETHTOOL_MSG_LINKINFO_NTFintoethnl_notify_handlersandethnl_default_notify_opslookup tables and calls toethtool_notify()where needed.Signed-off-by Michal Kubecek <[email protected]>
Signature · 1 line
Florian
PATCH v8 11/14 ethtool: provide link mode information with LINKMODES_GET request
In reply to Michal KubecekImplement LINKMODES_GET netlink request to get link modes related information provided by ETHTOOL_GLINKSETTINGS and ETHTOOL_GSET ioctl commands.
This request provides supported, advertised and peer advertised link modes, autonegotiation flag, speed and duplex.
LINKMODES_GET request can be used with NLM_F_DUMP (without device identification) to request the information for all devices in current network namespace providing the data.
--- Documentation/networking/ethtool-netlink.rst | 36 +++++ include/linux/ethtool_netlink.h | 3 + include/uapi/linux/ethtool_netlink.h | 18 +++ net/ethtool/Makefile | 2 +- net/ethtool/linkmodes.c | 140 +++++++++++++++++++ net/ethtool/netlink.c | 8 ++ net/ethtool/netlink.h | 1 + 7 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 net/ethtool/linkmodes.c
Documentation/networking/ethtool-netlink.rst +36 -0
@@ -172,6 +172,7 @@ Userspace to kernel: ``ETHTOOL_MSG_STRSET_GET`` get string set ``ETHTOOL_MSG_LINKINFO_GET`` get link settings ``ETHTOOL_MSG_LINKINFO_SET`` set link settings + ``ETHTOOL_MSG_LINKMODES_GET`` get link modes info ===================================== ================================ Kernel to userspace:
@@ -180,6 +181,7 @@ Kernel to userspace: ``ETHTOOL_MSG_STRSET_GET_REPLY`` string set contents ``ETHTOOL_MSG_LINKINFO_GET_REPLY`` link settings ``ETHTOOL_MSG_LINKINFO_NTF`` link settings notification + ``ETHTOOL_MSG_LINKMODES_GET_REPLY`` link modes info ===================================== ================================ ``GET`` requests are sent by userspace applications to retrieve device
@@ -322,6 +324,38 @@ MDI(-X) status and transceiver cannot be set, request with the corresponding attributes is rejected. +LINKMODES_GET +============= + +Requests link modes (supported, advertised and peer advertised) and related +information (autonegotiation status, link speed and duplex) as provided by +``ETHTOOL_GLINKSETTINGS``. The request does not use any attributes. + +Request contents: + + ==================================== ====== ========================== + ``ETHTOOL_A_LINKMODES_HEADER`` nested request header + ==================================== ====== ========================== + +Kernel response contents: + + ==================================== ====== ========================== + ``ETHTOOL_A_LINKMODES_HEADER`` nested reply header + ``ETHTOOL_A_LINKMODES_AUTONEG`` u8 autonegotiation status + ``ETHTOOL_A_LINKMODES_OURS`` bitset advertised link modes + ``ETHTOOL_A_LINKMODES_PEER`` bitset partner link modes + ``ETHTOOL_A_LINKMODES_SPEED`` u32 link speed (Mb/s) + ``ETHTOOL_A_LINKMODES_DUPLEX`` u8 duplex mode + ==================================== ====== ========================== + +For ``ETHTOOL_A_LINKMODES_OURS``, value represents advertised modes and mask +represents supported modes. ``ETHTOOL_A_LINKMODES_PEER`` in the reply is a bit +list. + +``LINKMODES_GET`` allows dump requests (kernel returns reply messages for all +devices supporting the request). + + Request translation ===================
@@ -333,6 +367,7 @@ have their netlink replacement yet. ioctl command netlink command =================================== ===================================== ``ETHTOOL_GSET`` ``ETHTOOL_MSG_LINKINFO_GET`` + ``ETHTOOL_MSG_LINKMODES_GET`` ``ETHTOOL_SSET`` ``ETHTOOL_MSG_LINKINFO_SET`` ``ETHTOOL_GDRVINFO`` n/a ``ETHTOOL_GREGS`` n/a
@@ -407,6 +442,7 @@ have their netlink replacement yet. ``ETHTOOL_GPHYSTATS`` n/a ``ETHTOOL_PERQUEUE`` n/a ``ETHTOOL_GLINKSETTINGS`` ``ETHTOOL_MSG_LINKINFO_GET`` + ``ETHTOOL_MSG_LINKMODES_GET`` ``ETHTOOL_SLINKSETTINGS`` ``ETHTOOL_MSG_LINKINFO_SET`` ``ETHTOOL_PHY_GTUNABLE`` n/a ``ETHTOOL_PHY_STUNABLE`` n/a
include/linux/ethtool_netlink.h +3 -0
@@ -7,6 +7,9 @@#include <linux/ethtool.h> #include <linux/netdevice.h> +#define __ETHTOOL_LINK_MODE_MASK_NWORDS \ + DIV_ROUND_UP(__ETHTOOL_LINK_MODE_MASK_NBITS, 32) +enum ethtool_multicast_groups {ETHNL_MCGRP_MONITOR , };
include/uapi/linux/ethtool_netlink.h +18 -0
@@ -17,6 +17,7 @@ enum {ETHTOOL_MSG_STRSET_GET ,ETHTOOL_MSG_LINKINFO_GET ,ETHTOOL_MSG_LINKINFO_SET , +ETHTOOL_MSG_LINKMODES_GET ,/* add new constants above here */ __ETHTOOL_MSG_USER_CNT,
@@ -29,6 +30,7 @@ enum {ETHTOOL_MSG_STRSET_GET_REPLY ,ETHTOOL_MSG_LINKINFO_GET_REPLY ,ETHTOOL_MSG_LINKINFO_NTF , +ETHTOOL_MSG_LINKMODES_GET_REPLY ,/* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT,
@@ -161,6 +163,22 @@ enum { ETHTOOL_A_LINKINFO_MAX = __ETHTOOL_A_LINKINFO_CNT - 1 }; +/* LINKMODES */ + +enum { +ETHTOOL_A_LINKMODES_UNSPEC , +ETHTOOL_A_LINKMODES_HEADER ,/* nest - _A_HEADER_* */ +ETHTOOL_A_LINKMODES_AUTONEG ,/* u8 */ +ETHTOOL_A_LINKMODES_OURS ,/* bitset */ +ETHTOOL_A_LINKMODES_PEER ,/* bitset */ +ETHTOOL_A_LINKMODES_SPEED ,/* u32 */ +ETHTOOL_A_LINKMODES_DUPLEX ,/* u8 */ + +/* add new constants above here */ + __ETHTOOL_A_LINKMODES_CNT, +ETHTOOL_A_LINKMODES_MAX = __ETHTOOL_A_LINKMODES_CNT -1 +}; +/* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool"#define ETHTOOL_GENL_VERSION 1
net/ethtool/Makefile +1 -1
@@ -4,4 +4,4 @@ obj-y += ioctl.o common.o obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o -ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o +ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o
net/ethtool/linkmodes.c new file +140 -0
140 lines not on this page · raw message
net/ethtool/netlink.c +8 -0
@@ -209,6 +209,7 @@ static const struct ethnl_request_ops * ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_STRSET_GET] = ðnl_strset_request_ops, [ETHTOOL_MSG_LINKINFO_GET] = ðnl_linkinfo_request_ops, + [ETHTOOL_MSG_LINKMODES_GET] = ðnl_linkmodes_request_ops, };static struct ethnl_dump_ctx *ethnl_dump_context (struct netlink_callback *cb)
@@ -630,6 +631,13 @@ static const struct genl_ops ethtool_genl_ops[] = { .flags = GENL_UNS_ADMIN_PERM, .doit = ethnl_set_linkinfo, }, + { + .cmd = ETHTOOL_MSG_LINKMODES_GET, + .doit = ethnl_default_doit, + .start = ethnl_default_start, + .dumpit = ethnl_default_dumpit, + .done = ethnl_default_done, + }, };static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/netlink.h +1 -0
@@ -332,6 +332,7 @@ struct ethnl_request_ops {extern const struct ethnl_request_ops ethnl_strset_request_ops;extern const struct ethnl_request_ops ethnl_linkinfo_request_ops; +extern const struct ethnl_request_ops ethnl_linkmodes_request_ops;int ethnl_set_linkinfo (struct sk_buff *skb,struct genl_info *info);
Signature · 1 line
2.24.1
Re: [PATCH net-next v8 11/14] ethtool: provide link mode information with LINKMODES_GET request
Quoted 4 lines · Michal Kubecek
Implement
LINKMODES_GETnetlink request to get link modes related information provided byETHTOOL_GLINKSETTINGSandETHTOOL_GSETioctl commands.
Quoted 8 lines
This request provides supported, advertised and peer advertised link modes, autonegotiation flag, speed and duplex.
LINKMODES_GETrequest can be used withNLM_F_DUMP(without device identification) to request the information for all devices in current network namespace providing the data.Signed-off-by Michal Kubecek <[email protected]>
Signature · 1 line
Florian
PATCH v8 12/14 ethtool: set link modes related data with LINKMODES_SET request
In reply to Michal KubecekImplement LINKMODES_SET netlink request to set advertised linkmodes and related attributes as ETHTOOL_SLINKSETTINGS and ETHTOOL_SSET commands do.
The request allows setting autonegotiation flag, speed, duplex and advertised link modes.
--- Documentation/networking/ethtool-netlink.rst | 27 +++ include/uapi/linux/ethtool_netlink.h | 1 + net/ethtool/linkmodes.c | 235 +++++++++++++++++++ net/ethtool/netlink.c | 5 + net/ethtool/netlink.h | 1 + 5 files changed, 269 insertions(+)
Documentation/networking/ethtool-netlink.rst +27 -0
@@ -173,6 +173,7 @@ Userspace to kernel: ``ETHTOOL_MSG_LINKINFO_GET`` get link settings ``ETHTOOL_MSG_LINKINFO_SET`` set link settings ``ETHTOOL_MSG_LINKMODES_GET`` get link modes info + ``ETHTOOL_MSG_LINKMODES_SET`` set link modes info ===================================== ================================ Kernel to userspace:
@@ -356,6 +357,30 @@ list. devices supporting the request). +LINKMODES_SET +============= + +Request contents: + + ==================================== ====== ========================== + ``ETHTOOL_A_LINKMODES_HEADER`` nested request header + ``ETHTOOL_A_LINKMODES_AUTONEG`` u8 autonegotiation status + ``ETHTOOL_A_LINKMODES_OURS`` bitset advertised link modes + ``ETHTOOL_A_LINKMODES_PEER`` bitset partner link modes + ``ETHTOOL_A_LINKMODES_SPEED`` u32 link speed (Mb/s) + ``ETHTOOL_A_LINKMODES_DUPLEX`` u8 duplex mode + ==================================== ====== ========================== + +``ETHTOOL_A_LINKMODES_OURS`` bit set allows setting advertised link modes. If +autonegotiation is on (either set now or kept from before), advertised modes +are not changed (no ``ETHTOOL_A_LINKMODES_OURS`` attribute) and at least one +of speed and duplex is specified, kernel adjusts advertised modes to all +supported modes matching speed, duplex or both (whatever is specified). This +autoselection is done on ethtool side with ioctl interface, netlink interface +is supposed to allow requesting changes without knowing what exactly kernel +supports. + + Request translation ===================
@@ -369,6 +394,7 @@ have their netlink replacement yet. ``ETHTOOL_GSET`` ``ETHTOOL_MSG_LINKINFO_GET`` ``ETHTOOL_MSG_LINKMODES_GET`` ``ETHTOOL_SSET`` ``ETHTOOL_MSG_LINKINFO_SET`` + ``ETHTOOL_MSG_LINKMODES_SET`` ``ETHTOOL_GDRVINFO`` n/a ``ETHTOOL_GREGS`` n/a ``ETHTOOL_GWOL`` n/a
@@ -444,6 +470,7 @@ have their netlink replacement yet. ``ETHTOOL_GLINKSETTINGS`` ``ETHTOOL_MSG_LINKINFO_GET`` ``ETHTOOL_MSG_LINKMODES_GET`` ``ETHTOOL_SLINKSETTINGS`` ``ETHTOOL_MSG_LINKINFO_SET`` + ``ETHTOOL_MSG_LINKMODES_SET`` ``ETHTOOL_PHY_GTUNABLE`` n/a ``ETHTOOL_PHY_STUNABLE`` n/a ``ETHTOOL_GFECPARAM`` n/a
include/uapi/linux/ethtool_netlink.h +1 -0
@@ -18,6 +18,7 @@ enum {ETHTOOL_MSG_LINKINFO_GET ,ETHTOOL_MSG_LINKINFO_SET ,ETHTOOL_MSG_LINKMODES_GET , +ETHTOOL_MSG_LINKMODES_SET ,/* add new constants above here */ __ETHTOOL_MSG_USER_CNT,
net/ethtool/linkmodes.c +235 -0
238 lines not on this page · raw message
net/ethtool/netlink.c +5 -0
@@ -638,6 +638,11 @@ static const struct genl_ops ethtool_genl_ops[] = { .dumpit = ethnl_default_dumpit, .done = ethnl_default_done, }, + { + .cmd = ETHTOOL_MSG_LINKMODES_SET, + .flags = GENL_UNS_ADMIN_PERM, + .doit = ethnl_set_linkmodes, + }, };static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/netlink.h +1 -0
@@ -335,5 +335,6 @@ extern const struct ethnl_request_ops ethnl_linkinfo_request_ops;extern const struct ethnl_request_ops ethnl_linkmodes_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);#endif /* _NET_ETHTOOL_NETLINK_H */
Signature · 1 line
2.24.1
Re: [PATCH net-next v8 12/14] ethtool: set link modes related data with LINKMODES_SET request
Quoted 8 lines · Michal Kubecek
Implement
LINKMODES_SETnetlink request to set advertised linkmodes and related attributes asETHTOOL_SLINKSETTINGSandETHTOOL_SSETcommands do.The request allows setting autonegotiation flag, speed, duplex and advertised link modes.
Signed-off-by Michal Kubecek <[email protected]>---
Signature · 1 line
Florian
PATCH v8 13/14 ethtool: add LINKMODES_NTF notification
In reply to Michal KubecekSend ETHTOOL_MSG_LINKMODES_NTF notification message whenever device link settings or advertised modes are modified using ETHTOOL_MSG_LINKMODES_SET netlink message or ETHTOOL_SLINKSETTINGS or ETHTOOL_SSET ioctl commands.
The notification message has the same format as reply to LINKMODES_GET request. ETHTOOL_MSG_LINKMODES_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 LINKMODES_GET requests, all that remains is adding entries for ETHTOOL_MSG_LINKMODES_NTF into ethnl_notify_handlers and ethnl_default_notify_ops lookup tables and calls to ethtool_notify() where needed.
--- Documentation/networking/ethtool-netlink.rst | 1 + include/uapi/linux/ethtool_netlink.h | 1 + net/ethtool/ioctl.c | 8 ++++++-- net/ethtool/linkmodes.c | 2 ++ net/ethtool/netlink.c | 2 ++ 5 files changed, 12 insertions(+), 2 deletions(-)
Documentation/networking/ethtool-netlink.rst +1 -0
@@ -183,6 +183,7 @@ Kernel to userspace: ``ETHTOOL_MSG_LINKINFO_GET_REPLY`` link settings ``ETHTOOL_MSG_LINKINFO_NTF`` link settings notification ``ETHTOOL_MSG_LINKMODES_GET_REPLY`` link modes info + ``ETHTOOL_MSG_LINKMODES_NTF`` link modes notification ===================================== ================================ ``GET`` requests are sent by userspace applications to retrieve device
include/uapi/linux/ethtool_netlink.h +1 -0
@@ -32,6 +32,7 @@ enum {ETHTOOL_MSG_LINKINFO_GET_REPLY ,ETHTOOL_MSG_LINKINFO_NTF ,ETHTOOL_MSG_LINKMODES_GET_REPLY , +ETHTOOL_MSG_LINKMODES_NTF ,/* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT,
net/ethtool/ioctl.c +6 -2
@@ -573,8 +573,10 @@ static int ethtool_set_link_ksettings(struct net_device *dev,return -EINVAL ; err = dev->ethtool_ops->set_link_ksettings (dev, &link_ksettings); -if (err >=0 ) +if (err >=0 ) {ethtool_notify (dev,ETHTOOL_MSG_LINKINFO_NTF ,NULL ); +ethtool_notify (dev,ETHTOOL_MSG_LINKMODES_NTF ,NULL ); + }return err; }
@@ -638,8 +640,10 @@ static int ethtool_set_settings(struct net_device *dev, void __user *useraddr) link_ksettings.base.link_mode_masks_nwords = __ETHTOOL_LINK_MODE_MASK_NU32; ret = dev->ethtool_ops->set_link_ksettings (dev, &link_ksettings); -if (ret >=0 ) +if (ret >=0 ) {ethtool_notify (dev,ETHTOOL_MSG_LINKINFO_NTF ,NULL ); +ethtool_notify (dev,ETHTOOL_MSG_LINKMODES_NTF ,NULL ); + }return ret; }
net/ethtool/linkmodes.c +2 -0
@@ -364,6 +364,8 @@ int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info) ret = dev->ethtool_ops->set_link_ksettings (dev, &ksettings);if (ret <0 )GENL_SET_ERR_MSG (info,"link settings update failed" ); +else +ethtool_notify (dev,ETHTOOL_MSG_LINKMODES_NTF ,NULL ); } out_ops:
net/ethtool/netlink.c +2 -0
@@ -511,6 +511,7 @@ static int ethnl_default_done(struct netlink_callback *cb)static const struct ethnl_request_ops * ethnl_default_notify_ops[ETHTOOL_MSG_KERNEL_MAX +1 ] = { [ETHTOOL_MSG_LINKINFO_NTF ] = ðnl_linkinfo_request_ops, + [ETHTOOL_MSG_LINKMODES_NTF ] = ðnl_linkmodes_request_ops, };/* default notification handler */
@@ -592,6 +593,7 @@ typedef void (*ethnl_notify_handler_t)(struct net_device *dev, unsigned int cmd,static const ethnl_notify_handler_t ethnl_notify_handlers[] = { [ETHTOOL_MSG_LINKINFO_NTF ] = ethnl_default_notify, + [ETHTOOL_MSG_LINKMODES_NTF ] = ethnl_default_notify, };void ethtool_notify (struct net_device *dev,unsigned int cmd,const void *data)
Signature · 1 line
2.24.1
Re: [PATCH net-next v8 13/14] ethtool: add LINKMODES_NTF notification
Quoted 10 lines · Michal Kubecek
Send
ETHTOOL_MSG_LINKMODES_NTFnotification message whenever device link settings or advertised modes are modified usingETHTOOL_MSG_LINKMODES_SETnetlink message orETHTOOL_SLINKSETTINGSorETHTOOL_SSETioctl commands.The notification message has the same format as reply to
LINKMODES_GETrequest.ETHTOOL_MSG_LINKMODES_SETnetlink 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.
Quoted 7 lines
As all work is done by
ethnl_default_notify()handler and callback functions introduced to handleLINKMODES_GETrequests, all that remains is adding entries forETHTOOL_MSG_LINKMODES_NTFintoethnl_notify_handlersandethnl_default_notify_opslookup tables and calls toethtool_notify()where needed.Signed-off-by Michal Kubecek <[email protected]>
Signature · 1 line
Florian
PATCH v8 14/14 ethtool: provide link state with LINKSTATE_GET request
In reply to Michal KubecekImplement LINKSTATE_GET netlink request to get link state information.
At the moment, only link up flag as provided by ETHTOOL_GLINK ioctl command is returned.
LINKSTATE_GET request can be used with NLM_F_DUMP (without device identification) to request the information for all devices in current network namespace providing the data.
--- Documentation/networking/ethtool-netlink.rst | 33 ++++++++- include/uapi/linux/ethtool_netlink.h | 14 ++++ net/ethtool/Makefile | 3 +- net/ethtool/common.c | 8 +++ net/ethtool/common.h | 3 + net/ethtool/ioctl.c | 8 +-- net/ethtool/linkstate.c | 74 ++++++++++++++++++++ net/ethtool/netlink.c | 8 +++ net/ethtool/netlink.h | 1 + 9 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 net/ethtool/linkstate.c
Documentation/networking/ethtool-netlink.rst +32 -1
@@ -174,6 +174,7 @@ Userspace to kernel: ``ETHTOOL_MSG_LINKINFO_SET`` set link settings ``ETHTOOL_MSG_LINKMODES_GET`` get link modes info ``ETHTOOL_MSG_LINKMODES_SET`` set link modes info + ``ETHTOOL_MSG_LINKSTATE_GET`` get link state ===================================== ================================ Kernel to userspace:
@@ -184,6 +185,7 @@ Kernel to userspace: ``ETHTOOL_MSG_LINKINFO_NTF`` link settings notification ``ETHTOOL_MSG_LINKMODES_GET_REPLY`` link modes info ``ETHTOOL_MSG_LINKMODES_NTF`` link modes notification + ``ETHTOOL_MSG_LINKSTATE_GET_REPLY`` link state info ===================================== ================================ ``GET`` requests are sent by userspace applications to retrieve device
@@ -382,6 +384,35 @@ is supposed to allow requesting changes without knowing what exactly kernel supports. +LINKSTATE_GET +============= + +Requests link state information. At the moment, only link up/down flag (as +provided by ``ETHTOOL_GLINK`` ioctl command) is provided but some future +extensions are planned (e.g. link down reason). This request does not have any +attributes. + +Request contents: + + ==================================== ====== ========================== + ``ETHTOOL_A_LINKSTATE_HEADER`` nested request header + ==================================== ====== ========================== + +Kernel response contents: + + ==================================== ====== ========================== + ``ETHTOOL_A_LINKSTATE_HEADER`` nested reply header + ``ETHTOOL_A_LINKSTATE_LINK`` u8 autonegotiation status + ==================================== ====== ========================== + +For most NIC drivers, the value of ``ETHTOOL_A_LINKSTATE_LINK`` returns +carrier flag provided by ``netif_carrier_ok()`` but there are drivers which +define their own handler. + +``LINKSTATE_GET`` allows dump requests (kernel returns reply messages for all +devices supporting the request). + + Request translation ===================
@@ -403,7 +434,7 @@ have their netlink replacement yet. ``ETHTOOL_GMSGLVL`` n/a ``ETHTOOL_SMSGLVL`` n/a ``ETHTOOL_NWAY_RST`` n/a - ``ETHTOOL_GLINK`` n/a + ``ETHTOOL_GLINK`` ``ETHTOOL_MSG_LINKSTATE_GET`` ``ETHTOOL_GEEPROM`` n/a ``ETHTOOL_SEEPROM`` n/a ``ETHTOOL_GCOALESCE`` n/a
include/uapi/linux/ethtool_netlink.h +14 -0
@@ -19,6 +19,7 @@ enum {ETHTOOL_MSG_LINKINFO_SET ,ETHTOOL_MSG_LINKMODES_GET ,ETHTOOL_MSG_LINKMODES_SET , +ETHTOOL_MSG_LINKSTATE_GET ,/* add new constants above here */ __ETHTOOL_MSG_USER_CNT,
@@ -33,6 +34,7 @@ enum {ETHTOOL_MSG_LINKINFO_NTF ,ETHTOOL_MSG_LINKMODES_GET_REPLY ,ETHTOOL_MSG_LINKMODES_NTF , +ETHTOOL_MSG_LINKSTATE_GET_REPLY ,/* add new constants above here */ __ETHTOOL_MSG_KERNEL_CNT,
@@ -181,6 +183,18 @@ enum { ETHTOOL_A_LINKMODES_MAX = __ETHTOOL_A_LINKMODES_CNT - 1 }; +/* LINKSTATE */ + +enum { +ETHTOOL_A_LINKSTATE_UNSPEC , +ETHTOOL_A_LINKSTATE_HEADER ,/* nest - _A_HEADER_* */ +ETHTOOL_A_LINKSTATE_LINK ,/* u8 */ + +/* add new constants above here */ + __ETHTOOL_A_LINKSTATE_CNT, +ETHTOOL_A_LINKSTATE_MAX = __ETHTOOL_A_LINKSTATE_CNT -1 +}; +/* generic netlink info */ #define ETHTOOL_GENL_NAME "ethtool"#define ETHTOOL_GENL_VERSION 1
net/ethtool/Makefile +2 -1
@@ -4,4 +4,5 @@ obj-y += ioctl.o common.o obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_nl.o -ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o +ethtool_nl-y := netlink.o bitset.o strset.o linkinfo.o linkmodes.o \ + linkstate.o
net/ethtool/common.c +8 -0
@@ -217,3 +217,11 @@ convert_legacy_settings_to_link_ksettings( = legacy_settings->eth_tp_mdix_ctrl;return retval; } + +int __ethtool_get_link (struct net_device *dev) +{ +if (!dev->ethtool_ops->get_link) +return -EOPNOTSUPP ; + +return netif_running (dev) && dev->ethtool_ops->get_link (dev); +}
net/ethtool/common.h +3 -0
@@ -3,6 +3,7 @@#ifndef _ETHTOOL_COMMON_H#define _ETHTOOL_COMMON_H +#include <linux/netdevice.h> #include <linux/ethtool.h> /* compose link mode index from speed, type and duplex */
@@ -19,6 +20,8 @@ extern const char phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN ];extern const char link_mode_names[][ETH_GSTRING_LEN ]; +int __ethtool_get_link (struct net_device *dev); +bool convert_legacy_settings_to_link_ksettings (struct ethtool_link_ksettings *link_ksettings,const struct ethtool_cmd *legacy_settings);
net/ethtool/ioctl.c +4 -4
@@ -1365,12 +1365,12 @@ static int ethtool_nway_reset(struct net_device *dev)static int ethtool_get_link (struct net_device *dev,char __user *useraddr) {struct ethtool_value edata = { .cmd =ETHTOOL_GLINK }; +int link =__ethtool_get_link (dev); -if (!dev->ethtool_ops->get_link) -return -EOPNOTSUPP ; - - edata.data =netif_running (dev) && dev->ethtool_ops->get_link (dev); +if (link <0 ) +return link; + edata.data = link;if (copy_to_user (useraddr, &edata,sizeof (edata)))return -EFAULT ;return 0 ;
net/ethtool/linkstate.c new file +74 -0
74 lines not on this page · raw message
net/ethtool/netlink.c +8 -0
@@ -210,6 +210,7 @@ ethnl_default_requests[__ETHTOOL_MSG_USER_CNT] = { [ETHTOOL_MSG_STRSET_GET] = ðnl_strset_request_ops, [ETHTOOL_MSG_LINKINFO_GET] = ðnl_linkinfo_request_ops, [ETHTOOL_MSG_LINKMODES_GET] = ðnl_linkmodes_request_ops, + [ETHTOOL_MSG_LINKSTATE_GET] = ðnl_linkstate_request_ops, };static struct ethnl_dump_ctx *ethnl_dump_context (struct netlink_callback *cb)
@@ -645,6 +646,13 @@ static const struct genl_ops ethtool_genl_ops[] = { .flags = GENL_UNS_ADMIN_PERM, .doit = ethnl_set_linkmodes, }, + { + .cmd = ETHTOOL_MSG_LINKSTATE_GET, + .doit = ethnl_default_doit, + .start = ethnl_default_start, + .dumpit = ethnl_default_dumpit, + .done = ethnl_default_done, + }, };static const struct genl_multicast_group ethtool_nl_mcgrps[] = {
net/ethtool/netlink.h +1 -0
@@ -333,6 +333,7 @@ struct ethnl_request_ops {extern const struct ethnl_request_ops ethnl_strset_request_ops;extern const struct ethnl_request_ops ethnl_linkinfo_request_ops;extern const struct ethnl_request_ops ethnl_linkmodes_request_ops; +extern const struct ethnl_request_ops ethnl_linkstate_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);
Signature · 1 line
2.24.1
Re: [PATCH net-next v8 14/14] ethtool: provide link state with LINKSTATE_GET request
Quoted 11 lines · Michal Kubecek
Implement
LINKSTATE_GETnetlink request to get link state information.At the moment, only link up flag as provided by
ETHTOOL_GLINKioctl command is returned.
LINKSTATE_GETrequest can be used withNLM_F_DUMP(without device identification) to request the information for all devices in current network namespace providing the data.Signed-off-by Michal Kubecek <[email protected]>---
[snip]
Documentation/networking/ethtool-netlink.rst is supposed to allow requesting changes without knowing what exactly kernel · line 405
Quoted 5 lines
Documentation/networking/ethtool-netlink.rst +5
-0+Kernel response contents: + + ==================================== ====== ========================== + ``ETHTOOL_A_LINKSTATE_HEADER`` nested reply header + ``ETHTOOL_A_LINKSTATE_LINK`` u8 autonegotiation status
^ ==== Humm, auto-negotiation status may not be exactly accurate especially with complex devices with SerDes/PHY/SFPs/what have you/. Other than that, the code looks correct:
Signature · 1 line
Florian
Re: [PATCH net-next v8 14/14] ethtool: provide link state with LINKSTATE_GET request
Quoted 17 lines · Florian Fainelli
Quoted 11 lines · Michal Kubecek
Implement
LINKSTATE_GETnetlink request to get link state information.At the moment, only link up flag as provided by
ETHTOOL_GLINKioctl command is returned.
LINKSTATE_GETrequest can be used withNLM_F_DUMP(without device identification) to request the information for all devices in current network namespace providing the data.Signed-off-by Michal Kubecek <[email protected]>---
[snip]
Quoted 9 lines
Documentation/networking/ethtool-netlink.rst is supposed to allow requesting changes without knowing what exactly kernel · line 405
Quoted 5 lines
Documentation/networking/ethtool-netlink.rst +5
-0+Kernel response contents: + + ==================================== ====== ========================== + ``ETHTOOL_A_LINKSTATE_HEADER`` nested reply header + ``ETHTOOL_A_LINKSTATE_LINK`` u8 autonegotiation status^ ==== Humm, auto-negotiation status may not be exactly accurate especially with complex devices with SerDes/PHY/SFPs/what have you/. Other than that, the code looks correct:
It seems I forgot to edit this cell text after copy&paste from LINKMODES_GET above. Fixed in v9, thanks.
Michal
Quoted 3 lines
Reviewed-by Florian Fainelli <[email protected]>Signature · 1 line
Florian
Hi Michal,
Quoted 15 lines · Michal Kubecek
This is first part of netlink based alternative userspace interface for ethtool. It aims to address some long known issues with the ioctl interface, mainly lack of extensibility, raciness, limited error reporting and absence of notifications. The goal is to allow userspace ethtool utility to provide all features it currently does but without using the ioctl interface. However, some features provided by ethtool ioctl API will be available through other netlink interfaces (rtnetlink, devlink) if it's more appropriate.
The interface uses generic netlink family "ethtool" and provides multicast group "monitor" which is used for notifications. Documentation for the interface is in
Documentation/networking/ethtool-netlink.rstfile. The netlink interface is optional, it is built whenCONFIG_ETHTOOL_NETLINK(bool) option is enabled.
Quoted 7 lines
There are three types of request messages distinguished by suffix "
_GET" (query for information), "_SET" (modify parameters) and "_ACT" (perform an action). Kernel reply messages have name with additional suffix "_REPLY" (e.g.ETHTOOL_MSG_SETTINGS_GET_REPLY). Most "_SET" and "_ACT" message types do not have matching reply type as only some of them need additional reply data beyond numeric error code and extack. Kernel also broadcasts notification messages ("_NTF" suffix) on changes.
Thanks for re-posting these patches again, would you have ethtool and iproute2 branches with your latest ethnl patches applied? I did find your ethnl directory on your github, but it applies to a slightly oldish ethtool version. If you could maintain forks with an "ethnl" branch there, that would help greatly.
I will continue reviewing from there on, but also wanted to give it a spin to get a feel.
Thanks!
Signature · 1 line
Florian
Quoted 26 lines · Florian Fainelli
Hi Michal,
Quoted 15 lines · Michal Kubecek
This is first part of netlink based alternative userspace interface for ethtool. It aims to address some long known issues with the ioctl interface, mainly lack of extensibility, raciness, limited error reporting and absence of notifications. The goal is to allow userspace ethtool utility to provide all features it currently does but without using the ioctl interface. However, some features provided by ethtool ioctl API will be available through other netlink interfaces (rtnetlink, devlink) if it's more appropriate.
The interface uses generic netlink family "ethtool" and provides multicast group "monitor" which is used for notifications. Documentation for the interface is in
Documentation/networking/ethtool-netlink.rstfile. The netlink interface is optional, it is built whenCONFIG_ETHTOOL_NETLINK(bool) option is enabled.Quoted 7 lines
There are three types of request messages distinguished by suffix "
_GET" (query for information), "_SET" (modify parameters) and "_ACT" (perform an action). Kernel reply messages have name with additional suffix "_REPLY" (e.g.ETHTOOL_MSG_SETTINGS_GET_REPLY). Most "_SET" and "_ACT" message types do not have matching reply type as only some of them need additional reply data beyond numeric error code and extack. Kernel also broadcasts notification messages ("_NTF" suffix) on changes.
Quoted 5 lines
Thanks for re-posting these patches again, would you have ethtool and iproute2 branches with your latest ethnl patches applied? I did find your ethnl directory on your github, but it applies to a slightly oldish ethtool version. If you could maintain forks with an "ethnl" branch there, that would help greatly.
The iproute2 patch (adding display of permanent hardware address) is in iproute2 "next" tree. As for (userspace) ethtool code, at the moment it's not in a presentable state. As I wanted on getting v8 out as soon as possible, I focused on making it work somehow so that I can test the kernel patchset. So at the moment, the userspace series is still in the form of an older one (implementing older UAPI) plus one bit "work in progress" patch adapting it to current UAPI.
The userspace code also still doesn't look the way I would like it to. I would like to spend some more time on it in second half of this week and then I plan to also update the repository on github.
Michal
Quoted 6 lines
I will continue reviewing from there on, but also wanted to give it a spin to get a feel.
Thanks!
Signature · 1 line
Florian
Quoted 41 lines · Michal Kubecek
Quoted 26 lines · Florian Fainelli
Hi Michal,
Quoted 15 lines · Michal Kubecek
This is first part of netlink based alternative userspace interface for ethtool. It aims to address some long known issues with the ioctl interface, mainly lack of extensibility, raciness, limited error reporting and absence of notifications. The goal is to allow userspace ethtool utility to provide all features it currently does but without using the ioctl interface. However, some features provided by ethtool ioctl API will be available through other netlink interfaces (rtnetlink, devlink) if it's more appropriate.
The interface uses generic netlink family "ethtool" and provides multicast group "monitor" which is used for notifications. Documentation for the interface is in
Documentation/networking/ethtool-netlink.rstfile. The netlink interface is optional, it is built whenCONFIG_ETHTOOL_NETLINK(bool) option is enabled.Quoted 7 lines
There are three types of request messages distinguished by suffix "
_GET" (query for information), "_SET" (modify parameters) and "_ACT" (perform an action). Kernel reply messages have name with additional suffix "_REPLY" (e.g.ETHTOOL_MSG_SETTINGS_GET_REPLY). Most "_SET" and "_ACT" message types do not have matching reply type as only some of them need additional reply data beyond numeric error code and extack. Kernel also broadcasts notification messages ("_NTF" suffix) on changes.Quoted 5 lines
Thanks for re-posting these patches again, would you have ethtool and iproute2 branches with your latest ethnl patches applied? I did find your ethnl directory on your github, but it applies to a slightly oldish ethtool version. If you could maintain forks with an "ethnl" branch there, that would help greatly.
The iproute2 patch (adding display of permanent hardware address) is in iproute2 "next" tree. As for (userspace) ethtool code, at the moment it's not in a presentable state. As I wanted on getting v8 out as soon as possible, I focused on making it work somehow so that I can test the kernel patchset. So at the moment, the userspace series is still in the form of an older one (implementing older UAPI) plus one bit "work in progress" patch adapting it to current UAPI.
Quoted 3 lines
The userspace code also still doesn't look the way I would like it to. I would like to spend some more time on it in second half of this week and then I plan to also update the repository on github.
OK, no problem. The patches do look fine to me with a few comments here and there. I hope Jiri likes the user space ABI now, as it would be good to get your changes included, from there we can have many more hands to help with converting/extending the existing ioctl() interface.
Signature · 1 line
Florian
David Miller
maintainerFrom: Michal Kubecek <[email protected]>
Date: Mon, 23 Dec 2019 00:45:14 +0100 (CET)
Quoted 8 lines
This is first part of netlink based alternative userspace interface for ethtool. It aims to address some long known issues with the ioctl interface, mainly lack of extensibility, raciness, limited error reporting and absence of notifications. The goal is to allow userspace ethtool utility to provide all features it currently does but without using the ioctl interface. However, some features provided by ethtool ioctl API will be available through other netlink interfaces (rtnetlink, devlink) if it's more appropriate.
...
Please address the feedback for patch #3 (especially the u32-->u8 thing) and then this series should be good to go!
Thanks!