Skip to content

Commit 7e1268e

Browse files
committed
add additional debugging statements
Signed-off-by: Nino Kodabande <[email protected]>
1 parent 83ede8b commit 7e1268e

File tree

1 file changed

+57
-43
lines changed

1 file changed

+57
-43
lines changed

pkg/hostagent/dns/dns.go

Lines changed: 57 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func (s *Server) Shutdown() {
5757
}
5858

5959
func newStaticClientConfig(ips []string) (*dns.ClientConfig, error) {
60+
logrus.Infof("newStaticClientConfig creating config for the the following IPs: %v", ips)
6061
s := ``
6162
for _, ip := range ips {
6263
s += fmt.Sprintf("nameserver %s\n", ip)
@@ -120,6 +121,7 @@ func (h *Handler) handleQuery(w dns.ResponseWriter, req *dns.Msg) {
120121
handled bool
121122
)
122123
reply.SetReply(req)
124+
logrus.Debugf("handleQuery received DNS query: %v", req)
123125
for _, q := range req.Question {
124126
hdr := dns.RR_Header{
125127
Name: q.Name,
@@ -128,7 +130,7 @@ func (h *Handler) handleQuery(w dns.ResponseWriter, req *dns.Msg) {
128130
Ttl: 5,
129131
}
130132
qtype := q.Qtype
131-
switch qtype {
133+
switch q.Qtype {
132134
case dns.TypeAAAA:
133135
if !h.ipv6 {
134136
// A "correct" answer would be to set `handled = true` and return a NODATA response.
@@ -209,63 +211,71 @@ func (h *Handler) handleQuery(w dns.ResponseWriter, req *dns.Msg) {
209211
}
210212
case dns.TypeTXT:
211213
txt, err := net.LookupTXT(q.Name)
212-
if err == nil && len(txt) > 0 {
213-
for _, s := range txt {
214-
a := &dns.TXT{
215-
Hdr: hdr,
216-
}
217-
// Per RFC7208 3.3, when a TXT answer has multiple strings, the answer must be treated as
218-
// a single concatenated string. net.LookupTXT is pre-concatenating such answers, which
219-
// means we need to break it back up for this resolver to return a valid response.
220-
a.Txt = chunkify(s, 255)
221-
reply.Answer = append(reply.Answer, a)
222-
handled = true
214+
if err != nil {
215+
logrus.Debugf("handleQuery lookup TXT failed: %v", err)
216+
continue
217+
}
218+
for _, s := range txt {
219+
a := &dns.TXT{
220+
Hdr: hdr,
223221
}
222+
// Per RFC7208 3.3, when a TXT answer has multiple strings, the answer must be treated as
223+
// a single concatenated string. net.LookupTXT is pre-concatenating such answers, which
224+
// means we need to break it back up for this resolver to return a valid response.
225+
a.Txt = chunkify(s, 255)
226+
reply.Answer = append(reply.Answer, a)
227+
handled = true
224228
}
225229
case dns.TypeNS:
226230
ns, err := net.LookupNS(q.Name)
227-
if err == nil && len(ns) > 0 {
228-
for _, s := range ns {
229-
if s.Host != "" {
230-
a := &dns.NS{
231-
Hdr: hdr,
232-
Ns: s.Host,
233-
}
234-
reply.Answer = append(reply.Answer, a)
235-
handled = true
231+
if err != nil {
232+
logrus.Debugf("handleQuery lookup NS failed: %v", err)
233+
continue
234+
}
235+
for _, s := range ns {
236+
if s.Host != "" {
237+
a := &dns.NS{
238+
Hdr: hdr,
239+
Ns: s.Host,
236240
}
241+
reply.Answer = append(reply.Answer, a)
242+
handled = true
237243
}
238244
}
239245
case dns.TypeMX:
240246
mx, err := net.LookupMX(q.Name)
241-
if err == nil && len(mx) > 0 {
242-
for _, s := range mx {
243-
if s.Host != "" {
244-
a := &dns.MX{
245-
Hdr: hdr,
246-
Mx: s.Host,
247-
Preference: s.Pref,
248-
}
249-
reply.Answer = append(reply.Answer, a)
250-
handled = true
247+
if err != nil {
248+
logrus.Debugf("handleQuery lookup MX failed: %v", err)
249+
continue
250+
}
251+
for _, s := range mx {
252+
if s.Host != "" {
253+
a := &dns.MX{
254+
Hdr: hdr,
255+
Mx: s.Host,
256+
Preference: s.Pref,
251257
}
258+
reply.Answer = append(reply.Answer, a)
259+
handled = true
252260
}
253261
}
254262
case dns.TypeSRV:
255263
_, addrs, err := net.LookupSRV("", "", q.Name)
256-
if err == nil {
257-
hdr.Rrtype = dns.TypeSRV
258-
for _, addr := range addrs {
259-
a := &dns.SRV{
260-
Hdr: hdr,
261-
Target: addr.Target,
262-
Port: addr.Port,
263-
Priority: addr.Priority,
264-
Weight: addr.Weight,
265-
}
266-
reply.Answer = append(reply.Answer, a)
267-
handled = true
264+
if err != nil {
265+
logrus.Debugf("handleQuery lookup SRV failed: %v", err)
266+
continue
267+
}
268+
hdr.Rrtype = dns.TypeSRV
269+
for _, addr := range addrs {
270+
a := &dns.SRV{
271+
Hdr: hdr,
272+
Target: addr.Target,
273+
Port: addr.Port,
274+
Priority: addr.Priority,
275+
Weight: addr.Weight,
268276
}
277+
reply.Answer = append(reply.Answer, a)
278+
handled = true
269279
}
270280
}
271281
}
@@ -276,12 +286,14 @@ func (h *Handler) handleQuery(w dns.ResponseWriter, req *dns.Msg) {
276286
if err := w.WriteMsg(&reply); err != nil {
277287
logrus.Debugf("handleQuery failed writing DNS reply: %v", err)
278288
}
289+
279290
return
280291
}
281292
h.handleDefault(w, req)
282293
}
283294

284295
func (h *Handler) handleDefault(w dns.ResponseWriter, req *dns.Msg) {
296+
logrus.Debugf("handleDefault for %v", req)
285297
for _, client := range h.clients {
286298
for _, srv := range h.clientConfig.Servers {
287299
addr := fmt.Sprintf("%s:%s", srv, h.clientConfig.Port)
@@ -334,6 +346,7 @@ func Start(opts ServerOptions) (*Server, error) {
334346
s := &dns.Server{Net: "udp", Addr: addr, Handler: h}
335347
server.udp = s
336348
go func() {
349+
logrus.Debugf("Start UDP server listening on: %v", addr)
337350
if e := s.ListenAndServe(); e != nil {
338351
panic(e)
339352
}
@@ -350,6 +363,7 @@ func Start(opts ServerOptions) (*Server, error) {
350363
s := &dns.Server{Net: "tcp", Addr: addr, Handler: h}
351364
server.tcp = s
352365
go func() {
366+
logrus.Debugf("Start TCP server listening on: %v", addr)
353367
if e := s.ListenAndServe(); e != nil {
354368
panic(e)
355369
}

0 commit comments

Comments
 (0)