Skip to content

Commit

Permalink
fix slirp4netns port forwarding with ranges
Browse files Browse the repository at this point in the history
The slirp4netns port forwarder was not updated to make use of the new
port format. This results in a problem when port ranges are used since
it does not read the range field from the port.

Update the logic to iterate through all ports with the range and
protocols. Also added a system test for port ranges with slirp4netns,
rootlesskit and the bridge network mode.

Fixes containers#13643

[Fixed merge conflict]

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
  • Loading branch information
Luap99 authored and paralin committed Jun 3, 2022
1 parent f7a5408 commit e240af3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/system/500-networking.bats
Original file line number Diff line number Diff line change
Expand Up @@ -747,4 +747,25 @@ EOF
done
}

@test "podman run port forward range" {
for netmode in bridge slirp4netns:port_handler=slirp4netns slirp4netns:port_handler=rootlesskit; do
local port=$(random_free_port)
local end_port=$(( $port + 2 ))
local range="$port-$end_port:$port-$end_port"
local random=$(random_string)

run_podman run --network $netmode -p "$range" -d $IMAGE sleep inf
cid="$output"
for port in $(seq $port $end_port); do
run_podman exec -d $cid nc -l -p $port -e /bin/cat
# -w 1 adds a 1 second timeout, for some reason ubuntus ncat doesn't close the connection on EOF,
# other options to change this are not portable across distros but -w seems to work
run nc -w 1 127.0.0.1 $port <<<$random
is "$output" "$random" "ncat got data back (netmode=$netmode port=$port)"
done

run_podman rm -f -t0 $cid
done
}

# vim: filetype=sh

0 comments on commit e240af3

Please sign in to comment.