Skip to contentSkip to conversation

network/iptables: reduce ping timeouts

PATCH New Alexey Kodanev 2 participants 7 messages Dec 17, 2019 – Dec 19, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 network/iptables: reduce ping timeouts

---
v2: no changes

 testcases/network/iptables/iptables_tests.sh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
testcases/network/iptables/iptables_tests.sh +6 -6
index 11412d6fb..d8b23283f 100755
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018 Oracle and/or its affiliates. All Rights Reserved.
+# Copyright (c) 2018-2019 Oracle and/or its affiliates. All Rights Reserved.
 # Copyright (c) International Business Machines  Corp., 2001
 #
 #  Author:	Jan 20 2004 Hubert Lin <[email protected]>
@@ -123,7 +123,7 @@ test2()
 	fi
 
 	tst_res TINFO "Pinging 127.0.0.1"
-	ping -c 2 127.0.0.1 > tst_iptables.out 2>&1
+	ping -c 2 127.0.0.1 -W 1 -i 0 > tst_iptables.out 2>&1
 	if [ $? -ne 0 ]; then
 		grep "100% packet loss" tst_iptables.out > tst_iptables.err 2>&1
 		if [ $? -ne 0 ]; then
@@ -148,7 +148,7 @@ test2()
 		return
 	fi
 	tst_res TINFO "Pinging 127.0.0.1 again"
-	ping -c 2 127.0.0.1 > tst_iptables.out 2>&1
+	ping -c 2 127.0.0.1 -W 1 -i 0 > tst_iptables.out 2>&1
 	if [ $? -ne 0 ]; then
 		tst_res TFAIL "iptables blocking loopback. This is expected" \
 			       "behaviour on certain distributions where" \
@@ -174,7 +174,7 @@ test3()
 	fi
 
 	tst_res TINFO "Pinging 127.0.0.1"
-	ping -c 2 127.0.0.1 > tst_iptables.out 2>&1
+	ping -c 2 127.0.0.1 -W 1 -i 0 > tst_iptables.out 2>&1
 	if [ $? -ne 0 ]; then
 		grep "100% packet loss" tst_iptables.out > tst_iptables.err 2>&1
 		if [ $? -ne 0 ]; then
@@ -198,7 +198,7 @@ test3()
 		return
 	fi
 	tst_res TINFO "Pinging 127.0.0.1 again"
-	ping -c 2 127.0.0.1 > tst_iptables.out 2>&1
+	ping -c 2 127.0.0.1 -W 1 -i 0 > tst_iptables.out 2>&1
 	if [ $? -ne 0 ]; then
 		tst_res TFAIL "iptables blocking ping requests. This is" \
 			      "expected behaviour on certain distributions" \
@@ -332,7 +332,7 @@ test6()
 	fi
 
 	tst_res TINFO "ping 127.0.0.1"
-	ping -c 10 127.0.0.1 > tst_iptables.out 2>&1
+	ping -c 10 127.0.0.1 -W 1 -i 0 > tst_iptables.out 2>&1
 	if [ $? -eq 0 ]; then
 		sleep 2
 		logcnt=$(dmesg | grep -c "$logprefix")
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 2/2 network/iptables: add new test for iptables-tranlsate and nft

* Reuse the test-case from iptables_tests by moving them in iptables_lib.sh.

* create nft rules with iptables-translate.

---
v2: * added nft setup with default input chain (in case firewalld not installed)
* removed dots in the messages
* removed redirection to file in cleanup

 runtest/net.tcp_cmds                         |   3 +-
 testcases/network/iptables/Makefile          |  23 +-
 testcases/network/iptables/iptables01.sh     |  18 +
 testcases/network/iptables/iptables_lib.sh   | 358 ++++++++++++++++++
 testcases/network/iptables/iptables_tests.sh | 366 -------------------
 testcases/network/iptables/nft01.sh          |  41 +++
 6 files changed, 422 insertions(+), 387 deletions(-)
 create mode 100755 testcases/network/iptables/iptables01.sh
 create mode 100755 testcases/network/iptables/iptables_lib.sh
 delete mode 100755 testcases/network/iptables/iptables_tests.sh
 create mode 100755 testcases/network/iptables/nft01.sh
runtest/net.tcp_cmds +2 -1
index 423a81756..afe6d7c71 100644
@@ -17,7 +17,8 @@ rsh rsh01.sh
 sendfile sendfile01.sh
 tcpdump tcpdump01.sh
 telnet telnet01.sh
-iptables iptables_tests.sh
+iptables iptables01.sh
+nft nft01.sh
 dhcpd dhcpd_tests.sh
 dnsmasq dnsmasq_tests.sh
 iproute ip_tests.sh
testcases/network/iptables/Makefile +3 -20
index afb96e9cb..1b42f25db 100644
@@ -1,29 +1,12 @@
-#
-#    network/iptables testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 #
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
 include $(top_srcdir)/include/mk/env_pre.mk
 
