* core: allow all CIDR ranges in zone specifications Allow (e.g.) a v4 reverse on a /17. If a zone is specified in such a way a FilterFunc is set in the config. This filter is checked against incoming queries. For all other queries this adds a 'x != nil' check which will not impact performace too much. Benchmark function is added as well to check for this as wel. Add multiple tests in tests/server_reverse_test.go. Benchmark shows in the non-reverse case this hardly impact the speed: ~~~ classless: pkg: github.com/coredns/coredns/core/dnsserver BenchmarkCoreServeDNS-4 1000000 1431 ns/op 16 B/op 1 allocs/op pkg: github.com/coredns/coredns/core/dnsserver BenchmarkCoreServeDNS-4 1000000 1429 ns/op 16 B/op 1 allocs/op master: pkg: github.com/coredns/coredns/core/dnsserver BenchmarkCoreServeDNS-4 1000000 1412 ns/op 16 B/op 1 allocs/op pkg: github.com/coredns/coredns/core/dnsserver BenchmarkCoreServeDNS-4 1000000 1429 ns/op 16 B/op 1 allocs/op ~~~ * README.md updates
64 lines
2 KiB
Go
64 lines
2 KiB
Go
package dnsserver
|
|
|
|
import "testing"
|
|
|
|
func TestNormalizeZone(t *testing.T) {
|
|
for i, test := range []struct {
|
|
input string
|
|
expected string
|
|
shouldErr bool
|
|
}{
|
|
{".", "dns://.:53", false},
|
|
{".:54", "dns://.:54", false},
|
|
{"..", "://:", true},
|
|
{"..", "://:", true},
|
|
{".:", "://:", true},
|
|
} {
|
|
addr, err := normalizeZone(test.input)
|
|
actual := addr.String()
|
|
if test.shouldErr && err == nil {
|
|
t.Errorf("Test %d: Expected error, but there wasn't any", i)
|
|
}
|
|
if !test.shouldErr && err != nil {
|
|
t.Errorf("Test %d: Expected no error, but there was one: %v", i, err)
|
|
}
|
|
if actual != test.expected {
|
|
t.Errorf("Test %d: Expected %s but got %s", i, test.expected, actual)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNormalizeZoneReverse(t *testing.T) {
|
|
for i, test := range []struct {
|
|
input string
|
|
expected string
|
|
shouldErr bool
|
|
}{
|
|
{"2003::1/64", "dns://0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.0.0.2.ip6.arpa.:53", false},
|
|
{"2003::1/64.", "dns://2003::1/64.:53", false}, // OK, with closing dot the parse will fail.
|
|
{"2003::1/64:53", "dns://0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.0.0.2.ip6.arpa.:53", false},
|
|
{"2003::1/64.:53", "dns://2003::1/64.:53", false},
|
|
|
|
{"10.0.0.0/24", "dns://0.0.10.in-addr.arpa.:53", false},
|
|
{"10.0.0.0/24.", "dns://10.0.0.0/24.:53", false},
|
|
{"10.0.0.0/24:53", "dns://0.0.10.in-addr.arpa.:53", false},
|
|
{"10.0.0.0/24.:53", "dns://10.0.0.0/24.:53", false},
|
|
|
|
// non %8==0 netmasks
|
|
{"2003::53/67", "dns://0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.3.0.0.2.ip6.arpa.:53", false},
|
|
{"10.0.0.0/25.", "dns://10.0.0.0/25.:53", false}, // has dot
|
|
{"10.0.0.0/25", "dns://0.0.10.in-addr.arpa.:53", false},
|
|
} {
|
|
addr, err := normalizeZone(test.input)
|
|
actual := addr.String()
|
|
if test.shouldErr && err == nil {
|
|
t.Errorf("Test %d: Expected error, but there wasn't any", i)
|
|
}
|
|
if !test.shouldErr && err != nil {
|
|
t.Errorf("Test %d: Expected no error, but there was one: %v", i, err)
|
|
}
|
|
if actual != test.expected {
|
|
t.Errorf("Test %d: Expected %s but got %s", i, test.expected, actual)
|
|
}
|
|
}
|
|
}
|