From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
sdf@google.com, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 12/12] tools: ynl: add sample for ethtool
Date: Fri, 9 Jun 2023 14:43:46 -0700 [thread overview]
Message-ID: <20230609214346.1605106-13-kuba@kernel.org> (raw)
In-Reply-To: <20230609214346.1605106-1-kuba@kernel.org>
Configuring / reading ring sizes and counts is a fairly common
operation for ethtool netlink. Present a sample doing that with
YNL:
$ ./ethtool
Channels:
enp1s0: combined 1
eni1np1: combined 1
eni2np1: combined 1
Rings:
enp1s0: rx 256 tx 256
eni1np1: rx 0 tx 0
eni2np1: rx 0 tx 0
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
tools/net/ynl/samples/.gitignore | 1 +
tools/net/ynl/samples/ethtool.c | 65 ++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+)
create mode 100644 tools/net/ynl/samples/ethtool.c
diff --git a/tools/net/ynl/samples/.gitignore b/tools/net/ynl/samples/.gitignore
index a24678b67557..2aae60c4829f 100644
--- a/tools/net/ynl/samples/.gitignore
+++ b/tools/net/ynl/samples/.gitignore
@@ -1,2 +1,3 @@
+ethtool
devlink
netdev
diff --git a/tools/net/ynl/samples/ethtool.c b/tools/net/ynl/samples/ethtool.c
new file mode 100644
index 000000000000..a7ebbd1b98db
--- /dev/null
+++ b/tools/net/ynl/samples/ethtool.c
@@ -0,0 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdio.h>
+#include <string.h>
+
+#include <ynl.h>
+
+#include <net/if.h>
+
+#include "ethtool-user.h"
+
+int main(int argc, char **argv)
+{
+ struct ethtool_channels_get_req_dump creq = {};
+ struct ethtool_rings_get_req_dump rreq = {};
+ struct ethtool_channels_get_list *channels;
+ struct ethtool_rings_get_list *rings;
+ struct ynl_sock *ys;
+
+ ys = ynl_sock_create(&ynl_ethtool_family, NULL);
+ if (!ys)
+ return 1;
+
+ creq._present.header = 1; /* ethtool needs an empty nest, sigh */
+ channels = ethtool_channels_get_dump(ys, &creq);
+ if (!channels)
+ goto err_close;
+
+ printf("Channels:\n");
+ ynl_dump_foreach(channels, dev) {
+ printf(" %8s: ", dev->header.dev_name);
+ if (dev->_present.rx_count)
+ printf("rx %d ", dev->rx_count);
+ if (dev->_present.tx_count)
+ printf("tx %d ", dev->tx_count);
+ if (dev->_present.combined_count)
+ printf("combined %d ", dev->combined_count);
+ printf("\n");
+ }
+ ethtool_channels_get_list_free(channels);
+
+ rreq._present.header = 1; /* ethtool needs an empty nest.. */
+ rings = ethtool_rings_get_dump(ys, &rreq);
+ if (!rings)
+ goto err_close;
+
+ printf("Rings:\n");
+ ynl_dump_foreach(rings, dev) {
+ printf(" %8s: ", dev->header.dev_name);
+ if (dev->_present.rx)
+ printf("rx %d ", dev->rx);
+ if (dev->_present.tx)
+ printf("tx %d ", dev->tx);
+ printf("\n");
+ }
+ ethtool_rings_get_list_free(rings);
+
+ ynl_sock_destroy(ys);
+
+ return 0;
+
+err_close:
+ fprintf(stderr, "YNL (%d): %s\n", ys->err.code, ys->err.msg);
+ ynl_sock_destroy(ys);
+ return 2;
+}
--
2.40.1
next prev parent reply other threads:[~2023-06-09 21:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-09 21:43 [PATCH net-next 00/12] tools: ynl: generate code for the ethtool family Jakub Kicinski
2023-06-09 21:43 ` [PATCH net-next 01/12] tools: ynl-gen: support excluding tricky ops Jakub Kicinski
2023-06-09 21:43 ` [PATCH net-next 02/12] tools: ynl-gen: record extra args for regen Jakub Kicinski
2023-06-09 21:43 ` [PATCH net-next 03/12] netlink: specs: support setting prefix-name per attribute Jakub Kicinski
2023-06-09 21:43 ` [PATCH net-next 04/12] netlink: specs: ethtool: add C render hints Jakub Kicinski
2023-06-09 21:43 ` [PATCH net-next 05/12] tools: ynl-gen: don't generate enum types if unnamed Jakub Kicinski
2023-06-09 21:43 ` [PATCH net-next 06/12] tools: ynl-gen: resolve enum vs struct name conflicts Jakub Kicinski
2023-06-09 21:43 ` [PATCH net-next 07/12] netlink: specs: ethtool: add empty enum stringset Jakub Kicinski
2023-06-09 21:43 ` [PATCH net-next 08/12] netlink: specs: ethtool: untangle UDP tunnels and cable test a bit Jakub Kicinski
2023-06-09 21:43 ` [PATCH net-next 09/12] netlink: specs: ethtool: untangle stats-get Jakub Kicinski
2023-06-09 21:43 ` [PATCH net-next 10/12] netlink: specs: ethtool: mark pads as pads Jakub Kicinski
2023-06-09 21:43 ` [PATCH net-next 11/12] tools: ynl: generate code for the ethtool family Jakub Kicinski
2023-06-09 21:43 ` Jakub Kicinski [this message]
2023-06-09 22:12 ` [PATCH net-next 00/12] " Stanislav Fomichev
2023-06-12 10:10 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230609214346.1605106-13-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).