mirror of
https://github.com/alexhopeoconnor/dnsmasq-webui.git
synced 2026-10-03 22:12:00 +10:00
- OptionSemantics: metadata only (no validator delegates); OptionValidationKind + PathPolicy - IOptionSemanticHandler: handler-first validation; handlers registered via IApplicationMultiSingleton - OptionSemanticValidator: single engine, handler dispatch then generic kind-based validation - Shared syntax: DnsmasqScopedDomainSyntax, DnsmasqDhcpRangeValueParser, DnsmasqDhcpOptionSyntax, DnsmasqRelaySyntax, DnsmasqDhcpTagSyntax, DnsmasqIpPrefixSyntax for reuse across handlers - New handlers: Server, Local, RevServer, Address, Alias, Ipset, Nftset, DhcpRange, DhcpHost, DhcpOption, DhcpRelay, DhcpProxy, IgnoreAddress, ConnmarkAllowlist, DhcpMatch, DhcpMac, PxeService, TrustAnchor, RebindDomainOk, BogusNxdomain, DhcpIgnoreNames, DhcpBoot, Slaac, BridgeInterface, SharedNetwork, DhcpOptionPxe, DhcpNameMatch, DhcpIgnore, DhcpVendorclass, DhcpUserclass, TagIf - Registry and pre-save validation use engine only; placeholders via DnsmasqOptionPlaceholders - DnsmasqConfigSetService uses DnsmasqDhcpRangeValueParser; DhcpRangeValueParserTests added
28 lines
962 B
C#
28 lines
962 B
C#
using System.Net;
|
|
|
|
namespace DnsmasqWebUI.Infrastructure.Services.EffectiveConfig.Validation;
|
|
|
|
/// <summary>
|
|
/// Shared helpers for option values that are an IP literal with an optional prefix length.
|
|
/// </summary>
|
|
internal static class DnsmasqIpPrefixSyntax
|
|
{
|
|
public static string? ValidateIpWithOptionalPrefix(string value, string optionName)
|
|
{
|
|
var parts = value.Split('/', 2);
|
|
if (!IPAddress.TryParse(parts[0], out var ip))
|
|
return $"{optionName} must start with a valid IP address.";
|
|
|
|
if (parts.Length == 1)
|
|
return null;
|
|
|
|
if (!int.TryParse(parts[1], out var prefix))
|
|
return $"{optionName} prefix length must be numeric.";
|
|
|
|
var maxPrefix = ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork ? 32 : 128;
|
|
return prefix >= 0 && prefix <= maxPrefix
|
|
? null
|
|
: $"{optionName} prefix length must be between 0 and {maxPrefix}.";
|
|
}
|
|
}
|