All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: Hangbin Liu <hangbin.liu@linux.dev>
Cc: David Ahern <dsahern@kernel.org>,
	Ido Schimmel <idosch@nvidia.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	Donald Hunter <donald.hunter@gmail.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	bpf@vger.kernel.org, Hangbin Liu <liuhangbin@kylinos.cn>
Subject: Re: [PATCH net-next v2 2/6] tools: ynl: convert enum selector to string for sub-message parsing
Date: Wed, 23 Sep 2026 18:14:01 -0700	[thread overview]
Message-ID: <20260923181401.41d836e2@kernel.org> (raw)
In-Reply-To: <20260920-ynl_rt_encap-v2-2-c664a3e726f6@kylinos.cn>

On Sun, 20 Sep 2026 18:06:37 +0800 Hangbin Liu wrote:
> 	const char *encap_type_str;
> 	encap_type_str = rt_route_encap_type_str(dst->encap_type);
> 	if (!encap_type_str)
> 		return ynl_submsg_failed(yarg, "encap", "encap-type");
> 	if (rt_route_encap_data_parse(&parg, encap_type_str, attr))
> 		return YNL_PARSE_CB_ERROR;

Please squash this in:

diff --git a/tools/net/ynl/pyynl/ynl_gen_c.py b/tools/net/ynl/pyynl/ynl_gen_c.py
index 785e747e5865..3b95e5d31638 100755
--- a/tools/net/ynl/pyynl/ynl_gen_c.py
+++ b/tools/net/ynl/pyynl/ynl_gen_c.py
@@ -954,14 +954,13 @@ from lib import SpecSubMessage
 
         parse_sel = sel_var
         get_lines = []
-        if not self.selector.is_external() and self.selector.attr and \
-           "enum" in self.selector.attr.attr:
-            enum_name = self.selector.attr.attr["enum"]
-            str_fn = c_lower(self.family.ident_name + "-" + enum_name) + "_str"
-            sel_str_var = f"{sel}_str"
-            get_lines += [f'const char *{sel_str_var};',
-                          f'{sel_str_var} = {str_fn}({sel_var});']
-            parse_sel = sel_str_var
+        local_vars = None
+
+        if self.selector.is_enum_val():
+            parse_sel = f"{sel}_str"
+            local_vars = [f'const char *{parse_sel};']
+            enum = self.family.consts[self.selector.get_enum_name()]
+            get_lines += [f'{parse_sel} = {enum.render_name}_str({sel_var});']
 
         get_lines += [f'if (!{parse_sel})',
                       f'return ynl_submsg_failed(yarg, "{self.name}", "{selector}");',
@@ -969,7 +968,7 @@ from lib import SpecSubMessage
                       "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:
@@ -991,6 +990,12 @@ from lib import SpecSubMessage
     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,

  reply	other threads:[~2026-09-24  1:14 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-20 10:06 [PATCH net-next v2 0/6] netlink: add lwtunnel encap sub-message support to rt-route Hangbin Liu
2026-09-20 10:06 ` [PATCH net-next v2 1/6] net: lwtunnel: change encap fill order Hangbin Liu
2026-09-20 10:06 ` [PATCH net-next v2 2/6] tools: ynl: convert enum selector to string for sub-message parsing Hangbin Liu
2026-09-24  1:14   ` Jakub Kicinski [this message]
2026-09-20 10:06 ` [PATCH net-next v2 3/6] netlink: specs: rt-route: add lwtunnel encap sub-message support Hangbin Liu
2026-09-24  1:14   ` Jakub Kicinski
2026-09-24  3:13     ` Hangbin Liu
2026-09-24 15:53       ` Jakub Kicinski
2026-09-20 10:06 ` [PATCH net-next v2 4/6] netlink: specs: rt-route: describe lwtunnel IP options Hangbin Liu
2026-09-21 10:07   ` sashiko-bot
2026-09-20 10:06 ` [PATCH net-next v2 5/6] netlink: specs: rt-route: describe lwt BPF program options Hangbin Liu
2026-09-21 10:07   ` sashiko-bot
2026-09-20 10:06 ` [PATCH net-next v2 6/6] netlink: specs: rt-route: describe seg6-local actions, counters and flavors Hangbin Liu

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=20260923181401.41d836e2@kernel.org \
    --to=kuba@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=hangbin.liu@linux.dev \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --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 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.