Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add control of recursion desired flag for DNS probes #859

Merged
merged 2 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ query_name: <string>
[ query_type: <string> | default = "ANY" ]
[ query_class: <string> | default = "IN" ]

# Set the recursion desired (RD) flag in the request.
[ recursion: <boolean> | default = true ]

# List of valid response codes.
valid_rcodes:
[ - <string> ... | default = "NOERROR" ]
Expand Down
6 changes: 4 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ var (
// DefaultDNSProbe set default value for DNSProbe
DefaultDNSProbe = DNSProbe{
IPProtocolFallback: true,
Recursion: true,
}
)

Expand Down Expand Up @@ -264,8 +265,9 @@ type DNSProbe struct {
TransportProtocol string `yaml:"transport_protocol,omitempty"`
QueryClass string `yaml:"query_class,omitempty"` // Defaults to IN.
QueryName string `yaml:"query_name,omitempty"`
QueryType string `yaml:"query_type,omitempty"` // Defaults to ANY.
ValidRcodes []string `yaml:"valid_rcodes,omitempty"` // Defaults to NOERROR.
QueryType string `yaml:"query_type,omitempty"` // Defaults to ANY.
Recursion bool `yaml:"recursion_desired,omitempty"` // Defaults to true.
ValidRcodes []string `yaml:"valid_rcodes,omitempty"` // Defaults to NOERROR.
ValidateAnswer DNSRRValidator `yaml:"validate_answer_rrs,omitempty"`
ValidateAuthority DNSRRValidator `yaml:"validate_authority_rrs,omitempty"`
ValidateAdditional DNSRRValidator `yaml:"validate_additional_rrs,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion prober/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func ProbeDNS(ctx context.Context, target string, module config.Module, registry

msg := new(dns.Msg)
msg.Id = dns.Id()
msg.RecursionDesired = true
msg.RecursionDesired = module.DNS.Recursion
msg.Question = make([]dns.Question, 1)
msg.Question[0] = dns.Question{dns.Fqdn(module.DNS.QueryName), qt, qc}

Expand Down
43 changes: 34 additions & 9 deletions prober/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,20 @@ func startDNSServer(protocol string, handler func(dns.ResponseWriter, *dns.Msg))
func recursiveDNSHandler(w dns.ResponseWriter, r *dns.Msg) {
m := new(dns.Msg)
m.SetReply(r)
answers := []string{
"example.com. 3600 IN A 127.0.0.1",
"example.com. 3600 IN A 127.0.0.2",
}
for _, rr := range answers {
a, err := dns.NewRR(rr)
if err != nil {
panic(err)
if !r.RecursionDesired {
m.Rcode = dns.RcodeRefused
} else {
answers := []string{
"example.com. 3600 IN A 127.0.0.1",
"example.com. 3600 IN A 127.0.0.2",
}
for _, rr := range answers {
a, err := dns.NewRR(rr)
if err != nil {
panic(err)
}
m.Answer = append(m.Answer, a)
}
m.Answer = append(m.Answer, a)
}
if err := w.WriteMsg(m); err != nil {
panic(err)
Expand All @@ -99,13 +103,15 @@ func TestRecursiveDNSResponse(t *testing.T) {
IPProtocol: "ip4",
IPProtocolFallback: true,
QueryName: "example.com",
Recursion: true,
}, true,
},
{
config.DNSProbe{
IPProtocol: "ip4",
IPProtocolFallback: true,
QueryName: "example.com",
Recursion: true,
ValidRcodes: []string{"SERVFAIL", "NXDOMAIN"},
}, false,
},
Expand All @@ -114,6 +120,7 @@ func TestRecursiveDNSResponse(t *testing.T) {
IPProtocol: "ip4",
IPProtocolFallback: true,
QueryName: "example.com",
Recursion: true,
ValidateAnswer: config.DNSRRValidator{
FailIfMatchesRegexp: []string{".*7200.*"},
FailIfNotMatchesRegexp: []string{".*3600.*"},
Expand All @@ -125,6 +132,7 @@ func TestRecursiveDNSResponse(t *testing.T) {
IPProtocol: "ip4",
IPProtocolFallback: true,
QueryName: "example.com",
Recursion: true,
ValidateAuthority: config.DNSRRValidator{
FailIfMatchesRegexp: []string{".*7200.*"},
},
Expand All @@ -135,11 +143,20 @@ func TestRecursiveDNSResponse(t *testing.T) {
IPProtocol: "ip4",
IPProtocolFallback: true,
QueryName: "example.com",
Recursion: true,
ValidateAdditional: config.DNSRRValidator{
FailIfNotMatchesRegexp: []string{".*3600.*"},
},
}, false,
},
{
config.DNSProbe{
IPProtocol: "ip4",
IPProtocolFallback: true,
QueryName: "example.com",
Recursion: false,
}, false,
},
}

for _, protocol := range PROTOCOLS {
Expand All @@ -166,6 +183,9 @@ func TestRecursiveDNSResponse(t *testing.T) {
"probe_dns_authority_rrs": 0,
"probe_dns_additional_rrs": 0,
}
if !test.Probe.Recursion {
expectedResults["probe_dns_answer_rrs"] = 0
}
checkRegistryResults(expectedResults, mfs, t)
}
}
Expand Down Expand Up @@ -474,6 +494,7 @@ func TestDNSProtocol(t *testing.T) {
QueryName: "example.com",
TransportProtocol: protocol,
IPProtocol: "ip6",
Recursion: true,
},
}
registry := prometheus.NewRegistry()
Expand All @@ -497,6 +518,7 @@ func TestDNSProtocol(t *testing.T) {
Timeout: time.Second,
DNS: config.DNSProbe{
QueryName: "example.com",
Recursion: true,
TransportProtocol: protocol,
IPProtocol: "ip4",
},
Expand All @@ -523,6 +545,7 @@ func TestDNSProtocol(t *testing.T) {
Timeout: time.Second,
DNS: config.DNSProbe{
QueryName: "example.com",
Recursion: true,
TransportProtocol: protocol,
},
}
Expand All @@ -548,6 +571,7 @@ func TestDNSProtocol(t *testing.T) {
Timeout: time.Second,
DNS: config.DNSProbe{
QueryName: "example.com",
Recursion: true,
},
}
registry = prometheus.NewRegistry()
Expand Down Expand Up @@ -590,6 +614,7 @@ func TestDNSMetrics(t *testing.T) {
IPProtocol: "ip4",
IPProtocolFallback: true,
QueryName: "example.com",
Recursion: true,
},
}
registry := prometheus.NewRegistry()
Expand Down