Core: convert IP addresses to reverse zone (#838)

* Core: convert IP addresses to reverse zone

If we see IP/mask syntax and the mask mod 8 == 0 we assume a reverse
zone and convert to in-addr or .arpa.

* typos

* integration test

* Addr is not used

* core: clean up normalize

Create a SplitHostPort function that can be used both from normalize.go
and address.go. This removes some (not all!) duplication between the
both and makes it work with reverse address notations.

* More tests
This commit is contained in:
Miek Gieben 2017-08-07 13:24:09 -07:00 committed by GitHub
parent 468d5b57de
commit e1c1521ad5
6 changed files with 145 additions and 47 deletions

View file

@ -69,7 +69,9 @@ func TestNameNormalize(t *testing.T) {
}
func TestHostNormalize(t *testing.T) {
hosts := []string{".:53", ".", "example.org:53", "example.org.", "example.org.:53", "example.org."}
hosts := []string{".:53", ".", "example.org:53", "example.org.", "example.org.:53", "example.org.",
"10.0.0.0/8:53", "10.in-addr.arpa.", "10.0.0.0/9", "10.0.0.0/9.",
"dns://example.org", "example.org."}
for i := 0; i < len(hosts); i += 2 {
ts := hosts[i]
@ -80,17 +82,3 @@ func TestHostNormalize(t *testing.T) {
}
}
}
func TestAddrNormalize(t *testing.T) {
addrs := []string{".:53", ".:53", "example.org", "example.org:53", "example.org.:1053", "example.org.:1053"}
for i := 0; i < len(addrs); i += 2 {
ts := addrs[i]
expected := addrs[i+1]
actual := Addr(ts).Normalize()
if expected != actual {
t.Errorf("Expected %v, got %v\n", expected, actual)
}
}
}