Skip to content

Commit 93c5629

Browse files
authored
Improved Error and EDNS handling (#62), ContinueOnEmptyResponse (#64)
* 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
1 parent 708e15a commit 93c5629

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4732
-2263
lines changed

Documentation/build.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cd %~dp0
44
call GetMsdn.cmd
55

66
SETLOCAL
7-
SET DOCFX_VERSION=2.16.7
7+
SET DOCFX_VERSION=2.50
88
SET CACHED_ZIP=%LocalAppData%\DocFx\docfx.%DOCFX_VERSION%.zip
99

1010
IF EXIST %CACHED_ZIP% goto extract

Documentation/docfx.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
"files": "**/*.csproj"
88
}
99
],
10-
"dest": "obj/api",
11-
"properties": {
12-
"TargetFramework": "netstandard1.3"
13-
}
10+
"dest": "obj/api"
1411
}
1512
],
1613
"build": {
@@ -56,13 +53,12 @@
5653
]
5754
}
5855
],
59-
6056
"globalMetadata": {
6157
"_gitContribute": {
6258
"branch": "dev",
6359
"apiSpecFolder": "Documentation/apispec"
6460
}
65-
},
61+
},
6662
"postProcessors": [ "ExtractSearchIndex" ],
6763
"xref": "msdn.4.5.2/content/msdn.4.5.2.zip",
6864
"dest": "..\\..\\dnsclient.michaco.net\\website\\Docs",
Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
{{#item}}
2-
<head>
3-
<title>{{#title}}{{title}}{{/title}}{{^title}}{{>partials/title}}{{/title}} {{#_appTitle}}| {{_appTitle}} {{/_appTitle}}</title>
4-
</head>
5-
61
<div id="wrapper">
72
<header>
83
{{^_disableBreadcrumb}}
@@ -21,30 +16,29 @@
2116
{{/_disableToc}}
2217
{{#_disableToc}}
2318
<div class="article row grid">
24-
{{/_disableToc}}
19+
{{/_disableToc}}
2520
{{#_disableAffix}}
2621
<div class="col-md-12">
2722
{{/_disableAffix}}
2823
{{^_disableAffix}}
2924
<div class="col-md-10">
3025
{{/_disableAffix}}
31-
<article class="content wrap" id="_content">
32-
{{#isNamespace}}
33-
{{>partials/namespace}}
34-
{{/isNamespace}}
35-
{{#isClass}}
36-
{{>partials/class}}
37-
{{/isClass}}
38-
{{#isEnum}}
39-
{{>partials/enum}}
40-
{{/isEnum}}
41-
{{>partials/customMREFContent}}
26+
<article class="content wrap" id="_content" data-uid="{{uid}}">
27+
{{#isNamespace}}
28+
{{>partials/namespace}}
29+
{{/isNamespace}}
30+
{{#isClass}}
31+
{{>partials/class}}
32+
{{/isClass}}
33+
{{#isEnum}}
34+
{{>partials/enum}}
35+
{{/isEnum}}
36+
{{>partials/customMREFContent}}
4237
</article>
4338
</div>
4439
{{^_disableAffix}}
4540
{{>partials/affix}}
4641
{{/_disableAffix}}
4742
</div>
4843
</div>
49-
</div>
50-
{{/item}}
44+
</div>

README.md

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# DnsClient.NET
22

3+
[![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)
34
[![NuGet](https://img.shields.io/nuget/v/DnsClient.svg?style=flat&label=Stable)](https://www.nuget.org/packages/DnsClient)
45
[![MyGet](https://img.shields.io/myget/dnsclient/vpre/DnsClient.svg?style=flat&label=Pre-release)](https://www.myget.org/feed/dnsclient/package/nuget/DnsClient)
56

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

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

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

1515
``` csharp
1616

1717
var lookup = new LookupClient();
18-
var result = await lookup.QueryAsync("google.com", QueryType.ANY);
18+
var result = await lookup.QueryAsync("google.com", QueryType.A);
1919

2020
var record = result.Answers.ARecords().FirstOrDefault();
21-
var address = record?.Address;
21+
var ip = record?.Address;
2222
```
2323

24-
## Builds
25-
26-
[![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)
27-
28-
Get it via NuGet https://www.nuget.org/packages/DnsClient/
29-
30-
Get beta builds from [MyGet](https://www.myget.org/feed/dnsclient/package/nuget/DnsClient).
31-
3224
## Features
3325

3426
### General
3527

36-
* Full Async API
37-
* UDP and TCP lookup, configurable if TCP should be used as fallback in case UDP result is truncated (default=true).
28+
* Sync & Async API
29+
* UDP and TCP lookup, configurable if TCP should be used as fallback in case the UDP result is truncated (default=true).
30+
* Configurable EDNS support to change the default UDP buffer size and request security relevant records
3831
* Caching
3932
* Query result cache based on provided TTL
4033
* 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)
41-
* Cache can be disabled altogether
42-
* Supports multiple DNS endpoints to be configured
43-
* Configurable retry over configured DNS servers if one or more returned a server error
44-
* Configurable retry logic in case of timeouts and other exceptions
34+
* Maximum TTL to limit cache duration
35+
* Cache can be disabled
36+
* Multiple DNS endpoints can be configured. DnsClient will use them in random or sequential order (configurable), with re-tries.
37+
* Configurable retry of queries
4538
* Optional audit trail of each response and exception
4639
* Configurable error handling. Throwing DNS errors, like `NotExistentDomain` is turned off by default
40+
* Optional Trace/Logging
4741

4842
### Supported resource records
4943

5044
* A, AAAA, NS, CNAME, SOA, MB, MG, MR, WKS, HINFO, MINFO, MX, RP, TXT, AFSDB, URI, CAA, NULL, SSHFP
5145
* PTR for reverse lookups
52-
* SRV For service discovery. `LookupClient` has some extensions to help with that.
53-
* OPT (currently only for reading the supported UDP buffer size, EDNS version)
46+
* SRV for service discovery. `LookupClient` has some extensions to help with that.
5447
* 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)
5548

5649
## Build from Source
5750

58-
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.
51+
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.
5952

60-
Just clone the repository and open the solution in Visual Studio 2017.
61-
Or use the dotnet client via command line.
53+
Just clone the repository and open the solution in Visual Studio 2017/2019.
6254

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

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

7264
``` cmd
73-
dotnet run -s localhost micha.mcnet.com any
74-
```
75-
76-
To test some random domain names, run MiniDig with the `random` sub command (works without setting up Bind, too).
77-
78-
``` cmd
79-
dotnet run random -s localhost
65+
dotnet run -s localhost mcnet.com any
8066
```
8167

8268
## Examples
8369

84-
* The [Samples](https://github.com/MichaCo/DnsClient.NET.Samples) repository will have some solutions to showcase the usage and also to test some functionality.
85-
86-
* [MiniDig](https://github.com/MichaCo/DnsClient.NET/tree/dev/samples/MiniDig) (See the readme over there)
87-
70+
* More docuemntation and a simple query window on http://dnsclient.michaco.net
71+
* The [Samples](https://github.com/MichaCo/DnsClient.NET.Samples) repository (there might be more in the future).
72+
* [MiniDig](https://github.com/MichaCo/DnsClient.NET/tree/dev/samples/MiniDig)

azure-pipelines-ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ trigger:
44
- dev
55
- master
66

7+
pr:
8+
autoCancel: false
9+
branches:
10+
include:
11+
- '*'
12+
713
# pool:
814
# vmImage: 'windows-latest'
915

samples/MiniDig/DnsCommand.cs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,6 @@
99

1010
namespace DigApp
1111
{
12-
public class LookupSettings
13-
{
14-
public IPEndPoint[] Endpoints { get; set; }
15-
16-
public TimeSpan MinTTL { get; set; }
17-
18-
public bool NoTcp { get; set; }
19-
20-
public bool Recursion { get; set; }
21-
22-
public int Retries { get; set; }
23-
24-
public bool TcpOnly { get; set; }
25-
26-
public TimeSpan Timeout { get; set; }
27-
28-
public bool UseCache { get; set; }
29-
}
30-
3112
public abstract class DnsCommand
3213
{
3314
public CommandOption ConnectTimeoutArg { get; set; }
@@ -36,6 +17,10 @@ public abstract class DnsCommand
3617

3718
public CommandOption MaximumTTLArg { get; set; }
3819

20+
public CommandOption MaximumBufferSizeArg { get; set; }
21+
22+
public CommandOption RequestDnsSecRecordsArg { get; set; }
23+
3924
public CommandOption NoRecurseArg { get; set; }
4025

4126
public string[] OriginalArgs { get; }
@@ -112,7 +97,9 @@ public LookupClientOptions GetLookupSettings()
11297
UseCache = GetUseCache(),
11398
UseTcpOnly = GetUseTcp(),
11499
UseTcpFallback = !GetNoTcp(),
115-
MaximumCacheTimeout = GetMaximumTTL()
100+
MaximumCacheTimeout = GetMaximumTTL(),
101+
ExtendedDnsBufferSize = GetMaximumBufferSize(),
102+
RequestDnsSecRecords = GetRequestDnsSec()
116103
};
117104
}
118105

@@ -136,6 +123,11 @@ public LookupClientOptions GetLookupSettings()
136123
return null;
137124
}
138125

126+
public int GetMaximumBufferSize()
127+
=> MaximumBufferSizeArg.HasValue() ? int.Parse(MaximumBufferSizeArg.Value()) : DnsQueryOptions.MaximumBufferSize;
128+
129+
public bool GetRequestDnsSec() => RequestDnsSecRecordsArg.HasValue();
130+
139131
public int GetTimeoutValue() => ConnectTimeoutArg.HasValue() ? int.Parse(ConnectTimeoutArg.Value()) : 1000;
140132

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

196-
App.HelpOption("-? | -h | --help");
188+
MaximumBufferSizeArg = App.Option(
189+
"--bufsize",
190+
"Maximum EDNS buffer size.",
191+
CommandOptionType.SingleValue);
192+
193+
RequestDnsSecRecordsArg = App.Option(
194+
"--dnssec",
195+
"Request DNS SEC records (do flag).",
196+
CommandOptionType.NoValue);
197+
198+
App.HelpOption("-? | -h | --help | --helpme");
197199
}
198200

199201
protected abstract Task<int> Execute();

samples/MiniDig/MiniDig.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net471;netcoreapp3.1;</TargetFrameworks>
4+
<TargetFrameworks>net45;net471;netcoreapp3.1;</TargetFrameworks>
55
<AssemblyName>MiniDig</AssemblyName>
66
<OutputType>Exe</OutputType>
77
<PackageId>MiniDig</PackageId>

samples/MiniDig/PerfCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected override void Configure()
4040
{
4141
QueryArg = App.Argument("query", "the domain query to run.", false);
4242
ClientsArg = App.Option("-c | --clients", "Number of clients to run", CommandOptionType.SingleValue);
43-
RuntimeArg = App.Option("-r | --runtime", "Time in seconds to run", CommandOptionType.SingleValue);
43+
RuntimeArg = App.Option("-r | --run", "Time in seconds to run", CommandOptionType.SingleValue);
4444
SyncArg = App.Option("--sync", "Run synchronous api", CommandOptionType.NoValue);
4545
base.Configure();
4646
}

samples/MiniDig/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class Program
99
{
1010
public static async Task Main(string[] args)
1111
{
12-
DnsClient.Tracing.Source.Switch.Level = SourceLevels.Warning;
12+
DnsClient.Tracing.Source.Switch.Level = SourceLevels.Verbose;
1313
DnsClient.Tracing.Source.Listeners.Add(new ConsoleTraceListener());
1414

1515
var app = new CommandLineApplication(throwOnUnexpectedArg: true);

0 commit comments

Comments
 (0)