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: [RFC PATCH net-next v1 6/6] tools/net/ynl: Add optional fixed-header to dynamic nests
Date: Wed, 29 Nov 2023 10:11:59 +0000 [thread overview]
Message-ID: <20231129101159.99197-7-donald.hunter@gmail.com> (raw)
In-Reply-To: <20231129101159.99197-1-donald.hunter@gmail.com>
Add support for an optional fixed-header to dynamic nested attribute
spaces. Several of the tc qdiscs have a binary struct for their
'options' instead of nested attributes. But the 'netem' qdisc has a
struct followed by nlattrs in its 'options'.
If a nest can have an optional fixed-header followed by zero or more
nlattrs then all cases can be supported.
Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
---
Documentation/netlink/netlink-raw.yaml | 2 ++
tools/net/ynl/lib/ynl.py | 24 +++++++++++++++---------
2 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/Documentation/netlink/netlink-raw.yaml b/Documentation/netlink/netlink-raw.yaml
index 62061e180f8f..b5295057dcea 100644
--- a/Documentation/netlink/netlink-raw.yaml
+++ b/Documentation/netlink/netlink-raw.yaml
@@ -292,6 +292,8 @@ properties:
description:
Name of the sub-space used inside the attribute.
type: string
+ fixed-header:
+ type: string
struct:
description:
Name of the struct type used for the attribute.
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 5ce01ce37573..86d591cb0047 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -170,10 +170,9 @@ class NlAttr:
class NlAttrs:
- def __init__(self, msg):
+ def __init__(self, msg, offset=0):
self.attrs = []
- offset = 0
while offset < len(msg):
attr = NlAttr(msg, offset)
offset += attr.full_len
@@ -371,8 +370,8 @@ class NetlinkProtocol:
fixed_header_size = 0
if ynl:
op = ynl.rsp_by_value[msg.cmd()]
- fixed_header_size = ynl._fixed_header_size(op)
- msg.raw_attrs = NlAttrs(msg.raw[fixed_header_size:])
+ fixed_header_size = ynl._fixed_header_size(op.fixed_header)
+ msg.raw_attrs = NlAttrs(msg.raw, fixed_header_size)
return msg
def get_mcast_id(self, mcast_name, mcast_groups):
@@ -571,8 +570,15 @@ class YnlFamily(SpecFamily):
decoded = self._decode_binary(attr, dyn_spec)
elif dyn_spec['type'] == 'nest':
attr_space = dyn_spec['nested-attributes']
+ fixed_header_name = dyn_spec.yaml.get('fixed-header')
if attr_space in self.attr_sets:
- decoded = self._decode(NlAttrs(attr.raw), attr_space)
+ decoded = {}
+ offset = 0
+ if fixed_header_name:
+ decoded.update(self._decode_fixed_header(attr, fixed_header_name));
+ offset = self._fixed_header_size(fixed_header_name)
+ subdict = self._decode(NlAttrs(attr.raw, offset), attr_space)
+ decoded.update(subdict)
else:
raise Exception(f"Unknown attribute-set '{attr_space}'")
else:
@@ -658,16 +664,16 @@ class YnlFamily(SpecFamily):
return
msg = self.nlproto.decode(self, NlMsg(request, 0, op.attr_set))
- offset = 20 + self._fixed_header_size(op)
+ offset = 20 + self._fixed_header_size(op.fixed_header)
path = self._decode_extack_path(msg.raw_attrs, op.attr_set, offset,
extack['bad-attr-offs'])
if path:
del extack['bad-attr-offs']
extack['bad-attr'] = path
- def _fixed_header_size(self, op):
- if op.fixed_header:
- fixed_header_members = self.consts[op.fixed_header].members
+ def _fixed_header_size(self, name):
+ if name:
+ fixed_header_members = self.consts[name].members
size = 0
for m in fixed_header_members:
format = NlAttr.get_format(m.type, m.byte_order)
--
2.42.0
next prev parent reply other threads:[~2023-11-29 10:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-29 10:11 [RFC PATCH net-next v1 0/6] tools/net/ynl: Add dynamic selector for options attrs Donald Hunter
2023-11-29 10:11 ` [RFC PATCH net-next v1 1/6] doc/netlink: Add bitfield32, s8, s16 to the netlink-raw schema Donald Hunter
2023-11-29 10:11 ` [RFC PATCH net-next v1 2/6] doc/netlink: Add a nest selector to " Donald Hunter
2023-11-29 10:11 ` [RFC PATCH net-next v1 3/6] tools/net/ynl: Add dynamic attribute decoding to ynl Donald Hunter
2023-11-29 10:11 ` [RFC PATCH net-next v1 4/6] doc/netlink/specs: add dynamic nest selector for rt_link data Donald Hunter
2023-11-29 10:11 ` [RFC PATCH net-next v1 5/6] doc/netlink/specs: Add a spec for tc Donald Hunter
2023-11-29 10:11 ` Donald Hunter [this message]
2023-11-29 16:09 ` [RFC PATCH net-next v1 0/6] tools/net/ynl: Add dynamic selector for options attrs Jakub Kicinski
2023-11-29 16:58 ` Donald Hunter
2023-11-29 17:49 ` Jakub Kicinski
2023-11-30 8:48 ` 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=20231129101159.99197-7-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).