Skip to contentSkip to conversation

tools/net/ynl: Add dynamic selector for options attrs

RFC PATCH In review Donald Hunter 2 participants 11 messages Nov 29, 2023 – Nov 30, 2023

Subsystems (4)
lore
Share & tools
lore

Donald Hunter

author maintainer
#0 lore raw

cover tools/net/ynl: Add dynamic selector for options attrs

This patchset adds a dynamic selector mechanism to YNL for kind-specific options attributes. I am sending this as an RFC solicit feedback on a couple of issues before I complete the patchset.

I started adding this feature for the rt_link spec which is monomorphic, i.e. the kind-specific 'data' attribute is always a nest. The selector looked like this:

-

    name: data
    type: dynamic
    selector:
      attribute: kind
      list:
        -
          value: bridge
          nested-attributes: linkinfo-bridge-attrs
        -
          value: erspan
          nested-attributes: linkinfo-gre-attrs

Then I started working on tc and found that the 'options' attribute is poymorphic. It is typically either a C struct or a nest. So I extended the dynamic selector to include a 'type' field and type-specific sub-fields:

-

    name: options
    type: dynamic
    selector:
      attribute: kind
      list:
        -
          value: bfifo
          type: binary
          struct: tc-fifo-qopt
        -
          value: cake
          type: nest
          nested-attributes: tc-cake-attrs
        -
          value: cbs
          type: nest
          nested-attributes: tc-cbs-attrs

Then I encountered 'netem' which has a nest with a C struct header. I realised that maybe my mental model had been wrong and that all cases could be supported by a nest type with an optional fixed-header followed by zero or more nlattrs.

-
value: netem
type: nest
fixed-header: tc-netem-qopt
nested-attributes: tc-netem-attrs

Perhaps it is attribute-sets in general that should have an optional fixed-header, which would also work for fixed-headers at the start of genetlink messages. I originally added fixed-header support to operations for genetlink, but fixed headers on attribute sets would work for all these cases.

I now see a few possible ways forward and would like feedback on the preferred approach:

1. Simplify the current patchset to implement fixed-header & nest support in the dynamic selector. This would leave existing fixed-header support for messages unchanged. We could drop the 'type' field.

-
value: netem
fixed-header: tc-netem-qopt
nested-attributes: tc-netem-attrs

2. Keep the 'type' field and support for the 'binary' type which is useful for specifying nests with unknown attribute spaces. An alternative would be to default to 'binary' behaviour if there is no selector entry.

3. Refactor the existing fixed-header support to be an optional part of all attribute sets instead of just messages (in legacy and raw specs) and dynamic attribute nests (in raw specs).

attribute-sets:

     -
       name: tc-netem-attrs
       fixed-header: tc-netem-qopt
       attributes:
         ...

Thoughts?

Patch 1 adds missing scalars to the netlink-raw schema Patch 2 and 3 add dynamic nest support to the schema and ynl Patches 4 and 5 contain specs that use dynamic nests Patch 6 adds support for nests with a fixed-header

Donald Hunter (6):
doc/netlink: Add bitfield32, s8, s16 to the netlink-raw schema doc/netlink: Add a nest selector to netlink-raw schema tools/net/ynl: Add dynamic attribute decoding to ynl doc/netlink/specs: add dynamic nest selector for rt_link data doc/netlink/specs: Add a spec for tc
tools/net/ynl: Add optional fixed-header to dynamic nests

 Documentation/netlink/netlink-raw.yaml   |   43 +-
 Documentation/netlink/specs/rt_link.yaml |  278 ++-
 Documentation/netlink/specs/tc.yaml      | 2074 ++++++++++++++++++++++
 tools/net/ynl/lib/nlspec.py              |   27 +
 tools/net/ynl/lib/ynl.py                 |   54 +-
 5 files changed, 2462 insertions(+), 14 deletions(-)
 create mode 100644 Documentation/netlink/specs/tc.yaml
Signature · 1 line
2.42.0
author maintainer
#1 lore raw

RFC PATCH 1/6 doc/netlink: Add bitfield32, s8, s16 to the netlink-raw schema

The netlink-raw schema was not updated when bitfield32 was added to the genetlink-legacy schema. It is needed for rtnetlink families.

s8 and s16 were also missing.

---
 Documentation/netlink/netlink-raw.yaml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/netlink/netlink-raw.yaml +2 -1
index 775cce8c548a..ad5395040765 100644
@@ -200,7 +200,8 @@ properties:
                 type: string
               type: &attr-type
                 description: The netlink attribute type
-                enum: [ unused, pad, flag, binary, u8, u16, u32, u64, s32, s64,
+                enum: [ unused, pad, flag, binary, bitfield32,
+                        u8, u16, u32, u64, s8, s16, s32, s64,
                         string, nest, array-nest, nest-type-value ]
               doc:
                 description: Documentation of the attribute.
Signature · 1 line
2.42.0
author maintainer
#2 lore raw

RFC PATCH 2/6 doc/netlink: Add a nest selector to netlink-raw schema

In reply to Donald Hunter

Add a 'dynamic' attribute type with a selector that declares how to choose the attribute-space for nested attributes. Use the value of another attribute as the selector key. For example if the following attribute has already been decoded:

{ "kind": "gre" }

then the following selector:

selector:

    attribute: kind
    list:
      -
        value: bridge
        type: nest
        nested-attributes: linkinfo-bridge-attrs
      -
        value: gre
        type: nest
        nested-attributes: linkinfo-gre-attrs
      -
        value: geneve
        type: nest
        nested-attributes: linkinfo-geneve-attrs

would decode the value as nested attributes, using the 'linkinfo-gre-attrs' attribute space.

This approach was chosen so that different value types can be handled by the same selector, allowing a mix of e.g. nest, struct and binary.

---
 Documentation/netlink/netlink-raw.yaml | 38 +++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)
Documentation/netlink/netlink-raw.yaml +37 -1
index ad5395040765..62061e180f8f 100644
@@ -202,7 +202,7 @@ properties:
                 description: The netlink attribute type
                 enum: [ unused, pad, flag, binary, bitfield32,
                         u8, u16, u32, u64, s8, s16, s32, s64,
-                        string, nest, array-nest, nest-type-value ]
+                        string, nest, array-nest, nest-type-value, dynamic ]
               doc:
                 description: Documentation of the attribute.
                 type: string
@@ -261,6 +261,42 @@ properties:
                 description: Name of the struct type used for the attribute.
                 type: string
               # End genetlink-legacy
+              # Start netlink-raw
+              selector:
+                description:
+                  Map of attribute definitions for dynamic selection of type
+                  specific attribute spaces.
+                type: object
+                required: [ attribute, list ]
+                additionalProperties: false
+                properties:
+                  attribute:
+                    description:
+                      Name of the attribute that contains the type identifier
+                      string.
+                    type: string
+                  list:
+                    type: array
+                    items:
+                      type: object
+                      required: [ value, type ]
+                      additionalProperties: false
+                      properties:
+                        value:
+                          description: Type identifier string to match.
+                          type: string
+                        type:
+                          description: The netlink attribute type.
+                          enum: [ binary, nest ]
+                        nested-attributes:
+                          description:
+                            Name of the sub-space used inside the attribute.
+                          type: string
+                        struct:
+                          description:
+                            Name of the struct type used for the attribute.
+                          type: string
+              # End netlink-raw
 
       # Make sure name-prefix does not appear in subsets (subsets inherit naming)
       dependencies:
Signature · 1 line
2.42.0
author maintainer
#3 lore raw

RFC PATCH 3/6 tools/net/ynl: Add dynamic attribute decoding to ynl

In reply to Donald Hunter

Implement dynamic attribute space selection and decoding to the ynl library.

Encode support is not yet implemented. Support for dynamic selectors at a different nest level from the key attribute is not yet supported.

---
 tools/net/ynl/lib/nlspec.py | 27 +++++++++++++++++++++++++++
 tools/net/ynl/lib/ynl.py    | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+)
tools/net/ynl/lib/nlspec.py +27 -0
index 92889298b197..c32c85ddf8fb 100644
@@ -142,6 +142,29 @@ class SpecEnumSet(SpecElement):
             mask += e.user_value(as_flags)
         return mask
 
