From a805e17b9c9ecb7f4841c9c56957eedbe8e73e03 Mon Sep 17 00:00:00 2001 From: Alex Wheeler Date: Tue, 30 Sep 2014 15:15:36 -0400 Subject: [PATCH 1/2] Adding support for enabling the DNS truncate flag for UDP queries. --- command/agent/config.go | 10 ++++++++++ command/agent/dns.go | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/command/agent/config.go b/command/agent/config.go index c9a47fa2d..929ed012b 100644 --- a/command/agent/config.go +++ b/command/agent/config.go @@ -58,6 +58,13 @@ type DNSConfig struct { // only the leader. AllowStale bool `mapstructure:"allow_stale"` + // EnableTruncate is used to enable setting the truncate + // flag for UDP DNS queries. This allows unmodified + // clients to re-query the consul server using TCP + // when the total number of records exceeds the number + // returned by default for UDP. + EnableTruncate bool `mapstructure:"enable_truncate"` + // MaxStale is used to bound how stale of a result is // accepted for a DNS lookup. This can be used with // AllowStale to limit how old of a value is served up. @@ -688,6 +695,9 @@ func MergeConfig(a, b *Config) *Config { if b.DNSConfig.AllowStale { result.DNSConfig.AllowStale = true } + if b.DNSConfig.EnableTruncate { + result.DNSConfig.EnableTruncate = true + } if b.DNSConfig.MaxStale != 0 { result.DNSConfig.MaxStale = b.DNSConfig.MaxStale } diff --git a/command/agent/dns.go b/command/agent/dns.go index 18e2b928b..8a1522f75 100644 --- a/command/agent/dns.go +++ b/command/agent/dns.go @@ -471,6 +471,10 @@ RPC: // If the network is not TCP, restrict the number of responses if network != "tcp" && len(out.Nodes) > maxServiceResponses { out.Nodes = out.Nodes[:maxServiceResponses] + // Flag that there are more records to return in the UDP response + if d.config.EnableTruncate == true { + resp.Truncated = true + } } // Add various responses depending on the request From 5917aa0e20bdd496df95036a3d1ce1f38ec60ff0 Mon Sep 17 00:00:00 2001 From: Alex Wheeler Date: Tue, 30 Sep 2014 15:31:28 -0400 Subject: [PATCH 2/2] Added the dns_config option enable_truncate to the docs. --- website/source/docs/agent/options.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/website/source/docs/agent/options.html.markdown b/website/source/docs/agent/options.html.markdown index 077fe6472..d24e2b077 100644 --- a/website/source/docs/agent/options.html.markdown +++ b/website/source/docs/agent/options.html.markdown @@ -266,6 +266,10 @@ definitions support being updated during a reload. there is no specific policy available for a service. By default, all services are served with a 0 TTL value. Setting this enables DNS caching. + * `enable_truncate` - If set to true, a UDP DNS query that would return more than 3 records + will set the truncated flag, indicating to clients that they should re-query using TCP to + get the full set of records. + * `domain` - By default, Consul responds to DNS queries in the "consul." domain. This flag can be used to change that domain. All queries in this domain are assumed to be handled by Consul, and will not be recursively resolved.