Skip to content

Commit

Permalink
pkg/hostagent/dns: truncate messages
Browse files Browse the repository at this point in the history
Fix issue 80: `lima busybox nslookup storage.googleapis.com 192.168.5.3` fails with `Can't find storage.googleapis.com: Parse error`

Signed-off-by: Akihiro Suda <[email protected]>
  • Loading branch information
AkihiroSuda committed Nov 4, 2021
1 parent dff324c commit 347a0bf
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/hostagent/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"github.com/sirupsen/logrus"
)

// Truncate for avoiding "Parse error" from `busybox nslookup`
// https://github.com/lima-vm/lima/issues/380
const truncateSize = 512

type Handler struct {
clientConfig *dns.ClientConfig
clients []*dns.Client
Expand Down Expand Up @@ -174,6 +178,7 @@ func (h *Handler) handleQuery(w dns.ResponseWriter, req *dns.Msg) {
}
}
if handled {
reply.Truncate(truncateSize)
_ = w.WriteMsg(&reply)
return
}
Expand All @@ -186,13 +191,15 @@ func (h *Handler) handleDefault(w dns.ResponseWriter, req *dns.Msg) {
addr := fmt.Sprintf("%s:%s", srv, h.clientConfig.Port)
reply, _, err := client.Exchange(req, addr)
if err == nil {
reply.Truncate(truncateSize)
_ = w.WriteMsg(reply)
return
}
}
}
var reply dns.Msg
reply.SetReply(req)
reply.Truncate(truncateSize)
_ = w.WriteMsg(&reply)
}

Expand Down

0 comments on commit 347a0bf

Please sign in to comment.