From 347a0bf25aced76427e90241014360f09c5ceae8 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Thu, 4 Nov 2021 19:43:33 +0900 Subject: [PATCH] pkg/hostagent/dns: truncate messages 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 --- pkg/hostagent/dns/dns.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/hostagent/dns/dns.go b/pkg/hostagent/dns/dns.go index c8024b7cb33..6b3887c9f05 100644 --- a/pkg/hostagent/dns/dns.go +++ b/pkg/hostagent/dns/dns.go @@ -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 @@ -174,6 +178,7 @@ func (h *Handler) handleQuery(w dns.ResponseWriter, req *dns.Msg) { } } if handled { + reply.Truncate(truncateSize) _ = w.WriteMsg(&reply) return } @@ -186,6 +191,7 @@ 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 } @@ -193,6 +199,7 @@ func (h *Handler) handleDefault(w dns.ResponseWriter, req *dns.Msg) { } var reply dns.Msg reply.SetReply(req) + reply.Truncate(truncateSize) _ = w.WriteMsg(&reply) }