DNS HTTP API listens on eth0 only

This commit is contained in:
Adam Harrison committed 2015-06-12 16:55:27 +01:00
1 parent 79c5343ca5
commit b6889ec8c3
2 files changed
+39 -4

No files matched your search

+37 -3
View File
@@ -11,6 +11,7 @@ import (
"github.com/weaveworks/weave/common/updater" "github.com/weaveworks/weave/common/updater"
weavedns "github.com/weaveworks/weave/nameserver" weavedns "github.com/weaveworks/weave/nameserver"
weavenet "github.com/weaveworks/weave/net" weavenet "github.com/weaveworks/weave/net"
"strconv"
) )
var version = "(unreleased version)" var version = "(unreleased version)"
@@ -22,6 +23,7 @@ func main() {
apiPath string apiPath string
domain string domain string
dnsPort int dnsPort int
httpIfaceName string
httpPort int httpPort int
wait int wait int
ttl int ttl int
@@ -46,6 +48,7 @@ func main() {
flag.StringVar(&domain, "domain", weavedns.DefaultLocalDomain, "local domain (ie, 'weave.local.')") flag.StringVar(&domain, "domain", weavedns.DefaultLocalDomain, "local domain (ie, 'weave.local.')")
flag.IntVar(&wait, "wait", 0, "number of seconds to wait for interface to be created and come up") flag.IntVar(&wait, "wait", 0, "number of seconds to wait for interface to be created and come up")
flag.IntVar(&dnsPort, "dnsport", weavedns.DefaultServerPort, "port to listen to DNS requests") flag.IntVar(&dnsPort, "dnsport", weavedns.DefaultServerPort, "port to listen to DNS requests")
flag.StringVar(&httpIfaceName, "httpiface", "", "interface on which to listen for HTTP requests (defaults to empty string which listens on all interfaces)")
flag.IntVar(&httpPort, "httpport", weavedns.DefaultHTTPPort, "port to listen to HTTP requests") flag.IntVar(&httpPort, "httpport", weavedns.DefaultHTTPPort, "port to listen to HTTP requests")
flag.IntVar(&cacheLen, "cache", weavedns.DefaultCacheLen, "cache length") flag.IntVar(&cacheLen, "cache", weavedns.DefaultCacheLen, "cache length")
flag.IntVar(&ttl, "ttl", weavedns.DefaultLocalTTL, "TTL (in secs) for responses for local names") flag.IntVar(&ttl, "ttl", weavedns.DefaultLocalTTL, "TTL (in secs) for responses for local names")
@@ -74,15 +77,45 @@ func main() {
var iface *net.Interface var iface *net.Interface
if ifaceName != "" { if ifaceName != "" {
var err error var err error
Info.Println("Waiting for interface", ifaceName, "to come up") Info.Println("[main] Waiting for mDNS interface", ifaceName, "to come up")
iface, err = weavenet.EnsureInterface(ifaceName, wait) iface, err = weavenet.EnsureInterface(ifaceName, wait)
if err != nil { if err != nil {
Error.Fatal(err) Error.Fatal(err)
} else { } else {
Info.Println("Interface", ifaceName, "is up") Info.Println("[main] Interface", ifaceName, "is up")
} }
} }
var httpIP string
if httpIfaceName == "" {
httpIP = "0.0.0.0"
} else {
Info.Println("[main] Waiting for HTTP interface", httpIfaceName, "to come up")
httpIface, err := weavenet.EnsureInterface(httpIfaceName, wait)
if err != nil {
Error.Fatal(err)
}
Info.Println("[main] Interface", httpIfaceName, "is up")
addrs, err := httpIface.Addrs()
if err != nil {
Error.Fatal(err)
}
if len(addrs) == 0 {
Error.Fatal("[main] No addresses on HTTP interface")
}
ip, _, err := net.ParseCIDR(addrs[0].String())
if err != nil {
Error.Fatal(err)
}
httpIP = ip.String()
}
httpAddr := net.JoinHostPort(httpIP, strconv.Itoa(httpPort))
zoneConfig := weavedns.ZoneConfig{ zoneConfig := weavedns.ZoneConfig{
Domain: domain, Domain: domain,
Iface: iface, Iface: iface,
@@ -134,10 +167,11 @@ func main() {
Error.Fatal("[main] Failed to initialize the WeaveDNS server", err) Error.Fatal("[main] Failed to initialize the WeaveDNS server", err)
} }
httpListener, err := net.Listen("tcp", fmt.Sprintf(":%d", httpPort)) httpListener, err := net.Listen("tcp", httpAddr)
if err != nil { if err != nil {
Error.Fatal("[main] Unable to create http listener: ", err) Error.Fatal("[main] Unable to create http listener: ", err)
} }
Info.Println("[main] HTTP API listening on", httpAddr)
go SignalHandlerLoop(srv) go SignalHandlerLoop(srv)
go weavedns.ServeHTTP(httpListener, version, srv, domain, zone) go weavedns.ServeHTTP(httpListener, version, srv, domain, zone)
+2 -1
View File
@@ -177,6 +177,7 @@ MTU=65535
PORT=${WEAVE_PORT:-6783} PORT=${WEAVE_PORT:-6783}
HTTP_PORT=6784 HTTP_PORT=6784
DNS_HTTP_PORT=6785 DNS_HTTP_PORT=6785
DNS_HTTP_IFNAME=eth0
PROXY_PORT=12375 PROXY_PORT=12375
PROXY_CONTAINER_NAME=weaveproxy PROXY_CONTAINER_NAME=weaveproxy
@@ -1021,7 +1022,7 @@ case "$COMMAND" in
DNS_CONTAINER=$(docker run --privileged -d --name=$DNS_CONTAINER_NAME \ DNS_CONTAINER=$(docker run --privileged -d --name=$DNS_CONTAINER_NAME \
-p $DOCKER_BRIDGE_IP:53:53/udp \ -p $DOCKER_BRIDGE_IP:53:53/udp \
-v /var/run/docker.sock:/var/run/docker.sock \ -v /var/run/docker.sock:/var/run/docker.sock \
$WEAVEDNS_DOCKER_ARGS $DNS_IMAGE -iface $CONTAINER_IFNAME "$@") $WEAVEDNS_DOCKER_ARGS $DNS_IMAGE -iface $CONTAINER_IFNAME -httpiface "$DNS_HTTP_IFNAME" "$@")
ipam_cidrs $DNS_CONTAINER $CIDR_ARGS ipam_cidrs $DNS_CONTAINER $CIDR_ARGS
with_container_netns_or_die $DNS_CONTAINER attach $ALL_CIDRS with_container_netns_or_die $DNS_CONTAINER attach $ALL_CIDRS
populate_dns populate_dns