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

@@ -1,10 +1,10 @@
package dnsserver
import (
"fmt"
"net"
"strings"
"github.com/coredns/coredns/middleware"
"github.com/miekg/dns"
)
@@ -32,8 +32,6 @@ func Transport(s string) string {
// normalizeZone parses an zone string into a structured format with separate
// host, and port portions, as well as the original input string.
//
// TODO(miek): possibly move this to middleware/normalize.go
func normalizeZone(str string) (zoneAddr, error) {
var err error
@@ -52,18 +50,9 @@ func normalizeZone(str string) (zoneAddr, error) {
str = str[len(TransportGRPC+"://"):]
}
host, port, err := net.SplitHostPort(str)
host, port, err := middleware.SplitHostPort(str)
if err != nil {
host, port, err = net.SplitHostPort(str + ":")
// no error check here; return err at end of function
}
if len(host) > 255 { // TODO(miek): this should take escaping into account.
return zoneAddr{}, fmt.Errorf("specified zone is too long: %d > 255", len(host))
}
_, d := dns.IsDomainName(host)
if !d {
return zoneAddr{}, fmt.Errorf("zone is not a valid domain name: %s", host)
return zoneAddr{}, err
}
if port == "" {
@@ -78,7 +67,7 @@ func normalizeZone(str string) (zoneAddr, error) {
}
}
return zoneAddr{Zone: strings.ToLower(dns.Fqdn(host)), Port: port, Transport: trans}, err
return zoneAddr{Zone: dns.Fqdn(host), Port: port, Transport: trans}, nil
}
// Supported transports.