Fetch DNS listen address from daemon
instead of assuming it's on the Docker bridge Also move DNS address validation into NewDNSServer(), so we only do it once.
This commit is contained in:
1 parent
00623be8a7
commit
b0274e11be
5 files changed
+27
-9
No files matched your search
+5
-1
@@ -90,7 +90,7 @@ type DNSServer struct {
|
||||
ns *Nameserver
|
||||
domain string
|
||||
ttl uint32
|
||||
address string
|
||||
address string // listen address and port, e.g. 1.2.3.4:53
|
||||
|
||||
servers []*dns.Server
|
||||
upstream Upstream
|
||||
@@ -99,6 +99,10 @@ type DNSServer struct {
|
||||
}
|
||||
|
||||
func NewDNSServer(ns *Nameserver, domain, address string, upstream Upstream, ttl uint32, clientTimeout time.Duration) (*DNSServer, error) {
|
||||
if _, _, err := net.SplitHostPort(address); err != nil {
|
||||
return nil, fmt.Errorf("invalid DNS listen address %q: %v", address, err)
|
||||
}
|
||||
|
||||
s := &DNSServer{
|
||||
ns: ns,
|
||||
domain: dns.Fqdn(domain),
|
||||
|
||||
@@ -3,6 +3,7 @@ package nameserver
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
@@ -84,3 +85,13 @@ func (n *Nameserver) HandleHTTP(router *mux.Router, dockerCli *docker.Client) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (d *DNSServer) HandleHTTP(router *mux.Router) {
|
||||
router.Methods("GET").Path("/dns-address-port").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, d.address)
|
||||
})
|
||||
router.Methods("GET").Path("/dns-address").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
host, _, _ := net.SplitHostPort(d.address) // address is validated in NewDNSServer()
|
||||
fmt.Fprint(w, host)
|
||||
})
|
||||
}
|
||||
+2
-4
@@ -55,10 +55,7 @@ type dnsConfig struct {
|
||||
|
||||
// return the address part of the DNS listen address, without ":53" on the end
|
||||
func (c dnsConfig) addressOnly() string {
|
||||
addr, _, err := net.SplitHostPort(c.ListenAddress)
|
||||
if err != nil {
|
||||
Log.Fatalf("Error when parsing DNS listen address %q: %s", c.ListenAddress, err)
|
||||
}
|
||||
addr, _, _ := net.SplitHostPort(c.ListenAddress)
|
||||
return addr
|
||||
}
|
||||
|
||||
@@ -474,6 +471,7 @@ func main() {
|
||||
}
|
||||
if ns != nil {
|
||||
ns.HandleHTTP(muxRouter, dockerCli)
|
||||
dnsserver.HandleHTTP(muxRouter)
|
||||
}
|
||||
router.HandleHTTP(muxRouter)
|
||||
HandleHTTP(muxRouter, version, router, allocator, defaultSubnet, ns, dnsserver, proxy, plugin, &waitReady)
|
||||
|
||||
@@ -39,6 +39,10 @@ the same time, the hostname takes precedence. In this circumstance, if
|
||||
the hostname is not in the weaveDNS domain, the container is *not*
|
||||
registered, but it will still use weaveDNS for resolution.
|
||||
|
||||
By default, weaveDNS will listen on port 53 on the address of the
|
||||
Docker bridge. To make it listen on a different address or port use
|
||||
`weave launch --dns-listen-address <address>:<port>`
|
||||
|
||||
To disable an application container's use of weaveDNS, add the
|
||||
`--without-dns` option to `weave launch`. To
|
||||
disable weaveDNS itself, launch weave with the `--no-dns` option.
|
||||
|
||||
@@ -43,6 +43,7 @@ weave launch [--password <pass>] [--trusted-subnets <cidr>,...]
|
||||
[--host <ip_address>]
|
||||
[--name <mac>] [--nickname <nickname>]
|
||||
[--no-restart] [--resume] [--no-discovery] [--no-dns]
|
||||
[--dns-listen-address <address>:<port>]
|
||||
[--ipalloc-init <mode>]
|
||||
[--ipalloc-range <cidr> [--ipalloc-default-subnet <cidr>]]
|
||||
[--plugin=false] [--proxy=false]
|
||||
@@ -775,6 +776,7 @@ dns_args() {
|
||||
DNS_DOMAIN=${DNS_DOMAIN:-$(call_weave GET /domain 2>/dev/null)} || retval=$?
|
||||
[ "$retval" -eq 4 ] && return 0
|
||||
DNS_DOMAIN=${DNS_DOMAIN:-weave.local.}
|
||||
DNS_ADDRESS=${DNS_ADDRESS:-$(call_weave GET /dns-address 2>/dev/null)}
|
||||
|
||||
NAME_ARG=""
|
||||
HOSTNAME_SPECIFIED=
|
||||
@@ -803,8 +805,7 @@ dns_args() {
|
||||
done
|
||||
[ -n "$WITHOUT_DNS" ] && return 0
|
||||
|
||||
[ -n "$DOCKER_BRIDGE_IP" ] || DOCKER_BRIDGE_IP=$(util_op bridge-ip $DOCKER_BRIDGE)
|
||||
DNS_ARGS="--dns=$DOCKER_BRIDGE_IP"
|
||||
DNS_ARGS="--dns=$DNS_ADDRESS"
|
||||
if [ -n "$NAME_ARG" -a -z "$HOSTNAME_SPECIFIED" ] ; then
|
||||
HOSTNAME="$NAME_ARG.${DNS_DOMAIN%.}"
|
||||
if [ ${#HOSTNAME} -gt 64 ] ; then
|
||||
@@ -1489,8 +1490,8 @@ case "$COMMAND" in
|
||||
;;
|
||||
dns-lookup)
|
||||
[ $# -eq 1 ] || usage
|
||||
DOCKER_BRIDGE_IP=$(util_op bridge-ip $DOCKER_BRIDGE)
|
||||
dig @$DOCKER_BRIDGE_IP +short $1
|
||||
DNS_ADDRESS=${DNS_ADDRESS:-$(call_weave GET /dns-address-port 2>/dev/null)}
|
||||
dig @${DNS_ADDRESS%:*} -p ${DNS_ADDRESS#*:} +short $1
|
||||
;;
|
||||
expose)
|
||||
WITHOUT_MASQUERADE=
|
||||
|
||||
Reference in new issue
Block a user