From: Hangbin Liu <liuhangbin@gmail•com>
To: netdev@vger•kernel.org
Cc: "Donald Hunter" <donald.hunter@gmail•com>,
"Jakub Kicinski" <kuba@kernel•org>,
"David S. Miller" <davem@davemloft•net>,
"Eric Dumazet" <edumazet@google•com>,
"Paolo Abeni" <pabeni@redhat•com>,
"Simon Horman" <horms@kernel•org>,
"Jan Stancek" <jstancek@redhat•com>,
"Matthieu Baerts (NGI0)" <matttbe@kernel•org>,
"Asbjørn Sloth Tønnesen" <ast@fiberby•net>,
"Stanislav Fomichev" <sdf@fomichev•me>,
"Ido Schimmel" <idosch@nvidia•com>,
"Guillaume Nault" <gnault@redhat•com>,
"Petr Machata" <petrm@nvidia•com>,
"Hangbin Liu" <liuhangbin@gmail•com>
Subject: [PATCHv2 net-next 1/3] tools: ynl: Add MAC address parsing support
Date: Wed, 5 Nov 2025 08:28:39 +0000 [thread overview]
Message-ID: <20251105082841.165212-2-liuhangbin@gmail.com> (raw)
In-Reply-To: <20251105082841.165212-1-liuhangbin@gmail.com>
Add missing support for parsing MAC addresses when display_hint is 'mac'
in the YNL library. This enables YNL CLI to accept MAC address strings
for attributes like lladdr in rt-neigh operations.
Signed-off-by: Hangbin Liu <liuhangbin@gmail•com>
---
tools/net/ynl/pyynl/lib/ynl.py | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/tools/net/ynl/pyynl/lib/ynl.py b/tools/net/ynl/pyynl/lib/ynl.py
index 225baad3c8f8..36d36eb7e3b8 100644
--- a/tools/net/ynl/pyynl/lib/ynl.py
+++ b/tools/net/ynl/pyynl/lib/ynl.py
@@ -985,6 +985,15 @@ class YnlFamily(SpecFamily):
raw = bytes.fromhex(string)
else:
raw = int(string, 16)
+ elif attr_spec.display_hint == 'mac':
+ # Parse MAC address in format "00:11:22:33:44:55" or "001122334455"
+ if ':' in string:
+ mac_bytes = [int(x, 16) for x in string.split(':')]
+ else:
+ if len(string) % 2 != 0:
+ raise Exception(f"Invalid MAC address format: {string}")
+ mac_bytes = [int(string[i:i+2], 16) for i in range(0, len(string), 2)]
+ raw = bytes(mac_bytes)
else:
raise Exception(f"Display hint '{attr_spec.display_hint}' not implemented"
f" when parsing '{attr_spec['name']}'")
--
2.50.1
next prev parent reply other threads:[~2025-11-05 8:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-05 8:28 [PATCHv2 net-next 0/3] Add YNL test framework and library improvements Hangbin Liu
2025-11-05 8:28 ` Hangbin Liu [this message]
2025-11-05 8:28 ` [PATCHv2 net-next 2/3] netlink: specs: update rt-rule src/dst attribute types to support IPv4 addresses Hangbin Liu
2025-11-05 8:28 ` [PATCHv2 net-next 3/3] tools: ynl: add YNL test framework Hangbin Liu
2025-11-05 17:00 ` Sabrina Dubroca
2025-11-06 1:39 ` Hangbin Liu
2025-11-06 2:33 ` Jakub Kicinski
2025-11-06 2:40 ` Hangbin Liu
2025-11-06 14:45 ` Jakub Kicinski
2025-11-10 3:14 ` Hangbin Liu
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=20251105082841.165212-2-liuhangbin@gmail.com \
--to=liuhangbin@gmail$(echo .)com \
--cc=ast@fiberby$(echo .)net \
--cc=davem@davemloft$(echo .)net \
--cc=donald.hunter@gmail$(echo .)com \
--cc=edumazet@google$(echo .)com \
--cc=gnault@redhat$(echo .)com \
--cc=horms@kernel$(echo .)org \
--cc=idosch@nvidia$(echo .)com \
--cc=jstancek@redhat$(echo .)com \
--cc=kuba@kernel$(echo .)org \
--cc=matttbe@kernel$(echo .)org \
--cc=netdev@vger$(echo .)kernel.org \
--cc=pabeni@redhat$(echo .)com \
--cc=petrm@nvidia$(echo .)com \
--cc=sdf@fomichev$(echo .)me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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