From: Simon Horman <horms@kernel.org>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net,
netdev@vger.kernel.org, kuba@kernel.org, pabeni@redhat.com,
edumazet@google.com, fw@strlen.de
Subject: Re: [PATCH net-next 06/26] netfilter: nf_tables: nft_fib: consistent l3mdev handling
Date: Fri, 23 May 2025 08:35:24 +0100 [thread overview]
Message-ID: <20250523073524.GR365796@horms.kernel.org> (raw)
In-Reply-To: <20250522165238.378456-7-pablo@netfilter.org>
On Thu, May 22, 2025 at 06:52:18PM +0200, Pablo Neira Ayuso wrote:
> From: Florian Westphal <fw@strlen.de>
>
> fib has two modes:
> 1. Obtain output device according to source or destination address
> 2. Obtain the type of the address, e.g. local, unicast, multicast.
>
> 'fib daddr type' should return 'local' if the address is configured
> in this netns or unicast otherwise.
>
> 'fib daddr . iif type' should return 'local' if the address is configured
> on the input interface or unicast otherwise, i.e. more restrictive.
>
> However, if the interface is part of a VRF, then 'fib daddr type'
> returns unicast even if the address is configured on the incoming
> interface.
>
> This is broken for both ipv4 and ipv6.
>
> In the ipv4 case, inet_dev_addr_type must only be used if the
> 'iif' or 'oif' (strict mode) was requested.
>
> Else inet_addr_type_dev_table() needs to be used and the correct
> dev argument must be passed as well so the correct fib (vrf) table
> is used.
>
> In the ipv6 case, the bug is similar, without strict mode, dev is NULL
> so .flowi6_l3mdev will be set to 0.
>
> Add a new 'nft_fib_l3mdev_master_ifindex_rcu()' helper and use that
> to init the .l3mdev structure member.
>
> For ipv6, use it from nft_fib6_flowi_init() which gets called from
> both the 'type' and the 'route' mode eval functions.
>
> This provides consistent behaviour for all modes for both ipv4 and ipv6:
> If strict matching is requested, the input respectively output device
> of the netfilter hooks is used.
>
> Otherwise, use skb->dev to obtain the l3mdev ifindex.
>
> Without this, most type checks in updated nft_fib.sh selftest fail:
>
> FAIL: did not find veth0 . 10.9.9.1 . local in fibtype4
> FAIL: did not find veth0 . dead:1::1 . local in fibtype6
> FAIL: did not find veth0 . dead:9::1 . local in fibtype6
> FAIL: did not find tvrf . 10.0.1.1 . local in fibtype4
> FAIL: did not find tvrf . 10.9.9.1 . local in fibtype4
> FAIL: did not find tvrf . dead:1::1 . local in fibtype6
> FAIL: did not find tvrf . dead:9::1 . local in fibtype6
> FAIL: fib expression address types match (iif in vrf)
>
> (fib errounously returns 'unicast' for all of them, even
> though all of these addresses are local to the vrf).
>
> 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>
> ---
> include/net/netfilter/nft_fib.h | 16 ++++++++++++++++
> net/ipv4/netfilter/nft_fib_ipv4.c | 11 +++++++++--
> net/ipv6/netfilter/nft_fib_ipv6.c | 4 +---
> 3 files changed, 26 insertions(+), 5 deletions(-)
>
> diff --git a/include/net/netfilter/nft_fib.h b/include/net/netfilter/nft_fib.h
> index 6e202ed5e63f..2eea102c6609 100644
> --- a/include/net/netfilter/nft_fib.h
> +++ b/include/net/netfilter/nft_fib.h
> @@ -2,6 +2,7 @@
> #ifndef _NFT_FIB_H_
> #define _NFT_FIB_H_
>
> +#include <net/l3mdev.h>
> #include <net/netfilter/nf_tables.h>
>
> struct nft_fib {
> @@ -39,6 +40,21 @@ static inline bool nft_fib_can_skip(const struct nft_pktinfo *pkt)
> return nft_fib_is_loopback(pkt->skb, indev);
> }
>
> +/**
> + * nft_fib_l3mdev_get_rcu - return ifindex of l3 master device
Hi Pablo,
I don't mean to hold up progress of this pull request. But it would be nice
if at some point the above could be changed to
nft_fib_l3mdev_master_ifindex_rcu so it matches the name of the function
below that it documents.
Flagged by ./scripts/kernel-doc -none
> + * @pkt: pktinfo container passed to nft_fib_eval function
> + * @iif: input interface, can be NULL
> + *
> + * Return: interface index or 0.
> + */
> +static inline int nft_fib_l3mdev_master_ifindex_rcu(const struct nft_pktinfo *pkt,
> + const struct net_device *iif)
> +{
> + const struct net_device *dev = iif ? iif : pkt->skb->dev;
> +
> + return l3mdev_master_ifindex_rcu(dev);
> +}
> +
> int nft_fib_dump(struct sk_buff *skb, const struct nft_expr *expr, bool reset);
> int nft_fib_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
> const struct nlattr * const tb[]);
...
next prev parent reply other threads:[~2025-05-23 7:35 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-22 16:52 [PATCH net-next 00/26] Netfilter updates for net-next Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 01/26] selftests: netfilter: nft_concat_range.sh: add coverage for 4bit group representation Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 02/26] netfilter: xtables: support arpt_mark and ipv6 optstrip for iptables-nft only builds Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 03/26] selftests: netfilter: nft_fib.sh: add 'type' mode tests Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 04/26] selftests: netfilter: move fib vrf test to nft_fib.sh Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 05/26] netfilter: nf_tables: nft_fib_ipv6: fix VRF ipv4/ipv6 result discrepancy Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 06/26] netfilter: nf_tables: nft_fib: consistent l3mdev handling Pablo Neira Ayuso
2025-05-23 7:35 ` Simon Horman [this message]
2025-05-23 7:39 ` Pablo Neira Ayuso
2025-05-23 13:26 ` Simon Horman
2025-05-23 13:29 ` Pablo Neira Ayuso
2025-05-23 13:38 ` Simon Horman
2025-05-22 16:52 ` [PATCH net-next 07/26] selftests: netfilter: nft_fib.sh: add type and oif tests with and without VRFs Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 08/26] netfilter: nft_tunnel: fix geneve_opt dump Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 09/26] netfilter: nf_dup{4, 6}: Move duplication check to task_struct Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 10/26] netfilter: nft_inner: Use nested-BH locking for nft_pcpu_tun_ctx Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 11/26] netfilter: nf_dup_netdev: Move the recursion counter struct netdev_xmit Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 12/26] netfilter: conntrack: make nf_conntrack_id callable without a module dependency Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 13/26] netfilter: nf_tables: add packets conntrack state to debug trace info Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 14/26] netfilter: nf_tables: Introduce functions freeing nft_hook objects Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 15/26] netfilter: nf_tables: Introduce nft_hook_find_ops{,_rcu}() Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 16/26] netfilter: nf_tables: Introduce nft_register_flowtable_ops() Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 17/26] netfilter: nf_tables: Pass nf_hook_ops to nft_unregister_flowtable_hook() Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 18/26] netfilter: nf_tables: Have a list of nf_hook_ops in nft_hook Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 19/26] netfilter: nf_tables: Prepare for handling NETDEV_REGISTER events Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 20/26] netfilter: nf_tables: Respect " Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 21/26] netfilter: nf_tables: Wrap netdev notifiers Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 22/26] netfilter: nf_tables: Handle NETDEV_CHANGENAME events Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 23/26] netfilter: nf_tables: Sort labels in nft_netdev_hook_alloc() Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 24/26] netfilter: nf_tables: Support wildcard netdev hook specs Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 25/26] netfilter: nf_tables: Add notifications for hook changes Pablo Neira Ayuso
2025-05-22 16:52 ` [PATCH net-next 26/26] selftests: netfilter: Torture nftables netdev hooks Pablo Neira Ayuso
-- strict thread matches above, loose matches on Subject: below --
2025-05-23 13:26 [PATCH net-next,v2 00/26] Netfilter updates for net-next Pablo Neira Ayuso
2025-05-23 13:26 ` [PATCH net-next 06/26] netfilter: nf_tables: nft_fib: consistent l3mdev handling Pablo Neira Ayuso
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=20250523073524.GR365796@horms.kernel.org \
--to=horms@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fw@strlen.de \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.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.