diff --git a/Apps/AdvancedBlockingApp/App.cs b/Apps/AdvancedBlockingApp/App.cs index b880a470..6244f3c5 100644 --- a/Apps/AdvancedBlockingApp/App.cs +++ b/Apps/AdvancedBlockingApp/App.cs @@ -51,7 +51,7 @@ namespace AdvancedBlocking bool _enableBlocking; int _blockListUrlUpdateIntervalHours; - Dictionary _localEndPointGroupMap; + Dictionary _localEndPointGroupMap; Dictionary _networkGroupMap; Dictionary _groups; @@ -279,16 +279,42 @@ namespace AdvancedBlocking { if ((request.Metadata is not null) && (request.Metadata.NameServer is not null)) { + Uri requestLocalUriEP = request.Metadata.NameServer.DoHEndPoint; + if (requestLocalUriEP is not null) + { + foreach (KeyValuePair entry in _localEndPointGroupMap) + { + if (entry.Key is DomainEndPoint ep) + { + if (((ep.Port == 0) || (ep.Port == requestLocalUriEP.Port)) && ep.Address.Equals(requestLocalUriEP.Host, StringComparison.OrdinalIgnoreCase)) + return entry.Value; + } + } + } + + DomainEndPoint requestLocalDomainEP = request.Metadata.NameServer.DomainEndPoint; + if (requestLocalDomainEP is not null) + { + foreach (KeyValuePair entry in _localEndPointGroupMap) + { + if (entry.Key is DomainEndPoint ep) + { + if (((ep.Port == 0) || (ep.Port == requestLocalDomainEP.Port)) && ep.Address.Equals(requestLocalDomainEP.Address, StringComparison.OrdinalIgnoreCase)) + return entry.Value; + } + } + } + IPEndPoint requestLocalEP = request.Metadata.NameServer.IPEndPoint; if (requestLocalEP is not null) { - foreach (KeyValuePair entry in _localEndPointGroupMap) + foreach (KeyValuePair entry in _localEndPointGroupMap) { - if ((entry.Key.Port == 0) && entry.Key.Address.Equals(requestLocalEP.Address)) - return entry.Value; - - if (entry.Key.Equals(requestLocalEP)) - return entry.Value; + if (entry.Key is IPEndPoint ep) + { + if (((ep.Port == 0) || (ep.Port == requestLocalEP.Port)) && ep.Address.Equals(requestLocalEP.Address)) + return entry.Value; + } } } } @@ -331,12 +357,12 @@ namespace AdvancedBlocking if (jsonConfig.TryReadObjectAsMap("localEndPointGroupMap", delegate (string localEP, JsonElement jsonGroup) { - if (!IPEndPoint.TryParse(localEP, out IPEndPoint ep)) + if (!EndPointExtensions.TryParse(localEP, out EndPoint ep)) throw new InvalidOperationException("Local end point group map contains an invalid end point: " + localEP); - return new Tuple(ep, jsonGroup.GetString()); + return new Tuple(ep, jsonGroup.GetString()); }, - out Dictionary localEndPointGroupMap)) + out Dictionary localEndPointGroupMap)) { _localEndPointGroupMap = localEndPointGroupMap; } diff --git a/Apps/AdvancedBlockingApp/dnsApp.config b/Apps/AdvancedBlockingApp/dnsApp.config index 9311f4e7..d941aa2a 100644 --- a/Apps/AdvancedBlockingApp/dnsApp.config +++ b/Apps/AdvancedBlockingApp/dnsApp.config @@ -3,7 +3,9 @@ "blockListUrlUpdateIntervalHours": 24, "localEndPointGroupMap": { "127.0.0.1": "bypass", - "192.168.10.2:53": "bypass" + "192.168.10.2:53": "bypass", + "user1.dot.example.com": "kids", + "user2.doh.example.com:443": "bypass" }, "networkGroupMap": { "192.168.10.20": "kids",