initial netlink interface implementation for 5.6 release
Subsystems (3)
v2 cover initial netlink interface implementation for 5.6 release
This series adds initial support for ethtool netlink interface provided by kernel since 5.6-rc1. The traditional ioctl interface is still supported for compatibility with older kernels. The netlink interface and message formats are documented in Documentation/networking/ethtool-netlink.rst file in kernel source tree.
Netlink interface is preferred but ethtool falls back to ioctl if netlink interface is not available (i.e. the "ethtool" genetlink family is not registered). It also falls back if a particular command is not implemented in netlink (kernel returns -EOPNOTSUPP). This allows new ethtool versions to work with older kernel versions while support for ethool commands is added in steps.
The series aims to touch existing ioctl code as little as possible in the first phase to minimize the risk of introducing regressions. It is also possible to build ethtool without netlink support if --disable-netlink is passed to configure script. The most visible changes to existing code are
- UAPI header copies are moved to uapi/ under original names
- some variables and functions which are going to be shared with netlink code are moved from ethtool.c to common.c and common.h
- args[] array in ethtool.c was rewritten to use named initializers
Except for changes to main(), all netlink specific code is in a separate directory netlink/ and is divided into multiple files.
Changes in v2:
- add support for permanent hardware addres ("ethtool -P", patch 20)
- add support for pretty printing of netlink messages (patches 21-25)
- make output of "ethtool <dev>" closer to ioctl implementation
- two more kernel uapi header copies (patch 5)
- support for rtnetlink socket and requests (needed for "ethtool -P")
- some kerneldoc style comments
Michal Kubecek (25):
move UAPI header copies to a separate directory update UAPI header copies
add --debug option to control debugging messages use named initializers in command line option list
netlink: add netlink related UAPI header files
netlink: introduce the netlink interface
netlink: message buffer and composition helpers
netlink: netlink socket wrapper and helpers
netlink: initialize ethtool netlink socket
netlink: add support for string sets
netlink: add notification monitor
move shared code into a common file
netlink: add bitset helpers
netlink: partial netlink handler for gset (no option)
netlink: support getting wake-on-lan and debugging settings
netlink: add basic command line parsing helpers
netlink: add bitset command line parser handlers
netlink: add netlink handler for sset (-s)
netlink: support tests with netlink enabled
netlink: add handler for permaddr (-P)
netlink: support for pretty printing netlink messages
netlink: message format description for ethtool netlink
netlink: message format descriptions for genetlink control
netlink: message format descriptions for rtnetlink
netlink: use pretty printing for ethtool netlink messages
Makefile.am | 31 +- common.c | 145 +++ common.h | 26 + configure.ac | 14 +- ethtool.8.in | 48 +- ethtool.c | 819 ++++++++------ internal.h | 31 +- netlink/bitset.c | 218 ++++ netlink/bitset.h | 26 + netlink/desc-ethtool.c | 139 +++ netlink/desc-genlctrl.c | 56 + netlink/desc-rtnl.c | 96 ++ netlink/extapi.h | 46 + netlink/monitor.c | 229 ++++ netlink/msgbuff.c | 255 +++++ netlink/msgbuff.h | 117 ++ netlink/netlink.c | 216 ++++ netlink/netlink.h | 87 ++ netlink/nlsock.c | 405 +++++++ netlink/nlsock.h | 45 + netlink/parser.c | 1058 ++++++++++++++++++ netlink/parser.h | 144 +++ netlink/permaddr.c | 114 ++ netlink/prettymsg.c | 237 ++++ netlink/prettymsg.h | 118 ++ netlink/settings.c | 955 ++++++++++++++++ netlink/strset.c | 297 +++++ netlink/strset.h | 25 + test-cmdline.c | 29 +- test-features.c | 11 + ethtool-copy.h => uapi/linux/ethtool.h | 17 + uapi/linux/ethtool_netlink.h | 237 ++++ uapi/linux/genetlink.h | 89 ++ uapi/linux/if_link.h | 1051 +++++++++++++++++ net_tstamp-copy.h => uapi/linux/net_tstamp.h | 27 + uapi/linux/netlink.h | 248 ++++ uapi/linux/rtnetlink.h | 777 +++++++++++++ 37 files changed, 8102 insertions(+), 381 deletions(-) create mode 100644 common.c create mode 100644 common.h create mode 100644 netlink/bitset.c create mode 100644 netlink/bitset.h create mode 100644 netlink/desc-ethtool.c create mode 100644 netlink/desc-genlctrl.c create mode 100644 netlink/desc-rtnl.c create mode 100644 netlink/extapi.h create mode 100644 netlink/monitor.c create mode 100644 netlink/msgbuff.c create mode 100644 netlink/msgbuff.h create mode 100644 netlink/netlink.c create mode 100644 netlink/netlink.h create mode 100644 netlink/nlsock.c create mode 100644 netlink/nlsock.h create mode 100644 netlink/parser.c create mode 100644 netlink/parser.h create mode 100644 netlink/permaddr.c create mode 100644 netlink/prettymsg.c create mode 100644 netlink/prettymsg.h create mode 100644 netlink/settings.c create mode 100644 netlink/strset.c create mode 100644 netlink/strset.h rename ethtool-copy.h => uapi/linux/ethtool.h (99%) create mode 100644 uapi/linux/ethtool_netlink.h create mode 100644 uapi/linux/genetlink.h create mode 100644 uapi/linux/if_link.h rename net_tstamp-copy.h => uapi/linux/net_tstamp.h (84%) create mode 100644 uapi/linux/netlink.h create mode 100644 uapi/linux/rtnetlink.h
Signature · 1 line
2.25.1
PATCH v2 1/25 move UAPI header copies to a separate directory
The upcoming netlink series is going to add more local copies of kernel UAPI header files and some of them are going to include others. Keeping them in the main directory under modified name would require modifying those includes as well which would be impractical.
Create a subdirectory uapi and move the UAPI headers there to allow including them in the usual way.
--- Makefile.am | 10 +++++----- internal.h | 4 ++-- ethtool-copy.h => uapi/linux/ethtool.h | 0 net_tstamp-copy.h => uapi/linux/net_tstamp.h | 0 4 files changed, 7 insertions(+), 7 deletions(-) rename ethtool-copy.h => uapi/linux/ethtool.h (100%) rename net_tstamp-copy.h => uapi/linux/net_tstamp.h (100%)
Makefile.am +5 -5
@@ -1,12 +1,12 @@ -AM_CFLAGS = -Wall +AM_CFLAGS = -I./uapi -Wall LDADD = -lm man_MANS = ethtool.8 EXTRA_DIST = LICENSE ethtool.8 ethtool.spec.in aclocal.m4 ChangeLog autogen.sh sbin_PROGRAMS = ethtool -ethtool_SOURCES = ethtool.c ethtool-copy.h internal.h net_tstamp-copy.h \ - rxclass.c +ethtool_SOURCES = ethtool.c uapi/linux/ethtool.h internal.h \ + uapi/linux/net_tstamp.h rxclass.c if ETHTOOL_ENABLE_PRETTY_DUMP ethtool_SOURCES += \ amd8111e.c de2104x.c dsa.c e100.c e1000.c et131x.c igb.c \
@@ -25,9 +25,9 @@ endif TESTS = test-cmdline test-features check_PROGRAMS = test-cmdline test-features test_cmdline_SOURCES = test-cmdline.c test-common.c $(ethtool_SOURCES) -test_cmdline_CFLAGS = -DTEST_ETHTOOL +test_cmdline_CFLAGS = $(AM_FLAGS) -DTEST_ETHTOOL test_features_SOURCES = test-features.c test-common.c $(ethtool_SOURCES) -test_features_CFLAGS = -DTEST_ETHTOOL +test_features_CFLAGS = $(AM_FLAGS) -DTEST_ETHTOOL dist-hook: cp $(top_srcdir)/ethtool.spec $(distdir)
internal.h +2 -2
@@ -44,8 +44,8 @@ typedef int32_t s32;#define __KERNEL_DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d))#endif -#include "ethtool-copy.h" -#include "net_tstamp-copy.h" +#include <linux/ethtool.h> +#include <linux/net_tstamp.h> #if __BYTE_ORDER == __BIG_ENDIANstatic inline u16 cpu_to_be16 (u16 value)
uapi/linux/ethtool.h renamed from ethtool-copy.h +0 -0
uapi/linux/net_tstamp.h renamed from net_tstamp-copy.h +0 -0
Signature · 1 line
2.25.1
PATCH v2 2/25 update UAPI header copies
In reply to Michal KubecekUpdate to v5.6-rc1.
--- uapi/linux/ethtool.h | 17 +++++++++++++++++ uapi/linux/net_tstamp.h | 27 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+)
uapi/linux/ethtool.h +17 -0
@@ -591,6 +591,9 @@ struct ethtool_pauseparam {* @ETH_SS_RSS_HASH_FUNCS: RSS hush function names * @ETH_SS_PHY_STATS: Statistic names, for use with %ETHTOOL_GPHYSTATS * @ETH_SS_PHY_TUNABLES: PHY tunable names +* @ETH_SS_LINK_MODES: link mode names +* @ETH_SS_MSG_CLASSES: debug message class names +* @ETH_SS_WOL_MODES: wake-on-lan modes */ enum ethtool_stringset {ETH_SS_TEST =0 ,
@@ -602,6 +605,12 @@ enum ethtool_stringset {ETH_SS_TUNABLES ,ETH_SS_PHY_STATS ,ETH_SS_PHY_TUNABLES , +ETH_SS_LINK_MODES , +ETH_SS_MSG_CLASSES , +ETH_SS_WOL_MODES , + +/* add new constants above here */ + ETH_SS_COUNT };/**
@@ -1505,6 +1514,11 @@ enum ethtool_link_mode_bit_indices { ETHTOOL_LINK_MODE_200000baseCR4_Full_BIT =66 , ETHTOOL_LINK_MODE_100baseT1_Full_BIT =67 , ETHTOOL_LINK_MODE_1000baseT1_Full_BIT =68 , + ETHTOOL_LINK_MODE_400000baseKR8_Full_BIT =69 , + ETHTOOL_LINK_MODE_400000baseSR8_Full_BIT =70 , + ETHTOOL_LINK_MODE_400000baseLR8_ER8_FR8_Full_BIT =71 , + ETHTOOL_LINK_MODE_400000baseDR8_Full_BIT =72 , + ETHTOOL_LINK_MODE_400000baseCR8_Full_BIT =73 ,/* must be last entry */ __ETHTOOL_LINK_MODE_MASK_NBITS
@@ -1616,6 +1630,7 @@ enum ethtool_link_mode_bit_indices {#define SPEED_56000 56000#define SPEED_100000 100000#define SPEED_200000 200000 +#define SPEED_400000 400000#define SPEED_UNKNOWN -1
@@ -1680,6 +1695,8 @@ static __inline__ int ethtool_validate_duplex(__u8 duplex)#define WAKE_MAGICSECURE (1 << 6)/* only meaningful if WAKE_MAGIC */ #define WAKE_FILTER (1 << 7) +#define WOL_MODE_COUNT 8 +/* L2-L4 network traffic flow types */ #define TCP_V4_FLOW 0x01/* hash or spec (tcp_ip4_spec) */ #define UDP_V4_FLOW 0x02/* hash or spec (udp_ip4_spec) */
uapi/linux/net_tstamp.h +27 -0
@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * Userspace API for hardware time stamping of network packets *
@@ -89,6 +90,14 @@ enum hwtstamp_tx_types {* queue. */ HWTSTAMP_TX_ONESTEP_SYNC , + +/* +* Same as HWTSTAMP_TX_ONESTEP_SYNC, but also enables time +* stamp insertion directly into PDelay_Resp packets. In this +* case, neither transmitted Sync nor PDelay_Resp packets will +* receive a time stamp via the socket error queue. +*/ + HWTSTAMP_TX_ONESTEP_P2P, };/* possible values for hwtstamp_config->rx_filter */
@@ -140,4 +149,22 @@ struct scm_ts_pktinfo { __u32 reserved[2]; }; +/* +* SO_TXTIME gets a struct sock_txtime with flags being an integer bit +* field comprised of these values. +*/ +enum txtime_flags { +SOF_TXTIME_DEADLINE_MODE = (1 <<0 ), +SOF_TXTIME_REPORT_ERRORS = (1 <<1 ), + +SOF_TXTIME_FLAGS_LAST =SOF_TXTIME_REPORT_ERRORS , +SOF_TXTIME_FLAGS_MASK = (SOF_TXTIME_FLAGS_LAST -1 ) | +SOF_TXTIME_FLAGS_LAST +}; + +struct sock_txtime { +__kernel_clockid_t clockid;/* reference clockid */ +__u32 flags;/* as defined by enum txtime_flags */ +}; +#endif /* _NET_TIMESTAMPING_H */
Signature · 1 line
2.25.1
PATCH v2 3/25 add --debug option to control debugging messages
In reply to Michal KubecekIntroduce --debug option to control which debugging messages will be shown. Argument is a number which is interpreted as bit mask; default value is zero (i.e. no debug messages).
--- ethtool.8.in | 12 ++++++++++++ ethtool.c | 18 ++++++++++++++++-- internal.h | 6 ++++++ 3 files changed, 34 insertions(+), 2 deletions(-)
ethtool.8.in +12 -0
@@ -129,6 +129,10 @@ ethtool \- query or control network driver and hardware settings .HP .B ethtool \-\-version .HP +.B ethtool +.BN --debug +.I args +.HP .B ethtool \-a|\-\-show\-pause .I devname .HP
@@ -437,6 +441,14 @@ Shows a short help message. .B \-\-version Shows the ethtool version number. .TP +.BI \-\-debug \ N +Turns on debugging messages. Argument is interpreted as a mask: +.TS +nokeep; +lB l. +0x01 Parser information +.TE +.TP .B \-a \-\-show\-pause Queries the specified Ethernet device for pause parameter information. .TP
ethtool.c +16 -2
@@ -5493,10 +5493,10 @@ static int show_usage(struct cmd_context *ctx maybe_unused)fprintf (stdout,PACKAGE " version " VERSION "\n" );fprintf (stdout,"Usage:\n" -" ethtool DEVNAME\t" +" ethtool [ --debug MASK ] DEVNAME\t" "Display standard information about device\n" );for (i =0 ; args[i].opts; i++) { -fputs (" ethtool " , stdout); +fputs (" ethtool [ --debug MASK ] " , stdout); fprintf(stdout, "%s %s\t%s\n", args[i].opts, args[i].want_device ? "DEVNAME" : "\t",
@@ -5712,6 +5712,20 @@ int main(int argc, char **argp) argp++; argc--; + ctx.debug =0 ; +if (*argp && !strcmp (*argp,"--debug" )) { +char *eptr; + +if (argc <2 ) +exit_bad_args (); + ctx.debug =strtoul (argp[1 ], &eptr,0 ); +if (!argp[1 ][0 ] || *eptr) +exit_bad_args (); + + argp +=2 ; + argc -=2 ; + } +/* First argument must be either a valid option or a device * name to get settings for (which we don't expect to begin * with '-').
internal.h +6 -0
@@ -107,6 +107,11 @@ static inline int test_bit(unsigned int nr, const unsigned long *addr)#define SIOCETHTOOL 0x8946#endif +/* debugging flags */ +enum { +DEBUG_PARSE , +}; +/* Internal values for old-style offload flags. Values and names * must not clash with the flags defined for ETHTOOL_{G,S}FLAGS. */
@@ -197,6 +202,7 @@ struct cmd_context {struct ifreq ifr;/* ifreq suitable for ethtool ioctl */ int argc;/* number of arguments to the sub-command */ char **argp;/* arguments to the sub-command */ +unsigned long debug;/* debugging mask */ };#ifdef TEST_ETHTOOL
Signature · 1 line
2.25.1
PATCH v2 4/25 use named initializers in command line option list
In reply to Michal KubecekThe command line option list initialization does not look very nice and adding another struct member would not make it look any better.
Reformat it to use named initializers. Also replace want_device with (bool) no_dev as only two options have want_device = 0 so that using an opposite would allow omitting the initializer for almost all options.
--- ethtool.c | 559 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 358 insertions(+), 201 deletions(-)
ethtool.c +358 -201
@@ -5288,200 +5288,357 @@ int send_ioctl(struct cmd_context *ctx, void *cmd)static int show_usage (struct cmd_context *ctx); -static const struct option { -const char *opts; -int want_device; -int (*func)(struct cmd_context *); -char *help; -char *opthelp; -} args[] = { - {"-s|--change" ,1 , do_sset,"Change generic options" , -" [ speed %d ]\n" -" [ duplex half|full ]\n" -" [ port tp|aui|bnc|mii|fibre ]\n" -" [ mdix auto|on|off ]\n" -" [ autoneg on|off ]\n" -" [ advertise %x ]\n" -" [ phyad %d ]\n" -" [ xcvr internal|external ]\n" -" [ wol p|u|m|b|a|g|s|f|d... ]\n" -" [ sopass %x:%x:%x:%x:%x:%x ]\n" -" [ msglvl %d | msglvl type on|off ... ]\n" }, - {"-a|--show-pause" ,1 , do_gpause,"Show pause options" }, - {"-A|--pause" ,1 , do_spause,"Set pause options" , -" [ autoneg on|off ]\n" -" [ rx on|off ]\n" -" [ tx on|off ]\n" }, - {"-c|--show-coalesce" ,1 , do_gcoalesce,"Show coalesce options" }, - {"-C|--coalesce" ,1 , do_scoalesce,"Set coalesce options" , -" [adaptive-rx on|off]\n" -" [adaptive-tx on|off]\n" -" [rx-usecs N]\n" -" [rx-frames N]\n" -" [rx-usecs-irq N]\n" -" [rx-frames-irq N]\n" -" [tx-usecs N]\n" -" [tx-frames N]\n" -" [tx-usecs-irq N]\n" -" [tx-frames-irq N]\n" -" [stats-block-usecs N]\n" -" [pkt-rate-low N]\n" -" [rx-usecs-low N]\n" -" [rx-frames-low N]\n" -" [tx-usecs-low N]\n" -" [tx-frames-low N]\n" -" [pkt-rate-high N]\n" -" [rx-usecs-high N]\n" -" [rx-frames-high N]\n" -" [tx-usecs-high N]\n" -" [tx-frames-high N]\n" -" [sample-interval N]\n" }, - {"-g|--show-ring" ,1 , do_gring,"Query RX/TX ring parameters" }, - {"-G|--set-ring" ,1 , do_sring,"Set RX/TX ring parameters" , -" [ rx N ]\n" -" [ rx-mini N ]\n" -" [ rx-jumbo N ]\n" -" [ tx N ]\n" }, - {"-k|--show-features|--show-offload" ,1 , do_gfeatures, -"Get state of protocol offload and other features" }, - {"-K|--features|--offload" ,1 , do_sfeatures, -"Set protocol offload and other features" , -" FEATURE on|off ...\n" }, - {"-i|--driver" ,1 , do_gdrv,"Show driver information" }, - {"-d|--register-dump" ,1 , do_gregs,"Do a register dump" , -" [ raw on|off ]\n" -" [ file FILENAME ]\n" }, - {"-e|--eeprom-dump" ,1 , do_geeprom,"Do a EEPROM dump" , -" [ raw on|off ]\n" -" [ offset N ]\n" -" [ length N ]\n" }, - {"-E|--change-eeprom" ,1 , do_seeprom, -"Change bytes in device EEPROM" , -" [ magic N ]\n" -" [ offset N ]\n" -" [ length N ]\n" -" [ value N ]\n" }, - {"-r|--negotiate" ,1 , do_nway_rst,"Restart N-WAY negotiation" }, - {"-p|--identify" ,1 , do_phys_id, -"Show visible port identification (e.g. blinking)" , -" [ TIME-IN-SECONDS ]\n" }, - {"-t|--test" ,1 , do_test,"Execute adapter self test" , -" [ online | offline | external_lb ]\n" }, - {"-S|--statistics" ,1 , do_gnicstats,"Show adapter statistics" }, - {"--phy-statistics" ,1 , do_gphystats, -"Show phy statistics" }, - {"-n|-u|--show-nfc|--show-ntuple" ,1 , do_grxclass, -"Show Rx network flow classification options or rules" , -" [ rx-flow-hash tcp4|udp4|ah4|esp4|sctp4|" -"tcp6|udp6|ah6|esp6|sctp6 [context %d] |\n" -" rule %d ]\n" }, - {"-N|-U|--config-nfc|--config-ntuple" ,1 , do_srxclass, -"Configure Rx network flow classification options or rules" , -" rx-flow-hash tcp4|udp4|ah4|esp4|sctp4|" -"tcp6|udp6|ah6|esp6|sctp6 m|v|t|s|d|f|n|r... [context %d] |\n" -" flow-type ether|ip4|tcp4|udp4|sctp4|ah4|esp4|" -"ip6|tcp6|udp6|ah6|esp6|sctp6\n" -" [ src %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]\n" -" [ dst %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]\n" -" [ proto %d [m %x] ]\n" -" [ src-ip IP-ADDRESS [m IP-ADDRESS] ]\n" -" [ dst-ip IP-ADDRESS [m IP-ADDRESS] ]\n" -" [ tos %d [m %x] ]\n" -" [ tclass %d [m %x] ]\n" -" [ l4proto %d [m %x] ]\n" -" [ src-port %d [m %x] ]\n" -" [ dst-port %d [m %x] ]\n" -" [ spi %d [m %x] ]\n" -" [ vlan-etype %x [m %x] ]\n" -" [ vlan %x [m %x] ]\n" -" [ user-def %x [m %x] ]\n" -" [ dst-mac %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]\n" -" [ action %d ] | [ vf %d queue %d ]\n" -" [ context %d ]\n" -" [ loc %d]] |\n" -" delete %d\n" }, - {"-T|--show-time-stamping" ,1 , do_tsinfo, -"Show time stamping capabilities" }, - {"-x|--show-rxfh-indir|--show-rxfh" ,1 , do_grxfh, -"Show Rx flow hash indirection table and/or RSS hash key" , -" [ context %d ]\n" }, - {"-X|--set-rxfh-indir|--rxfh" ,1 , do_srxfh, -"Set Rx flow hash indirection table and/or RSS hash key" , -" [ context %d|new ]\n" -" [ equal N | weight W0 W1 ... | default ]\n" -" [ hkey %x:%x:%x:%x:%x:.... ]\n" -" [ hfunc FUNC ]\n" -" [ delete ]\n" }, - {"-f|--flash" ,1 , do_flash, -"Flash firmware image from the specified file to a region on the device" , -" FILENAME [ REGION-NUMBER-TO-FLASH ]\n" }, - {"-P|--show-permaddr" ,1 , do_permaddr, -"Show permanent hardware address" }, - {"-w|--get-dump" ,1 , do_getfwdump, -"Get dump flag, data" , -" [ data FILENAME ]\n" }, - {"-W|--set-dump" ,1 , do_setfwdump, -"Set dump flag of the device" , -" N\n" }, - {"-l|--show-channels" ,1 , do_gchannels,"Query Channels" }, - {"-L|--set-channels" ,1 , do_schannels,"Set Channels" , -" [ rx N ]\n" -" [ tx N ]\n" -" [ other N ]\n" -" [ combined N ]\n" }, - {"--show-priv-flags" ,1 , do_gprivflags,"Query private flags" }, - {"--set-priv-flags" ,1 , do_sprivflags,"Set private flags" , -" FLAG on|off ...\n" }, - {"-m|--dump-module-eeprom|--module-info" ,1 , do_getmodule, -"Query/Decode Module EEPROM information and optical diagnostics if available" , -" [ raw on|off ]\n" -" [ hex on|off ]\n" -" [ offset N ]\n" -" [ length N ]\n" }, - {"--show-eee" ,1 , do_geee,"Show EEE settings" }, - {"--set-eee" ,1 , do_seee,"Set EEE settings" , -" [ eee on|off ]\n" -" [ advertise %x ]\n" -" [ tx-lpi on|off ]\n" -" [ tx-timer %d ]\n" }, - {"--set-phy-tunable" ,1 , do_set_phy_tunable,"Set PHY tunable" , -" [ downshift on|off [count N] ]\n" -" [ fast-link-down on|off [msecs N] ]\n" -" [ energy-detect-power-down on|off [msecs N] ]\n" }, - {"--get-phy-tunable" ,1 , do_get_phy_tunable,"Get PHY tunable" , -" [ downshift ]\n" -" [ fast-link-down ]\n" -" [ energy-detect-power-down ]\n" }, - {"--reset" ,1 , do_reset,"Reset components" , -" [ flags %x ]\n" -" [ mgmt ]\n" -" [ mgmt-shared ]\n" -" [ irq ]\n" -" [ irq-shared ]\n" -" [ dma ]\n" -" [ dma-shared ]\n" -" [ filter ]\n" -" [ filter-shared ]\n" -" [ offload ]\n" -" [ offload-shared ]\n" -" [ mac ]\n" -" [ mac-shared ]\n" -" [ phy ]\n" -" [ phy-shared ]\n" -" [ ram ]\n" -" [ ram-shared ]\n" -" [ ap ]\n" -" [ ap-shared ]\n" -" [ dedicated ]\n" -" [ all ]\n" }, - {"--show-fec" ,1 , do_gfec,"Show FEC settings" }, - {"--set-fec" ,1 , do_sfec,"Set FEC settings" , -" [ encoding auto|off|rs|baser [...]]\n" }, - {"-Q|--per-queue" ,1 , do_perqueue,"Apply per-queue command." -"The supported sub commands include --show-coalesce, --coalesce" , -" [queue_mask %x] SUB_COMMAND\n" }, - {"-h|--help" ,0 , show_usage,"Show this help" }, - {"--version" ,0 , do_version,"Show version number" }, +struct option { +const char *opts; +bool no_dev; +int (*func)(struct cmd_context *); +const char *help; +const char *xhelp; +}; + +static const struct option args[] = { + { + .opts ="-s|--change" , + .func = do_sset, + .help ="Change generic options" , + .xhelp =" [ speed %d ]\n" +" [ duplex half|full ]\n" +" [ port tp|aui|bnc|mii|fibre ]\n" +" [ mdix auto|on|off ]\n" +" [ autoneg on|off ]\n" +" [ advertise %x ]\n" +" [ phyad %d ]\n" +" [ xcvr internal|external ]\n" +" [ wol p|u|m|b|a|g|s|f|d... ]\n" +" [ sopass %x:%x:%x:%x:%x:%x ]\n" +" [ msglvl %d | msglvl type on|off ... ]\n" + }, + { + .opts ="-a|--show-pause" , + .func = do_gpause, + .help ="Show pause options" + }, + { + .opts ="-A|--pause" , + .func = do_spause, + .help ="Set pause options" , + .xhelp =" [ autoneg on|off ]\n" +" [ rx on|off ]\n" +" [ tx on|off ]\n" + }, + { + .opts ="-c|--show-coalesce" , + .func = do_gcoalesce, + .help ="Show coalesce options" + }, + { + .opts ="-C|--coalesce" , + .func = do_scoalesce, + .help ="Set coalesce options" , + .xhelp =" [adaptive-rx on|off]\n" +" [adaptive-tx on|off]\n" +" [rx-usecs N]\n" +" [rx-frames N]\n" +" [rx-usecs-irq N]\n" +" [rx-frames-irq N]\n" +" [tx-usecs N]\n" +" [tx-frames N]\n" +" [tx-usecs-irq N]\n" +" [tx-frames-irq N]\n" +" [stats-block-usecs N]\n" +" [pkt-rate-low N]\n" +" [rx-usecs-low N]\n" +" [rx-frames-low N]\n" +" [tx-usecs-low N]\n" +" [tx-frames-low N]\n" +" [pkt-rate-high N]\n" +" [rx-usecs-high N]\n" +" [rx-frames-high N]\n" +" [tx-usecs-high N]\n" +" [tx-frames-high N]\n" +" [sample-interval N]\n" + }, + { + .opts ="-g|--show-ring" , + .func = do_gring, + .help ="Query RX/TX ring parameters" + }, + { + .opts ="-G|--set-ring" , + .func = do_sring, + .help ="Set RX/TX ring parameters" , + .xhelp =" [ rx N ]\n" +" [ rx-mini N ]\n" +" [ rx-jumbo N ]\n" +" [ tx N ]\n" + }, + { + .opts ="-k|--show-features|--show-offload" , + .func = do_gfeatures, + .help ="Get state of protocol offload and other features" + }, + { + .opts ="-K|--features|--offload" , + .func = do_sfeatures, + .help ="Set protocol offload and other features" , + .xhelp =" FEATURE on|off ...\n" + }, + { + .opts ="-i|--driver" , + .func = do_gdrv, + .help ="Show driver information" + }, + { + .opts ="-d|--register-dump" , + .func = do_gregs, + .help ="Do a register dump" , + .xhelp =" [ raw on|off ]\n" +" [ file FILENAME ]\n" + }, + { + .opts ="-e|--eeprom-dump" , + .func = do_geeprom, + .help ="Do a EEPROM dump" , + .xhelp =" [ raw on|off ]\n" +" [ offset N ]\n" +" [ length N ]\n" + }, + { + .opts ="-E|--change-eeprom" , + .func = do_seeprom, + .help ="Change bytes in device EEPROM" , + .xhelp =" [ magic N ]\n" +" [ offset N ]\n" +" [ length N ]\n" +" [ value N ]\n" + }, + { + .opts ="-r|--negotiate" , + .func = do_nway_rst, + .help ="Restart N-WAY negotiation" + }, + { + .opts ="-p|--identify" , + .func = do_phys_id, + .help ="Show visible port identification (e.g. blinking)" , + .xhelp =" [ TIME-IN-SECONDS ]\n" + }, + { + .opts ="-t|--test" , + .func = do_test, + .help ="Execute adapter self test" , + .xhelp =" [ online | offline | external_lb ]\n" + }, + { + .opts ="-S|--statistics" , + .func = do_gnicstats, + .help ="Show adapter statistics" + }, + { + .opts ="--phy-statistics" , + .func = do_gphystats, + .help ="Show phy statistics" + }, + { + .opts ="-n|-u|--show-nfc|--show-ntuple" , + .func = do_grxclass, + .help ="Show Rx network flow classification options or rules" , + .xhelp =" [ rx-flow-hash tcp4|udp4|ah4|esp4|sctp4|" +"tcp6|udp6|ah6|esp6|sctp6 [context %d] |\n" +" rule %d ]\n" + }, + { + .opts ="-N|-U|--config-nfc|--config-ntuple" , + .func = do_srxclass, + .help ="Configure Rx network flow classification options or rules" , + .xhelp =" rx-flow-hash tcp4|udp4|ah4|esp4|sctp4|" +"tcp6|udp6|ah6|esp6|sctp6 m|v|t|s|d|f|n|r... [context %d] |\n" +" flow-type ether|ip4|tcp4|udp4|sctp4|ah4|esp4|" +"ip6|tcp6|udp6|ah6|esp6|sctp6\n" +" [ src %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]\n" +" [ dst %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]\n" +" [ proto %d [m %x] ]\n" +" [ src-ip IP-ADDRESS [m IP-ADDRESS] ]\n" +" [ dst-ip IP-ADDRESS [m IP-ADDRESS] ]\n" +" [ tos %d [m %x] ]\n" +" [ tclass %d [m %x] ]\n" +" [ l4proto %d [m %x] ]\n" +" [ src-port %d [m %x] ]\n" +" [ dst-port %d [m %x] ]\n" +" [ spi %d [m %x] ]\n" +" [ vlan-etype %x [m %x] ]\n" +" [ vlan %x [m %x] ]\n" +" [ user-def %x [m %x] ]\n" +" [ dst-mac %x:%x:%x:%x:%x:%x [m %x:%x:%x:%x:%x:%x] ]\n" +" [ action %d ] | [ vf %d queue %d ]\n" +" [ context %d ]\n" +" [ loc %d]] |\n" +" delete %d\n" + }, + { + .opts ="-T|--show-time-stamping" , + .func = do_tsinfo, + .help ="Show time stamping capabilities" + }, + { + .opts ="-x|--show-rxfh-indir|--show-rxfh" , + .func = do_grxfh, + .help ="Show Rx flow hash indirection table and/or RSS hash key" , + .xhelp =" [ context %d ]\n" + }, + { + .opts ="-X|--set-rxfh-indir|--rxfh" , + .func = do_srxfh, + .help ="Set Rx flow hash indirection table and/or RSS hash key" , + .xhelp =" [ context %d|new ]\n" +" [ equal N | weight W0 W1 ... | default ]\n" +" [ hkey %x:%x:%x:%x:%x:.... ]\n" +" [ hfunc FUNC ]\n" +" [ delete ]\n" + }, + { + .opts ="-f|--flash" , + .func = do_flash, + .help ="Flash firmware image from the specified file to a region on the device" , + .xhelp =" FILENAME [ REGION-NUMBER-TO-FLASH ]\n" + }, + { + .opts ="-P|--show-permaddr" , + .func = do_permaddr, + .help ="Show permanent hardware address" + }, + { + .opts ="-w|--get-dump" , + .func = do_getfwdump, + .help ="Get dump flag, data" , + .xhelp =" [ data FILENAME ]\n" + }, + { + .opts ="-W|--set-dump" , + .func = do_setfwdump, + .help ="Set dump flag of the device" , + .xhelp =" N\n" + }, + { + .opts ="-l|--show-channels" , + .func = do_gchannels, + .help ="Query Channels" + }, + { + .opts ="-L|--set-channels" , + .func = do_schannels, + .help ="Set Channels" , + .xhelp =" [ rx N ]\n" +" [ tx N ]\n" +" [ other N ]\n" +" [ combined N ]\n" + }, + { + .opts ="--show-priv-flags" , + .func = do_gprivflags, + .help ="Query private flags" + }, + { + .opts ="--set-priv-flags" , + .func = do_sprivflags, + .help ="Set private flags" , + .xhelp =" FLAG on|off ...\n" + }, + { + .opts ="-m|--dump-module-eeprom|--module-info" , + .func = do_getmodule, + .help ="Query/Decode Module EEPROM information and optical diagnostics if available" , + .xhelp =" [ raw on|off ]\n" +" [ hex on|off ]\n" +" [ offset N ]\n" +" [ length N ]\n" + }, + { + .opts ="--show-eee" , + .func = do_geee, + .help ="Show EEE settings" , + }, + { + .opts ="--set-eee" , + .func = do_seee, + .help ="Set EEE settings" , + .xhelp =" [ eee on|off ]\n" +" [ advertise %x ]\n" +" [ tx-lpi on|off ]\n" +" [ tx-timer %d ]\n" + }, + { + .opts ="--set-phy-tunable" , + .func = do_set_phy_tunable, + .help ="Set PHY tunable" , + .xhelp =" [ downshift on|off [count N] ]\n" +" [ fast-link-down on|off [msecs N] ]\n" +" [ energy-detect-power-down on|off [msecs N] ]\n" + }, + { + .opts ="--get-phy-tunable" , + .func = do_get_phy_tunable, + .help ="Get PHY tunable" , + .xhelp =" [ downshift ]\n" +" [ fast-link-down ]\n" +" [ energy-detect-power-down ]\n" + }, + { + .opts ="--reset" , + .func = do_reset, + .help ="Reset components" , + .xhelp =" [ flags %x ]\n" +" [ mgmt ]\n" +" [ mgmt-shared ]\n" +" [ irq ]\n" +" [ irq-shared ]\n" +" [ dma ]\n" +" [ dma-shared ]\n" +" [ filter ]\n" +" [ filter-shared ]\n" +" [ offload ]\n" +" [ offload-shared ]\n" +" [ mac ]\n" +" [ mac-shared ]\n" +" [ phy ]\n" +" [ phy-shared ]\n" +" [ ram ]\n" +" [ ram-shared ]\n" +" [ ap ]\n" +" [ ap-shared ]\n" +" [ dedicated ]\n" +" [ all ]\n" + }, + { + .opts ="--show-fec" , + .func = do_gfec, + .help ="Show FEC settings" , + }, + { + .opts ="--set-fec" , + .func = do_sfec, + .help ="Set FEC settings" , + .xhelp =" [ encoding auto|off|rs|baser [...]]\n" + }, + { + .opts ="-Q|--per-queue" , + .func = do_perqueue, + .help ="Apply per-queue command. " , + .xhelp ="The supported sub commands include --show-coalesce, --coalesce" +" [queue_mask %x] SUB_COMMAND\n" , + }, + { + .opts ="-h|--help" , + .no_dev = true, + .func = show_usage, + .help ="Show this help" + }, + { + .opts ="--version" , + .no_dev = true, + .func = do_version, + .help ="Show version number" + }, {} };
@@ -5499,10 +5656,10 @@ static int show_usage(struct cmd_context *ctx maybe_unused)fputs (" ethtool [ --debug MASK ] " , stdout);fprintf (stdout,"%s %s\t%s\n" , args[i].opts, - args[i].want_device ?"DEVNAME" :"\t" , + args[i].no_dev ?"\t" :"DEVNAME" , args[i].help); -if (args[i].opthelp) -fputs (args[i].opthelp, stdout); +if (args[i].xhelp) +fputs (args[i].xhelp, stdout); }return 0 ;
@@ -5702,8 +5859,8 @@ static int do_perqueue(struct cmd_context *ctx)int main (int argc,char **argp) {int (*func)(struct cmd_context *); -int want_device;struct cmd_context ctx; +bool no_dev;int k;init_global_link_mode_masks ();
@@ -5738,16 +5895,16 @@ int main(int argc, char **argp) argp++; argc--; func = args[k].func; - want_device = args[k].want_device; + no_dev = args[k].no_dev; goto opt_found; }if ((*argp)[0 ] =='-' )exit_bad_args (); func = do_gset; - want_device =1 ; + no_dev = false; opt_found: -if (want_device) { +if (!no_dev) { ctx.devname = *argp++; argc--;
Signature · 1 line
2.25.1
PATCH v2 5/25 netlink: add netlink related UAPI header files
In reply to Michal KubecekAdd copies of kernel UAPI header files needed for netlink interface:
<linux/netlink.h>
<linux/genetlink.h>
<linux/ethtool_netlink.h>
<linux/rtnetlink.h>
<linux/if_link.h>
The (sanitized) copies are taken from v5.6-rc1.
v2:
- add linux/rtnetlink.h and linux/if_link.h
--- uapi/linux/ethtool_netlink.h | 237 ++++++++ uapi/linux/genetlink.h | 89 +++ uapi/linux/if_link.h | 1051 ++++++++++++++++++++++++++++++++++ uapi/linux/netlink.h | 248 ++++++++ uapi/linux/rtnetlink.h | 777 +++++++++++++++++++++++++ 5 files changed, 2402 insertions(+) create mode 100644 uapi/linux/ethtool_netlink.h create mode 100644 uapi/linux/genetlink.h create mode 100644 uapi/linux/if_link.h create mode 100644 uapi/linux/netlink.h create mode 100644 uapi/linux/rtnetlink.h
uapi/linux/ethtool_netlink.h new file +237 -0
@@ -0,0 +1,237 @@ +/* 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 _LINUX_ETHTOOL_NETLINK_H_ +#define _LINUX_ETHTOOL_NETLINK_H_ + +#include <linux/ethtool.h> + +/* message types - userspace to kernel */ +enum { +ETHTOOL_MSG_USER_NONE , +ETHTOOL_MSG_STRSET_GET , +ETHTOOL_MSG_LINKINFO_GET , +ETHTOOL_MSG_LINKINFO_SET , +ETHTOOL_MSG_LINKMODES_GET , +ETHTOOL_MSG_LINKMODES_SET , +ETHTOOL_MSG_LINKSTATE_GET , +ETHTOOL_MSG_DEBUG_GET , +ETHTOOL_MSG_DEBUG_SET , +ETHTOOL_MSG_WOL_GET , +ETHTOOL_MSG_WOL_SET , + +/* 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 , +ETHTOOL_MSG_STRSET_GET_REPLY , +ETHTOOL_MSG_LINKINFO_GET_REPLY , +ETHTOOL_MSG_LINKINFO_NTF , +ETHTOOL_MSG_LINKMODES_GET_REPLY , +ETHTOOL_MSG_LINKMODES_NTF , +ETHTOOL_MSG_LINKSTATE_GET_REPLY , +ETHTOOL_MSG_DEBUG_GET_REPLY , +ETHTOOL_MSG_DEBUG_NTF , +ETHTOOL_MSG_WOL_GET_REPLY , +ETHTOOL_MSG_WOL_NTF , + +/* add new constants above here */ + __ETHTOOL_MSG_KERNEL_CNT, +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 +}; + +/* 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 +}; + +/* string sets */ + +enum { +ETHTOOL_A_STRING_UNSPEC , +ETHTOOL_A_STRING_INDEX ,/* u32 */ +ETHTOOL_A_STRING_VALUE ,/* string */ + +/* add new constants above here */ + __ETHTOOL_A_STRING_CNT, +ETHTOOL_A_STRING_MAX = __ETHTOOL_A_STRING_CNT -1 +}; + +enum { +ETHTOOL_A_STRINGS_UNSPEC , +ETHTOOL_A_STRINGS_STRING ,/* nest - _A_STRINGS_* */ + +/* add new constants above here */ + __ETHTOOL_A_STRINGS_CNT, +ETHTOOL_A_STRINGS_MAX = __ETHTOOL_A_STRINGS_CNT -1 +}; + +enum { +ETHTOOL_A_STRINGSET_UNSPEC , +ETHTOOL_A_STRINGSET_ID ,/* u32 */ +ETHTOOL_A_STRINGSET_COUNT ,/* u32 */ +ETHTOOL_A_STRINGSET_STRINGS ,/* nest - _A_STRINGS_* */ + +/* add new constants above here */ + __ETHTOOL_A_STRINGSET_CNT, +ETHTOOL_A_STRINGSET_MAX = __ETHTOOL_A_STRINGSET_CNT -1 +}; + +enum { +ETHTOOL_A_STRINGSETS_UNSPEC , +ETHTOOL_A_STRINGSETS_STRINGSET ,/* nest - _A_STRINGSET_* */ + +/* add new constants above here */ + __ETHTOOL_A_STRINGSETS_CNT, +ETHTOOL_A_STRINGSETS_MAX = __ETHTOOL_A_STRINGSETS_CNT -1 +}; + +/* STRSET */ + +enum { +ETHTOOL_A_STRSET_UNSPEC , +ETHTOOL_A_STRSET_HEADER ,/* nest - _A_HEADER_* */ +ETHTOOL_A_STRSET_STRINGSETS ,/* nest - _A_STRINGSETS_* */ +ETHTOOL_A_STRSET_COUNTS_ONLY ,/* flag */ + +/* add new constants above here */ + __ETHTOOL_A_STRSET_CNT, +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 +}; + +/* 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 +}; + +/* 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 +}; + +/* DEBUG */ + +enum { +ETHTOOL_A_DEBUG_UNSPEC , +ETHTOOL_A_DEBUG_HEADER ,/* nest - _A_HEADER_* */ +ETHTOOL_A_DEBUG_MSGMASK ,/* bitset */ + +/* add new constants above here */ + __ETHTOOL_A_DEBUG_CNT, +ETHTOOL_A_DEBUG_MAX = __ETHTOOL_A_DEBUG_CNT -1 +}; + +/* WOL */ + +enum { +ETHTOOL_A_WOL_UNSPEC , +ETHTOOL_A_WOL_HEADER ,/* nest - _A_HEADER_* */ +ETHTOOL_A_WOL_MODES ,/* bitset */ +ETHTOOL_A_WOL_SOPASS ,/* binary */ + +/* add new constants above here */ + __ETHTOOL_A_WOL_CNT, +ETHTOOL_A_WOL_MAX = __ETHTOOL_A_WOL_CNT -1 +}; + +/* generic netlink info */ +#define ETHTOOL_GENL_NAME "ethtool" +#define ETHTOOL_GENL_VERSION 1 + +#define ETHTOOL_MCGRP_MONITOR_NAME "monitor" + +#endif /* _LINUX_ETHTOOL_NETLINK_H_ */
uapi/linux/genetlink.h new file +89 -0
89 lines not on this page · raw message
uapi/linux/if_link.h new file +1051 -0
1,051 lines not on this page · raw message
uapi/linux/netlink.h new file +248 -0
248 lines not on this page · raw message
uapi/linux/rtnetlink.h new file +777 -0
777 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 6/25 netlink: introduce the netlink interface
In reply to Michal KubecekInitial part of netlink interface based on genetlink and libmnl. The netlink interface is available in kernel since 5.6-rc1. This commit only adds the generic infrastructure but does not override any ethtool command so that there is no actual change in behaviour.
Netlink handlers for ethtool commands are added as nlfunc members to args array in ethtool.c. A netlink handler is used if it is available (i.e. nlfunc is not null) and ethtool succeeds to initialize netlink socket. If netlink implementation exists for a command but the request is not supported by kernel (e.g. when new ethtool is used on older kernel), ioctl implementation is also used as fallback.
Running configure with --disable-netlink completely disables the netlink interface.
v2:
- change type of nl_context::suppress_nlerr
- add nl_context::rtnl_socket
--- Makefile.am | 18 +++++++++-- configure.ac | 14 ++++++++- ethtool.c | 76 +++++++++++++++++++++++++++++++++++------------ internal.h | 12 ++++++++ netlink/extapi.h | 31 +++++++++++++++++++ netlink/netlink.c | 36 ++++++++++++++++++++++ netlink/netlink.h | 26 ++++++++++++++++ 7 files changed, 191 insertions(+), 22 deletions(-) create mode 100644 netlink/extapi.h create mode 100644 netlink/netlink.c create mode 100644 netlink/netlink.h
Makefile.am +16 -2
@@ -7,6 +7,8 @@ EXTRA_DIST = LICENSE ethtool.8 ethtool.spec.in aclocal.m4 ChangeLog autogen.sh sbin_PROGRAMS = ethtool ethtool_SOURCES = ethtool.c uapi/linux/ethtool.h internal.h \ uapi/linux/net_tstamp.h rxclass.c +ethtool_CFLAGS = $(AM_CFLAGS) +ethtool_LDADD = $(LDADD) if ETHTOOL_ENABLE_PRETTY_DUMP ethtool_SOURCES += \ amd8111e.c de2104x.c dsa.c e100.c e1000.c et131x.c igb.c \
@@ -22,12 +24,24 @@ bashcompletiondir = $(BASH_COMPLETION_DIR) dist_bashcompletion_DATA = shell-completion/bash/ethtool endif +if ETHTOOL_ENABLE_NETLINK +ethtool_SOURCES += \ + netlink/netlink.c netlink/netlink.h netlink/extapi.h \ + uapi/linux/ethtool_netlink.h \ + uapi/linux/netlink.h uapi/linux/genetlink.h \ + uapi/linux/rtnetlink.h uapi/linux/if_link.h +ethtool_CFLAGS += @MNL_CFLAGS@ +ethtool_LDADD += @MNL_LIBS@ +endif + TESTS = test-cmdline test-features check_PROGRAMS = test-cmdline test-features test_cmdline_SOURCES = test-cmdline.c test-common.c $(ethtool_SOURCES) -test_cmdline_CFLAGS = $(AM_FLAGS) -DTEST_ETHTOOL +test_cmdline_CFLAGS = $(ethtool_CFLAGS) -DTEST_ETHTOOL +test_cmdline_LDADD = $(ethtool_LDADD) test_features_SOURCES = test-features.c test-common.c $(ethtool_SOURCES) -test_features_CFLAGS = $(AM_FLAGS) -DTEST_ETHTOOL +test_features_CFLAGS = $(ethtool_CFLAGS) -DTEST_ETHTOOL +test_features_LDADD = $(ethtool_LDADD) dist-hook: cp $(top_srcdir)/ethtool.spec $(distdir)
configure.ac +13 -1
@@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(ethtool, 5.4, [email protected]) AC_PREREQ(2.52) AC_CONFIG_SRCDIR([ethtool.c]) -AM_INIT_AUTOMAKE([gnu]) +AM_INIT_AUTOMAKE([gnu subdir-objects]) AC_CONFIG_HEADERS([ethtool-config.h]) AM_MAINTAINER_MODE
@@ -66,5 +66,17 @@ AC_SUBST([BASH_COMPLETION_DIR]) AM_CONDITIONAL([ENABLE_BASH_COMPLETION], [test "x$with_bash_completion_dir" != xno]) +AC_ARG_ENABLE(netlink, + [ --enable-netlink enable netlink interface (enabled by default)], + , + enable_netlink=yes) +if test x$enable_netlink = xyes; then + PKG_PROG_PKG_CONFIG + PKG_CHECK_MODULES([MNL], [libmnl]) + AC_DEFINE(ETHTOOL_ENABLE_NETLINK, 1, + Define this to support netlink interface to talk to kernel.) +fi +AM_CONDITIONAL([ETHTOOL_ENABLE_NETLINK], [test x$enable_netlink = xyes]) + AC_CONFIG_FILES([Makefile ethtool.spec ethtool.8]) AC_OUTPUT
ethtool.c +57 -19
126 lines not on this page · raw message
internal.h +12 -0
@@ -25,6 +25,11 @@#define maybe_unused __attribute__((__unused__)) +/* internal for netlink interface */ +#ifdef ETHTOOL_ENABLE_NETLINK +struct nl_context ; +#endif +/* ethtool.h expects these to be defined by <linux/types.h> */ #ifndef HAVE_BE_TYPES typedef uint16_t __be16 ;
@@ -44,6 +49,10 @@ typedef int32_t s32;#define __KERNEL_DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d))#endif +#ifndef ALTIFNAMSIZ +#define ALTIFNAMSIZ 128 +#endif +#include <linux/ethtool.h> #include <linux/net_tstamp.h>
@@ -203,6 +212,9 @@ struct cmd_context {int argc;/* number of arguments to the sub-command */ char **argp;/* arguments to the sub-command */ unsigned long debug;/* debugging mask */ +#ifdef ETHTOOL_ENABLE_NETLINK +struct nl_context *nlctx;/* netlink context (opaque) */ +#endif };#ifdef TEST_ETHTOOL
netlink/extapi.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* extapi.h - external interface of netlink code +* +* Declarations needed by non-netlink code (mostly ethtool.c). +*/ + +#ifndef ETHTOOL_EXTAPI_H__ +#define ETHTOOL_EXTAPI_H__ + +struct cmd_context ; +struct nl_context ; + +#ifdef ETHTOOL_ENABLE_NETLINK + +int netlink_init (struct cmd_context *ctx); +void netlink_done (struct cmd_context *ctx); + +#else /* ETHTOOL_ENABLE_NETLINK */ + +static inline int netlink_init(struct cmd_context *ctx maybe_unused) +{ +return -EOPNOTSUPP ; +} + +static inline void netlink_done(struct cmd_context *ctx maybe_unused) +{ +} + +#endif /* ETHTOOL_ENABLE_NETLINK */ + +#endif /* ETHTOOL_EXTAPI_H__ */
netlink/netlink.c new file +36 -0
@@ -0,0 +1,36 @@ +/* +* netlink.c - basic infrastructure for netlink code +* +* Heart of the netlink interface implementation. +*/ + +#include <errno.h> + +#include "../internal.h" +#include "netlink.h" +#include "extapi.h" + +/* initialization */ + +int netlink_init (struct cmd_context *ctx) +{ +struct nl_context *nlctx; + + nlctx =calloc (1 ,sizeof (*nlctx)); +if (!nlctx) +return -ENOMEM ; + nlctx->ctx = ctx; + + ctx->nlctx = nlctx; + +return 0 ; +} + +void netlink_done (struct cmd_context *ctx) +{ +if (!ctx->nlctx) +return ; + +free (ctx->nlctx); + ctx->nlctx =NULL ; +}
netlink/netlink.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* netlink.h - common interface for all netlink code +* +* Declarations of data structures, global data and helpers for netlink code +*/ + +#ifndef ETHTOOL_NETLINK_INT_H__ +#define ETHTOOL_NETLINK_INT_H__ + +#include <libmnl/libmnl.h> +#include <linux/netlink.h> +#include <linux/genetlink.h> +#include <linux/ethtool_netlink.h> + +#define WILDCARD_DEVNAME "*" + +struct nl_context { +struct cmd_context *ctx; +void *cmd_private; +const char *devname; +bool is_dump; +int exit_code; +unsigned int suppress_nlerr; +}; + +#endif /* ETHTOOL_NETLINK_INT_H__ */
Signature · 1 line
2.25.1
PATCH v2 7/25 netlink: message buffer and composition helpers
In reply to Michal KubecekAdd data structure for flexible message buffer and helpers for safe message composition.
The nl_msg_buff structure is an abstraction for a message buffer used to compose an outgoing netlink message. When the message exceeds currently allocated length, buffer is reallocated. Only if the buffer size reaches MAX_MSG_SIZE (4 MB), an error is issued.
v2:
- add kerneldoc style comments
--- Makefile.am | 1 + netlink/msgbuff.c | 255 ++++++++++++++++++++++++++++++++++++++++++++++ netlink/msgbuff.h | 117 +++++++++++++++++++++ netlink/netlink.h | 1 + 4 files changed, 374 insertions(+) create mode 100644 netlink/msgbuff.c create mode 100644 netlink/msgbuff.h
Makefile.am +1 -0
@@ -27,6 +27,7 @@ endif if ETHTOOL_ENABLE_NETLINK ethtool_SOURCES += \ netlink/netlink.c netlink/netlink.h netlink/extapi.h \ + netlink/msgbuff.c netlink/msgbuff.h \ uapi/linux/ethtool_netlink.h \ uapi/linux/netlink.h uapi/linux/genetlink.h \ uapi/linux/rtnetlink.h uapi/linux/if_link.h
netlink/msgbuff.c new file +255 -0
255 lines not on this page · raw message
netlink/msgbuff.h new file +117 -0
117 lines not on this page · raw message
netlink/netlink.h +1 -0
@@ -21,6 +21,7 @@ struct nl_context {bool is_dump;int exit_code;unsigned int suppress_nlerr; + uint16_t ethnl_fam; };#endif /* ETHTOOL_NETLINK_INT_H__ */
Signature · 1 line
2.25.1
PATCH v2 8/25 netlink: netlink socket wrapper and helpers
In reply to Michal KubecekAdd data structure for netlink socket and few helpers to work with it.
The nl_socket structure is a wrapper for struct mnl_socket from libmnl, a message buffer and some additional data. Helpers for sending netlink (and genetlink), processing replies are provided as well as debugging helpers.
v2:
- reworked debugging output for incoming/outgoing messages
- drop tables of message type names (replaced in patch 22)
- nl_context::suppress_nlerr allows two levels (EOPNOTSUPP / all codes)
- drop nlsock_init(), rename __nlsock_init() to nlsock_init()
- add kerneldoc style comments
--- Makefile.am | 3 +- internal.h | 8 + netlink/netlink.c | 28 ++++ netlink/netlink.h | 11 ++ netlink/nlsock.c | 364 ++++++++++++++++++++++++++++++++++++++++++++++ netlink/nlsock.h | 45 ++++++ 6 files changed, 458 insertions(+), 1 deletion(-) create mode 100644 netlink/nlsock.c create mode 100644 netlink/nlsock.h
Makefile.am +2 -1
@@ -27,7 +27,8 @@ endif if ETHTOOL_ENABLE_NETLINK ethtool_SOURCES += \ netlink/netlink.c netlink/netlink.h netlink/extapi.h \ - netlink/msgbuff.c netlink/msgbuff.h \ + netlink/msgbuff.c netlink/msgbuff.h netlink/nlsock.c \ + netlink/nlsock.h \ uapi/linux/ethtool_netlink.h \ uapi/linux/netlink.h uapi/linux/genetlink.h \ uapi/linux/rtnetlink.h uapi/linux/if_link.h
internal.h +8 -0
@@ -119,8 +119,16 @@ static inline int test_bit(unsigned int nr, const unsigned long *addr)/* debugging flags */ enum {DEBUG_PARSE , +DEBUG_NL_MSGS ,/* incoming/outgoing netlink messages */ +DEBUG_NL_DUMP_SND ,/* dump outgoing netlink messages */ +DEBUG_NL_DUMP_RCV ,/* dump incoming netlink messages */ }; +static inline bool debug_on (unsigned long debug,unsigned int bit) +{ +return (debug & (1 << bit)); +} +/* Internal values for old-style offload flags. Values and names * must not clash with the flags defined for ETHTOOL_{G,S}FLAGS. */
netlink/netlink.c +28 -0
@@ -10,6 +10,34 @@#include "netlink.h" #include "extapi.h" +/* Used as reply callback for requests where no reply is expected (e.g. most +* "set" type commands) +*/ +int nomsg_reply_cb (const struct nlmsghdr *nlhdr,void *data) +{ +const struct genlmsghdr *ghdr = (const struct genlmsghdr *)(nlhdr +1 ); + +fprintf (stderr,"received unexpected message: len=%u type=%u cmd=%u\n" , + nlhdr->nlmsg_len, nlhdr->nlmsg_type, ghdr->cmd); +return MNL_CB_OK ; +} + +/* standard attribute parser callback; it fills provided array with pointers +* to attributes like kernel nla_parse(). We must expect to run on top of +* a newer kernel which may send attributes that we do not know (yet). Rather +* than treating them as an error, just ignore them. +*/ +int attr_cb (const struct nlattr *attr,void *data) +{ +const struct attr_tb_info *tb_info = data; +int type =mnl_attr_get_type (attr); + +if (type >=0 && type <= tb_info->max_type) + tb_info->tb[type] = attr; + +return MNL_CB_OK ; +} +/* initialization */ int netlink_init (struct cmd_context *ctx)
netlink/netlink.h +11 -0
@@ -24,4 +24,15 @@ struct nl_context { uint16_t ethnl_fam; }; +struct attr_tb_info { +const struct nlattr **tb; +unsigned int max_type; +}; + +#define DECLARE_ATTR_TB_INFO (tbl) \ + struct attr_tb_info tbl ## _info = { (tbl), (MNL_ARRAY_SIZE(tbl) - 1) } + +int nomsg_reply_cb (const struct nlmsghdr *nlhdr,void *data); +int attr_cb (const struct nlattr *attr,void *data); +#endif /* ETHTOOL_NETLINK_INT_H__ */
netlink/nlsock.c new file +364 -0
364 lines not on this page · raw message
netlink/nlsock.h new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 9/25 netlink: initialize ethtool netlink socket
In reply to Michal KubecekAs part of the netlink initialization, set up netlink socket for ethtool netlink and get id of ethtool genetlink family and monitor multicast group.
--- netlink/netlink.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++- netlink/netlink.h | 11 ++++++ 2 files changed, 104 insertions(+), 1 deletion(-)
netlink/netlink.c +93 -1
@@ -9,6 +9,8 @@#include "../internal.h" #include "netlink.h" #include "extapi.h" +#include "msgbuff.h" +#include "nlsock.h" /* Used as reply callback for requests where no reply is expected (e.g. most * "set" type commands)
@@ -40,18 +42,108 @@ int attr_cb(const struct nlattr *attr, void *data)/* initialization */ +struct fam_info { +const char *fam_name; +const char *grp_name; +uint16_t fam_id; +uint32_t grp_id; +}; + +static void find_mc_group (struct nlattr *nest,struct fam_info *info) +{ +const struct nlattr *grp_tb[CTRL_ATTR_MCAST_GRP_MAX +1 ] = {}; +DECLARE_ATTR_TB_INFO (grp_tb); +struct nlattr *grp_attr; +int ret; + +mnl_attr_for_each_nested (grp_attr, nest) { + ret =mnl_attr_parse_nested (grp_attr, attr_cb, &grp_tb_info); +if (ret <0 ) +return ; +if (!grp_tb[CTRL_ATTR_MCAST_GRP_NAME ] || + !grp_tb[CTRL_ATTR_MCAST_GRP_ID ]) +continue ; +if (strcmp (mnl_attr_get_str (grp_tb[CTRL_ATTR_MCAST_GRP_NAME ]), + info->grp_name)) +continue ; + info->grp_id = +mnl_attr_get_u32 (grp_tb[CTRL_ATTR_MCAST_GRP_ID ]); +return ; + } +} + +static int family_info_cb (const struct nlmsghdr *nlhdr,void *data) +{ +struct fam_info *info = data; +struct nlattr *attr; + +mnl_attr_for_each (attr, nlhdr,GENL_HDRLEN ) { +switch (mnl_attr_get_type (attr)) { +case CTRL_ATTR_FAMILY_ID : + info->fam_id =mnl_attr_get_u16 (attr); +break ; +case CTRL_ATTR_MCAST_GROUPS : +find_mc_group (attr, info); +break ; + } + } + +return MNL_CB_OK ; +} + +static int get_genl_family (struct nl_socket *nlsk,struct fam_info *info) +{ +struct nl_msg_buff *msgbuff = &nlsk->msgbuff; +int ret; + + nlsk->nlctx->suppress_nlerr =2 ; + ret =__msg_init (msgbuff,GENL_ID_CTRL ,CTRL_CMD_GETFAMILY , +NLM_F_REQUEST |NLM_F_ACK ,1 ); +if (ret <0 ) + goto out; + ret = -EMSGSIZE ; +if (ethnla_put_strz (msgbuff,CTRL_ATTR_FAMILY_NAME , info->fam_name)) + goto out; + +nlsock_sendmsg (nlsk,NULL ); +nlsock_process_reply (nlsk, family_info_cb, info); + ret = info->fam_id ?0 : -EADDRNOTAVAIL ; + +out: + nlsk->nlctx->suppress_nlerr =0 ; +return ret; +} +int netlink_init (struct cmd_context *ctx) { +struct fam_info info = { + .fam_name =ETHTOOL_GENL_NAME , + .grp_name =ETHTOOL_MCGRP_MONITOR_NAME , + };struct nl_context *nlctx; +int ret; nlctx =calloc (1 ,sizeof (*nlctx));if (!nlctx)return -ENOMEM ; nlctx->ctx = ctx; + ret =nlsock_init (nlctx, &nlctx->ethnl_socket,NETLINK_GENERIC ); +if (ret <0 ) + goto out_free; + ret =get_genl_family (nlctx->ethnl_socket, &info); +if (ret <0 ) + goto out_nlsk; + nlctx->ethnl_fam = info.fam_id; + nlctx->ethnl_mongrp = info.grp_id; ctx->nlctx = nlctx; -return 0 ; + +out_nlsk: +nlsock_done (nlctx->ethnl_socket); +out_free: +free (nlctx); +return ret; }void netlink_done (struct cmd_context *ctx)
netlink/netlink.h +11 -0
@@ -11,6 +11,7 @@#include <linux/netlink.h> #include <linux/genetlink.h> #include <linux/ethtool_netlink.h> +#include "nlsock.h" #define WILDCARD_DEVNAME "*"
@@ -22,6 +23,9 @@ struct nl_context {int exit_code;unsigned int suppress_nlerr;uint16_t ethnl_fam; +uint32_t ethnl_mongrp; +struct nl_socket *ethnl_socket; +struct nl_socket *ethnl2_socket; };struct attr_tb_info {
@@ -35,4 +39,11 @@ struct attr_tb_info {int nomsg_reply_cb (const struct nlmsghdr *nlhdr,void *data);int attr_cb (const struct nlattr *attr,void *data); +static inline int netlink_init_ethnl2_socket (struct nl_context *nlctx) +{ +if (nlctx->ethnl2_socket) +return 0 ; +return nlsock_init (nlctx, &nlctx->ethnl2_socket,NETLINK_GENERIC ); +} +#endif /* ETHTOOL_NETLINK_INT_H__ */
Signature · 1 line
2.25.1
PATCH v2 10/25 netlink: add support for string sets
In reply to Michal KubecekAdd infrastructure for querying kernel for string sets (analog to ioctl commands ETHTOOL_GSSET_INFO and ETHTOOL_GSTRINGS), caching the results and making them available to netlink code.
There are two types of string sets: global (not related to a device) and per device (each device has its set of string sets). Per device string sets are stored in a linked list (one entry for each device) for now.
String sets can be either preloaded completely on start using preload_global_strings() and preload_perdev_strings() or requested by one when there is a need for them. In the latter case (preferred, in particular for one shot operation mode), second netlink socket is used to request the string set contents.
--- Makefile.am | 2 +- netlink/netlink.c | 53 +++++++++ netlink/netlink.h | 9 ++ netlink/strset.c | 295 ++++++++++++++++++++++++++++++++++++++++++++++ netlink/strset.h | 25 ++++ 5 files changed, 383 insertions(+), 1 deletion(-) create mode 100644 netlink/strset.c create mode 100644 netlink/strset.h
Makefile.am +1 -1
@@ -28,7 +28,7 @@ if ETHTOOL_ENABLE_NETLINK ethtool_SOURCES += \ netlink/netlink.c netlink/netlink.h netlink/extapi.h \ netlink/msgbuff.c netlink/msgbuff.h netlink/nlsock.c \ - netlink/nlsock.h \ + netlink/nlsock.h netlink/strset.c netlink/strset.h \ uapi/linux/ethtool_netlink.h \ uapi/linux/netlink.h uapi/linux/genetlink.h \ uapi/linux/rtnetlink.h uapi/linux/if_link.h
netlink/netlink.c +53 -0
69 lines not on this page · raw message
netlink/netlink.h +9 -0
@@ -39,6 +39,15 @@ struct attr_tb_info {int nomsg_reply_cb (const struct nlmsghdr *nlhdr,void *data);int attr_cb (const struct nlattr *attr,void *data); +const char *get_dev_name (const struct nlattr *nest); +int get_dev_info (const struct nlattr *nest,int *ifindex,char *ifname); + +static inline void copy_devname (char *dst,const char *src) +{ +strncpy (dst, src,ALTIFNAMSIZ ); + dst[ALTIFNAMSIZ -1 ] ='\0' ; +} +static inline int netlink_init_ethnl2_socket (struct nl_context *nlctx) {if (nlctx->ethnl2_socket)
netlink/strset.c new file +295 -0
295 lines not on this page · raw message
netlink/strset.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* strset.h - string set handling +* +* Interface for local cache of ethtool string sets. +*/ + +#ifndef ETHTOOL_NETLINK_STRSET_H__ +#define ETHTOOL_NETLINK_STRSET_H__ + +struct nl_socket ; +struct stringset ; + +const struct stringset *global_stringset (unsigned int type, +struct nl_socket *nlsk); +const struct stringset *perdev_stringset (const char *dev,unsigned int type, +struct nl_socket *nlsk); + +unsigned int get_count (const struct stringset *set); +const char *get_string (const struct stringset *set,unsigned int idx); + +int preload_global_strings (struct nl_socket *nlsk); +int preload_perdev_strings (struct nl_socket *nlsk,const char *dev); +void cleanup_all_strings (void ); + +#endif /* ETHTOOL_NETLINK_STRSET_H__ */
Signature · 1 line
2.25.1
PATCH v2 11/25 netlink: add notification monitor
In reply to Michal KubecekWith 'ethtool --monitor [ --all | opt ] [dev]', let ethtool listen to netlink notification and display them in a format similar to output of related "get" commands.
With --all or without option, show all types of notifications. If a device name is specified, show only notifications for that device, if no device name or "*" is passed, show notifications for all devices.
--- Makefile.am | 1 + ethtool.8.in | 21 +++++ ethtool.c | 14 ++++ netlink/extapi.h | 8 ++ netlink/monitor.c | 197 ++++++++++++++++++++++++++++++++++++++++++++++ netlink/netlink.h | 11 +++ netlink/strset.c | 2 + 7 files changed, 254 insertions(+) create mode 100644 netlink/monitor.c
Makefile.am +1 -0
@@ -29,6 +29,7 @@ ethtool_SOURCES += \ netlink/netlink.c netlink/netlink.h netlink/extapi.h \ netlink/msgbuff.c netlink/msgbuff.h netlink/nlsock.c \ netlink/nlsock.h netlink/strset.c netlink/strset.h \ + netlink/monitor.c \ uapi/linux/ethtool_netlink.h \ uapi/linux/netlink.h uapi/linux/genetlink.h \ uapi/linux/rtnetlink.h uapi/linux/if_link.h
ethtool.8.in +21 -0
@@ -133,6 +133,13 @@ ethtool \- query or control network driver and hardware settings .BN --debug .I args .HP +.B ethtool \-\-monitor +[ +.I command +] [ +.I devname +] +.HP .B ethtool \-a|\-\-show\-pause .I devname .HP
@@ -1244,6 +1251,20 @@ If queue_mask is not set, the sub command will be applied to all queues. Sub command to apply. The supported sub commands include --show-coalesce and --coalesce. .RE +.TP +.B \-\-monitor +Listens to netlink notification and displays them. +.RS 4 +.TP +.I command +If argument matching a command is used, ethtool only shows notifications of +this type. Without such argument or with --all, all notification types are +shown. +.TP +.I devname +If a device name is used as argument, only notification for this device are +shown. Default is to show notifications for all devices. +.RE .SH BUGS Not supported (in part or whole) on all network drivers. .SH AUTHOR
ethtool.c +14 -0
@@ -5664,6 +5664,7 @@ static int show_usage(struct cmd_context *ctx maybe_unused)if (args[i].xhelp)fputs (args[i].xhelp, stdout); } +nl_monitor_usage ();return 0 ; }
@@ -5909,6 +5910,19 @@ int main(int argc, char **argp) argp +=2 ; argc -=2 ; } +#ifdef ETHTOOL_ENABLE_NETLINK +if (*argp && !strcmp (*argp,"--monitor" )) { +if (netlink_init (&ctx)) { +fprintf (stderr, +"Option --monitor is only available with netlink.\n" ); +return 1 ; + }else { + ctx.argp = ++argp; + ctx.argc = --argc; +return nl_monitor (&ctx); + } + } +#endif /* First argument must be either a valid option or a device * name to get settings for (which we don't expect to begin
netlink/extapi.h +8 -0
@@ -15,6 +15,10 @@ struct nl_context;int netlink_init (struct cmd_context *ctx);void netlink_done (struct cmd_context *ctx); +int nl_monitor (struct cmd_context *ctx); + +void nl_monitor_usage (void ); +#else /* ETHTOOL_ENABLE_NETLINK */ static inline int netlink_init(struct cmd_context *ctx maybe_unused)
@@ -26,6 +30,10 @@ static inline void netlink_done(struct cmd_context *ctx maybe_unused) { } +static inline void nl_monitor_usage (void ) +{ +} +#endif /* ETHTOOL_ENABLE_NETLINK */ #endif /* ETHTOOL_EXTAPI_H__ */
netlink/monitor.c new file +197 -0
197 lines not on this page · raw message
netlink/netlink.h +11 -0
@@ -14,6 +14,7 @@#include "nlsock.h" #define WILDCARD_DEVNAME "*" +#define CMDMASK_WORDS DIV_ROUND_UP(__ETHTOOL_MSG_KERNEL_CNT, 32)struct nl_context {struct cmd_context *ctx;
@@ -26,6 +27,9 @@ struct nl_context {uint32_t ethnl_mongrp;struct nl_socket *ethnl_socket;struct nl_socket *ethnl2_socket; +bool is_monitor; +uint32_t filter_cmds[CMDMASK_WORDS ]; +const char *filter_devname; };struct attr_tb_info {
@@ -48,6 +52,13 @@ static inline void copy_devname(char *dst, const char *src) dst[ALTIFNAMSIZ -1 ] ='\0' ; } +static inline bool dev_ok (const struct nl_context *nlctx) +{ +return !nlctx->filter_devname || + (nlctx->devname && + !strcmp (nlctx->devname, nlctx->filter_devname)); +} +static inline int netlink_init_ethnl2_socket (struct nl_context *nlctx) {if (nlctx->ethnl2_socket)
netlink/strset.c +2 -0
@@ -149,6 +149,8 @@ static int strset_reply_cb(const struct nlmsghdr *nlhdr, void *data)return MNL_CB_OK ; nlctx->devname = devname; } +if (ifindex && !dev_ok (nlctx)) +return MNL_CB_OK ;if (ifindex) {struct perdev_strings *perdev;
Signature · 1 line
2.25.1
PATCH v2 12/25 move shared code into a common file
In reply to Michal KubecekMove code which is going to be shared between ioctl and netlink implementation into a common file common.c and declarations into header file common.h.
--- Makefile.am | 2 +- common.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++++ common.h | 26 +++++++++ ethtool.c | 151 +++------------------------------------------------- 4 files changed, 179 insertions(+), 145 deletions(-) create mode 100644 common.c create mode 100644 common.h
Makefile.am +1 -1
@@ -6,7 +6,7 @@ EXTRA_DIST = LICENSE ethtool.8 ethtool.spec.in aclocal.m4 ChangeLog autogen.sh sbin_PROGRAMS = ethtool ethtool_SOURCES = ethtool.c uapi/linux/ethtool.h internal.h \ - uapi/linux/net_tstamp.h rxclass.c + uapi/linux/net_tstamp.h rxclass.c common.c common.h ethtool_CFLAGS = $(AM_CFLAGS) ethtool_LDADD = $(LDADD) if ETHTOOL_ENABLE_PRETTY_DUMP
common.c new file +145 -0
145 lines not on this page · raw message
common.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* common.h - common code header +* +* Declarations for data and functions shared by ioctl and netlink code. +*/ + +#ifndef ETHTOOL_COMMON_H__ +#define ETHTOOL_COMMON_H__ + +#include "internal.h" + +#define KERNEL_VERSION (a, b, c) (((a) << 16) + ((b) << 8) + (c)) + +struct flag_info { +const char *name; +u32 value; +}; + +extern const struct flag_info flags_msglvl[]; +extern const unsigned int n_flags_msglvl; + +void print_flags (const struct flag_info *info,unsigned int n_info,u32 value); +int dump_wol (struct ethtool_wolinfo *wol); +void dump_mdix (u8 mdix,u8 mdix_ctrl); + +#endif /* ETHTOOL_COMMON_H__ */
ethtool.c +7 -144
204 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 13/25 netlink: add bitset helpers
In reply to Michal KubecekAdd basic functions for work with arbitrary length bitsets used in ethtool netlink interface.
The most important function is walk_bitset() which iterates through bits of a bitset (passed as pointer to the nest attribute) and calls provided callback for each bit.
v2:
- add bitset_is_compact() helper
--- Makefile.am | 2 +- netlink/bitset.c | 218 +++++++++++++++++++++++++++++++++++++++++++++++ netlink/bitset.h | 26 ++++++ 3 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 netlink/bitset.c create mode 100644 netlink/bitset.h
Makefile.am +1 -1
@@ -29,7 +29,7 @@ ethtool_SOURCES += \ netlink/netlink.c netlink/netlink.h netlink/extapi.h \ netlink/msgbuff.c netlink/msgbuff.h netlink/nlsock.c \ netlink/nlsock.h netlink/strset.c netlink/strset.h \ - netlink/monitor.c \ + netlink/monitor.c netlink/bitset.c netlink/bitset.h \ uapi/linux/ethtool_netlink.h \ uapi/linux/netlink.h uapi/linux/genetlink.h \ uapi/linux/rtnetlink.h uapi/linux/if_link.h
netlink/bitset.c new file +218 -0
218 lines not on this page · raw message
netlink/bitset.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* bitset.h - netlink bitset helpers +* +* Declarations of helpers for handling ethtool netlink bitsets. +*/ + +#ifndef ETHTOOL_NETLINK_BITSET_H__ +#define ETHTOOL_NETLINK_BITSET_H__ + +#include <libmnl/libmnl.h> +#include <linux/netlink.h> +#include <linux/genetlink.h> +#include <linux/ethtool_netlink.h> +#include "strset.h" + +typedef void (*bitset_walk_callback )(unsigned int ,const char *,bool ,void *); + +uint32_t bitset_get_count (const struct nlattr *bitset,int *retptr); +bool bitset_get_bit (const struct nlattr *bitset,bool mask,unsigned int idx, +int *retptr); +bool bitset_is_compact (const struct nlattr *bitset); +bool bitset_is_empty (const struct nlattr *bitset,bool mask,int *retptr); +int walk_bitset (const struct nlattr *bitset,const struct stringset *labels, +bitset_walk_callback cb,void *data); + +#endif /* ETHTOOL_NETLINK_BITSET_H__ */
Signature · 1 line
2.25.1
PATCH v2 14/25 netlink: partial netlink handler for gset (no option)
In reply to Michal KubecekPartially implement "ethtool <dev>" subcommand. This commit retrieves and displays information provided by ETHTOOL_MSG_LINKINFO_GET, ETHTOOL_MSG_LINKMODES_GET and ETHTOOL_MSG_LINKSTATE_GET netlink requests, i.e. everything except wake-on-lan and debugging (msglevel).
Also register the callbacks in monitor so that corresponding notifications can be displayed with "ethtool --monitor".
v2:
- print banner only once unless monitor or wildcard (dump request)
- suppress error messages for -EOPNOTSUPP responses
- only show "No data available" if there is no reply at all
- more readable nl_gset()
--- Makefile.am | 1 + ethtool.c | 1 + netlink/extapi.h | 3 + netlink/monitor.c | 16 ++ netlink/netlink.h | 4 + netlink/settings.c | 647 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 672 insertions(+) create mode 100644 netlink/settings.c
Makefile.am +1 -0
@@ -30,6 +30,7 @@ ethtool_SOURCES += \ netlink/msgbuff.c netlink/msgbuff.h netlink/nlsock.c \ netlink/nlsock.h netlink/strset.c netlink/strset.h \ netlink/monitor.c netlink/bitset.c netlink/bitset.h \ + netlink/settings.c \ uapi/linux/ethtool_netlink.h \ uapi/linux/netlink.h uapi/linux/genetlink.h \ uapi/linux/rtnetlink.h uapi/linux/if_link.h
ethtool.c +1 -0
@@ -5805,6 +5805,7 @@ int main(int argc, char **argp) }if ((*argp)[0 ] =='-' )exit_bad_args (); + nlfunc = nl_gset; func = do_gset; no_dev = false;
netlink/extapi.h +3 -0
@@ -15,6 +15,7 @@ struct nl_context;int netlink_init (struct cmd_context *ctx);void netlink_done (struct cmd_context *ctx); +int nl_gset (struct cmd_context *ctx);int nl_monitor (struct cmd_context *ctx);void nl_monitor_usage (void );
@@ -34,6 +35,8 @@ static inline void nl_monitor_usage(void) { } +#define nl_gset NULL +#endif /* ETHTOOL_ENABLE_NETLINK */ #endif /* ETHTOOL_EXTAPI_H__ */
netlink/monitor.c +16 -0
@@ -15,6 +15,14 @@ static struct {uint8_t cmd;mnl_cb_t cb; } monitor_callbacks[] = { + { + .cmd = ETHTOOL_MSG_LINKMODES_NTF, + .cb = linkmodes_reply_cb, + }, + { + .cmd = ETHTOOL_MSG_LINKINFO_NTF, + .cb = linkinfo_reply_cb, + }, }; static void clear_filter(struct nl_context *nlctx)
@@ -70,6 +78,14 @@ static struct monitor_option monitor_opts[] = { .pattern = "|--all", .cmd = 0, }, + { + .pattern = "-s|--change", + .cmd = ETHTOOL_MSG_LINKINFO_NTF, + }, + { + .pattern = "-s|--change", + .cmd = ETHTOOL_MSG_LINKMODES_NTF, + }, };static bool pattern_match (const char *s,const char *pattern)
netlink/netlink.h +4 -0
@@ -30,6 +30,7 @@ struct nl_context {bool is_monitor;uint32_t filter_cmds[CMDMASK_WORDS ];const char *filter_devname; +bool no_banner; };struct attr_tb_info {
@@ -46,6 +47,9 @@ int attr_cb(const struct nlattr *attr, void *data);const char *get_dev_name (const struct nlattr *nest);int get_dev_info (const struct nlattr *nest,int *ifindex,char *ifname); +int linkmodes_reply_cb (const struct nlmsghdr *nlhdr,void *data); +int linkinfo_reply_cb (const struct nlmsghdr *nlhdr,void *data); +static inline void copy_devname (char *dst,const char *src) {strncpy (dst, src,ALTIFNAMSIZ );
netlink/settings.c new file +647 -0
647 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 15/25 netlink: support getting wake-on-lan and debugging settings
In reply to Michal KubecekFinish "ethtool <dev>" command implementation by adding support for wake-on-lan (ETHTOOL_MSG_WOL_GET) and debugging (ETHTOOL_MSG_DEBUG_GET, currently only msglevel) settings.
Register the callbacks also with monitor so that "ethtool --monitor" can display corresponding notifications.
v2:
- suppress error messages for -EOPNOTSUPP responses
- perform WOL_GET and DEBUG_GET requests before LINKSTATE_GET
- adjust to changes in patch 14
--- netlink/monitor.c | 16 +++++++ netlink/netlink.h | 2 + netlink/settings.c | 115 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+)
netlink/monitor.c +16 -0
@@ -23,6 +23,14 @@ static struct { .cmd = ETHTOOL_MSG_LINKINFO_NTF, .cb = linkinfo_reply_cb, }, + { + .cmd = ETHTOOL_MSG_WOL_NTF, + .cb = wol_reply_cb, + }, + { + .cmd = ETHTOOL_MSG_DEBUG_NTF, + .cb = debug_reply_cb, + }, };static void clear_filter (struct nl_context *nlctx)
@@ -86,6 +94,14 @@ static struct monitor_option monitor_opts[] = { .pattern = "-s|--change", .cmd = ETHTOOL_MSG_LINKMODES_NTF, }, + { + .pattern = "-s|--change", + .cmd = ETHTOOL_MSG_WOL_NTF, + }, + { + .pattern = "-s|--change", + .cmd = ETHTOOL_MSG_DEBUG_NTF, + }, };static bool pattern_match (const char *s,const char *pattern)
netlink/netlink.h +2 -0
@@ -49,6 +49,8 @@ int get_dev_info(const struct nlattr *nest, int *ifindex, char *ifname);int linkmodes_reply_cb (const struct nlmsghdr *nlhdr,void *data);int linkinfo_reply_cb (const struct nlmsghdr *nlhdr,void *data); +int wol_reply_cb (const struct nlmsghdr *nlhdr,void *data); +int debug_reply_cb (const struct nlmsghdr *nlhdr,void *data);static inline void copy_devname (char *dst,const char *src) {
netlink/settings.c +115 -0
132 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 16/25 netlink: add basic command line parsing helpers
In reply to Michal KubecekExisting command line parser functions from the ioctl interface are often too closely tied to the ioctl data structures and would not be easily adapted to generating netlink messages. Introduce a new parser framework which assigns parser handlers to parameters and provide basic handlers for most common parameter types:
- flag represented by presence of a parameter
- u8 bool represented by name followed by "on" or "off"
- string represented by string argument
- u32 represented by numeric argument
- u8 represented by numeric argument
- u32 represented by symbolic name (lookup table)
- u8 represented by symbolic name (lookup table)
- binary blob represented by MAC-like syntax
Main parser entry point is nl_parse() function; it gets an array of with entries assigning parser handlers and optional data to command line parameters and generates corresponding netlink attributes or fills raw data.
Optionally, attributes can be divided into multiple netlink messages or multiple nested attributes.
--- Makefile.am | 2 +- netlink/netlink.h | 4 + netlink/parser.c | 615 ++++++++++++++++++++++++++++++++++++++++++++++ netlink/parser.h | 123 ++++++++++ 4 files changed, 743 insertions(+), 1 deletion(-) create mode 100644 netlink/parser.c create mode 100644 netlink/parser.h
Makefile.am +1 -1
@@ -30,7 +30,7 @@ ethtool_SOURCES += \ netlink/msgbuff.c netlink/msgbuff.h netlink/nlsock.c \ netlink/nlsock.h netlink/strset.c netlink/strset.h \ netlink/monitor.c netlink/bitset.c netlink/bitset.h \ - netlink/settings.c \ + netlink/settings.c netlink/parser.c netlink/parser.h \ uapi/linux/ethtool_netlink.h \ uapi/linux/netlink.h uapi/linux/genetlink.h \ uapi/linux/rtnetlink.h uapi/linux/if_link.h
netlink/netlink.h +4 -0
@@ -31,6 +31,10 @@ struct nl_context {uint32_t filter_cmds[CMDMASK_WORDS ];const char *filter_devname;bool no_banner; +const char *cmd; +const char *param; +char **argp; +int argc; };struct attr_tb_info {
netlink/parser.c new file +615 -0
615 lines not on this page · raw message
netlink/parser.h new file +123 -0
123 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 17/25 netlink: add bitset command line parser handlers
In reply to Michal KubecekAdd three more command line parser handlers for different representation of bitsets:
- series of "name on|off" pairs for bitset with mask
- series of names for bitsets without mask (lists)
- string consisting of characters representing bits (e.g. WoL modes); extended syntax "([+-][a-z])+" is supported for bitsets with mask
Numeric syntax %u[/%u] is also supported.
--- netlink/parser.c | 443 +++++++++++++++++++++++++++++++++++++++++++++++ netlink/parser.h | 21 +++ 2 files changed, 464 insertions(+)
netlink/parser.c +443 -0
@@ -43,6 +43,12 @@ static void parser_err_invalid_value(struct nl_context *nlctx, const char *val) nlctx->cmd, val, nlctx->param); } +static void parser_err_invalid_flag (struct nl_context *nlctx,const char *flag) +{ +fprintf (stderr,"ethtool (%s): flag '%s' for parameter '%s' is not followed by 'on' or 'off'\n" , + nlctx->cmd, flag, nlctx->param); +} +static bool __prefix_0x (const char *p) {return p[0 ] =='0' && (p[1 ] =='x' || p[1 ] =='X' );
@@ -282,6 +288,35 @@ int nl_parse_lookup_u8(struct nl_context *nlctx, uint16_t type,return (type &ðnla_put_u8 (msgbuff, type, val)) ? -EMSGSIZE :0 ; } +/* number of significant bits */ +static unsigned int __nsb (uint32_t x) +{ +unsigned int ret =0 ; + +if (x &0xffff0000U ) { + x >>=16 ; + ret +=16 ; + } +if (x &0xff00U ) { + x >>=8 ; + ret +=8 ; + } +if (x &0xf0U ) { + x >>=4 ; + ret +=4 ; + } +if (x &0xcU ) { + x >>=2 ; + ret +=2 ; + } +if (x &0x2U ) { + x >>=1 ; + ret +=1 ; + } + +return ret + x; +} +static bool __is_hex (char c) {if (isdigit (c))
@@ -405,6 +440,414 @@ int nl_parse_error(struct nl_context *nlctx, uint16_t type, const void *data,return parser_data->ret_val; } +/* bitset parser handlers */ + +/* Return true if a bitset argument should be parsed as numeric, i.e. +* (a) it starts with '0x' +* (b) it consists only of hex digits and at most one slash which can be +* optionally followed by "0x"; if no_mask is true, slash is not allowed +*/ +static bool is_numeric_bitset (const char *arg,bool no_mask) +{ +const char *p = arg; +bool has_slash = false; + +if (!arg) +return false; +if (__prefix_0x (arg)) +return true; +while (*p) { +if (*p =='/' ) { +if (has_slash || no_mask) +return false; + has_slash = true; + p++; +if (__prefix_0x (p)) + p +=2 ; +continue ; + } +if (!__is_hex (*p)) +return false; + p++; + } +return true; +} + +#define __MAX_U32_DIGITS 10 + +/* Parse hex string (without leading "0x") into a bitmap consisting of 32-bit +* words. Caller must make sure arg is at least len characters long and dst has +* place for at least (len + 7) / 8 32-bit words. If force_hex is false, allow +* also base 10 unsigned 32-bit value. +* +* Returns number of significant bits in the bitmap on success and negative +* value on error. +*/ +static int __parse_num_string (const char *arg,unsigned int len,uint32_t *dst, +bool force_hex) +{ +char buff[__MAX_U32_DIGITS +1 ] = {}; +unsigned int nbits =0 ; +const char *p = arg; + +if (!len) +return -EINVAL ; +if (!force_hex && len <= __MAX_U32_DIGITS) { +strncpy (buff, arg, len); +if (!buff[__MAX_U32_DIGITS]) { +u32 val; +int ret; + + ret =parse_u32d (buff, &val); +if (!ret) { + *dst = val; +return __nsb (val); + } + } + } + + dst += (len -1 ) /8 ; +while (len >0 ) { +unsigned int chunk = (len %8 ) ?:8 ; +unsigned long val; +char *endp; + +memcpy (buff, p, chunk); + buff[chunk] ='\0' ; + val =strtoul (buff, &endp,16 ); +if (*endp) +return -EINVAL ; + *dst-- = (uint32_t )val; +if (nbits) + nbits +=4 * chunk; +else + nbits =__nsb (val); + + p += chunk; + len -= chunk; + } +return nbits; +} + +/* Parse bitset provided as a base 16 numeric value (@no_mask is true) or pair +* of base 16 numeric values separated by '/' (@no_mask is false). The "0x" +* prefix is optional. Generates bitset nested attribute in compact form. +*/ +static int parse_numeric_bitset (struct nl_context *nlctx,uint16_t type, +bool no_mask,bool force_hex, +struct nl_msg_buff *msgbuff) +{ +unsigned int nwords, len1, len2; +const char *arg = *nlctx->argp; +bool force_hex1 = force_hex; +bool force_hex2 = force_hex; +uint32_t *value =NULL ; +uint32_t *mask =NULL ; +struct nlattr *nest; +const char *maskptr; +int ret =0 ; +int nbits; + +if (__prefix_0x (arg)) { + force_hex1 = true; + arg +=2 ; + } + + maskptr =strchr (arg,'/' ); +if (maskptr && no_mask) { +parser_err_invalid_value (nlctx, arg); +return -EINVAL ; + } + len1 = maskptr ? (maskptr - arg) :strlen (arg); + nwords =DIV_ROUND_UP (len1,8 ); + nbits =0 ; + +if (maskptr) { + maskptr++; +if (__prefix_0x (maskptr)) { + maskptr +=2 ; + force_hex2 = true; + } + len2 =strlen (maskptr); +if (len2 > len1) + nwords =DIV_ROUND_UP (len2,8 ); + mask =calloc (nwords,sizeof (uint32_t )); +if (!mask) +return -ENOMEM ; + ret =__parse_num_string (maskptr,strlen (maskptr), mask, + force_hex2); +if (ret <0 ) { +parser_err_invalid_value (nlctx, arg); + goto out_free; + } + nbits = ret; + } + + value =calloc (nwords,sizeof (uint32_t )); +if (!value) +return -ENOMEM ; + ret =__parse_num_string (arg, len1, value, force_hex1); +if (ret <0 ) { +parser_err_invalid_value (nlctx, arg); + goto out_free; + } + nbits = (nbits < ret) ? ret : nbits; + nwords = (nbits +31 ) /32 ; + + ret =0 ; +if (!type) + goto out_free; + ret = -EMSGSIZE ; + nest =ethnla_nest_start (msgbuff, type); +if (!nest) + goto out_free; +if (ethnla_put_flag (msgbuff,ETHTOOL_A_BITSET_NOMASK , !mask) || +ethnla_put_u32 (msgbuff,ETHTOOL_A_BITSET_SIZE , nbits) || +ethnla_put (msgbuff,ETHTOOL_A_BITSET_VALUE , + nwords *sizeof (uint32_t ), value) || + (mask && +ethnla_put (msgbuff,ETHTOOL_A_BITSET_MASK , + nwords *sizeof (uint32_t ), mask))) + goto out_free; +ethnla_nest_end (msgbuff, nest); + ret =0 ; + +out_free: +free (value); +free (mask); + nlctx->argp++; + nlctx->argc--; +return ret; +} + +/* Parse bitset provided as series of "name on|off" pairs (@no_mask is false) +* or names (@no_mask is true). Generates bitset nested attribute in verbose +* form with names from command line. +*/ +static int parse_name_bitset (struct nl_context *nlctx,uint16_t type, +bool no_mask,struct nl_msg_buff *msgbuff) +{ +struct nlattr *bitset_attr; +struct nlattr *bits_attr; +struct nlattr *bit_attr; +int ret; + + bitset_attr =ethnla_nest_start (msgbuff, type); +if (!bitset_attr) +return -EMSGSIZE ; + ret = -EMSGSIZE ; +if (no_mask &ðnla_put_flag (msgbuff,ETHTOOL_A_BITSET_NOMASK , true)) + goto err; + bits_attr =ethnla_nest_start (msgbuff,ETHTOOL_A_BITSET_BITS ); +if (!bits_attr) + goto err; + +while (nlctx->argc >0 ) { +bool bit_val = true; + +if (!strcmp (*nlctx->argp,"--" )) { + nlctx->argp++; + nlctx->argc--; +break ; + } + ret = -EINVAL ; +if (!no_mask) { +if (nlctx->argc <2 || + (strcmp (nlctx->argp[1 ],"on" ) && +strcmp (nlctx->argp[1 ],"off" ))) { +parser_err_invalid_flag (nlctx, *nlctx->argp); + goto err; + } + bit_val = !strcmp (nlctx->argp[1 ],"on" ); + } + + ret = -EMSGSIZE ; + bit_attr =ethnla_nest_start (msgbuff, +ETHTOOL_A_BITSET_BITS_BIT ); +if (!bit_attr) + goto err; +if (ethnla_put_strz (msgbuff,ETHTOOL_A_BITSET_BIT_NAME , + nlctx->argp[0 ])) + goto err; +if (!no_mask && +ethnla_put_flag (msgbuff,ETHTOOL_A_BITSET_BIT_VALUE , + bit_val)) + goto err; +ethnla_nest_end (msgbuff, bit_attr); + + nlctx->argp += (no_mask ?1 :2 ); + nlctx->argc -= (no_mask ?1 :2 ); + } + +ethnla_nest_end (msgbuff, bits_attr); +ethnla_nest_end (msgbuff, bitset_attr); +return 0 ; +err: +ethnla_nest_cancel (msgbuff, bitset_attr); +return ret; +} + +static bool is_char_bitset (const char *arg, +const struct char_bitset_parser_data *data) +{ +bool mask = (arg[0 ] =='+' || arg[0 ] =='-' ); +unsigned int i; +const char *p; + +for (p = arg; *p; p++) { +if (*p == data->reset_char) +continue ; +if (mask && (*p =='+' || *p =='-' )) +continue ; +for (i =0 ; i < data->nbits; i++) +if (*p == data->bit_chars[i]) + goto found; +return false; +found: + ; + } + +return true; +} + +/* Parse bitset provided as a string consisting of characters corresponding to +* bit indices. The "reset character" resets the no-mask bitset to empty. If +* the first character is '+' or '-', generated bitset has mask and '+' and +* '-' switch between enabling and disabling the following bits (i.e. their +* value being true/false). In such case, "reset character" is not allowed. +*/ +static int parse_char_bitset (struct nl_context *nlctx,uint16_t type, +const struct char_bitset_parser_data *data, +struct nl_msg_buff *msgbuff) +{ +const char *arg = *nlctx->argp; +struct nlattr *bitset_attr; +struct nlattr *saved_pos; +struct nlattr *bits_attr; +struct nlattr *bit_attr; +unsigned int idx; +bool val = true; +const char *p; +bool no_mask; +int ret; + + no_mask = data->no_mask || !(arg[0 ] =='+' || arg[0 ] =='-' ); + bitset_attr =ethnla_nest_start (msgbuff, type); +if (!bitset_attr) +return -EMSGSIZE ; + ret = -EMSGSIZE ; +if (no_mask &ðnla_put_flag (msgbuff,ETHTOOL_A_BITSET_NOMASK , true)) + goto err; + bits_attr =ethnla_nest_start (msgbuff,ETHTOOL_A_BITSET_BITS ); +if (!bits_attr) + goto err; + saved_pos =mnl_nlmsg_get_payload_tail (msgbuff->nlhdr); + +for (p = arg; *p; p++) { +if (*p =='+' || *p =='-' ) { +if (no_mask) { +parser_err_invalid_value (nlctx, arg); + ret = -EINVAL ; + goto err; + } + val = (*p =='+' ); +continue ; + } +if (*p == data->reset_char) { +if (no_mask) { +mnl_attr_nest_cancel (msgbuff->nlhdr, saved_pos); +continue ; + } +fprintf (stderr,"ethtool (%s): invalid char '%c' in '%s' for parameter '%s'\n" , + nlctx->cmd, *p, arg, nlctx->param); + ret = -EINVAL ; + goto err; + } + +for (idx =0 ; idx < data->nbits; idx++) { +if (data->bit_chars[idx] == *p) +break ; + } +if (idx >= data->nbits) { +fprintf (stderr,"ethtool (%s): invalid char '%c' in '%s' for parameter '%s'\n" , + nlctx->cmd, *p, arg, nlctx->param); + ret = -EINVAL ; + goto err; + } + bit_attr =ethnla_nest_start (msgbuff, +ETHTOOL_A_BITSET_BITS_BIT ); +if (!bit_attr) + goto err; +if (ethnla_put_u32 (msgbuff,ETHTOOL_A_BITSET_BIT_INDEX , idx)) + goto err; +if (!no_mask && +ethnla_put_flag (msgbuff,ETHTOOL_A_BITSET_BIT_VALUE , val)) + goto err; +ethnla_nest_end (msgbuff, bit_attr); + } + +ethnla_nest_end (msgbuff, bits_attr); +ethnla_nest_end (msgbuff, bitset_attr); + nlctx->argp++; + nlctx->argc--; +return 0 ; +err: +ethnla_nest_cancel (msgbuff, bitset_attr); +return ret; +} + +/* Parser handler for bitset. Expects either a numeric value (base 16 or 10 +* (unless force_hex is set)), optionally followed by '/' and another numeric +* value (mask, unless no_mask is set), or a series of "name on|off" pairs +* (no_mask not set) or names (no_mask set). In the latter case, names are +* passed on as they are and kernel performs their interpretation and +* validation. The @data parameter points to struct bitset_parser_data. +* Generates only a bitset nested attribute. Fails if @type is zero or @dest +* is not null. +*/ +int nl_parse_bitset (struct nl_context *nlctx,uint16_t type,const void *data, +struct nl_msg_buff *msgbuff,void *dest) +{ +const struct bitset_parser_data *parser_data = data; + +if (!type || dest) { +fprintf (stderr,"ethtool (%s): internal error parsing '%s'\n" , + nlctx->cmd, nlctx->param); +return -EFAULT ; + } +if (is_numeric_bitset (*nlctx->argp, false)) +return parse_numeric_bitset (nlctx, type, parser_data->no_mask, + parser_data->force_hex, msgbuff); +else +return parse_name_bitset (nlctx, type, parser_data->no_mask, + msgbuff); +} + +/* Parser handler for bitset. Expects either a numeric value (base 10 or 16), +* optionally followed by '/' and another numeric value (mask, unless no_mask +* is set), or a string consisting of characters corresponding to bit indices. +* The @data parameter points to struct char_bitset_parser_data. Generates +* biset nested attribute. Fails if type is zero or if @dest is not null. +*/ +int nl_parse_char_bitset (struct nl_context *nlctx,uint16_t type, +const void *data,struct nl_msg_buff *msgbuff, +void *dest) +{ +const struct char_bitset_parser_data *parser_data = data; + +if (!type || dest) { +fprintf (stderr,"ethtool (%s): internal error parsing '%s'\n" , + nlctx->cmd, nlctx->param); +return -EFAULT ; + } +if (is_char_bitset (*nlctx->argp, data) || + !is_numeric_bitset (*nlctx->argp, false)) +return parse_char_bitset (nlctx, type, parser_data, msgbuff); +else +return parse_numeric_bitset (nlctx, type, parser_data->no_mask, + false, msgbuff); +} +/* parser implementation */ static const struct param_parser *find_parser(const struct param_parser *params,
netlink/parser.h +21 -0
@@ -79,6 +79,20 @@ struct error_parser_data {unsigned int extra_args; }; +/* used by nl_parse_bitset() */ +struct bitset_parser_data { +bool force_hex; +bool no_mask; +}; + +/* used by nl_parse_char_bitset() */ +struct char_bitset_parser_data { +const char *bit_chars; +unsigned int nbits; +char reset_char; +bool no_mask; +}; +int parse_u32 (const char *arg,uint32_t *result);/* parser handlers to use as param_parser::handler */
@@ -115,6 +129,13 @@ int nl_parse_error(struct nl_context *nlctx, uint16_t type, const void *data,int nl_parse_byte_str (struct nl_context *nlctx,uint16_t type,const void *data,struct nl_msg_buff *msgbuff,void *dest); +/* bitset represented by %x[/%x] or name on|off ... [--] */ +int nl_parse_bitset (struct nl_context *nlctx,uint16_t type,const void *data, +struct nl_msg_buff *msgbuff,void *dest); +/* bitset represented by %u[/%u] or string (characters for bits) */ +int nl_parse_char_bitset (struct nl_context *nlctx,uint16_t type, +const void *data,struct nl_msg_buff *msgbuff, +void *dest);/* main entry point called to parse the command line */ int nl_parser(struct nl_context *nlctx, const struct param_parser *params,
Signature · 1 line
2.25.1
PATCH v2 18/25 netlink: add netlink handler for sset (-s)
In reply to Michal KubecekImplement "ethtool -s <dev>" subcommand using netlink interface request ETHTOOL_MSG_LINKINFO_SET, ETHTOOL_MSG_LINKMODES_SET, ETHTOOL_MSG_WOL_SET and ETHTOOL_MSG_DEBUG_SET.
Parser grouping with PARSER_GROUP_MSG group style is used to create multiple request messages from one set of attributes which can be in arbitrary order.
--- ethtool.8.in | 15 ++-- ethtool.c | 9 ++- netlink/extapi.h | 2 + netlink/settings.c | 193 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 210 insertions(+), 9 deletions(-)
ethtool.8.in +10 -5
@@ -242,16 +242,21 @@ ethtool \- query or control network driver and hardware settings .I devname .BN speed .B2 duplex half full -.B4 port tp aui bnc mii fibre +.B4 port tp aui bnc mii fibre da .B3 mdix auto on off .B2 autoneg on off -.BN advertise +.RB [ advertise \ \fIN\fP[\fB/\fP\fIM\fP] +| +.BI advertise \ mode +.A1 on off +.RB ...] .BN phyad .B2 xcvr internal external -.RB [ wol \ \*(WO] +.RB [ wol \ \fIN\fP[\fB/\fP\fIM\fP] +.RB | \ wol \ \*(WO] .RB [ sopass \ \*(MA] .RB [ msglvl -.IR N \ | +.IR N\fP[/\fIM\fP] \ | .BI msglvl \ type .A1 on off .RB ...]
@@ -638,7 +643,7 @@ with just the device name as an argument will show you the supported device spee .A2 duplex half full Sets full or half duplex mode. .TP -.A4 port tp aui bnc mii fibre +.A4 port tp aui bnc mii fibre da Selects device port. .TP .A3 mdix auto on off
ethtool.c +5 -4
@@ -5166,18 +5166,19 @@ static const struct option args[] = { { .opts = "-s|--change", .func = do_sset, + .nlfunc = nl_sset, .help = "Change generic options", .xhelp =" [ speed %d ]\n" " [ duplex half|full ]\n" -" [ port tp|aui|bnc|mii|fibre ]\n" +" [ port tp|aui|bnc|mii|fibre|da ]\n" " [ mdix auto|on|off ]\n" " [ autoneg on|off ]\n" -" [ advertise %x ]\n" +" [ advertise %x[/%x] | mode on|off ... [--] ]\n" " [ phyad %d ]\n" " [ xcvr internal|external ]\n" -" [ wol p|u|m|b|a|g|s|f|d... ]\n" +" [ wol %d[/%d] | p|u|m|b|a|g|s|f|d... ]\n" " [ sopass %x:%x:%x:%x:%x:%x ]\n" -" [ msglvl %d | msglvl type on|off ... ]\n" +" [ msglvl %d[/%d] | type on|off ... [--] ]\n" }, { .opts = "-a|--show-pause",
netlink/extapi.h +2 -0
@@ -16,6 +16,7 @@ int netlink_init(struct cmd_context *ctx);void netlink_done (struct cmd_context *ctx);int nl_gset (struct cmd_context *ctx); +int nl_sset (struct cmd_context *ctx);int nl_monitor (struct cmd_context *ctx);void nl_monitor_usage (void );
@@ -36,6 +37,7 @@ static inline void nl_monitor_usage(void) }#define nl_gset NULL +#define nl_sset NULL#endif /* ETHTOOL_ENABLE_NETLINK */
netlink/settings.c +193 -0
202 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 19/25 netlink: support tests with netlink enabled
In reply to Michal KubecekAs there is no netlink implementation of features (-k / -K) yet, we only need to take care of test-cmdline. With this patch, the full test suite succeeds with both --enable-netlink and --disable-netlink.
There are two differences between results with netlink enabled and disabled:
1. The netlink interface allows network device names up to 127 characters (ALTIFNAMSIZ - 1). While alternative names can be used to identify a device with ioctl, fixed structure does not allow passing names longer than 15 characters (IFNAMSIZ - 1).
2. Failure with deprecated 'xcvr' parameter for -s / --change is done in slightly different way so that netlink code will have it interpreted as a parser failure while ioctl code as (fake) request failure. Another difference is that no kernel with ethtool netlink support can possibly allow changing transceiver using ethtool request.
The command line tests affected by these differences have expected return code depending on ETHTOOL_ENABLE_NETLINK.
--- netlink/netlink.c | 7 +++++++ netlink/nlsock.c | 2 ++ test-cmdline.c | 29 ++++++++++++++++++++++++++--- test-features.c | 11 +++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-)
netlink/netlink.c +7 -0
@@ -143,6 +143,12 @@ static int family_info_cb(const struct nlmsghdr *nlhdr, void *data)return MNL_CB_OK ; } +#ifdef TEST_ETHTOOL +static int get_genl_family (struct nl_socket *nlsk,struct fam_info *info) +{ +return 0 ; +} +#else static int get_genl_family (struct nl_socket *nlsk,struct fam_info *info) {struct nl_msg_buff *msgbuff = &nlsk->msgbuff;
@@ -165,6 +171,7 @@ out: nlsk->nlctx->suppress_nlerr =0 ; return ret; } +#endif int netlink_init (struct cmd_context *ctx) {
netlink/nlsock.c +2 -0
@@ -261,6 +261,7 @@ int nlsock_prep_get_request(struct nl_socket *nlsk, unsigned int nlcmd,return 0 ; } +#ifndef TEST_ETHTOOL /** * nlsock_sendmsg() - send a netlink message to kernel * @nlsk: netlink socket
@@ -277,6 +278,7 @@ ssize_t nlsock_sendmsg(struct nl_socket *nlsk, struct nl_msg_buff *altbuff)debug_msg (nlsk, msgbuff->buff, nlhdr->nlmsg_len, true); return mnl_socket_sendto(nlsk->sk, nlhdr, nlhdr->nlmsg_len); } +#endif /** * nlsock_send_get_request() - send request and process reply
test-cmdline.c +26 -3
@@ -12,6 +12,12 @@#define TEST_NO_WRAPPERS #include "internal.h" +#ifdef ETHTOOL_ENABLE_NETLINK +#define IS_NL 1 +#else +#define IS_NL 0 +#endif + static struct test_case { int rc; const char *args;
@@ -19,7 +25,10 @@ static struct test_case { { 1, "" }, { 0, "devname" }, { 0, "15_char_devname" }, - { 1, "16_char_devname!" }, +/* netlink interface allows names up to 127 characters */ + { !IS_NL, "16_char_devname!" }, + { !IS_NL, "127_char_devname0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde" }, + { 1, "128_char_devname0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" },/* Argument parsing for -s is specialised */ { 0, "-s devname" }, { 0, "--change devname speed 100 duplex half mdix auto" },
@@ -55,7 +64,8 @@ static struct test_case { { 0, "-s devname phyad 1" }, { 1, "--change devname phyad foo" }, { 1, "-s devname phyad" }, - { 0, "--change devname xcvr external" }, +/* Deprecated 'xcvr' detected by netlink parser */ + { IS_NL, "--change devname xcvr external" }, { 1, "-s devname xcvr foo" }, { 1, "--change devname xcvr" }, { 0, "-s devname wol p" },
@@ -69,7 +79,9 @@ static struct test_case { { 0, "-s devname msglvl hw on rx_status off" }, { 1, "--change devname msglvl hw foo" }, { 1, "-s devname msglvl hw" }, - { 0, "--change devname speed 100 duplex half port tp autoneg on advertise 0x1 phyad 1 xcvr external wol p sopass 01:23:45:67:89:ab msglvl 1" }, + { 0, "--change devname speed 100 duplex half port tp autoneg on advertise 0x1 phyad 1 wol p sopass 01:23:45:67:89:ab msglvl 1" }, +/* Deprecated 'xcvr' detected by netlink parser */ + { IS_NL, "--change devname speed 100 duplex half port tp autoneg on advertise 0x1 phyad 1 xcvr external wol p sopass 01:23:45:67:89:ab msglvl 1" }, { 1, "-s devname foo" }, { 1, "-s" }, { 0, "-a devname" },
@@ -294,6 +306,17 @@ int send_ioctl(struct cmd_context *ctx, void *cmd)test_exit (0 ); } +#ifdef ETHTOOL_ENABLE_NETLINK +struct nl_socket ; +struct nl_msg_buff ; + +ssize_t nlsock_sendmsg (struct nl_socket *nlsk,struct nl_msg_buff *altbuff) +{ +/* If we get this far then parsing succeeded */ +test_exit (0 ); +} +#endif +int main (void ) {struct test_case *tc;
test-features.c +11 -0
@@ -511,6 +511,17 @@ int send_ioctl(struct cmd_context *ctx, void *cmd)return rc; } +#ifdef ETHTOOL_ENABLE_NETLINK +struct nl_socket ; +struct nl_msg_buff ; + +ssize_t nlsock_sendmsg (struct nl_socket *nlsk,struct nl_msg_buff *altbuff) +{ +/* Should not be called with test-features */ +exit (1 ); +} +#endif +int main (void ) {const struct test_case *tc;
Signature · 1 line
2.25.1
PATCH v2 20/25 netlink: add handler for permaddr (-P)
In reply to Michal KubecekImplement "ethtool -P <dev>" subcommand. This retrieves and displays information traditionally provided by ETHTOOL_GPERMADDR ioctl request.
Permanent hardware address is provided by rtnetlink RTM_GETLINK request so that basic support for rtnetlink (which is not based on genetlink) requests is also added.
The IFLA_PERM_ADDRESS attribute in RTM_NEWLINK message is not set if the device driver did not set its permanent hardware address which is hard to distinguish from ethtool running on top of an older kernel not supporting the attribute. As IFLA_PERM_ADDRESS attribute was added to kernel shortly before the initial portion of ethtool netlink interface, we let ethtool initialize ethtool netlink even if it is not needed so that we can fall back to ioctl on older kernels and assume that absence of IFLA_PERM_ADDRESS means the permanent address is not set. This would be only wrong on some distribution kernel which would backport ethtool netlink interface but not IFLA_PERM_ADDRESS which is unlikely.
Permanent address is immutable (or not mutable using standard interfaces) so that there is no related notification message.
--- Makefile.am | 1 + ethtool.c | 1 + netlink/extapi.h | 2 + netlink/netlink.h | 8 ++++ netlink/permaddr.c | 114 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 126 insertions(+) create mode 100644 netlink/permaddr.c
Makefile.am +1 -0
@@ -31,6 +31,7 @@ ethtool_SOURCES += \ netlink/nlsock.h netlink/strset.c netlink/strset.h \ netlink/monitor.c netlink/bitset.c netlink/bitset.h \ netlink/settings.c netlink/parser.c netlink/parser.h \ + netlink/permaddr.c \ uapi/linux/ethtool_netlink.h \ uapi/linux/netlink.h uapi/linux/genetlink.h \ uapi/linux/rtnetlink.h uapi/linux/if_link.h
ethtool.c +1 -0
@@ -5372,6 +5372,7 @@ static const struct option args[] = { { .opts = "-P|--show-permaddr", .func = do_permaddr, + .nlfunc = nl_permaddr, .help ="Show permanent hardware address" }, {
netlink/extapi.h +2 -0
@@ -17,6 +17,7 @@ void netlink_done(struct cmd_context *ctx);int nl_gset (struct cmd_context *ctx);int nl_sset (struct cmd_context *ctx); +int nl_permaddr (struct cmd_context *ctx);int nl_monitor (struct cmd_context *ctx);void nl_monitor_usage (void );
@@ -38,6 +39,7 @@ static inline void nl_monitor_usage(void)#define nl_gset NULL#define nl_sset NULL +#define nl_permaddr NULL#endif /* ETHTOOL_ENABLE_NETLINK */
netlink/netlink.h +8 -0
@@ -27,6 +27,7 @@ struct nl_context {uint32_t ethnl_mongrp;struct nl_socket *ethnl_socket;struct nl_socket *ethnl2_socket; +struct nl_socket *rtnl_socket;bool is_monitor;uint32_t filter_cmds[CMDMASK_WORDS ];const char *filter_devname;
@@ -76,4 +77,11 @@ static inline int netlink_init_ethnl2_socket(struct nl_context *nlctx) return nlsock_init(nlctx, &nlctx->ethnl2_socket, NETLINK_GENERIC); } +static inline int netlink_init_rtnl_socket (struct nl_context *nlctx) +{ +if (nlctx->rtnl_socket) +return 0 ; +return nlsock_init (nlctx, &nlctx->rtnl_socket,NETLINK_ROUTE ); +} +#endif /* ETHTOOL_NETLINK_INT_H__ */
netlink/permaddr.c new file +114 -0
114 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 21/25 netlink: support for pretty printing netlink messages
In reply to Michal KubecekTo improve message reporting and debugging, add support for displaying netlink messages in human readable form, e.g.
# ethtool --debug 0x10 -s eth0 msglvl drv on foo on probe off
netlink error: bit name not found
offending message and attribute:
ETHTOOL_MSG_DEBUG_SET
ETHTOOL_A_DEBUG_HEADER
ETHTOOL_A_HEADER_DEV_NAME = "eth0"
ETHTOOL_A_DEBUG_MSGMASK
ETHTOOL_A_BITSET_BITS
ETHTOOL_A_BITSET_BITS_BIT
ETHTOOL_A_BITSET_BIT_NAME = "drv"
ETHTOOL_A_BITSET_BIT_VALUE = true
ETHTOOL_A_BITSET_BITS_BIT
===> ETHTOOL_A_BITSET_BIT_NAME = "foo"
ETHTOOL_A_BITSET_BIT_VALUE = true
ETHTOOL_A_BITSET_BITS_BIT
ETHTOOL_A_BITSET_BIT_NAME = "probe"This commit only adds support for parsing and displaying a message and (optionally) highlighting an attribute on given offset (for extack error reporting). To actually use it, one also needs message descriptions, i.e. mapping of netlink attribute types to their symbolic names and payload formats (depending on context).
--- Makefile.am | 2 +- netlink/prettymsg.c | 193 ++++++++++++++++++++++++++++++++++++++++++++ netlink/prettymsg.h | 102 +++++++++++++++++++++++ 3 files changed, 296 insertions(+), 1 deletion(-) create mode 100644 netlink/prettymsg.c create mode 100644 netlink/prettymsg.h
Makefile.am +1 -1
@@ -31,7 +31,7 @@ ethtool_SOURCES += \ netlink/nlsock.h netlink/strset.c netlink/strset.h \ netlink/monitor.c netlink/bitset.c netlink/bitset.h \ netlink/settings.c netlink/parser.c netlink/parser.h \ - netlink/permaddr.c \ + netlink/permaddr.c netlink/prettymsg.c netlink/prettymsg.h \ uapi/linux/ethtool_netlink.h \ uapi/linux/netlink.h uapi/linux/genetlink.h \ uapi/linux/rtnetlink.h uapi/linux/if_link.h
netlink/prettymsg.c new file +193 -0
193 lines not on this page · raw message
netlink/prettymsg.h new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 22/25 netlink: message format description for ethtool netlink
In reply to Michal KubecekAdd description of ethtool netlink message formats to be used for pretty printing infrastructure. These arrays map (numeric) attribute types to their symbolic names and format of their payload so that attributes can be displayed in human friendly form.
--- Makefile.am | 1 + netlink/desc-ethtool.c | 139 +++++++++++++++++++++++++++++++++++++++++ netlink/prettymsg.h | 7 +++ 3 files changed, 147 insertions(+) create mode 100644 netlink/desc-ethtool.c
Makefile.am +1 -0
@@ -32,6 +32,7 @@ ethtool_SOURCES += \ netlink/monitor.c netlink/bitset.c netlink/bitset.h \ netlink/settings.c netlink/parser.c netlink/parser.h \ netlink/permaddr.c netlink/prettymsg.c netlink/prettymsg.h \ + netlink/desc-ethtool.c \ uapi/linux/ethtool_netlink.h \ uapi/linux/netlink.h uapi/linux/genetlink.h \ uapi/linux/rtnetlink.h uapi/linux/if_link.h
netlink/desc-ethtool.c new file +139 -0
139 lines not on this page · raw message
netlink/prettymsg.h +7 -0
@@ -99,4 +99,11 @@ int pretty_print_genlmsg(const struct nlmsghdr *nlhdr,const struct pretty_nlmsg_desc *desc, unsigned int ndesc, unsigned int err_offset); +/* message descriptions */ + +extern const struct pretty_nlmsg_desc ethnl_umsg_desc[]; +extern const unsigned int ethnl_umsg_n_desc; +extern const struct pretty_nlmsg_desc ethnl_kmsg_desc[]; +extern const unsigned int ethnl_kmsg_n_desc; +#endif /* ETHTOOL_NETLINK_PRETTYMSG_H__ */
Signature · 1 line
2.25.1
PATCH v2 23/25 netlink: message format descriptions for genetlink control
In reply to Michal KubecekFor the sake of completeness, add description of genetlink message formats of GENL_ID_CTRL family. We use this to get the id of "ethtool" genetlink family and "monitor" multicast group.
--- Makefile.am | 2 +- netlink/desc-genlctrl.c | 56 +++++++++++++++++++++++++++++++++++++++++ netlink/prettymsg.h | 3 +++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 netlink/desc-genlctrl.c
Makefile.am +1 -1
@@ -32,7 +32,7 @@ ethtool_SOURCES += \ netlink/monitor.c netlink/bitset.c netlink/bitset.h \ netlink/settings.c netlink/parser.c netlink/parser.h \ netlink/permaddr.c netlink/prettymsg.c netlink/prettymsg.h \ - netlink/desc-ethtool.c \ + netlink/desc-ethtool.c netlink/desc-genlctrl.c \ uapi/linux/ethtool_netlink.h \ uapi/linux/netlink.h uapi/linux/genetlink.h \ uapi/linux/rtnetlink.h uapi/linux/if_link.h
netlink/desc-genlctrl.c new file +56 -0
56 lines not on this page · raw message
netlink/prettymsg.h +3 -0
@@ -106,4 +106,7 @@ extern const unsigned int ethnl_umsg_n_desc;extern const struct pretty_nlmsg_desc ethnl_kmsg_desc[];extern const unsigned int ethnl_kmsg_n_desc; +extern const struct pretty_nlmsg_desc genlctrl_msg_desc[]; +extern const unsigned int genlctrl_msg_n_desc; +#endif /* ETHTOOL_NETLINK_PRETTYMSG_H__ */
Signature · 1 line
2.25.1
PATCH v2 24/25 netlink: message format descriptions for rtnetlink
In reply to Michal KubecekAdd description of rtnetlink message formats to be used for pretty printing infrastructure and helper function to pretty print rtnetlink messages.
As rtnetlink is quite complex and only RTM_GETLINK and RTM_NEWLINK messages are interesting for ethtool at the moment, this commit provides only names of a limited subset of rtnetlink messages and names and formats of top level attributes used in RTM_{NEW,DEL,GET,SET}LINK messages.
--- Makefile.am | 1 + netlink/desc-rtnl.c | 96 +++++++++++++++++++++++++++++++++++++++++++++ netlink/prettymsg.c | 44 +++++++++++++++++++++ netlink/prettymsg.h | 6 +++ 4 files changed, 147 insertions(+) create mode 100644 netlink/desc-rtnl.c
Makefile.am +1 -0
@@ -33,6 +33,7 @@ ethtool_SOURCES += \ netlink/settings.c netlink/parser.c netlink/parser.h \ netlink/permaddr.c netlink/prettymsg.c netlink/prettymsg.h \ netlink/desc-ethtool.c netlink/desc-genlctrl.c \ + netlink/desc-rtnl.c \ uapi/linux/ethtool_netlink.h \ uapi/linux/netlink.h uapi/linux/genetlink.h \ uapi/linux/rtnetlink.h uapi/linux/if_link.h
netlink/desc-rtnl.c new file +96 -0
96 lines not on this page · raw message
netlink/prettymsg.c +44 -0
47 lines not on this page · raw message
netlink/prettymsg.h +6 -0
@@ -98,6 +98,7 @@ struct pretty_nlmsg_desc {int pretty_print_genlmsg (const struct nlmsghdr *nlhdr,const struct pretty_nlmsg_desc *desc,unsigned int ndesc,unsigned int err_offset); +int pretty_print_rtnlmsg (const struct nlmsghdr *nlhdr,unsigned int err_offset);/* message descriptions */
@@ -109,4 +110,9 @@ extern const unsigned int ethnl_kmsg_n_desc;extern const struct pretty_nlmsg_desc genlctrl_msg_desc[];extern const unsigned int genlctrl_msg_n_desc; +extern const struct pretty_nlmsg_desc rtnl_msg_desc[]; +extern const unsigned int rtnl_msg_n_desc; +extern const unsigned short rtnl_msghdr_lengths[]; +extern const unsigned int rtnl_msghdr_n_len; +#endif /* ETHTOOL_NETLINK_PRETTYMSG_H__ */
Signature · 1 line
2.25.1
PATCH v2 25/25 netlink: use pretty printing for ethtool netlink messages
In reply to Michal KubecekIntroduce new debugging flag DEBUG_NL_PRETTY_MSG (0x10) which has two effects:
- show request messages embedded in extack error messages in human readable form; if failing attribute offset is provided, highlight the attribute
- if DEBUG_NL_MSGS is also set, show structure of all outgoing and incoming ethtool netlink messages in addition to their summary
--- internal.h | 1 + netlink/nlsock.c | 71 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 56 insertions(+), 16 deletions(-)
internal.h +1 -0
@@ -122,6 +122,7 @@ enum {DEBUG_NL_MSGS ,/* incoming/outgoing netlink messages */ DEBUG_NL_DUMP_SND ,/* dump outgoing netlink messages */ DEBUG_NL_DUMP_RCV ,/* dump incoming netlink messages */ + DEBUG_NL_PRETTY_MSG, /* pretty print of messages and errors */ };static inline bool debug_on (unsigned long debug,unsigned int bit)
netlink/nlsock.c +55 -16
156 lines not on this page · raw message
Signature · 1 line
2.25.1
John,
If you would prefer that, feel free to use v1 and I'll send the later updates as a shorter follow-up series.
Michal
Quoted 121 lines · Michal Kubecek
This series adds initial support for ethtool netlink interface provided by kernel since 5.6-rc1. The traditional ioctl interface is still supported for compatibility with older kernels. The netlink interface and message formats are documented in
Documentation/networking/ethtool-netlink.rstfile in kernel source tree.Netlink interface is preferred but ethtool falls back to ioctl if netlink interface is not available (i.e. the "ethtool" genetlink family is not registered). It also falls back if a particular command is not implemented in netlink (kernel returns
-EOPNOTSUPP). This allows new ethtool versions to work with older kernel versions while support for ethool commands is added in steps.The series aims to touch existing ioctl code as little as possible in the first phase to minimize the risk of introducing regressions. It is also possible to build ethtool without netlink support if --disable-netlink is passed to configure script. The most visible changes to existing code are
- UAPI header copies are moved to uapi/ under original names
- some variables and functions which are going to be shared with netlink code are moved fromethtool.ctocommon.candcommon.h
- args[] array inethtool.cwas rewritten to use named initializersExcept for changes to
main(), all netlink specific code is in a separate directory netlink/ and is divided into multiple files.Changes in v2:
- add support for permanent hardware addres ("ethtool -P", patch 20)
- add support for pretty printing of netlink messages (patches 21-25)
- make output of "ethtool <dev>" closer to ioctl implementation
- two more kernel uapi header copies (patch 5)
- support for rtnetlink socket and requests (needed for "ethtool -P")
- some kerneldoc style commentsMichal Kubecek (25):
move UAPI header copies to a separate directory update UAPI header copies
add --debug option to control debugging messages use named initializers in command line option list
netlink: add netlink related UAPI header files
netlink: introduce the netlink interface
netlink: message buffer and composition helpers
netlink: netlink socket wrapper and helpers
netlink: initialize ethtool netlink socket
netlink: add support for string sets
netlink: add notification monitor
move shared code into a common file
netlink: add bitset helpers
netlink: partial netlink handler for gset (no option)
netlink: support getting wake-on-lan and debugging settings
netlink: add basic command line parsing helpers
netlink: add bitset command line parser handlers
netlink: add netlink handler for sset (-s)
netlink: support tests with netlink enabled
netlink: add handler for permaddr (-P)
netlink: support for pretty printing netlink messages
netlink: message format description for ethtool netlink
netlink: message format descriptions for genetlink control
netlink: message format descriptions for rtnetlink
netlink: use pretty printing for ethtool netlink messagesMakefile.am | 31 +- common.c | 145 +++ common.h | 26 + configure.ac | 14 +- ethtool.8.in | 48 +- ethtool.c | 819 ++++++++------ internal.h | 31 +- netlink/bitset.c | 218 ++++ netlink/bitset.h | 26 + netlink/desc-ethtool.c | 139 +++ netlink/desc-genlctrl.c | 56 + netlink/desc-rtnl.c | 96 ++ netlink/extapi.h | 46 + netlink/monitor.c | 229 ++++ netlink/msgbuff.c | 255 +++++ netlink/msgbuff.h | 117 ++ netlink/netlink.c | 216 ++++ netlink/netlink.h | 87 ++ netlink/nlsock.c | 405 +++++++ netlink/nlsock.h | 45 + netlink/parser.c | 1058 ++++++++++++++++++ netlink/parser.h | 144 +++ netlink/permaddr.c | 114 ++ netlink/prettymsg.c | 237 ++++ netlink/prettymsg.h | 118 ++ netlink/settings.c | 955 ++++++++++++++++ netlink/strset.c | 297 +++++ netlink/strset.h | 25 + test-cmdline.c | 29 +- test-features.c | 11 + ethtool-copy.h => uapi/linux/ethtool.h | 17 + uapi/linux/ethtool_netlink.h | 237 ++++ uapi/linux/genetlink.h | 89 ++ uapi/linux/if_link.h | 1051 +++++++++++++++++ net_tstamp-copy.h => uapi/linux/net_tstamp.h | 27 + uapi/linux/netlink.h | 248 ++++ uapi/linux/rtnetlink.h | 777 +++++++++++++ 37 files changed, 8102 insertions(+), 381 deletions(-) create mode 100644 common.c create mode 100644 common.h create mode 100644 netlink/bitset.c create mode 100644 netlink/bitset.h create mode 100644 netlink/desc-ethtool.c create mode 100644 netlink/desc-genlctrl.c create mode 100644 netlink/desc-rtnl.c create mode 100644 netlink/extapi.h create mode 100644 netlink/monitor.c create mode 100644 netlink/msgbuff.c create mode 100644 netlink/msgbuff.h create mode 100644 netlink/netlink.c create mode 100644 netlink/netlink.h create mode 100644 netlink/nlsock.c create mode 100644 netlink/nlsock.h create mode 100644 netlink/parser.c create mode 100644 netlink/parser.h create mode 100644 netlink/permaddr.c create mode 100644 netlink/prettymsg.c create mode 100644 netlink/prettymsg.h create mode 100644 netlink/settings.c create mode 100644 netlink/strset.c
Quoted 11 lines
create mode 100644 netlink/strset.h rename ethtool-copy.h => uapi/linux/ethtool.h (99%) create mode 100644 uapi/linux/ethtool_netlink.h create mode 100644 uapi/linux/genetlink.h create mode 100644 uapi/linux/if_link.h rename net_tstamp-copy.h => uapi/linux/net_tstamp.h (84%) create mode 100644 uapi/linux/netlink.h create mode 100644 uapi/linux/rtnetlink.hSignature · 1 line
2.25.1
Just a quick check -- executing "./autogen.sh ; ./configure ; make distcheck" fails with the attached log output.
John
Signature · 2 lines
John W. Linville Someday the world will need a hero, and you [email protected] might be all we have. Be ready.
make dist-gzip am__post_remove_distdir='@:'
make[1]: Entering directory '/home/linville/git/ethtool'
make distdir-am
make[2]: Entering directory '/home/linville/git/ethtool'
if test -d "ethtool-5.4"; then find "ethtool-5.4" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -rf "ethtool-5.4" || { sleep 5 && rm -rf "ethtool-5.4"; }; else :; fi test -d "ethtool-5.4" || mkdir "ethtool-5.4"
make \
top_distdir="ethtool-5.4" distdir="ethtool-5.4" \
dist-hook
make[3]: Entering directory '/home/linville/git/ethtool'
cp ./ethtool.spec ethtool-5.4
make[3]: Leaving directory '/home/linville/git/ethtool'
test -n "" \
|| find "ethtool-5.4" -type d ! -perm -755 \
-exec chmod u+rwx,go+rx {} \; -o \ ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
! -type d ! -perm -400 -exec chmod a+r {} \; -o \
! -type d ! -perm -444 -exec /bin/sh /home/linville/git/ethtool/install-sh -c -m a+r {} {} \; \
|| chmod -R a+r "ethtool-5.4"
make[2]: Leaving directory '/home/linville/git/ethtool'
tardir=ethtool-5.4 && ${TAR-tar} chof - "$tardir" | eval GZIP= gzip --best -c >ethtool-5.4.tar.gz
make[1]: Leaving directory '/home/linville/git/ethtool'
if test -d "ethtool-5.4"; then find "ethtool-5.4" -type d ! -perm -200 -exec chmod u+w {} ';' && rm -rf "ethtool-5.4" || { sleep 5 && rm -rf "ethtool-5.4"; }; else :; fi case 'ethtool-5.4.tar.gz' in \
*.tar.gz*) \
eval GZIP= gzip --best -dc ethtool-5.4.tar.gz | ${TAR-tar} xf - ;;\
*.tar.bz2*) \
bzip2 -dc ethtool-5.4.tar.bz2 | ${TAR-tar} xf - ;;\
*.tar.lz*) \
lzip -dc ethtool-5.4.tar.lz | ${TAR-tar} xf - ;;\
*.tar.xz*) \
xz -dc ethtool-5.4.tar.xz | ${TAR-tar} xf - ;;\
*.tar.Z*) \
uncompress -c ethtool-5.4.tar.Z | ${TAR-tar} xf - ;;\
*.shar.gz*) \
eval GZIP= gzip --best -dc ethtool-5.4.shar.gz | unshar ;;\
*.zip*) \
unzip ethtool-5.4.zip ;;\
esac
chmod -R a-w ethtool-5.4
chmod u+w ethtool-5.4
mkdir ethtool-5.4/_build ethtool-5.4/_build/sub ethtool-5.4/_inst
chmod a-w ethtool-5.4
test -d ethtool-5.4/_build || exit 0; \
dc_install_base=CDPATH="${ZSH_VERSION+.}:" && cd ethtool-5.4/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,' \
&& dc_destdir="${TMPDIR-/tmp}/am-dc-$$/" \
&& am__cwd=pwd \
&& CDPATH="${ZSH_VERSION+.}:" && cd ethtool-5.4/_build/sub \
&& ../../configure \
\
\
--srcdir=../.. --prefix="$dc_install_base" \
&& make \
&& make dvi \
&& make check \
&& make install \
&& make installcheck \
&& make uninstall \
&& make distuninstallcheck_dir="$dc_install_base" \
distuninstallcheck \
&& chmod -R a-w "$dc_install_base" \
&& ({ \
(cd ../.. && umask 077 && mkdir "$dc_destdir") \
&& make DESTDIR="$dc_destdir" install \
&& make DESTDIR="$dc_destdir" uninstall \
&& make DESTDIR="$dc_destdir" \
distuninstallcheck_dir="$dc_destdir" distuninstallcheck; \
} || { rm -rf "$dc_destdir"; exit 1; }) \ && rm -rf "$dc_destdir" \
&& make dist \
&& rm -rf ethtool-5.4.tar.gz \
&& make distcleancheck \
&& cd "$am__cwd" \
|| exit 1
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking whether make supports the include directive... yes (GNU style)
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking whether gcc needs -traditional... no
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking whether <linux/types.h> defines big-endian types... yes
checking for ANSI C header files... yes
checking for socket... yes
checking for strtol... yes
checking for bash-completion directory... ${prefix}/share/bash-completion/completions
checking for pkg-config... (cached) /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for MNL... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating ethtool.spec
config.status: creating ethtool.8
config.status: creating ethtool-config.h
config.status: executing depfiles commands
make[1]: Entering directory '/home/linville/git/ethtool/ethtool-5.4/_build/sub'
make all-am
make[2]: Entering directory '/home/linville/git/ethtool/ethtool-5.4/_build/sub'
gcc -DHAVE_CONFIG_H -I. -I../.. -I./uapi -Wall -g -O2 -MT ethtool-ethtool.o -MD -MP -MF .deps/ethtool-ethtool.Tpo -c -o ethtool-ethtool.o test -f 'ethtool.c' || echo '../../'ethtool.c../../ethtool.c: In function ‘do_get_phy_tunable’:../../ethtool.c:4773:16: error: ‘ETHTOOL_PHY_EDPD’ undeclared (first use in this function); did you mean ‘ETHTOOL_PHYS_ID’?
4773 | cont.ds.id = ETHTOOL_PHY_EDPD;
| ^~~~~~~~~~~~~~~~
| ETHTOOL_PHYS_ID
../../ethtool.c:4773:16: note: each undeclared identifier is reported only once for each function it appears in
../../ethtool.c:4781:21: error: ‘ETHTOOL_PHY_EDPD_DISABLE’ undeclared (first use in this function); did you mean ‘ETHTOOL_PHY_STUNABLE’?
4781 | if (cont.msecs == ETHTOOL_PHY_EDPD_DISABLE)
| ^~~~~~~~~~~~~~~~~~~~~~~~
| ETHTOOL_PHY_STUNABLE
../../ethtool.c:4783:26: error: ‘ETHTOOL_PHY_EDPD_NO_TX’ undeclared (first use in this function)
4783 | else if (cont.msecs == ETHTOOL_PHY_EDPD_NO_TX)
| ^~~~~~~~~~~~~~~~~~~~~~
../../ethtool.c: In function ‘do_set_phy_tunable’:
../../ethtool.c:4962:25: error: ‘ETHTOOL_PHY_EDPD_DFLT_TX_MSECS’ undeclared (first use in this function)
4962 | u16 edpd_tx_interval = ETHTOOL_PHY_EDPD_DFLT_TX_MSECS;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../ethtool.c:5003:23: error: ‘ETHTOOL_PHY_EDPD_DISABLE’ undeclared (first use in this function); did you mean ‘ETHTOOL_PHY_STUNABLE’?
5003 | edpd_tx_interval = ETHTOOL_PHY_EDPD_DISABLE;
| ^~~~~~~~~~~~~~~~~~~~~~~~
| ETHTOOL_PHY_STUNABLE
../../ethtool.c:5005:23: error: ‘ETHTOOL_PHY_EDPD_NO_TX’ undeclared (first use in this function)
5005 | edpd_tx_interval = ETHTOOL_PHY_EDPD_NO_TX;
| ^~~~~~~~~~~~~~~~~~~~~~
../../ethtool.c:5053:17: error: ‘ETHTOOL_PHY_EDPD’ undeclared (first use in this function); did you mean ‘ETHTOOL_PHYS_ID’?
5053 | cont.fld.id = ETHTOOL_PHY_EDPD;
| ^~~~~~~~~~~~~~~~
| ETHTOOL_PHYS_IDmake[2]: *** [Makefile:1255: ethtool-ethtool.o] Error 1
make[2]: Leaving directory '/home/linville/git/ethtool/ethtool-5.4/_build/sub' make[1]: *** [Makefile:881: all] Error 2
make[1]: Leaving directory '/home/linville/git/ethtool/ethtool-5.4/_build/sub'
make: *** [Makefile:3670: distcheck] Error 1
Quoted 3 lines · John W. Linville
Just a quick check -- executing "./autogen.sh ; ./configure ; make distcheck" fails with the attached log output.
[...]
Quoted 2 lines
make[2]: Entering directory '
/home/linville/git/ethtool/ethtool-5.4/_build/sub'
gcc -DHAVE_CONFIG_H -I. -I../.. -I./uapi -Wall -g -O2 -MT ethtool-ethtool.o -MD -MP -MF .deps/ethtool-ethtool.Tpo -c -o ethtool-ethtool.otest -f 'ethtool.c' || echo '../../'ethtool.c
I can see what is going on: this runs in subdirectory and correctly adds "-I../.." but not "-I../../uapi". I'm afraid I'll have to dive into automake documentation to see how to make it adjust that path as well.
Quoted 5 lines
../../ethtool.c: In function ‘do_get_phy_tunable’:../../ethtool.c:4773:16: error: ‘ETHTOOL_PHY_EDPD’ undeclared (first use in this function); did you mean ‘ETHTOOL_PHYS_ID’?4773 | cont.ds.id = ETHTOOL_PHY_EDPD; | ^~~~~~~~~~~~~~~~ | ETHTOOL_PHYS_ID
This is a result of the missing include path above: instead of up-to-date uapi/linux/ethtool.h, older system file from /usr/include is used so that new additions are missing. I have many more errors like this and when I tried to rename /usr/include/linux/ethtool.h, the build failed with
../../internal.h:56:10: fatal error: linux/ethtool.h: No such file or directory
I'll try to find what is the right way to add an include directory, adding "-I./uapi" to AM_CFLAGS did the trick for regular build but clearly isn't sufficient for other targets.
Michal
Quoted 24 lines · Michal Kubecek
Quoted 3 lines · John W. Linville
Just a quick check -- executing "./autogen.sh ; ./configure ; make distcheck" fails with the attached log output.
[...]
Quoted 2 lines
make[2]: Entering directory '
/home/linville/git/ethtool/ethtool-5.4/_build/sub'
gcc -DHAVE_CONFIG_H -I. -I../.. -I./uapi -Wall -g -O2 -MT ethtool-ethtool.o -MD -MP -MF .deps/ethtool-ethtool.Tpo -c -o ethtool-ethtool.otest -f 'ethtool.c' || echo '../../'ethtool.cI can see what is going on: this runs in subdirectory and correctly adds "-I../.." but not "-I../../uapi". I'm afraid I'll have to dive into automake documentation to see how to make it adjust that path as well.
Quoted 5 lines
../../ethtool.c: In function ‘do_get_phy_tunable’:../../ethtool.c:4773:16: error: ‘ETHTOOL_PHY_EDPD’ undeclared (first use in this function); did you mean ‘ETHTOOL_PHYS_ID’?4773 | cont.ds.id = ETHTOOL_PHY_EDPD; | ^~~~~~~~~~~~~~~~ | ETHTOOL_PHYS_IDThis is a result of the missing include path above: instead of up-to-date
uapi/linux/ethtool.h, older system file from/usr/includeis used so that new additions are missing. I have many more errors like this and when I tried to rename/usr/include/linux/ethtool.h, the build failed with
Quoted 5 lines
../../internal.h:56:10: fatal error:linux/ethtool.h: No such file or directoryI'll try to find what is the right way to add an include directory, adding "-I./uapi" to
AM_CFLAGSdid the trick for regular build but clearly isn't sufficient for other targets.
The change below seems to fix the problem but I'll run some more tests tomorrow to see that it does not break anything.
Michal
Makefile.am +2 -1
@@ -1,4 +1,5 @@ -AM_CFLAGS = -I./uapi -Wall +AM_CFLAGS = -Wall +AM_CPPFLAGS = -I$(top_srcdir)/uapi LDADD = -lm man_MANS = ethtool.8