diff mbox series

[net-next,v1,2/6] doc/netlink: Add sub-message support to netlink-raw

Message ID 20231130214959.27377-3-donald.hunter@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series tools/net/ynl: Add 'sub-message' support to ynl | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 69 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Donald Hunter Nov. 30, 2023, 9:49 p.m. UTC
Add a 'sub-message' attribute type with a selector that supports
polymorphic attribute formats for raw netlink families like tc.

A sub-message attribute uses the value of another attribute as a
selector key to choose the right sub-message format. For example if the
following attribute has already been decoded:

  { "kind": "gre" }

and we encounter the following attribute spec:

  -
    name: data
    type: sub-message
    sub-message: linkinfo-data-msg
    selector: kind

Then we look for a sub-message definition called 'linkinfo-data-msg' and
use the value of the 'kind' attribute i.e. 'gre' as the key to choose
the correct format for the sub-message:

  sub-messages:
    name: linkinfo-data-msg
    formats:
      -
        value: bridge
        attribute-set: linkinfo-bridge-attrs
      -
        value: gre
        attribute-set: linkinfo-gre-attrs
      -
        value: geneve
        attribute-set: linkinfo-geneve-attrs

This would decode the attribute value as a sub-message with the
attribute-set called 'linkinfo-gre-attrs' as the attribute space.

A sub-message can have an optional 'fixed-header' followed by zero or
more attributes from an attribute-set. For example the following
'tc-options-msg' sub-message defines message formats that use a mixture
of fixed-header, attribute-set or both together:

  sub-messages:
    -
      name: tc-options-msg
      formats:
        -
          value: bfifo
          fixed-header: tc-fifo-qopt
        -
          value: cake
          attribute-set: tc-cake-attrs
        -
          value: netem
          fixed-header: tc-netem-qopt
          attribute-set: tc-netem-attrs

Signed-off-by: Donald Hunter <donald.hunter@gmail.com>
---
 Documentation/netlink/netlink-raw.yaml | 51 +++++++++++++++++++++++++-
 1 file changed, 50 insertions(+), 1 deletion(-)

Comments

Jakub Kicinski Dec. 2, 2023, 1:53 a.m. UTC | #1
On Thu, 30 Nov 2023 21:49:54 +0000 Donald Hunter wrote:
> Add a 'sub-message' attribute type with a selector that supports
> polymorphic attribute formats for raw netlink families like tc.
> 
> A sub-message attribute uses the value of another attribute as a
> selector key to choose the right sub-message format. For example if the
> following attribute has already been decoded:
> 
>   { "kind": "gre" }
> 
> and we encounter the following attribute spec:
> 
>   -
>     name: data
>     type: sub-message
>     sub-message: linkinfo-data-msg
>     selector: kind
> 
> Then we look for a sub-message definition called 'linkinfo-data-msg' and
> use the value of the 'kind' attribute i.e. 'gre' as the key to choose
> the correct format for the sub-message:
> 
>   sub-messages:
>     name: linkinfo-data-msg
>     formats:
>       -
>         value: bridge
>         attribute-set: linkinfo-bridge-attrs
>       -
>         value: gre
>         attribute-set: linkinfo-gre-attrs
>       -
>         value: geneve
>         attribute-set: linkinfo-geneve-attrs
> 
> This would decode the attribute value as a sub-message with the
> attribute-set called 'linkinfo-gre-attrs' as the attribute space.
> 
> A sub-message can have an optional 'fixed-header' followed by zero or
> more attributes from an attribute-set. For example the following
> 'tc-options-msg' sub-message defines message formats that use a mixture
> of fixed-header, attribute-set or both together:
> 
>   sub-messages:
>     -
>       name: tc-options-msg
>       formats:
>         -
>           value: bfifo
>           fixed-header: tc-fifo-qopt
>         -
>           value: cake
>           attribute-set: tc-cake-attrs
>         -
>           value: netem
>           fixed-header: tc-netem-qopt
>           attribute-set: tc-netem-attrs

SGTM, could you add all the info from the commit message somewhere 
in the documentation? Perhaps a new section at the end of
Documentation/userspace-api/netlink/specs.rst

> @@ -261,6 +262,17 @@ properties:
>                  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.
> +                type: string
> +              selector:
> +                description:
> +                  Name of the attribute to use for dynamic selection of sub-message
> +                  format specifier.
> +                type: string

We can leave it for later either way, but have you seen any selectors
which would key on an integer, rather than a string?
Donald Hunter Dec. 4, 2023, 3:58 p.m. UTC | #2
Jakub Kicinski <kuba@kernel.org> writes:
>
> SGTM, could you add all the info from the commit message somewhere 
> in the documentation? Perhaps a new section at the end of
> Documentation/userspace-api/netlink/specs.rst

Ack, will do.

>> @@ -261,6 +262,17 @@ properties:
>>                  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.
>> +                type: string
>> +              selector:
>> +                description:
>> +                  Name of the attribute to use for dynamic selection of sub-message
>> +                  format specifier.
>> +                type: string
>
> We can leave it for later either way, but have you seen any selectors
> which would key on an integer, rather than a string?

From what I have seen, I am fairly sure it's always going to be a
string. (famous last words)
diff mbox series

Patch

diff --git a/Documentation/netlink/netlink-raw.yaml b/Documentation/netlink/netlink-raw.yaml
index ad5395040765..26203282422f 100644
--- a/Documentation/netlink/netlink-raw.yaml
+++ b/Documentation/netlink/netlink-raw.yaml
@@ -202,7 +202,8 @@  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,
+                        sub-message ]
               doc:
                 description: Documentation of the attribute.
                 type: string
@@ -261,6 +262,17 @@  properties:
                 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.
+                type: string
+              selector:
+                description:
+                  Name of the attribute to use for dynamic selection of sub-message
+                  format specifier.
+                type: string
+              # End netlink-raw
 
       # Make sure name-prefix does not appear in subsets (subsets inherit naming)
       dependencies:
@@ -283,6 +295,43 @@  properties:
             items:
               required: [ type ]
 
+  # Start netlink-raw
+  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
+  # End netlink-raw
+
   operations:
     description: Operations supported by the protocol.
     type: object