@@ -477,3 +477,60 @@ func TestDefaultBridgeAddresses(t *testing.T) {
477477 })
478478 }
479479}
480+
481+ // Test that a container on an 'internal' network has IP connectivity with
482+ // the host (on its own subnet, because the n/w bridge has an address on that
483+ // subnet, and it's in the host's namespace).
484+ // Regression test for https://github.com/moby/moby/issues/47329
485+ func TestInternalNwConnectivity (t * testing.T ) {
486+ skip .If (t , testEnv .DaemonInfo .OSType == "windows" )
487+
488+ ctx := setupTest (t )
489+
490+ d := daemon .New (t )
491+ d .StartWithBusybox (ctx , t , "-D" , "--experimental" , "--ip6tables" )
492+ defer d .Stop (t )
493+
494+ c := d .NewClientT (t )
495+ defer c .Close ()
496+
497+ const bridgeName = "intnw"
498+ const gw4 = "172.30.0.1"
499+ const gw6 = "fda9:4130:4715::1234"
500+ network .CreateNoError (ctx , t , c , bridgeName ,
501+ network .WithInternal (),
502+ network .WithIPv6 (),
503+ network .WithIPAM ("172.30.0.0/24" , gw4 ),
504+ network .WithIPAM ("fda9:4130:4715::/64" , gw6 ),
505+ network .WithDriver ("bridge" ),
506+ network .WithOption ("com.docker.network.bridge.name" , bridgeName ),
507+ )
508+ defer network .RemoveNoError (ctx , t , c , bridgeName )
509+
510+ const ctrName = "intctr"
511+ id := container .Run (ctx , t , c ,
512+ container .WithName (ctrName ),
513+ container .WithImage ("busybox:latest" ),
514+ container .WithCmd ("top" ),
515+ container .WithNetworkMode (bridgeName ),
516+ )
517+ defer c .ContainerRemove (ctx , id , containertypes.RemoveOptions {Force : true })
518+
519+ execCtx , cancel := context .WithTimeout (ctx , 20 * time .Second )
520+ defer cancel ()
521+
522+ res := container .ExecT (execCtx , t , c , id , []string {"ping" , "-c1" , "-W3" , gw4 })
523+ assert .Check (t , is .Equal (res .ExitCode , 0 ))
524+ assert .Check (t , is .Equal (res .Stderr (), "" ))
525+ assert .Check (t , is .Contains (res .Stdout (), "1 packets transmitted, 1 packets received" ))
526+
527+ res = container .ExecT (execCtx , t , c , id , []string {"ping6" , "-c1" , "-W3" , gw6 })
528+ assert .Check (t , is .Equal (res .ExitCode , 0 ))
529+ assert .Check (t , is .Equal (res .Stderr (), "" ))
530+ assert .Check (t , is .Contains (res .Stdout (), "1 packets transmitted, 1 packets received" ))
531+
532+ // Addresses outside the internal subnet must not be accessible.
533+ res = container .ExecT (execCtx , t , c , id , []string {"ping" , "-c1" , "-W3" , "8.8.8.8" })
534+ assert .Check (t , is .Equal (res .ExitCode , 1 ))
535+ assert .Check (t , is .Contains (res .Stderr (), "Network is unreachable" ))
536+ }
0 commit comments