From 396329cc9a2419c5be8ddd0bc8fbde67fdcb03fa Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Wed, 23 Aug 2023 20:14:37 +0200 Subject: vrf: T5428: stop DHCP processes on VRF removal This is a workaround for the priority inversion from T5492 ("CLI node priority is not inversed on node deletion"). As this is a corner case bug that's only triggered if an interface is removed from a VRF and also the VRF is removed in one commit, priorities are not honored. Thus we implement this workaround which stop the DHCP(v6) client processes on the VRF associated interfaces to get out the DHCP RELEASE message before interfaces are shut down. (cherry picked from commit 005151f77be5cf999689cfd03620bbc39df59018) --- python/vyos/util.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'python') diff --git a/python/vyos/util.py b/python/vyos/util.py index 03809fc83..ede22006c 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -912,3 +912,24 @@ def sysctl_write(name, value): def is_ipv6_enabled() -> bool: """ Check if IPv6 support on the system is enabled or not """ return (sysctl_read('net.ipv6.conf.all.disable_ipv6') == '0') + +def interface_exists(interface) -> bool: + import os + return os.path.exists(f'/sys/class/net/{interface}') + +def get_vrf_members(vrf: str) -> list: + """ + Get list of interface VRF members + :param vrf: str + :return: list + """ + import json + if not interface_exists(vrf): + raise ValueError(f'VRF "{vrf}" does not exist!') + output = cmd(f'ip --json --brief link show master {vrf}') + answer = json.loads(output) + interfaces = [] + for data in answer: + if 'ifname' in data: + interfaces.append(data.get('ifname')) + return interfaces -- cgit v1.2.3