diff options
| author | l0crian1 <ryan.claridge13@gmail.com> | 2025-10-30 19:47:06 -0400 |
|---|---|---|
| committer | l0crian1 <ryan.claridge13@gmail.com> | 2025-10-30 19:47:06 -0400 |
| commit | 7e5fd62fcf585fa2b72161a7b1d0ba37b565c9eb (patch) | |
| tree | 94a66ff45220443dddfcab37c36103d8257e76b7 /src/helpers | |
| parent | c3bc42001e478da712bd6c31befd11f56cbd4236 (diff) | |
| download | vyos-1x-7e5fd62fcf585fa2b72161a7b1d0ba37b565c9eb.tar.gz vyos-1x-7e5fd62fcf585fa2b72161a7b1d0ba37b565c9eb.zip | |
wlb: TT7966: Refactor dynamic nexthop resolution
Diffstat (limited to 'src/helpers')
| -rwxr-xr-x | src/helpers/vyos-load-balancer.py | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/helpers/vyos-load-balancer.py b/src/helpers/vyos-load-balancer.py index 249433f0b..bd62d1479 100755 --- a/src/helpers/vyos-load-balancer.py +++ b/src/helpers/vyos-load-balancer.py @@ -103,15 +103,36 @@ def get_ipv4_address(ifname): return addr_json['addr_info'][0]['local'] return None +def get_dynamic_nexthop(ifname: str) -> str | None | bool: + ''' + Resolve the dynamic next-hop for a WAN interface. + + Determines the current default gateway learned dynamically on the interface: + - PPPoE interfaces (`pppoe*`): uses `parse_ppp_nexthop`. + - Other interfaces (e.g. DHCP): uses `parse_dhcp_nexthop`. + + Return values: + - str: IPv4 next-hop address + - None: when DHCP lease has no router value + - False: when PPPoE nexthop state file is missing + + Args: + ifname: Interface name (e.g. 'pppoe0', 'eth0'). + + Returns: + See above for possible values. + ''' + if ifname.startswith('pppoe'): + return parse_ppp_nexthop(ifname) + else: + return parse_dhcp_nexthop(ifname) + def dynamic_nexthop_update(lb, ifname): # Update on DHCP/PPP address/nexthop changes # Return True if nftables needs to be updated - IP change if 'dhcp_nexthop' in lb['health_state'][ifname]: - if ifname[:5] == 'pppoe': - dhcp_nexthop_addr = parse_ppp_nexthop(ifname) - else: - dhcp_nexthop_addr = parse_dhcp_nexthop(ifname) + dhcp_nexthop_addr = get_dynamic_nexthop(ifname) table_num = lb['health_state'][ifname]['table_number'] @@ -151,10 +172,7 @@ def restore_default_route(lb: dict, ifname: str) -> None: return else: if 'dhcp_nexthop' in lb['health_state'][ifname]: - if ifname[:5] == 'pppoe': - nexthop_addr = parse_ppp_nexthop(ifname) - else: - nexthop_addr = parse_dhcp_nexthop(ifname) + nexthop_addr = get_dynamic_nexthop(ifname) else: nexthop_addr = dict_search_args(lb, 'interface_health', ifname, 'nexthop') @@ -335,7 +353,6 @@ if __name__ == '__main__': restore_default_route(lb, ifname) - if any(state['state_changed'] for ifname, state in lb['health_state'].items()): if not nftables_update(lb): break |