+class SpecDynAttr(SpecElement):
+    """ Single Dynamic Netlink atttribute type
+
+    Represents a choice of dynamic attribute type within an attr space.
+
+    Attributes:
+        value         attribute value to match against dynamic type selector
+        struct_name   string, name of struct definition
+        sub_type      string, name of sub type
+        len           integer, optional byte length of binary types
+        display_hint  string, hint to help choose format specifier
+                      when displaying the value
+    """
+    def __init__(self, family, parent, yaml):
+        super().__init__(family, yaml)
+
+        self.value = yaml.get('value')
+        self.struct_name = yaml.get('struct')
+        self.sub_type = yaml.get('sub-type')
+        self.byte_order = yaml.get('byte-order')
+        self.len = yaml.get('len')
+        self.display_hint = yaml.get('display-hint')
+
 
 class SpecAttr(SpecElement):
     """ Single Netlink atttribute type
@@ -173,9 +196,13 @@ class SpecAttr(SpecElement):
         self.byte_order = yaml.get('byte-order')
         self.len = yaml.get('len')
         self.display_hint = yaml.get('display-hint')
+        self.dynamic_types = {}
 
         self.is_auto_scalar = self.type == "sint" or self.type == "uint"
 
+        if 'selector' in yaml:
+            for item in yaml.get('selector').get('list', []):
+                self.dynamic_types[item['value']] = SpecDynAttr(family, self, item)
 
 class SpecAttrSet(SpecElement):
     """ Netlink Attribute Set class.
tools/net/ynl/lib/ynl.py +32 -0
index 92995bca14e1..5ce01ce37573 100644
@@ -549,6 +549,36 @@ class YnlFamily(SpecFamily):
         else:
             rsp[name] = [decoded]
 
+    def _resolve_selector(self, attr_spec, vals):
+        if 'selector' in attr_spec:
+            selector = attr_spec['selector']
+            key = selector['attribute']
+            if key in vals:
+                value = vals[key]
+                if value in attr_spec.dynamic_types:
+                    spec = attr_spec.dynamic_types[value]
+                    return spec
+                else:
+                    raise Exception(f"No entry for {key}={value} in selector for '{attr_spec['name']}'")
+            else:
+                raise Exception(f"There is no value for {key} to use in selector for '{attr_spec['name']}'")
+        else:
+            raise Exception("type=dynamic requires a selector in '{attr_spec['name']}'")
+
+    def _decode_dynamic(self, attr, attr_spec, rsp):
+        dyn_spec = self._resolve_selector(attr_spec, rsp)
+        if dyn_spec['type'] == 'binary':
+            decoded = self._decode_binary(attr, dyn_spec)
+        elif dyn_spec['type'] == 'nest':
+            attr_space = dyn_spec['nested-attributes']
+            if attr_space in self.attr_sets:
+                decoded = self._decode(NlAttrs(attr.raw), attr_space)
+            else:
+                raise Exception(f"Unknown attribute-set '{attr_space}'")
+        else:
+            raise Exception(f"Unknown type '{spec['type']}' for value '{value}'")
+        return decoded
+
     def _decode(self, attrs, space):
         if space:
             attr_space = self.attr_sets[space]
@@ -586,6 +616,8 @@ class YnlFamily(SpecFamily):
                     value = self._decode_enum(value, attr_spec)
                     selector = self._decode_enum(selector, attr_spec)
                 decoded = {"value": value, "selector": selector}
+            elif attr_spec["type"] == 'dynamic':
+                decoded = self._decode_dynamic(attr, attr_spec, rsp)
             else:
                 if not self.process_unknown:
                     raise Exception(f'Unknown {attr_spec["type"]} with name {attr_spec["name"]}')
Signature · 1 line
2.42.0
author maintainer
#4 lore raw

RFC PATCH 4/6 doc/netlink/specs: add dynamic nest selector for rt_link data

In reply to Donald Hunter

Switch to using a dynamic nest selector in the rt_link spec for the link-specific 'data' attribute.

---
 Documentation/netlink/specs/rt_link.yaml | 278 ++++++++++++++++++++++-
 1 file changed, 274 insertions(+), 4 deletions(-)
Documentation/netlink/specs/rt_link.yaml +274 -4
index 1ec6cb6a0d96..498d3ce38c91 100644
@@ -965,8 +965,46 @@ attribute-sets:
         type: string
       -
         name: data
-        type: binary
-        # kind specific nest, e.g. linkinfo-bridge-attrs
+        type: dynamic
+        selector:
+          attribute: kind
+          list:
+            -
+              value: bridge
+              type: nest
+              nested-attributes: linkinfo-bridge-attrs
+            -
+              value: erspan
+              type: nest
+              nested-attributes: linkinfo-gre-attrs
+            -
+              value: gre
+              type: nest
+              nested-attributes: linkinfo-gre-attrs
+            -
+              value: gretap
+              type: nest
+              nested-attributes: linkinfo-gre-attrs
+            -
+              value: geneve
+              type: nest
+              nested-attributes: linkinfo-geneve-attrs
+            -
+              value: ipip
+              type: nest
+              nested-attributes: linkinfo-iptun-attrs
+            -
+              value: sit
+              type: nest
+              nested-attributes: linkinfo-iptun-attrs
+            -
+              value: tun
+              type: nest
+              nested-attributes: linkinfo-tun-attrs
+            -
+              value: vrf
+              type: nest
+              nested-attributes: linkinfo-vrf-attrs
       -
         name: xstats
         type: binary
@@ -975,10 +1013,10 @@ attribute-sets:
         type: string
       -
         name: slave-data
-        type: binary
-        # kind specific nest
+        type: binary # kind specific nest
   -
     name: linkinfo-bridge-attrs
+    name-prefix: ifla-br-
     attributes:
       -
         name: forward-delay
@@ -1122,6 +1160,238 @@ attribute-sets:
       -
         name: mcast-querier-state
         type: binary
+  -
+    name: linkinfo-gre-attrs
+    name-prefix: ifla-gre-
+    attributes:
+      -
+        name: link
+        type: u32
+      -
+        name: iflags
+        type: u16
+      -
+        name: oflags
+        type: u16
+      -
+        name: ikey
+        type: u32
+      -
+        name: okey
+        type: u32
+      -
+        name: local
+        type: binary
+        display-hint: ipv4
+      -
+        name: remote
+        type: binary
+        display-hint: ipv4
+      -
+        name: ttl
+        type: u8
+      -
+        name: tos
+        type: u8
+      -
+        name: pmtudisc
+        type: u8
+      -
+        name: encap-limit
+        type: u32
+      -
+        name: flowinfo
+        type: u32
+      -
+        name: flags
+        type: u32
+      -
+        name: encap-type
+        type: u16
+      -
+        name: encap-flags
+        type: u16
+      -
+        name: encap-sport
+        type: u16
+      -
+        name: encap-dport
+        type: u16
+      -
+        name: collect-metadata
+        type: flag
+      -
+        name: ignore-df
+        type: u8
+      -
+        name: fwmark
+        type: u32
+      -
+        name: erspan-index
+        type: u32
+      -
+        name: erspan-ver
+        type: u8
+      -
+        name: erspan-dir
+        type: u8
+      -
+        name: erspan-hwid
+        type: u16
+  -
+    name: linkinfo-geneve-attrs
+    name-prefix: ifla-geneve-
+    attributes:
+      -
+        name: id
+        type: u32
+      -
+        name: remote
+        type: binary
+        display-hint: ipv4
+      -
+        name: ttl
+        type: u8
+      -
+        name: tos
+        type: u8
+      -
+        name: port
+        type: u16
+      -
+        name: collect-metadata
+        type: flag
+      -
+        name: remote6
+        type: binary
+        display-hint: ipv6
+      -
+        name: udp-csum
+        type: u8
+      -
+        name: udp-zero-csum6-tx
+        type: u8
+      -
+        name: udp-zero-csum6-rx
+        type: u8
+      -
+        name: label
+        type: u32
+      -
+        name: ttl-inherit
+        type: u8
+      -
+        name: df
+        type: u8
+      -
+        name: inner-proto-inherit
+        type: flag
+  -
+    name: linkinfo-iptun-attrs
+    name-prefix: ifla-iptun-
+    attributes:
+      -
+        name: link
+        type: u32
+      -
+        name: local
+        type: binary
+        display-hint: ipv4
+      -
+        name: remote
+        type: binary
+        display-hint: ipv4
+      -
+        name: ttl
+        type: u8
+      -
+        name: tos
+        type: u8
+      -
+        name: encap-limit
+        type: u8
+      -
+        name: flowinfo
+        type: u32
+      -
+        name: flags
+        type: u16
+      -
+        name: proto
+        type: u8
+      -
+        name: pmtudisc
+        type: u8
+      -
+        name: 6rd-prefix
+        type: binary
+        display-hint: ipv6
+      -
+        name: 6rd-relay-prefix
+        type: binary
+        display-hint: ipv4
+      -
+        name: 6rd-prefixlen
+        type: u16
+      -
+        name: 6rd-relay-prefixlen
+        type: u16
+      -
+        name: encap-type
+        type: u16
+      -
+        name: encap-flags
+        type: u16
+      -
+        name: encap-sport
+        type: u16
+      -
+        name: encap-dport
+        type: u16
+      -
+        name: collect-metadata
+        type: flag
+      -
+        name: fwmark
+        type: u32
+  -
+    name: linkinfo-tun-attrs
+    name-prefix: ifla-tun-
+    attributes:
+      -
+        name: owner
+        type: u32
+      -
+        name: group
+        type: u32
+      -
+        name: type
+        type: u8
+      -
+        name: pi
+        type: u8
+      -
+        name: vnet-hdr
+        type: u8
+      -
+        name: persist
+        type: u8
+      -
+        name: multi-queue
+        type: u8
+      -
+        name: num-queues
+        type: u32
+      -
+        name: num-disabled-queues
+        type: u32
+  -
+    name: linkinfo-vrf-attrs
+    name-prefix: ifla-vrf-
+    attributes:
+      -
+        name: table
+        type: u32
   -
     name: xdp-attrs
     attributes:
