All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Andrii Melnychenko <a.melnychenko@vyos.io>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH 1/1] tests: shell: Updated nat_ftp tests
Date: Mon, 27 Oct 2025 20:02:35 +0100	[thread overview]
Message-ID: <aP_By5SYOFlM9LmZ@strlen.de> (raw)
In-Reply-To: <20251027113907.451391-1-a.melnychenko@vyos.io>

Andrii Melnychenko <a.melnychenko@vyos.io> wrote:
> Added DNAT and SNAT only tests.
> There was an issue with DNAT that was not covered by tests.
> DNAT misses setting up the `seqadj`, which leads to FTP failures.
> The fix for DNAT has already been proposed to the kernel.

Thanks, could you please send a v2 that splits the refactoring
from the new test case (i.e. two changes)?

> Acked-by: Florian Westphal <fw@strlen.de>

This should not be here unless you would be re-sending a v2
of a patch that is almost 100% the same as the one I acked before.

And I don't recall acking this change, so please don't add this
yourself.

> +	# flush and add FTP helper
> +	read -r -d '' str <<-EOF
>  	flush ruleset
>  	table ip6 ftp_helper_nat_test {
>  		ct helper ftp-standard {
>  			type "ftp" protocol tcp;
>  		}
> +	EOF
> +	ruleset+=$str$'\n'

I'd suggest to just use multiple nft -f invocations
instead of this.

> +	# add DNAT
> +	if [[ $add_dnat -ne 0 ]]; then
> +		read -r -d '' str <<-EOF
>  		chain PRE-dnat {
>  			type nat hook prerouting priority dstnat; policy accept;
>  			# Dnat the control connection, data connection will be automaticly NATed.
>  			ip6 daddr ${ip_rc} counter ip6 nexthdr tcp tcp dport 2121 counter dnat ip6 to [${ip_sr}]:21
>  		}
> +		EOF
> +		ruleset+=$str$'\n'
> +	fi

Just move this from reload_ruleset to a helper function.

> @@ -111,18 +125,51 @@ reload_ruleset()
>  			ip6 nexthdr tcp ct state established counter accept
>  			ip6 nexthdr tcp ct state related     counter log accept
>  		}
> +	EOF
> +	ruleset+=$str$'\n'
>  
> +	# add SNAT
> +	if [[ $add_snat -ne 0 ]]; then
> +		read -r -d '' str <<-EOF

Same here, just omit this.

> +reload_ruleset()
> +{
> +	reload_ruleset_base 1 1
> +}

Then this would be something like:

reload_ruleset_dnat()
{
	reload_ruleset
	load_dnat
}

reload_ruleset_snat()
{
	reload_ruleset
	load_snat
}

reload_ruleset_allnat
{
	reload_ruleset
	load_snat
	load_dnat
}

(or similar naming).  I find that easier to follow, esp. because this
allows a refactor patch before adding the _snat/_dnat tests.

The reload_ruleset -> reload_ruleset_base rename is also ok if you
prefer that.

> +
>  dd if=/dev/urandom of="$INFILE" bs=4096 count=1 2>/dev/null
>  chmod 755 $INFILE
> +
> +mkdir -p /var/run/vsftpd/empty/
> +cp $INFILE /var/run/vsftpd/empty/

I don't understand this change, how is that related?

> +reload_ruleset_dnat_only
> +
> +ip netns exec $S tcpdump -q --immediate-mode -Ui s_r -w ${PCAP} 2> /dev/null &
> +pid=$!
> +sleep 0.5
> +ip netns exec $C curl --no-progress-meter -P - --connect-timeout 5 ftp://[${ip_rc}]:2121/$(basename $INFILE) -o $OUTFILE
> +assert_pass "curl ftp active mode "

Not a requirement, but there is a lot of repitition
of this sequence now, albeit with small changes.

Perhaps this should be in a reuseable function first
before adding the new test cases to this script.

> +ip netns exec $S tcpdump -q --immediate-mode -Ui s_r -w ${PCAP} 2> /dev/null &
> +pid=$!
> +sleep 0.5
> +ip netns exec $C curl --no-progress-meter -P - --connect-timeout 5 ftp://[${ip_sr}]:21/$(basename $INFILE) -o $OUTFILE
> +assert_pass "curl ftp active mode "
> +
> +cmp "$INFILE" "$OUTFILE"
> +assert_pass "FTP Active mode: in and output files remain the same when FTP traffic passes through NAT."
> +
> +kill $pid; sync

I don't understand this 'sync' (I know its already there is source).
It seems its not needed?

  reply	other threads:[~2025-10-27 19:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-27 11:39 [PATCH 1/1] tests: shell: Updated nat_ftp tests Andrii Melnychenko
2025-10-27 19:02 ` Florian Westphal [this message]
2025-10-28 14:06   ` Andrii Melnychenko
2025-10-28 14:11     ` Florian Westphal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aP_By5SYOFlM9LmZ@strlen.de \
    --to=fw@strlen.de \
    --cc=a.melnychenko@vyos.io \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.