mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
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. Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Link: https://patch.msgid.link/20251117024457.3034-2-liuhangbin@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
committed by
Jakub Kicinski
parent
616d860439
commit
4abe51dba6
@@ -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']}'")
|
||||
|
||||
Reference in New Issue
Block a user