diff --git a/nameserver/cache.go b/nameserver/cache.go index 96be41dc..c65824ed 100644 --- a/nameserver/cache.go +++ b/nameserver/cache.go @@ -22,8 +22,6 @@ var ( ) const ( - DefaultCacheNegLocalTTL = 30 // Default TTL for negative local resolutions - defPendingTimeout int = 5 // timeout for a resolution ) diff --git a/nameserver/cache_test.go b/nameserver/cache_test.go index 492438bb..5182fcca 100644 --- a/nameserver/cache_test.go +++ b/nameserver/cache_test.go @@ -196,26 +196,26 @@ func TestCacheEntries(t *testing.T) { question3 := &questionMsg3.Question[0] t.Logf("Checking that a entry with CacheNoLocalReplies return an error") - l.Put(questionMsg3, nil, DefaultCacheNegLocalTTL, CacheNoLocalReplies) + l.Put(questionMsg3, nil, DefaultLocalTTL, CacheNoLocalReplies) resp, err = l.Get(questionMsg3, minUDPSize) wt.AssertNil(t, resp, "Get() response with CacheNoLocalReplies") wt.AssertTrue(t, err == errNoLocalReplies, "Get() error with CacheNoLocalReplies") t.Logf("Checking that more Put's do not make the negative TTL longer") - clk.Add(time.Duration(DefaultCacheNegLocalTTL/2) * time.Second) - l.Put(questionMsg3, nil, DefaultCacheNegLocalTTL, CacheNoLocalReplies) + clk.Add(time.Duration(DefaultLocalTTL/2) * time.Second) + l.Put(questionMsg3, nil, DefaultLocalTTL, CacheNoLocalReplies) clk.Add(time.Duration(1) * time.Second) - l.Put(questionMsg3, nil, DefaultCacheNegLocalTTL, CacheNoLocalReplies) + l.Put(questionMsg3, nil, DefaultLocalTTL, CacheNoLocalReplies) clk.Add(time.Duration(1) * time.Second) - l.Put(questionMsg3, nil, DefaultCacheNegLocalTTL, CacheNoLocalReplies) + l.Put(questionMsg3, nil, DefaultLocalTTL, CacheNoLocalReplies) resp, err = l.Get(questionMsg3, minUDPSize) wt.AssertNil(t, resp, "Get() response with CacheNoLocalReplies") wt.AssertTrue(t, err == errNoLocalReplies, "Get() error with CacheNoLocalReplies") - clk.Add(time.Duration(DefaultCacheNegLocalTTL/2) * time.Second) - t.Logf("Checking that we get an expired response after %f seconds", DefaultCacheNegLocalTTL) - clk.Add(time.Second * time.Duration(DefaultCacheNegLocalTTL+1)) - t.Logf("Checking that we get an expired response after %d seconds", DefaultCacheNegLocalTTL) + clk.Add(time.Duration(DefaultLocalTTL/2) * time.Second) + t.Logf("Checking that we get an expired response after %f seconds", DefaultLocalTTL) + clk.Add(time.Second * time.Duration(DefaultLocalTTL+1)) + t.Logf("Checking that we get an expired response after %d seconds", DefaultLocalTTL) resp, err = l.Get(questionMsg3, minUDPSize) wt.AssertNil(t, resp, "expired Get() response with CacheNoLocalReplies") wt.AssertNil(t, err, "expired Get() error with CacheNoLocalReplies") diff --git a/nameserver/server.go b/nameserver/server.go index 194a2eb4..336b863f 100644 --- a/nameserver/server.go +++ b/nameserver/server.go @@ -45,7 +45,7 @@ type DNSServerConfig struct { Cache ZoneCache // (Optional) TTL for local domain responses LocalTTL int - // (Optional) TTL for negative results in the local domain + // (Optional) TTL for negative results in the local domain (defaults to LocalTTL) CacheNegLocalTTL int // (Optional) for a specific clock provider Clock clock.Clock @@ -120,7 +120,6 @@ func NewDNSServer(config DNSServerConfig) (s *DNSServer, err error) { cacheDisabled: false, maxAnswers: DefaultMaxAnswers, localTTL: DefaultLocalTTL, - negLocalTTL: DefaultCacheNegLocalTTL, clock: config.Clock, } @@ -164,6 +163,8 @@ func NewDNSServer(config DNSServerConfig) (s *DNSServer, err error) { } if config.CacheNegLocalTTL > 0 { s.negLocalTTL = config.CacheNegLocalTTL + } else { + s.negLocalTTL = s.localTTL } if config.CacheDisabled { s.cacheDisabled = true diff --git a/prog/weavedns/main.go b/prog/weavedns/main.go index 85878e6a..e915905c 100644 --- a/prog/weavedns/main.go +++ b/prog/weavedns/main.go @@ -5,13 +5,13 @@ import ( "fmt" "net" "os" + "strconv" "github.com/miekg/dns" . "github.com/weaveworks/weave/common" "github.com/weaveworks/weave/common/docker" weavedns "github.com/weaveworks/weave/nameserver" weavenet "github.com/weaveworks/weave/net" - "strconv" ) var version = "(unreleased version)" @@ -55,7 +55,7 @@ func main() { flag.BoolVar(&watch, "watch", true, "watch the docker socket for container events") flag.BoolVar(&debug, "debug", false, "output debugging info to stderr") // advanced options - flag.IntVar(&negTTL, "neg-ttl", weavedns.DefaultCacheNegLocalTTL, "negative TTL (in secs) for unanswered queries for local names") + flag.IntVar(&negTTL, "neg-ttl", 0, "negative TTL (in secs) for unanswered queries for local names") flag.IntVar(&refreshInterval, "refresh", weavedns.DefaultRefreshInterval, "refresh interval (in secs) for local names (0=disable)") flag.IntVar(&maxAnswers, "max-answers", weavedns.DefaultMaxAnswers, "maximum number of answers returned to clients (0=unlimited)") flag.IntVar(&relevantTime, "relevant", weavedns.DefaultRelevantTime, "life time for info in the absence of queries (in secs)")