Signature · 1 line
2.42.0
author maintainer
#5 lore raw

RFC PATCH 5/6 doc/netlink/specs: Add a spec for tc

In reply to Donald Hunter

This is a work-in-progress spec for tc that covers:
- most of the qdiscs
- the flower classifier
- new, del, get for qdisc, chain, class and filter

Notable omissions:
- most of the stats attrs are left as binary blobs
- notifications are not yet implemented

---
 Documentation/netlink/specs/tc.yaml | 2074 +++++++++++++++++++++++++++
 1 file changed, 2074 insertions(+)
 create mode 100644 Documentation/netlink/specs/tc.yaml
Documentation/netlink/specs/tc.yaml new file +2073 -0
new file mode 100644
index 000000000000..885761e2c97a
@@ -0,0 +1,2073 @@
+# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
+
+name: tc
+protocol: netlink-raw
+protonum: 0
+
+doc:
+  Netlink raw family for tc qdisc, chain, class and filter configuration
+  over rtnetlink.
+
+definitions:
+  -
+    name: tcmsg
+    type: struct
+    members:
+      -
+        name: family
+        type: u8
+      -
+        name: pad1
+        type: u8
+      -
+        name: pad2
+        type: u16
+      -
+        name: ifindex
+        type: s32
+      -
+        name: handle
+        type: u32
+      -
+        name: parent
+        type: u32
+      -
+        name: info
+        type: u32
+  -
+    name: tc-cls-flags
+    type: flags
+    entries:
+      - skip-hw
+      - skip-sw
+      - in-hw
+      - not-in-nw
+      - verbose
+  -
+    name: tc-stats
+    type: struct
+    members:
+      -
+        name: bytes
+        type: u64
+      -
+        name: packets
+        type: u32
+      -
+        name: drops
+        type: u32
+      -
+        name: overlimits
+        type: u32
+      -
+        name: bps
+        type: u32
+      -
+        name: pps
+        type: u32
+      -
+        name: qlen
+        type: u32
+      -
+        name: backlog
+        type: u32
+  -
+    name: tc-cbs-qopt
+    type: struct
+    members:
+      -
+        name: offload
+        type: u8
+      -
+        name: pad
+        type: binary
+        len: 3
+      -
+        name: hicredit
+        type: s32
+      -
+        name: locredit
+        type: s32
+      -
+        name: idleslope
+        type: s32
+      -
+        name: sendslope
+        type: s32
+  -
+    name: tc-etf-qopt
+    type: struct
+    members:
+      -
+        name: delta
+        type: s32
+      -
+        name: clockid
+        type: s32
+      -
+        name: flags
+        type: s32
+  -
+    name: tc-fifo-qopt
+    type: struct
+    members:
+      -
+        name: limit
+        type: u32
+  -
+    name: tc-htb-opt
+    type: struct
+    members:
+      -
+        name: rate
+        type: binary
+        len: 12
+      -
+        name: ceil
+        type: binary
+        len: 12
+      -
+        name: buffer
+        type: u32
+      -
+        name: cbuffer
+        type: u32
+      -
+        name: quantum
+        type: u32
+      -
+        name: level
+        type: u32
+      -
+        name: prio
+        type: u32
+  -
+    name: tc-htb-glob
+    type: struct
+    members:
+      -
+        name: version
+        type: u32
+      -
+        name: rate2quantum
+        type: u32
+      -
+        name: defcls
+        type: u32
+      -
+        name: debug
+        type: u32
+      -
+        name: direct-pkts
+        type: u32
+  -
+    name: tc-gred-qopt
+    type: struct
+    members:
+      -
+        name: limit
+        type: u32
+      -
+        name: qth-min
+        type: u32
+      -
+        name: qth-max
+        type: u32
+      -
+        name: DP
+        type: u32
+      -
+        name: backlog
+        type: u32
+      -
+        name: qave
+        type: u32
+      -
+        name: forced
+        type: u32
+      -
+        name: early
+        type: u32
+      -
+        name: other
+        type: u32
+      -
+        name: pdrop
+        type: u32
+      -
+        name: Wlog
+        type: u8
+      -
+        name: Plog
+        type: u8
+      -
+        name: Scell_log
+        type: u8
+      -
+        name: prio
+        type: u8
+      -
+        name: packets
+        type: u32
+      -
+        name: bytesin
+        type: u32
+  -
+    name: tc-gred-sopt
+    type: struct
+    members:
+      -
+        name: DPs
+        type: u32
+      -
+        name: def_DP
+        type: u32
+      -
+        name: grio
+        type: u8
+      -
+        name: flags
+        type: u8
+      -
+        name: pad1
+        type: u16
+  -
+    name: tc-hfsc-qopt
+    type: struct
+    members:
+      -
+        name: defcls
+        type: u16
+  -
+    name: tc-mqprio-qopt
+    type: struct
+    members:
+      -
+        name: num-tc
+        type: u8
+      -
+        name: prio-tc-map
+        type: binary
+        len: 16
+      -
+        name: hw
+        type: u8
+      -
+        name: count
+        type: binary
+        len: 32
+      -
+        name: offset
+        type: binary
+        len: 32
+  -
+    name: tc-multiq-qopt
+    type: struct
+    members:
+      -
+        name: bands
+        type: u16
+      -
+        name: max-bands
+        type: u16
+  -
+    name: tc-netem-qopt
+    type: struct
+    members:
+      -
+        name: latency
+        type: u32
+      -
+        name: limit
+        type: u32
+      -
+        name: loss
+        type: u32
+      -
+        name: gap
+        type: u32
+      -
+        name: duplicate
+        type: u32
+      -
+        name: jitter
+        type: u32
+  -
+    name: tc-prio-qopt
+    type: struct
+    members:
+      -
+        name: bands
+        type: u16
+      -
+        name: priomap
+        type: binary
+        len: 16
+  -
+    name: tc-red-qopt
+    type: struct
+    members:
+      -
+        name: limit
+        type: u32
+      -
+        name: qth-min
+        type: u32
+      -
+        name: qth-max
+        type: u32
+      -
+        name: Wlog
+        type: u8
+      -
+        name: Plog
+        type: u8
+      -
+        name: Scell-log
+        type: u8
+      -
+        name: flags
+        type: u8
+  -
+    name: tc-sfb-qopt
+    type: struct
+    members:
+      -
+        name: rehash-interval
+        type: u32
+      -
+        name: warmup-time
+        type: u32
+      -
+        name: max
+        type: u32
+      -
+        name: bin-size
+        type: u32
+      -
+        name: increment
+        type: u32
+      -
+        name: decrement
+        type: u32
+      -
+        name: limit
+        type: u32
+      -
+        name: penalty-rate
+        type: u32
+      -
+        name: penalty-burst
+        type: u32
+  -
+    name: tc-sfq-qopt-v1 # TODO nested structs
+    type: struct
+    members:
+      -
+        name: quantum
+        type: u32
+      -
+        name: perturb-period
+        type: s32
+      -
+        name: limit
+        type: u32
+      -
+        name: divisor
+        type: u32
+      -
+        name: flows
+        type: u32
+      -
+        name: depth
+        type: u32
+      -
+        name: headdrop
+        type: u32
+      -
+        name: limit
+        type: u32
+      -
+        name: qth-min
+        type: u32
+      -
+        name: qth-mac
+        type: u32
+      -
+        name: Wlog
+        type: u8
+      -
+        name: Plog
+        type: u8
+      -
+        name: Scell-log
+        type: u8
+      -
+        name: flags
+        type: u8
+      -
+        name: max-P
+        type: u32
+      -
+        name: prob-drop
+        type: u32
+      -
+        name: forced-drop
+        type: u32
+      -
+        name: prob-mark
+        type: u32
+      -
+        name: forced-mark
+        type: u32
+      -
+        name: prob-mark-head
+        type: u32
+      -
+        name: forced-mark-head
+        type: u32
+  -
+    name: tc-tbf-qopt
+    type: struct
+    members:
+      -
+        name: rate
+        type: binary # TODO nested struct tc_ratespec
+        len: 12
+      -
+        name: peakrate
+        type: binary # TODO nested struct tc_ratespec
+        len: 12
+      -
+        name: limit
+        type: u32
+      -
+        name: buffer
+        type: u32
+      -
+        name: mtu
+        type: u32
+  -
+    name: tc-sizespec
+    type: struct
+    members:
+      -
+        name: cell-log
+        type: u8
+      -
+        name: size-log
+        type: u8
+      -
+        name: cell-align
+        type: s16
+      -
+        name: overhead
+        type: s32
+      -
+        name: linklayer
+        type: u32
+      -
+        name: mpu
+        type: u32
+      -
+        name: mtu
+        type: u32
+      -
+        name: tsize
+        type: u32
+  -
+    name: gnet-estimator
+    type: struct
+    members:
+      -
+        name: interval
+        type: s8
+      -
+        name: ewma-log
+        type: u8
+attribute-sets:
+  -
+    name: tc-attrs
+    attributes:
+      -
+        name: kind
+        type: string
+      -
+        name: options
+        type: dynamic
+        selector:
+          attribute: kind
+          list:
+            -
+              value: bfifo
+              type: binary
+              struct: tc-fifo-qopt
+            -
+              value: cake
+              type: nest
+              nested-attributes: tc-cake-attrs
+            -
+              value: cbs
+              type: nest
+              nested-attributes: tc-cbs-attrs
+            -
+              value: choke
+              type: nest
+              nested-attributes: tc-choke-attrs
+            -
+              value: clsact
+              type: binary # empty nest
+            -
+              value: codel
+              type: nest
+              nested-attributes: tc-codel-attrs
+            -
+              value: drr
+              type: binary # TODO
+            -
+              value: etf
+              type: nest
+              nested-attributes: tc-etf-attrs
+            -
+              value: ets
+              type: nest
+              nested-attributes: tc-ets-attrs
+            -
+              value: fq
+              type: nest
+              nested-attributes: tc-fq-attrs
+            -
+              value: fq_codel
+              type: nest
+              nested-attributes: tc-fq-codel-attrs
+            -
+              value: fq_pie
+              type: nest
+              nested-attributes: tc-fq-pie-attrs
+            -
+              value: flower
+              type: nest
+              nested-attributes: tc-flower-attrs
+            -
+              value: gred
+              type: nest
+              nested-attributes: tc-gred-attrs
+            -
+              value: hfsc
+              type: binary
+              struct: tc-hfsc-qopt
+            -
+              value: hhf
+              type: nest
+              nested-attributes: tc-hhf-attrs
+            -
+              value: htb
+              type: nest
+              nested-attributes: tc-htb-attrs
+            -
+              value: ingress
+              type: binary # empty nest
+            -
+              value: mq
+              type: binary # TODO
+            -
+              value: mqprio
+              type: binary
+              struct: tc-mqprio-qopt
+            -
+              value: multiq
+              type: binary
+              struct: tc-multiq-qopt
+            -
+              value: netem
+              type: nest
+              fixed-header: tc-netem-qopt
+              nested-attributes: tc-netem-attrs
+            -
+              value: pfifo
+              type: binary
+              struct: tc-fifo-qopt
+            -
+              value: pfifo_fast
+              type: binary
+              struct: tc-prio-qopt
+            -
+              value: pfifo_head_drop
+              type: binary
+              struct: tc-fifo-qopt
+            -
+              value: pie
+              type: nest
+              nested-attributes: tc-pie-attrs
+            -
+              value: plug
+              type: binary # TODO
+            -
+              value: prio
+              type: binary
+              struct: tc-prio-qopt
+            -
+              value: qfq
+              type: binary # TODO
+            -
+              value: red
+              type: nest
+              nested-attributes: tc-red-attrs
+            -
+              value: sfb
+              type: binary
+              struct: tc-sfb-qopt
+            -
+              value: sfq
+              type: binary
+              struct: tc-sfq-qopt-v1
+            -
+              value: taprio
+              type: nest
+              nested-attributes: tc-taprio-attrs
+            -
+              value: tbf
+              type: nest
+              nested-attributes: tc-tbf-attrs
+      -
+        name: stats
+        type: binary
+        struct: tc-stats
+      -
+        name: xstats
+        type: binary
+      -
+        name: rate
+        type: binary
+        struct: gnet-estimator
+      -
+        name: fcnt
+        type: u32
+      -
+        name: stats2
+        type: nest
+        nested-attributes: tca-stats-attrs
+      -
+        name: stab
+        type: nest
+        nested-attributes: tca-stab-attrs
+      -
+        name: pad
+        type: pad
+      -
+        name: dump-invisible
+        type: flag
+      -
+        name: chain
+        type: u32
+      -
+        name: hw-offload
+        type: u8
+      -
+        name: ingress-block
+        type: u32
+      -
+        name: egress-block
+        type: u32
+      -
+        name: dump-flags
+        type: bitfield32
+      -
+        name: ext-warn-msg
+        type: string
+  -
+    name: tc-cake-attrs
+    attributes:
+      -
+        name: pad
+        type: pad
+      -
+        name: base-rate64
+        type: u64
+      -
+        name: diffserv-mode
+        type: u32
+      -
+        name: atm
+        type: u32
+      -
+        name: flow-mode
+        type: u32
+      -
+        name: overhead
+        type: u32
+      -
+        name: rtt
+        type: u32
+      -
+        name: target
+        type: u32
+      -
+        name: autorate
+        type: u32
+      -
+        name: memory
+        type: u32
+      -
+        name: nat
+        type: u32
+      -
+        name: raw
+        type: u32
+      -
+        name: wash
+        type: u32
+      -
+        name: mpu
+        type: u32
+      -
+        name: ingress
+        type: u32
+      -
+        name: ack-filter
+        type: u32
+      -
+        name: split-gso
+        type: u32
+      -
+        name: fwmark
+        type: u32
+  -
+    name: tc-cake-stats-attrs
+    attributes:
+      -
+        name: pad
+        type: pad
+      -
+        name: capacity-estimate64
+        type: u64
+      -
+        name: memory-limit
+        type: u32
+      -
+        name: memory-used
+        type: u32
+      -
+        name: avg-netoff
+        type: u32
+      -
+        name: min-netlen
+        type: u32
+      -
+        name: max-netlen
+        type: u32
+      -
+        name: min-adjlen
+        type: u32
+      -
+        name: max-adjlen
+        type: u32
+      -
+        name: tin-stats
+        type: binary
+      -
+        name: deficit
+        type: s32
+      -
+        name: cobalt-count
+        type: u32
+      -
+        name: dropping
+        type: u32
+      -
+        name: drop-next-us
+        type: s32
+      -
+        name: p-drop
+        type: u32
+      -
+        name: blue-timer-us
+        type: s32
+  -
+    name: tc-cbs-attrs
+    attributes:
+      -
+        name: parms
+        type: binary
+        struct: tc-cbs-qopt
+  -
+    name: tc-choke-attrs
+    attributes:
+      -
+        name: parms
+        type: binary
+        struct: tc-red-qopt
+      -
+        name: stab
+        type: binary
+      -
+        name: max-p
+        type: u32
+  -
+    name: tc-codel-attrs
+    attributes:
+      -
+        name: target
+        type: u32
+      -
+        name: limit
+        type: u32
+      -
+        name: interval
+        type: u32
+      -
+        name: ecn
+        type: u32
+      -
+        name: ce-threshold
+        type: u32
+  -
+    name: tc-flower-attrs
+    attributes:
+      -
+        name: classid
+        type: u32
+      -
+        name: indev
+        type: string
+      -
+        name: act
+        type: array-nest
+        nested-attributes: tc-act-attrs
+      -
+        name: key-eth-dst
+        type: binary
+        display-hint: mac
+      -
+        name: key-eth-dst-mask
+        type: binary
+        display-hint: mac
+      -
+        name: key-eth-src
+        type: binary
+        display-hint: mac
+      -
+        name: key-eth-src-mask
+        type: binary
+        display-hint: mac
+      -
+        name: key-eth-type
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-ip-proto
+        type: u8
+      -
+        name: key-ipv4-src
+        type: u32
+        byte-order: big-endian
+        display-hint: ipv4
+      -
+        name: key-ipv4-src-mask
+        type: u32
+        byte-order: big-endian
+        display-hint: ipv4
+      -
+        name: key-ipv4-dst
+        type: u32
+        byte-order: big-endian
+        display-hint: ipv4
+      -
+        name: key-ipv4-dst-mask
+        type: u32
+        byte-order: big-endian
+        display-hint: ipv4
+      -
+        name: key-ipv6-src
+        type: binary
+        display-hint: ipv6
+      -
+        name: key-ipv6-src-mask
+        type: binary
+        display-hint: ipv6
+      -
+        name: key-ipv6-dst
+        type: binary
+        display-hint: ipv6
+      -
+        name: key-ipv6-dst-mask
+        type: binary
+        display-hint: ipv6
+      -
+        name: key-tcp-src
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-tcp-dst
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-udp-src
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-udp-dst
+        type: u16
+        byte-order: big-endian
+      -
+        name: flags
+        type: u32
+        enum: tc-cls-flags
+        enum-as-flags: true
+      -
+        name: key-vlan-id
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-vlan-prio
+        type: u8
+      -
+        name: key-vlan-eth-type
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-enc-key-id
+        type: u32
+        byte-order: big-endian
+      -
+        name: key-enc-ipv4-src
+        type: u32
+        byte-order: big-endian
+        display-hint: ipv4
+      -
+        name: key-enc-ipv4-src-mask
+        type: u32
+        byte-order: big-endian
+        display-hint: ipv4
+      -
+        name: key-enc-ipv4-dst
+        type: u32
+        byte-order: big-endian
+        display-hint: ipv4
+      -
+        name: key-enc-ipv4-dst-mask
+        type: u32
+        byte-order: big-endian
+        display-hint: ipv4
+      -
+        name: key-enc-ipv6-src
+        type: binary
+        display-hint: ipv6
+      -
+        name: key-enc-ipv6-src-mask
+        type: binary
+        display-hint: ipv6
+      -
+        name: key-enc-ipv6-dst
+        type: binary
+        display-hint: ipv6
+      -
+        name: key-enc-ipv6-dst-mask
+        type: binary
+        display-hint: ipv6
+      -
+        name: key-tcp-src-mask
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-tcp-dst-mask
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-udp-src-mask
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-udp-dst-mask
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-sctp-src-mask
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-sctp-dst-mask
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-sctp-src
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-sctp-dst
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-enc-udp-src-port
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-enc-udp-src-port-mask
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-enc-udp-dst-port
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-enc-udp-dst-port-mask
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-flags
+        type: u32
+        byte-order: big-endian
+      -
+        name: key-flags-mask
+        type: u32
+        byte-order: big-endian
+      -
+        name: key-icmpv4-code
+        type: u8
+      -
+        name: key-icmpv4-code-mask
+        type: u8
+      -
+        name: key-icmpv4-type
+        type: u8
+      -
+        name: key-icmpv4-type-mask
+        type: u8
+      -
+        name: key-icmpv6-code
+        type: u8
+      -
+        name: key-icmpv6-code-mask
+        type: u8
+      -
+        name: key-icmpv6-type
+        type: u8
+      -
+        name: key-icmpv6-type-mask
+        type: u8
+      -
+        name: key-arp-sip
+        type: u32
+        byte-order: big-endian
+      -
+        name: key-arp-sip-mask
+        type: u32
+        byte-order: big-endian
+      -
+        name: key-arp-tip
+        type: u32
+        byte-order: big-endian
+      -
+        name: key-arp-tip-mask
+        type: u32
+        byte-order: big-endian
+      -
+        name: key-arp-op
+        type: u8
+      -
+        name: key-arp-op-mask
+        type: u8
+      -
+        name: key-arp-sha
+        type: binary
+      -
+        name: key-arp-sha-mask
+        type: binary
+      -
+        name: key-arp-tha
+        type: binary
+      -
+        name: key-arp-tha-mask
+        type: binary
+      -
+        name: key-mpls-ttl
+        type: u8
+      -
+        name: key-mpls-bos
+        type: u8
+      -
+        name: key-mpls-tc
+        type: u8
+      -
+        name: key-mpls-label
+        type: u32
+        byte-order: big-endian
+      -
+        name: key-tcp-flags
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-tcp-flags-mask
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-ip-tos
+        type: u8
+      -
+        name: key-ip-tos-mask
+        type: u8
+      -
+        name: key-ip-ttl
+        type: u8
+      -
+        name: key-ip-ttl-mask
+        type: u8
+      -
+        name: key-cvlan-id
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-cvlan-prio
+        type: u8
+      -
+        name: key-cvlan-eth-type
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-enc-ip-tos
+        type: u8
+      -
+        name: key-enc-ip-tos-mask
+        type: u8
+      -
+        name: key-enc-ip-ttl
+        type: u8
+      -
+        name: key-enc-ip-ttl-mask
+        type: u8
+      -
+        name: key-enc-opts
+        type: binary
+      -
+        name: key-enc-opts-mask
+        type: binary
+      -
+        name: in-hw-count
+        type: u32
+      -
+        name: key-port-src-min
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-port-src-max
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-port-dst-min
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-port-dst-max
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-ct-state
+        type: u16
+      -
+        name: key-ct-state-mask
+        type: u16
+      -
+        name: key-ct-zone
+        type: u16
+      -
+        name: key-ct-zone-mask
+        type: u16
+      -
+        name: key-ct-mark
+        type: u32
+      -
+        name: key-ct-mark-mask
+        type: u32
+      -
+        name: key-ct-labels
+        type: binary
+      -
+        name: key-ct-labels-mask
+        type: binary
+      -
+        name: key-mpls-opts
+        type: binary
+      -
+        name: key-hash
+        type: u32
+      -
+        name: key-hash-mask
+        type: u32
+      -
+        name: key-num-of-vlans
+        type: u8
+      -
+        name: key-pppoe-sid
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-ppp-proto
+        type: u16
+        byte-order: big-endian
+      -
+        name: key-l2-tpv3-sid
+        type: u32
+        byte-order: big-endian
+  -
+    name: tc-gred-attrs
+    attributes:
+      -
+        name: parms
+        type: binary # array of struct: tc-gred-qopt
+      -
+        name: stab
+        type: binary
+        sub-type: u8
+      -
+        name: dps
+        type: binary
+        struct: tc-gred-sopt
+      -
+        name: max-p
+        type: binary
+        sub-type: u32
+      -
+        name: limit
+        type: u32
+      -
+        name: vq-list
+        type: nest
+        nested-attributes: tca-gred-vq-list-attrs
+  -
+    name: tca-gred-vq-list-attrs
+    attributes:
+      -
+        name: entry
+        type: nest
+        nested-attributes: tca-gred-vq-entry-attrs
+        multi-attr: true
+  -
+    name: tca-gred-vq-entry-attrs
+    attributes:
+      -
+        name: pad
+        type: pad
+      -
+        name: dp
+        type: u32
+      -
+        name: stat-bytes
+        type: u32
+      -
+        name: stat-packets
+        type: u32
+      -
+        name: stat-backlog
+        type: u32
+      -
+        name: stat-prob-drop
+        type: u32
+      -
+        name: stat-prob-mark
+        type: u32
+      -
+        name: stat-forced-drop
+        type: u32
+      -
+        name: stat-forced-mark
+        type: u32
+      -
+        name: stat-pdrop
+        type: u32
+      -
+        name: stat-other
+        type: u32
+      -
+        name: flags
+        type: u32
+  -
+    name: tc-hfsc-attrs
+    attributes:
+      -
+        name: rsc
+        type: binary
+      -
+        name: fsc
+        type: binary
+      -
+        name: usc
+        type: binary
+  -
+    name: tc-hhf-attrs
+    attributes:
+      -
+        name: backlog-limit
+        type: u32
+      -
+        name: quantum
+        type: u32
+      -
+        name: hh-flows-limit
+        type: u32
+      -
+        name: reset-timeout
+        type: u32
+      -
+        name: admit-bytes
+        type: u32
+      -
+        name: evict-timeout
+        type: u32
+      -
+        name: non-hh-weight
+        type: u32
+  -
+    name: tc-htb-attrs
+    attributes:
+      -
+        name: parms
+        type: binary
+        struct: tc-htb-opt
+      -
+        name: init
+        type: binary
+        struct: tc-htb-glob
+      -
+        name: ctab
+        type: binary
+      -
+        name: rtab
+        type: binary
+      -
+        name: direct-qlen
+        type: u32
+      -
+        name: rate64
+        type: u64
+      -
+        name: ceil64
+        type: u64
+      -
+        name: pad
+        type: pad
+      -
+        name: offload
+        type: flag
+  -
+    name: tc-act-attrs
+    attributes:
+      -
+        name: kind
+        type: string
+      -
+        name: options
+        type: dynamic
+        selector:
+          attribute: kind
+          list:
+            -
+              value: gact
+              type: nest
+              nested-attributes: tca-gact-attrs
+      -
+        name: index
+        type: u32
+      -
+        name: stats
+        type: binary
+      -
+        name: pad
+        type: pad
+      -
+        name: cookie
+        type: binary
+      -
+        name: flags
+        type: bitfield32
+      -
+        name: hw-stats
+        type: bitfield32
+      -
+        name: used-hw-stats
+        type: bitfield32
+      -
+        name: in-hw-count
+        type: u32
+  -
+    name: tc-etf-attrs
+    attributes:
+      -
+        name: parms
+        type: binary
+        struct: tc-etf-qopt
+  -
+    name: tc-ets-attrs
+    attributes:
+      -
+        name: nbands
+        type: u8
+      -
+        name: nstrict
+        type: u8
+      -
+        name: quanta
+        type: nest
+        nested-attributes: tc-ets-attrs
+      -
+        name: quanta-band
+        type: u32
+        multi-attr: true
+      -
+        name: priomap
+        type: nest
+        nested-attributes: tc-ets-attrs
+      -
+        name: priomap-band
+        type: u8
+        multi-attr: true
+  -
+    name: tc-fq-attrs
+    attributes:
+      -
+        name: plimit
+        type: u32
+      -
+        name: flow-plimit
+        type: u32
+      -
+        name: quantum
+        type: u32
+      -
+        name: initial-quantum
+        type: u32
+      -
+        name: rate-enable
+        type: u32
+      -
+        name: flow-default-rate
+        type: u32
+      -
+        name: flow-max-rate
+        type: u32
+      -
+        name: buckets-log
+        type: u32
+      -
+        name: flow-refill-delay
+        type: u32
+      -
+        name: orphan-mask
+        type: u32
+      -
+        name: low-rate-threshold
+        type: u32
+      -
+        name: ce-threshold
+        type: u32
+      -
+        name: timer-slack
+        type: u32
+      -
+        name: horizon
+        type: u32
+      -
+        name: horizon-drop
+        type: u8
+  -
+    name: tc-fq-codel-attrs
+    attributes:
+      -
+        name: target
+        type: u32
+      -
+        name: limit
+        type: u32
+      -
+        name: interval
+        type: u32
+      -
+        name: ecn
+        type: u32
+      -
+        name: flows
+        type: u32
+      -
+        name: quantum
+        type: u32
+      -
+        name: ce-threshold
+        type: u32
+      -
+        name: drop-batch-size
+        type: u32
+      -
+        name: memory-limit
+        type: u32
+      -
+        name: ce-threshold-selector
+        type: u8
+      -
+        name: ce-threshold-mask
+        type: u8
+  -
+    name: tc-fq-pie-attrs
+    attributes:
+      -
+        name: limit
+        type: u32
+      -
+        name: flows
+        type: u32
+      -
+        name: target
+        type: u32
+      -
+        name: tupdate
+        type: u32
+      -
+        name: alpha
+        type: u32
+      -
+        name: beta
+        type: u32
+      -
+        name: quantum
+        type: u32
+      -
+        name: memory-limit
+        type: u32
+      -
+        name: ecn-prob
+        type: u32
+      -
+        name: ecn
+        type: u32
+      -
+        name: bytemode
+        type: u32
+      -
+        name: dq-rate-estimator
+        type: u32
+  -
+    name: tc-netem-attrs
+    attributes:
+      -
+        name: corr
+        type: binary
+      -
+        name: delay-dist
+        type: binary
+        sub-type: s16
+      -
+        name: reorder
+        type: binary
+      -
+        name: corrupt
+        type: binary
+      -
+        name: loss
+        type: binary
+      -
+        name: rate
+        type: binary
+      -
+        name: ecn
+        type: u32
+      -
+        name: rate64
+        type: u64
+      -
+        name: pad
+        type: u32
+      -
+        name: latency64
+        type: s64
+      -
+        name: jitter64
+        type: s64
+      -
+        name: slot
+        type: binary
+      -
+        name: slot-dist
+        type: binary
+        sub-type: s16
+  -
+    name: tc-pie-attrs
+    attributes:
+      -
+        name: target
+        type: u32
+      -
+        name: limit
+        type: u32
+      -
+        name: tupdate
+        type: u32
+      -
+        name: alpha
+        type: u32
+      -
+        name: beta
+        type: u32
+      -
+        name: ecn
+        type: u32
+      -
+        name: bytemode
+        type: u32
+      -
+        name: dq-rate-estimator
+        type: u32
+  -
+    name: tc-red-attrs
+    attributes:
+      -
+        name: parms
+        type: binary
+        struct: tc-red-qopt
+      -
+        name: stab
+        type: binary
+      -
+        name: max-p
+        type: u32
+      -
+        name: flags
+        type: binary
+      -
+        name: early-drop-block
+        type: u32
+      -
+        name: mark-block
+        type: u32
+  -
+    name: tc-taprio-attrs
+    attributes:
+      -
+        name: priomap
+        type: binary
+        struct: tc-mqprio-qopt
+      -
+        name: sched-entry-list
+        type: nest
+        nested-attributes: tc-taprio-sched-entry-list
+      -
+        name: sched-base-time
+        type: s64
+      -
+        name: sched-single-entry
+        type: nest
+        nested-attributes: tc-taprio-sched-entry
+      -
+        name: sched-clockid
+        type: s32
+      -
+        name: pad
+        type: pad
+      -
+        name: admin-sched
+        type: binary
+      -
+        name: sched-cycle-time
+        type: s64
+      -
+        name: sched-cycle-time-extension
+        type: s64
+      -
+        name: flags
+        type: u32
+      -
+        name: txtime-delay
+        type: u32
+      -
+        name: tc-entry
+        type: nest
+        nested-attributes: tc-taprio-tc-entry-attrs
+  -
+    name: tc-taprio-sched-entry-list
+    attributes:
+      -
+        name: entry
+        type: nest
+        nested-attributes: tc-taprio-sched-entry
+  -
+    name: tc-taprio-sched-entry
+    attributes:
+      -
+        name: index
+        type: u32
+      -
+        name: cmd
+        type: u8
+      -
+        name: gate-mask
+        type: u32
+      -
+        name: interval
+        type: u32
+  -
+    name: tc-taprio-tc-entry-attrs
+    attributes:
+      -
+        name: index
+        type: u32
+      -
+        name: max-sdu
+        type: u32
+      -
+        name: fp
+        type: u32
+  -
+    name: tc-tbf-attrs
+    attributes:
+      -
+        name: parms
+        type: binary
+        struct: tc-tbf-qopt
+      -
+        name: rtab
+        type: binary
+      -
+        name: ptab
+        type: binary
+      -
+        name: rate64
+        type: u64
+      -
+        name: prate4
+        type: u64
+      -
+        name: burst
+        type: u32
+      -
+        name: pburst
+        type: u32
+      -
+        name: pad
+        type: pad
+  -
+    name: tca-gact-attrs
+    attributes:
+      -
+        name: tm
+        type: binary
+      -
+        name: parms
+        type: binary
+      -
+        name: prob
+        type: binary
+      -
+        name: pad
+        type: pad
+  -
+    name: tca-stab-attrs
+    attributes:
+      -
+        name: base
+        type: binary
+        struct: tc-sizespec
+      -
+        name: data
+        type: binary
+  -
+    name: tca-stats-attrs
+    attributes:
+      -
+        name: basic
+        type: binary
+      -
+        name: rate-est
+        type: binary
+      -
+        name: queue
+        type: binary
+      -
+        name: app
+        type: binary # TODO dynamic 2+ level nest
+        selector:
+          attribute: tca-kind
+          list:
+            -
+              value: bfifo
+              type: binary
+            -
+              value: blackhole
+              type: binary
+            -
+              value: cake
+              type: nest
+              nested-attributes: tc-cake-stats-attrs
+            -
+              value: cbs
+              type: binary
+            -
+              value: choke
+              type: binary
+            -
+              value: clsact
+              type: binary
+            -
+              value: codel
+              type: binary
+            -
+              value: drr
+              type: binary
+            -
+              value: etf
+              type: binary
+            -
+              value: ets
+              type: binary
+            -
+              value: fq
+              type: binary
+            -
+              value: fq_codel
+              type: binary
+            -
+              value: fq_pie
+              type: binary
+            -
+              value: flower
+              type: binary
+            -
+              value: gred
+              type: binary
+            -
+              value: hfsc
+              type: binary
+            -
+              value: hhf
+              type: binary
+            -
+              value: htb
+              type: binary
+            -
+              value: ingress
+              type: binary
+            -
+              value: mq
+              type: binary
+            -
+              value: mqprio
+              type: binary
+            -
+              value: multiq
+              type: binary
+            -
+              value: netem
+              type: binary
+            -
+              value: noqueue
+              type: binary
+            -
+              value: pfifo
+              type: binary
+            -
+              value: pfifo_fast
+              type: binary
+            -
+              value: pfifo_head_drop
+              type: binary
+            -
+              value: pie
+              type: binary
+            -
+              value: plug
+              type: binary
+            -
+              value: prio
+              type: binary
+            -
+              value: qfq
+              type: binary
+            -
+              value: red
+              type: binary
+            -
+              value: sfb
+              type: binary
+            -
+              value: sfq
+              type: binary
+            -
+              value: taprio
+              type: binary
+            -
+              value: tbf
+              type: binary
+      -
+        name: rate-est64
+        type: binary
+      -
+        name: pad
+        type: pad
+      -
+        name: basic-hw
+        type: binary
+      -
+        name: pkt64
+        type: binary
+
+operations:
+  enum-model: directional
+  list:
+    -
+      name: newqdisc
+      doc: Create new tc qdisc.
+      attribute-set: tc-attrs
+      fixed-header: tcmsg
+      do:
+        request:
+          value: 36
+          attributes: &create-params
+            - tcm-family
+            - tcm-ifindex
+            - tcm-handle
+            - tcm-parent
+            - tca-kind
+            - tca-options
+            - tca-rate
+            - tca-stab
+            - tca-chain
+            - tca-ingress-block
+            - tca-egress-block
+    -
+      name: delqdisc
+      doc: Delete existing tc qdisc.
+      attribute-set: tc-attrs
+      fixed-header: tcmsg
+      do:
+        request:
+          value: 37
+          attributes: &lookup-params
+            - tcm-family
+            - tcm-ifindex
+            - tcm-handle
+            - tcm-parent
+    -
+      name: getqdisc
+      doc: Get / dump tc qdisc information.
+      attribute-set: tc-attrs
+      fixed-header: tcmsg
+      do:
+        request:
+          value: 38
+          attributes:
+            - tcm-family
+            - tcm-ifindex
+            - tcm-handle
+            - tcm-parent
+            - tca-dump-invisible
+            - tca-dump-flags
+        reply:
+          value: 36
+          attributes: &tc-all
+            - tcm-family
+            - tcm-ifindex
+            - tcm-handle
+            - tcm-parent
+            - tca-kind
+            - tca-options
+            - tca-stats
+            - tca-xstats
+            - tca-rate
+            - tca-fcnt
+            - tca-stats2
+            - tca-stab
+            - tca-chain
+            - tca-ingress-block
+            - tca-egress-block
+    -
+      name: newtclass
+      doc: Get / dump tc traffic class information.
+      attribute-set: tc-attrs
+      fixed-header: tcmsg
+      do:
+        request:
+          value: 40
+          attributes: *create-params
+    -
+      name: deltclass
+      doc: Get / dump tc traffic class information.
+      attribute-set: tc-attrs
+      fixed-header: tcmsg
+      do:
+        request:
+          value: 41
+          attributes: *lookup-params
+    -
+      name: gettclass
+      doc: Get / dump tc traffic class information.
+      attribute-set: tc-attrs
+      fixed-header: tcmsg
+      do:
+        request:
+          value: 42
+          attributes: *lookup-params
+        reply:
+          value: 40
+          attributes: *tc-all
+    -
+      name: newtfilter
+      doc: Get / dump tc filter information.
+      attribute-set: tc-attrs
+      fixed-header: tcmsg
+      do:
+        request:
+          value: 44
+          attributes: *create-params
+    -
+      name: deltfilter
+      doc: Get / dump tc filter information.
+      attribute-set: tc-attrs
+      fixed-header: tcmsg
+      do:
+        request:
+          value: 45
+          attributes: *lookup-params
+    -
+      name: gettfilter
+      doc: Get / dump tc filter information.
+      attribute-set: tc-attrs
+      fixed-header: tcmsg
+      do:
+        request:
+          value: 46
+          attributes: *lookup-params
+        reply:
+          value: 44
+          attributes: *tc-all
+    -
+      name: newchain
+      doc: Get / dump tc chain information.
+      attribute-set: tc-attrs
+      fixed-header: tcmsg
+      do:
+        request:
+          value: 100
+          attributes: *create-params
+    -
+      name: delchain
+      doc: Get / dump tc chain information.
+      attribute-set: tc-attrs
+      fixed-header: tcmsg
+      do:
+        request:
+          value: 101
+          attributes: *lookup-params
+    -
+      name: getchain
+      doc: Get / dump tc chain information.
+      attribute-set: tc-attrs
+      fixed-header: tcmsg
+      do:
+        request:
+          value: 102
+          attributes: *lookup-params
+        reply:
+          value: 100
+          attributes: *tc-all
+
+mcast-groups:
+  list:
+    -
+      name: rtnlgrp-tc
+      value: 4
Signature · 1 line
2.42.0
author maintainer
#6 lore raw

RFC PATCH 6/6 tools/net/ynl: Add optional fixed-header to dynamic nests

In reply to Donald Hunter

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.

---
 Documentation/netlink/netlink-raw.yaml |  2 ++
 tools/net/ynl/lib/ynl.py               | 24 +++++++++++++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)
Documentation/netlink/netlink-raw.yaml +2 -0
index 62061e180f8f..b5295057dcea 100644
@@ -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.
tools/net/ynl/lib/ynl.py +15 -9
index 5ce01ce37573..86d591cb0047 100644
@@ -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)
Signature · 1 line
2.42.0
maintainer
#7 lore raw
In reply to Donald Hunter
Quoted 3 lines · On Wed, 29 Nov 2023 10:11:53 +0000 Donald Hunter wrote:

This patchset adds a dynamic selector mechanism to YNL for kind-specific options attributes. I am sending this as an RFC solicit feedback on a couple of issues before I complete the patchset.

Exciting stuff!

Quoted 5 lines

I started adding this feature for the rt_link spec which is monomorphic, i.e. the kind-specific 'data' attribute is always a nest. The selector looked like this:

-

Quoted 11 lines
    name: data
    type: dynamic
    selector:
      attribute: kind
      list:
        -
          value: bridge
          nested-attributes: linkinfo-bridge-attrs
        -
          value: erspan
          nested-attributes: linkinfo-gre-attrs

