mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	When the interface doesn't exist you get: plugin/bind: not a valid IP address: eth0 Fix the wording that this can also be interface name. Also %q the argument in the error mesg. Signed-off-by: Miek Gieben <miek@miek.nl>
		
			
				
	
	
		
			58 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package bind
 | |
| 
 | |
| import (
 | |
| 	"fmt"
 | |
| 	"net"
 | |
| 
 | |
| 	"github.com/coredns/caddy"
 | |
| 	"github.com/coredns/coredns/core/dnsserver"
 | |
| 	"github.com/coredns/coredns/plugin"
 | |
| )
 | |
| 
 | |
| func setup(c *caddy.Controller) error {
 | |
| 	config := dnsserver.GetConfig(c)
 | |
| 
 | |
| 	// addresses will be consolidated over all BIND directives available in that BlocServer
 | |
| 	all := []string{}
 | |
| 	for c.Next() {
 | |
| 		args := c.RemainingArgs()
 | |
| 		if len(args) == 0 {
 | |
| 			return plugin.Error("bind", fmt.Errorf("at least one address or interface name is expected"))
 | |
| 		}
 | |
| 
 | |
| 		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 addresses of the interface: %q", arg))
 | |
| 					}
 | |
| 					for _, addr := range addrs {
 | |
| 						if ipnet, ok := addr.(*net.IPNet); ok {
 | |
| 							if ipnet.IP.To4() != nil || (!ipnet.IP.IsLinkLocalMulticast() && !ipnet.IP.IsLinkLocalUnicast()) {
 | |
| 								all = append(all, ipnet.IP.String())
 | |
| 							}
 | |
| 						}
 | |
| 					}
 | |
| 				}
 | |
| 			}
 | |
| 			if !isIface {
 | |
| 				if net.ParseIP(arg) == nil {
 | |
| 					return plugin.Error("bind", fmt.Errorf("not a valid IP address or interface name: %q", arg))
 | |
| 				}
 | |
| 				all = append(all, arg)
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	config.ListenHosts = all
 | |
| 	return nil
 | |
| }
 |