Skip to content

Commit

Permalink
add correct slirp ip to /etc/hosts
Browse files Browse the repository at this point in the history
The container name should have the slirp interface ip set in /etc/hosts
and not the gateway ip. Commit c8dfcce introduced this regression.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1972073

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 authored and mheon committed Jun 24, 2021
1 parent 6c4ee85 commit 1c04cfe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ func (c *Container) getHosts() string {
if c.Hostname() != "" {
if c.config.NetMode.IsSlirp4netns() {
// When using slirp4netns, the interface gets a static IP
slirp4netnsIP, err := GetSlirp4netnsGateway(c.slirp4netnsSubnet)
slirp4netnsIP, err := GetSlirp4netnsIP(c.slirp4netnsSubnet)
if err != nil {
logrus.Warn("failed to determine slirp4netnsIP: ", err.Error())
} else {
Expand Down
14 changes: 8 additions & 6 deletions test/system/500-networking.bats
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,25 @@ load helpers
done
}

@test "podman run with slirp4ns assigns correct gateway address to host.containers.internal" {
@test "podman run with slirp4ns assigns correct addresses to /etc/hosts" {
CIDR="$(random_rfc1918_subnet)"
run_podman run --network slirp4netns:cidr="${CIDR}.0/24" \
$IMAGE grep 'host.containers.internal' /etc/hosts
is "$output" "${CIDR}.2 host.containers.internal" "host.containers.internal should be the cidr+2 address"
local conname=con-$(random_string 10)
run_podman run --rm --network slirp4netns:cidr="${CIDR}.0/24" \
--name $conname --hostname $conname $IMAGE cat /etc/hosts
is "$output" ".*${CIDR}.2 host.containers.internal" "host.containers.internal should be the cidr+2 address"
is "$output" ".*${CIDR}.100 $conname $conname" "$conname should be the cidr+100 address"
}

@test "podman run with slirp4ns adds correct dns address to resolv.conf" {
CIDR="$(random_rfc1918_subnet)"
run_podman run --network slirp4netns:cidr="${CIDR}.0/24" \
run_podman run --rm --network slirp4netns:cidr="${CIDR}.0/24" \
$IMAGE grep "${CIDR}" /etc/resolv.conf
is "$output" "nameserver ${CIDR}.3" "resolv.conf should have slirp4netns cidr+3 as a nameserver"
}

@test "podman run with slirp4ns assigns correct ip address container" {
CIDR="$(random_rfc1918_subnet)"
run_podman run --network slirp4netns:cidr="${CIDR}.0/24" \
run_podman run --rm --network slirp4netns:cidr="${CIDR}.0/24" \
$IMAGE sh -c "ip address | grep ${CIDR}"
is "$output" ".*inet ${CIDR}.100/24 \+" "container should have slirp4netns cidr+100 assigned to interface"
}
Expand Down

0 comments on commit 1c04cfe

Please sign in to comment.