Add support for encoding multi-attr to ynl
Subsystems (3)
cover Add support for encoding multi-attr to ynl
This patchset add the support for encoding multi-attr attributes, making it possible to use ynl with qdisc which have this kind of attributes (e.g: taprio, ets).
Example:
The equivalent to:
# tc qdisc add dev eni1np1 root handle:1 ets bands 8 priomap 7 6 5 4 3 2 1 0
would be in ynl:
# ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/tc.yaml --do
newqdisc --create --json '{"family":1, "ifindex":4, "handle":65536,
"parent":4294967295, "kind":"ets", "options":{"nbands":8, "priomap":
[{"priomap-band":7}, {"priomap-band":6}, {"priomap-band":5},
{"priomap-band":4}, {"priomap-band":3}, {"priomap-band":2},
{"priomap-band":1}, {"priomap-band":0}]}}'This patchset depends on the work done by Donald Hunter:
https://lore.kernel.org/netdev/[email protected]/T/#t
It is a modified version of a previous patch I've submitted, where I removed the part already addressed by Donald and modified the rest accordingly. Previous patch:
https://lore.kernel.org/netdev/[email protected]/T/#t
Patch 1 corrects two docstrings in nlspec.py Patch 2 adds the multi-attr attribute to taprio entry Patch 3 adds the support for encoding multi-attr
Alessandro Marcolini (3):
tools: ynl: correct typo and docstring
doc: netlink: specs: tc: add multi-attr to tc-taprio-sched-entry
tools: ynl: add support for encoding multi-attr
Documentation/netlink/specs/tc.yaml | 1 + tools/net/ynl/lib/nlspec.py | 9 ++++----- tools/net/ynl/lib/ynl.py | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 9 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/3 tools: ynl: correct typo and docstring
Correct typo in SpecAttr docstring. Changed SpecSubMessageFormat docstring.
--- tools/net/ynl/lib/nlspec.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
tools/net/ynl/lib/nlspec.py +4 -5
@@ -144,7 +144,7 @@ class SpecEnumSet(SpecElement): class SpecAttr(SpecElement): - """ Single Netlink atttribute type + """ Single Netlink attribute type Represents a single attribute type within an attr space.
@@ -308,10 +308,9 @@ class SpecSubMessage(SpecElement): class SpecSubMessageFormat(SpecElement): - """ Netlink sub-message definition - - Represents a set of sub-message formats for polymorphic nlattrs - that contain type-specific sub messages. + """ Netlink sub-message format definition + + Represents a single format for a sub-message. Attributes: value attribute value to match against type selector
Signature · 1 line
2.43.0
PATCH 2/3 doc: netlink: specs: tc: add multi-attr to tc-taprio-sched-entry
In reply to Alessandro MarcoliniAdd multi-attr attribute to tc-taprio-sched-entry to specify multiple entries.
--- Documentation/netlink/specs/tc.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/netlink/specs/tc.yaml +1 -0
@@ -3375,6 +3375,7 @@ attribute-sets: - name: entry type: nest + multi-attr: true nested-attributes: tc-taprio-sched-entry - name: tc-taprio-sched-entry
Signature · 1 line
2.43.0
PATCH 3/3 tools: ynl: add support for encoding multi-attr
In reply to Alessandro MarcoliniMulti-attr elements could not be encoded because of missing logic in the ynl code. Enable encoding of these attributes by checking if the nest attribute in the spec contains multi-attr attributes and if the value to be processed is a list.
This has been tested both with the taprio and ets qdisc which contain this kind of attributes.
--- tools/net/ynl/lib/ynl.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
tools/net/ynl/lib/ynl.py +12 -4
@@ -427,10 +427,18 @@ class YnlFamily(SpecFamily): if attr["type"] == 'nest': nl_type |= Netlink.NLA_F_NESTED attr_payload = b'' - subvals = ChainMap(value, vals) - for subname, subvalue in value.items(): - attr_payload += self._add_attr(attr['nested-attributes'], - subname, subvalue, subvals) + nested_attrs = self.attr_sets[attr['nested-attributes']].attrs + if any(a.is_multi for a in nested_attrs.values()) and isinstance(value, list): + for item in value: + subvals = ChainMap(item, vals) + for subname, subvalue in item.items(): + attr_payload += self._add_attr(attr['nested-attributes'], + subname, subvalue, subvals) + else: + subvals = ChainMap(value, vals) + for subname, subvalue in value.items(): + attr_payload += self._add_attr(attr['nested-attributes'], + subname, subvalue, subvals) elif attr["type"] == 'flag': attr_payload = b'' elif attr["type"] == 'string':
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerQuoted 2 lines · On Wed, 24 Jan 2024 17:34:35 +0100 Alessandro Marcolini wrote:
This patchset depends on the work done by Donald Hunter:
https://lore.kernel.org/netdev/[email protected]/T/#t
You'll have to repost once Donald's changes are in, sorry :( Our build bots and CI do not know how to handle series with dependencies.
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Wed, 24 Jan 2024 17:34:35 +0100 Alessandro Marcolini wrote:
This patchset depends on the work done by Donald Hunter:
https://lore.kernel.org/netdev/[email protected]/T/#tYou'll have to repost once Donald's changes are in, sorry :( Our build bots and CI do not know how to handle series with dependencies.
Ok, thanks for the update :)