Skip to contentSkip to conversation

netlink: specs: devlink: add the rest of missing attribute definitions

PATCH Superseded Jiri Pirko 3 participants 32 messages Feb 19, 2024 – Feb 22, 2024

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

cover netlink: specs: devlink: add the rest of missing attribute definitions

From: Jiri Pirko <[email protected]>

This patchset is adding the missing definitions of devlink attributes.

It got a bit tricky, as the param and fmsg value attributes have different type according to a value of another attribute. Thankfully, the selector infrastructure was recently introduced to ynl. This patchset extends it a bit and uses it.

Another tricky bit was the fact that fmsg contains a list of attributes that go as a stream and can be present multiple times. Also, it is important to maintain the attribute position. For that, list output needed to be added.

Also, nested devlink attributes definitions was added.

Examples:

$ sudo ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/devlink.yaml \
                              --dump param-get
[{'bus-name': 'netdevsim',
  'dev-name': 'netdevsim1',
  'param': {'param-generic': True,
            'param-name': 'max_macs',
            'param-type': 'u32',
            'param-values-list': {'param-value': [{'param-value-cmode': 'driverinit',
                                                   'param-value-data': 32}]}}},
 {'bus-name': 'netdevsim',
  'dev-name': 'netdevsim1',
  'param': {'param-name': 'test1',
            'param-type': 'flag',
            'param-values-list': {'param-value': [{'param-value-cmode': 'driverinit',
                                                   'param-value-data': True}]}}}]
$ sudo ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/devlink.yaml \
                              --do param-set \
			      --json '{"bus-name": "netdevsim", "dev-name": "netdevsim1", "param-name": "max_macs", "param-type": "u32", "param-value-data": 21, "param-value-cmode": "driverinit"}'
$ sudo ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/devlink.yaml \
                              --do param-set \
			      --json '{"bus-name": "netdevsim", "dev-name": "netdevsim1", "param-name": "test1", "param-type": "flag", "param-value-data": false, "param-value-cmode": "driverinit"}'
$ sudo ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/devlink.yaml \
                              --dump health-reporter-dump-get --json '{"bus-name": "netdevsim", "dev-name": "netdevsim1", "health-reporter-name": "dummy"}'
[{'fmsg': [{'fmsg-obj-nest-start': True},
           {'fmsg-pair-nest-start': True},
           {'fmsg-obj-name': 'test_bool'},
           {'fmsg-obj-value-type': 'flag'},
           {'fmsg-obj-value-data': True},
           {'fmsg-nest-end': True},
           {'fmsg-pair-nest-start': True},
           {'fmsg-obj-name': 'test_u8'},
           {'fmsg-obj-value-type': 'u8'},
           {'fmsg-obj-value-data': 1},
           {'fmsg-nest-end': True},
           {'fmsg-pair-nest-start': True},
           {'fmsg-obj-name': 'test_u32'},
           {'fmsg-obj-value-type': 'u32'},
           {'fmsg-obj-value-data': 3},
.....
           {'fmsg-nest-end': True}]}]
$ sudo ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/devlink.yaml \
		              --do port-get \
			      --json '{"bus-name": "pci", "dev-name": "0000:08:00.1", "port-index": 98304}'
{'bus-name': 'pci',
 'dev-name': '0000:08:00.1',
 'port-controller-number': 0,
 'port-flavour': 'pci_sf',
 'port-function': {'caps': {'selector': {'roce-bit'}, 'value': {'roce-bit'}},
                   'devlink': {'bus-name': 'auxiliary',
                               'dev-name': 'mlx5_core.sf.2'},
                   'hw-addr': b'\x00\x00\x00\x00\x00\x00',
                   'opstate': 'attached',
                   'state': 'active'},
 'port-index': 98304,
 'port-netdev-ifindex': 7,
 'port-netdev-name': 'eth4',
 'port-pci-pf-number': 1,
 'port-pci-sf-number': 109,
 'port-splittable': 0,
 'port-type': 'eth'}

Jiri Pirko (13):
tools: ynl: allow user to specify flag attr with bool values
tools: ynl: process all scalar types encoding in single elif statement
tools: ynl: allow user to pass enum string instead of scalar value
netlink: specs: allow sub-messages in genetlink-legacy
tools: ynl: allow attr in a subset to be of a different type
tools: ynl: introduce attribute-replace for sub-message
tools: ynl: add support for list in nested attribute
netlink: specs: devlink: add enum for param-type attribute values
netlink: specs: devlink: add missing param attribute definitions
netlink: specs: devlink: treat dl-fmsg attribute as list
netlink: specs: devlink: add enum for fmsg-obj-value-type attribute
values
netlink: specs: devlink: add missing fmsg-obj-value-data attribute
definitions
netlink: specs: devlink: add missing nested devlink definitions

 Documentation/netlink/genetlink-legacy.yaml   |  54 +++-
 Documentation/netlink/netlink-raw.yaml        |  10 +-
 Documentation/netlink/specs/devlink.yaml      | 260 +++++++++++++++++-
 .../netlink/genetlink-legacy.rst              | 126 +++++++++
 .../userspace-api/netlink/netlink-raw.rst     | 101 -------
 tools/net/ynl/lib/nlspec.py                   |   8 +
 tools/net/ynl/lib/ynl.py                      |  81 ++++--
 7 files changed, 500 insertions(+), 140 deletions(-)
Signature · 1 line
2.43.2
author
#1 lore raw

PATCH 1/13 tools: ynl: allow user to specify flag attr with bool values

From: Jiri Pirko <[email protected]>

The flag attr presence in Netlink message indicates value "true", if it is missing in the message it means "false".

Allow user to specify attrname with value "true"/"false" in json for flag attrs, treat "false" value properly.

---
 tools/net/ynl/lib/ynl.py | 2 ++
 1 file changed, 2 insertions(+)
tools/net/ynl/lib/ynl.py +2 -0
index f45ee5f29bed..108fe7eadd93 100644
@@ -459,6 +459,8 @@ class YnlFamily(SpecFamily):
                 attr_payload += self._add_attr(attr['nested-attributes'],
                                                subname, subvalue, sub_attrs)
         elif attr["type"] == 'flag':
+            if value == False:
+                return b''
             attr_payload = b''
         elif attr["type"] == 'string':
             attr_payload = str(value).encode('ascii') + b'\x00'
Signature · 1 line
2.43.2
author
#4 lore raw

PATCH 2/13 tools: ynl: process all scalar types encoding in single elif statement

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

As a preparation to handle enums for scalar values, unify the processing of all scalar types in a single elif statement.

---
 tools/net/ynl/lib/ynl.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
tools/net/ynl/lib/ynl.py +7 -7
index 108fe7eadd93..ccdb2f1e7379 100644
@@ -473,14 +473,14 @@ class YnlFamily(SpecFamily):
                 attr_payload = self._encode_struct(attr.struct_name, value)
             else:
                 raise Exception(f'Unknown type for binary attribute, value: {value}')
