From 1b75f9657163121e881377e59af45cc9f61dd835 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 | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/microcloud/mdns/lookup.go b/microcloud/mdns/lookup.go index a39160ded..dc542d63a 100644 --- a/microcloud/mdns/lookup.go +++ b/microcloud/mdns/lookup.go @@ -148,7 +148,26 @@ 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 IP 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 + } + + if params.DisableIPv4 && params.DisableIPv6 { + return nil, fmt.Errorf("No supported IP versions on the network interface %q", iface.Name) + } + + err = mdns.Query(params) if err != nil { return nil, fmt.Errorf("Failed lookup: %w", err) }