mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2025-12-22 09:29:50 +00:00
GeoDistance.Address: Implemented support for ISP/ASN database.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
Technitium DNS Server
|
Technitium DNS Server
|
||||||
Copyright (C) 2023 Shreyas Zare (shreyas@technitium.com)
|
Copyright (C) 2024 Shreyas Zare (shreyas@technitium.com)
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -105,18 +105,22 @@ namespace GeoDistance
|
|||||||
case DnsResourceRecordType.AAAA:
|
case DnsResourceRecordType.AAAA:
|
||||||
Location location = null;
|
Location location = null;
|
||||||
|
|
||||||
bool ecsUsed = false;
|
byte scopePrefixLength = 0;
|
||||||
EDnsClientSubnetOptionData requestECS = request.GetEDnsClientSubnetOption();
|
EDnsClientSubnetOptionData requestECS = request.GetEDnsClientSubnetOption();
|
||||||
if (requestECS is not null)
|
if (requestECS is not null)
|
||||||
{
|
{
|
||||||
if (_maxMind.DatabaseReader.TryCity(requestECS.Address, out CityResponse csResponse) && csResponse.Location.HasCoordinates)
|
if ((_maxMind.IspReader is not null) && _maxMind.IspReader.TryIsp(requestECS.Address, out IspResponse csIsp) && (csIsp.Network is not null))
|
||||||
{
|
scopePrefixLength = (byte)csIsp.Network.PrefixLength;
|
||||||
ecsUsed = true;
|
else if ((_maxMind.AsnReader is not null) && _maxMind.AsnReader.TryAsn(requestECS.Address, out AsnResponse csAsn) && (csAsn.Network is not null))
|
||||||
|
scopePrefixLength = (byte)csAsn.Network.PrefixLength;
|
||||||
|
else
|
||||||
|
scopePrefixLength = requestECS.SourcePrefixLength;
|
||||||
|
|
||||||
|
if (_maxMind.CityReader.TryCity(requestECS.Address, out CityResponse csResponse) && csResponse.Location.HasCoordinates)
|
||||||
location = csResponse.Location;
|
location = csResponse.Location;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ((location is null) && _maxMind.DatabaseReader.TryCity(remoteEP.Address, out CityResponse response) && response.Location.HasCoordinates)
|
if ((location is null) && _maxMind.CityReader.TryCity(remoteEP.Address, out CityResponse response) && response.Location.HasCoordinates)
|
||||||
location = response.Location;
|
location = response.Location;
|
||||||
|
|
||||||
using (JsonDocument jsonDocument = JsonDocument.Parse(appRecordData))
|
using (JsonDocument jsonDocument = JsonDocument.Parse(appRecordData))
|
||||||
@@ -182,19 +186,10 @@ namespace GeoDistance
|
|||||||
if (answers.Count > 1)
|
if (answers.Count > 1)
|
||||||
answers.Shuffle();
|
answers.Shuffle();
|
||||||
|
|
||||||
EDnsOption[] options;
|
EDnsOption[] options = null;
|
||||||
|
|
||||||
if (requestECS is null)
|
if (requestECS is not null)
|
||||||
{
|
options = EDnsClientSubnetOptionData.GetEDnsClientSubnetOption(requestECS.SourcePrefixLength, scopePrefixLength, requestECS.Address);
|
||||||
options = null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ecsUsed)
|
|
||||||
options = EDnsClientSubnetOptionData.GetEDnsClientSubnetOption(requestECS.SourcePrefixLength, requestECS.SourcePrefixLength, requestECS.Address);
|
|
||||||
else
|
|
||||||
options = EDnsClientSubnetOptionData.GetEDnsClientSubnetOption(requestECS.SourcePrefixLength, 0, requestECS.Address);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Task.FromResult(new DnsDatagram(request.Identifier, true, request.OPCODE, true, false, request.RecursionDesired, isRecursionAllowed, false, false, DnsResponseCode.NoError, request.Question, answers, null, null, _dnsServer.UdpPayloadSize, EDnsHeaderFlags.None, options));
|
return Task.FromResult(new DnsDatagram(request.Identifier, true, request.OPCODE, true, false, request.RecursionDesired, isRecursionAllowed, false, false, DnsResponseCode.NoError, request.Question, answers, null, null, _dnsServer.UdpPayloadSize, EDnsHeaderFlags.None, options));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user