-        elif attr.is_auto_scalar:
+        elif attr['type'] in NlAttr.type_formats or attr.is_auto_scalar:
             scalar = int(value)
-            real_type = attr["type"][0] + ('32' if scalar.bit_length() <= 32 else '64')
-            format = NlAttr.get_format(real_type, attr.byte_order)
-            attr_payload = format.pack(int(value))
-        elif attr['type'] in NlAttr.type_formats:
-            format = NlAttr.get_format(attr['type'], attr.byte_order)
-            attr_payload = format.pack(int(value))
+            if attr.is_auto_scalar:
+                attr_type = attr["type"][0] + ('32' if scalar.bit_length() <= 32 else '64')
+            else:
+                attr_type = attr["type"]
+            format = NlAttr.get_format(attr_type, attr.byte_order)
+            attr_payload = format.pack(scalar)
         elif attr['type'] in "bitfield32":
             attr_payload = struct.pack("II", int(value["value"]), int(value["selector"]))
         elif attr['type'] == 'sub-message':
Signature · 1 line
2.43.2
author
#5 lore raw

PATCH 3/13 tools: ynl: allow user to pass enum string instead of scalar value

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

During decoding of messages coming from kernel, attribute values are converted to enum names in case the attribute type is enum of bitfield32.

However, when user constructs json message, he has to pass plain scalar values. See "state" "selector" and "value" attributes in following examples:

$ sudo ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --do pin-set --json '{"id": 0, "parent-device": {"parent-id": 0, "state": 1}}'
$ sudo ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/devlink.yaml --do port-set --json '{"bus-name": "pci", "dev-name": "0000:08:00.1", "port-index": 98304, "port-function": {"caps": {"selector": 1, "value": 1 }}}'

Allow user to pass strings containing enum names, convert them to scalar values to be encoded into Netlink message:

$ sudo ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/dpll.yaml --do pin-set --json '{"id": 0, "parent-device": {"parent-id": 0, "state": "connected"}}'
$ sudo ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/devlink.yaml --do port-set --json '{"bus-name": "pci", "dev-name": "0000:08:00.1", "port-index": 98304, "port-function": {"caps": {"selector": ["roce-bit"], "value": ["roce-bit"] }}}'
---
 tools/net/ynl/lib/ynl.py | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
tools/net/ynl/lib/ynl.py +19 -2
index ccdb2f1e7379..d2ea1571d00c 100644
@@ -438,6 +438,21 @@ class YnlFamily(SpecFamily):
         self.sock.setsockopt(Netlink.SOL_NETLINK, Netlink.NETLINK_ADD_MEMBERSHIP,
                              mcast_id)
 
+    def _get_scalar(self, attr_spec, value):
+        try:
+            return int(value)
+        except (ValueError, TypeError) as e:
+            if 'enum' not in attr_spec:
+                raise e
+        enum = self.consts[attr_spec['enum']]
+        if enum.type == 'flags' or attr_spec.get('enum-as-flags', False):
+            scalar = 0
+            for single_value in value:
+                scalar += enum.entries[single_value].user_value(as_flags = True)
+            return scalar
+        else:
+            return enum.entries[value].user_value()
+
     def _add_attr(self, space, name, value, search_attrs):
         try:
             attr = self.attr_sets[space][name]
@@ -474,7 +489,7 @@ class YnlFamily(SpecFamily):
             else:
                 raise Exception(f'Unknown type for binary attribute, value: {value}')
         elif attr['type'] in NlAttr.type_formats or attr.is_auto_scalar:
-            scalar = int(value)
+            scalar = self._get_scalar(attr, value)
             if attr.is_auto_scalar:
                 attr_type = attr["type"][0] + ('32' if scalar.bit_length() <= 32 else '64')
             else:
@@ -482,7 +497,9 @@ class YnlFamily(SpecFamily):
             format = NlAttr.get_format(attr_type, attr.byte_order)
             attr_payload = format.pack(scalar)
         elif attr['type'] in "bitfield32":
-            attr_payload = struct.pack("II", int(value["value"]), int(value["selector"]))
+            scalar_value = self._get_scalar(attr, value["value"])
+            scalar_selector = self._get_scalar(attr, value["selector"])
+            attr_payload = struct.pack("II", scalar_value, scalar_selector)
         elif attr['type'] == 'sub-message':
             msg_format = self._resolve_selector(attr, search_attrs)
             attr_payload = b''
Signature · 1 line
2.43.2
author
#14 lore raw

PATCH 4/13 netlink: specs: allow sub-messages in genetlink-legacy

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Currently sub-messages are only supported in netlink-raw template. To be able to utilize them in devlink spec, allow them in genetlink-legacy as well.

---
 Documentation/netlink/genetlink-legacy.yaml   |  47 +++++++-
 Documentation/netlink/netlink-raw.yaml        |   6 +-
 .../netlink/genetlink-legacy.rst              | 101 ++++++++++++++++++
 .../userspace-api/netlink/netlink-raw.rst     | 101 ------------------
 4 files changed, 148 insertions(+), 107 deletions(-)
Documentation/netlink/genetlink-legacy.yaml +46 -1
index 938703088306..6cb50e2cc021 100644
@@ -200,7 +200,8 @@ properties:
                 description: The netlink attribute type
                 enum: [ unused, pad, flag, binary, bitfield32,
                         uint, sint, u8, u16, u32, u64, s32, s64,
-                        string, nest, array-nest, nest-type-value ]
+                        string, nest, array-nest, nest-type-value,
+                        sub-message ]
               doc:
                 description: Documentation of the attribute.
                 type: string
@@ -261,6 +262,15 @@ properties:
               struct:
                 description: Name of the struct type used for the attribute.
                 type: string
+              sub-message:
+                description: |
+                  Name of the sub-message definition to use for the attribute.
+                type: string
+              selector:
+                description: |
+                  Name of the attribute to use for dynamic selection of sub-message
+                  format specifier.
+                type: string
               # End genetlink-legacy
 
       # Make sure name-prefix does not appear in subsets (subsets inherit naming)
@@ -284,6 +294,41 @@ properties:
             items:
               required: [ type ]
 
+  sub-messages:
+    description: Definition of sub message attributes
+    type: array
+    items:
+      type: object
+      additionalProperties: False
+      required: [ name, formats ]
+      properties:
+        name:
+          description: Name of the sub-message definition
+          type: string
+        formats:
+          description: Dynamically selected format specifiers
+          type: array
+          items:
+            type: object
+            additionalProperties: False
+            required: [ value ]
+            properties:
+              value:
+                description: |
+                  Value to match for dynamic selection of sub-message format
+                  specifier.
+                type: string
+              fixed-header:
+                description: |
+                  Name of the struct definition to use as the fixed header
+                  for the sub message.
+                type: string
+              attribute-set:
+                description: |
+                  Name of the attribute space from which to resolve attributes
+                  in the sub message.
+                type: string
+
   operations:
     description: Operations supported by the protocol.
     type: object
