diff options
| author | Robert Navarro <crshman@gmail.com> | 2026-05-31 13:34:09 -0700 |
|---|---|---|
| committer | Robert Navarro <crshman@gmail.com> | 2026-06-03 10:19:54 -0700 |
| commit | 3649dd09743e47700d36ecd25bffcd77dbb3cc3f (patch) | |
| tree | dc4b580eee974d347ba7a7dcca7fa47e17c46906 /src | |
| parent | 6d0d9e424936671f03df19ee59c94f7aa5c69d3e (diff) | |
| download | vyos-1x-3649dd09743e47700d36ecd25bffcd77dbb3cc3f.tar.gz vyos-1x-3649dd09743e47700d36ecd25bffcd77dbb3cc3f.zip | |
vyos-netlinkd: T8950: track per-interface operstate to suppress UP-to-UP DHCP restarts
_handle_dhcp_events() restarts dhclient/dhcp6c on every RTM_NEWLINK
that carries operstate=UP, regardless of whether the interface was
already UP. Normal kernel events that re-notify UP without a preceding
DOWN (e.g. post-migration gratuitous-ARP, promiscuous-mode toggles)
trigger unnecessary DHCP restarts. Each restart also creates a feedback
loop: dhclient-script runs "ip link set dev <if> up" during PREINIT,
which emits another RTM_NEWLINK(UP), which triggers another restart.
One seed event becomes 10+ restarts in 15 seconds.
Add a module-level dict tracking the last observed operstate per
interface. Only proceed with the DHCP restart when the transition is
DOWN-to-UP or when no previous state is recorded (first boot / service
restart). UP-to-UP re-notifications are suppressed with a LOG_DEBUG
message.
Validated on a production VyOS 2026.05.26-1327-rolling router: a
controlled KVM live migration after the patch produced zero DHCP
restarts (all UP-to-UP events suppressed), with no impact on normal
DOWN-to-UP DHCP recovery.
Diffstat (limited to 'src')
| -rwxr-xr-x | src/services/vyos-netlinkd | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/services/vyos-netlinkd b/src/services/vyos-netlinkd index 2b158e05d..0e7da7a59 100755 --- a/src/services/vyos-netlinkd +++ b/src/services/vyos-netlinkd @@ -40,6 +40,10 @@ running = True # compile regex once during startup for fast match IFACE_RE = re.compile(r"^(?:eth|br|bond|wlan)") +# Per-interface previous operstate, used to suppress DHCP restarts on +# UP-to-UP re-notifications (e.g. post-migration gratuitous-ARP events). +_iface_prev_operstate: dict[str, str] = {} + def match_iface(ifname: str) -> bool: """ Helper function returning true if interface name is a match for further processing (e.g. restart of DHCP(v6) client) @@ -60,6 +64,14 @@ def _handle_dhcp_events(operstate: Optional[str], ifname: str) -> None: if operstate not in ['UP', 'DOWN']: return None + prev = _iface_prev_operstate.get(ifname) + _iface_prev_operstate[ifname] = operstate + + if operstate == 'UP' and prev == 'UP': + syslog.syslog(syslog.LOG_DEBUG, + f'Suppressing DHCP restart for {ifname}: already UP') + return None + if operstate == 'DOWN': # Interface moved state to down if is_systemd_service_active(systemdV4_service): @@ -168,7 +180,10 @@ def main(): # Deletion of a network link which has been previously added to the kernel case 'RTM_DELLINK': - pass + attrs = dict(message.get('attrs', [])) + ifname = attrs.get('IFLA_IFNAME', None) + if ifname: + _iface_prev_operstate.pop(ifname, None) case _: pass |
