EnsureGatewayTakeover

Phase 2 of the OPNsense LAN takeover (see docs/firewall.adoc).

Phase 1 baseline: config.GatewayIP points at the real upstream port (ISP/test-bench). Once the OPNsense VM is provisioned and reachable on its LAN IP, this helper flips:

  • Proxmox host: rewrites gateway line under vmbr0 in /etc/network/interfaces + runs ifreload -a.

  • In-memory: config.GatewayIP = opnsenseLan so NixOS VMs re-template their networking.defaultGateway via UpdateNixosVm next cycle.

Idempotent: ping fails → skip; gateway already == OPNsense LAN → skip; otherwise rewrite. Best-effort: catches all exceptions, logs warning, returns (must never abort RunProxmoxUpdate).

TODO: Windows DC NIC gateway rewrite via PSDirect is not yet implemented — Windows VMs keep their install-time gateway until reinstalled or manually rewired.

public static class EnsureGatewayTakeover

1. Methods

1.1. Run(ISystemHost, NETSetupConfig)

public static void Run(ISystemHost host, NETSetupConfig config)
Table 1. Parameters
Name Type Description

host

ISystemHost

config

NETSetupConfig

1.2. RunCore(ISystemHost, NETSetupConfig, Func<string, bool>, Action<string>)

Testable core. pingFn probes the OPNsense LAN reachability; execFn performs the actual /etc/network/interfaces rewrite
ifreload -a. Both seams are stubbable from unit tests.

public static EnsureGatewayTakeover.Outcome RunCore(ISystemHost host, NETSetupConfig config, Func<string, bool> pingFn, Action<string> execFn)
Table 2. Parameters
Name Type Description

host

ISystemHost

config

NETSetupConfig

pingFn

Func<string, bool>

execFn

Action<string>

Returns: EnsureGatewayTakeover.Outcome