Thread (55 messages) 55 messages, 6 authors, 2025-09-11

Re: [PATCH net-next 09/11] tools: ynl: encode indexed-array

From: Asbjørn Sloth Tønnesen <hidden>
Date: 2025-09-05 15:34:40
Also in: lkml

Hi Donald,

Thanks for the reviews.

On 9/5/25 10:49 AM, Donald Hunter wrote:
Asbjørn Sloth Tønnesen [off-list ref] writes:
quoted
This patch adds support for encoding indexed-array
attributes with sub-type nest in pyynl.

Signed-off-by: Asbjørn Sloth Tønnesen <redacted>
---
  tools/net/ynl/pyynl/lib/ynl.py | 17 +++++++++++++++++
  1 file changed, 17 insertions(+)
diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py
index 4928b41c636a..a37294a751da 100644
--- a/tools/net/ynl/pyynl/lib/ynl.py
+++ b/tools/net/ynl/pyynl/lib/ynl.py
@@ -564,6 +564,11 @@ class YnlFamily(SpecFamily):
              nl_type |= Netlink.NLA_F_NESTED
              sub_space = attr['nested-attributes']
              attr_payload = self._add_nest_attrs(value, sub_space, search_attrs)
+        elif attr['type'] == 'indexed-array' and attr['sub-type'] == 'nest':
+            nl_type |= Netlink.NLA_F_NESTED
+            sub_space = attr['nested-attributes']
+            attr_payload = self._encode_indexed_array(value, sub_space,
+                                                      search_attrs)
          elif attr["type"] == 'flag':
              if not value:
                  # If value is absent or false then skip attribute creation.
@@ -617,6 +622,9 @@ class YnlFamily(SpecFamily):
          else:
              raise Exception(f'Unknown type at {space} {name} {value} {attr["type"]}')
  
+        return self._add_attr_raw(nl_type, attr_payload)
+
+    def _add_attr_raw(self, nl_type, attr_payload):
          pad = b'\x00' * ((4 - len(attr_payload) % 4) % 4)
          return struct.pack('HH', len(attr_payload) + 4, nl_type) + attr_payload + pad
  
@@ -628,6 +636,15 @@ class YnlFamily(SpecFamily):
                                             sub_attrs)
          return attr_payload
  
+    def _encode_indexed_array(self, vals, sub_space, search_attrs):
+        attr_payload = b''
+        nested_flag = Netlink.NLA_F_NESTED
This line is not doing anything, right?
Right, that line shouldn't be there, it is a remain of an early version, where
I didn't add the indexes, as NLA_NESTED_ARRAY is actually an unindexed-array.

The wireguard kernel code only sends zero types, and it doesn't care that user-
space sends an indexed array back, eg. when setting multiple allowed ips.
quoted
+        for i, val in enumerate(vals):
+            idx = i | Netlink.NLA_F_NESTED
+            val_payload = self._add_nest_attrs(val, sub_space, search_attrs)
+            attr_payload += self._add_attr_raw(idx, val_payload)
+        return attr_payload
+
      def _get_enum_or_unknown(self, enum, raw):
          try:
              name = enum.entries_by_val[raw].name
-- 
pw-bot: cr
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help