From 280dd995e8292a752631bbf6a82def7902ecefd3 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 12 Jan 2025 17:49:48 +0530 Subject: [PATCH] DnsServer: Updated WriteClientSubnetRateLimitLog() to check for QPM bypass list before logging rate limit event entries. --- DnsServerCore/Dns/DnsServer.cs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/DnsServerCore/Dns/DnsServer.cs b/DnsServerCore/Dns/DnsServer.cs index ac38b097..242843e7 100644 --- a/DnsServerCore/Dns/DnsServer.cs +++ b/DnsServerCore/Dns/DnsServer.cs @@ -4312,23 +4312,31 @@ namespace DnsServerCore.Dns } } - internal bool IsQpmLimitCrossed(IPAddress remoteIP) + private bool IsQpmLimitBypassed(IPAddress remoteIP) { - if ((_qpmLimitRequests < 1) && (_qpmLimitErrors < 1)) - return false; - if (IPAddress.IsLoopback(remoteIP)) - return false; + return true; if (_qpmLimitBypassList is not null) { foreach (NetworkAddress networkAddress in _qpmLimitBypassList) { if (networkAddress.Contains(remoteIP)) - return false; + return true; } } + return false; + } + + internal bool IsQpmLimitCrossed(IPAddress remoteIP) + { + if ((_qpmLimitRequests < 1) && (_qpmLimitErrors < 1)) + return false; + + if (IsQpmLimitBypassed(remoteIP)) + return false; + IPAddress remoteSubnet; switch (remoteIP.AddressFamily) @@ -4400,6 +4408,9 @@ namespace DnsServerCore.Dns if (oldAverageCountPerMinute >= qpmLimit) { //previously over limit + if (IsQpmLimitBypassed(sampleEntry.Key)) + continue; //network bypassed + long averageCountPerMinute = 0; if (newQpmLimitClientSubnetStats.TryGetValue(sampleEntry.Key, out long newCountPerSample)) @@ -4417,6 +4428,9 @@ namespace DnsServerCore.Dns if (averageCountPerMinute >= qpmLimit) { //currently over limit + if (IsQpmLimitBypassed(sampleEntry.Key)) + continue; //network bypassed + if ((oldQpmLimitClientSubnetStats is not null) && oldQpmLimitClientSubnetStats.TryGetValue(sampleEntry.Key, out long oldCountPerSample)) { long oldAverageCountPerMinute = oldCountPerSample / _qpmLimitSampleMinutes;