From 9ce26e69734dfd4eb133e2539156277808c3c0f4 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 17 Mar 2015 13:49:26 +0000 Subject: [PATCH 01/13] Replace hand parsing and validation of URLs with Gorilla mux --- nameserver/http.go | 121 ++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 67 deletions(-) diff --git a/nameserver/http.go b/nameserver/http.go index c028c28b..83fbbf0e 100644 --- a/nameserver/http.go +++ b/nameserver/http.go @@ -1,7 +1,6 @@ package nameserver import ( - "errors" "fmt" "github.com/miekg/dns" . "github.com/zettio/weave/common" @@ -9,18 +8,9 @@ import ( "log" "net" "net/http" - "strings" + "github.com/gorilla/mux" ) -// Parse a URL of the form PUT /name// -func parseUrl(url string) (identifier string, ipaddr string, err error) { - parts := strings.Split(url, "/") - if len(parts) != 4 { - return "", "", errors.New("Unable to parse url: " + url) - } - return parts[2], parts[3], nil -} - func httpErrorAndLog(level *log.Logger, w http.ResponseWriter, msg string, status int, logmsg string, logargs ...interface{}) { http.Error(w, msg, status) @@ -29,78 +19,75 @@ func httpErrorAndLog(level *log.Logger, w http.ResponseWriter, msg string, func ListenHttp(domain string, db Zone, port int) { - http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) { - if r.Method != "GET" { - http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) - } else { - io.WriteString(w, "ok") - } + router := mux.NewRouter() + + router.Methods("GET").Path("/status").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, "ok") }) - http.HandleFunc("/name/", func(w http.ResponseWriter, r *http.Request) { - + router.Methods("PUT").Path("/name/{identifier:.+}/{ip:.+}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { reqError := func(msg string, logmsg string, logargs ...interface{}) { - httpErrorAndLog(Warning, w, msg, http.StatusBadRequest, - logmsg, logargs...) + httpErrorAndLog(Warning, w, msg, http.StatusBadRequest, logmsg, logargs...) } - switch r.Method { - case "PUT": - ident, ipStr, err := parseUrl(r.URL.Path) - name := r.FormValue("fqdn") - if ident == "" || ipStr == "" || name == "" { - reqError("Invalid request", "Invalid request: %s, %s", r.URL, r.Form) - return - } + vars := mux.Vars(r) + ident := vars["identifier"] + ipStr := vars["ip"] + name := r.FormValue("fqdn") - ip := net.ParseIP(ipStr) - if ip == nil { - reqError("Invalid IP", "Invalid IP in request: %s", ipStr) - return - } + if name == "" { + reqError("Invalid FQDN", "Invalid FQDN in request: %s, %s", r.URL, r.Form) + return + } - if dns.IsSubDomain(domain, name) { - Info.Printf("[http] Adding %s -> %s", name, ipStr) - if err = db.AddRecord(ident, name, ip); err != nil { - if _, ok := err.(DuplicateError); !ok { - httpErrorAndLog( - Error, w, "Internal error", http.StatusInternalServerError, - "Unexpected error from DB: %s", err) - return - } // oh, I already know this. whatever. - } - } else { - Info.Printf("[http] Ignoring name %s, not in %s", name, domain) - } + ip := net.ParseIP(ipStr) + if ip == nil { + reqError("Invalid IP", "Invalid IP in request: %s", ipStr) + return + } - case "DELETE": - ident, ipStr, err := parseUrl(r.URL.Path) - if ident == "" || ipStr == "" { - reqError("Invalid Request", "Invalid request: %s, %s", r.URL, r.Form) - return - } - - ip := net.ParseIP(ipStr) - if ip == nil { - reqError("Invalid IP in request", "Invalid IP in request: %s", ipStr) - return - } - Info.Printf("[http] Deleting %s (%s)", ident, ipStr) - if err = db.DeleteRecord(ident, ip); err != nil { - if _, ok := err.(LookupError); !ok { + if dns.IsSubDomain(domain, name) { + Info.Printf("[http] Adding %s -> %s", name, ipStr) + if err := db.AddRecord(ident, name, ip); err != nil { + if _, ok := err.(DuplicateError); !ok { httpErrorAndLog( Error, w, "Internal error", http.StatusInternalServerError, "Unexpected error from DB: %s", err) return - } + } // oh, I already know this. whatever. } - default: - msg := "Unexpected http method: " + r.Method - reqError(msg, msg) - return + } else { + Info.Printf("[http] Ignoring name %s, not in %s", name, domain) } }) + router.Methods("DELETE").Path("/name/{identifier:.+}/{ip:.+}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + reqError := func(msg string, logmsg string, logargs ...interface{}) { + httpErrorAndLog(Warning, w, msg, http.StatusBadRequest, logmsg, logargs...) + } + + vars := mux.Vars(r) + ident := vars["identifier"] + ipStr := vars["ip"] + + ip := net.ParseIP(ipStr) + if ip == nil { + reqError("Invalid IP in request", "Invalid IP in request: %s", ipStr) + return + } + Info.Printf("[http] Deleting %s (%s)", ident, ipStr) + if err := db.DeleteRecord(ident, ip); err != nil { + if _, ok := err.(LookupError); !ok { + httpErrorAndLog( + Error, w, "Internal error", http.StatusInternalServerError, + "Unexpected error from DB: %s", err) + return + } + } + }) + + http.Handle("/", router) + address := fmt.Sprintf(":%d", port) if err := http.ListenAndServe(address, nil); err != nil { Error.Fatal("[http] Unable to create http listener: ", err) From 9cf7da7277726dbf540e457240a0cf603ee16d32 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 17 Mar 2015 14:03:18 +0000 Subject: [PATCH 02/13] Modify weave status to include DNS information --- weave | 1 + 1 file changed, 1 insertion(+) diff --git a/weave b/weave index 89763f0f..d9faa022 100755 --- a/weave +++ b/weave @@ -556,6 +556,7 @@ case "$COMMAND" in ;; status) http_call $CONTAINER_NAME $HTTP_PORT GET /status + http_call $DNS_CONTAINER_NAME $DNS_HTTP_PORT GET /status ;; ps) [ $# -eq 0 ] || usage From 50f6402774bbff5b60a882bf34a481ee1a49543e Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 17 Mar 2015 14:28:26 +0000 Subject: [PATCH 03/13] Include DNS version and domain in status --- nameserver/http.go | 5 +++-- weavedns/main.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/nameserver/http.go b/nameserver/http.go index 83fbbf0e..5e3e7181 100644 --- a/nameserver/http.go +++ b/nameserver/http.go @@ -17,12 +17,13 @@ func httpErrorAndLog(level *log.Logger, w http.ResponseWriter, msg string, level.Printf("[http] "+logmsg, logargs...) } -func ListenHttp(domain string, db Zone, port int) { +func ListenHttp(version string, domain string, db Zone, port int) { router := mux.NewRouter() router.Methods("GET").Path("/status").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - io.WriteString(w, "ok") + io.WriteString(w, fmt.Sprintln("weave DNS", version)) + io.WriteString(w, fmt.Sprintln("Serving domain", domain)) }) router.Methods("PUT").Path("/name/{identifier:.+}/{ip:.+}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/weavedns/main.go b/weavedns/main.go index 46560467..9e1fd2fb 100644 --- a/weavedns/main.go +++ b/weavedns/main.go @@ -83,7 +83,7 @@ func main() { Debug.Printf("DNS fallback at %s:%s", fallbackHost, fallbackPort) } - go weavedns.ListenHttp(localDomain, zone, httpPort) + go weavedns.ListenHttp(version, localDomain, zone, httpPort) srv, err := weavedns.NewDNSServer(srvConfig, zone, iface) if err != nil { Error.Fatal("Failed to initialize the WeaveDNS server", err) From 6f57774d15164ac6120bb6ca208dd9026e5e78dd Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 17 Mar 2015 15:02:09 +0000 Subject: [PATCH 04/13] Include zone records in status --- nameserver/http.go | 1 + nameserver/zone.go | 14 ++++++++++++++ weave | 1 + 3 files changed, 16 insertions(+) diff --git a/nameserver/http.go b/nameserver/http.go index 5e3e7181..a21a1b7c 100644 --- a/nameserver/http.go +++ b/nameserver/http.go @@ -24,6 +24,7 @@ func ListenHttp(version string, domain string, db Zone, port int) { router.Methods("GET").Path("/status").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { io.WriteString(w, fmt.Sprintln("weave DNS", version)) io.WriteString(w, fmt.Sprintln("Serving domain", domain)) + io.WriteString(w, db.Status()) }) router.Methods("PUT").Path("/name/{identifier:.+}/{ip:.+}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/nameserver/zone.go b/nameserver/zone.go index ae07eb88..cbec126d 100644 --- a/nameserver/zone.go +++ b/nameserver/zone.go @@ -5,6 +5,8 @@ import ( . "github.com/zettio/weave/common" "net" "sync" + "bytes" + "fmt" ) const ( @@ -20,6 +22,7 @@ type Lookup interface { } type Zone interface { + Status() string AddRecord(ident string, name string, ip net.IP) error DeleteRecord(ident string, ip net.IP) error DeleteRecordsFor(ident string) error @@ -61,6 +64,17 @@ func (zone *ZoneDb) indexOf(match func(Record) bool) int { return -1 } +func (zone *ZoneDb) Status() string { + zone.mx.RLock() + defer zone.mx.RUnlock() + var buf bytes.Buffer + buf.WriteString("Records:\n") + for _, r := range zone.recs { + buf.WriteString(fmt.Sprintf("%s %s %v\n", r.Ident, r.IP, r.Name)) + } + return buf.String() +} + func (zone *ZoneDb) LookupName(name string) (net.IP, error) { zone.mx.RLock() defer zone.mx.RUnlock() diff --git a/weave b/weave index d9faa022..ef606e5b 100755 --- a/weave +++ b/weave @@ -556,6 +556,7 @@ case "$COMMAND" in ;; status) http_call $CONTAINER_NAME $HTTP_PORT GET /status + echo http_call $DNS_CONTAINER_NAME $DNS_HTTP_PORT GET /status ;; ps) From c36543a247b230bb2508740d9ddd50ce784f4f19 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 17 Mar 2015 15:41:01 +0000 Subject: [PATCH 05/13] Include DNS server config in status --- nameserver/http.go | 9 ++++----- nameserver/server.go | 12 ++++++++++++ nameserver/zone.go | 4 +--- weavedns/main.go | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/nameserver/http.go b/nameserver/http.go index a21a1b7c..5f22f5a7 100644 --- a/nameserver/http.go +++ b/nameserver/http.go @@ -17,14 +17,13 @@ func httpErrorAndLog(level *log.Logger, w http.ResponseWriter, msg string, level.Printf("[http] "+logmsg, logargs...) } -func ListenHttp(version string, domain string, db Zone, port int) { +func ListenHttp(version string, server *DNSServer, db Zone, port int) { router := mux.NewRouter() router.Methods("GET").Path("/status").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { io.WriteString(w, fmt.Sprintln("weave DNS", version)) - io.WriteString(w, fmt.Sprintln("Serving domain", domain)) - io.WriteString(w, db.Status()) + io.WriteString(w, server.Status()) }) router.Methods("PUT").Path("/name/{identifier:.+}/{ip:.+}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -48,7 +47,7 @@ func ListenHttp(version string, domain string, db Zone, port int) { return } - if dns.IsSubDomain(domain, name) { + if dns.IsSubDomain(server.Domain, name) { Info.Printf("[http] Adding %s -> %s", name, ipStr) if err := db.AddRecord(ident, name, ip); err != nil { if _, ok := err.(DuplicateError); !ok { @@ -59,7 +58,7 @@ func ListenHttp(version string, domain string, db Zone, port int) { } // oh, I already know this. whatever. } } else { - Info.Printf("[http] Ignoring name %s, not in %s", name, domain) + Info.Printf("[http] Ignoring name %s, not in %s", name, server.Domain) } }) diff --git a/nameserver/server.go b/nameserver/server.go index 8b5bb7f7..1c1647b4 100644 --- a/nameserver/server.go +++ b/nameserver/server.go @@ -6,6 +6,7 @@ import ( . "github.com/zettio/weave/common" "net" "sync" + "bytes" ) const ( @@ -142,6 +143,17 @@ func (s *DNSServer) Start() error { return nil } +// Return status string +func (s *DNSServer) Status() string { + var buf bytes.Buffer + buf.WriteString(fmt.Sprintln("Local domain", s.Domain)) + buf.WriteString(fmt.Sprintln("Listen address", s.ListenAddr)) + buf.WriteString(fmt.Sprintln("mDNS interface", s.iface)) + buf.WriteString(fmt.Sprintln("Fallback DNS config", s.upstream)) + buf.WriteString(fmt.Sprintf("Zone database:\n%s", s.zone)) + return buf.String() +} + // Perform a graceful shutdown func (s *DNSServer) Stop() error { if err := s.tcpSrv.Shutdown(); err != nil { diff --git a/nameserver/zone.go b/nameserver/zone.go index cbec126d..61755f3e 100644 --- a/nameserver/zone.go +++ b/nameserver/zone.go @@ -22,7 +22,6 @@ type Lookup interface { } type Zone interface { - Status() string AddRecord(ident string, name string, ip net.IP) error DeleteRecord(ident string, ip net.IP) error DeleteRecordsFor(ident string) error @@ -64,11 +63,10 @@ func (zone *ZoneDb) indexOf(match func(Record) bool) int { return -1 } -func (zone *ZoneDb) Status() string { +func (zone *ZoneDb) String() string { zone.mx.RLock() defer zone.mx.RUnlock() var buf bytes.Buffer - buf.WriteString("Records:\n") for _, r := range zone.recs { buf.WriteString(fmt.Sprintf("%s %s %v\n", r.Ident, r.IP, r.Name)) } diff --git a/weavedns/main.go b/weavedns/main.go index 9e1fd2fb..62ea0f67 100644 --- a/weavedns/main.go +++ b/weavedns/main.go @@ -83,11 +83,11 @@ func main() { Debug.Printf("DNS fallback at %s:%s", fallbackHost, fallbackPort) } - go weavedns.ListenHttp(version, localDomain, zone, httpPort) srv, err := weavedns.NewDNSServer(srvConfig, zone, iface) if err != nil { Error.Fatal("Failed to initialize the WeaveDNS server", err) } + go weavedns.ListenHttp(version, srv, zone, httpPort) err = srv.Start() if err != nil { Error.Fatal("Failed to start the WeaveDNS server", err) From 0f492b563e144ed0119802856a9db21e1a92589e Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 17 Mar 2015 17:42:16 +0000 Subject: [PATCH 06/13] Fix test compilation Tests weren't compiling due to change of ListenHttp() signature. Fixed for now by reintroducing domain parameter in addition to server, as this allows the HTTP tests to pass in a nil server parameter. In the long term DNSServer should probably become an interface so we can mock it easily in such a scenario. --- nameserver/http.go | 6 +++--- nameserver/http_test.go | 2 +- weavedns/main.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nameserver/http.go b/nameserver/http.go index 5f22f5a7..d4a4d4c1 100644 --- a/nameserver/http.go +++ b/nameserver/http.go @@ -17,7 +17,7 @@ func httpErrorAndLog(level *log.Logger, w http.ResponseWriter, msg string, level.Printf("[http] "+logmsg, logargs...) } -func ListenHttp(version string, server *DNSServer, db Zone, port int) { +func ListenHttp(version string, server *DNSServer, domain string, db Zone, port int) { router := mux.NewRouter() @@ -47,7 +47,7 @@ func ListenHttp(version string, server *DNSServer, db Zone, port int) { return } - if dns.IsSubDomain(server.Domain, name) { + if dns.IsSubDomain(domain, name) { Info.Printf("[http] Adding %s -> %s", name, ipStr) if err := db.AddRecord(ident, name, ip); err != nil { if _, ok := err.(DuplicateError); !ok { @@ -58,7 +58,7 @@ func ListenHttp(version string, server *DNSServer, db Zone, port int) { } // oh, I already know this. whatever. } } else { - Info.Printf("[http] Ignoring name %s, not in %s", name, server.Domain) + Info.Printf("[http] Ignoring name %s, not in %s", name, domain) } }) diff --git a/nameserver/http_test.go b/nameserver/http_test.go index fd613861..6a72b6c6 100644 --- a/nameserver/http_test.go +++ b/nameserver/http_test.go @@ -30,7 +30,7 @@ func TestHttp(t *testing.T) { var zone = new(ZoneDb) port := rand.Intn(10000) + 32768 fmt.Println("Http test on port", port) - go ListenHttp(testDomain, zone, port) + go ListenHttp("", nil, testDomain, zone, port) time.Sleep(100 * time.Millisecond) // Allow for http server to get going diff --git a/weavedns/main.go b/weavedns/main.go index 62ea0f67..53ddd987 100644 --- a/weavedns/main.go +++ b/weavedns/main.go @@ -87,7 +87,7 @@ func main() { if err != nil { Error.Fatal("Failed to initialize the WeaveDNS server", err) } - go weavedns.ListenHttp(version, srv, zone, httpPort) + go weavedns.ListenHttp(version, srv, localDomain, zone, httpPort) err = srv.Start() if err != nil { Error.Fatal("Failed to start the WeaveDNS server", err) From 8f675f15c0b513347fd2e215478769307265be6a Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Tue, 17 Mar 2015 17:52:39 +0000 Subject: [PATCH 07/13] Revert Gorilla mux introduction --- nameserver/http.go | 121 +++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 54 deletions(-) diff --git a/nameserver/http.go b/nameserver/http.go index d4a4d4c1..0427e79c 100644 --- a/nameserver/http.go +++ b/nameserver/http.go @@ -1,6 +1,7 @@ package nameserver import ( + "errors" "fmt" "github.com/miekg/dns" . "github.com/zettio/weave/common" @@ -8,9 +9,18 @@ import ( "log" "net" "net/http" - "github.com/gorilla/mux" + "strings" ) +// Parse a URL of the form PUT /name// +func parseUrl(url string) (identifier string, ipaddr string, err error) { + parts := strings.Split(url, "/") + if len(parts) != 4 { + return "", "", errors.New("Unable to parse url: " + url) + } + return parts[2], parts[3], nil +} + func httpErrorAndLog(level *log.Logger, w http.ResponseWriter, msg string, status int, logmsg string, logargs ...interface{}) { http.Error(w, msg, status) @@ -19,76 +29,79 @@ func httpErrorAndLog(level *log.Logger, w http.ResponseWriter, msg string, func ListenHttp(version string, server *DNSServer, domain string, db Zone, port int) { - router := mux.NewRouter() - - router.Methods("GET").Path("/status").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - io.WriteString(w, fmt.Sprintln("weave DNS", version)) - io.WriteString(w, server.Status()) + http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) { + if r.Method != "GET" { + http.Error(w, "Method not allowed", http.StatusMethodNotAllowed) + } else { + io.WriteString(w, fmt.Sprintln("weave DNS", version)) + io.WriteString(w, server.Status()) + } }) - router.Methods("PUT").Path("/name/{identifier:.+}/{ip:.+}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + http.HandleFunc("/name/", func(w http.ResponseWriter, r *http.Request) { + reqError := func(msg string, logmsg string, logargs ...interface{}) { - httpErrorAndLog(Warning, w, msg, http.StatusBadRequest, logmsg, logargs...) + httpErrorAndLog(Warning, w, msg, http.StatusBadRequest, + logmsg, logargs...) } - vars := mux.Vars(r) - ident := vars["identifier"] - ipStr := vars["ip"] - name := r.FormValue("fqdn") + switch r.Method { + case "PUT": + ident, ipStr, err := parseUrl(r.URL.Path) + name := r.FormValue("fqdn") + if ident == "" || ipStr == "" || name == "" { + reqError("Invalid request", "Invalid request: %s, %s", r.URL, r.Form) + return + } - if name == "" { - reqError("Invalid FQDN", "Invalid FQDN in request: %s, %s", r.URL, r.Form) - return - } + ip := net.ParseIP(ipStr) + if ip == nil { + reqError("Invalid IP", "Invalid IP in request: %s", ipStr) + return + } - ip := net.ParseIP(ipStr) - if ip == nil { - reqError("Invalid IP", "Invalid IP in request: %s", ipStr) - return - } + if dns.IsSubDomain(domain, name) { + Info.Printf("[http] Adding %s -> %s", name, ipStr) + if err = db.AddRecord(ident, name, ip); err != nil { + if _, ok := err.(DuplicateError); !ok { + httpErrorAndLog( + Error, w, "Internal error", http.StatusInternalServerError, + "Unexpected error from DB: %s", err) + return + } // oh, I already know this. whatever. + } + } else { + Info.Printf("[http] Ignoring name %s, not in %s", name, domain) + } - if dns.IsSubDomain(domain, name) { - Info.Printf("[http] Adding %s -> %s", name, ipStr) - if err := db.AddRecord(ident, name, ip); err != nil { - if _, ok := err.(DuplicateError); !ok { + case "DELETE": + ident, ipStr, err := parseUrl(r.URL.Path) + if ident == "" || ipStr == "" { + reqError("Invalid Request", "Invalid request: %s, %s", r.URL, r.Form) + return + } + + ip := net.ParseIP(ipStr) + if ip == nil { + reqError("Invalid IP in request", "Invalid IP in request: %s", ipStr) + return + } + Info.Printf("[http] Deleting %s (%s)", ident, ipStr) + if err = db.DeleteRecord(ident, ip); err != nil { + if _, ok := err.(LookupError); !ok { httpErrorAndLog( Error, w, "Internal error", http.StatusInternalServerError, "Unexpected error from DB: %s", err) return - } // oh, I already know this. whatever. + } } - } else { - Info.Printf("[http] Ignoring name %s, not in %s", name, domain) - } - }) - - router.Methods("DELETE").Path("/name/{identifier:.+}/{ip:.+}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - reqError := func(msg string, logmsg string, logargs ...interface{}) { - httpErrorAndLog(Warning, w, msg, http.StatusBadRequest, logmsg, logargs...) - } - - vars := mux.Vars(r) - ident := vars["identifier"] - ipStr := vars["ip"] - - ip := net.ParseIP(ipStr) - if ip == nil { - reqError("Invalid IP in request", "Invalid IP in request: %s", ipStr) + default: + msg := "Unexpected http method: " + r.Method + reqError(msg, msg) return } - Info.Printf("[http] Deleting %s (%s)", ident, ipStr) - if err := db.DeleteRecord(ident, ip); err != nil { - if _, ok := err.(LookupError); !ok { - httpErrorAndLog( - Error, w, "Internal error", http.StatusInternalServerError, - "Unexpected error from DB: %s", err) - return - } - } }) - http.Handle("/", router) - address := fmt.Sprintf(":%d", port) if err := http.ListenAndServe(address, nil); err != nil { Error.Fatal("[http] Unable to create http listener: ", err) From 0aa36cf8d0c4300df22e0461eabaa0f7e92ce65b Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Wed, 18 Mar 2015 13:04:45 +0000 Subject: [PATCH 08/13] Try to get weaveDNS status even if router container is missing --- weave | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/weave b/weave index ef606e5b..4f344e5a 100755 --- a/weave +++ b/weave @@ -555,7 +555,7 @@ case "$COMMAND" in http_call $CONTAINER_NAME $HTTP_PORT POST /connect -d "peer=$1" ;; status) - http_call $CONTAINER_NAME $HTTP_PORT GET /status + http_call $CONTAINER_NAME $HTTP_PORT GET /status || true echo http_call $DNS_CONTAINER_NAME $DNS_HTTP_PORT GET /status ;; From 66f4fd94e3f538e41295c6dc6be4f717527bc122 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Wed, 18 Mar 2015 13:09:11 +0000 Subject: [PATCH 09/13] Update documentation --- site/troubleshooting.md | 11 +++++++-- weavedns/README.md | 55 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/site/troubleshooting.md b/site/troubleshooting.md index ef6f07af..b1cec0e3 100644 --- a/site/troubleshooting.md +++ b/site/troubleshooting.md @@ -51,7 +51,7 @@ The command weave status -reports on the current status of the weave router. +reports on the current status of the weave router and DNS. This produces output like: @@ -80,6 +80,8 @@ broadcast: 7a:16:dd:5b:83:de -> [] Reconnects: 192.168.32.1:6783 (next try at 2014-10-23 16:39:50.585932102 +0000 UTC) + +weavedns container is not present; have you launched it? ```` The terms used here are explained further at @@ -117,11 +119,16 @@ weave network is not fully connected. See the [architecture documentation](https://raw.githubusercontent.com/zettio/weave/master/docs/architecture.txt) for a full explanation. -Finally, 'Reconnects' lists peers that this router is aware of, but is +The 'Reconnects' section lists peers that this router is aware of, but is not currently connected to. Each line contains some information about whether it is attempting to connect or is waiting for a while before connecting again. +Finally, status information from weave DNS is included. In this example, +the DNS container has not been launched so no status information is +available (see the [WeaveDNS README](https://github.com/zettio/weave/blob/master/weavedns/README.md) +for more information). + ### List attached containers weave ps diff --git a/weavedns/README.md b/weavedns/README.md index e27f3b23..d24e7a05 100644 --- a/weavedns/README.md +++ b/weavedns/README.md @@ -177,6 +177,61 @@ $ dns_ip=$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' weavedns) $ curl -X DELETE "http://$dns_ip:6785/name/$shell2/10.2.1.27" ``` +## Troubleshooting + +The command + + weave status + +reports on the current status of the weave router and DNS: + +```` +weave router git-8f675f15c0b5 +Encryption off +Our name is 7a:17:ee:72:ef:9c (ubuntu-14) +Sniffing traffic on &{42 65535 ethwe 36:59:20:e5:a4:64 up|broadcast|multicast} +MACs: +32:ff:76:23:d3:f1 -> 7a:17:ee:72:ef:9c (2015-03-18 12:52:37.329938912 +0000 UTC) +36:59:20:e5:a4:64 -> 7a:17:ee:72:ef:9c (2015-03-18 12:52:36.495276933 +0000 UTC) +Peers: +Peer 7a:17:ee:72:ef:9c (ubuntu-14) (v0) (UID 11664962155092689251) +Routes: +unicast: +7a:17:ee:72:ef:9c -> 00:00:00:00:00:00 +broadcast: +7a:17:ee:72:ef:9c -> [] +Reconnects: + +weave DNS git-8f675f15c0b5 +Local domain weave.local. +Listen address :53 +mDNS interface &{26 65535 ethwe fa:b6:b1:85:ac:9b up|broadcast|multicast} +Fallback DNS config &{[66.28.0.45 8.8.8.8] [] 53 1 5 2} +Zone database: +710978857a888f3d9a126452bf58db12d3aeb4f6bf7f076eb639bc714aaa1f4b 10.2.1.26 wiff.weave.local. +e8d85b1dcdb15053c8ca5a747812a886125a9150b060a66b66fe7d18ecdad762 10.2.1.27 waff.weave.local. +26bd05f9a0cbef1d57425562126a725383027a23f7368518ad5162e1cb958c17 10.2.1.28 ping.weave.local. +1ab0e8b17c391733057a1abdfd2c7842c15b415775571402c328d2735a46e323 10.2.1.29 pong.weave.local. +```` + +The first section covers the router; see the troubleshooting guide in +the main documentation for more detail. + +The second section is pertinent to weaveDNS, and includes: + +* The local domain suffix which is being served +* The address on which the DNS server is listening +* The interface being used for multicast DNS +* The fallback DNS which will be used to resolve non local names +* The names known to this host's DNS server. Each entry comprises the container ID, IP address and it's fully qualified domain name + +In the case where weaveDNS has not been launched, the second section of `weave status` +will report the following: + +```` +weavedns container is not present; have you launched it? +```` + ## Present limitations * The server will not know about restarted containers, but if you From 0005715b1ad80f5a6647427bdf83229a7efd5638 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Wed, 18 Mar 2015 14:49:48 +0000 Subject: [PATCH 10/13] Weave status only returns success if both router and DNS are up --- weave | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/weave b/weave index 4f344e5a..a33bc111 100755 --- a/weave +++ b/weave @@ -555,9 +555,10 @@ case "$COMMAND" in http_call $CONTAINER_NAME $HTTP_PORT POST /connect -d "peer=$1" ;; status) - http_call $CONTAINER_NAME $HTTP_PORT GET /status || true + if http_call $CONTAINER_NAME $HTTP_PORT GET /status; then ROUTER_UP=true; else ROUTER_UP=false; fi echo - http_call $DNS_CONTAINER_NAME $DNS_HTTP_PORT GET /status + if http_call $DNS_CONTAINER_NAME $DNS_HTTP_PORT GET /status; then DNS_UP=true; else DNS_UP=false; fi + $ROUTER_UP && $DNS_UP ;; ps) [ $# -eq 0 ] || usage From 6c5dbe0d0180bd618c269efb1f93e2683d311f7f Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Wed, 18 Mar 2015 14:57:29 +0000 Subject: [PATCH 11/13] Address documentation comments --- weavedns/README.md | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/weavedns/README.md b/weavedns/README.md index d24e7a05..054cc3a9 100644 --- a/weavedns/README.md +++ b/weavedns/README.md @@ -187,20 +187,7 @@ reports on the current status of the weave router and DNS: ```` weave router git-8f675f15c0b5 -Encryption off -Our name is 7a:17:ee:72:ef:9c (ubuntu-14) -Sniffing traffic on &{42 65535 ethwe 36:59:20:e5:a4:64 up|broadcast|multicast} -MACs: -32:ff:76:23:d3:f1 -> 7a:17:ee:72:ef:9c (2015-03-18 12:52:37.329938912 +0000 UTC) -36:59:20:e5:a4:64 -> 7a:17:ee:72:ef:9c (2015-03-18 12:52:36.495276933 +0000 UTC) -Peers: -Peer 7a:17:ee:72:ef:9c (ubuntu-14) (v0) (UID 11664962155092689251) -Routes: -unicast: -7a:17:ee:72:ef:9c -> 00:00:00:00:00:00 -broadcast: -7a:17:ee:72:ef:9c -> [] -Reconnects: +... weave DNS git-8f675f15c0b5 Local domain weave.local. @@ -223,14 +210,7 @@ The second section is pertinent to weaveDNS, and includes: * The address on which the DNS server is listening * The interface being used for multicast DNS * The fallback DNS which will be used to resolve non local names -* The names known to this host's DNS server. Each entry comprises the container ID, IP address and it's fully qualified domain name - -In the case where weaveDNS has not been launched, the second section of `weave status` -will report the following: - -```` -weavedns container is not present; have you launched it? -```` +* The names known to the local weaveDNS server. Each entry comprises the container ID, IP address and its fully qualified domain name ## Present limitations From 2e7c281b46846c4b5203ac6c83cf2683685928ad Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Wed, 18 Mar 2015 16:46:51 +0000 Subject: [PATCH 12/13] Weave status returns success irrespective of whether router or DNS up --- weave | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/weave b/weave index a33bc111..e73058f1 100755 --- a/weave +++ b/weave @@ -555,10 +555,9 @@ case "$COMMAND" in http_call $CONTAINER_NAME $HTTP_PORT POST /connect -d "peer=$1" ;; status) - if http_call $CONTAINER_NAME $HTTP_PORT GET /status; then ROUTER_UP=true; else ROUTER_UP=false; fi + http_call $CONTAINER_NAME $HTTP_PORT GET /status || true echo - if http_call $DNS_CONTAINER_NAME $DNS_HTTP_PORT GET /status; then DNS_UP=true; else DNS_UP=false; fi - $ROUTER_UP && $DNS_UP + http_call $DNS_CONTAINER_NAME $DNS_HTTP_PORT GET /status || true ;; ps) [ $# -eq 0 ] || usage From fcab4ee2392de2f52dffc1197fe569eeb92a4d8c Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Wed, 18 Mar 2015 17:56:58 +0000 Subject: [PATCH 13/13] Truncate container IDs to twelve characters --- nameserver/zone.go | 2 +- weavedns/README.md | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nameserver/zone.go b/nameserver/zone.go index 61755f3e..f4c78149 100644 --- a/nameserver/zone.go +++ b/nameserver/zone.go @@ -68,7 +68,7 @@ func (zone *ZoneDb) String() string { defer zone.mx.RUnlock() var buf bytes.Buffer for _, r := range zone.recs { - buf.WriteString(fmt.Sprintf("%s %s %v\n", r.Ident, r.IP, r.Name)) + buf.WriteString(fmt.Sprintf("%.12s %s %v\n", r.Ident, r.IP, r.Name)) } return buf.String() } diff --git a/weavedns/README.md b/weavedns/README.md index 054cc3a9..90b2bd86 100644 --- a/weavedns/README.md +++ b/weavedns/README.md @@ -195,10 +195,10 @@ Listen address :53 mDNS interface &{26 65535 ethwe fa:b6:b1:85:ac:9b up|broadcast|multicast} Fallback DNS config &{[66.28.0.45 8.8.8.8] [] 53 1 5 2} Zone database: -710978857a888f3d9a126452bf58db12d3aeb4f6bf7f076eb639bc714aaa1f4b 10.2.1.26 wiff.weave.local. -e8d85b1dcdb15053c8ca5a747812a886125a9150b060a66b66fe7d18ecdad762 10.2.1.27 waff.weave.local. -26bd05f9a0cbef1d57425562126a725383027a23f7368518ad5162e1cb958c17 10.2.1.28 ping.weave.local. -1ab0e8b17c391733057a1abdfd2c7842c15b415775571402c328d2735a46e323 10.2.1.29 pong.weave.local. +710978857a88 10.2.1.26 wiff.weave.local. +e8d85b1dcdb1 10.2.1.27 waff.weave.local. +26bd05f9a0cb 10.2.1.28 ping.weave.local. +1ab0e8b17c39 10.2.1.29 pong.weave.local. ```` The first section covers the router; see the troubleshooting guide in