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
gatewayline undervmbr0in/etc/network/interfaces+ runsifreload -a. -
In-memory:
config.GatewayIP = opnsenseLanso NixOS VMs re-template theirnetworking.defaultGatewayviaUpdateNixosVmnext 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)
| 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)
| Name | Type | Description |
|---|---|---|
host |
ISystemHost |
|
config |
NETSetupConfig |
|
pingFn |
Func<string, bool> |
|
execFn |
Action<string> |
Returns: EnsureGatewayTakeover.Outcome