-INSTALL_TARGETS		:= iptables_tests.sh
+INSTALL_TARGETS		:= *.sh
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/network/iptables/iptables01.sh new file +18 -0
new file mode 100755
index 000000000..de38272e1
@@ -0,0 +1,18 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2018-2019 Oracle and/or its affiliates. All Rights Reserved.
+
+TST_CNT=6
+TST_SETUP="init"
+TST_TESTFUNC="test"
+TST_CLEANUP="cleanup"
+TST_NEEDS_TMPDIR=1
+TST_NEEDS_ROOT=1
+TST_NEEDS_CMDS="iptables grep ping telnet"
+TST_NEEDS_DRIVERS="ip_tables"
+use_iptables=1
+
+. iptables_lib.sh
+. tst_test.sh
+
+tst_run
testcases/network/iptables/iptables_lib.sh new file +358 -0

358 lines not on this page · raw message

testcases/network/iptables/iptables_tests.sh deleted +0 -366

366 lines not on this page · raw message

testcases/network/iptables/nft01.sh new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
2.20.1
#2 lore raw

PATCH v2 2/2 network/iptables: add new test for iptables-tranlsate and nft

Hi Alexey,

one more fix below.

Quoted 10 lines

+++ b/testcases/network/iptables/nft01.sh

testcases/network/iptables/nft01.sh new file +8 -0
@@ -0,0 +1,41 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2019 Oracle and/or its affiliates. All Rights Reserved.
+
+TST_CNT=6
+TST_SETUP="do_setup"
+TST_TESTFUNC="test"
+TST_CLEANUP="do_cleanup"

testcases/network/iptables/nft01.sh line 18

Quoted 10 lines
testcases/network/iptables/nft01.sh new file +10 -0
+TST_NEEDS_TMPDIR=1
+TST_NEEDS_ROOT=1
+TST_NEEDS_CMDS="nft iptables-translate grep ping telnet"
+TST_NEEDS_DRIVERS="nf_tables"
+use_iptables=0
+
+. iptables_lib.sh
+. tst_test.sh
+
+cleanup_tables=0

cleanup_table=0

Otherwise it fails:
nft01 1 TCONF: 'nft' not found /opt/ltp/testcases/bin/nft01.sh: line 37: [: -eq: unary operator expected

+ nit (code style comments, feel free to ignore):

1) I'd use empty variable instead of 0 (and [ "$cleanup_chain" = 1 ]), we discuss it with previous patches.

2) I'd move TST_CNT=6 to iptables_lib.sh (if test function adds more tests, all iptables_lib.sh uses would have to update it). Maybe all but these could be
there: TST_SETUP, TST_CLEANUP and use_iptables.

3) I'd move cleanup_table and cleanup_chain below use_iptables (or use_iptables below, just to have all 3 variables together).

Kind regards,
Petr

#3 lore raw

PATCH v2 2/2 network/iptables: add new test for iptables-tranlsate and nft

Quoted 5 lines · Petr Vorel

Hi Alexey,

one more fix below.

...

Quoted 14 lines

testcases/network/iptables/nft01.sh line 18

Quoted 4 lines

+. iptables_lib.sh
+. tst_test.sh

testcases/network/iptables/nft01.sh new file +2 -0
+
+cleanup_tables=0

cleanup_table=0

Otherwise it fails:
nft01 1 TCONF: 'nft' not found /opt/ltp/testcases/bin/nft01.sh: line 37: [: -eq: unary operator expected>
+ nit (code style comments, feel free to ignore):

1) I'd use empty variable instead of 0 (and [ "$cleanup_chain" = 1 ]), we discuss it with previous patches.

Quoted 6 lines

2) I'd move TST_CNT=6 to iptables_lib.sh (if test function adds more tests, all iptables_lib.sh uses would have to update it). Maybe all but these could be
there: TST_SETUP, TST_CLEANUP and use_iptables.

3) I'd move cleanup_table and cleanup_chain below use_iptables (or use_iptables below, just to have all 3 variables together).

Thanks Petr! Fixed them and applied the patches.

#4 lore raw

PATCH v2 2/2 network/iptables: add new test for iptables-tranlsate and nft

Hi Alexey,

Quoted 1 line

Thanks Petr! Fixed them and applied the patches.

Thanks for your work.

BTW even more setup could be moved into iptables_lib.sh. If you like this change, I can push it.

Kind regards,
Petr

 testcases/network/iptables/iptables01.sh   | 3 ---
 testcases/network/iptables/iptables_lib.sh | 8 ++++++++
 testcases/network/iptables/nft01.sh        | 3 ---
 3 files changed, 8 insertions(+), 6 deletions(-)
testcases/network/iptables/iptables01.sh +0 -3
index e6ed4afab..96d68e62e 100755
@@ -4,11 +4,8 @@
 
 TST_SETUP="init"
 TST_CLEANUP="cleanup"
