Skip to content

Commit

Permalink
dnsforward: imp err msg, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Jul 28, 2022
1 parent fd9ee82 commit ea2272d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
20 changes: 17 additions & 3 deletions internal/dnsforward/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func newUpstreamConfig(upstreams []string) (conf *proxy.UpstreamConfig, err erro

_, err = validateUpstream(ups, domains)
if err != nil {
return nil, fmt.Errorf("validating the upstream %s: %w", u, err)
return nil, fmt.Errorf("validating upstream %s: %w", u, err)
}
}

Expand Down Expand Up @@ -526,13 +526,19 @@ type excFunc func(u upstream.Upstream) (err error)

// checkDNSUpstreamExc checks if the DNS upstream exchanges correctly.
func checkDNSUpstreamExc(u upstream.Upstream) (err error) {
// testTLD is the special-use fully-qualified domain name for testing the
// DNS server reachability.
//
// See https://datatracker.ietf.org/doc/html/rfc6761#section-6.2.
const testTLD = "test."

req := &dns.Msg{
MsgHdr: dns.MsgHdr{
Id: dns.Id(),
RecursionDesired: true,
},
Question: []dns.Question{{
Name: "test.",
Name: testTLD,
Qtype: dns.TypeA,
Qclass: dns.ClassINET,
}},
Expand All @@ -551,14 +557,22 @@ func checkDNSUpstreamExc(u upstream.Upstream) (err error) {

// checkPrivateUpstreamExc checks if the upstream for resolving private
// addresses exchanges correctly.
//
// TODO(e.burkov): Think on testing the ip6.arpa. as well.
func checkPrivateUpstreamExc(u upstream.Upstream) (err error) {
// inAddrArpaTLD is the special-use fully-qualified domain name for PTR IP
// address resolution.
//
// See https://datatracker.ietf.org/doc/html/rfc1035#section-3.5.
const inAddrArpaTLD = "in-addr.arpa."

req := &dns.Msg{
MsgHdr: dns.MsgHdr{
Id: dns.Id(),
RecursionDesired: true,
},
Question: []dns.Question{{
Name: "in-addr.arpa.",
Name: inAddrArpaTLD,
Qtype: dns.TypePTR,
Qclass: dns.ClassINET,
}},
Expand Down
10 changes: 5 additions & 5 deletions internal/dnsforward/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func TestDNSForwardHTTP_handleSetConfig(t *testing.T) {
}, {
name: "upstream_dns_bad",
wantSet: `validating upstream servers: ` +
`validating the upstream !!!: bad ipport address "!!!": ` +
`validating upstream !!!: bad ipport address "!!!": ` +
`address !!!: missing port in address`,
}, {
name: "bootstraps_bad",
Expand Down Expand Up @@ -293,23 +293,23 @@ func TestValidateUpstreams(t *testing.T) {
},
}, {
name: "invalid",
wantErr: `validating the upstream dhcp://fake.dns: wrong protocol`,
wantErr: `validating upstream dhcp://fake.dns: wrong protocol`,
set: []string{"dhcp://fake.dns"},
}, {
name: "invalid",
wantErr: `validating the upstream 1.2.3.4.5: bad ipport address "1.2.3.4.5": address 1.2.3.4.5: missing port in address`,
wantErr: `validating upstream 1.2.3.4.5: bad ipport address "1.2.3.4.5": address 1.2.3.4.5: missing port in address`,
set: []string{"1.2.3.4.5"},
}, {
name: "invalid",
wantErr: `validating the upstream 123.3.7m: bad ipport address "123.3.7m": address 123.3.7m: missing port in address`,
wantErr: `validating upstream 123.3.7m: bad ipport address "123.3.7m": address 123.3.7m: missing port in address`,
set: []string{"123.3.7m"},
}, {
name: "invalid",
wantErr: `bad upstream for domain "[/host.com]tls://dns.adguard.com": missing separator`,
set: []string{"[/host.com]tls://dns.adguard.com"},
}, {
name: "invalid",
wantErr: `validating the upstream [host.ru]#: bad ipport address "[host.ru]#": address [host.ru]#: missing port in address`,
wantErr: `validating upstream [host.ru]#: bad ipport address "[host.ru]#": address [host.ru]#: missing port in address`,
set: []string{"[host.ru]#"},
}, {
name: "valid_default",
Expand Down

0 comments on commit ea2272d

Please sign in to comment.