diff --git a/nameserver/http.go b/nameserver/http.go index 19a6534a..f5d5bafe 100644 --- a/nameserver/http.go +++ b/nameserver/http.go @@ -57,32 +57,32 @@ func ServeHTTP(listener net.Listener, version string, server *DNSServer, dockerC } domain := server.Zone.Domain() - if dns.IsSubDomain(domain, name) { - Info.Printf("[http] Adding %s -> %s", name, ipStr) - if err := server.Zone.AddRecord(idStr, 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. - } - - if dockerCli != nil { - if !docker.IsContainerID(idStr) { - Debug.Printf("[http] '%s' does not seem a container id", idStr) - return - } - - if running, err := dockerCli.IsContainerRunning(idStr); err != nil { - Error.Printf("[http] Could not check container status: %s", err) - } else if !running { - Info.Printf("[http] '%s' is not running: removing", idStr) - server.Zone.DeleteRecords(idStr, name, ip) - } - } - } else { + if !dns.IsSubDomain(domain, name) { Info.Printf("[http] Ignoring name %s, not in %s", name, domain) + return + } + Info.Printf("[http] Adding %s -> %s", name, ipStr) + if err := server.Zone.AddRecord(idStr, 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. + } + + if dockerCli != nil { + if !docker.IsContainerID(idStr) { + Debug.Printf("[http] '%s' does not seem to be a container id", idStr) + return + } + + if running, err := dockerCli.IsContainerRunning(idStr); err != nil { + Error.Printf("[http] Could not check container status: %s", err) + } else if !running { + Info.Printf("[http] '%s' is not running: removing", idStr) + server.Zone.DeleteRecords(idStr, name, ip) + } } })