Skip to content

Commit a76e706

Browse files
committed
libnetwork/pasta: do not ignore ipv4 link local
Starting with pasta 2024_11_27.c0fbc7e there is new "local mode"[1] in pasta that defaults to setting up link local addresses in the netns when no suitable interface was found. this is done to fix the podman issue[2] where we fail to start in these cases which was a poor UX. Now the pasta change alone works fine for these users but there is one problem. Podman adds hosts entries for the container ip/name tuple and for the host.containers.internal. These entries are filtered out thus neither ipv4 or ipv6 bool was set and no addresses where added to IPAddresses. Thus podman had no info to add entries and just left them empty, while for most cases this is fine there might be a few users who expect host.containers.internal and the container name to resolve correctly. This commit changes the logic to only skip ipv6 link local addresses but allow ipv4 link local addresses. With that podman will add the proper entry. [1] https://archives.passt.top/passt-dev/[email protected]/ [2] containers/podman#24614 Signed-off-by: Paul Holzinger <[email protected]> (cherry picked from commit 0b0b18e)
1 parent c846f02 commit a76e706

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

Diff for: libnetwork/pasta/pasta_linux.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,26 @@ func Setup(opts *SetupOptions) (*SetupResult, error) {
110110
return err
111111
}
112112
for _, addr := range addrs {
113-
// make sure to skip localhost and other special addresses
114-
if ipnet, ok := addr.(*net.IPNet); ok && ipnet.IP.IsGlobalUnicast() {
115-
result.IPAddresses = append(result.IPAddresses, ipnet.IP)
116-
if !ipv4 && util.IsIPv4(ipnet.IP) {
113+
// make sure to skip loopback and multicast addresses
114+
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() && !ipnet.IP.IsMulticast() {
115+
if util.IsIPv4(ipnet.IP) {
116+
result.IPAddresses = append(result.IPAddresses, ipnet.IP)
117117
ipv4 = true
118-
}
119-
if !ipv6 && util.IsIPv6(ipnet.IP) {
118+
} else if !ipnet.IP.IsLinkLocalUnicast() {
119+
// Else must be ipv6.
120+
// We shouldn't resolve hosts.containers.internal to IPv6
121+
// link-local addresses, for two reasons:
122+
// 1. even if IPv6 is disabled in pasta (--ipv4-only), the
123+
// kernel will configure an IPv6 link-local address in the
124+
// container, but that doesn't mean that IPv6 connectivity
125+
// is actually working
126+
// 2. link-local addresses need to be suffixed by the zone
127+
// (interface) to be of any use, but we can't do it here
128+
//
129+
// Thus, don't include IPv6 link-local addresses in
130+
// IPAddresses: Podman uses them for /etc/hosts entries, and
131+
// those need to be functional.
132+
result.IPAddresses = append(result.IPAddresses, ipnet.IP)
120133
ipv6 = true
121134
}
122135
}

0 commit comments

Comments
 (0)