aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Kubecek <mkubecek@suse.cz>2020-05-29 01:22:02 +0200
committerMichal Kubecek <mkubecek@suse.cz>2020-06-07 19:11:06 +0200
commite4c424e046c26af77e4cce56494ba51d17112eb9 (patch)
tree143d28e433bf0cbd729730b748a25a0fc21e0ae9
parent99a46916838dd379f7f554fa83a96079221bd0db (diff)
downloadethtool-e4c424e046c26af77e4cce56494ba51d17112eb9.tar.gz
netlink: add netlink handler for gring (-g)
Implement "ethtool -g <dev>" subcommand using ETHTOOL_MSG_RINGS_GET netlink message. This retrieves and displays device ring sizes, traditionally provided by ETHTOOL_GRINGPARAM ioctl request. Also register the callback with monitor code so that the monitor can display ETHTOOL_MSG_RINGS_NTF notifications. Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
-rw-r--r--Makefile.am2
-rw-r--r--ethtool.c1
-rw-r--r--netlink/extapi.h2
-rw-r--r--netlink/monitor.c8
-rw-r--r--netlink/netlink.h13
-rw-r--r--netlink/rings.c71
6 files changed, 96 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index 0a4c4e8..f7d7b44 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -31,7 +31,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/features.c netlink/privflags.c \
+ netlink/features.c netlink/privflags.c netlink/rings.c \
netlink/desc-ethtool.c netlink/desc-genlctrl.c \
netlink/desc-rtnl.c \
uapi/linux/ethtool_netlink.h \
diff --git a/ethtool.c b/ethtool.c
index 81472ad..fc3fb11 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -5199,6 +5199,7 @@ static const struct option args[] = {
{
.opts = "-g|--show-ring",
.func = do_gring,
+ .nlfunc = nl_gring,
.help = "Query RX/TX ring parameters"
},
{
diff --git a/netlink/extapi.h b/netlink/extapi.h
index ec5d086..3b3579d 100644
--- a/netlink/extapi.h
+++ b/netlink/extapi.h
@@ -24,6 +24,7 @@ int nl_gfeatures(struct cmd_context *ctx);
int nl_sfeatures(struct cmd_context *ctx);
int nl_gprivflags(struct cmd_context *ctx);
int nl_sprivflags(struct cmd_context *ctx);
+int nl_gring(struct cmd_context *ctx);
int nl_monitor(struct cmd_context *ctx);
void nl_monitor_usage(void);
@@ -52,6 +53,7 @@ static inline void nl_monitor_usage(void)
#define nl_sfeatures NULL
#define nl_gprivflags NULL
#define nl_sprivflags NULL
+#define nl_gring NULL
#endif /* ETHTOOL_ENABLE_NETLINK */
diff --git a/netlink/monitor.c b/netlink/monitor.c
index ca2654b..c89e613 100644
--- a/netlink/monitor.c
+++ b/netlink/monitor.c
@@ -39,6 +39,10 @@ static struct {
.cmd = ETHTOOL_MSG_PRIVFLAGS_NTF,
.cb = privflags_reply_cb,
},
+ {
+ .cmd = ETHTOOL_MSG_RINGS_NTF,
+ .cb = rings_reply_cb,
+ },
};
static void clear_filter(struct nl_context *nlctx)
@@ -118,6 +122,10 @@ static struct monitor_option monitor_opts[] = {
.pattern = "--show-priv-flags|--set-priv-flags",
.cmd = ETHTOOL_MSG_PRIVFLAGS_NTF,
},
+ {
+ .pattern = "-g|--show-ring|-G|--set-ring",
+ .cmd = ETHTOOL_MSG_RINGS_NTF,
+ },
};
static bool pattern_match(const char *s, const char *pattern)
diff --git a/netlink/netlink.h b/netlink/netlink.h
index 2e90dbe..fe68e23 100644
--- a/netlink/netlink.h
+++ b/netlink/netlink.h
@@ -64,6 +64,19 @@ int wol_reply_cb(const struct nlmsghdr *nlhdr, void *data);
int debug_reply_cb(const struct nlmsghdr *nlhdr, void *data);
int features_reply_cb(const struct nlmsghdr *nlhdr, void *data);
int privflags_reply_cb(const struct nlmsghdr *nlhdr, void *data);
+int rings_reply_cb(const struct nlmsghdr *nlhdr, void *data);
+
+/* dump helpers */
+
+static inline void show_u32(const struct nlattr *attr, const char *label)
+{
+ if (attr)
+ printf("%s%u\n", label, mnl_attr_get_u32(attr));
+ else
+ printf("%sn/a\n", label);
+}
+
+/* misc */
static inline void copy_devname(char *dst, const char *src)
{
diff --git a/netlink/rings.c b/netlink/rings.c
new file mode 100644
index 0000000..98ee5db
--- /dev/null
+++ b/netlink/rings.c
@@ -0,0 +1,71 @@
+/*
+ * rings.c - netlink implementation of ring commands
+ *
+ * Implementation of "ethtool -g <dev>"
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "../internal.h"
+#include "../common.h"
+#include "netlink.h"
+
+/* RINGS_GET */
+
+int rings_reply_cb(const struct nlmsghdr *nlhdr, void *data)
+{
+ const struct nlattr *tb[ETHTOOL_A_RINGS_MAX + 1] = {};
+ DECLARE_ATTR_TB_INFO(tb);
+ struct nl_context *nlctx = data;
+ bool silent;
+ int err_ret;
+ int ret;
+
+ silent = nlctx->is_dump || nlctx->is_monitor;
+ err_ret = silent ? MNL_CB_OK : MNL_CB_ERROR;
+ ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info);
+ if (ret < 0)
+ return err_ret;
+ nlctx->devname = get_dev_name(tb[ETHTOOL_A_RINGS_HEADER]);
+ if (!dev_ok(nlctx))
+ return err_ret;
+
+ if (silent)
+ putchar('\n');
+ printf("Ring parameters for %s:\n", nlctx->devname);
+ printf("Pre-set maximums:\n");
+ show_u32(tb[ETHTOOL_A_RINGS_RX_MAX], "RX:\t\t");
+ show_u32(tb[ETHTOOL_A_RINGS_RX_MINI_MAX], "RX Mini:\t");
+ show_u32(tb[ETHTOOL_A_RINGS_RX_JUMBO_MAX], "RX Jumbo:\t");
+ show_u32(tb[ETHTOOL_A_RINGS_TX_MAX], "TX:\t\t");
+ printf("Current hardware settings:\n");
+ show_u32(tb[ETHTOOL_A_RINGS_RX], "RX:\t\t");
+ show_u32(tb[ETHTOOL_A_RINGS_RX_MINI], "RX Mini:\t");
+ show_u32(tb[ETHTOOL_A_RINGS_RX_JUMBO], "RX Jumbo:\t");
+ show_u32(tb[ETHTOOL_A_RINGS_TX], "TX:\t\t");
+
+ return MNL_CB_OK;
+}
+
+int nl_gring(struct cmd_context *ctx)
+{
+ struct nl_context *nlctx = ctx->nlctx;
+ struct nl_socket *nlsk = nlctx->ethnl_socket;
+ int ret;
+
+ if (netlink_cmd_check(ctx, ETHTOOL_MSG_RINGS_GET, true))
+ return -EOPNOTSUPP;
+ if (ctx->argc > 0) {
+ fprintf(stderr, "ethtool: unexpected parameter '%s'\n",
+ *ctx->argp);
+ return 1;
+ }
+
+ ret = nlsock_prep_get_request(nlsk, ETHTOOL_MSG_RINGS_GET,
+ ETHTOOL_A_RINGS_HEADER, 0);
+ if (ret < 0)
+ return ret;
+ return nlsock_send_get_request(nlsk, rings_reply_cb);
+}