Documentation/netlink/netlink-raw.yaml +1 -5
index ac4e05415f2f..cc38b026c451 100644
@@ -280,8 +280,6 @@ properties:
               struct:
                 description: Name of the struct type used for the attribute.
                 type: string
-              # End genetlink-legacy
-              # Start netlink-raw
               sub-message:
                 description: |
                   Name of the sub-message definition to use for the attribute.
@@ -291,7 +289,7 @@ properties:
                   Name of the attribute to use for dynamic selection of sub-message
                   format specifier.
                 type: string
-              # End netlink-raw
+              # End genetlink-legacy
 
       # Make sure name-prefix does not appear in subsets (subsets inherit naming)
       dependencies:
@@ -314,7 +312,6 @@ properties:
             items:
               required: [ type ]
 
-  # Start netlink-raw
   sub-messages:
     description: Definition of sub message attributes
     type: array
@@ -349,7 +346,6 @@ properties:
                   Name of the attribute space from which to resolve attributes
                   in the sub message.
                 type: string
-  # End netlink-raw
 
   operations:
     description: Operations supported by the protocol.
Documentation/userspace-api/netlink/genetlink-legacy.rst +101 -0

104 lines not on this page · raw message

Documentation/userspace-api/netlink/netlink-raw.rst +0 -101

107 lines not on this page · raw message

Signature · 1 line
2.43.2
author
#17 lore raw

PATCH 5/13 tools: ynl: allow attr in a subset to be of a different type

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Currently, when subset attribute is defined, it inherits the whole definition of the attribute in original set. To be able to achieve sub message decoding of the same attribute of different type, allow spec to define different type for the same attribute.

---
 tools/net/ynl/lib/nlspec.py | 2 ++
 1 file changed, 2 insertions(+)
tools/net/ynl/lib/nlspec.py +2 -0
index fbce52395b3b..5e48ee0fb8b4 100644
@@ -217,6 +217,8 @@ class SpecAttrSet(SpecElement):
             real_set = family.attr_sets[self.subset_of]
             for elem in self.yaml['attributes']:
                 attr = real_set[elem['name']]
+                if 'type' in elem and attr.type != elem['type']:
+                    attr = self.new_attr(elem, attr.value)
                 self.attrs[attr.name] = attr
                 self.attrs_by_val[attr.value] = attr
 
Signature · 1 line
2.43.2
author
#18 lore raw

PATCH 6/13 tools: ynl: introduce attribute-replace for sub-message

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

For devlink param, param-value-data attr is used by kernel to fill different attribute type according to param-type attribute value.

Currently the sub-message feature allows spec to embed custom message selected by another attribute. The sub-message is then nested inside the attr of sub-message type.

Benefit from the sub-message feature and extend it. Introduce attribute-replace spec flag by which the spec indicates that ynl should consider sub-message as not nested in the original attribute, but rather to consider the original attribute as the sub-message right away.

---
 Documentation/netlink/genetlink-legacy.yaml   |  4 +++
 Documentation/netlink/netlink-raw.yaml        |  4 +++
 .../netlink/genetlink-legacy.rst              | 25 ++++++++++++++++++
 tools/net/ynl/lib/nlspec.py                   |  6 +++++
 tools/net/ynl/lib/ynl.py                      | 26 ++++++++++++++-----
 5 files changed, 59 insertions(+), 6 deletions(-)
Documentation/netlink/genetlink-legacy.yaml +4 -0
index 6cb50e2cc021..77d89f81c71f 100644
@@ -328,6 +328,10 @@ properties:
                   Name of the attribute space from which to resolve attributes
                   in the sub message.
                 type: string
+              attribute-replace:
+                description: |
+                  Replace the parent nested attribute with attribute set
+                type: boolean
 
   operations:
     description: Operations supported by the protocol.
Documentation/netlink/netlink-raw.yaml +4 -0
index cc38b026c451..e32660fbe6c3 100644
@@ -346,6 +346,10 @@ properties:
                   Name of the attribute space from which to resolve attributes
                   in the sub message.
                 type: string
+              attribute-replace:
+                description: |
+                  Replace the parent nested attribute with attribute set
+                type: boolean
 
   operations:
     description: Operations supported by the protocol.
Documentation/userspace-api/netlink/genetlink-legacy.rst +25 -0
index 7126b650090e..a9ccbfbb4a8d 100644
@@ -381,3 +381,28 @@ alongside a sub-message selector and also in a top level ``attribute-set``, then
 the selector will be resolved using the value 'closest' to the selector. If the
 value is not present in the message at the same level as defined in the spec
 then this is an error.
+
+Some users, like devlink param, fill different attribute type according to
+selector attribute value. ``replace-attribute`` set to ``true`` indicates,
+that sub-message is not nested inside the attribute, but rather replacing
+the attribute. This allows to treat the attribute type differently according
+to the selector:
+
+.. code-block:: yaml
+
+  sub-messages:
+    -
+      name: dl-param-value-data-msg
+      formats:
+        -
+          value: u32
+          attribute-set: dl-param-value-data-u32-attrs
+          attribute-replace: true
+        -
+          value: string
+          attribute-set: dl-param-value-data-string-attrs
+          attribute-replace: true
+        -
+          value: bool
+          attribute-set: dl-param-value-data-bool-attrs
+          attribute-replace: true
tools/net/ynl/lib/nlspec.py +6 -0
index 5e48ee0fb8b4..280d50e9079c 100644
@@ -237,6 +237,9 @@ class SpecAttrSet(SpecElement):
     def items(self):
         return self.attrs.items()
 
+    def keys(self):
+        return self.attrs.keys()
+
 
 class SpecStructMember(SpecElement):
     """Struct member attribute
@@ -318,6 +321,8 @@ class SpecSubMessageFormat(SpecElement):
         value         attribute value to match against type selector
         fixed_header  string, name of fixed header, or None
         attr_set      string, name of attribute set, or None
+        attr_replace  bool, indicates replacement of parent attribute with
+                      attr_set decode, or None
     """
     def __init__(self, family, yaml):
         super().__init__(family, yaml)
@@ -325,6 +330,7 @@ class SpecSubMessageFormat(SpecElement):
         self.value = yaml.get('value')
         self.fixed_header = yaml.get('fixed-header')
         self.attr_set = yaml.get('attribute-set')
+        self.attr_replace = yaml.get('attribute-replace')
 
 
 class SpecOperation(SpecElement):
tools/net/ynl/lib/ynl.py +20 -6
index d2ea1571d00c..8591e6bfe40b 100644
@@ -507,11 +507,16 @@ class YnlFamily(SpecFamily):
                 attr_payload += self._encode_struct(msg_format.fixed_header, value)
             if msg_format.attr_set:
                 if msg_format.attr_set in self.attr_sets:
