aboutsummaryrefslogtreecommitdiff
path: root/plugin/bind/setup.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/bind/setup.go')
-rw-r--r--plugin/bind/setup.go38
1 files changed, 31 insertions, 7 deletions
diff --git a/plugin/bind/setup.go b/plugin/bind/setup.go
index 44c9b8a6f..afca06097 100644
--- a/plugin/bind/setup.go
+++ b/plugin/bind/setup.go
@@ -15,16 +15,40 @@ func setup(c *caddy.Controller) error {
// addresses will be consolidated over all BIND directives available in that BlocServer
all := []string{}
for c.Next() {
- addrs := c.RemainingArgs()
- if len(addrs) == 0 {
- return plugin.Error("bind", fmt.Errorf("at least one address is expected"))
+ args := c.RemainingArgs()
+ if len(args) == 0 {
+ return plugin.Error("bind", fmt.Errorf("at least one address or interface name is expected"))
}
- for _, addr := range addrs {
- if net.ParseIP(addr) == nil {
- return plugin.Error("bind", fmt.Errorf("not a valid IP address: %s", addr))
+
+ ifaces, err := net.Interfaces()
+ if err != nil {
+ return plugin.Error("bind", fmt.Errorf("failed to get interfaces list"))
+ }
+
+ var isIface bool
+ for _, arg := range args {
+ isIface = false
+ for _, iface := range ifaces {
+ if arg == iface.Name {
+ isIface = true
+ addrs, err := iface.Addrs()
+ if err != nil {
+ return plugin.Error("bind", fmt.Errorf("failed to get the IP(s) of the interface: %s", arg))
+ }
+ for _, addr := range addrs {
+ if ipnet, ok := addr.(*net.IPNet); ok {
+ all = append(all, ipnet.IP.String())
+ }
+ }
+ }
+ }
+ if !isIface {
+ if net.ParseIP(arg) == nil {
+ return plugin.Error("bind", fmt.Errorf("not a valid IP address: %s", arg))
+ }
+ all = append(all, arg)
}
}
- all = append(all, addrs...)
}
config.ListenHosts = all
return nil