It's kinda moot given your discovery below :(, but FWIW this is very close to what I've been thinking.

After some pondering I thought it'd be better to structure it just a bit differently:

-
name: data
type: poly-nest
selector: kind # which attr carries the key

that's it for the attr, and then in attr-set I'd add a "key":

-
name: linkinfo-bridge-attrs
poly-key: bridge

putting the key on the attr set is worse if we ever need to "key" the same attr set with different selectors, but it makes the attr definition a lot smaller. And in practice I didn't expect us to ever need keying into one attr set with different selectors. If we did - we could complicate it later, but start simple.

Quoted 62 lines

Then I started working on tc and found that the 'options' attribute is poymorphic. It is typically either a C struct or a nest. So I extended the dynamic selector to include a 'type' field and type-specific sub-fields:

-

    name: options
    type: dynamic
    selector:
      attribute: kind
      list:
        -
          value: bfifo
          type: binary
          struct: tc-fifo-qopt
        -
          value: cake
          type: nest
          nested-attributes: tc-cake-attrs
        -
          value: cbs
          type: nest
          nested-attributes: tc-cbs-attrs

Then I encountered 'netem' which has a nest with a C struct header. I realised that maybe my mental model had been wrong and that all cases could be supported by a nest type with an optional fixed-header followed by zero or more nlattrs.