-                    nl_type |= Netlink.NLA_F_NESTED
-                    sub_attrs = SpaceAttrs(msg_format.attr_set, value, search_attrs)
-                    for subname, subvalue in value.items():
-                        attr_payload += self._add_attr(msg_format.attr_set,
-                                                       subname, subvalue, sub_attrs)
+                    if msg_format.attr_replace:
+                        first_attr_name = list(self.attr_sets[msg_format.attr_set].keys())[0]
+                        return self._add_attr(msg_format.attr_set, first_attr_name,
+                                              value, search_attrs)
+                    else:
+                        nl_type |= Netlink.NLA_F_NESTED
+                        sub_attrs = SpaceAttrs(msg_format.attr_set, value, search_attrs)
+                        for subname, subvalue in value.items():
+                            attr_payload += self._add_attr(msg_format.attr_set,
+                                                           subname, subvalue, sub_attrs)
                 else:
                     raise Exception(f"Unknown attribute-set '{msg_format.attr_set}'")
         else:
@@ -600,8 +605,17 @@ class YnlFamily(SpecFamily):
             offset = self._struct_size(msg_format.fixed_header)
         if msg_format.attr_set:
             if msg_format.attr_set in self.attr_sets:
-                subdict = self._decode(NlAttrs(attr.raw, offset), msg_format.attr_set)
+                if msg_format.attr_replace:
+                    attrs = [attr]
+                else:
+                    attrs = NlAttrs(attr.raw, offset);
+                subdict = self._decode(attrs, msg_format.attr_set)
                 decoded.update(subdict)
+                if msg_format.attr_replace:
+                    try:
+                        decoded = decoded[attr_spec.name]
+                    except KeyError:
+                        raise Exception(f"Attribute-set '{attr_space}' does not contain '{attr_spec.name}'")
             else:
                 raise Exception(f"Unknown attribute-set '{attr_space}' when decoding '{attr_spec.name}'")
         return decoded
Signature · 1 line
2.43.2
author
#25 lore raw

PATCH 7/13 tools: ynl: add support for list in nested attribute

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Some nested attributes, like devlink-fmg, contain plain list of attributes that may repeat. Current decode rsp implementation is dictionary which causes duplicate attributes to be re-written.

To solve this, introduce "nested-list" flag for "nest" type which indicates the _decode() function to use list instead of dictionary and store each decoded attribute into this list as a separate dictionary.

---
 Documentation/netlink/genetlink-legacy.yaml |  3 +++
 tools/net/ynl/lib/ynl.py                    | 18 ++++++++++++++----
 2 files changed, 17 insertions(+), 4 deletions(-)
Documentation/netlink/genetlink-legacy.yaml +3 -0
index 77d89f81c71f..0e0ee3b4ff5f 100644
@@ -220,6 +220,9 @@ properties:
               nested-attributes:
                 description: Name of the space (sub-space) used inside the attribute.
                 type: string
+              nested-list:
+                description: The nested attribute contains a list of attributes.
+                type: boolean
               enum:
                 description: Name of the enum type used for the attribute.
                 type: string
tools/net/ynl/lib/ynl.py +14 -4
index 8591e6bfe40b..08fe27c8dec7 100644
@@ -386,8 +386,12 @@ class SpaceAttrs:
     def lookup(self, name):
         for scope in self.scopes:
             if name in scope.spec:
-                if name in scope.values:
+                if isinstance(scope.values, dict) and name in scope.values:
                     return scope.values[name]
+                if isinstance(scope.values, list):
+                    for item in reversed(scope.values):
+                        if name in item:
+                            return item[name]
                 spec_name = scope.spec.yaml['name']
                 raise Exception(
                     f"No value for '{name}' in attribute space '{spec_name}'")
@@ -568,6 +572,10 @@ class YnlFamily(SpecFamily):
             return attr.as_bin()
 
     def _rsp_add(self, rsp, name, is_multi, decoded):
+        if isinstance(rsp, list):
+            rsp.append({name: decoded})
+            return
+
         if is_multi == None:
             if name in rsp and type(rsp[name]) is not list:
                 rsp[name] = [rsp[name]]
@@ -620,8 +628,8 @@ class YnlFamily(SpecFamily):
                 raise Exception(f"Unknown attribute-set '{attr_space}' when decoding '{attr_spec.name}'")
         return decoded
 
-    def _decode(self, attrs, space, outer_attrs = None):
-        rsp = dict()
+    def _decode(self, attrs, space, outer_attrs = None, to_list = False):
+        rsp = list() if to_list else dict()
         if space:
             attr_space = self.attr_sets[space]
             search_attrs = SpaceAttrs(attr_space, rsp, outer_attrs)
@@ -637,7 +645,9 @@ class YnlFamily(SpecFamily):
                 continue
 
             if attr_spec["type"] == 'nest':
-                subdict = self._decode(NlAttrs(attr.raw), attr_spec['nested-attributes'], search_attrs)
+                nested_list = attr_spec['nested-list'] if 'nested-list' in attr_spec else False
+                subdict = self._decode(NlAttrs(attr.raw), attr_spec['nested-attributes'],
+                                       search_attrs, to_list = nested_list)
                 decoded = subdict
             elif attr_spec["type"] == 'string':
                 decoded = attr.as_strz()
Signature · 1 line
2.43.2
author
#26 lore raw

PATCH 8/13 netlink: specs: devlink: add enum for param-type attribute values

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

For devlink param values, devlink relies on NLA_* values what are used internally in kernel to indicate which type the attribute is. This is not exposed over UAPI. Add devlink-param-type enum that defines these values as part of devlink yaml spec.

---
 Documentation/netlink/specs/devlink.yaml | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
Documentation/netlink/specs/devlink.yaml +17 -0
index cf6eaa0da821..88abe137c8ef 100644
@@ -164,6 +164,22 @@ definitions:
         value: 1
       -
         name: fw-activate
+  -
+    type: enum
+    name: param-type
+    entries:
+      -
+        name: u8
+        value: 1
+      -
+        name: u16
+      -
+        name: u32
+      -
+        name: string
+        value: 5
+      -
+        name: flag
   -
     type: enum
     name: param-cmode
@@ -498,6 +514,7 @@ attribute-sets:
       -
         name: param-type
         type: u8
+        enum: param-type
 
       # TODO: fill in the attributes in between
 
Signature · 1 line
2.43.2
author
#27 lore raw

PATCH 9/13 netlink: specs: devlink: add missing param attribute definitions

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Add missing values list attribute and all nested attributes definition, including param-value-data. For this one, use newly introduced sub-message replace-attribute infrastructure to allow to process attribute type selected by param-value-type.

---
 Documentation/netlink/specs/devlink.yaml | 108 +++++++++++++++++++++--
 1 file changed, 102 insertions(+), 6 deletions(-)
