Skip to content

Commit

Permalink
Improved Error and EDNS handling (#62), ContinueOnEmptyResponse (#64)
Browse files Browse the repository at this point in the history
* changed how opt records are created and used. Added configuration to disable EDNS and to set the requested buffer size and DnsSec
* Changes the behavior in case of bad responses which were truncated by some middleman proxy or router - fixes #52
* Changing default unknown record handling to preserve the original data so that users can work with those records.
* Reworking error handling see #60
* Adding new setting ContinueOnEmptyResponse #64
  • Loading branch information
MichaCo authored Mar 14, 2020
1 parent 708e15a commit 93c5629
Show file tree
Hide file tree
Showing 55 changed files with 4,732 additions and 2,263 deletions.
2 changes: 1 addition & 1 deletion Documentation/build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cd %~dp0
call GetMsdn.cmd

SETLOCAL
SET DOCFX_VERSION=2.16.7
SET DOCFX_VERSION=2.50
SET CACHED_ZIP=%LocalAppData%\DocFx\docfx.%DOCFX_VERSION%.zip

IF EXIST %CACHED_ZIP% goto extract
Expand Down
8 changes: 2 additions & 6 deletions Documentation/docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
"files": "**/*.csproj"
}
],
"dest": "obj/api",
"properties": {
"TargetFramework": "netstandard1.3"
}
"dest": "obj/api"
}
],
"build": {
Expand Down Expand Up @@ -56,13 +53,12 @@
]
}
],

