From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 1/3] tools: ynl-gen: make the mnl_type() method public
Date: Wed, 18 Oct 2023 14:39:19 -0700 [thread overview]
Message-ID: <20231018213921.2694459-2-kuba@kernel.org> (raw)
In-Reply-To: <20231018213921.2694459-1-kuba@kernel.org>
uint/sint support will add more logic to mnl_type(),
deduplicate it and make it more accessible.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
tools/net/ynl/ynl-gen-c.py | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index 552ba49a444c..6f4c538bda9a 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -159,6 +159,15 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
spec = self._attr_policy(policy)
cw.p(f"\t[{self.enum_name}] = {spec},")
+ def _mnl_type(self):
+ # mnl does not have helpers for signed integer types
+ # turn signed type into unsigned
+ # this only makes sense for scalar types
+ t = self.type
+ if t[0] == 's':
+ t = 'u' + t[1:]
+ return t
+
def _attr_typol(self):
raise Exception(f"Type policy not implemented for class type {self.type}")
@@ -329,12 +338,8 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
else:
self.type_name = '__' + self.type
- def _mnl_type(self):
- t = self.type
- # mnl does not have a helper for signed types
- if t[0] == 's':
- t = 'u' + t[1:]
- return t
+ def mnl_type(self):
+ return self._mnl_type()
def _attr_policy(self, policy):
if 'flags-mask' in self.checks or self.is_bitfield:
@@ -363,10 +368,10 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
return [f'{self.type_name} {self.c_name}{self.byte_order_comment}']
def attr_put(self, ri, var):
- self._attr_put_simple(ri, var, self._mnl_type())
+ self._attr_put_simple(ri, var, self.mnl_type())
def _attr_get(self, ri, var):
- return f"{var}->{self.c_name} = mnl_attr_get_{self._mnl_type()}(attr);", None, None
+ return f"{var}->{self.c_name} = mnl_attr_get_{self.mnl_type()}(attr);", None, None
def _setter_lines(self, ri, member, presence):
return [f"{member} = {self.c_name};"]
@@ -524,12 +529,8 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
def presence_type(self):
return 'count'
- def _mnl_type(self):
- t = self.type
- # mnl does not have a helper for signed types
- if t[0] == 's':
- t = 'u' + t[1:]
- return t
+ def mnl_type(self):
+ return self._mnl_type()
def _complex_member_type(self, ri):
if 'type' not in self.attr or self.attr['type'] == 'nest':
@@ -564,7 +565,7 @@ from lib import SpecFamily, SpecAttrSet, SpecAttr, SpecOperation, SpecEnumSet, S
def attr_put(self, ri, var):
if self.attr['type'] in scalars:
- put_type = self._mnl_type()
+ put_type = self.mnl_type()
ri.cw.p(f"for (unsigned int i = 0; i < {var}->n_{self.c_name}; i++)")
ri.cw.p(f"mnl_attr_put_{put_type}(nlh, {self.enum_name}, {var}->{self.c_name}[i]);")
elif 'type' not in self.attr or self.attr['type'] == 'nest':
@@ -1580,11 +1581,8 @@ _C_KW = {
ri.cw.p(f"parg.data = &dst->{aspec.c_name}[i];")
ri.cw.p(f"if ({aspec.nested_render_name}_parse(&parg, attr))")
ri.cw.p('return MNL_CB_ERROR;')
- elif aspec['type'] in scalars:
- t = aspec['type']
- if t[0] == 's':
- t = 'u' + t[1:]
- ri.cw.p(f"dst->{aspec.c_name}[i] = mnl_attr_get_{t}(attr);")
+ elif aspec.type in scalars:
+ ri.cw.p(f"dst->{aspec.c_name}[i] = mnl_attr_get_{aspec.mnl_type()}(attr);")
else:
raise Exception('Nest parsing type not supported yet')
ri.cw.p('i++;')
--
2.41.0
next prev parent reply other threads:[~2023-10-18 21:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-18 21:39 [PATCH net-next 0/3] netlink: add variable-length / auto integers Jakub Kicinski
2023-10-18 21:39 ` Jakub Kicinski [this message]
2023-10-18 21:39 ` [PATCH net-next 2/3] " Jakub Kicinski
2023-10-20 7:24 ` Nicolas Dichtel
2023-10-18 21:39 ` [PATCH net-next 3/3] netlink: specs: add support for auto-sized scalars Jakub Kicinski
2023-10-20 7:44 ` Nicolas Dichtel
2023-10-20 7:24 ` [PATCH net-next 0/3] netlink: add variable-length / auto integers Nicolas Dichtel
2023-10-20 22:35 ` Jakub Kicinski
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=20231018213921.2694459-2-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--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;
as well as URLs for NNTP newsgroup(s).