diff options
author | Jakub Kicinski <kuba@kernel.org> | 2023-06-07 22:24:03 +0200 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2023-06-08 23:01:10 +0200 |
commit | fff8660b5425bb2f441d67758926df62e61a69aa (patch) | |
tree | 181da6c9a1479e29c0d4c60d0b21e4462209523c /tools/net | |
parent | tools: ynl: generate code for the devlink family (diff) | |
download | linux-fff8660b5425bb2f441d67758926df62e61a69aa.tar.xz linux-fff8660b5425bb2f441d67758926df62e61a69aa.zip |
tools: ynl: add sample for devlink
Add a sample to show off how to issue basic devlink requests.
For added testing issue get requests while walking a dump.
$ ./devlink
netdevsim/netdevsim1:
driver: netdevsim
running fw:
fw.mgmt: 10.20.30
...
netdevsim/netdevsim2:
driver: netdevsim
running fw:
fw.mgmt: 10.20.30
...
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/net')
-rw-r--r-- | tools/net/ynl/samples/.gitignore | 1 | ||||
-rw-r--r-- | tools/net/ynl/samples/devlink.c | 60 |
2 files changed, 61 insertions, 0 deletions
diff --git a/tools/net/ynl/samples/.gitignore b/tools/net/ynl/samples/.gitignore index 7b1f5179cb54..a24678b67557 100644 --- a/tools/net/ynl/samples/.gitignore +++ b/tools/net/ynl/samples/.gitignore @@ -1 +1,2 @@ +devlink netdev diff --git a/tools/net/ynl/samples/devlink.c b/tools/net/ynl/samples/devlink.c new file mode 100644 index 000000000000..d2611d7ebab4 --- /dev/null +++ b/tools/net/ynl/samples/devlink.c @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <stdio.h> +#include <string.h> + +#include <ynl.h> + +#include "devlink-user.h" + +int main(int argc, char **argv) +{ + struct devlink_get_list *devs; + struct ynl_sock *ys; + + ys = ynl_sock_create(&ynl_devlink_family, NULL); + if (!ys) + return 1; + + devs = devlink_get_dump(ys); + if (!devs) + goto err_close; + + ynl_dump_foreach(devs, d) { + struct devlink_info_get_req *info_req; + struct devlink_info_get_rsp *info_rsp; + + printf("%s/%s:\n", d->bus_name, d->dev_name); + + info_req = devlink_info_get_req_alloc(); + devlink_info_get_req_set_bus_name(info_req, d->bus_name); + devlink_info_get_req_set_dev_name(info_req, d->dev_name); + + info_rsp = devlink_info_get(ys, info_req); + devlink_info_get_req_free(info_req); + if (!info_rsp) + goto err_free_devs; + + if (info_rsp->_present.info_driver_name_len) + printf(" driver: %s\n", info_rsp->info_driver_name); + if (info_rsp->n_info_version_running) + printf(" running fw:\n"); + for (unsigned i = 0; i < info_rsp->n_info_version_running; i++) + printf(" %s: %s\n", + info_rsp->info_version_running[i].info_version_name, + info_rsp->info_version_running[i].info_version_value); + printf(" ...\n"); + devlink_info_get_rsp_free(info_rsp); + } + devlink_get_list_free(devs); + + ynl_sock_destroy(ys); + + return 0; + +err_free_devs: + devlink_get_list_free(devs); +err_close: + fprintf(stderr, "YNL: %s\n", ys->err.msg); + ynl_sock_destroy(ys); + return 2; +} |