netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nf 1/2] netfilter: fib: check correct rtable in vrf setups
@ 2024-10-09  7:19 Florian Westphal
  2024-10-09  7:19 ` [PATCH nf 2/2] selftests: netfilter: conntrack_vrf.sh: add fib test case Florian Westphal
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Florian Westphal @ 2024-10-09  7:19 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal

We need to init l3mdev unconditionally, else main routing table is searched
and incorrect result is returned unless strict (iif keyword) matching is
requested.

Next patch adds a selftest for this.

Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1761
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/ipv4/netfilter/nft_fib_ipv4.c | 4 +---
 net/ipv6/netfilter/nft_fib_ipv6.c | 5 +++--
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/net/ipv4/netfilter/nft_fib_ipv4.c b/net/ipv4/netfilter/nft_fib_ipv4.c
index 00da1332bbf1..09fff5d424ef 100644
--- a/net/ipv4/netfilter/nft_fib_ipv4.c
+++ b/net/ipv4/netfilter/nft_fib_ipv4.c
@@ -65,6 +65,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
 		.flowi4_scope = RT_SCOPE_UNIVERSE,
 		.flowi4_iif = LOOPBACK_IFINDEX,
 		.flowi4_uid = sock_net_uid(nft_net(pkt), NULL),
+		.flowi4_l3mdev = l3mdev_master_ifindex_rcu(nft_in(pkt)),
 	};
 	const struct net_device *oif;
 	const struct net_device *found;
@@ -83,9 +84,6 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
 	else
 		oif = NULL;
 
-	if (priv->flags & NFTA_FIB_F_IIF)
-		fl4.flowi4_l3mdev = l3mdev_master_ifindex_rcu(oif);
-
 	if (nft_hook(pkt) == NF_INET_PRE_ROUTING &&
 	    nft_fib_is_loopback(pkt->skb, nft_in(pkt))) {
 		nft_fib_store_result(dest, priv, nft_in(pkt));
diff --git a/net/ipv6/netfilter/nft_fib_ipv6.c b/net/ipv6/netfilter/nft_fib_ipv6.c
index 36dc14b34388..c9f1634b3838 100644
--- a/net/ipv6/netfilter/nft_fib_ipv6.c
+++ b/net/ipv6/netfilter/nft_fib_ipv6.c
@@ -41,8 +41,6 @@ static int nft_fib6_flowi_init(struct flowi6 *fl6, const struct nft_fib *priv,
 	if (ipv6_addr_type(&fl6->daddr) & IPV6_ADDR_LINKLOCAL) {
 		lookup_flags |= RT6_LOOKUP_F_IFACE;
 		fl6->flowi6_oif = get_ifindex(dev ? dev : pkt->skb->dev);
-	} else if (priv->flags & NFTA_FIB_F_IIF) {
-		fl6->flowi6_l3mdev = l3mdev_master_ifindex_rcu(dev);
 	}
 
 	if (ipv6_addr_type(&fl6->saddr) & IPV6_ADDR_UNICAST)
@@ -75,6 +73,8 @@ static u32 __nft_fib6_eval_type(const struct nft_fib *priv,
 	else if (priv->flags & NFTA_FIB_F_OIF)
 		dev = nft_out(pkt);
 
+	fl6.flowi6_l3mdev = l3mdev_master_ifindex_rcu(dev);
+
 	nft_fib6_flowi_init(&fl6, priv, pkt, dev, iph);
 
 	if (dev && nf_ipv6_chk_addr(nft_net(pkt), &fl6.daddr, dev, true))
@@ -165,6 +165,7 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,
 		.flowi6_iif = LOOPBACK_IFINDEX,
 		.flowi6_proto = pkt->tprot,
 		.flowi6_uid = sock_net_uid(nft_net(pkt), NULL),
+		.flowi6_l3mdev = l3mdev_master_ifindex_rcu(nft_in(pkt)),
 	};
 	struct rt6_info *rt;
 	int lookup_flags;
-- 
2.46.2


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

* [PATCH nf 2/2] selftests: netfilter: conntrack_vrf.sh: add fib test case
  2024-10-09  7:19 [PATCH nf 1/2] netfilter: fib: check correct rtable in vrf setups Florian Westphal
@ 2024-10-09  7:19 ` Florian Westphal
  2024-10-09  9:08 ` [PATCH nf 1/2] netfilter: fib: check correct rtable in vrf setups Pablo Neira Ayuso
  2024-10-09 21:26 ` Pablo Neira Ayuso
  2 siblings, 0 replies; 4+ messages in thread
From: Florian Westphal @ 2024-10-09  7:19 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal

  meta iifname veth0 ip daddr ... fib daddr oif

