mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2026-01-06 16:53:59 +00:00
SplitHorizonApp: updated app to v1.3 to support custom networks specified by their CIDR network address.
This commit is contained in:
@@ -57,15 +57,33 @@ namespace SplitHorizon
|
||||
case DnsResourceRecordType.A:
|
||||
case DnsResourceRecordType.AAAA:
|
||||
dynamic jsonAppRecordData = JsonConvert.DeserializeObject(appRecordData);
|
||||
dynamic jsonAddresses;
|
||||
dynamic jsonAddresses = null;
|
||||
|
||||
if (NetUtilities.IsPrivateIP(remoteEP.Address))
|
||||
jsonAddresses = jsonAppRecordData.@private;
|
||||
else
|
||||
jsonAddresses = jsonAppRecordData.@public;
|
||||
foreach (dynamic jsonProperty in jsonAppRecordData)
|
||||
{
|
||||
string name = jsonProperty.Name;
|
||||
|
||||
if (jsonAddresses == null)
|
||||
return Task.FromResult<DnsDatagram>(null);
|
||||
if ((name == "public") || (name == "private"))
|
||||
continue;
|
||||
|
||||
NetworkAddress networkAddress = NetworkAddress.Parse(name);
|
||||
if (networkAddress.Contains(remoteEP.Address))
|
||||
{
|
||||
jsonAddresses = jsonProperty.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (jsonAddresses is null)
|
||||
{
|
||||
if (NetUtilities.IsPrivateIP(remoteEP.Address))
|
||||
jsonAddresses = jsonAppRecordData.@private;
|
||||
else
|
||||
jsonAddresses = jsonAppRecordData.@public;
|
||||
|
||||
if (jsonAddresses is null)
|
||||
return Task.FromResult<DnsDatagram>(null);
|
||||
}
|
||||
|
||||
List<DnsResourceRecord> answers = new List<DnsResourceRecord>();
|
||||
|
||||
@@ -110,7 +128,7 @@ namespace SplitHorizon
|
||||
#region properties
|
||||
|
||||
public string Description
|
||||
{ get { return "Returns A or AAAA records with different set of IP addresses for clients querying over public and private networks."; } }
|
||||
{ get { return "Returns A or AAAA records with different set of IP addresses for clients querying over public, private, or other specified networks."; } }
|
||||
|
||||
public string ApplicationRecordDataTemplate
|
||||
{
|
||||
@@ -124,6 +142,9 @@ namespace SplitHorizon
|
||||
""private"": [
|
||||
""192.168.1.1"",
|
||||
""::1""
|
||||
],
|
||||
""10.0.0.0/8"": [
|
||||
""10.1.1.1""
|
||||
]
|
||||
}";
|
||||
}
|
||||
|
||||
@@ -51,26 +51,45 @@ namespace SplitHorizon
|
||||
public Task<DnsDatagram> ProcessRequestAsync(DnsDatagram request, IPEndPoint remoteEP, string zoneName, uint appRecordTtl, string appRecordData, bool isRecursionAllowed, IDnsServer dnsServer)
|
||||
{
|
||||
dynamic jsonAppRecordData = JsonConvert.DeserializeObject(appRecordData);
|
||||
dynamic jsonCname;
|
||||
dynamic jsonCname = null;
|
||||
|
||||
if (NetUtilities.IsPrivateIP(remoteEP.Address))
|
||||
jsonCname = jsonAppRecordData.@private;
|
||||
else
|
||||
jsonCname = jsonAppRecordData.@public;
|
||||
foreach (dynamic jsonProperty in jsonAppRecordData)
|
||||
{
|
||||
string name = jsonProperty.Name;
|
||||
|
||||
if (jsonCname == null)
|
||||
return Task.FromResult<DnsDatagram>(null);
|
||||
if ((name == "public") || (name == "private"))
|
||||
continue;
|
||||
|
||||
NetworkAddress networkAddress = NetworkAddress.Parse(name);
|
||||
if (networkAddress.Contains(remoteEP.Address))
|
||||
{
|
||||
jsonCname = jsonProperty.Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (jsonCname is null)
|
||||
{
|
||||
if (NetUtilities.IsPrivateIP(remoteEP.Address))
|
||||
jsonCname = jsonAppRecordData.@private;
|
||||
else
|
||||
jsonCname = jsonAppRecordData.@public;
|
||||
|
||||
if (jsonCname is null)
|
||||
return Task.FromResult<DnsDatagram>(null);
|
||||
}
|
||||
|
||||
string cname = jsonCname.Value;
|
||||
if (string.IsNullOrEmpty(cname))
|
||||
return Task.FromResult<DnsDatagram>(null);
|
||||
|
||||
DnsQuestionRecord question = request.Question[0];
|
||||
IReadOnlyList<DnsResourceRecord> answers;
|
||||
|
||||
if (request.Question[0].Name.Equals(zoneName, StringComparison.OrdinalIgnoreCase)) //check for zone apex
|
||||
answers = new DnsResourceRecord[] { new DnsResourceRecord(request.Question[0].Name, DnsResourceRecordType.ANAME, DnsClass.IN, appRecordTtl, new DnsANAMERecord(cname)) }; //use ANAME
|
||||
if (question.Name.Equals(zoneName, StringComparison.OrdinalIgnoreCase)) //check for zone apex
|
||||
answers = new DnsResourceRecord[] { new DnsResourceRecord(question.Name, DnsResourceRecordType.ANAME, DnsClass.IN, appRecordTtl, new DnsANAMERecord(cname)) }; //use ANAME
|
||||
else
|
||||
answers = new DnsResourceRecord[] { new DnsResourceRecord(request.Question[0].Name, DnsResourceRecordType.CNAME, DnsClass.IN, appRecordTtl, new DnsCNAMERecord(cname)) };
|
||||
answers = new DnsResourceRecord[] { new DnsResourceRecord(question.Name, DnsResourceRecordType.CNAME, DnsClass.IN, appRecordTtl, new DnsCNAMERecord(cname)) };
|
||||
|
||||
return Task.FromResult(new DnsDatagram(request.Identifier, true, request.OPCODE, true, false, request.RecursionDesired, isRecursionAllowed, false, false, DnsResponseCode.NoError, request.Question, answers));
|
||||
}
|
||||
@@ -80,7 +99,7 @@ namespace SplitHorizon
|
||||
#region properties
|
||||
|
||||
public string Description
|
||||
{ get { return "Returns different CNAME record for clients querying over public and private networks. Note that the app will return ANAME record for an APP record at zone apex."; } }
|
||||
{ get { return "Returns different CNAME record for clients querying over public, private, or other specified networks. Note that the app will return ANAME record for an APP record at zone apex."; } }
|
||||
|
||||
public string ApplicationRecordDataTemplate
|
||||
{
|
||||
@@ -88,7 +107,8 @@ namespace SplitHorizon
|
||||
{
|
||||
return @"{
|
||||
""public"": ""api.example.com"",
|
||||
""private"": ""api.example.corp""
|
||||
""private"": ""api.example.corp"",
|
||||
""10.0.0.0/8"": ""api.intranet.example.corp""
|
||||
}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<Version>1.2</Version>
|
||||
<Version>1.3</Version>
|
||||
<Company>Technitium</Company>
|
||||
<Product>Technitium DNS Server</Product>
|
||||
<Authors>Shreyas Zare</Authors>
|
||||
|
||||
Reference in New Issue
Block a user