Documentation/netlink/specs/devlink.yaml +102 -6
index 88abe137c8ef..71a95163c419 100644
@@ -515,14 +515,24 @@ attribute-sets:
         name: param-type
         type: u8
         enum: param-type
-
-      # TODO: fill in the attributes in between
-
+      -
+        name: param-values-list
+        type: nest
+        nested-attributes: dl-param-values-list
+      -
+        name: param-value
+        type: nest
+        multi-attr: true
+        nested-attributes: dl-param-value
+      -
+        name: param-value-data
+        type: sub-message
+        sub-message: dl-param-value-data-msg
+        selector: param-type
       -
         name: param-value-cmode
         type: u8
         enum: param-cmode
-        value: 87
       -
         name: region-name
         type: string
@@ -1131,8 +1141,24 @@ attribute-sets:
         name: param-generic
       -
         name: param-type
+      -
+        name: param-values-list
+
+  -
+    name: dl-param-values-list
+    subset-of: devlink
+    attributes:
+      -
+        name: param-value
 
-      # TODO: fill in the attribute param-value-list
+  -
+    name: dl-param-value
+    subset-of: devlink
+    attributes:
+      -
+        name: param-value-data
+      -
+        name: param-value-cmode
 
   -
     name: dl-region-snapshots
@@ -1243,6 +1269,71 @@ attribute-sets:
         name: flash
         type: flag
 
+  -
+    name: dl-param-value-data-u8-attrs
+    subset-of: devlink
+    attributes:
+      -
+        name: param-value-data
+        type: u8
+
+  -
+    name: dl-param-value-data-u16-attrs
+    subset-of: devlink
+    attributes:
+      -
+        name: param-value-data
+        type: u16
+
+  -
+    name: dl-param-value-data-u32-attrs
+    subset-of: devlink
+    attributes:
+      -
+        name: param-value-data
+        type: u32
+
+  -
+    name: dl-param-value-data-string-attrs
+    subset-of: devlink
+    attributes:
+      -
+        name: param-value-data
+        type: string
+
+  -
+    name: dl-param-value-data-flag-attrs
+    subset-of: devlink
+    attributes:
+      -
+        name: param-value-data
+        type: flag
+
+sub-messages:
+  -
+    name: dl-param-value-data-msg
+    formats:
+      -
+        value: u8
+        attribute-set: dl-param-value-data-u8-attrs
+        attribute-replace: true
+      -
+        value: u16
+        attribute-set: dl-param-value-data-u16-attrs
+        attribute-replace: true
+      -
+        value: u32
+        attribute-set: dl-param-value-data-u32-attrs
+        attribute-replace: true
+      -
+        value: string
+        attribute-set: dl-param-value-data-string-attrs
+        attribute-replace: true
+      -
+        value: flag
+        attribute-set: dl-param-value-data-flag-attrs
+        attribute-replace: true
+
 operations:
   enum-model: directional
   list:
@@ -1731,7 +1822,12 @@ operations:
             - dev-name
             - param-name
         reply: &param-get-reply
-          attributes: *param-id-attrs
+          attributes:
+            - bus-name
+            - dev-name
+            - param-name
+            - param-type
+            - param-values-list
       dump:
         request:
           attributes: *dev-id-attrs
Signature · 1 line
2.43.2
author
#28 lore raw

PATCH 10/13 netlink: specs: devlink: treat dl-fmsg attribute as list

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Benefit from the previously introduces "nested-list" flag for "nest" type and use it to indicate dl-fmsg attribute contains a list.

---
 Documentation/netlink/specs/devlink.yaml | 1 +
 1 file changed, 1 insertion(+)
Documentation/netlink/specs/devlink.yaml +1 -0
index 71a95163c419..df1afdf06068 100644
@@ -601,6 +601,7 @@ attribute-sets:
         name: fmsg
         type: nest
         nested-attributes: dl-fmsg
+        nested-list: true
       -
         name: fmsg-obj-nest-start
         type: flag
Signature · 1 line
2.43.2
author
#29 lore raw

PATCH 11/13 netlink: specs: devlink: add enum for fmsg-obj-value-type attribute values

From: Jiri Pirko <[email protected]>

For devlink fmsg object values, devlink relies on NLA_* values what are used internally in kernel to indicate which type the attribute is. This is not exposed over UAPI. Add devlink-param-type enum that defines these values as part of devlink yaml spec.

---
 Documentation/netlink/specs/devlink.yaml | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
Documentation/netlink/specs/devlink.yaml +21 -0
index df1afdf06068..fa4440141b05 100644
@@ -218,6 +218,26 @@ definitions:
         name: exception
       -
         name: control
+  -
+    type: enum
+    name: fmsg-obj-value-type
+    entries:
+      -
+        name: u8
+        value: 1
+      -
+        name: u32
+        value: 3
+      -
+        name: u64
+      -
+        name: flag
+        value: 6
+      -
+        name: string
+        value: 10
+      -
+        name: binary
 
 attribute-sets:
   -
@@ -620,6 +640,7 @@ attribute-sets:
       -
         name: fmsg-obj-value-type
         type: u8
+        enum: fmsg-obj-value-type
 
       # TODO: fill in the attributes in between
 
Signature · 1 line
2.43.2
author
#30 lore raw

PATCH 12/13 netlink: specs: devlink: add missing fmsg-obj-value-data attribute definitions

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Add missing fmsg-obj-value-data definition. Use newly introduced sub-message replace-attribute infrastructure to allow to process attribute type selected by fmsg-obj-value-type.

---
 Documentation/netlink/specs/devlink.yaml | 89 ++++++++++++++++++++++--
 1 file changed, 85 insertions(+), 4 deletions(-)
Documentation/netlink/specs/devlink.yaml +85 -4
index fa4440141b05..d2bc0e366d09 100644
@@ -641,13 +641,14 @@ attribute-sets:
         name: fmsg-obj-value-type
         type: u8
         enum: fmsg-obj-value-type
-
-      # TODO: fill in the attributes in between
-
+      -
+        name: fmsg-obj-value-data
+        type: sub-message
+        sub-message: dl-fmsg-obj-value-data-msg
+        selector: fmsg-obj-value-type
       -
         name: health-reporter
         type: nest
-        value: 114
         nested-attributes: dl-health-reporter
       -
         name: health-reporter-name
@@ -1226,6 +1227,10 @@ attribute-sets:
         name: fmsg-nest-end
       -
         name: fmsg-obj-name
+      -
+        name: fmsg-obj-value-type
+      -
+        name: fmsg-obj-value-data
 
   -
     name: dl-health-reporter
@@ -1331,6 +1336,54 @@ attribute-sets:
         name: param-value-data
         type: flag
 
