Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753168AbdLKNxi (ORCPT ); Mon, 11 Dec 2017 08:53:38 -0500 Received: from mx2.suse.de ([195.135.220.15]:60136 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752629AbdLKNxd (ORCPT ); Mon, 11 Dec 2017 08:53:33 -0500 Message-Id: <37174026f818dd1a61ca1b37bef2f1b114198de2.1513000306.git.mkubecek@suse.cz> In-Reply-To: References: From: Michal Kubecek Subject: [RFC PATCH 2/9] ethtool: introduce ethtool netlink interface To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org Date: Mon, 11 Dec 2017 14:53:31 +0100 (CET) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 9802 Lines: 315 No function implemented yet, only genetlink and module infrastructure. Register/unregister genetlink family "ethtool" and allow the module to be autoloaded by genetlink code (if built as a module, distributions would probably prefer "y"). Signed-off-by: Michal Kubecek --- Documentation/networking/ethtool-netlink.txt | 155 +++++++++++++++++++++++++++ include/linux/ethtool_netlink.h | 9 ++ include/uapi/linux/ethtool_netlink.h | 33 ++++++ net/Kconfig | 7 ++ net/core/Makefile | 1 + net/core/ethtool_netlink.c | 46 ++++++++ 6 files changed, 251 insertions(+) create mode 100644 Documentation/networking/ethtool-netlink.txt create mode 100644 include/linux/ethtool_netlink.h create mode 100644 include/uapi/linux/ethtool_netlink.h create mode 100644 net/core/ethtool_netlink.c diff --git a/Documentation/networking/ethtool-netlink.txt b/Documentation/networking/ethtool-netlink.txt new file mode 100644 index 000000000000..c94da66cb5fb --- /dev/null +++ b/Documentation/networking/ethtool-netlink.txt @@ -0,0 +1,155 @@ + 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 uapi header). This family uses a message +header of 24 bytes: + +struct ethnlmsghdr { + __u32 ifindex; + __u16 flags; + union { + __u16 info_mask; + __u16 index; + } + char ifname[IFNAMSIZ]; +}; + +In requests, device can be identified by ifindex or by name; if both are used, +they must match. In replies, kernel fills both. The meaning of flags, +info_mask and index fields depends on request type. + +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 request 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. + + +List of message types +--------------------- + +All constants use ETHTOOL_CMD_ prefix followed by "GET", "SET" or "ACT" to +indicate the type. + +Messages of type "get" are used by userspace to request information and +usually do not contain any attributes (that may be added later for dump +filtering). Kernel response is in the form of corresopinding "set" message; +the same message can be also used to set (some of) the parameters, except for +messages marked as "response only" in the table above. + +Later sections describe the format and semantics of these request messages. + + +Request translation +------------------- + +The following table maps iosctl 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 n/a +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 + diff --git a/include/linux/ethtool_netlink.h b/include/linux/ethtool_netlink.h new file mode 100644 index 000000000000..0412adb4f42f --- /dev/null +++ b/include/linux/ethtool_netlink.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ + +#ifndef _LINUX_ETHTOOL_NETLINK_H_ +#define _LINUX_ETHTOOL_NETLINK_H_ + +#include +#include + +#endif /* _LINUX_ETHTOOL_NETLINK_H_ */ diff --git a/include/uapi/linux/ethtool_netlink.h b/include/uapi/linux/ethtool_netlink.h new file mode 100644 index 000000000000..06cff2b52dfe --- /dev/null +++ b/include/uapi/linux/ethtool_netlink.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ + +#ifndef _UAPI_LINUX_ETHTOOL_NETLINK_H_ +#define _UAPI_LINUX_ETHTOOL_NETLINK_H_ + +#include + +/* identifies the device to query/set + * - use either ifindex or ifname, not both + * - for dumps and messages not related to a particular devices, fill neither + * - info_mask is a bitfield, interpretation depends on the command + */ +struct ethnlmsghdr { + __u32 ifindex; /* device ifindex */ + __u16 flags; /* request/response flags */ + __u16 info_mask; /* request/response info mask */ + char ifname[IFNAMSIZ]; /* device name */ +}; + +#define ETHNL_HDRLEN NLMSG_ALIGN(sizeof(struct ethnlmsghdr)) + +enum { + ETHTOOL_CMD_NOOP, + + __ETHTOOL_CMD_MAX, + ETHTOOL_CMD_MAX = (__ETHTOOL_CMD_MAX - 1), +}; + +/* generic netlink info */ +#define ETHTOOL_GENL_NAME "ethtool" +#define ETHTOOL_GENL_VERSION 1 + +#endif /* _UAPI_LINUX_ETHTOOL_NETLINK_H_ */ diff --git a/net/Kconfig b/net/Kconfig index 9dba2715919d..a5e3c89a2495 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -440,6 +440,13 @@ config MAY_USE_DEVLINK on MAY_USE_DEVLINK to ensure they do not cause link errors when devlink is a loadable module and the driver using it is built-in. +config ETHTOOL_NETLINK + tristate "Netlink interface for ethtool" + default m + help + New netlink based interface for ethtool which is going to obsolete + the old ioctl based one once it provides all features. + endif # if NET # Used by archs to tell that they support BPF JIT compiler plus which flavour. diff --git a/net/core/Makefile b/net/core/Makefile index 1fd0a9c88b1b..617ab2abecdf 100644 --- a/net/core/Makefile +++ b/net/core/Makefile @@ -30,3 +30,4 @@ obj-$(CONFIG_DST_CACHE) += dst_cache.o obj-$(CONFIG_HWBM) += hwbm.o obj-$(CONFIG_NET_DEVLINK) += devlink.o obj-$(CONFIG_GRO_CELLS) += gro_cells.o +obj-$(CONFIG_ETHTOOL_NETLINK) += ethtool_netlink.o diff --git a/net/core/ethtool_netlink.c b/net/core/ethtool_netlink.c new file mode 100644 index 000000000000..46a226bb9a2c --- /dev/null +++ b/net/core/ethtool_netlink.c @@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ + +#include +#include +#include +#include +#include "ethtool_common.h" + +static struct genl_family ethtool_genl_family; + +/* genetlink paperwork */ + +static const struct genl_ops ethtool_genl_ops[] = { +}; + +static struct genl_family ethtool_genl_family = { + .hdrsize = ETHNL_HDRLEN, + .name = ETHTOOL_GENL_NAME, + .version = ETHTOOL_GENL_VERSION, + .netnsok = true, + .ops = ethtool_genl_ops, + .n_ops = ARRAY_SIZE(ethtool_genl_ops), +}; + +/* module paperwork */ + +static int __init ethtool_nl_init(void) +{ + return genl_register_family(ðtool_genl_family); +} + +static void __exit ethtool_nl_exit(void) +{ + genl_unregister_family(ðtool_genl_family); +} + +module_init(ethtool_nl_init); +module_exit(ethtool_nl_exit); + +/* this alias is for autoload */ +MODULE_ALIAS("net-pf-" __stringify(PF_NETLINK) + "-proto-" __stringify(NETLINK_GENERIC) + "-family-" ETHTOOL_GENL_NAME); +MODULE_AUTHOR("Michal Kubecek "); +MODULE_DESCRIPTION("Netlink interface for ethtool"); +MODULE_LICENSE("GPL"); -- 2.15.1