Skip to content

Commit

Permalink
libnetwork/etchosts: add PreferIP option
Browse files Browse the repository at this point in the history
For the pasta network mode we now use --map-guest-addr which means we
have a specific ip that we want to use as host.containers.internal
address. I first thought we could handle it in podman but that doesn't
work as the contianers.conf option must have a higher priority.

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Sep 2, 2024
1 parent 6e3e128 commit 6125e26
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libnetwork/etchosts/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type HostContainersInternalOptions struct {
// Exclude are then ips that should not be returned, this is
// useful to prevent returning the same ip as in the container.
Exclude []net.IP
// PreferIP is a ip that should be used if set but it has a
// lower priority than the containers.conf config option.
// This is used for the pasta --map-guest-addr ip.
PreferIP string
}

// GetHostContainersInternalIP returns the host.containers.internal ip
Expand All @@ -38,6 +42,12 @@ func GetHostContainersInternalIP(opts HostContainersInternalOptions) string {
default:
return opts.Conf.Containers.HostContainersInternalIP
}

// caller has a specific ip it prefers
if opts.PreferIP != "" {
return opts.PreferIP
}

ip := ""
// Only use the bridge ip when root, as rootless the interfaces are created
// inside the special netns and not the host so we cannot use them.
Expand Down

0 comments on commit 6125e26

Please sign in to comment.