netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org
Subject: [PATCH net-next 11/11] selftests: netfilter: add fib expression forward test case
Date: Mon, 11 Apr 2022 12:27:44 +0200	[thread overview]
Message-ID: <20220411102744.282101-12-pablo@netfilter.org> (raw)
In-Reply-To: <20220411102744.282101-1-pablo@netfilter.org>

From: Florian Westphal <fw@strlen.de>

Its now possible to use fib expression in the forward chain (where both
the input and output interfaces are known).

Add a simple test case for this.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 tools/testing/selftests/netfilter/nft_fib.sh | 50 ++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/tools/testing/selftests/netfilter/nft_fib.sh b/tools/testing/selftests/netfilter/nft_fib.sh
index 695a1958723f..fd76b69635a4 100755
--- a/tools/testing/selftests/netfilter/nft_fib.sh
+++ b/tools/testing/selftests/netfilter/nft_fib.sh
@@ -66,6 +66,20 @@ table inet filter {
 EOF
 }
 
+load_pbr_ruleset() {
+	local netns=$1
+
+ip netns exec ${netns} nft -f /dev/stdin <<EOF
+table inet filter {
+	chain forward {
+		type filter hook forward priority raw;
+		fib saddr . iif oif gt 0 accept
+		log drop
+	}
+}
+EOF
+}
+
 load_ruleset_count() {
 	local netns=$1
 
@@ -219,4 +233,40 @@ sleep 2
 ip netns exec ${ns1} ping -c 3 -q 1c3::c01d > /dev/null
 check_fib_counter 3 ${nsrouter} 1c3::c01d || exit 1
 
+# delete all rules
+ip netns exec ${ns1} nft flush ruleset
+ip netns exec ${ns2} nft flush ruleset
+ip netns exec ${nsrouter} nft flush ruleset
+
+ip -net ${ns1} addr add 10.0.1.99/24 dev eth0
+ip -net ${ns1} addr add dead:1::99/64 dev eth0
+
+ip -net ${ns1} addr del 10.0.2.99/24 dev eth0
+ip -net ${ns1} addr del dead:2::99/64 dev eth0
+
+ip -net ${nsrouter} addr del dead:2::1/64 dev veth0
+
+# ... pbr ruleset for the router, check iif+oif.
+load_pbr_ruleset ${nsrouter}
+if [ $? -ne 0 ] ; then
+	echo "SKIP: Could not load fib forward ruleset"
+	exit $ksft_skip
+fi
+
+ip -net ${nsrouter} rule add from all table 128
+ip -net ${nsrouter} rule add from all iif veth0 table 129
+ip -net ${nsrouter} route add table 128 to 10.0.1.0/24 dev veth0
+ip -net ${nsrouter} route add table 129 to 10.0.2.0/24 dev veth1
+
+# drop main ipv4 table
+ip -net ${nsrouter} -4 rule delete table main
+
+test_ping 10.0.2.99 dead:2::99
+if [ $? -ne 0 ] ; then
+	ip -net ${nsrouter} nft list ruleset
+	echo "FAIL: fib mismatch in pbr setup"
+	exit 1
+fi
+
+echo "PASS: fib expression forward check with policy based routing"
 exit 0
-- 
2.30.2


      parent reply	other threads:[~2022-04-11 10:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-11 10:27 [PATCH net-next 00/11] Netfilter updates for net-next Pablo Neira Ayuso
2022-04-11 10:27 ` [PATCH net-next 01/11] netfilter: nf_tables: replace unnecessary use of list_for_each_entry_continue() Pablo Neira Ayuso
2022-04-11 10:50   ` patchwork-bot+netdevbpf
2022-04-11 10:27 ` [PATCH net-next 02/11] netfilter: ecache: move to separate structure Pablo Neira Ayuso
2022-04-11 10:27 ` [PATCH net-next 03/11] netfilter: conntrack: split inner loop of list dumping to own function Pablo Neira Ayuso
2022-04-11 10:27 ` [PATCH net-next 04/11] netfilter: cttimeout: inc/dec module refcount per object, not per use refcount Pablo Neira Ayuso
2022-04-11 10:27 ` [PATCH net-next 05/11] netfilter: nf_log_syslog: Merge MAC header dumpers Pablo Neira Ayuso
2022-04-11 10:27 ` [PATCH net-next 06/11] netfilter: nf_log_syslog: Don't ignore unknown protocols Pablo Neira Ayuso
2022-04-11 10:27 ` [PATCH net-next 07/11] netfilter: nf_log_syslog: Consolidate entry checks Pablo Neira Ayuso
2022-04-11 10:27 ` [PATCH net-next 08/11] netfilter: bitwise: replace hard-coded size with `sizeof` expression Pablo Neira Ayuso
2022-04-11 10:27 ` [PATCH net-next 09/11] netfilter: bitwise: improve error goto labels Pablo Neira Ayuso
2022-04-11 10:27 ` [PATCH net-next 10/11] netfilter: nft_fib: reverse path filter for policy-based routing on iif Pablo Neira Ayuso
2022-04-11 10:27 ` Pablo Neira Ayuso [this message]

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=20220411102744.282101-12-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --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 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).