From 97e74caa682298323165baa5055483405b740dac Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Sun, 13 Apr 2025 07:25:32 +0200 Subject: netplug: T7353: bugfix DHCP client not stopped when interface goes down The initial rewrite of vyos-netplug-dhcp-client by me tried to outsmart the DHCP client implementation by re-using vyos.ifconfig.Interface(). This added a regression where an interface loosing it's carrier no longer deconfigured it's IP address. This was a change in behavior form VyOS 1.3. In addition a bug is fixed as when a VLANs interface parent looses it's carrier we now also stop the DHCP client process. This script is now back to simply starting/stopping the DHCP client process. --- src/etc/netplug/vyos-netplug-dhcp-client | 34 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'src/etc') diff --git a/src/etc/netplug/vyos-netplug-dhcp-client b/src/etc/netplug/vyos-netplug-dhcp-client index 7fe6cda75..42ae5df1d 100755 --- a/src/etc/netplug/vyos-netplug-dhcp-client +++ b/src/etc/netplug/vyos-netplug-dhcp-client @@ -20,10 +20,10 @@ import sys from time import sleep from vyos.config import Config -from vyos.configdict import get_interface_dict -from vyos.ifconfig import Interface from vyos.ifconfig import Section from vyos.utils.boot import boot_configuration_complete +from vyos.utils.process import cmd +from vyos.utils.process import is_systemd_service_active from vyos.utils.commit import commit_in_progress from vyos import airbag @@ -38,21 +38,29 @@ if not boot_configuration_complete(): sys.exit(1) interface = sys.argv[1] -# helper scripts should only work on physical interfaces not on individual -# sub-interfaces. Moving e.g. a VLAN interface in/out a VRF will also trigger -# this script which should be prohibited - bail out early -if '.' in interface: - sys.exit(0) while commit_in_progress(): - sleep(1) + sleep(0.250) in_out = sys.argv[2] config = Config() interface_path = ['interfaces'] + Section.get_config_path(interface).split() -_, interface_config = get_interface_dict( - config, interface_path[:-1], ifname=interface, with_pki=True -) -if 'deleted' not in interface_config: - Interface(interface).update(interface_config) + +systemdV4_service = f'dhclient@{interface}.service' +if in_out == 'out': + # Interface moved state to down + if is_systemd_service_active(systemdV4_service): + cmd(f'systemctl stop {systemdV4_service}') +elif in_out == 'in': + if config.exists_effective(interface_path + ['address']): + tmp = config.return_effective_values(interface_path + ['address']) + # Always (re-)start the DHCP(v6) client service. If the DHCP(v6) client + # is already running - which could happen if the interface is re- + # configured in operational down state, it will have a backoff + # time increasing while not receiving a DHCP(v6) reply. + # + # To make the interface instantly available, and as for a DHCP(v6) lease + # we will re-start the service and thus cancel the backoff time. + if 'dhcp' in tmp: + cmd(f'systemctl restart {systemdV4_service}') -- cgit v1.2.3 From 588f2e02028bc3e0d1203c750c3cba56fb8291f2 Mon Sep 17 00:00:00 2001 From: Christian Breunig Date: Mon, 14 Apr 2025 21:26:47 +0200 Subject: netplug: T7360: DHCPv6 address is not cleared when interface goes oper-down When an interface goes down - e.g. cable unplugged - the DHCPv6 assigned IPv6 address is not removed from said interface. We should provide the same behavior as with IPv4. IPv6 address should be removed and dhcpv6 client restarted once the interface goes operational up again. --- src/etc/netplug/vyos-netplug-dhcp-client | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/etc') diff --git a/src/etc/netplug/vyos-netplug-dhcp-client b/src/etc/netplug/vyos-netplug-dhcp-client index 42ae5df1d..a230fe900 100755 --- a/src/etc/netplug/vyos-netplug-dhcp-client +++ b/src/etc/netplug/vyos-netplug-dhcp-client @@ -48,10 +48,13 @@ config = Config() interface_path = ['interfaces'] + Section.get_config_path(interface).split() systemdV4_service = f'dhclient@{interface}.service' +systemdV6_service = f'dhcp6c@{interface}.service' if in_out == 'out': # Interface moved state to down if is_systemd_service_active(systemdV4_service): cmd(f'systemctl stop {systemdV4_service}') + if is_systemd_service_active(systemdV6_service): + cmd(f'systemctl stop {systemdV6_service}') elif in_out == 'in': if config.exists_effective(interface_path + ['address']): tmp = config.return_effective_values(interface_path + ['address']) @@ -64,3 +67,5 @@ elif in_out == 'in': # we will re-start the service and thus cancel the backoff time. if 'dhcp' in tmp: cmd(f'systemctl restart {systemdV4_service}') + if 'dhcpv6' in tmp: + cmd(f'systemctl restart {systemdV6_service}') -- cgit v1.2.3