OuSubnetResolver
Resolves the per-customer LAN CIDR used to size DHCP scopes, derive static reservations, and configure the OPNsense LAN side. Default convention: 10.X.0.0/24 where X is 1-based OU index (1..254). When OuSubnets carries an explicit entry, that value wins.
public static class OuSubnetResolver
1. Fields
1.1. DefaultOuIndex
Default base subnet octet when no explicit OU subnet provided (10.X.0.0/24).
public const int DefaultOuIndex
2. Methods
2.1. AutoCidrForIndex(int)
Auto-derived CIDR for an OU index: 10.{index}.0.0/24. Index clamped to 1..254.
public static string AutoCidrForIndex(int index)
| Name | Type | Description |
|---|---|---|
index |
int |
Returns: string
2.2. DhcpPoolEnd(string, int)
Returns the DHCP-pool end address (default {net}.199) for the CIDR.
public static string DhcpPoolEnd(string cidr, int end = 199)
| Name | Type | Description |
|---|---|---|
cidr |
string |
|
end |
int |
Returns: string
2.3. DhcpPoolStart(string, int)
Returns the DHCP-pool start address (default offset 100 from network base) for the CIDR. Used to seed OPNsense DHCP scope. Caller pairs with DhcpPoolEnd(string, int).
public static string DhcpPoolStart(string cidr, int offset = 100)
| Name | Type | Description |
|---|---|---|
cidr |
string |
|
offset |
int |
Returns: string
2.4. GatewayAddress(string)
Returns the gateway IP of the CIDR (typically {net}.1). For non-/24 prefixes, computes the first host address in the network.
public static string GatewayAddress(string cidr)
| Name | Type | Description |
|---|---|---|
cidr |
string |
Returns: string
2.5. ParseCidr(string)
Parses a CIDR like 10.1.0.0/24 into network address + prefix length. Throws NETSetupException when the input is malformed.
public static (IPAddress NetworkAddress, int PrefixLength) ParseCidr(string cidr)
| Name | Type | Description |
|---|---|---|
cidr |
string |
Returns: (IPAddress NetworkAddress, int PrefixLength)
2.6. ResolveForOu(NETSetupConfig, string, int)
Resolves CIDR for a specific OU. If OuSubnets has the key, returns it; else returns the auto-computed 10.{ouIndex}.0.0/24. ouIndex must be in 1..254 (octet range).
public static string ResolveForOu(NETSetupConfig config, string ouName, int ouIndex)
| Name | Type | Description |
|---|---|---|
config |
NETSetupConfig |
|
ouName |
string |
|
ouIndex |
int |
Returns: string
2.7. ResolveLanCidr(NETSetupConfig)
Returns the primary LAN CIDR. Picks the first entry from OuSubnets when present; otherwise falls back to 10.1.0.0/24.
public static string ResolveLanCidr(NETSetupConfig config)
| Name | Type | Description |
|---|---|---|
config |
NETSetupConfig |
Returns: string