From c022e31ad51e249e8ca9cf349f96b28c6ceca649 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sat, 26 Sep 2020 12:20:14 +0530 Subject: [PATCH] DhcpServer: fixed issue in FindScope() caused due to unnecessary validation to check if RelayAgentIpAddress equals remoteAddress. --- DnsServerCore/Dhcp/DhcpServer.cs | 35 ++++++++++++-------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/DnsServerCore/Dhcp/DhcpServer.cs b/DnsServerCore/Dhcp/DhcpServer.cs index 08cb31b1..0a958684 100644 --- a/DnsServerCore/Dhcp/DhcpServer.cs +++ b/DnsServerCore/Dhcp/DhcpServer.cs @@ -578,8 +578,6 @@ namespace DnsServerCore.Dhcp private Scope FindScope(DhcpMessage request, IPAddress remoteAddress, IPPacketInformation ipPacketInformation) { - bool broadcast; - if (request.RelayAgentIpAddress.Equals(IPAddress.Any)) { //no relay agent @@ -588,39 +586,32 @@ namespace DnsServerCore.Dhcp if (!ipPacketInformation.Address.Equals(IPAddress.Broadcast)) return null; //message destination address must be broadcast address - broadcast = true; //broadcast request + //broadcast request + foreach (KeyValuePair scope in _scopes) + { + if (scope.Value.Enabled && (scope.Value.InterfaceIndex == ipPacketInformation.Interface)) + return scope.Value; + } } else { if (!remoteAddress.Equals(request.ClientIpAddress)) return null; //client ip must match udp src addr - broadcast = false; //unicast request + //unicast request + foreach (KeyValuePair scope in _scopes) + { + if (scope.Value.Enabled && (scope.Value.IsAddressInRange(remoteAddress))) + return scope.Value; + } } } else { //relay agent unicast - - if (!remoteAddress.Equals(request.RelayAgentIpAddress)) - return null; //relay ip must match udp src addr - - broadcast = false; //unicast request - } - - if (broadcast) - { foreach (KeyValuePair scope in _scopes) { - if (scope.Value.Enabled && (scope.Value.InterfaceIndex == ipPacketInformation.Interface)) - return scope.Value; - } - } - else - { - foreach (KeyValuePair scope in _scopes) - { - if (scope.Value.Enabled && (scope.Value.IsAddressInRange(remoteAddress))) + if (scope.Value.Enabled && (scope.Value.IsAddressInRange(request.RelayAgentIpAddress))) return scope.Value; } }