Fix Corefile parsing

Fix some file/secondary issues when parsing a Corefile, also allow

for multiple origins to be specified. Also don't fail on startup when

a zonetransfer fails.



Fixes: #54
This commit is contained in:
Miek Gieben
2016-04-03 15:52:23 +01:00
parent e41e8683bd
commit 3b25bfd7ae
5 changed files with 32 additions and 38 deletions

View File

@@ -13,7 +13,6 @@ func File(c *Controller) (middleware.Middleware, error) {
if err != nil {
return nil, err
}
// Set start function is transfer is specified
return func(next middleware.Handler) middleware.Handler {
return file.File{Next: next, Zones: zones}
@@ -32,22 +31,25 @@ func fileParse(c *Controller) (file.Zones, error) {
}
fileName := c.Val()
origin := c.ServerBlockHosts[c.ServerBlockHostIndex]
if c.NextArg() {
origin = c.Val()
origins := []string{c.ServerBlockHosts[c.ServerBlockHostIndex]}
args := c.RemainingArgs()
if len(args) > 0 {
origins = args
}
origin = middleware.Host(origin).Normalize()
// TODO(miek): we should allow more. Issue #54.
reader, err := os.Open(fileName)
if err != nil {
return file.Zones{}, err
}
zone, err := file.Parse(reader, origin, fileName)
for i, _ := range origins {
origins[i] = middleware.Host(origins[i]).Normalize()
zone, err := file.Parse(reader, origins[i], fileName)
if err == nil {
z[origin] = zone
z[origins[i]] = zone
}
names = append(names, origins[i])
}
names = append(names, origin)
for c.NextBlock() {
t, _, e := parseTransfer(c)
@@ -55,10 +57,12 @@ func fileParse(c *Controller) (file.Zones, error) {
return file.Zones{}, e
}
// discard from, here, maybe check and show log when we do?
for _, origin := range origins {
z[origin].TransferTo = append(z[origin].TransferTo, t)
}
}
}
}
return file.Zones{Z: z, Names: names}, nil
}

View File

@@ -35,25 +35,28 @@ func secondaryParse(c *Controller) (file.Zones, error) {
for c.Next() {
if c.Val() == "secondary" {
// secondary [origin]
origin := c.ServerBlockHosts[c.ServerBlockHostIndex]
if c.NextArg() {
origin = c.Val()
origins := []string{c.ServerBlockHosts[c.ServerBlockHostIndex]}
args := c.RemainingArgs()
if len(args) > 0 {
origins = args
}
for i, _ := range origins {
origins[i] = middleware.Host(origins[i]).Normalize()
z[origins[i]] = file.NewZone(origins[i])
names = append(names, origins[i])
}
// TODO(miek): we should allow more. Issue #54.
origin = middleware.Host(origin).Normalize()
z[origin] = file.NewZone(origin)
names = append(names, origin)
for c.NextBlock() {
t, f, e := parseTransfer(c)
if e != nil {
return file.Zones{}, e
}
for _, origin := range origins {
z[origin].TransferTo = append(z[origin].TransferTo, t)
z[origin].TransferFrom = append(z[origin].TransferFrom, f)
}
}
}
}
return file.Zones{Z: z, Names: names}, nil
}

View File

@@ -207,7 +207,7 @@ func setVersion() {
}
}
const appName = "Caddy"
const appName = "CoreDNS"
// Flags that control program flow or startup
var (

View File

@@ -14,10 +14,6 @@ func (z *Zone) TransferIn() error {
t := new(dns.Transfer)
m := new(dns.Msg)
m.SetAxfr(z.name)
/*
t.TsigSecret = map[string]string{"axfr.": "so6ZGir4GPAqINNh9U5c3A=="}
m.SetTsig("axfr.", dns.HmacMD5, 300, time.Now().Unix())
*/
var Err error
Transfer:
@@ -48,16 +44,6 @@ Transfer:
}
}
}
return Err
return nil
return Err // ignore errors for now. TODO(miek)
}
/*
28800 ; refresh (8 hours)
7200 ; retry (2 hours)
604800 ; expire (1 week)
3600 ; minimum (1 hour)
// Check SOA
// Just check every refresh hours, if fail set to retry until succeeds
// expire is need: to give SERVFAIL.
*/

View File

@@ -273,6 +273,7 @@ func (s *Server) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
b := make([]byte, len(q))
off, end := 0, false
ctx := context.Background()
for {
l := len(q[off:])
for i := 0; i < l; i++ {