... is expected to return "dummy0" interface which is part of same vrf
as veth0.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 .../selftests/net/netfilter/conntrack_vrf.sh  | 33 +++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/tools/testing/selftests/net/netfilter/conntrack_vrf.sh b/tools/testing/selftests/net/netfilter/conntrack_vrf.sh
index 073e8e62d350..e95ecb37c2b1 100755
--- a/tools/testing/selftests/net/netfilter/conntrack_vrf.sh
+++ b/tools/testing/selftests/net/netfilter/conntrack_vrf.sh
@@ -32,6 +32,7 @@ source lib.sh
 
 IP0=172.30.30.1
 IP1=172.30.30.2
+DUMMYNET=10.9.9
 PFXL=30
 ret=0
 
@@ -54,6 +55,7 @@ setup_ns ns0 ns1
 ip netns exec "$ns0" sysctl -q -w net.ipv4.conf.default.rp_filter=0
 ip netns exec "$ns0" sysctl -q -w net.ipv4.conf.all.rp_filter=0
 ip netns exec "$ns0" sysctl -q -w net.ipv4.conf.all.rp_filter=0
+ip netns exec "$ns0" sysctl -q -w net.ipv4.conf.all.forwarding=1
 
 if ! ip link add veth0 netns "$ns0" type veth peer name veth0 netns "$ns1" > /dev/null 2>&1; then
 	echo "SKIP: Could not add veth device"
@@ -65,13 +67,18 @@ if ! ip -net "$ns0" li add tvrf type vrf table 9876; then
 	exit $ksft_skip
 fi
 
+ip -net "$ns0" link add dummy0 type dummy
+
 ip -net "$ns0" li set veth0 master tvrf
+ip -net "$ns0" li set dummy0 master tvrf
 ip -net "$ns0" li set tvrf up
 ip -net "$ns0" li set veth0 up
+ip -net "$ns0" li set dummy0 up
 ip -net "$ns1" li set veth0 up
 
 ip -net "$ns0" addr add $IP0/$PFXL dev veth0
 ip -net "$ns1" addr add $IP1/$PFXL dev veth0
+ip -net "$ns0" addr add $DUMMYNET.1/$PFXL dev dummy0
 
 listener_ready()
 {
@@ -212,9 +219,35 @@ EOF
 	fi
 }
 
+test_fib()
+{
+ip netns exec "$ns0" nft -f - <<EOF
+flush ruleset
+table ip t {
+	counter fibcount { }
+
+	chain prerouting {
+		type filter hook prerouting priority 0;
+		meta iifname veth0 ip daddr $DUMMYNET.2 fib daddr oif dummy0 counter name fibcount notrack
+	}
+}
+EOF
+	ip -net "$ns1" route add 10.9.9.0/24 via "$IP0" dev veth0
+	ip netns exec "$ns1" ping -q -w 1 -c 1 "$DUMMYNET".2 > /dev/null
+
+	if ip netns exec "$ns0" nft list counter t fibcount | grep -q "packets 1"; then
+		echo "PASS: fib lookup returned exepected output interface"
+	else
+		echo "FAIL: fib lookup did not return exepected output interface"
+		ret=1
+		return
+	fi
+}
+
 test_ct_zone_in
 test_masquerade_vrf "default"
 test_masquerade_vrf "pfifo"
 test_masquerade_veth
+test_fib
 
 exit $ret
-- 
2.46.2


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

