From b0f9bc1c7b4e0e75e9076490e01cb967f87fda37 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 29 Mar 2020 15:59:17 +0530 Subject: [PATCH] DhcpServer: fixed unhandeled exception in ReadUdpRequestAsync(). Removed marking dhcp forward and reverse zones as internal to allow users to edit those zones. ActivateScope() updated to also remove expired leases from the zones. --- DnsServerCore/Dhcp/DhcpServer.cs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/DnsServerCore/Dhcp/DhcpServer.cs b/DnsServerCore/Dhcp/DhcpServer.cs index 59a1317a..d0a65547 100644 --- a/DnsServerCore/Dhcp/DhcpServer.cs +++ b/DnsServerCore/Dhcp/DhcpServer.cs @@ -1,6 +1,6 @@ /* Technitium DNS Server -Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com) +Copyright (C) 2020 Shreyas Zare (shreyas@technitium.com) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -144,10 +144,11 @@ namespace DnsServerCore.Dhcp EndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0); byte[] recvBuffer = new byte[576]; int bytesRecv; - bool processOnlyUnicastMessages = !(udpListener.LocalEndPoint as IPEndPoint).Address.Equals(IPAddress.Any); //only 0.0.0.0 ip should process broadcast to avoid duplicate offers on Windows try { + bool processOnlyUnicastMessages = !(udpListener.LocalEndPoint as IPEndPoint).Address.Equals(IPAddress.Any); //only 0.0.0.0 ip should process broadcast to avoid duplicate offers on Windows + while (true) { SocketFlags flags = SocketFlags.None; @@ -629,8 +630,6 @@ namespace DnsServerCore.Dhcp //create forward zone _authoritativeZoneRoot.SetRecords(scope.DomainName, DnsResourceRecordType.SOA, 14400, new DnsResourceRecordData[] { new DnsSOARecord(_authoritativeZoneRoot.ServerDomain, "hostmaster." + scope.DomainName, 1, 14400, 3600, 604800, 900) }); _authoritativeZoneRoot.SetRecords(scope.DomainName, DnsResourceRecordType.NS, 14400, new DnsResourceRecordData[] { new DnsNSRecord(_authoritativeZoneRoot.ServerDomain) }); - - _authoritativeZoneRoot.MakeZoneInternal(scope.DomainName); } _authoritativeZoneRoot.SetRecords(lease.HostName, DnsResourceRecordType.A, scope.DnsTtl, new DnsResourceRecordData[] { new DnsARecord(lease.Address) }); @@ -643,8 +642,6 @@ namespace DnsServerCore.Dhcp //create reverse zone _authoritativeZoneRoot.SetRecords(scope.ReverseZone, DnsResourceRecordType.SOA, 14400, new DnsResourceRecordData[] { new DnsSOARecord(_authoritativeZoneRoot.ServerDomain, "hostmaster." + scope.ReverseZone, 1, 14400, 3600, 604800, 900) }); _authoritativeZoneRoot.SetRecords(scope.ReverseZone, DnsResourceRecordType.NS, 14400, new DnsResourceRecordData[] { new DnsNSRecord(_authoritativeZoneRoot.ServerDomain) }); - - _authoritativeZoneRoot.MakeZoneInternal(scope.ReverseZone); } _authoritativeZoneRoot.SetRecords(Scope.GetReverseZone(lease.Address, 32), DnsResourceRecordType.PTR, scope.DnsTtl, new DnsResourceRecordData[] { new DnsPTRRecord(lease.HostName) }); @@ -764,10 +761,7 @@ namespace DnsServerCore.Dhcp DateTime utcNow = DateTime.UtcNow; foreach (Lease lease in scope.Leases) - { - if (utcNow < lease.LeaseExpires) - UpdateDnsAuthZone(true, scope, lease); //lease valid - } + UpdateDnsAuthZone(utcNow < lease.LeaseExpires, scope, lease); //lease valid } LogManager log = _log;