diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-03-28 16:07:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-28 16:07:50 +0100 |
commit | b53d0e10d0fc7ed9d18833008da1d4a1d2520a78 (patch) | |
tree | ea540b08dc630bf2efb01c2b50b54a1deb69fb63 /python/vyos | |
parent | 792c00a018d0b237996e60845edf8ad970c4afbb (diff) | |
parent | 6a13bd7e89566b76f6c7daf09160f697c2af4df1 (diff) | |
download | vyos-1x-b53d0e10d0fc7ed9d18833008da1d4a1d2520a78.tar.gz vyos-1x-b53d0e10d0fc7ed9d18833008da1d4a1d2520a78.zip |
Merge pull request #279 from thomas-mangin/T2057-better-mac
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 |