Re: [PATCH net-next] tools: ynl-gen: use big-endian netlink attribute types

From: Asbjørn Sloth Tønnesen
Date: Sat Sep 14 2024 - 15:04:33 EST


Hi Kuba,

On 9/14/24 4:39 AM, Jakub Kicinski wrote:
Nice improvement! Since it technically missed net-next closing by a few
hours, let me nit pick a little..

Yeah, sorry about that, first realized that net-next had closed after posting.
I had just waited for my net patch to make its way to net-next before posting, so
MPTCP_PM_ADDR_ATTR_PORT wouldn't change to NLA_BE16.

On Fri, 13 Sep 2024 08:55:54 +0000 Asbjørn Sloth Tønnesen wrote:
diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index 717530bc9c52e..e26f2c3c40891 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -48,6 +48,7 @@ class Type(SpecAttr):
self.attr = attr
self.attr_set = attr_set
self.type = attr['type']
+ self.nla_type = self.type

is it worth introducing nla_type as Type attribute just for one user?
inside a netlink code generator meaning of nla_type may not be crystal
clear

Maybe not, I just took the same approach as byte_order_comment, and
co-located it with the existing byte-order condition in TypeScalar.

self.checks = attr.get('checks', {})
self.request = False
@@ -157,7 +158,7 @@ class Type(SpecAttr):
return '{ .type = ' + policy + ', }'
def attr_policy(self, cw):
- policy = c_upper('nla-' + self.attr['type'])
+ policy = c_upper('nla-' + self.nla_type)

We could just swap the type directly here?

That could work too, WDYT?

diff --git a/tools/net/ynl/ynl-gen-c.py b/tools/net/ynl/ynl-gen-c.py
index 717530bc9c52e..e8706f36e5e7b 100755
--- a/tools/net/ynl/ynl-gen-c.py
+++ b/tools/net/ynl/ynl-gen-c.py
@@ -157,7 +157,10 @@ class Type(SpecAttr):
return '{ .type = ' + policy + ', }'

def attr_policy(self, cw):
- policy = c_upper('nla-' + self.attr['type'])
+ policy = f'NLA_{c_upper(self.type)}'
+ if self.attr.get('byte-order', '') == 'big-endian':
+ if self.type in {'u16', 'u32'}:
+ policy = f'NLA_BE{self.type[1:]}'

spec = self._attr_policy(policy)
cw.p(f"\t[{self.enum_name}] = {spec},")