-
value: netem
type: nest
fixed-header: tc-netem-qopt
nested-attributes: tc-netem-attrs

Perhaps it is attribute-sets in general that should have an optional fixed-header, which would also work for fixed-headers at the start of genetlink messages. I originally added fixed-header support to operations for genetlink, but fixed headers on attribute sets would work for all these cases.

I now see a few possible ways forward and would like feedback on the preferred approach:

1. Simplify the current patchset to implement fixed-header & nest support in the dynamic selector. This would leave existing fixed-header support for messages unchanged. We could drop the 'type' field.

   -
     value: netem
     fixed-header: tc-netem-qopt
     nested-attributes: tc-netem-attrs

2. Keep the 'type' field and support for the 'binary' type which is useful for specifying nests with unknown attribute spaces. An alternative would be to default to 'binary' behaviour if there is no selector entry.

3. Refactor the existing fixed-header support to be an optional part of all attribute sets instead of just messages (in legacy and raw specs) and dynamic attribute nests (in raw specs).

Quoted 5 lines
   attribute-sets:
     -
       name: tc-netem-attrs
       fixed-header: tc-netem-qopt
       attributes:

Reading this makes me feel like netem wants to be a "sub-message"? It has a fixed header followed by attrs, that's quite message-like.

Something along the lines of 1 makes most sense to me, but can we put the "selector ladder" out-of-line? I'm worried that the attr definition will get crazy long.