+  -
+    name: dl-fmsg-obj-value-data-u8-attrs
+    subset-of: devlink
+    attributes:
+      -
+        name: fmsg-obj-value-data
+        type: u8
+
+  -
+    name: dl-fmsg-obj-value-data-u32-attrs
+    subset-of: devlink
+    attributes:
+      -
+        name: fmsg-obj-value-data
+        type: u32
+
+  -
+    name: dl-fmsg-obj-value-data-u64-attrs
+    subset-of: devlink
+    attributes:
+      -
+        name: fmsg-obj-value-data
+        type: u64
+
+  -
+    name: dl-fmsg-obj-value-data-flag-attrs
+    subset-of: devlink
+    attributes:
+      -
+        name: fmsg-obj-value-data
+        type: flag
+
+  -
+    name: dl-fmsg-obj-value-data-string-attrs
+    subset-of: devlink
+    attributes:
+      -
+        name: fmsg-obj-value-data
+        type: string
+
+  -
+    name: dl-fmsg-obj-value-data-binary-attrs
+    subset-of: devlink
+    attributes:
+      -
+        name: fmsg-obj-value-data
+        type: binary
+
 sub-messages:
   -
     name: dl-param-value-data-msg
@@ -1356,6 +1409,34 @@ sub-messages:
         attribute-set: dl-param-value-data-flag-attrs
         attribute-replace: true
 
+  -
+    name: dl-fmsg-obj-value-data-msg
+    formats:
+      -
+        value: u8
+        attribute-set: dl-fmsg-obj-value-data-u8-attrs
+        attribute-replace: true
+      -
+        value: u32
+        attribute-set: dl-fmsg-obj-value-data-u32-attrs
+        attribute-replace: true
+      -
+        value: u64
+        attribute-set: dl-fmsg-obj-value-data-u64-attrs
+        attribute-replace: true
+      -
+        value: flag
+        attribute-set: dl-fmsg-obj-value-data-flag-attrs
+        attribute-replace: true
+      -
+        value: string
+        attribute-set: dl-fmsg-obj-value-data-string-attrs
+        attribute-replace: true
+      -
+        value: binary
+        attribute-set: dl-fmsg-obj-value-data-binary-attrs
+        attribute-replace: true
+
 operations:
   enum-model: directional
   list:
Signature · 1 line
2.43.2
author
#31 lore raw

PATCH 13/13 netlink: specs: devlink: add missing nested devlink definitions

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Add missing nested devlink subspace definition with definition of two attributes using it.

---
 Documentation/netlink/specs/devlink.yaml | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
Documentation/netlink/specs/devlink.yaml +20 -4
index d2bc0e366d09..c416339b69a6 100644
@@ -853,13 +853,14 @@ attribute-sets:
         name: linecard-supported-types
         type: nest
         nested-attributes: dl-linecard-supported-types
-
-      # TODO: fill in the attributes in between
-
+      -
+        name: nested-devlink
+        type: nest
+        multi-attr: true
+        nested-attributes: dl-nested-devlink
       -
         name: selftests
         type: nest
-        value: 176
         nested-attributes: dl-selftest-id
       -
         name: rate-tx-priority
@@ -944,6 +945,10 @@ attribute-sets:
         type: bitfield32
         enum: port-fn-attr-cap
         enum-as-flags: True
+      -
+        name: devlink
+        type: nest
+        nested-attributes: dl-nested-devlink
 
   -
     name: dl-dpipe-tables
@@ -1288,6 +1293,17 @@ attribute-sets:
       -
         name: linecard-type
 
+  -
+    name: dl-nested-devlink
+    subset-of: devlink
+    attributes:
+      -
+        name: bus-name
+      -
+        name: dev-name
+      -
+        name: netns-id
+
   -
     name: dl-selftest-id
     name-prefix: devlink-attr-selftest-id-
Signature · 1 line
2.43.2
maintainer
#2 lore raw

Re: [patch net-next 01/13] tools: ynl: allow user to specify flag attr with bool values

In reply to Jiri Pirko

tools/net/ynl/lib/ynl.py class YnlFamily(SpecFamily): · line 463

Quoted 3 lines · On Mon, 19 Feb 2024 18:25:17 +0100 Jiri Pirko wrote:
         elif attr["type"] == 'flag':
tools/net/ynl/lib/ynl.py +2 -0
+            if value == False:
+                return b''

how about "if value:" ? It could also be null / None or some other "false" object.

maintainer
#6 lore raw

Re: [patch net-next 03/13] tools: ynl: allow user to pass enum string instead of scalar value

In reply to Jiri Pirko
Quoted 1 line · On Mon, 19 Feb 2024 18:25:19 +0100 Jiri Pirko wrote:

+ def _get_scalar(self, attr_spec, value):

It'd be cleaner to make it more symmetric with _decode_enum(), and call it _encode_enum().

maintainer
#10 lore raw

Re: [patch net-next 03/13] tools: ynl: allow user to pass enum string instead of scalar value

In reply to Jiri Pirko

tools/net/ynl/lib/ynl.py class YnlFamily(SpecFamily): · line 451

Quoted 4 lines · On Mon, 19 Feb 2024 18:25:19 +0100 Jiri Pirko wrote:
tools/net/ynl/lib/ynl.py +4 -0
+        if enum.type == 'flags' or attr_spec.get('enum-as-flags', False):
+            scalar = 0
+            for single_value in value:
+                scalar += enum.entries[single_value].user_value(as_flags = True)

If the user mistakenly passes a single value for a flag, rather than a set, this is going to generate a hard to understand error. How about we check isinstance(, str) and handle that directly, whether a flag or not.

maintainer
#15 lore raw

Re: [patch net-next 04/13] netlink: specs: allow sub-messages in genetlink-legacy

In reply to Jiri Pirko
Quoted 3 lines · On Mon, 19 Feb 2024 18:25:20 +0100 Jiri Pirko wrote:

Currently sub-messages are only supported in netlink-raw template. To be able to utilize them in devlink spec, allow them in genetlink-legacy as well.

Why missing in the commit message.

maintainer
#19 lore raw

Re: [patch net-next 06/13] tools: ynl: introduce attribute-replace for sub-message

In reply to Jiri Pirko
Quoted 11 lines · On Mon, 19 Feb 2024 18:25:22 +0100 Jiri Pirko wrote:

For devlink param, param-value-data attr is used by kernel to fill different attribute type according to param-type attribute value.

Currently the sub-message feature allows spec to embed custom message selected by another attribute. The sub-message is then nested inside the attr of sub-message type.

Benefit from the sub-message feature and extend it. Introduce attribute-replace spec flag by which the spec indicates that ynl should consider sub-message as not nested in the original attribute, but rather to consider the original attribute as the sub-message right away.

The "type agnostic" / generic style of devlink params and fmsg are contrary to YNL's direction and goals. YNL abstracts parsing and typing using external spec. devlink params and fmsg go in a different direction where all information is carried by netlink values and netlink typing is just to create "JSON-like" formatting. These are incompatible ideas, and combining these two abstractions in one library provides little value - devlink CLI already has an implementation for fmsg and params. YNL doesn't have to cover everything.

