Skip to contentSkip to conversation

Add support for encoding multi-attr to ynl

PATCH Superseded Alessandro Marcolini 2 participants 6 messages Jan 24, 2024 – Jan 25, 2024

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 5d197a12ab8d..9c205022f8c0 100644
@@ -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
#2 lore raw

PATCH 2/3 doc: netlink: specs: tc: add multi-attr to tc-taprio-sched-entry

In reply to Alessandro Marcolini

Add 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
index 4b21b00dbebe..0468070e7872 100644
@@ -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
#3 lore raw

PATCH 3/3 tools: ynl: add support for encoding multi-attr

In reply to Alessandro Marcolini

Multi-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
index dff2c042e6c3..bd01b1016fef 100644
@@ -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
#5 lore raw
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/#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.

Ok, thanks for the update :)