diff --git a/DnsServerCore/Dhcp/DhcpServer.cs b/DnsServerCore/Dhcp/DhcpServer.cs index f7806d22b..4ad42b5c0 100644 --- a/DnsServerCore/Dhcp/DhcpServer.cs +++ b/DnsServerCore/Dhcp/DhcpServer.cs @@ -655,7 +655,14 @@ private Scope FindScope(DhcpMessage request, IPAddress remoteAddress, IPPacketIn { Scope scope = entry.Value; - if (scope.Enabled && scope.IsAddressInRange(request.ClientIpAddress)) + if (!scope.Enabled) + continue; + + Lease reservedLease = scope.GetReservedLease(request); + if ((reservedLease is not null) && reservedLease.Address.Equals(request.ClientIpAddress)) + return scope; //ciaddr is this client's reserved address (may be out of pool range) + + if (scope.IsAddressInRange(request.ClientIpAddress)) return scope; } diff --git a/DnsServerCore/Dhcp/Scope.cs b/DnsServerCore/Dhcp/Scope.cs index 4486dd566..4240c23f8 100644 --- a/DnsServerCore/Dhcp/Scope.cs +++ b/DnsServerCore/Dhcp/Scope.cs @@ -1477,6 +1477,9 @@ public void ChangeNetwork(IPAddress startingAddress, IPAddress endingAddress, IP public bool TryAddReservedLease(Lease reservedLease) { + if (!IsAddressInNetwork(reservedLease.Address)) + throw new ArgumentOutOfRangeException(nameof(reservedLease), "Reserved address must be within the scope's subnet."); + if (_reservedLeases.TryAdd(reservedLease.ClientIdentifier, reservedLease)) { _dhcpServer.AddDnsEntries(this, reservedLease); @@ -2175,8 +2178,8 @@ public IReadOnlyCollection ReservedLeases { foreach (Lease reservedLease in value) { - if (!IsAddressInRange(reservedLease.Address)) - throw new ArgumentOutOfRangeException(nameof(ReservedLeases), "Reserved address must be in scope range."); + if (!IsAddressInNetwork(reservedLease.Address)) + throw new ArgumentOutOfRangeException(nameof(ReservedLeases), "Reserved address must be within the scope's subnet."); } //remove DNS entries for reserved leases being removed or has updated domain name