Merge pull request #52821 from notandruu/daemon/rlkclient-loopback-simplify

libnet/rlkclient: simplify ChildHostIP loopback handling
This commit is contained in:
Sebastiaan van Stijn
2026-06-12 17:03:16 +02:00
committed by GitHub
2 changed files with 13 additions and 5 deletions

View File

@@ -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() {

View File

@@ -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,