Skip to content

FirewallRuleKeeper

Class in Oadm.Sdk.Network · Oadm.Sdk.dll

Keeps one firewall rule in line with a service’s enabled state (NTP server, DHCP server): FirewallRuleKeeper.SyncAsync opens the rule when the service is enabled and closes it when disabled or stopped. The first call always applies the state (a rule left by a crashed server is removed), later calls only on a change. Best effort: firewall errors are logged and never fail the service. Without a host firewall (null) it does nothing. Not thread-safe: callers serialize the calls (the services call it under their own gate).

public sealed class FirewallRuleKeeper
FirewallRuleKeeper(FirewallRule rule, IFirewallRules? firewall, ILogger? logger = null)

Keeps rule; without firewall it does nothing.

bool IsOpen { get; }

True once the rule was opened (and not closed since).

FirewallRule Rule { get; }

The rule it keeps.

Task SyncAsync(bool enabled, CancellationToken ct)

Opens the rule when enabled, closes it otherwise.