Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: nf_tables: nft_fib_ipv6: fix VRF ipv4/ipv6 result discrepancy

With a VRF, ipv4 and ipv6 FIB expression behave differently.

fib daddr . iif oif

Will return the input interface name for ipv4, but the real device
for ipv6. Example:

If VRF device name is tvrf and real (incoming) device is veth0.
First round is ok, both ipv4 and ipv6 will yield 'veth0'.

But in the second round (incoming device will be set to "tvrf"), ipv4
will yield "tvrf" whereas ipv6 returns "veth0" for the second round too.

This makes ipv6 behave like ipv4.

A followup patch will add a test case for this, without this change
it will fail with:
get element inet t fibif6iif { tvrf . dead:1::99 . tvrf }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FAIL: did not find tvrf . dead:1::99 . tvrf in fibif6iif

Alternatively we could either not do anything at all or change
ipv4 to also return the lower/real device, however, nft (userspace)
doc says "iif: if fib lookup provides a route then check its output
interface is identical to the packets input interface." which is what
the nft fib ipv4 behaviour is.

Fixes: f6d0cbcf09c5 ("netfilter: nf_tables: add fib expression")
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Florian Westphal and committed by
Pablo Neira Ayuso
8b53f46e 98287045

+9 -4
+9 -4
net/ipv6/netfilter/nft_fib_ipv6.c
··· 158 158 { 159 159 const struct nft_fib *priv = nft_expr_priv(expr); 160 160 int noff = skb_network_offset(pkt->skb); 161 + const struct net_device *found = NULL; 161 162 const struct net_device *oif = NULL; 162 163 u32 *dest = &regs->data[priv->dreg]; 163 164 struct ipv6hdr *iph, _iph; ··· 204 203 if (rt->rt6i_flags & (RTF_REJECT | RTF_ANYCAST | RTF_LOCAL)) 205 204 goto put_rt_err; 206 205 207 - if (oif && oif != rt->rt6i_idev->dev && 208 - l3mdev_master_ifindex_rcu(rt->rt6i_idev->dev) != oif->ifindex) 209 - goto put_rt_err; 206 + if (!oif) { 207 + found = rt->rt6i_idev->dev; 208 + } else { 209 + if (oif == rt->rt6i_idev->dev || 210 + l3mdev_master_ifindex_rcu(rt->rt6i_idev->dev) == oif->ifindex) 211 + found = oif; 212 + } 210 213 211 - nft_fib_store_result(dest, priv, rt->rt6i_idev->dev); 214 + nft_fib_store_result(dest, priv, found); 212 215 put_rt_err: 213 216 ip6_rt_put(rt); 214 217 }