author
#3 lore raw

Re: [patch net-next 01/13] tools: ynl: allow user to specify flag attr with bool values

In reply to Jakub Kicinski
Quoted 7 lines · Mon, Feb 19, 2024 at 09:42:22PM CET, [email protected] wrote:

tools/net/ynl/lib/ynl.py class YnlFamily(SpecFamily): · line 463

Quoted 3 lines · On Mon, 19 Feb 2024 18:25:17 +0100 Jiri Pirko wrote:
         elif attr["type"] == 'flag':
tools/net/ynl/lib/ynl.py +2 -0
+            if value == False:
+                return b''

how about "if value:" ? It could also be null / None or some other "false" object.

Sure, why not.

author
#7 lore raw

Re: [patch net-next 03/13] tools: ynl: allow user to pass enum string instead of scalar value

In reply to Jakub Kicinski
Quoted 5 lines · Mon, Feb 19, 2024 at 09:49:14PM CET, [email protected] wrote:
Quoted 1 line · On Mon, 19 Feb 2024 18:25:19 +0100 Jiri Pirko wrote:

+ def _get_scalar(self, attr_spec, value):

It'd be cleaner to make it more symmetric with _decode_enum(), and call it _encode_enum().

That is misleading name, as it does not have to be enum.

author
#11 lore raw

Re: [patch net-next 03/13] tools: ynl: allow user to pass enum string instead of scalar value

In reply to Jakub Kicinski
Quoted 10 lines · Mon, Feb 19, 2024 at 09:51:00PM CET, [email protected] wrote:

tools/net/ynl/lib/ynl.py class YnlFamily(SpecFamily): · line 451

Quoted 4 lines · On Mon, 19 Feb 2024 18:25:19 +0100 Jiri Pirko wrote:
tools/net/ynl/lib/ynl.py +4 -0
+        if enum.type == 'flags' or attr_spec.get('enum-as-flags', False):
+            scalar = 0
+            for single_value in value:
+                scalar += enum.entries[single_value].user_value(as_flags = True)

If the user mistakenly passes a single value for a flag, rather than a set, this is going to generate a hard to understand error. How about we check isinstance(, str) and handle that directly, whether a flag or not.

Yeah, I was thinking about that as well. But as the flag output is always list, here we expect also always list. I can either do what you suggest of Errout with some sane message in case of the variable is not a list. I didn't find ynl to be particularly forgiving in case of input and error messages, that is why I didn't bother here.

author
#16 lore raw

Re: [patch net-next 04/13] netlink: specs: allow sub-messages in genetlink-legacy

In reply to Jakub Kicinski
Quoted 6 lines · Mon, Feb 19, 2024 at 09:51:18PM CET, [email protected] wrote:
Quoted 3 lines · On Mon, 19 Feb 2024 18:25:20 +0100 Jiri Pirko wrote:

Currently sub-messages are only supported in netlink-raw template. To be able to utilize them in devlink spec, allow them in genetlink-legacy as well.

Why missing in the commit message.

Sure.

author
#20 lore raw

Re: [patch net-next 06/13] tools: ynl: introduce attribute-replace for sub-message

In reply to Jakub Kicinski
Quoted 8 lines · Mon, Feb 19, 2024 at 11:52:04PM CET, [email protected] wrote:
Quoted 7 lines · On Mon, 19 Feb 2024 18:25:22 +0100 Jiri Pirko wrote:

For devlink param, param-value-data attr is used by kernel to fill different attribute type according to param-type attribute value.

Currently the sub-message feature allows spec to embed custom message selected by another attribute. The sub-message is then nested inside the attr of sub-message type.

Quoted 7 lines
Quoted 4 lines

Benefit from the sub-message feature and extend it. Introduce attribute-replace spec flag by which the spec indicates that ynl should consider sub-message as not nested in the original attribute, but rather to consider the original attribute as the sub-message right away.

The "type agnostic" / generic style of devlink params and fmsg are contrary to YNL's direction and goals. YNL abstracts parsing

True, but that's what we have. Similar to what we have in TC where sub-messages are present, that is also against ynl's direction and goals.

Quoted 3 lines

and typing using external spec. devlink params and fmsg go in a different direction where all information is carried by netlink values and netlink typing is just to create "JSON-like" formatting.

Only fmsg, not params.

Quoted 4 lines

These are incompatible ideas, and combining these two abstractions in one library provides little value - devlink CLI already has an implementation for fmsg and params. YNL doesn't have to cover everything.

True. In this patchset, I'm just using the existing sub-message infrastructure with a bit of extension. The json-like thing of fmsg is ignored, I don't try to reconstruct json from netlink message of fmsg.

maintainer
#8 lore raw

Re: [patch net-next 03/13] tools: ynl: allow user to pass enum string instead of scalar value

In reply to Jiri Pirko
Quoted 4 lines · On Tue, 20 Feb 2024 08:25:14 +0100 Jiri Pirko wrote:
Quoted 2 lines

It'd be cleaner to make it more symmetric with _decode_enum(), and call it _encode_enum().

That is misleading name, as it does not have to be enum.

It's a variant of a encode function using enum metadata.

maintainer
#12 lore raw

Re: [patch net-next 03/13] tools: ynl: allow user to pass enum string instead of scalar value

In reply to Jiri Pirko
Quoted 10 lines · On Tue, 20 Feb 2024 08:27:57 +0100 Jiri Pirko wrote:
Quoted 4 lines

If the user mistakenly passes a single value for a flag, rather than a set, this is going to generate a hard to understand error. How about we check isinstance(, str) and handle that directly, whether a flag or not.

Yeah, I was thinking about that as well. But as the flag output is always list, here we expect also always list. I can either do what you suggest of Errout with some sane message in case of the variable is not a list. I didn't find ynl to be particularly forgiving in case of input and error messages, that is why I didn't bother here.

It's not the same thing, but (without looking at the code IIRC) for multi-attr we do accept both a list and direct value. Here we don't have to be lenient in what we accept. Clear error message would be good enough.

Some of the sharp edges in Python YNL are because I very much anticipated the pyroute2 maintainer to do a proper implementation, and this tool was just a very crude PoC :D

maintainer
#21 lore raw

Re: [patch net-next 06/13] tools: ynl: introduce attribute-replace for sub-message

In reply to Jiri Pirko
Quoted 6 lines · On Tue, 20 Feb 2024 08:31:23 +0100 Jiri Pirko wrote:
Quoted 2 lines

The "type agnostic" / generic style of devlink params and fmsg are contrary to YNL's direction and goals. YNL abstracts parsing

True, but that's what we have. Similar to what we have in TC where sub-messages are present, that is also against ynl's direction and goals.

But TC and ip-link are raw netlink, meaning genetlink-legacy remains fairly straightforward. BTW since we currently have full parity in C code gen adding this series will break build for tools/net/ynl.

