diff mbox series

[net-next] doc/netlink/specs: Add vlan attr in rt_link spec

Message ID 20240308041518.3047900-1-liuhangbin@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] doc/netlink/specs: Add vlan attr in rt_link spec | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
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/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 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, 87 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
netdev/contest success net-next-2024-03-08--09-00 (tests: 890)

Commit Message

Hangbin Liu March 8, 2024, 4:15 a.m. UTC
With command:
 # ./tools/net/ynl/cli.py \
 --spec Documentation/netlink/specs/rt_link.yaml \
 --do getlink --json '{"ifname": "eno1.2"}'

Before:
Exception: No message format for 'vlan' in sub-message spec 'linkinfo-data-msg'

After:
 'linkinfo': {'data': {'flag': {'flags': {'bridge-binding',
                                          'gvrp',
                                          'reorder-hdr'},
                                'mask': 4294967295},
                       'id': 2,
                       'protocol': 129},
              'kind': 'vlan'},

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
Not sure if there is a proper way to show the mask and protocol
---
 Documentation/netlink/specs/rt_link.yaml | 69 ++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

Comments

Donald Hunter March 8, 2024, 1:05 p.m. UTC | #1
Hangbin Liu <liuhangbin@gmail.com> writes:

> With command:
>  # ./tools/net/ynl/cli.py \
>  --spec Documentation/netlink/specs/rt_link.yaml \
>  --do getlink --json '{"ifname": "eno1.2"}'
>
> Before:
> Exception: No message format for 'vlan' in sub-message spec 'linkinfo-data-msg'
>
> After:
>  'linkinfo': {'data': {'flag': {'flags': {'bridge-binding',
>                                           'gvrp',
>                                           'reorder-hdr'},
>                                 'mask': 4294967295},
>                        'id': 2,
>                        'protocol': 129},
>               'kind': 'vlan'},
>
> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
> ---
> Not sure if there is a proper way to show the mask and protocol

Using display-hint, e.g. display-hint: hex, is intended to tell the ynl
cli to render output in a human readable way. Unfortunately it currently
only works for binary attributes.

It can be done like this:

      -
        name: mask
        type: binary
        len: 4
        display-hint: hex

./tools/net/ynl/cli.py \
--spec Documentation/netlink/specs/rt_link.yaml \
--do getlink --json '{"ifname": "wlan0.8"}' --output-json | jq -C '.linkinfo'
{
  "kind": "vlan",
  "data": {
    "protocol": 33024,
    "id": 8,
    "flag": {
      "flags": [
        "reorder-hdr"
      ],
      "mask": "ff ff ff ff"
    }
  }
}

But it seems wrong to change the struct definition for this. We should
patch ynl to support hex rendering of integers.

For the protocol, you'd need to add an enum of ethernet protocol
numbers, from the info in include/uapi/linux/if_ether.h

> +  -
> +    name: linkinfo-vlan-attrs
> +    name-prefix: ifla-vlan-
> +    attributes:
> +      -
> +        name: id
> +        type: u16
> +      -
> +        name: flag
> +        type: binary
> +        struct: ifla-vlan-flags
> +      -
> +        name: egress-qos
> +        type: nest
> +        nested-attributes: ifla-vlan-qos
> +      -
> +        name: ingress-qos
> +        type: nest
> +        nested-attributes: ifla-vlan-qos
> +      -
> +        name: protocol
> +        type: u16

The protocol value is in big endian format, so it is actually 33024
(0x8100) not 129. You need to add byte-order: big-endian

