Allow more than 1 address for transfer (#121)
No reason why not to allow more then one address: `transfer to 127.0.0.1 10.240.20.1`. Fix startup as well, as it turned out to be broken...
This commit is contained in:
parent
eb1f21bfff
commit
885e6e8246
4 changed files with 41 additions and 23 deletions
|
@ -1,6 +1,8 @@
|
|||
package setup
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"github.com/miekg/coredns/middleware"
|
||||
|
@ -68,8 +70,8 @@ func fileParse(c *Controller) (file.Zones, error) {
|
|||
}
|
||||
// discard from, here, maybe check and show log when we do?
|
||||
for _, origin := range origins {
|
||||
if t != "" {
|
||||
z[origin].TransferTo = append(z[origin].TransferTo, t)
|
||||
if t != nil {
|
||||
z[origin].TransferTo = append(z[origin].TransferTo, t...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -78,30 +80,41 @@ func fileParse(c *Controller) (file.Zones, error) {
|
|||
return file.Zones{Z: z, Names: names}, nil
|
||||
}
|
||||
|
||||
// transfer to [address]
|
||||
func parseTransfer(c *Controller) (to, from string, err error) {
|
||||
// transfer to [address...]
|
||||
func parseTransfer(c *Controller) (tos, froms []string, err error) {
|
||||
what := c.Val()
|
||||
if !c.NextArg() {
|
||||
return "", "", c.ArgErr()
|
||||
return nil, nil, c.ArgErr()
|
||||
}
|
||||
value := c.Val()
|
||||
switch what {
|
||||
case "transfer":
|
||||
if !c.NextArg() {
|
||||
return "", "", c.ArgErr()
|
||||
return nil, nil, c.ArgErr()
|
||||
}
|
||||
if value == "to" {
|
||||
to = c.Val()
|
||||
if to != "*" {
|
||||
to = middleware.Addr(to).Normalize()
|
||||
tos := c.RemainingArgs()
|
||||
for i, _ := range tos {
|
||||
if x := net.ParseIP(tos[i]); x == nil {
|
||||
return nil, nil, fmt.Errorf("must specify an IP addres: `%s'", tos[i])
|
||||
}
|
||||
if tos[i] != "*" {
|
||||
tos[i] = middleware.Addr(tos[i]).Normalize()
|
||||
}
|
||||
}
|
||||
}
|
||||
if value == "from" {
|
||||
from = c.Val()
|
||||
if from == "*" {
|
||||
// print some kind of error? TODO(miek)
|
||||
froms := c.RemainingArgs()
|
||||
for i, _ := range froms {
|
||||
if x := net.ParseIP(froms[i]); x == nil {
|
||||
return nil, nil, fmt.Errorf("must specify an IP addres: `%s'", froms[i])
|
||||
}
|
||||
if froms[i] != "*" {
|
||||
froms[i] = middleware.Addr(froms[i]).Normalize()
|
||||
} else {
|
||||
return nil, nil, fmt.Errorf("can't use '*' in transfer from")
|
||||
}
|
||||
}
|
||||
from = middleware.Addr(from).Normalize()
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
|
@ -57,11 +57,11 @@ func secondaryParse(c *Controller) (file.Zones, error) {
|
|||
return file.Zones{}, e
|
||||
}
|
||||
for _, origin := range origins {
|
||||
if t != "" {
|
||||
z[origin].TransferTo = append(z[origin].TransferTo, t)
|
||||
if t != nil {
|
||||
z[origin].TransferTo = append(z[origin].TransferTo, t...)
|
||||
}
|
||||
if f != "" {
|
||||
z[origin].TransferFrom = append(z[origin].TransferFrom, f)
|
||||
if f != nil {
|
||||
z[origin].TransferFrom = append(z[origin].TransferFrom, f...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,18 +18,19 @@ file dbfile [zones...]
|
|||
If you want to round robin A and AAAA responses look at the `loadbalance` middleware.
|
||||
|
||||
TSIG key configuration is TODO; directive format for transfer will probably be extended with
|
||||
TSIG key information, something like `transfer out [address] key [name] [base64]`
|
||||
TSIG key information, something like `transfer out [address...] key [name] [base64]`
|
||||
|
||||
~~~
|
||||
file dbfile [zones... ] {
|
||||
transfer out [address...]
|
||||
transfer to [address]
|
||||
transfer from [address...]
|
||||
transfer to [address...]
|
||||
|
||||
}
|
||||
~~~
|
||||
|
||||
* `transfer` enables zone transfers. It may be specified multiples times. *To* or *from* signals
|
||||
the direction. Address must be denoted in CIDR notation (127.0.0.1/32 etc.). The special
|
||||
wildcard "*" means: the entire internet.
|
||||
the direction. Addresses must be denoted in CIDR notation (127.0.0.1/32 etc.) or just as plain
|
||||
address. The special wildcard "*" means: the entire internet (only valid for 'transfer to').
|
||||
|
||||
## Examples
|
||||
|
||||
|
|
|
@ -163,17 +163,20 @@ func (s *Server) Serve(ln ListenerFile) error {
|
|||
// ListenAndServe starts the server with a new listener. It blocks until the server stops.
|
||||
func (s *Server) ListenAndServe() error {
|
||||
err := s.setup()
|
||||
defer close(s.startChan)
|
||||
// defer close(s.startChan) // Don't understand why defer wouldn't actually work in this method.
|
||||
if err != nil {
|
||||
close(s.startChan)
|
||||
return err
|
||||
}
|
||||
|
||||
l, err := net.Listen("tcp", s.Addr)
|
||||
if err != nil {
|
||||
close(s.startChan)
|
||||
return err
|
||||
}
|
||||
pc, err := net.ListenPacket("udp", s.Addr)
|
||||
if err != nil {
|
||||
close(s.startChan)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -187,6 +190,7 @@ func (s *Server) ListenAndServe() error {
|
|||
go func() {
|
||||
s.server[0].ActivateAndServe()
|
||||
}()
|
||||
close(s.startChan)
|
||||
return s.server[1].ActivateAndServe()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue