diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:27:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:27:49 +0000 |
commit | ace9429bb58fd418f0c81d4c2835699bddf6bde6 (patch) | |
tree | b2d64bc10158fdd5497876388cd68142ca374ed3 /tools/net/ynl/samples/ethtool.c | |
parent | Initial commit. (diff) | |
download | linux-ace9429bb58fd418f0c81d4c2835699bddf6bde6.tar.xz linux-ace9429bb58fd418f0c81d4c2835699bddf6bde6.zip |
Adding upstream version 6.6.15.upstream/6.6.15
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/net/ynl/samples/ethtool.c')
-rw-r--r-- | tools/net/ynl/samples/ethtool.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tools/net/ynl/samples/ethtool.c b/tools/net/ynl/samples/ethtool.c new file mode 100644 index 0000000000..a7ebbd1b98 --- /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; +} |