summaryrefslogtreecommitdiff
path: root/python/vyos/ifconfig
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-10-09 08:38:06 +0200
committerChristian Poessinger <christian@poessinger.com>2021-10-09 08:38:06 +0200
commitf19c92f255011149eeb7626a2e158456abe4c9b8 (patch)
tree0cd51a6342248358cda76068ccecfa01c0ba216a /python/vyos/ifconfig
parent5aadf673497b93e2d4ad304e567de1cd571f9e25 (diff)
downloadvyos-1x-f19c92f255011149eeb7626a2e158456abe4c9b8.tar.gz
vyos-1x-f19c92f255011149eeb7626a2e158456abe4c9b8.zip
tunnel: T3894: fix design when building synthetic MAC addresses
It seems not all systems have eth0 - get a list of all available Ethernet interfaces on the system (without VLAN subinterfaces) and then take the first one.
Diffstat (limited to 'python/vyos/ifconfig')
-rwxr-xr-xpython/vyos/ifconfig/interface.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index e6dbd861b..c73ffb634 100755
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -461,15 +461,19 @@ class Interface(Control):
# Get processor ID number
cpu_id = self._cmd('sudo dmidecode -t 4 | grep ID | head -n1 | sed "s/.*ID://;s/ //g"')
- # Get system eth0 base MAC address - every system has eth0
- eth0_mac = Interface('eth0').get_mac()
+
+ # XXX: T3894 - it seems not all systems have eth0 - get a list of all
+ # available Ethernet interfaces on the system (without VLAN subinterfaces)
+ # and then take the first one.
+ all_eth_ifs = [x for x in Section.interfaces('ethernet') if '.' not in x]
+ first_mac = Interface(all_eth_ifs[0]).get_mac()
sha = sha256()
# Calculate SHA256 sum based on the CPU ID number, eth0 mac address and
# this interface identifier - this is as predictable as an interface
# MAC address and thus can be used in the same way
sha.update(cpu_id.encode())
- sha.update(eth0_mac.encode())
+ sha.update(first_mac.encode())
sha.update(self.ifname.encode())
# take the most significant 48 bits from the SHA256 string
tmp = sha.hexdigest()[:12]