From: Donald Hunter <donald.hunter@gmail.com>
To: netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>
Cc: donald.hunter@redhat.com, Donald Hunter <donald.hunter@gmail.com>
Subject: [PATCH net-next v2 3/4] tools: ynl: Support enums in struct members in genetlink-legacy
Date: Sat, 27 May 2023 14:31:06 +0100 [thread overview]
Message-ID: <20230527133107.68161-4-donald.hunter@gmail.com> (raw)
In-Reply-To: <20230527133107.68161-1-donald.hunter@gmail.com>
Support decoding scalars as enums in struct members for genetlink-legacy
specs.
Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
---
Documentation/netlink/genetlink-legacy.yaml | 3 +++
tools/net/ynl/lib/nlspec.py | 2 ++
tools/net/ynl/lib/ynl.py | 6 +++++-
3 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/netlink/genetlink-legacy.yaml
index d8f132114308..ac4350498f5e 100644
--- a/Documentation/netlink/genetlink-legacy.yaml
+++ b/Documentation/netlink/genetlink-legacy.yaml
@@ -127,6 +127,9 @@ properties:
doc:
description: Documentation for the struct member attribute.
type: string
+ enum:
+ description: Name of the enum type used for the attribute.
+ type: string
# End genetlink-legacy
attribute-sets:
diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py
index c624cdfde223..ada22b073aa2 100644
--- a/tools/net/ynl/lib/nlspec.py
+++ b/tools/net/ynl/lib/nlspec.py
@@ -228,11 +228,13 @@ class SpecStructMember(SpecElement):
Attributes:
type string, type of the member attribute
byte_order string or None for native byte order
+ enum string, name of the enum definition
"""
def __init__(self, family, yaml):
super().__init__(family, yaml)
self.type = yaml['type']
self.byte_order = yaml.get('byte-order')
+ self.enum = yaml.get('enum')
class SpecStruct(SpecElement):
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 85ee6a4bee72..0692293447ad 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -412,7 +412,11 @@ class YnlFamily(SpecFamily):
def _decode_binary(self, attr, attr_spec):
if attr_spec.struct_name:
- decoded = attr.as_struct(self.consts[attr_spec.struct_name])
+ members = self.consts[attr_spec.struct_name]
+ decoded = attr.as_struct(members)
+ for m in members:
+ if m.enum:
+ self._decode_enum(decoded, m)
elif attr_spec.sub_type:
decoded = attr.as_c_array(attr_spec.sub_type)
else:
--
2.39.0
next prev parent reply other threads:[~2023-05-27 13:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-27 13:31 [PATCH net-next v2 0/4] netlink: specs: add ynl spec for ovs_flow Donald Hunter
2023-05-27 13:31 ` [PATCH net-next v2 1/4] doc: ynl: Add doc attr to struct members in genetlink-legacy spec Donald Hunter
2023-05-27 13:31 ` [PATCH net-next v2 2/4] tools: ynl: Initialise fixed headers to 0 in genetlink-legacy Donald Hunter
2023-05-27 13:31 ` Donald Hunter [this message]
2023-05-27 13:31 ` [PATCH net-next v2 4/4] netlink: specs: add ynl spec for ovs_flow Donald Hunter
2023-05-30 5:10 ` [PATCH net-next v2 0/4] " 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=20230527133107.68161-4-donald.hunter@gmail.com \
--to=donald.hunter@gmail.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@redhat.com \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--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).