Plus ip-link is a really high value target. I had been pondering how to solve it myself. There's probably a hundred different implementations out there of container management systems which spawn veths using odd hacks because "netlink is scary". Once I find the time to finish rtnetlink codegen we can replace all the unholy libbpf netlink hacks with ynl, too.

So at this stage I'd really like to focus YNL on language coverage (adding more codegens), packaging and usability polish, not extending the spec definitions to cover not-so-often used corner cases. Especially those which will barely benefit because they are in themselves built to be an abstraction.

maintainer
#13 lore raw

Re: [patch net-next 03/13] tools: ynl: allow user to pass enum string instead of scalar value

In reply to Jakub Kicinski
Quoted 4 lines · Jakub Kicinski

Some of the sharp edges in Python YNL are because I very much anticipated the pyroute2 maintainer to do a proper implementation, and this tool was just a very crude PoC :D

Hah yeah, I looked at pyroute2 a while back and thought there was a bit of an impedance mismatch between the dynamic schema driven approach of ynl and the declarative / procedural code in iproute2. I think a code generator would be the way to target iproute2.

https://github.com/svinota/pyroute2/blob/34d0768f89fd232126c49e2f7c94e6da6582795b/pyroute2/netlink/rtnl/rtmsg.py#L102-L139

I find ynl to be a very useful tool when writing and testing spec files and have been happy to contribute to it for that purpose. I think we have started to remove some of the sharp edges, but there is more to do :-)

author
#22 lore raw

Re: [patch net-next 06/13] tools: ynl: introduce attribute-replace for sub-message

In reply to Jakub Kicinski
Quoted 19 lines · Wed, Feb 21, 2024 at 03:10:04AM CET, [email protected] wrote:
Quoted 6 lines · On Tue, 20 Feb 2024 08:31:23 +0100 Jiri Pirko wrote:
Quoted 2 lines

The "type agnostic" / generic style of devlink params and fmsg are contrary to YNL's direction and goals. YNL abstracts parsing

True, but that's what we have. Similar to what we have in TC where sub-messages are present, that is also against ynl's direction and goals.

But TC and ip-link are raw netlink, meaning genetlink-legacy remains fairly straightforward. BTW since we currently have full parity in C code gen adding this series will break build for tools/net/ynl.

Plus ip-link is a really high value target. I had been pondering how to solve it myself. There's probably a hundred different implementations out there of container management systems which spawn veths using odd hacks because "netlink is scary". Once I find the time to finish rtnetlink codegen we can replace all the unholy libbpf netlink hacks with ynl, too.

Quoted 5 lines

So at this stage I'd really like to focus YNL on language coverage (adding more codegens), packaging and usability polish, not extending the spec definitions to cover not-so-often used corner cases. Especially those which will barely benefit because they are in themselves built to be an abstraction.

That leaves devlink.yaml incomplete, which I'm not happy about. It is a legacy, it should be covered by genetlink-legacy I believe.

To undestand you correctly, should I wait until codegen for raw netlink is done and then to rebase-repost this? Or do you say this will never be acceptable?

author
#9 lore raw

Re: [patch net-next 03/13] tools: ynl: allow user to pass enum string instead of scalar value

In reply to Jakub Kicinski
Quoted 7 lines · Wed, Feb 21, 2024 at 02:55:56AM CET, [email protected] wrote:
Quoted 4 lines · On Tue, 20 Feb 2024 08:25:14 +0100 Jiri Pirko wrote:
Quoted 2 lines

It'd be cleaner to make it more symmetric with _decode_enum(), and call it _encode_enum().

That is misleading name, as it does not have to be enum.

It's a variant of a encode function using enum metadata.

Not really. "decode_enum()" is exactly that, it only works with enum case. Here, the enum is optional. If user passes scalar directly or if the attribute does not have "enum" defined, this has nothing to do with enum. But, as you wish.

maintainer
#23 lore raw

Re: [patch net-next 06/13] tools: ynl: introduce attribute-replace for sub-message

In reply to Jiri Pirko
Quoted 17 lines · On Wed, 21 Feb 2024 13:48:13 +0100 Jiri Pirko wrote:
Quoted 11 lines

But TC and ip-link are raw netlink, meaning genetlink-legacy remains fairly straightforward. BTW since we currently have full parity in C code gen adding this series will break build for tools/net/ynl.

Plus ip-link is a really high value target. I had been pondering how to solve it myself. There's probably a hundred different implementations out there of container management systems which spawn veths using odd hacks because "netlink is scary". Once I find the time to finish rtnetlink codegen we can replace all the unholy libbpf netlink hacks with ynl, too.

Quoted 5 lines

So at this stage I'd really like to focus YNL on language coverage (adding more codegens), packaging and usability polish, not extending the spec definitions to cover not-so-often used corner cases. Especially those which will barely benefit because they are in themselves built to be an abstraction.

Quoted 6 lines

That leaves devlink.yaml incomplete, which I'm not happy about. It is a legacy, it should be covered by genetlink-legacy I believe.

To undestand you correctly, should I wait until codegen for raw netlink is done and then to rebase-repost this? Or do you say this will never be acceptable?

It'd definitely not acceptable before the rtnetlink C codegen is complete, and at least two other code gens for genetlink-legacy. At that point we can reconsider complicating the schema further.

author
#24 lore raw

Re: [patch net-next 06/13] tools: ynl: introduce attribute-replace for sub-message

Quoted 21 lines · Wed, Feb 21, 2024 at 07:45:05PM CET, [email protected] wrote:
Quoted 20 lines · On Wed, 21 Feb 2024 13:48:13 +0100 Jiri Pirko wrote:
Quoted 11 lines

But TC and ip-link are raw netlink, meaning genetlink-legacy remains fairly straightforward. BTW since we currently have full parity in C code gen adding this series will break build for tools/net/ynl.

Plus ip-link is a really high value target. I had been pondering how to solve it myself. There's probably a hundred different implementations out there of container management systems which spawn veths using odd hacks because "netlink is scary". Once I find the time to finish rtnetlink codegen we can replace all the unholy libbpf netlink hacks with ynl, too.

Quoted 5 lines

So at this stage I'd really like to focus YNL on language coverage (adding more codegens), packaging and usability polish, not extending the spec definitions to cover not-so-often used corner cases. Especially those which will barely benefit because they are in themselves built to be an abstraction.

That leaves devlink.yaml incomplete, which I'm not happy about. It is a legacy, it should be covered by genetlink-legacy I believe.

Quoted 7 lines
Quoted 3 lines

To undestand you correctly, should I wait until codegen for raw netlink is done and then to rebase-repost this? Or do you say this will never be acceptable?

It'd definitely not acceptable before the rtnetlink C codegen is complete, and at least two other code gens for genetlink-legacy. At that point we can reconsider complicating the schema further.

Okay, will keep it in the cupboard for now. I would definitelly love to get the devlink.yaml complete. Next step is to generate the uapi header from it replacing the existing one.