From 7b02365de87cdb9408b4924ffb61c2fd527e036c Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 9 Oct 2014 19:33:58 +0100 Subject: [PATCH 1/7] make dns resolution work in weave container by using go's internal DNS resolver. NB: this relies on go's std library having been compiled with the netgo build tag, e.g. sudo go install -tags netgo -a std issue #93 --- weaver/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/weaver/Makefile b/weaver/Makefile index 772730c7..38898deb 100644 --- a/weaver/Makefile +++ b/weaver/Makefile @@ -6,8 +6,8 @@ SUDO=sudo all: docker-image weaver: ../*.go main.go - go get - go build -ldflags '-extldflags "-static"' + go get -tags netgo + go build -ldflags '-extldflags "-static"' -tags netgo .PHONY: docker-image docker-image: /var/tmp/weave.tar From cf9c479727d4870f06a9abe5a6f06e6b874d79d0 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 9 Oct 2014 20:57:56 +0100 Subject: [PATCH 2/7] check that the go stdlib was built with the required options AFAICT, go build tags are a compile-time only construct, so there is no way to query whether a certain package was built with a specific tag. However, the 'netgo' tag triggers conditional compilation of the cgo_stubs.go file, and that file name ends up in the executable. (we could have looked for specific symbols in the 'net.a' library instead, but that requires locating it first, which is more hassle than it is worth) issue #93 --- weaver/Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/weaver/Makefile b/weaver/Makefile index 38898deb..e5b53486 100644 --- a/weaver/Makefile +++ b/weaver/Makefile @@ -8,6 +8,13 @@ all: docker-image weaver: ../*.go main.go go get -tags netgo go build -ldflags '-extldflags "-static"' -tags netgo + @strings $@ | grep cgo_stub\\\.go >/dev/null || { \ + rm $@; \ + echo "\nYour go standard library was built without the 'netgo' build tag."; \ + echo "To fix that, run"; \ + echo " sudo go install -a -tags netgo std"; \ + false; \ + } .PHONY: docker-image docker-image: /var/tmp/weave.tar From eef311ba6980183e204eda0b85b40d350aa97dd2 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 10 Oct 2014 11:45:10 +0100 Subject: [PATCH 3/7] Resolve name to IP address when removing connected targets --- connection_maker.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/connection_maker.go b/connection_maker.go index 12c5474a..b9a6b5c7 100644 --- a/connection_maker.go +++ b/connection_maker.go @@ -133,7 +133,9 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections() time.Duration { now := time.Now() // make sure we catch items just added after := MaxDuration for address, target := range cm.targets { - if our_connected_targets[address] { + tcpAddr, err := net.ResolveTCPAddr("tcp4", address) + ipAddr := tcpAddr.String() + if err == nil && our_connected_targets[ipAddr] { delete(cm.targets, address) continue } From af3e1b88882bac022556ebd5bf1f950034bb037f Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 10 Oct 2014 11:57:34 +0100 Subject: [PATCH 4/7] Revert "Resolve name to IP address when removing connected targets" This reverts commit eef311ba6980183e204eda0b85b40d350aa97dd2. --- connection_maker.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/connection_maker.go b/connection_maker.go index b9a6b5c7..12c5474a 100644 --- a/connection_maker.go +++ b/connection_maker.go @@ -133,9 +133,7 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections() time.Duration { now := time.Now() // make sure we catch items just added after := MaxDuration for address, target := range cm.targets { - tcpAddr, err := net.ResolveTCPAddr("tcp4", address) - ipAddr := tcpAddr.String() - if err == nil && our_connected_targets[ipAddr] { + if our_connected_targets[address] { delete(cm.targets, address) continue } From be39cb01bdba294b85744e40380a80f3e5ed715a Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 10 Oct 2014 12:22:01 +0100 Subject: [PATCH 5/7] Resolve peer names to IP address at startup --- weaver/main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/weaver/main.go b/weaver/main.go index 3ca078db..d7eeff34 100644 --- a/weaver/main.go +++ b/weaver/main.go @@ -127,7 +127,13 @@ func main() { router := weave.NewRouter(iface, ourName, []byte(password), connLimit, bufSz*1024*1024, logFrame) router.Start() for _, peer := range peers { - router.ConnectionMaker.InitiateConnection(peer) + normPeer := weave.NormalisePeerAddr(peer) + addr, err := net.ResolveTCPAddr("tcp4", normPeer) + if err == nil { + router.ConnectionMaker.InitiateConnection(addr.String()) + } else { + log.Fatal(err) + } } go handleHttp(router) handleSignals(router) From 8de22f4bf1350fac5c927196c9f6eb157f2365d2 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 10 Oct 2014 12:28:52 +0100 Subject: [PATCH 6/7] reformat --- weaver/main.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/weaver/main.go b/weaver/main.go index d7eeff34..1f351255 100644 --- a/weaver/main.go +++ b/weaver/main.go @@ -127,9 +127,7 @@ func main() { router := weave.NewRouter(iface, ourName, []byte(password), connLimit, bufSz*1024*1024, logFrame) router.Start() for _, peer := range peers { - normPeer := weave.NormalisePeerAddr(peer) - addr, err := net.ResolveTCPAddr("tcp4", normPeer) - if err == nil { + if addr, err := net.ResolveTCPAddr("tcp4", weave.NormalisePeerAddr(peer)); err == nil { router.ConnectionMaker.InitiateConnection(addr.String()) } else { log.Fatal(err) From 61ce4d36e5843397ef1234a4a2dfd3543af6a377 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 10 Oct 2014 12:42:37 +0100 Subject: [PATCH 7/7] Change README to say that hostnames are allowed on the commandline --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 64e6db41..18f3c38c 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,9 @@ We repeat similar steps on $HOST2... The only difference, apart from the choice of IP addresses for the weave router and the application container, is that we tell our weave that it should peer with the weave on $HOST1 (specified as the IP -address by which $HOST2 can reach it). NB: if there is a firewall -between $HOST1 and $HOST2, you must open port 6783 for TCP and UDP. +address or hostname by which $HOST2 can reach it). NB: if there is a +firewall between $HOST1 and $HOST2, you must open port 6783 for TCP +and UDP. Note that we could instead have told the weave on $HOST1 to connect to $HOST2, or told both about each other. Order does not matter here;