mirror of
https://github.com/moby/moby.git
synced 2026-06-30 19:58:03 +00:00
Merge pull request #52821 from notandruu/daemon/rlkclient-loopback-simplify
libnet/rlkclient: simplify ChildHostIP loopback handling
This commit is contained in:
@@ -110,11 +110,12 @@ func (c *PortDriverClient) ChildHostIP(proto string, hostIP netip.Addr) netip.Ad
|
||||
if c.childIP.IsValid() {
|
||||
return c.childIP
|
||||
}
|
||||
// Preserve IPv4 loopback addresses, the child namespace's lo covers all
|
||||
// of 127.0.0.0/8. Mapping them all to 127.0.0.1 makes bindings on the
|
||||
// same port but distinct loopback addresses collide in the child
|
||||
// namespace.
|
||||
if hostIP.Is4() && hostIP.IsLoopback() {
|
||||
// Child namespaces only listen on loopback addresses. Preserve requested
|
||||
// loopback addresses (the child namespace's lo covers all of 127.0.0.0/8,
|
||||
// and collapsing them makes bindings on the same port but distinct
|
||||
// loopback addresses collide); otherwise use the canonical loopback
|
||||
// address for the family.
|
||||
if hostIP.IsLoopback() {
|
||||
return hostIP
|
||||
}
|
||||
if hostIP.Is6() {
|
||||
|
||||
@@ -77,6 +77,13 @@ func TestChildHostIP(t *testing.T) {
|
||||
hostIP: netip.MustParseAddr("127.0.1.2"),
|
||||
want: netip.MustParseAddr("127.0.1.2"),
|
||||
},
|
||||
{
|
||||
name: "v6 loopback",
|
||||
pdc: builtin,
|
||||
proto: "tcp",
|
||||
hostIP: netip.MustParseAddr("::1"),
|
||||
want: netip.IPv6Loopback(),
|
||||
},
|
||||
{
|
||||
name: "v6 non-loopback",
|
||||
pdc: builtin,
|
||||
|
||||
Reference in New Issue
Block a user