netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nf] selftests: nft_nat: ensuring the listening side is up before starting the client
@ 2023-02-27  9:36 Hangbin Liu
  2023-03-01 16:23 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 2+ messages in thread
From: Hangbin Liu @ 2023-02-27  9:36 UTC (permalink / raw)
  To: netfilter-devel
  Cc: Yi Chen, Florian Westphal, Pablo Neira Ayuso, netdev,
	linux-kselftest, Hangbin Liu

The test_local_dnat_portonly() function initiates the client-side as
soon as it sets the listening side to the background. This could lead to
a race condition where the server may not be ready to listen. To ensure
that the server-side is up and running before initiating the
client-side, a delay is introduced to the test_local_dnat_portonly()
function.

Before the fix:
  # ./nft_nat.sh
  PASS: netns routing/connectivity: ns0-rthlYrBU can reach ns1-rthlYrBU and ns2-rthlYrBU
  PASS: ping to ns1-rthlYrBU was ip NATted to ns2-rthlYrBU
  PASS: ping to ns1-rthlYrBU OK after ip nat output chain flush
  PASS: ipv6 ping to ns1-rthlYrBU was ip6 NATted to ns2-rthlYrBU
  2023/02/27 04:11:03 socat[6055] E connect(5, AF=2 10.0.1.99:2000, 16): Connection refused
  ERROR: inet port rewrite

After the fix:
  # ./nft_nat.sh
  PASS: netns routing/connectivity: ns0-9sPJV6JJ can reach ns1-9sPJV6JJ and ns2-9sPJV6JJ
  PASS: ping to ns1-9sPJV6JJ was ip NATted to ns2-9sPJV6JJ
  PASS: ping to ns1-9sPJV6JJ OK after ip nat output chain flush
  PASS: ipv6 ping to ns1-9sPJV6JJ was ip6 NATted to ns2-9sPJV6JJ
  PASS: inet port rewrite without l3 address

Fixes: 282e5f8fe907 ("netfilter: nat: really support inet nat without l3 address")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 tools/testing/selftests/netfilter/nft_nat.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/netfilter/nft_nat.sh b/tools/testing/selftests/netfilter/nft_nat.sh
index 924ecb3f1f73..dd40d9f6f259 100755
--- a/tools/testing/selftests/netfilter/nft_nat.sh
+++ b/tools/testing/selftests/netfilter/nft_nat.sh
@@ -404,6 +404,8 @@ EOF
 	echo SERVER-$family | ip netns exec "$ns1" timeout 5 socat -u STDIN TCP-LISTEN:2000 &
 	sc_s=$!
 
+	sleep 1
+
 	result=$(ip netns exec "$ns0" timeout 1 socat TCP:$daddr:2000 STDOUT)
 
 	if [ "$result" = "SERVER-inet" ];then
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH nf] selftests: nft_nat: ensuring the listening side is up before starting the client
  2023-02-27  9:36 [PATCH nf] selftests: nft_nat: ensuring the listening side is up before starting the client Hangbin Liu
@ 2023-03-01 16:23 ` Pablo Neira Ayuso
  0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2023-03-01 16:23 UTC (permalink / raw)
  To: Hangbin Liu
  Cc: netfilter-devel, Yi Chen, Florian Westphal, netdev, linux-kselftest

On Mon, Feb 27, 2023 at 05:36:46PM +0800, Hangbin Liu wrote:
> The test_local_dnat_portonly() function initiates the client-side as
> soon as it sets the listening side to the background. This could lead to
> a race condition where the server may not be ready to listen. To ensure
> that the server-side is up and running before initiating the
> client-side, a delay is introduced to the test_local_dnat_portonly()
> function.
> 
> Before the fix:
>   # ./nft_nat.sh
>   PASS: netns routing/connectivity: ns0-rthlYrBU can reach ns1-rthlYrBU and ns2-rthlYrBU
>   PASS: ping to ns1-rthlYrBU was ip NATted to ns2-rthlYrBU
>   PASS: ping to ns1-rthlYrBU OK after ip nat output chain flush
>   PASS: ipv6 ping to ns1-rthlYrBU was ip6 NATted to ns2-rthlYrBU
>   2023/02/27 04:11:03 socat[6055] E connect(5, AF=2 10.0.1.99:2000, 16): Connection refused
>   ERROR: inet port rewrite
> 
> After the fix:
>   # ./nft_nat.sh
>   PASS: netns routing/connectivity: ns0-9sPJV6JJ can reach ns1-9sPJV6JJ and ns2-9sPJV6JJ
>   PASS: ping to ns1-9sPJV6JJ was ip NATted to ns2-9sPJV6JJ
>   PASS: ping to ns1-9sPJV6JJ OK after ip nat output chain flush
>   PASS: ipv6 ping to ns1-9sPJV6JJ was ip6 NATted to ns2-9sPJV6JJ
>   PASS: inet port rewrite without l3 address

Applied, thanks

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-01 16:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-27  9:36 [PATCH nf] selftests: nft_nat: ensuring the listening side is up before starting the client Hangbin Liu
2023-03-01 16:23 ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).