diff options
author | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-03-28 15:02:38 +0000 |
---|---|---|
committer | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-03-28 15:02:38 +0000 |
commit | 6a13bd7e89566b76f6c7daf09160f697c2af4df1 (patch) | |
tree | ea540b08dc630bf2efb01c2b50b54a1deb69fb63 /python/vyos | |
parent | 792c00a018d0b237996e60845edf8ad970c4afbb (diff) | |
download | vyos-1x-6a13bd7e89566b76f6c7daf09160f697c2af4df1.tar.gz vyos-1x-6a13bd7e89566b76f6c7daf09160f697c2af4df1.zip |
ifconfig: T2057: correctly provide the reason why a MAC could not be set
Diffstat (limited to 'python/vyos')
-rw-r--r-- | python/vyos/validate.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/python/vyos/validate.py b/python/vyos/validate.py index 48a18642b..0e6d34e7e 100644 --- a/python/vyos/validate.py +++ b/python/vyos/validate.py @@ -204,11 +204,19 @@ def assert_mtu(mtu, min=68, max=9000): def assert_mac(m): - octets = [int(i, 16) for i in m.split(':')] + split = m.split(':') + size = len(split) # a mac address consits out of 6 octets - if len(octets) != 6: - raise ValueError(f'wrong number of MAC octets: {octets}') + if size != 6: + raise ValueError(f'wrong number of MAC octets ({size}): {m}') + + octets = [] + try: + for octet in split: + octets.append(int(octet, 16)) + except ValueError: + raise ValueError(f'invalid hex number "{octet}" in : {m}') # validate against the first mac address byte if it's a multicast # address |