From a242d1af0b43e31e6103348557115572a43101b5 Mon Sep 17 00:00:00 2001 From: Gabriel Mougard Date: Tue, 5 Dec 2023 14:53:20 +0100 Subject: [PATCH] mdns: if host does not support IPv6, disable mDNS IPv6 networking Signed-off-by: Gabriel Mougard --- microcloud/mdns/lookup.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/microcloud/mdns/lookup.go b/microcloud/mdns/lookup.go index a39160ded..4702a3305 100644 --- a/microcloud/mdns/lookup.go +++ b/microcloud/mdns/lookup.go @@ -148,7 +148,22 @@ func Lookup(ctx context.Context, iface *net.Interface, service string, size int) params.Interface = iface params.Entries = entriesCh params.Timeout = 100 * time.Millisecond - err := mdns.Query(params) + ipv4Supported, ipv6Supported, err := checkIPStatus(iface.Name) + if err != nil { + return nil, fmt.Errorf("Failed to check IPv6 status: %w", err) + } + + if !ipv4Supported { + logger.Infof("IPv4 is not supported on this system network interface %q: disabling IPv4 mDNS\n", iface.Name) + params.DisableIPv4 = true + } + + if !ipv6Supported { + logger.Infof("IPv6 is not supported on this system network interface %q: disabling IPv6 mDNS\n", iface.Name) + params.DisableIPv6 = true + } + + err = mdns.Query(params) if err != nil { return nil, fmt.Errorf("Failed lookup: %w", err) }