From d7f4719fd02fbde5a6ea4a20847f06c70cd3fd8f Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 4 Oct 2020 14:35:16 +0530 Subject: [PATCH] DhcpServer: added support to shift an allocation from dynamic to another reserved lease address and vice versa. --- DnsServerCore/Dhcp/DhcpServer.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/DnsServerCore/Dhcp/DhcpServer.cs b/DnsServerCore/Dhcp/DhcpServer.cs index b36275e2..00153a2b 100644 --- a/DnsServerCore/Dhcp/DhcpServer.cs +++ b/DnsServerCore/Dhcp/DhcpServer.cs @@ -347,6 +347,26 @@ namespace DnsServerCore.Dhcp //send nak return new DhcpMessage(request, IPAddress.Any, IPAddress.Any, new DhcpOption[] { new DhcpMessageTypeOption(DhcpMessageType.Nak), new ServerIdentifierOption(scope.InterfaceAddress), DhcpOption.CreateEndOption() }); } + + Lease reservedLease = scope.GetReservedLease(request); + if (reservedLease == null) + { + if (leaseOffer.Type == LeaseType.Reserved) + { + //client's reserved has been removed so release the current lease and send NAK to allow it to get new allocation + scope.ReleaseLease(leaseOffer); + return new DhcpMessage(request, IPAddress.Any, IPAddress.Any, new DhcpOption[] { new DhcpMessageTypeOption(DhcpMessageType.Nak), new ServerIdentifierOption(scope.InterfaceAddress), DhcpOption.CreateEndOption() }); + } + } + else + { + if (!reservedLease.Address.Equals(leaseOffer.Address)) + { + //client has a new reserved lease so release the current lease and send NAK to allow it to get new allocation + scope.ReleaseLease(leaseOffer); + return new DhcpMessage(request, IPAddress.Any, IPAddress.Any, new DhcpOption[] { new DhcpMessageTypeOption(DhcpMessageType.Nak), new ServerIdentifierOption(scope.InterfaceAddress), DhcpOption.CreateEndOption() }); + } + } } else {