attribute-sets:
-

    name: outside-attrs
    attributes:
      ...
      -
         name: kind
         type: string
      -
         name: options
         type: sub-message
         sub-type: inside-msg  # reuse sub-type or new property?
         selector: kind
    ...
  -
    name: inside-attrs:
    attributes: 
      ...

sub-messages:
list:

    -
      name: inside-msg
      formats: # not a great name?..
        -
          value: some-value
          fixed-header: struct-name
        -
          value: other-value
          fixed-header: struct-name-two
          nested-attributes: inside-attrs
        -
          value: another-one
          nested-attributes: inside-attrs
    -
      name: different-inside-msg
      ...

operations:
...

At least that's what comes to my mind after reading the problem description. Does it make sense?

author maintainer
#8 lore raw
Quoted 41 lines · Jakub Kicinski
Quoted 3 lines · On Wed, 29 Nov 2023 10:11:53 +0000 Donald Hunter wrote:

This patchset adds a dynamic selector mechanism to YNL for kind-specific options attributes. I am sending this as an RFC solicit feedback on a couple of issues before I complete the patchset.

Exciting stuff!

Quoted 5 lines

I started adding this feature for the rt_link spec which is monomorphic, i.e. the kind-specific 'data' attribute is always a nest. The selector looked like this:

