From: Hangbin Liu <hangbin.liu@linux.dev>
To: David Ahern <dsahern@kernel.org>,
Ido Schimmel <idosch@nvidia.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Donald Hunter <donald.hunter@gmail.com>,
Eric Dumazet <edumazet@kernel.org>,
Eric Dumazet <edumazet@kernel.org>
Cc: Hangbin Liu <hangbin.liu@linux.dev>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, Hangbin Liu <liuhangbin@kylinos.cn>
Subject: [PATCH net-next v4 2/6] tools: ynl: convert enum selector to string for sub-message parsing
Date: Thu, 08 Oct 2026 16:24:02 +0800 [thread overview]
Message-ID: <20261008-ynl_rt_encap-v4-2-4ed2ccf7f949@kylinos.cn> (raw)
In-Reply-To: <20261008-ynl_rt_encap-v4-0-4ed2ccf7f949@kylinos.cn>
From: Hangbin Liu <liuhangbin@kylinos.cn>
YNL sub-message parsing expects a string selector for strcmp(). So for
non-external enum selectors, convert the integer value to its string form
via the family's {enum}_str() helper. This enables correct decoding of
sub-messages keyed by enum values.
After the change, if there is no encap_type (e.g. previous ordering on
older kernels), or a new encap_type is missing from the spec file in
future kernel, the code will report "Sub-message key not set", the same
with string lookup fails. With the subsequent rt-route encap spec update,
the newly generated code will look like:
if (!dst->_present.encap_type)
return ynl_submsg_failed(yarg, "encap", "encap-type");
encap_type_str = rt_route_encap_type_str(dst->encap_type);
if (!encap_type_str)
return ynl_submsg_failed(yarg, "encap", "enum-lookup-failed");
if (rt_route_encap_data_parse(&parg, encap_type_str, attr))
return YNL_PARSE_CB_ERROR;
Signed-off-by: Hangbin Liu <liuhangbin@kylinos.cn>
---
For sashiko:
1. For the extack error-walking path in ynl.c that doesn't handle
enum-keyed selectors. This series doesn't modify ynl.c, it changes
the code generator to emit the _str() conversion in generated parsing
code. The run time error-walking path is a separate concern.
Since rt-route encap is the first enum-keyed sub-message in the YNL
specs, this is a new limitation rather than a regression in existing
functionality. It can be addressed as a follow-up patch to ynl.c.
2. For the selector byte-order issue. This doesn't affect the current
series. The encap-type selector is type: u16 with no byte-order
specified (native order), so the raw value passed to _str() is already
host-order. nftables is in GENS_UNSUP today, so no in-tree generated
family hits this yet. We address this as a follow-up.
---
tools/net/ynl/pyynl/ynl_gen_c.py | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
index 15c79849c609..4aca51396a9e 100755
--- a/tools/net/ynl/pyynl/ynl_gen_c.py
+++ b/tools/net/ynl/pyynl/ynl_gen_c.py
@@ -951,13 +951,31 @@ class TypeSubMessage(TypeNest):
sel_var = f"_sel_{sel}"
else:
sel_var = f"{var}->{sel}"
- get_lines = [f'if (!{sel_var})',
- f'return ynl_submsg_failed(yarg, "{self.name}", "{selector}");',
- f"if ({self.nested_render_name}_parse(&parg, {sel_var}, attr))",
- "return YNL_PARSE_CB_ERROR;"]
+
+ local_vars = None
+
+ if self.selector.is_enum_val() and not self.selector.is_external():
+ enum = self.family.consts[self.selector.get_enum_name()]
+ pres_var = f"{var}->_present.{sel}"
+ parse_sel = f"{sel}_str"
+ local_vars = [f'const char *{parse_sel};']
+
+ get_lines = [
+ f'if (!{pres_var})',
+ f'return ynl_submsg_failed(yarg, "{self.name}", "{selector}");',
+ f'{parse_sel} = {enum.render_name}_str({sel_var});',
+ f'if (!{parse_sel})',
+ f'return ynl_submsg_failed(yarg, "{self.name}", "enum-lookup-failed");']
+ else:
+ parse_sel = sel_var
+ get_lines = [f'if (!{parse_sel})',
+ f'return ynl_submsg_failed(yarg, "{self.name}", "{selector}");']
+
+ get_lines += [f"if ({self.nested_render_name}_parse(&parg, {parse_sel}, attr))",
+ "return YNL_PARSE_CB_ERROR;"]
init_lines = [f"parg.rsp_policy = &{self.nested_render_name}_nest;",
f"parg.data = &{var}->{self.c_name};"]
- return get_lines, init_lines, None
+ return get_lines, init_lines, local_vars
class Selector:
@@ -979,6 +997,12 @@ class Selector:
def is_external(self):
return self._external
+ def is_enum_val(self):
+ return self.get_enum_name() is not None
+
+ def get_enum_name(self):
+ return self.attr and self.attr.attr.get("enum")
+
class Struct:
def __init__(self, family, space_name, type_list=None, fixed_header=None,
--
2.55.0
next prev parent reply other threads:[~2026-10-08 8:24 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 8:24 [PATCH net-next v4 0/6] netlink: add lwtunnel encap sub-message support to rt-route Hangbin Liu
2026-10-08 8:24 ` [PATCH net-next v4 1/6] net: lwtunnel: change encap fill order Hangbin Liu
2026-10-08 8:24 ` Hangbin Liu [this message]
2026-10-09 9:06 ` [PATCH net-next v4 2/6] tools: ynl: convert enum selector to string for sub-message parsing netdev-bot+sashiko
2026-10-09 9:40 ` Hangbin Liu
2026-10-08 8:24 ` [PATCH net-next v4 3/6] netlink: specs: rt-route: add lwtunnel encap sub-message support Hangbin Liu
2026-10-09 9:06 ` netdev-bot+sashiko
2026-10-08 8:24 ` [PATCH net-next v4 4/6] netlink: specs: rt-route: describe lwtunnel IP options Hangbin Liu
2026-10-09 9:07 ` netdev-bot+sashiko
2026-10-09 9:44 ` Hangbin Liu
2026-10-08 8:24 ` [PATCH net-next v4 5/6] netlink: specs: rt-route: describe lwt BPF program options Hangbin Liu
2026-10-08 8:24 ` [PATCH net-next v4 6/6] netlink: specs: rt-route: describe seg6-local attrs Hangbin Liu
2026-10-09 9:07 ` netdev-bot+sashiko
2026-10-16 0:10 ` [PATCH net-next v4 0/6] netlink: add lwtunnel encap sub-message support to rt-route 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=20261008-ynl_rt_encap-v4-2-4ed2ccf7f949@kylinos.cn \
--to=hangbin.liu@linux.dev \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liuhangbin@kylinos.cn \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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
all inboxes | Powered by JetHome®