> +  -
> +    name: ifla-vlan-qos
> +    name-prefix: ifla-vlan-qos
> +    attributes:
> +      -
> +        name: mapping
> +        type: binary
> +        struct: ifla-vlan-qos-mapping
>    -
>      name: linkinfo-vrf-attrs
>      name-prefix: ifla-vrf-
> @@ -1666,6 +1732,9 @@ sub-messages:
>        -
>          value: tun
>          attribute-set: linkinfo-tun-attrs
> +      -
> +        value: vlan
> +        attribute-set: linkinfo-vlan-attrs
>        -
>          value: vrf
>          attribute-set: linkinfo-vrf-attrs
Hangbin Liu March 11, 2024, 10:08 a.m. UTC | #2
Hi Donald,
On Fri, Mar 08, 2024 at 01:05:45PM +0000, Donald Hunter wrote:
> > Not sure if there is a proper way to show the mask and protocol
> 
> Using display-hint, e.g. display-hint: hex, is intended to tell the ynl
> cli to render output in a human readable way. Unfortunately it currently
> only works for binary attributes.
> 
> It can be done like this:
> 
>       -
>         name: mask
>         type: binary
>         len: 4
>         display-hint: hex
> 
> ./tools/net/ynl/cli.py \
> --spec Documentation/netlink/specs/rt_link.yaml \
> --do getlink --json '{"ifname": "wlan0.8"}' --output-json | jq -C '.linkinfo'
> {
>   "kind": "vlan",
>   "data": {
>     "protocol": 33024,
>     "id": 8,
>     "flag": {
>       "flags": [
>         "reorder-hdr"
>       ],
>       "mask": "ff ff ff ff"
>     }
>   }
> }
> 
> But it seems wrong to change the struct definition for this. We should
> patch ynl to support hex rendering of integers.

I only processed the numbers with hex display hint

diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 2d7fdd903d9e..d92b8ef287a1 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -787,7 +787,11 @@ class YnlFamily(SpecFamily):
                 if m.enum:
                     value = self._decode_enum(value, m)
                 elif m.display_hint:
-                    value = self._formatted_string(value, m.display_hint)
+                    if m.type in {'u8', 'u16', 'u32', 'u64', 's32', 's64',
+                                  'uint', 'sint'} and m.display_hint == 'hex':
+                        value = hex(value)
+                    else:
+                        value = self._formatted_string(value, m.display_hint)
                 attrs[m.name] = value
         return attrs

And the output looks like:

{
  "kind": "vlan",
  "data": {
    "protocol": "8021q",
    "id": 2,
    "flag": {
      "flags": [
        "reorder-hdr"
      ],
      "mask": "0xffffffff"
    }
  }
}

Do you think if it is enough?

> 
> For the protocol, you'd need to add an enum of ethernet protocol
> numbers, from the info in include/uapi/linux/if_ether.h

Thanks, I will add VLAN protocols first.

Hangbin
diff mbox series

Patch

diff --git a/Documentation/netlink/specs/rt_link.yaml b/Documentation/netlink/specs/rt_link.yaml
index 8e4d19adee8c..5559ea18ccc7 100644
--- a/Documentation/netlink/specs/rt_link.yaml
+++ b/Documentation/netlink/specs/rt_link.yaml
@@ -729,6 +729,42 @@  definitions:
       -
         name: filter-mask
         type: u32
+  -
+    name: ifla-vlan-flags
+    type: struct
+    members:
+      -
+        name: flags
+        type: u32
+        enum: vlan-flags
+        enum-as-flags: true
+      -
+        name: mask
+        type: u32
+  -
+    name: vlan-flags
+    type: flags
+    entries:
+      -
+        name: reorder-hdr
+      -
+        name: gvrp
+      -
+        name: loose-binding
+      -
+        name: mvrp
+      -
+        name: bridge-binding
+  -
+    name: ifla-vlan-qos-mapping
+    type: struct
+    members:
+      -
+        name: from
+        type: u32
+      -
+        name: to
+        type: u32
 
 
 attribute-sets:
@@ -1507,6 +1543,36 @@  attribute-sets:
       -
         name: num-disabled-queues
         type: u32
+  -
+    name: linkinfo-vlan-attrs
+    name-prefix: ifla-vlan-
+    attributes:
+      -
+        name: id
+        type: u16
+      -
+        name: flag
+        type: binary
+        struct: ifla-vlan-flags
+      -
+        name: egress-qos
+        type: nest
+        nested-attributes: ifla-vlan-qos
+      -
+        name: ingress-qos
+        type: nest
+        nested-attributes: ifla-vlan-qos
+      -
+        name: protocol
+        type: u16
+  -
+    name: ifla-vlan-qos
+    name-prefix: ifla-vlan-qos
+    attributes:
+      -
+        name: mapping
+        type: binary
+        struct: ifla-vlan-qos-mapping
   -
     name: linkinfo-vrf-attrs
     name-prefix: ifla-vrf-
@@ -1666,6 +1732,9 @@  sub-messages:
       -
         value: tun
         attribute-set: linkinfo-tun-attrs
+      -
+        value: vlan
+        attribute-set: linkinfo-vlan-attrs
       -
         value: vrf
         attribute-set: linkinfo-vrf-attrs