* Re: [PATCH nf 1/2] netfilter: fib: check correct rtable in vrf setups
  2024-10-09  7:19 [PATCH nf 1/2] netfilter: fib: check correct rtable in vrf setups Florian Westphal
  2024-10-09  7:19 ` [PATCH nf 2/2] selftests: netfilter: conntrack_vrf.sh: add fib test case Florian Westphal
@ 2024-10-09  9:08 ` Pablo Neira Ayuso
  2024-10-09 21:26 ` Pablo Neira Ayuso
  2 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2024-10-09  9:08 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel

On Wed, Oct 09, 2024 at 09:19:02AM +0200, Florian Westphal wrote:
> We need to init l3mdev unconditionally, else main routing table is searched
> and incorrect result is returned unless strict (iif keyword) matching is
> requested.
> 
> Next patch adds a selftest for this.

Fixes: 2a8a7c0eaa87 ("netfilter: nft_fib: Fix for rpath check with VRF devices")

> Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1761
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
>  net/ipv4/netfilter/nft_fib_ipv4.c | 4 +---
>  net/ipv6/netfilter/nft_fib_ipv6.c | 5 +++--
>  2 files changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/net/ipv4/netfilter/nft_fib_ipv4.c b/net/ipv4/netfilter/nft_fib_ipv4.c
> index 00da1332bbf1..09fff5d424ef 100644
> --- a/net/ipv4/netfilter/nft_fib_ipv4.c
> +++ b/net/ipv4/netfilter/nft_fib_ipv4.c
> @@ -65,6 +65,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
>  		.flowi4_scope = RT_SCOPE_UNIVERSE,
>  		.flowi4_iif = LOOPBACK_IFINDEX,
>  		.flowi4_uid = sock_net_uid(nft_net(pkt), NULL),
> +		.flowi4_l3mdev = l3mdev_master_ifindex_rcu(nft_in(pkt)),
>  	};
>  	const struct net_device *oif;
>  	const struct net_device *found;
> @@ -83,9 +84,6 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
>  	else
>  		oif = NULL;
>  
> -	if (priv->flags & NFTA_FIB_F_IIF)
> -		fl4.flowi4_l3mdev = l3mdev_master_ifindex_rcu(oif);
> -
>  	if (nft_hook(pkt) == NF_INET_PRE_ROUTING &&
>  	    nft_fib_is_loopback(pkt->skb, nft_in(pkt))) {
>  		nft_fib_store_result(dest, priv, nft_in(pkt));
> diff --git a/net/ipv6/netfilter/nft_fib_ipv6.c b/net/ipv6/netfilter/nft_fib_ipv6.c
> index 36dc14b34388..c9f1634b3838 100644
> --- a/net/ipv6/netfilter/nft_fib_ipv6.c
> +++ b/net/ipv6/netfilter/nft_fib_ipv6.c
> @@ -41,8 +41,6 @@ static int nft_fib6_flowi_init(struct flowi6 *fl6, const struct nft_fib *priv,
>  	if (ipv6_addr_type(&fl6->daddr) & IPV6_ADDR_LINKLOCAL) {
>  		lookup_flags |= RT6_LOOKUP_F_IFACE;
>  		fl6->flowi6_oif = get_ifindex(dev ? dev : pkt->skb->dev);
> -	} else if (priv->flags & NFTA_FIB_F_IIF) {
> -		fl6->flowi6_l3mdev = l3mdev_master_ifindex_rcu(dev);
>  	}
>  
>  	if (ipv6_addr_type(&fl6->saddr) & IPV6_ADDR_UNICAST)
> @@ -75,6 +73,8 @@ static u32 __nft_fib6_eval_type(const struct nft_fib *priv,
>  	else if (priv->flags & NFTA_FIB_F_OIF)
>  		dev = nft_out(pkt);
>  
> +	fl6.flowi6_l3mdev = l3mdev_master_ifindex_rcu(dev);
> +
>  	nft_fib6_flowi_init(&fl6, priv, pkt, dev, iph);
>  
>  	if (dev && nf_ipv6_chk_addr(nft_net(pkt), &fl6.daddr, dev, true))
> @@ -165,6 +165,7 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,
>  		.flowi6_iif = LOOPBACK_IFINDEX,
>  		.flowi6_proto = pkt->tprot,
>  		.flowi6_uid = sock_net_uid(nft_net(pkt), NULL),
> +		.flowi6_l3mdev = l3mdev_master_ifindex_rcu(nft_in(pkt)),
>  	};
>  	struct rt6_info *rt;
>  	int lookup_flags;
> -- 
> 2.46.2
> 
> 

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

* Re: [PATCH nf 1/2] netfilter: fib: check correct rtable in vrf setups
  2024-10-09  7:19 [PATCH nf 1/2] netfilter: fib: check correct rtable in vrf setups Florian Westphal
  2024-10-09  7:19 ` [PATCH nf 2/2] selftests: netfilter: conntrack_vrf.sh: add fib test case Florian Westphal
  2024-10-09  9:08 ` [PATCH nf 1/2] netfilter: fib: check correct rtable in vrf setups Pablo Neira Ayuso
@ 2024-10-09 21:26 ` Pablo Neira Ayuso
  2 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2024-10-09 21:26 UTC (permalink / raw)
  To: Florian Westphal; +Cc: netfilter-devel

On Wed, Oct 09, 2024 at 09:19:02AM +0200, Florian Westphal wrote:
> We need to init l3mdev unconditionally, else main routing table is searched
> and incorrect result is returned unless strict (iif keyword) matching is
> requested.
> 
> Next patch adds a selftest for this.

Series applied, thanks

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

end of thread, other threads:[~2024-10-09 21:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-09  7:19 [PATCH nf 1/2] netfilter: fib: check correct rtable in vrf setups Florian Westphal
2024-10-09  7:19 ` [PATCH nf 2/2] selftests: netfilter: conntrack_vrf.sh: add fib test case Florian Westphal
2024-10-09  9:08 ` [PATCH nf 1/2] netfilter: fib: check correct rtable in vrf setups Pablo Neira Ayuso
2024-10-09 21:26 ` 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).