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, sdf@fomichev.me,
Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 04/12] tools: ynl: let classic netlink requests specify extra nlflags
Date: Wed, 23 Apr 2025 19:11:59 -0700 [thread overview]
Message-ID: <20250424021207.1167791-5-kuba@kernel.org> (raw)
In-Reply-To: <20250424021207.1167791-1-kuba@kernel.org>
Classic netlink makes extensive use of flags. Support specifying
them the same way as attributes are specified (using a helper),
for example:
rt_link_newlink_req_set_nlflags(req, NLM_F_CREATE | NLM_F_ECHO);
Wrap the code up in a RenderInfo predicate. I think that some
genetlink families may want this, too. It should be easy to
add a spec property later.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
tools/net/ynl/lib/ynl-priv.h | 2 +-
tools/net/ynl/lib/ynl.c | 4 ++--
tools/net/ynl/pyynl/ynl_gen_c.py | 21 ++++++++++++++++++++-
3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/tools/net/ynl/lib/ynl-priv.h b/tools/net/ynl/lib/ynl-priv.h
index 634eb16548b9..5debb09491e7 100644
--- a/tools/net/ynl/lib/ynl-priv.h
+++ b/tools/net/ynl/lib/ynl-priv.h
@@ -94,7 +94,7 @@ struct ynl_ntf_base_type {
unsigned char data[] __attribute__((aligned(8)));
};
-struct nlmsghdr *ynl_msg_start_req(struct ynl_sock *ys, __u32 id);
+struct nlmsghdr *ynl_msg_start_req(struct ynl_sock *ys, __u32 id, __u16 flags);
struct nlmsghdr *ynl_msg_start_dump(struct ynl_sock *ys, __u32 id);
struct nlmsghdr *
diff --git a/tools/net/ynl/lib/ynl.c b/tools/net/ynl/lib/ynl.c
index 70f899a54007..c16f01372ca3 100644
--- a/tools/net/ynl/lib/ynl.c
+++ b/tools/net/ynl/lib/ynl.c
@@ -451,9 +451,9 @@ ynl_gemsg_start(struct ynl_sock *ys, __u32 id, __u16 flags,
return nlh;
}
-struct nlmsghdr *ynl_msg_start_req(struct ynl_sock *ys, __u32 id)
+struct nlmsghdr *ynl_msg_start_req(struct ynl_sock *ys, __u32 id, __u16 flags)
{
- return ynl_msg_start(ys, id, NLM_F_REQUEST | NLM_F_ACK);
+ return ynl_msg_start(ys, id, NLM_F_REQUEST | NLM_F_ACK | flags);
}
struct nlmsghdr *ynl_msg_start_dump(struct ynl_sock *ys, __u32 id)
diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
index 569768bcf155..35a7e3ba0725 100755
--- a/tools/net/ynl/pyynl/ynl_gen_c.py
+++ b/tools/net/ynl/pyynl/ynl_gen_c.py
@@ -1296,6 +1296,9 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
def type_empty(self, key):
return len(self.struct[key].attr_list) == 0 and self.fixed_hdr is None
+ def needs_nlflags(self, direction):
+ return self.op_mode == 'do' and direction == 'request' and self.family.is_classic()
+
class CodeWriter:
def __init__(self, nlib, out_file=None, overwrite=True):
@@ -1926,7 +1929,7 @@ _C_KW = {
ri.cw.write_func_lvar(local_vars)
if ri.family.is_classic():
- ri.cw.p(f"nlh = ynl_msg_start_req(ys, {ri.op.enum_name});")
+ ri.cw.p(f"nlh = ynl_msg_start_req(ys, {ri.op.enum_name}, req->_nlmsg_flags);")
else:
ri.cw.p(f"nlh = ynl_gemsg_start_req(ys, {ri.nl.get_family_id()}, {ri.op.enum_name}, 1);")
@@ -2055,6 +2058,16 @@ _C_KW = {
ri.cw.write_func_prot('void', f"{name}_free", [f"struct {struct_name} *{arg}"], suffix=suffix)
+def print_nlflags_set(ri, direction):
+ name = op_prefix(ri, direction)
+ ri.cw.write_func_prot(f'static inline void', f"{name}_set_nlflags",
+ [f"struct {name} *req", "__u16 nl_flags"])
+ ri.cw.block_start()
+ ri.cw.p('req->_nlmsg_flags = nl_flags;')
+ ri.cw.block_end()
+ ri.cw.nl()
+
+
def _print_type(ri, direction, struct):
suffix = f'_{ri.type_name}{direction_to_suffix[direction]}'
if not direction and ri.type_name_conflict:
@@ -2065,6 +2078,9 @@ _C_KW = {
ri.cw.block_start(line=f"struct {ri.family.c_name}{suffix}")
+ if ri.needs_nlflags(direction):
+ ri.cw.p('__u16 _nlmsg_flags;')
+ ri.cw.nl()
if ri.fixed_hdr:
ri.cw.p(ri.fixed_hdr + ' _hdr;')
ri.cw.nl()
@@ -2104,6 +2120,9 @@ _C_KW = {
print_free_prototype(ri, direction)
ri.cw.nl()
+ if ri.needs_nlflags(direction):
+ print_nlflags_set(ri, direction)
+
if ri.ku_space == 'user' and direction == 'request':
for _, attr in ri.struct[direction].member_list():
attr.setter(ri, ri.attr_set, direction, deref=deref)
--
2.49.0
next prev parent reply other threads:[~2025-04-24 2:12 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-24 2:11 [PATCH net-next 00/12] tools: ynl-gen: additional C types and classic netlink handling Jakub Kicinski
2025-04-24 2:11 ` [PATCH net-next 01/12] tools: ynl-gen: fix comment about nested struct dict Jakub Kicinski
2025-04-24 15:40 ` Jacob Keller
2025-04-24 2:11 ` [PATCH net-next 02/12] tools: ynl-gen: factor out free_needs_iter for a struct Jakub Kicinski
2025-04-24 15:42 ` Jacob Keller
2025-04-24 2:11 ` [PATCH net-next 03/12] tools: ynl-gen: fill in missing empty attr lists Jakub Kicinski
2025-04-24 15:49 ` Jacob Keller
2025-04-25 2:36 ` Jakub Kicinski
2025-04-24 2:11 ` Jakub Kicinski [this message]
2025-04-24 15:51 ` [PATCH net-next 04/12] tools: ynl: let classic netlink requests specify extra nlflags Jacob Keller
2025-04-24 2:12 ` [PATCH net-next 05/12] tools: ynl-gen: support using dump types for ntf Jakub Kicinski
2025-04-24 15:51 ` Jacob Keller
2025-04-24 2:12 ` [PATCH net-next 06/12] tools: ynl-gen: support CRUD-like notifications for classic Netlink Jakub Kicinski
2025-04-24 15:52 ` Jacob Keller
2025-04-24 2:12 ` [PATCH net-next 07/12] tools: ynl-gen: multi-attr: type gen for string Jakub Kicinski
2025-04-24 15:54 ` Jacob Keller
2025-04-24 2:12 ` [PATCH net-next 08/12] tools: ynl-gen: mutli-attr: support binary types with struct Jakub Kicinski
2025-04-24 15:55 ` Jacob Keller
2025-04-24 2:12 ` [PATCH net-next 09/12] tools: ynl-gen: array-nest: support put for scalar Jakub Kicinski
2025-04-24 15:56 ` Jacob Keller
2025-04-24 2:12 ` [PATCH net-next 10/12] tools: ynl-gen: array-nest: support binary array with exact-len Jakub Kicinski
2025-04-24 15:57 ` Jacob Keller
2025-04-24 2:12 ` [PATCH net-next 11/12] tools: ynl-gen: don't init enum checks for classic netlink Jakub Kicinski
2025-04-24 15:59 ` Jacob Keller
2025-04-25 2:36 ` Jakub Kicinski
2025-04-24 2:12 ` [PATCH net-next 12/12] tools: ynl: allow fixed-header to be specified per op Jakub Kicinski
2025-04-24 16:00 ` Jacob Keller
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=20250424021207.1167791-5-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=horms@kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
/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).