summaryrefslogtreecommitdiff
path: root/python/vyos/configdict.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/vyos/configdict.py')
-rw-r--r--python/vyos/configdict.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py
index 4a4a767f3..58ecd3f17 100644
--- a/python/vyos/configdict.py
+++ b/python/vyos/configdict.py
@@ -228,6 +228,41 @@ def is_member(conf, interface, intftype=None):
old_level = conf.set_level(old_level)
return ret_val
+def is_source_interface(conf, interface, intftype=None):
+ """
+ Checks if passed interface is configured as source-interface of other
+ interfaces of specified type. intftype is optional, if not passed it will
+ search all known types (currently pppoe, macsec, pseudo-ethernet, tunnel
+ and vxlan)
+
+ Returns:
+ None -> Interface is not a member
+ interface name -> Interface is a member of this interface
+ False -> interface type cannot have members
+ """
+ ret_val = None
+ intftypes = ['macsec', 'pppoe', 'pseudo-ethernet', 'tunnel', 'vxlan']
+ if intftype not in intftypes + [None]:
+ raise ValueError(f'unknown interface type "{intftype}" or it can not '
+ 'have a source-interface')
+
+ intftype = intftypes if intftype == None else [intftype]
+
+ # set config level to root
+ old_level = conf.get_level()
+ conf.set_level([])
+
+ for it in intftype:
+ base = ['interfaces', it]
+ for intf in conf.list_nodes(base):
+ lower_intf = base + [intf, 'source-interface']
+ if conf.exists(lower_intf) and interface in conf.return_values(lower_intf):
+ ret_val = intf
+ break
+
+ old_level = conf.set_level(old_level)
+ return ret_val
+
def get_interface_dict(config, base, ifname=''):
"""
Common utility function to retrieve and mandgle the interfaces available
@@ -284,6 +319,17 @@ def get_interface_dict(config, base, ifname=''):
bond = is_member(config, ifname, 'bonding')
if bond: dict.update({'is_bond_member' : bond})
+ # Some interfaces come with a source_interface which must also not be part
+ # of any other bond or bridge interface as it is exclusivly assigned as the
+ # Kernels "lower" interface to this new "virtual/upper" interface.
+ if 'source_interface' in dict:
+ # Check if source interface is member of another bridge
+ tmp = is_member(config, dict['source_interface'], 'bridge')
+ if tmp: dict.update({'source_interface_is_bridge_member' : tmp})
+
+ # Check if source interface is member of another bridge
+ tmp = is_member(config, dict['source_interface'], 'bonding')
+ if tmp: dict.update({'source_interface_is_bond_member' : tmp})
mac = leaf_node_changed(config, ['mac'])
if mac: dict.update({'mac_old' : mac})