Skip to content

Commit

Permalink
selftests: netfilter: switch to socat for tests using -q option
Browse files Browse the repository at this point in the history
The nc cmd(nmap-ncat) that distributed with Fedora/Red Hat does not have
option -q. This make some tests failed with:

	nc: invalid option -- 'q'

Let's switch to socat which is far more dependable.

Signed-off-by: Hangbin Liu <[email protected]>
Acked-by: Florian Westphal <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
  • Loading branch information
liuhangbin authored and ummakynes committed Jan 6, 2022
1 parent d94a69c commit 1585f59
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 5 additions & 4 deletions tools/testing/selftests/netfilter/ipip-conntrack-mtu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ checktool (){

checktool "iptables --version" "run test without iptables"
checktool "ip -Version" "run test without ip tool"
checktool "which nc" "run test without nc (netcat)"
checktool "which socat" "run test without socat"
checktool "ip netns add ${r_a}" "create net namespace"

for n in ${r_b} ${r_w} ${c_a} ${c_b};do
Expand All @@ -60,11 +60,12 @@ trap cleanup EXIT
test_path() {
msg="$1"

ip netns exec ${c_b} nc -n -w 3 -q 3 -u -l -p 5000 > ${rx} < /dev/null &
ip netns exec ${c_b} socat -t 3 - udp4-listen:5000,reuseaddr > ${rx} < /dev/null &

sleep 1
for i in 1 2 3; do
head -c1400 /dev/zero | tr "\000" "a" | ip netns exec ${c_a} nc -n -w 1 -u 192.168.20.2 5000
head -c1400 /dev/zero | tr "\000" "a" | \
ip netns exec ${c_a} socat -t 1 -u STDIN UDP:192.168.20.2:5000
done

wait
Expand Down Expand Up @@ -189,7 +190,7 @@ ip netns exec ${r_w} sysctl -q net.ipv4.conf.all.forwarding=1 > /dev/null
#---------------------
#Now we send a 1400 bytes UDP packet from Client A to Client B:

# clienta:~# head -c1400 /dev/zero | tr "\000" "a" | nc -u 192.168.20.2 5000
# clienta:~# head -c1400 /dev/zero | tr "\000" "a" | socat -u STDIN UDP:192.168.20.2:5000
test_path "without"

# The IPv4 stack on Client A already knows the PMTU to Client B, so the
Expand Down
10 changes: 5 additions & 5 deletions tools/testing/selftests/netfilter/nf_nat_edemux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,23 @@ ip netns exec $ns2 ip route add 10.96.0.1 via 192.168.1.1
sleep 1

# add a persistent connection from the other namespace
ip netns exec $ns2 nc -q 10 -w 10 192.168.1.1 5201 > /dev/null &
ip netns exec $ns2 socat -t 10 - TCP:192.168.1.1:5201 > /dev/null &

sleep 1

# ip daddr:dport will be rewritten to 192.168.1.1 5201
# NAT must reallocate source port 10000 because
# 192.168.1.2:10000 -> 192.168.1.1:5201 is already in use
echo test | ip netns exec $ns2 nc -w 3 -q 3 10.96.0.1 443 >/dev/null
echo test | ip netns exec $ns2 socat -t 3 -u STDIN TCP:10.96.0.1:443 >/dev/null
ret=$?

kill $iperfs

# Check nc can connect to 10.96.0.1:443 (aka 192.168.1.1:5201).
# Check socat can connect to 10.96.0.1:443 (aka 192.168.1.1:5201).
if [ $ret -eq 0 ]; then
echo "PASS: nc can connect via NAT'd address"
echo "PASS: socat can connect via NAT'd address"
else
echo "FAIL: nc cannot connect via NAT'd address"
echo "FAIL: socat cannot connect via NAT'd address"
exit 1
fi

Expand Down

0 comments on commit 1585f59

Please sign in to comment.