@@ -69,16 +69,20 @@ func startDNSServer(protocol string, handler func(dns.ResponseWriter, *dns.Msg))
69
69
func recursiveDNSHandler (w dns.ResponseWriter , r * dns.Msg ) {
70
70
m := new (dns.Msg )
71
71
m .SetReply (r )
72
- answers := []string {
73
- "example.com. 3600 IN A 127.0.0.1" ,
74
- "example.com. 3600 IN A 127.0.0.2" ,
75
- }
76
- for _ , rr := range answers {
77
- a , err := dns .NewRR (rr )
78
- if err != nil {
79
- panic (err )
72
+ if ! r .RecursionDesired {
73
+ m .Rcode = dns .RcodeRefused
74
+ } else {
75
+ answers := []string {
76
+ "example.com. 3600 IN A 127.0.0.1" ,
77
+ "example.com. 3600 IN A 127.0.0.2" ,
78
+ }
79
+ for _ , rr := range answers {
80
+ a , err := dns .NewRR (rr )
81
+ if err != nil {
82
+ panic (err )
83
+ }
84
+ m .Answer = append (m .Answer , a )
80
85
}
81
- m .Answer = append (m .Answer , a )
82
86
}
83
87
if err := w .WriteMsg (m ); err != nil {
84
88
panic (err )
@@ -99,13 +103,15 @@ func TestRecursiveDNSResponse(t *testing.T) {
99
103
IPProtocol : "ip4" ,
100
104
IPProtocolFallback : true ,
101
105
QueryName : "example.com" ,
106
+ RecursionDesired : true ,
102
107
}, true ,
103
108
},
104
109
{
105
110
config.DNSProbe {
106
111
IPProtocol : "ip4" ,
107
112
IPProtocolFallback : true ,
108
113
QueryName : "example.com" ,
114
+ RecursionDesired : true ,
109
115
ValidRcodes : []string {"SERVFAIL" , "NXDOMAIN" },
110
116
}, false ,
111
117
},
@@ -114,6 +120,7 @@ func TestRecursiveDNSResponse(t *testing.T) {
114
120
IPProtocol : "ip4" ,
115
121
IPProtocolFallback : true ,
116
122
QueryName : "example.com" ,
123
+ RecursionDesired : true ,
117
124
ValidateAnswer : config.DNSRRValidator {
118
125
FailIfMatchesRegexp : []string {".*7200.*" },
119
126
FailIfNotMatchesRegexp : []string {".*3600.*" },
@@ -125,6 +132,7 @@ func TestRecursiveDNSResponse(t *testing.T) {
125
132
IPProtocol : "ip4" ,
126
133
IPProtocolFallback : true ,
127
134
QueryName : "example.com" ,
135
+ RecursionDesired : true ,
128
136
ValidateAuthority : config.DNSRRValidator {
129
137
FailIfMatchesRegexp : []string {".*7200.*" },
130
138
},
@@ -135,11 +143,20 @@ func TestRecursiveDNSResponse(t *testing.T) {
135
143
IPProtocol : "ip4" ,
136
144
IPProtocolFallback : true ,
137
145
QueryName : "example.com" ,
146
+ RecursionDesired : true ,
138
147
ValidateAdditional : config.DNSRRValidator {
139
148
FailIfNotMatchesRegexp : []string {".*3600.*" },
140
149
},
141
150
}, false ,
142
151
},
152
+ {
153
+ config.DNSProbe {
154
+ IPProtocol : "ip4" ,
155
+ IPProtocolFallback : true ,
156
+ QueryName : "example.com" ,
157
+ RecursionDesired : false ,
158
+ }, false ,
159
+ },
143
160
}
144
161
145
162
for _ , protocol := range PROTOCOLS {
@@ -166,6 +183,9 @@ func TestRecursiveDNSResponse(t *testing.T) {
166
183
"probe_dns_authority_rrs" : 0 ,
167
184
"probe_dns_additional_rrs" : 0 ,
168
185
}
186
+ if ! test .Probe .RecursionDesired {
187
+ expectedResults ["probe_dns_answer_rrs" ] = 0
188
+ }
169
189
checkRegistryResults (expectedResults , mfs , t )
170
190
}
171
191
}
@@ -474,6 +494,7 @@ func TestDNSProtocol(t *testing.T) {
474
494
QueryName : "example.com" ,
475
495
TransportProtocol : protocol ,
476
496
IPProtocol : "ip6" ,
497
+ RecursionDesired : true ,
477
498
},
478
499
}
479
500
registry := prometheus .NewRegistry ()
@@ -497,6 +518,7 @@ func TestDNSProtocol(t *testing.T) {
497
518
Timeout : time .Second ,
498
519
DNS : config.DNSProbe {
499
520
QueryName : "example.com" ,
521
+ RecursionDesired : true ,
500
522
TransportProtocol : protocol ,
501
523
IPProtocol : "ip4" ,
502
524
},
@@ -523,6 +545,7 @@ func TestDNSProtocol(t *testing.T) {
523
545
Timeout : time .Second ,
524
546
DNS : config.DNSProbe {
525
547
QueryName : "example.com" ,
548
+ RecursionDesired : true ,
526
549
TransportProtocol : protocol ,
527
550
},
528
551
}
@@ -547,7 +570,8 @@ func TestDNSProtocol(t *testing.T) {
547
570
module = config.Module {
548
571
Timeout : time .Second ,
549
572
DNS : config.DNSProbe {
550
- QueryName : "example.com" ,
573
+ QueryName : "example.com" ,
574
+ RecursionDesired : true ,
551
575
},
552
576
}
553
577
registry = prometheus .NewRegistry ()
@@ -590,6 +614,7 @@ func TestDNSMetrics(t *testing.T) {
590
614
IPProtocol : "ip4" ,
591
615
IPProtocolFallback : true ,
592
616
QueryName : "example.com" ,
617
+ RecursionDesired : true ,
593
618
},
594
619
}
595
620
registry := prometheus .NewRegistry ()
0 commit comments