diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-06-15 20:48:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-15 20:48:10 +0200 |
commit | 9c4d9a76d58d872b7828c2f1e762997843bc7cf5 (patch) | |
tree | aebb256325024f500e5b584f926ec49d2439ed5b /python/vyos/ifconfig/section.py | |
parent | 8193515fe6fefb9ca5b5d0f38f89745ad46a3682 (diff) | |
parent | d6acd1f07c7257bbded38a6b6189cf3964b87b7f (diff) | |
download | vyos-1x-9c4d9a76d58d872b7828c2f1e762997843bc7cf5.tar.gz vyos-1x-9c4d9a76d58d872b7828c2f1e762997843bc7cf5.zip |
Merge pull request #458 from thomas-mangin/T2599
ifconfig: T2599: fix regex for search, smaller numbers
Diffstat (limited to 'python/vyos/ifconfig/section.py')
-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) |