Skip to content

Commit 1585f59

Browse files
liuhangbinummakynes
authored andcommitted
selftests: netfilter: switch to socat for tests using -q option
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]>
1 parent d94a69c commit 1585f59

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

tools/testing/selftests/netfilter/ipip-conntrack-mtu.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ checktool (){
4141

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

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

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

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

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

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

195196
# The IPv4 stack on Client A already knows the PMTU to Client B, so the

tools/testing/selftests/netfilter/nf_nat_edemux.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,23 @@ ip netns exec $ns2 ip route add 10.96.0.1 via 192.168.1.1
7676
sleep 1
7777

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

8181
sleep 1
8282

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

8989
kill $iperfs
9090

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

0 commit comments

Comments
 (0)