| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | package bind
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							|  |  |  | 	"fmt"
 | 
					
						
							|  |  |  | 	"net"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 22:51:47 -08:00
										 |  |  | 	"github.com/coredns/coredns/core/dnsserver"
 | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin"
 | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-03 09:04:47 +08:00
										 |  |  | 	"github.com/caddyserver/caddy"
 | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-28 19:56:14 -08:00
										 |  |  | func setup(c *caddy.Controller) error {
 | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | 	config := dnsserver.GetConfig(c)
 | 
					
						
							| 
									
										
										
										
											2018-02-14 14:19:32 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// addresses will be consolidated over all BIND directives available in that BlocServer
 | 
					
						
							|  |  |  | 	all := []string{}
 | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | 	for c.Next() {
 | 
					
						
							| 
									
										
										
										
											2018-02-14 14:19:32 -05:00
										 |  |  | 		addrs := c.RemainingArgs()
 | 
					
						
							|  |  |  | 		if len(addrs) == 0 {
 | 
					
						
							|  |  |  | 			return plugin.Error("bind", fmt.Errorf("at least one address is expected"))
 | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2018-02-14 14:19:32 -05:00
										 |  |  | 		for _, addr := range addrs {
 | 
					
						
							|  |  |  | 			if net.ParseIP(addr) == nil {
 | 
					
						
							|  |  |  | 				return plugin.Error("bind", fmt.Errorf("not a valid IP address: %s", addr))
 | 
					
						
							|  |  |  | 			}
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 		all = append(all, addrs...)
 | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | 	}
 | 
					
						
							| 
									
										
										
										
											2018-02-14 14:19:32 -05:00
										 |  |  | 	config.ListenHosts = all
 | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | 	return nil
 | 
					
						
							|  |  |  | }
 |