-

Quoted 11 lines
    name: data
    type: dynamic
    selector:
      attribute: kind
      list:
        -
          value: bridge
          nested-attributes: linkinfo-bridge-attrs
        -
          value: erspan
          nested-attributes: linkinfo-gre-attrs

It's kinda moot given your discovery below :(, but FWIW this is very close to what I've been thinking.

After some pondering I thought it'd be better to structure it just a bit differently:

-
name: data
type: poly-nest
selector: kind # which attr carries the key

that's it for the attr, and then in attr-set I'd add a "key":

-
name: linkinfo-bridge-attrs
poly-key: bridge

Quoted 5 lines

putting the key on the attr set is worse if we ever need to "key" the same attr set with different selectors, but it makes the attr definition a lot smaller. And in practice I didn't expect us to ever need keying into one attr set with different selectors. If we did - we could complicate it later, but start simple.

rt_link shares attribute-sets between different kinds of link so I think that rules out putting the key on the attribute-set. I think we may also see reuse across stats attribute sets in tc.

FWIW I initially considered avoiding a selector list by using a template to generate the attribute set name, but that broke pretty quickly.

Quoted 23 lines
Quoted 23 lines

...
I now see a few possible ways forward and would like feedback on the preferred approach:

1. Simplify the current patchset to implement fixed-header & nest support in the dynamic selector. This would leave existing fixed-header support for messages unchanged. We could drop the 'type' field.

   -
     value: netem
     fixed-header: tc-netem-qopt
     nested-attributes: tc-netem-attrs

2. Keep the 'type' field and support for the 'binary' type which is useful for specifying nests with unknown attribute spaces. An alternative would be to default to 'binary' behaviour if there is no selector entry.

3. Refactor the existing fixed-header support to be an optional part of all attribute sets instead of just messages (in legacy and raw specs) and dynamic attribute nests (in raw specs).

Quoted 8 lines
Quoted 5 lines
   attribute-sets:
     -
       name: tc-netem-attrs
       fixed-header: tc-netem-qopt
       attributes:

Reading this makes me feel like netem wants to be a "sub-message"? It has a fixed header followed by attrs, that's quite message-like.

Yeah, I guess we could call it sub-message because it's not a pure nest and the different name makes it an explicitly netlink-raw concept.

Quoted 3 lines

Something along the lines of 1 makes most sense to me, but can we put the "selector ladder" out-of-line? I'm worried that the attr definition will get crazy long.

It seems reasonable to pull the selector list out of line because they do get big, e.g. over 100 lines for tc "options".

My preference is 1, probably including a fallback to "binary" if there is no selector match.

Quoted 38 lines

attribute-sets:
-

    name: outside-attrs
    attributes:
      ...
      -
         name: kind
         type: string
      -
         name: options
         type: sub-message
         sub-type: inside-msg  # reuse sub-type or new property?
         selector: kind
    ...
  -
    name: inside-attrs:
    attributes: 
      ...

sub-messages:
list:

    -
      name: inside-msg
      formats: # not a great name?..
        -
          value: some-value
          fixed-header: struct-name
        -
          value: other-value
          fixed-header: struct-name-two
          nested-attributes: inside-attrs
        -
          value: another-one
          nested-attributes: inside-attrs
    -
      name: different-inside-msg
      ...
Quoted 5 lines

operations:
...

At least that's what comes to my mind after reading the problem description. Does it make sense?

I think that once you have broken out to a sub-message, they're no longer "nested-attributes" and we should maybe reuse "attribute-set".

I don't think we can reuse "sub-type" because the schema for it is the set of netlink type names, not a free string. Maybe we add "sub-message" instead? So how about this:

attribute-sets:
-

    name: outside-attrs
    attributes:
      ...
      -
         name: kind
         type: string
      -
         name: options
         type: sub-message
         sub-message: inside-msg
         selector: kind
    ...
  -
    name: inside-attrs:
    attributes:
      ...

sub-messages:
-

    name: inside-msg
    formats:
      -
        value: some-value
        fixed-header: struct-name
      -
        value: other-value
        fixed-header: struct-name-two
        attribute-set: inside-attrs
      -
        value: another-one
        attribute-set: inside-attrs
  -
    name: different-inside-msg
    ...

operations:
...

I cannot think of a better name than "formats" so happy to go with that. Did you want an explicit "list:" in the yaml schema?

Thanks,
Donald.

maintainer
#9 lore raw
Quoted 6 lines · On Wed, 29 Nov 2023 16:58:57 +0000 Donald Hunter wrote:

rt_link shares attribute-sets between different kinds of link so I think that rules out putting the key on the attribute-set. I think we may also see reuse across stats attribute sets in tc.

FWIW I initially considered avoiding a selector list by using a template to generate the attribute set name, but that broke pretty quickly.

Ah :(

Quoted 5 lines

It seems reasonable to pull the selector list out of line because they do get big, e.g. over 100 lines for tc "options".

My preference is 1, probably including a fallback to "binary" if there is no selector match.

Are there any "nests" that need a real binary type? An actual byte array? Or are these all structs? If the latter then fixed-header covers it.

Quoted 2 lines

I think that once you have broken out to a sub-message, they're no longer "nested-attributes" and we should maybe reuse "attribute-set".

Good point.

Quoted 3 lines

I don't think we can reuse "sub-type" because the schema for it is the set of netlink type names, not a free string. Maybe we add "sub-message" instead?

Sounds good.

Quoted 39 lines

So how about this:

attribute-sets:
-

    name: outside-attrs
    attributes:
      ...
      -
         name: kind
         type: string
      -
         name: options
         type: sub-message
         sub-message: inside-msg
         selector: kind
    ...
  -
    name: inside-attrs:
    attributes:
      ...

sub-messages:
-

    name: inside-msg
    formats:
      -
        value: some-value
        fixed-header: struct-name
      -
        value: other-value
        fixed-header: struct-name-two
        attribute-set: inside-attrs
      -
        value: another-one
        attribute-set: inside-attrs
  -
    name: different-inside-msg
    ...
Quoted 2 lines

operations:
...

LG!

Quoted 1 line

I cannot think of a better name than "formats" so happy to go with that.

Or maybe "variants" ?

Quoted 1 line

Did you want an explicit "list:" in the yaml schema?

You mean instead of the "formats" or in addition somewhere? Under sub-messages?

The "formats" is basically a "list", just feels less artificial to call it something else than "list". No strong preference, tho.

If you mean under "sub-messages" - I can't think of any extra property we may want to put there. So going directly to entries seems fine.

author maintainer
#10 lore raw
Quoted 11 lines · Jakub Kicinski
Quoted 2 lines

Did you want an explicit "list:" in the yaml schema?

You mean instead of the "formats" or in addition somewhere? Under sub-messages?

The "formats" is basically a "list", just feels less artificial to call it something else than "list". No strong preference, tho.

If you mean under "sub-messages" - I can't think of any extra property we may want to put there. So going directly to entries seems fine.

Sorry, I wasn't clear - yes, under sub-messages.

Thanks!