-TST_NEEDS_CMDS="iptables grep ping telnet"
-TST_NEEDS_DRIVERS="ip_tables"
 use_iptables=1
 
 . iptables_lib.sh
-. tst_test.sh
 
 tst_run
testcases/network/iptables/iptables_lib.sh +8 -0
index b098479e4..87f33dfca 100755
@@ -12,11 +12,19 @@ TST_NEEDS_TMPDIR=1
 TST_NEEDS_ROOT=1
 
 if [ "$use_iptables" = 1 ]; then
+	cmds="iptables"
 	toolname=iptables
+	TST_NEEDS_DRIVERS="ip_tables"
 else
+	cmds="nft iptables-translate"
 	toolname=nft
+	TST_NEEDS_DRIVERS="nf_tables"
 fi
 
+TST_NEEDS_CMDS="$cmds grep ping telnet"
+
+. tst_test.sh
+
 NFRUN()
 {
 	local rule
testcases/network/iptables/nft01.sh +0 -3
index 9bd10a7f5..6cbd7a3a6 100755
@@ -4,14 +4,11 @@
 
 TST_SETUP="do_setup"
 TST_CLEANUP="do_cleanup"
-TST_NEEDS_CMDS="nft iptables-translate grep ping telnet"
-TST_NEEDS_DRIVERS="nf_tables"
 use_iptables=0
 cleanup_table=0
 cleanup_chain=0
 
 . iptables_lib.sh
-. tst_test.sh
 
 do_setup()
 {
Signature · 1 line
2.24.0
#5 lore raw

PATCH v2 2/2 network/iptables: add new test for iptables-tranlsate and nft

Hi Petr,

Quoted 7 lines · Petr Vorel

Hi Alexey,

Quoted 1 line

Thanks Petr! Fixed them and applied the patches.

Thanks for your work.

BTW even more setup could be moved into iptables_lib.sh. If you like this change, I can push it.

No objections. I thought it is better to keep these TST_* variables per test, in the header, rather than searching in the lib... but looks like it might save some duplication.

Quoted 69 lines

Kind regards,
Petr

 testcases/network/iptables/iptables01.sh   | 3 ---
 testcases/network/iptables/iptables_lib.sh | 8 ++++++++
 testcases/network/iptables/nft01.sh        | 3 ---
 3 files changed, 8 insertions(+), 6 deletions(-)
testcases/network/iptables/iptables01.sh +0 -3
index e6ed4afab..96d68e62e 100755
@@ -4,11 +4,8 @@
 
 TST_SETUP="init"
 TST_CLEANUP="cleanup"
-TST_NEEDS_CMDS="iptables grep ping telnet"
-TST_NEEDS_DRIVERS="ip_tables"
 use_iptables=1
 
 . iptables_lib.sh
-. tst_test.sh
 
 tst_run
testcases/network/iptables/iptables_lib.sh +8 -0
index b098479e4..87f33dfca 100755
@@ -12,11 +12,19 @@ TST_NEEDS_TMPDIR=1
 TST_NEEDS_ROOT=1
 
 if [ "$use_iptables" = 1 ]; then
+	cmds="iptables"
 	toolname=iptables
+	TST_NEEDS_DRIVERS="ip_tables"
 else
+	cmds="nft iptables-translate"
 	toolname=nft
+	TST_NEEDS_DRIVERS="nf_tables"
 fi
 
+TST_NEEDS_CMDS="$cmds grep ping telnet"
+
+. tst_test.sh
+
 NFRUN()
 {
 	local rule
testcases/network/iptables/nft01.sh +0 -3
index 9bd10a7f5..6cbd7a3a6 100755
@@ -4,14 +4,11 @@
 
 TST_SETUP="do_setup"
 TST_CLEANUP="do_cleanup"
-TST_NEEDS_CMDS="nft iptables-translate grep ping telnet"
-TST_NEEDS_DRIVERS="nf_tables"
 use_iptables=0
 cleanup_table=0
 cleanup_chain=0
 
 . iptables_lib.sh
-. tst_test.sh
 
 do_setup()
 {
#6 lore raw

PATCH v2 2/2 network/iptables: add new test for iptables-tranlsate and nft

Hi Alexey,

Quoted 6 lines
Quoted 2 lines

BTW even more setup could be moved into iptables_lib.sh. If you like this change, I can push it.

No objections. I thought it is better to keep these TST_* variables per test, in the header, rather than searching in the lib... but looks like it might save some duplication.

The main reason for me to move TST_* variables into library is to keep code together, where it's used.
The downside of it is that these variables may be accidentally overwritten by setup in test. That's why I used default values, which can be overwritten in if-lib.sh.

I'll send a patch, feel free to not ack that (agree, that it's a syntax optimization, the test itself is what matters).

Kind regards,
Petr