Commit 3654361b authored by Miek Gieben's avatar Miek Gieben Committed by GitHub

core: small cleanup (#877)

Add some docs about normalize.Host and normalize.Name. They are used
correctly in the middleware even though they are somewhat confusing,
esp when you copy from ServerBlockKeys in your middleware.
parent 28447234
...@@ -81,7 +81,6 @@ func autoParse(c *caddy.Controller) (Auto, error) { ...@@ -81,7 +81,6 @@ func autoParse(c *caddy.Controller) (Auto, error) {
config := dnsserver.GetConfig(c) config := dnsserver.GetConfig(c)
for c.Next() { for c.Next() {
if c.Val() == "auto" {
// auto [ZONES...] // auto [ZONES...]
a.Zones.origins = make([]string, len(c.ServerBlockKeys)) a.Zones.origins = make([]string, len(c.ServerBlockKeys))
copy(a.Zones.origins, c.ServerBlockKeys) copy(a.Zones.origins, c.ServerBlockKeys)
...@@ -165,8 +164,6 @@ func autoParse(c *caddy.Controller) (Auto, error) { ...@@ -165,8 +164,6 @@ func autoParse(c *caddy.Controller) (Auto, error) {
} }
} }
} }
}
} }
return a, nil return a, nil
} }
...@@ -42,7 +42,6 @@ func dnssecParse(c *caddy.Controller) ([]string, []*DNSKEY, int, error) { ...@@ -42,7 +42,6 @@ func dnssecParse(c *caddy.Controller) ([]string, []*DNSKEY, int, error) {
capacity := defaultCap capacity := defaultCap
for c.Next() { for c.Next() {
if c.Val() == "dnssec" {
// dnssec [zones...] // dnssec [zones...]
zones = make([]string, len(c.ServerBlockKeys)) zones = make([]string, len(c.ServerBlockKeys))
copy(zones, c.ServerBlockKeys) copy(zones, c.ServerBlockKeys)
...@@ -73,7 +72,6 @@ func dnssecParse(c *caddy.Controller) ([]string, []*DNSKEY, int, error) { ...@@ -73,7 +72,6 @@ func dnssecParse(c *caddy.Controller) ([]string, []*DNSKEY, int, error) {
} }
} }
}
for i := range zones { for i := range zones {
zones[i] = middleware.Host(zones[i]).Normalize() zones[i] = middleware.Host(zones[i]).Normalize()
} }
......
...@@ -60,7 +60,6 @@ func etcdParse(c *caddy.Controller) (*Etcd, bool, error) { ...@@ -60,7 +60,6 @@ func etcdParse(c *caddy.Controller) (*Etcd, bool, error) {
stubzones = false stubzones = false
) )
for c.Next() { for c.Next() {
if c.Val() == "etcd" {
etc.Zones = c.RemainingArgs() etc.Zones = c.RemainingArgs()
if len(etc.Zones) == 0 { if len(etc.Zones) == 0 {
etc.Zones = make([]string, len(c.ServerBlockKeys)) etc.Zones = make([]string, len(c.ServerBlockKeys))
...@@ -125,7 +124,6 @@ func etcdParse(c *caddy.Controller) (*Etcd, bool, error) { ...@@ -125,7 +124,6 @@ func etcdParse(c *caddy.Controller) (*Etcd, bool, error) {
return &etc, stubzones, nil return &etc, stubzones, nil
} }
}
return &Etcd{}, false, nil return &Etcd{}, false, nil
} }
......
...@@ -55,7 +55,6 @@ func fileParse(c *caddy.Controller) (Zones, error) { ...@@ -55,7 +55,6 @@ func fileParse(c *caddy.Controller) (Zones, error) {
config := dnsserver.GetConfig(c) config := dnsserver.GetConfig(c)
for c.Next() { for c.Next() {
if c.Val() == "file" {
// file db.file [zones...] // file db.file [zones...]
if !c.NextArg() { if !c.NextArg() {
return Zones{}, c.ArgErr() return Zones{}, c.ArgErr()
...@@ -127,7 +126,6 @@ func fileParse(c *caddy.Controller) (Zones, error) { ...@@ -127,7 +126,6 @@ func fileParse(c *caddy.Controller) (Zones, error) {
} }
} }
} }
}
return Zones{Z: z, Names: names}, nil return Zones{Z: z, Names: names}, nil
} }
......
...@@ -41,7 +41,6 @@ func hostsParse(c *caddy.Controller) (Hosts, error) { ...@@ -41,7 +41,6 @@ func hostsParse(c *caddy.Controller) (Hosts, error) {
config := dnsserver.GetConfig(c) config := dnsserver.GetConfig(c)
for c.Next() { for c.Next() {
if c.Val() == "hosts" { // hosts [FILE] [ZONES...]
args := c.RemainingArgs() args := c.RemainingArgs()
if len(args) >= 1 { if len(args) >= 1 {
h.path = args[0] h.path = args[0]
...@@ -83,6 +82,5 @@ func hostsParse(c *caddy.Controller) (Hosts, error) { ...@@ -83,6 +82,5 @@ func hostsParse(c *caddy.Controller) (Hosts, error) {
} }
} }
} }
}
return h, nil return h, nil
} }
...@@ -30,7 +30,8 @@ func (z Zones) Matches(qname string) string { ...@@ -30,7 +30,8 @@ func (z Zones) Matches(qname string) string {
return zone return zone
} }
// Normalize fully qualifies all zones in z. // Normalize fully qualifies all zones in z. The zones in Z must be domain names, without
// a port or protocol prefix.
func (z Zones) Normalize() { func (z Zones) Normalize() {
for i := range z { for i := range z {
z[i] = Name(z[i]).Normalize() z[i] = Name(z[i]).Normalize()
...@@ -54,7 +55,7 @@ func (n Name) Normalize() string { return strings.ToLower(dns.Fqdn(string(n))) } ...@@ -54,7 +55,7 @@ func (n Name) Normalize() string { return strings.ToLower(dns.Fqdn(string(n))) }
type ( type (
// Host represents a host from the Corefile, may contain port. // Host represents a host from the Corefile, may contain port.
Host string // Host represents a host from the Corefile, may contain port. Host string
) )
// Normalize will return the host portion of host, stripping // Normalize will return the host portion of host, stripping
......
...@@ -34,19 +34,15 @@ func setupReverse(c *caddy.Controller) error { ...@@ -34,19 +34,15 @@ func setupReverse(c *caddy.Controller) error {
} }
func reverseParse(c *caddy.Controller) (nets networks, fall bool, err error) { func reverseParse(c *caddy.Controller) (nets networks, fall bool, err error) {
// normalize zones, validation is almost done by dnsserver
// TODO(miek): need sane helpers for these.
zones := make([]string, len(c.ServerBlockKeys)) zones := make([]string, len(c.ServerBlockKeys))
wildcard := false wildcard := false
// We copy from the serverblock, these contains Hosts.
for i, str := range c.ServerBlockKeys { for i, str := range c.ServerBlockKeys {
zones[i] = middleware.Host(str).Normalize() zones[i] = middleware.Host(str).Normalize()
} }
for c.Next() { for c.Next() {
if c.Val() == "reverse" {
var cidrs []*net.IPNet var cidrs []*net.IPNet
// parse all networks // parse all networks
...@@ -144,7 +140,6 @@ func reverseParse(c *caddy.Controller) (nets networks, fall bool, err error) { ...@@ -144,7 +140,6 @@ func reverseParse(c *caddy.Controller) (nets networks, fall bool, err error) {
}) })
} }
} }
}
// sort by cidr // sort by cidr
sort.Sort(nets) sort.Sort(nets)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment