Skip to content

Commit 6373780

Browse files
committed
T7557: Fix netplug hook for interface flapping
1 parent 5462fd6 commit 6373780

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

python/vyos/ifconfig/interface.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from vyos.utils.network import get_interface_namespace
4949
from vyos.utils.network import get_vrf_tableid
5050
from vyos.utils.network import is_netns_interface
51+
from vyos.utils.network import is_carrier_up
5152
from vyos.utils.process import is_systemd_service_active
5253
from vyos.utils.process import run
5354
from vyos.utils.file import read_file
@@ -1525,7 +1526,9 @@ def set_dhcp(self, enable: bool, vrf_changed: bool=False):
15251526
# the old lease is released a new one is acquired (T4203). We will
15261527
# only restart DHCP client if it's option changed, or if it's not
15271528
# running, but it should be running (e.g. on system startup)
1528-
if (vrf_changed or
1529+
#
1530+
# T7557 - Add carrier check, netplug hook will start it
1531+
if is_carrier_up(self.ifname) and (vrf_changed or
15291532
('dhcp_options_changed' in self.config) or
15301533
(not is_systemd_service_active(systemd_service))):
15311534
return self._cmd(f'systemctl restart {systemd_service}')
@@ -1582,7 +1585,9 @@ def set_dhcpv6(self, enable: bool, vrf_changed: bool=False):
15821585

15831586
# We must ignore any return codes. This is required to enable
15841587
# DHCPv6-PD for interfaces which are yet not up and running.
1585-
if (vrf_changed or
1588+
#
1589+
# T7557 - Add carrier check, netplug hook will start it
1590+
if is_carrier_up(self.ifname) and (vrf_changed or
15861591
('dhcpv6_options_changed' in self.config) or
15871592
(not is_systemd_service_active(systemd_service))):
15881593
return self._popen(f'systemctl restart {systemd_service}')

python/vyos/utils/network.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,3 +666,11 @@ def is_valid_ipv6_address_or_range(addr: str) -> bool:
666666
return ip_network(addr).version == 6
667667
except:
668668
return False
669+
670+
def is_carrier_up(ifname: str) -> bool | None:
671+
try:
672+
carrier_path = f'/sys/class/net/{ifname}/carrier'
673+
with open(carrier_path, 'r') as f:
674+
return f.read().strip() == '1'
675+
except:
676+
return None

src/etc/netplug/vyos-netplug-dhcp-client

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ from time import sleep
2222
from vyos.config import Config
2323
from vyos.ifconfig import Section
2424
from vyos.utils.boot import boot_configuration_complete
25+
from vyos.utils.network import is_carrier_up
2526
from vyos.utils.process import cmd
2627
from vyos.utils.process import is_systemd_service_active
2728
from vyos.utils.commit import commit_in_progress
@@ -49,7 +50,8 @@ interface_path = ['interfaces'] + Section.get_config_path(interface).split()
4950

5051
systemdV4_service = f'dhclient@{interface}.service'
5152
systemdV6_service = f'dhcp6c@{interface}.service'
52-
if in_out == 'out':
53+
# T7557 - Check the interface is still down at time of script
54+
if in_out == 'out' and not is_carrier_up(interface):
5355
# Interface moved state to down
5456
if is_systemd_service_active(systemdV4_service):
5557
cmd(f'systemctl stop {systemdV4_service}')

0 commit comments

Comments
 (0)