[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251029082245.128675-2-liuhangbin@gmail.com>
Date: Wed, 29 Oct 2025 08:22:43 +0000
From: Hangbin Liu <liuhangbin@...il.com>
To: netdev@...r.kernel.org
Cc: Donald Hunter <donald.hunter@...il.com>,
Jakub Kicinski <kuba@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Paolo Abeni <pabeni@...hat.com>,
Simon Horman <horms@...nel.org>,
Jan Stancek <jstancek@...hat.com>,
"Matthieu Baerts (NGI0)" <matttbe@...nel.org>,
Asbjørn Sloth Tønnesen <ast@...erby.net>,
Stanislav Fomichev <sdf@...ichev.me>,
Shuah Khan <shuah@...nel.org>,
Ido Schimmel <idosch@...dia.com>,
Guillaume Nault <gnault@...hat.com>,
Petr Machata <petrm@...dia.com>,
linux-kselftest@...r.kernel.org,
Hangbin Liu <liuhangbin@...il.com>
Subject: [PATCH net-next 1/3] tools: ynl: Add MAC address parsing support
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@...il.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
Powered by blists - more mailing lists