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>, Jonathan Corbet <corbet@lwn.net>,
linux-doc@vger.kernel.org
Cc: donald.hunter@redhat.com, Donald Hunter <donald.hunter@gmail.com>
Subject: [patch net-next v1 2/2] tools: ynl: Handle byte-order in struct members
Date: Sun, 21 May 2023 18:07:33 +0100 [thread overview]
Message-ID: <20230521170733.13151-3-donald.hunter@gmail.com> (raw)
In-Reply-To: <20230521170733.13151-1-donald.hunter@gmail.com>
Add support for byte-order in struct members in the genetlink-legacy
spec.
Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
---
Documentation/netlink/genetlink-legacy.yaml | 2 ++
tools/net/ynl/lib/nlspec.py | 4 +++-
tools/net/ynl/lib/ynl.py | 6 +++---
3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/Documentation/netlink/genetlink-legacy.yaml b/Documentation/netlink/genetlink-legacy.yaml
index b33541a51d6b..b5319cde9e17 100644
--- a/Documentation/netlink/genetlink-legacy.yaml
+++ b/Documentation/netlink/genetlink-legacy.yaml
@@ -122,6 +122,8 @@ properties:
enum: [ u8, u16, u32, u64, s8, s16, s32, s64, string ]
len:
$ref: '#/$defs/len-or-define'
+ byte-order:
+ enum: [ little-endian, big-endian ]
# End genetlink-legacy
attribute-sets:
diff --git a/tools/net/ynl/lib/nlspec.py b/tools/net/ynl/lib/nlspec.py
index a0241add3839..c624cdfde223 100644
--- a/tools/net/ynl/lib/nlspec.py
+++ b/tools/net/ynl/lib/nlspec.py
@@ -226,11 +226,13 @@ class SpecStructMember(SpecElement):
Represents a single struct member attribute.
Attributes:
- type string, type of the member attribute
+ type string, type of the member attribute
+ byte_order string or None for native byte order
"""
def __init__(self, family, yaml):
super().__init__(family, yaml)
self.type = yaml['type']
+ self.byte_order = yaml.get('byte-order')
class SpecStruct(SpecElement):
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 62e31db07c1f..41a4f8de7e17 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -124,7 +124,7 @@ class NlAttr:
offset = 0
for m in members:
# TODO: handle non-scalar members
- format = self.get_format(m.type)
+ format = self.get_format(m.type, m.byte_order)
decoded = format.unpack_from(self.raw, offset)
offset += format.size
value[m.name] = decoded[0]
@@ -305,7 +305,7 @@ class GenlMsg:
self.fixed_header_attrs = dict()
for m in fixed_header_members:
- format = NlAttr.get_format(m.type)
+ format = NlAttr.get_format(m.type, m.byte_order)
decoded = format.unpack_from(nl_msg.raw, offset)
offset += format.size
self.fixed_header_attrs[m.name] = decoded[0]
@@ -544,7 +544,7 @@ class YnlFamily(SpecFamily):
fixed_header_members = self.consts[op.fixed_header].members
for m in fixed_header_members:
value = vals.pop(m.name)
- format = NlAttr.get_format(m.type)
+ format = NlAttr.get_format(m.type, m.byte_order)
msg += format.pack(value)
for name, value in vals.items():
msg += self._add_attr(op.attr_set.name, name, value)
--
2.39.0
next prev parent reply other threads:[~2023-05-21 17:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-21 17:07 [patch net-next v1 0/2] tools: ynl: Add byte-order support for struct members Donald Hunter
2023-05-21 17:07 ` [patch net-next v1 1/2] tools: ynl: Use dict of predefined Structs to decode scalar types Donald Hunter
2023-05-23 2:37 ` Jakub Kicinski
2023-05-23 8:21 ` Donald Hunter
2023-05-21 17:07 ` Donald Hunter [this message]
2023-05-23 2:38 ` [patch net-next v1 2/2] tools: ynl: Handle byte-order in struct members Jakub Kicinski
2023-05-23 8:22 ` Donald Hunter
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=20230521170733.13151-3-donald.hunter@gmail.com \
--to=donald.hunter@gmail.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=donald.hunter@redhat.com \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.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).