Skip to content

Commit

Permalink
weaveworks#362 - command line arg for using a specific fallback DNS s…
Browse files Browse the repository at this point in the history
…erver
  • Loading branch information
inercia committed Feb 23, 2015
1 parent f3c7bdf commit d1adde1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
7 changes: 2 additions & 5 deletions nameserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ func TestUDPDNSServer(t *testing.T) {
config := &dns.ClientConfig{Servers: []string{"127.0.0.1"}, Port: fallbackPort}
srv := NewDNSServer(config, zone, nil, port)
defer srv.Stop()
err = srv.Start()
wt.AssertNoErr(t, err)
go srv.Start()
time.Sleep(100 * time.Millisecond) // Allow sever goroutine to start

c := new(dns.Client)
Expand Down Expand Up @@ -192,8 +191,7 @@ func TestTCPDNSServer(t *testing.T) {
config := &dns.ClientConfig{Servers: []string{"127.0.0.1"}, Port: fallbackPort}
srv := NewDNSServer(config, zone, nil, port)
defer srv.Stop()
err = srv.Start()
wt.AssertNoErr(t, err)
go srv.Start()
time.Sleep(100 * time.Millisecond) // Allow sever goroutine to start

t.Logf("Creating a UDP and a TCP client")
Expand Down Expand Up @@ -267,7 +265,6 @@ func RunLocalTCPServer(t *testing.T, laddr string, handler dns.HandlerFunc) (*dn
l.Close()
}()


t.Logf("Fallback TCP server listening at %s", l.Addr().String())
return server, l.Addr().String(), nil
}
21 changes: 17 additions & 4 deletions weavedns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package main
import (
"flag"
"fmt"
"github.com/miekg/dns"
. "github.com/zettio/weave/common"
weavedns "github.com/zettio/weave/nameserver"
weavenet "github.com/zettio/weave/net"
"io"
"net"
"os"
"github.com/miekg/dns"
)

var version = "(unreleased version)"
Expand All @@ -19,11 +19,13 @@ func main() {
justVersion bool
ifaceName string
apiPath string
fallback string
dnsPort int
httpPort int
wait int
watch bool
debug bool
err error
)

flag.BoolVar(&justVersion, "version", false, "print version and exit")
Expand All @@ -32,6 +34,7 @@ func main() {
flag.IntVar(&wait, "wait", 0, "number of seconds to wait for interface to be created and come up")
flag.IntVar(&dnsPort, "dnsport", 53, "port to listen to DNS requests")
flag.IntVar(&httpPort, "httpport", 6785, "port to listen to HTTP requests")
flag.StringVar(&fallback, "fallback", "", "Fallback server and port (ie, '8.8.8.8:53')")
flag.BoolVar(&watch, "watch", true, "watch the docker socket for container events")
flag.BoolVar(&debug, "debug", false, "output debugging info to stderr")
flag.Parse()
Expand Down Expand Up @@ -64,9 +67,19 @@ func main() {
}
}

config, err := dns.ClientConfigFromFile("/etc/resolv.conf")
if err != nil {
Error.Fatal("Failed obtain DNS client configuration", err)
var config *dns.ClientConfig
if len(fallback) > 0 {
fallbackHost, fallbackPort, err := net.SplitHostPort(fallback)
if err != nil {
Error.Fatal("Fould not parse fallback host and port", err)
}
config = &dns.ClientConfig{Servers: []string{fallbackHost}, Port: fallbackPort}
Debug.Printf("DNS fallback at %s:%s", fallbackHost, fallbackPort)
} else {
config, err = dns.ClientConfigFromFile("/etc/resolv.conf")
if err != nil {
Error.Fatal("Failed obtain DNS client configuration", err)
}
}

go weavedns.ListenHttp(weavedns.LOCAL_DOMAIN, zone, httpPort)
Expand Down

0 comments on commit d1adde1

Please sign in to comment.