From: Hangbin Liu <liuhangbin@gmail.com>
To: Donald Hunter <donald.hunter@gmail.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Jacob Keller <jacob.e.keller@intel.com>,
Jiri Pirko <jiri@resnulli.us>
Subject: Re: [PATCH net-next] doc/netlink/specs: Add vlan attr in rt_link spec
Date: Mon, 11 Mar 2024 18:08:45 +0800 [thread overview]
Message-ID: <Ze7YLcBgbxJzKod3@Laptop-X1> (raw)
In-Reply-To: <m2sf10g9g6.fsf@gmail.com>
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
prev parent reply other threads:[~2024-03-11 10:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-08 4:15 [PATCH net-next] doc/netlink/specs: Add vlan attr in rt_link spec Hangbin Liu
2024-03-08 13:05 ` Donald Hunter
2024-03-11 10:08 ` Hangbin Liu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Ze7YLcBgbxJzKod3@Laptop-X1 \
--to=liuhangbin@gmail.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=edumazet@google.com \
--cc=jacob.e.keller@intel.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox