TechnitiumSoftware / DnsServer

Technitium DNS Server
https://technitium.com/dns/
GNU General Public License v3.0
4.25k stars 418 forks source link

Misleading exception message suggests address pool exhaustion when exception is really due to scope configuration only offering reserved leases #66

Closed PonchoPowers closed 4 years ago

PonchoPowers commented 5 years ago

If the firewall blocks either of the outgoing ports 67 or 68, this leads to address pool exhaustion, and a massive amount of the following errors being logged:

[2019-07-20 01:37:46 UTC] [0.0.0.0:68] DnsServerCore.Dhcp.DhcpServerException: DHCP Server failed to offer address: address unavailable due to address pool exhaustion.

at DnsServerCore.Dhcp.DhcpServer.ProcessDhcpMessage(DhcpMessage request, IPEndPoint remoteEP, IPPacketInformation ipPacketInformation)

at DnsServerCore.Dhcp.DhcpServer.ProcessUdpRequestAsync(Object parameter)

[2019-07-20 01:37:47 UTC] [0.0.0.0:68] DnsServerCore.Dhcp.DhcpServerException: DHCP Server failed to offer address: address unavailable due to address pool exhaustion.

at DnsServerCore.Dhcp.DhcpServer.ProcessDhcpMessage(DhcpMessage request, IPEndPoint remoteEP, IPPacketInformation ipPacketInformation)

at DnsServerCore.Dhcp.DhcpServer.ProcessUdpRequestAsync(Object parameter)

[2019-07-20 01:37:49 UTC] [0.0.0.0:68] DnsServerCore.Dhcp.DhcpServerException: DHCP Server failed to offer address: address unavailable due to address pool exhaustion.

at DnsServerCore.Dhcp.DhcpServer.ProcessDhcpMessage(DhcpMessage request, IPEndPoint remoteEP, IPPacketInformation ipPacketInformation)

at DnsServerCore.Dhcp.DhcpServer.ProcessUdpRequestAsync(Object parameter)

[2019-07-20 01:37:50 UTC] [0.0.0.0:68] DnsServerCore.Dhcp.DhcpServerException: DHCP Server failed to offer address: address unavailable due to address pool exhaustion.

at DnsServerCore.Dhcp.DhcpServer.ProcessDhcpMessage(DhcpMessage request, IPEndPoint remoteEP, IPPacketInformation ipPacketInformation)

at DnsServerCore.Dhcp.DhcpServer.ProcessUdpRequestAsync(Object parameter)

[2019-07-20 01:37:51 UTC] [0.0.0.0:68] DnsServerCore.Dhcp.DhcpServerException: DHCP Server failed to offer address: address unavailable due to address pool exhaustion.

at DnsServerCore.Dhcp.DhcpServer.ProcessDhcpMessage(DhcpMessage request, IPEndPoint remoteEP, IPPacketInformation ipPacketInformation)

at DnsServerCore.Dhcp.DhcpServer.ProcessUdpRequestAsync(Object parameter)

[2019-07-20 01:37:55 UTC] [0.0.0.0:68] DnsServerCore.Dhcp.DhcpServerException: DHCP Server failed to offer address: address unavailable due to address pool exhaustion.

at DnsServerCore.Dhcp.DhcpServer.ProcessDhcpMessage(DhcpMessage request, IPEndPoint remoteEP, IPPacketInformation ipPacketInformation)

at DnsServerCore.Dhcp.DhcpServer.ProcessUdpRequestAsync(Object parameter)

[2019-07-20 01:37:59 UTC] [0.0.0.0:68] DnsServerCore.Dhcp.DhcpServerException: DHCP Server failed to offer address: address unavailable due to address pool exhaustion.

at DnsServerCore.Dhcp.DhcpServer.ProcessDhcpMessage(DhcpMessage request, IPEndPoint remoteEP, IPPacketInformation ipPacketInformation)

at DnsServerCore.Dhcp.DhcpServer.ProcessUdpRequestAsync(Object parameter)

PonchoPowers commented 5 years ago

I should add that I think it is firewall related, haven't been able to quite work out what is going on as of yet.

ShreyasZare commented 5 years ago

Firewall config usually do not block outbound packets. It seems to be something else. I would suggest that you run Wireshark with DHCP traffic filter and see how it goes.

PonchoPowers commented 5 years ago

I have got to the bottom of what is going on now.

Firstly, my apologies as it is my wrongdoing misconfiguring the DHCP server.

But as a result I'd like to make a suggestion anyway.

The option I enabled, causing me problems was the Reserved Leases > Allow Only Reserved Lease Allocations option.

This in turn causes the following code to be executed:

Lease offer = scope.GetOffer(request);
if (offer == null)
  throw new DhcpServerException("DHCP Server failed to offer address: address unavailable due to address pool exhaustion.");

Following it through I get to:

if (_allowOnlyReservedLeases)
  return null; //client does not have reserved address as per scope requirements

This in turn returns null, causing the exception to be thrown.

The exception message makes sense now I know what is going on, but the message is factually incorrect.

I think the code should be changed to:

if (_allowOnlyReservedLeases)
  throw new DhcpServerException("DHCP Server failed to offer address: only reserved leases can be offered.");

This way at least the message makes sense.

Either that or upon returning null, the AllowOnlyReservedLeases property could be checked, and instead of throwing the "address unavailable due to address pool exhaustion." message, you can then throw the "only reserved leases can be offered." message.

PonchoPowers commented 5 years ago

Further down the code:

if (existingOffer.Type == LeaseType.None)
                    return null; //dummy offer so another thread is handling offer; do nothing

also returns null, but this should not throw an exception as the comment suggests another thread is already handling the offer.

ShreyasZare commented 5 years ago

Thanks for the debugging. I will update the exception message.

ShreyasZare commented 4 years ago

Technitium DNS Server v4.1 is now available that fixes this issue.