From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
andrew+netdev@lunn.ch, horms@kernel.org, donald.hunter@gmail.com,
jacob.e.keller@intel.com, yuyanghuang@google.com,
sdf@fomichev.me, gnault@redhat.com, nicolas.dichtel@6wind.com,
petrm@nvidia.com, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 12/13] tools: ynl: generate code for rt-addr and add a sample
Date: Tue, 8 Apr 2025 17:03:59 -0700 [thread overview]
Message-ID: <20250409000400.492371-13-kuba@kernel.org> (raw)
In-Reply-To: <20250409000400.492371-1-kuba@kernel.org>
YNL C can now generate code for simple classic netlink families.
Include rt-addr in the Makefile for generation and add a sample.
$ ./tools/net/ynl/samples/rt-addr
lo: 127.0.0.1
wlp0s20f3: 192.168.1.101
lo: ::
wlp0s20f3: fe80::6385:be6:746e:8116
vpn0: fe80::3597:d353:b5a7:66dd
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
tools/net/ynl/Makefile.deps | 1 +
tools/net/ynl/generated/Makefile | 2 +-
tools/net/ynl/samples/rt-addr.c | 80 ++++++++++++++++++++++++++++++++
tools/net/ynl/samples/.gitignore | 3 +-
4 files changed, 84 insertions(+), 2 deletions(-)
create mode 100644 tools/net/ynl/samples/rt-addr.c
diff --git a/tools/net/ynl/Makefile.deps b/tools/net/ynl/Makefile.deps
index f3269ce39e5b..e55d94211df6 100644
--- a/tools/net/ynl/Makefile.deps
+++ b/tools/net/ynl/Makefile.deps
@@ -29,4 +29,5 @@ CFLAGS_nfsd:=$(call get_hdr_inc,_LINUX_NFSD_NETLINK_H,nfsd_netlink.h)
CFLAGS_ovs_datapath:=$(call get_hdr_inc,__LINUX_OPENVSWITCH_H,openvswitch.h)
CFLAGS_ovs_flow:=$(call get_hdr_inc,__LINUX_OPENVSWITCH_H,openvswitch.h)
CFLAGS_ovs_vport:=$(call get_hdr_inc,__LINUX_OPENVSWITCH_H,openvswitch.h)
+CFLAGS_rt-addr:=$(call get_hdr_inc,__LINUX_RTNETLINK_H,rtnetlink.h)
CFLAGS_tcp_metrics:=$(call get_hdr_inc,_LINUX_TCP_METRICS_H,tcp_metrics.h)
diff --git a/tools/net/ynl/generated/Makefile b/tools/net/ynl/generated/Makefile
index 21f9e299dc75..67ce3b8988ef 100644
--- a/tools/net/ynl/generated/Makefile
+++ b/tools/net/ynl/generated/Makefile
@@ -25,7 +25,7 @@ SPECS_DIR:=../../../../Documentation/netlink/specs
GENS_PATHS=$(shell grep -nrI --files-without-match \
'protocol: netlink' \
$(SPECS_DIR))
-GENS=$(patsubst $(SPECS_DIR)/%.yaml,%,${GENS_PATHS})
+GENS=$(patsubst $(SPECS_DIR)/%.yaml,%,${GENS_PATHS}) rt-addr
SRCS=$(patsubst %,%-user.c,${GENS})
HDRS=$(patsubst %,%-user.h,${GENS})
OBJS=$(patsubst %,%-user.o,${GENS})
diff --git a/tools/net/ynl/samples/rt-addr.c b/tools/net/ynl/samples/rt-addr.c
new file mode 100644
index 000000000000..c9a6436ad420
--- /dev/null
+++ b/tools/net/ynl/samples/rt-addr.c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <stdio.h>
+#include <string.h>
+
+#include <ynl.h>
+
+#include <arpa/inet.h>
+#include <net/if.h>
+
+#include "rt-addr-user.h"
+
+static void rt_addr_print(struct rt_addr_getaddr_rsp *a, unsigned int op)
+{
+ char ifname[IF_NAMESIZE];
+ char addr_str[64];
+ const char *addr;
+ const char *name;
+
+ name = if_indextoname(a->_hdr.ifa_index, ifname);
+ if (name)
+ printf("%16s: ", name);
+
+ switch (a->_present.address_len) {
+ case 4:
+ addr = inet_ntop(AF_INET, a->address,
+ addr_str, sizeof(addr_str));
+ break;
+ case 16:
+ addr = inet_ntop(AF_INET6, a->address,
+ addr_str, sizeof(addr_str));
+ break;
+ default:
+ addr = NULL;
+ break;
+ }
+ if (addr)
+ printf("%s", addr);
+ else
+ printf("[%d]", a->_present.address_len);
+
+ printf("\n");
+}
+
+int main(int argc, char **argv)
+{
+ struct rt_addr_getaddr_list *rsp;
+ struct rt_addr_getaddr_req *req;
+ struct ynl_error yerr;
+ struct ynl_sock *ys;
+
+ ys = ynl_sock_create(&ynl_rt_addr_family, &yerr);
+ if (!ys) {
+ fprintf(stderr, "YNL: %s\n", yerr.msg);
+ return 1;
+ }
+
+ req = rt_addr_getaddr_req_alloc();
+ if (!req)
+ goto err_destroy;
+
+ rsp = rt_addr_getaddr_dump(ys, req);
+ rt_addr_getaddr_req_free(req);
+ if (!rsp)
+ goto err_close;
+
+ if (ynl_dump_empty(rsp))
+ fprintf(stderr, "Error: no addresses reported\n");
+ ynl_dump_foreach(rsp, addr)
+ rt_addr_print(addr, 0);
+ rt_addr_getaddr_list_free(rsp);
+
+ ynl_sock_destroy(ys);
+ return 0;
+
+err_close:
+ fprintf(stderr, "YNL: %s\n", ys->err.msg);
+err_destroy:
+ ynl_sock_destroy(ys);
+ return 2;
+}
diff --git a/tools/net/ynl/samples/.gitignore b/tools/net/ynl/samples/.gitignore
index dda6686257a7..2bc8721d6144 100644
--- a/tools/net/ynl/samples/.gitignore
+++ b/tools/net/ynl/samples/.gitignore
@@ -2,4 +2,5 @@ ethtool
devlink
netdev
ovs
-page-pool
\ No newline at end of file
+page-pool
+rt-addr
--
2.49.0
next prev parent reply other threads:[~2025-04-09 0:04 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-09 0:03 [PATCH net-next 00/13] tools: ynl: c: basic netlink-raw support Jakub Kicinski
2025-04-09 0:03 ` [PATCH net-next 01/13] netlink: specs: rename rtnetlink specs in accordance with family name Jakub Kicinski
2025-04-09 4:49 ` Jacob Keller
2025-04-09 12:15 ` Donald Hunter
2025-04-09 14:15 ` Jakub Kicinski
2025-04-09 14:36 ` Donald Hunter
2025-04-09 0:03 ` [PATCH net-next 02/13] netlink: specs: rt-route: specify fixed-header at operations level Jakub Kicinski
2025-04-09 4:50 ` Jacob Keller
2025-04-09 12:16 ` Donald Hunter
2025-04-09 0:03 ` [PATCH net-next 03/13] netlink: specs: rt-addr: remove the fixed members from attrs Jakub Kicinski
2025-04-09 4:53 ` Jacob Keller
2025-04-09 4:58 ` Jacob Keller
2025-04-09 12:19 ` Donald Hunter
2025-04-09 0:03 ` [PATCH net-next 04/13] netlink: specs: rt-route: " Jakub Kicinski
2025-04-09 4:58 ` Jacob Keller
2025-04-09 12:20 ` Donald Hunter
2025-04-09 0:03 ` [PATCH net-next 05/13] netlink: specs: rt-addr: add C naming info Jakub Kicinski
2025-04-09 4:54 ` Jacob Keller
2025-04-09 12:21 ` Donald Hunter
2025-04-09 0:03 ` [PATCH net-next 06/13] netlink: specs: rt-route: " Jakub Kicinski
2025-04-09 4:54 ` Jacob Keller
2025-04-09 12:21 ` Donald Hunter
2025-04-09 0:03 ` [PATCH net-next 07/13] tools: ynl: support creating non-genl sockets Jakub Kicinski
2025-04-09 4:56 ` Jacob Keller
2025-04-09 12:25 ` Donald Hunter
2025-04-09 0:03 ` [PATCH net-next 08/13] tools: ynl-gen: don't consider requests with fixed hdr empty Jakub Kicinski
2025-04-09 4:57 ` Jacob Keller
2025-04-09 0:03 ` [PATCH net-next 09/13] tools: ynl: don't use genlmsghdr in classic netlink Jakub Kicinski
2025-04-09 4:59 ` Jacob Keller
2025-04-09 12:26 ` Donald Hunter
2025-04-09 0:03 ` [PATCH net-next 10/13] tools: ynl-gen: consider dump ops without a do "type-consistent" Jakub Kicinski
2025-04-09 5:01 ` Jacob Keller
2025-04-09 12:38 ` Donald Hunter
2025-04-09 13:52 ` Jakub Kicinski
2025-04-09 21:58 ` Jacob Keller
2025-04-09 0:03 ` [PATCH net-next 11/13] tools: ynl-gen: use family c-name in notifications Jakub Kicinski
2025-04-09 5:01 ` Jacob Keller
2025-04-09 12:38 ` Donald Hunter
2025-04-09 0:03 ` Jakub Kicinski [this message]
2025-04-09 5:04 ` [PATCH net-next 12/13] tools: ynl: generate code for rt-addr and add a sample Jacob Keller
2025-04-09 15:01 ` Jakub Kicinski
2025-04-09 12:50 ` Donald Hunter
2025-04-09 0:04 ` [PATCH net-next 13/13] tools: ynl: generate code for rt-route " Jakub Kicinski
2025-04-09 5:05 ` Jacob Keller
2025-04-09 12:49 ` Donald Hunter
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=20250409000400.492371-13-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=gnault@redhat.com \
--cc=horms@kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.com \
--cc=sdf@fomichev.me \
--cc=yuyanghuang@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.