"globalMetadata": {
"_gitContribute": {
"branch": "dev",
"apiSpecFolder": "Documentation/apispec"
}
},
},
"postProcessors": [ "ExtractSearchIndex" ],
"xref": "msdn.4.5.2/content/msdn.4.5.2.zip",
"dest": "..\\..\\dnsclient.michaco.net\\website\\Docs",
Expand Down
32 changes: 13 additions & 19 deletions Documentation/template/ManagedReference.html.primary.tmpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
{{#item}}
<head>
<title>{{#title}}{{title}}{{/title}}{{^title}}{{>partials/title}}{{/title}} {{#_appTitle}}| {{_appTitle}} {{/_appTitle}}</title>
</head>

<div id="wrapper">
<header>
{{^_disableBreadcrumb}}
Expand All @@ -21,30 +16,29 @@
{{/_disableToc}}
{{#_disableToc}}
<div class="article row grid">
{{/_disableToc}}
{{/_disableToc}}
{{#_disableAffix}}
<div class="col-md-12">
{{/_disableAffix}}
{{^_disableAffix}}
<div class="col-md-10">
{{/_disableAffix}}
<article class="content wrap" id="_content">
{{#isNamespace}}
{{>partials/namespace}}
{{/isNamespace}}
{{#isClass}}
{{>partials/class}}
{{/isClass}}
{{#isEnum}}
{{>partials/enum}}
{{/isEnum}}
{{>partials/customMREFContent}}
<article class="content wrap" id="_content" data-uid="{{uid}}">
{{#isNamespace}}
{{>partials/namespace}}
{{/isNamespace}}
{{#isClass}}
{{>partials/class}}
{{/isClass}}
{{#isEnum}}
{{>partials/enum}}
{{/isEnum}}
{{>partials/customMREFContent}}
</article>
</div>
{{^_disableAffix}}
{{>partials/affix}}
{{/_disableAffix}}
</div>
</div>
</div>
{{/item}}
</div>
53 changes: 19 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# DnsClient.NET

[![Build Status](https://dev.azure.com/michaco/DnsClient/_apis/build/status/MichaCo.DnsClient.NET?branchName=dev)](https://dev.azure.com/michaco/DnsClient/_build/latest?definitionId=1&branchName=dev)
[![NuGet](https://img.shields.io/nuget/v/DnsClient.svg?style=flat&label=Stable)](https://www.nuget.org/packages/DnsClient)
[![MyGet](https://img.shields.io/myget/dnsclient/vpre/DnsClient.svg?style=flat&label=Pre-release)](https://www.myget.org/feed/dnsclient/package/nuget/DnsClient)

Expand All @@ -9,56 +10,47 @@ DnsClient.NET is a simple yet very powerful and high performant open source libr

See http://dnsclient.michaco.net for more details and documentation.

The following example instantiates a new `LookupClient` without specifying a DNS endpoint.
DnsClient.NET will query your system network adapters to determine available DNS servers.
The following example instantiates a new `LookupClient` to query some IP address.

``` csharp

var lookup = new LookupClient();
var result = await lookup.QueryAsync("google.com", QueryType.ANY);
var result = await lookup.QueryAsync("google.com", QueryType.A);

var record = result.Answers.ARecords().FirstOrDefault();
var address = record?.Address;
var ip = record?.Address;
```

## Builds

[![Build Status](https://dev.azure.com/michaco/DnsClient/_apis/build/status/MichaCo.DnsClient.NET?branchName=dev)](https://dev.azure.com/michaco/DnsClient/_build/latest?definitionId=1&branchName=dev)

Get it via NuGet https://www.nuget.org/packages/DnsClient/

Get beta builds from [MyGet](https://www.myget.org/feed/dnsclient/package/nuget/DnsClient).

## Features

### General

* Full Async API
* UDP and TCP lookup, configurable if TCP should be used as fallback in case UDP result is truncated (default=true).
* Sync & Async API
* UDP and TCP lookup, configurable if TCP should be used as fallback in case the UDP result is truncated (default=true).
* Configurable EDNS support to change the default UDP buffer size and request security relevant records
* Caching
* Query result cache based on provided TTL
* Minimum TTL setting to overrule the result's TTL and always cache the responses for at least that time. (Even very low value, like a few milliseconds, do make a huge difference if used in high traffic low latency scenarios)
* Cache can be disabled altogether
* Supports multiple DNS endpoints to be configured
* Configurable retry over configured DNS servers if one or more returned a server error
* Configurable retry logic in case of timeouts and other exceptions
* Maximum TTL to limit cache duration
* Cache can be disabled
* Multiple DNS endpoints can be configured. DnsClient will use them in random or sequential order (configurable), with re-tries.
* Configurable retry of queries
* Optional audit trail of each response and exception
* Configurable error handling. Throwing DNS errors, like `NotExistentDomain` is turned off by default
* Optional Trace/Logging

### Supported resource records

* A, AAAA, NS, CNAME, SOA, MB, MG, MR, WKS, HINFO, MINFO, MX, RP, TXT, AFSDB, URI, CAA, NULL, SSHFP
* PTR for reverse lookups
* SRV For service discovery. `LookupClient` has some extensions to help with that.
* OPT (currently only for reading the supported UDP buffer size, EDNS version)
* SRV for service discovery. `LookupClient` has some extensions to help with that.
* AXFR zone transfer (as per spec, LookupClient has to be set to TCP mode only for this type. Also, the result depends on if the DNS server trusts your current connection)

## Build from Source

The solution requires a .NET Core 2.x SDK and the [.NET 4.7.1 Dev Pack](https://www.microsoft.com/net/download/dotnet-framework/net471) being installed.
The solution requires a .NET Core 3.x SDK and the [.NET 4.7.1 Dev Pack](https://www.microsoft.com/net/download/dotnet-framework/net471) being installed.

Just clone the repository and open the solution in Visual Studio 2017.
Or use the dotnet client via command line.
Just clone the repository and open the solution in Visual Studio 2017/2019.

The unit tests don't require any additional setup right now.

Expand All @@ -70,18 +62,11 @@ Now, you can use **samples/MiniDig** to query the local DNS server.
The following should return many different resource records:

``` cmd
dotnet run -s localhost micha.mcnet.com any
```

To test some random domain names, run MiniDig with the `random` sub command (works without setting up Bind, too).

``` cmd
dotnet run random -s localhost
dotnet run -s localhost mcnet.com any
```

## Examples

* The [Samples](https://github.com/MichaCo/DnsClient.NET.Samples) repository will have some solutions to showcase the usage and also to test some functionality.

* [MiniDig](https://github.com/MichaCo/DnsClient.NET/tree/dev/samples/MiniDig) (See the readme over there)

* More docuemntation and a simple query window on http://dnsclient.michaco.net
* The [Samples](https://github.com/MichaCo/DnsClient.NET.Samples) repository (there might be more in the future).
* [MiniDig](https://github.com/MichaCo/DnsClient.NET/tree/dev/samples/MiniDig)
6 changes: 6 additions & 0 deletions azure-pipelines-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ trigger:
- dev
- master

pr:
autoCancel: false
branches:
include:
- '*'

# pool:
# vmImage: 'windows-latest'

Expand Down
44 changes: 23 additions & 21 deletions samples/MiniDig/DnsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,6 @@

namespace DigApp
{
public class LookupSettings
{
public IPEndPoint[] Endpoints { get; set; }

public TimeSpan MinTTL { get; set; }

public bool NoTcp { get; set; }

public bool Recursion { get; set; }

public int Retries { get; set; }

public bool TcpOnly { get; set; }

public TimeSpan Timeout { get; set; }

public bool UseCache { get; set; }
}

public abstract class DnsCommand
{
public CommandOption ConnectTimeoutArg { get; set; }
Expand All @@ -36,6 +17,10 @@ public abstract class DnsCommand

public CommandOption MaximumTTLArg { get; set; }

public CommandOption MaximumBufferSizeArg { get; set; }

public CommandOption RequestDnsSecRecordsArg { get; set; }

public CommandOption NoRecurseArg { get; set; }

public string[] OriginalArgs { get; }
Expand Down Expand Up @@ -112,7 +97,9 @@ public LookupClientOptions GetLookupSettings()
UseCache = GetUseCache(),
UseTcpOnly = GetUseTcp(),
UseTcpFallback = !GetNoTcp(),
MaximumCacheTimeout = GetMaximumTTL()
MaximumCacheTimeout = GetMaximumTTL(),
ExtendedDnsBufferSize = GetMaximumBufferSize(),
RequestDnsSecRecords = GetRequestDnsSec()
};
}

Expand All @@ -136,6 +123,11 @@ public LookupClientOptions GetLookupSettings()
return null;
}

public int GetMaximumBufferSize()
=> MaximumBufferSizeArg.HasValue() ? int.Parse(MaximumBufferSizeArg.Value()) : DnsQueryOptions.MaximumBufferSize;

public bool GetRequestDnsSec() => RequestDnsSecRecordsArg.HasValue();

public int GetTimeoutValue() => ConnectTimeoutArg.HasValue() ? int.Parse(ConnectTimeoutArg.Value()) : 1000;

public int GetTriesValue() => TriesArg.HasValue() ? int.Parse(TriesArg.Value()) : 5;
Expand Down Expand Up @@ -193,7 +185,17 @@ protected virtual void Configure()
"Maximum cache ttl.",
CommandOptionType.SingleValue);

App.HelpOption("-? | -h | --help");
MaximumBufferSizeArg = App.Option(
"--bufsize",
"Maximum EDNS buffer size.",
CommandOptionType.SingleValue);

RequestDnsSecRecordsArg = App.Option(
"--dnssec",
"Request DNS SEC records (do flag).",
CommandOptionType.NoValue);

App.HelpOption("-? | -h | --help | --helpme");
}

protected abstract Task<int> Execute();
Expand Down
2 changes: 1 addition & 1 deletion samples/MiniDig/MiniDig.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net471;netcoreapp3.1;</TargetFrameworks>
<TargetFrameworks>net45;net471;netcoreapp3.1;</TargetFrameworks>
<AssemblyName>MiniDig</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>MiniDig</PackageId>
Expand Down
2 changes: 1 addition & 1 deletion samples/MiniDig/PerfCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected override void Configure()
{
QueryArg = App.Argument("query", "the domain query to run.", false);
ClientsArg = App.Option("-c | --clients", "Number of clients to run", CommandOptionType.SingleValue);
RuntimeArg = App.Option("-r | --runtime", "Time in seconds to run", CommandOptionType.SingleValue);
RuntimeArg = App.Option("-r | --run", "Time in seconds to run", CommandOptionType.SingleValue);
SyncArg = App.Option("--sync", "Run synchronous api", CommandOptionType.NoValue);
base.Configure();
}
Expand Down
2 changes: 1 addition & 1 deletion samples/MiniDig/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Program
{
public static async Task Main(string[] args)
{
DnsClient.Tracing.Source.Switch.Level = SourceLevels.Warning;
DnsClient.Tracing.Source.Switch.Level = SourceLevels.Verbose;
DnsClient.Tracing.Source.Listeners.Add(new ConsoleTraceListener());

var app = new CommandLineApplication(throwOnUnexpectedArg: true);
Expand Down
Loading

0 comments on commit 93c5629

Please sign in to comment.