Skip to content

Commit

Permalink
Merge pull request moby#49128 from robmry/v6only/enable_ext_dns
Browse files Browse the repository at this point in the history
Enable external DNS if a network has an IPv6 gateway
  • Loading branch information
thaJeztah authored Dec 18, 2024
2 parents bdfc384 + b0be1f3 commit 93101be
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions integration/network/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 1 addition & 1 deletion libnetwork/endpoint_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 93101be

Please sign in to comment.