Skip to content

Commit e27bd27

Browse files
committed
dhcp: allow reserved leases outside scope pool range but within subnet
Reserved DHCP leases whose IP is outside the scope's [startingAddress, endingAddress] pool range but still inside the scope's subnet were rejected on add and, when added via the API back door, failed unicast renewal. - Scope: validate reserved-lease addresses by subnet membership (IsAddressInNetwork) instead of pool range (IsAddressInRange), in both the ReservedLeases setter and TryAddReservedLease so the console form and API agree. Wrong-subnet addresses are still rejected. - DhcpServer.FindScope: in the no-relay unicast (RENEW/REBIND) branch, match the scope by the client's reserved lease (keyed on MAC) before the pool-range check, mirroring the broadcast and relay branches. Previously an out-of-pool ciaddr matched no scope, so the REQUEST was silently dropped and the client lost its lease at T1.
1 parent d0484b6 commit e27bd27

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

DnsServerCore/Dhcp/DhcpServer.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,14 @@ private Scope FindScope(DhcpMessage request, IPAddress remoteAddress, IPPacketIn
655655
{
656656
Scope scope = entry.Value;
657657

658-
if (scope.Enabled && scope.IsAddressInRange(request.ClientIpAddress))
658+
if (!scope.Enabled)
659+
continue;
660+
661+
Lease reservedLease = scope.GetReservedLease(request);
662+
if ((reservedLease is not null) && reservedLease.Address.Equals(request.ClientIpAddress))
663+
return scope; //ciaddr is this client's reserved address (may be out of pool range)
664+
665+
if (scope.IsAddressInRange(request.ClientIpAddress))
659666
return scope;
660667
}
661668

DnsServerCore/Dhcp/Scope.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,9 @@ public void ChangeNetwork(IPAddress startingAddress, IPAddress endingAddress, IP
14771477

14781478
public bool TryAddReservedLease(Lease reservedLease)
14791479
{
1480+
if (!IsAddressInNetwork(reservedLease.Address))
1481+
throw new ArgumentOutOfRangeException(nameof(reservedLease), "Reserved address must be within the scope's subnet.");
1482+
14801483
if (_reservedLeases.TryAdd(reservedLease.ClientIdentifier, reservedLease))
14811484
{
14821485
_dhcpServer.AddDnsEntries(this, reservedLease);
@@ -2175,8 +2178,8 @@ public IReadOnlyCollection<Lease> ReservedLeases
21752178
{
21762179
foreach (Lease reservedLease in value)
21772180
{
2178-
if (!IsAddressInRange(reservedLease.Address))
2179-
throw new ArgumentOutOfRangeException(nameof(ReservedLeases), "Reserved address must be in scope range.");
2181+
if (!IsAddressInNetwork(reservedLease.Address))
2182+
throw new ArgumentOutOfRangeException(nameof(ReservedLeases), "Reserved address must be within the scope's subnet.");
21802183
}
21812184

21822185
//remove DNS entries for reserved leases being removed or has updated domain name

0 commit comments

Comments
 (0)