diff options
author | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-06-15 17:15:06 +0100 |
---|---|---|
committer | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-06-15 17:15:06 +0100 |
commit | d6acd1f07c7257bbded38a6b6189cf3964b87b7f (patch) | |
tree | aebb256325024f500e5b584f926ec49d2439ed5b /python | |
parent | 8193515fe6fefb9ca5b5d0f38f89745ad46a3682 (diff) | |
download | vyos-1x-d6acd1f07c7257bbded38a6b6189cf3964b87b7f.tar.gz vyos-1x-d6acd1f07c7257bbded38a6b6189cf3964b87b7f.zip |
ifconfig: T2599: fix regex for search, smaller numbers
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/ifconfig/section.py | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/python/vyos/ifconfig/section.py b/python/vyos/ifconfig/section.py index bf1468bdb..173a90bb4 100644 --- a/python/vyos/ifconfig/section.py +++ b/python/vyos/ifconfig/section.py @@ -110,24 +110,22 @@ class Section: """ def key(ifname): value = 0 - parts = re.split(r'(\w+)([0-9])[.]?([0-9]+)?[.]?([0-9]+)?', ifname) + parts = re.split(r'([^0-9]+)([0-9]+)[.]?([0-9]+)?[.]?([0-9]+)?', ifname) length = len(parts) name = parts[1] if length >= 3 else parts[0] - number = int(parts[2]) if length >= 4 and parts[2] is not None else 0 - vlan = int(parts[3]) if length >= 5 and parts[3] is not None else 0 - qinq = int(parts[4]) if length >= 6 and parts[4] is not None else 0 + # the +1 makes sure eth0.0.0 after eth0.0 + number = int(parts[2]) + 1 if length >= 4 and parts[2] is not None else 0 + vlan = int(parts[3]) + 1 if length >= 5 and parts[3] is not None else 0 + qinq = int(parts[4]) + 1 if length >= 6 and parts[4] is not None else 0 # so that "lo" (or short names) are handled (as "loa") for n in (name + 'aaa')[:3]: value *= 100 value += (ord(n) - ord('a')) - - for n in (number, vlan, qinq): - # if the interface number is big enough it could cause the order to not be right - # but there is no real alternative with only one pass over the data - value *= 100000 - # the +1 makes sure eth0.0.0 after eth0.0 - value += (n+1) + value += number + # vlan are 16 bits, so this can not overflow + value = (value << 16) + vlan + value = (value << 16) + qinq return value l = list(generator) |