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
|
package setup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/miekg/coredns/middleware"
|
"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?
|
// discard from, here, maybe check and show log when we do?
|
||||||
for _, origin := range origins {
|
for _, origin := range origins {
|
||||||
if t != "" {
|
if t != nil {
|
||||||
z[origin].TransferTo = append(z[origin].TransferTo, t)
|
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
|
return file.Zones{Z: z, Names: names}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// transfer to [address]
|
// transfer to [address...]
|
||||||
func parseTransfer(c *Controller) (to, from string, err error) {
|
func parseTransfer(c *Controller) (tos, froms []string, err error) {
|
||||||
what := c.Val()
|
what := c.Val()
|
||||||
if !c.NextArg() {
|
if !c.NextArg() {
|
||||||
return "", "", c.ArgErr()
|
return nil, nil, c.ArgErr()
|
||||||
}
|
}
|
||||||
value := c.Val()
|
value := c.Val()
|
||||||
switch what {
|
switch what {
|
||||||
case "transfer":
|
case "transfer":
|
||||||
if !c.NextArg() {
|
if !c.NextArg() {
|
||||||
return "", "", c.ArgErr()
|
return nil, nil, c.ArgErr()
|
||||||
}
|
}
|
||||||
if value == "to" {
|
if value == "to" {
|
||||||
to = c.Val()
|
tos := c.RemainingArgs()
|
||||||
if to != "*" {
|
for i, _ := range tos {
|
||||||
to = middleware.Addr(to).Normalize()
|
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" {
|
if value == "from" {
|
||||||
from = c.Val()
|
froms := c.RemainingArgs()
|
||||||
if from == "*" {
|
for i, _ := range froms {
|
||||||
// print some kind of error? TODO(miek)
|
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
|
return
|
||||||
|
|
|
@ -57,11 +57,11 @@ func secondaryParse(c *Controller) (file.Zones, error) {
|
||||||
return file.Zones{}, e
|
return file.Zones{}, e
|
||||||
}
|
}
|
||||||
for _, origin := range origins {
|
for _, origin := range origins {
|
||||||
if t != "" {
|
if t != nil {
|
||||||
z[origin].TransferTo = append(z[origin].TransferTo, t)
|
z[origin].TransferTo = append(z[origin].TransferTo, t...)
|
||||||
}
|
}
|
||||||
if f != "" {
|
if f != nil {
|
||||||
z[origin].TransferFrom = append(z[origin].TransferFrom, f)
|
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.
|
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 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... ] {
|
file dbfile [zones... ] {
|
||||||
transfer out [address...]
|
transfer from [address...]
|
||||||
transfer to [address]
|
transfer to [address...]
|
||||||
|
|
||||||
}
|
}
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
* `transfer` enables zone transfers. It may be specified multiples times. *To* or *from* signals
|
* `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
|
the direction. Addresses must be denoted in CIDR notation (127.0.0.1/32 etc.) or just as plain
|
||||||
wildcard "*" means: the entire internet.
|
address. The special wildcard "*" means: the entire internet (only valid for 'transfer to').
|
||||||
|
|
||||||
## Examples
|
## 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.
|
// ListenAndServe starts the server with a new listener. It blocks until the server stops.
|
||||||
func (s *Server) ListenAndServe() error {
|
func (s *Server) ListenAndServe() error {
|
||||||
err := s.setup()
|
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 {
|
if err != nil {
|
||||||
|
close(s.startChan)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
l, err := net.Listen("tcp", s.Addr)
|
l, err := net.Listen("tcp", s.Addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
close(s.startChan)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
pc, err := net.ListenPacket("udp", s.Addr)
|
pc, err := net.ListenPacket("udp", s.Addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
close(s.startChan)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,6 +190,7 @@ func (s *Server) ListenAndServe() error {
|
||||||
go func() {
|
go func() {
|
||||||
s.server[0].ActivateAndServe()
|
s.server[0].ActivateAndServe()
|
||||||
}()
|
}()
|
||||||
|
close(s.startChan)
|
||||||
return s.server[1].ActivateAndServe()
|
return s.server[1].ActivateAndServe()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue