From b0be1f3af84b6ee82973ba9d7d175ee8e0863f18 Mon Sep 17 00:00:00 2001 From: Rob Murray Date: Wed, 18 Dec 2024 12:22:45 +0000 Subject: [PATCH] Enable external DNS if a network has an IPv6 gateway Signed-off-by: Rob Murray --- integration/network/dns_test.go | 36 +++++++++++++++++++++++++++++++++ libnetwork/endpoint_info.go | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/integration/network/dns_test.go b/integration/network/dns_test.go index 320db1647bae6..d0798732cfbb6 100644 --- a/integration/network/dns_test.go +++ b/integration/network/dns_test.go @@ -90,3 +90,39 @@ func TestIntDNSAsExtDNS(t *testing.T) { }) } } + +// TestExtDNSInIPv6OnlyNw checks that an IPv6-only bridge network has external +// DNS access. +func TestExtDNSInIPv6OnlyNw(t *testing.T) { + skip.If(t, testEnv.DaemonInfo.OSType == "windows", "No IPv6 Windows") + skip.If(t, testEnv.IsRootless, "Can't use resolver on host in rootless mode") + ctx := setupTest(t) + + // Start a DNS server on the loopback interface. + network.StartDaftDNS(t, "127.0.0.1") + + // Set up a temp resolv.conf pointing at that DNS server, and a daemon using it. + tmpFileName := network.WriteTempResolvConf(t, "127.0.0.1") + d := daemon.New(t, daemon.WithEnvVars("DOCKER_TEST_RESOLV_CONF_PATH="+tmpFileName), daemon.WithExperimental()) + d.StartWithBusybox(ctx, t) + defer d.Stop(t) + + c := d.NewClientT(t) + defer c.Close() + + netName := "v6only" + network.CreateNoError(ctx, t, c, netName, + network.WithDriver("bridge"), + network.WithIPv4(false), + network.WithIPv6(), + ) + defer network.RemoveNoError(ctx, t, c, netName) + + ctrId := container.Run(ctx, t, c, container.WithNetworkMode(netName)) + defer c.ContainerRemove(ctx, ctrId, containertypes.RemoveOptions{Force: true}) + + res, err := container.Exec(ctx, c, ctrId, []string{"nslookup", "test.example"}) + assert.NilError(t, err) + assert.Check(t, is.Equal(res.ExitCode, 0)) + assert.Check(t, is.Contains(res.Stdout(), network.DNSRespAddr)) +} diff --git a/libnetwork/endpoint_info.go b/libnetwork/endpoint_info.go index c75769d06885d..313f6efadacdd 100644 --- a/libnetwork/endpoint_info.go +++ b/libnetwork/endpoint_info.go @@ -388,7 +388,7 @@ func (ep *Endpoint) hasGatewayOrDefaultRoute() bool { defer ep.mu.Unlock() if ep.joinInfo != nil { - if len(ep.joinInfo.gw) > 0 { + if len(ep.joinInfo.gw) > 0 || len(ep.joinInfo.gw6) > 0 { return true } for _, route := range ep.joinInfo.StaticRoutes {