Skip to content

Commit c053764

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

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

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)