summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-12-18 23:01:43 +0100
committerChristian Breunig <christian@breunig.cc>2024-12-18 23:01:43 +0100
commitd2a7584a6d5cc3fcd01471b9cfd45735b5458724 (patch)
tree3c648d102bd36576f18a02cdfc2de9cd4e7f00ba
parent77628e49379066e07b4046a00007187263e7206b (diff)
downloadvyos-1x-d2a7584a6d5cc3fcd01471b9cfd45735b5458724.tar.gz
vyos-1x-d2a7584a6d5cc3fcd01471b9cfd45735b5458724.zip
ifconfig: fix AttributeError caused by internal race condition
File "/usr/lib/python3/dist-packages/vyos/ifconfig/interface.py", line 342 if not self.iftype: ^^^^^^^^^^^ AttributeError: 'Interface' object has no attribute 'iftype'
-rw-r--r--python/vyos/ifconfig/interface.py11
-rw-r--r--python/vyos/ifconfig/macvlan.py5
2 files changed, 7 insertions, 9 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py
index cd562e1fe..eac9f61f5 100644
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -26,8 +26,9 @@ from netifaces import ifaddresses
# this is not the same as socket.AF_INET/INET6
from netifaces import AF_INET
from netifaces import AF_INET6
+from netaddr import EUI
+from netaddr import mac_unix_expanded
-from vyos import ConfigError
from vyos.configdict import list_diff
from vyos.configdict import dict_merge
from vyos.configdict import get_vlan_ids
@@ -61,9 +62,7 @@ from vyos.ifconfig.control import Control
from vyos.ifconfig.vrrp import VRRP
from vyos.ifconfig.operational import Operational
from vyos.ifconfig import Section
-
-from netaddr import EUI
-from netaddr import mac_unix_expanded
+from vyos import ConfigError
link_local_prefix = 'fe80::/64'
@@ -339,8 +338,8 @@ class Interface(Control):
# Any instance of Interface, such as Interface('eth0') can be used
# safely to access the generic function in this class as 'type' is
# unset, the class can not be created
- if not self.iftype:
- raise Exception(f'interface "{ifname}" not found')
+ if not hasattr(self, 'iftype'):
+ raise ConfigError(f'Interface "{ifname}" has no "iftype" attribute defined!')
self.config['type'] = self.iftype
# Should an Instance of a child class (EthernetIf, DummyIf, ..)
diff --git a/python/vyos/ifconfig/macvlan.py b/python/vyos/ifconfig/macvlan.py
index 2266879ec..fb7f1d298 100644
--- a/python/vyos/ifconfig/macvlan.py
+++ b/python/vyos/ifconfig/macvlan.py
@@ -1,4 +1,4 @@
-# Copyright 2019-2022 VyOS maintainers and contributors <maintainers@vyos.io>
+# Copyright 2019-2024 VyOS maintainers and contributors <maintainers@vyos.io>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -42,6 +42,5 @@ class MACVLANIf(Interface):
self.set_admin_state('down')
def set_mode(self, mode):
- ifname = self.config['ifname']
- cmd = f'ip link set dev {ifname} type macvlan mode {mode}'
+ cmd = f'ip link set dev {self.ifname} type {self.iftype} mode {mode}'
return self._cmd(cmd)