netfilter fixes for net
Subsystems (4)
Florian Westphal
maintainercover netfilter fixes for net
Hello,
This series from Phil Sutter for the *net* tree fixes a problem with a change from the 6.1 development phase: the change to nft_fib should have used the more recent flowic_l3mdev field. Pointed out by Guillaume Nault. This also makes the older iptables module follow the same pattern.
Also add selftest case and avoid test failure in nft_fib.sh when the host environment has set rp_filter=1.
Please consider pulling this from
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git master
----------------------------------------------------------------
The following changes since commit 739cfa34518ef3a6789f5f77239073972a387359:
net/mlx5: Make ASO poll CQ usable in atomic context (2022-10-12 09:16:05 +0100)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git master
for you to fetch changes up to 6a91e7270936c5a504af7e0a197d7021e169d281:
selftests: netfilter: Fix nft_fib.sh for all.rp_filter=1 (2022-10-12 14:08:15 +0200)
----------------------------------------------------------------
Phil Sutter (3):
selftests: netfilter: Test reverse path filtering
netfilter: rpfilter/fib: Populate flowic_l3mdev field
selftests: netfilter: Fix nft_fib.sh for all.rp_filter=1
net/ipv4/netfilter/ipt_rpfilter.c | 2 +- net/ipv4/netfilter/nft_fib_ipv4.c | 2 +- net/ipv6/netfilter/ip6t_rpfilter.c | 9 +- net/ipv6/netfilter/nft_fib_ipv6.c | 5 +- tools/testing/selftests/netfilter/Makefile | 2 +- tools/testing/selftests/netfilter/nft_fib.sh | 1 + tools/testing/selftests/netfilter/rpath.sh | 147 +++++++++++++++++++++++++++ 7 files changed, 156 insertions(+), 12 deletions(-) create mode 100755 tools/testing/selftests/netfilter/rpath.sh
Florian Westphal
maintainerPATCH 1/3 selftests: netfilter: Test reverse path filtering
From: Phil Sutter <[email protected]>
Test reverse path (filter) matches in iptables, ip6tables and nftables. Both with a regular interface and a VRF.
--- tools/testing/selftests/netfilter/Makefile | 2 +- tools/testing/selftests/netfilter/rpath.sh | 147 +++++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/netfilter/rpath.sh
tools/testing/selftests/netfilter/Makefile +1 -1
@@ -6,7 +6,7 @@ TEST_PROGS := nft_trans_stress.sh nft_fib.sh nft_nat.sh bridge_brouter.sh \ nft_concat_range.sh nft_conntrack_helper.sh \ nft_queue.sh nft_meta.sh nf_nat_edemux.sh \ ipip-conntrack-mtu.sh conntrack_tcp_unreplied.sh \ - conntrack_vrf.sh nft_synproxy.sh + conntrack_vrf.sh nft_synproxy.sh rpath.sh CFLAGS += $(shell pkg-config --cflags libmnl 2>/dev/null || echo "-I/usr/include/libmnl") LDLIBS = -lmnl
tools/testing/selftests/netfilter/rpath.sh new file +147 -0
147 lines not on this page · raw message
Signature · 1 line
2.35.1
Re: [PATCH net 1/3] selftests: netfilter: Test reverse path filtering
This series was applied to netdev/net.git (master) by Florian Westphal <[email protected]>:
Hello:
This series was applied to netdev/net.git (master) by Florian Westphal <[email protected]>:
Quoted 10 lines · On Wed, 12 Oct 2022 14:19:00 +0200 you wrote:
From: Phil Sutter <[email protected]>
Test reverse path (filter) matches in iptables, ip6tables and nftables. Both with a regular interface and a VRF.
Signed-off-by Phil Sutter <[email protected]>Reviewed-by Guillaume Nault <[email protected]>Signed-off-by Florian Westphal <[email protected]>[...]
Here is the summary with links:
- [net,1/3] selftests: netfilter: Test reverse path filtering
https://git.kernel.org/netdev/net/c/6e31ce831c63 - [net,2/3] netfilter: rpfilter/fib: Populate flowic_l3mdev field https://git.kernel.org/netdev/net/c/acc641ab95b6 - [net,3/3] selftests: netfilter: Fix nft_fib.sh for all.rp_filter=1 https://git.kernel.org/netdev/net/c/6a91e7270936
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Florian Westphal
maintainerPATCH 2/3 netfilter: rpfilter/fib: Populate flowic_l3mdev field
In reply to Florian WestphalFrom: Phil Sutter <[email protected]>
Use the introduced field for correct operation with VRF devices instead of conditionally overwriting flowic_oif. This is a partial revert of commit b575b24b8eee3 ("netfilter: Fix rpfilter dropping vrf packets by mistake"), implementing a simpler solution.
--- net/ipv4/netfilter/ipt_rpfilter.c | 2 +- net/ipv4/netfilter/nft_fib_ipv4.c | 2 +- net/ipv6/netfilter/ip6t_rpfilter.c | 9 +++------ net/ipv6/netfilter/nft_fib_ipv6.c | 5 ++--- 4 files changed, 7 insertions(+), 11 deletions(-)
net/ipv4/netfilter/ipt_rpfilter.c +1 -1
@@ -77,7 +77,7 @@ static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par) flow.flowi4_mark = info->flags &XT_RPFILTER_VALID_MARK ? skb->mark :0 ; flow.flowi4_tos = iph->tos &IPTOS_RT_MASK ; flow.flowi4_scope =RT_SCOPE_UNIVERSE ; - flow.flowi4_oif =l3mdev_master_ifindex_rcu (xt_in (par)); + flow.flowi4_l3mdev =l3mdev_master_ifindex_rcu (xt_in (par));return rpfilter_lookup_reverse (xt_net (par), &flow,xt_in (par), info->flags) ^ invert; }
net/ipv4/netfilter/nft_fib_ipv4.c +1 -1
@@ -84,7 +84,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs, oif =NULL ;if (priv->flags &NFTA_FIB_F_IIF ) - fl4.flowi4_oif =l3mdev_master_ifindex_rcu (oif); + 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))) {
net/ipv6/netfilter/ip6t_rpfilter.c +3 -6
@@ -37,6 +37,7 @@ static bool rpfilter_lookup_reverse6(struct net *net, const struct sk_buff *skb,bool ret = false;struct flowi6 fl6 = { .flowi6_iif =LOOPBACK_IFINDEX , + .flowi6_l3mdev =l3mdev_master_ifindex_rcu (dev), .flowlabel = (* (__be32 *) iph) &IPV6_FLOWINFO_MASK , .flowi6_proto = iph->nexthdr, .daddr = iph->saddr,
@@ -55,9 +56,7 @@ static bool rpfilter_lookup_reverse6(struct net *net, const struct sk_buff *skb,if (rpfilter_addr_linklocal (&iph->saddr)) { lookup_flags |=RT6_LOOKUP_F_IFACE ; fl6.flowi6_oif = dev->ifindex; -/* Set flowi6_oif for vrf devices to lookup route in l3mdev domain. */ - }else if (netif_is_l3_master (dev) ||netif_is_l3_slave (dev) || - (flags &XT_RPFILTER_LOOSE ) ==0 ) + }else if ((flags &XT_RPFILTER_LOOSE ) ==0 ) fl6.flowi6_oif = dev->ifindex; rt = (void *)ip6_route_lookup (net, &fl6, skb, lookup_flags);
@@ -72,9 +71,7 @@ static bool rpfilter_lookup_reverse6(struct net *net, const struct sk_buff *skb, goto out; } -if (rt->rt6i_idev->dev == dev || -l3mdev_master_ifindex_rcu (rt->rt6i_idev->dev) == dev->ifindex || - (flags &XT_RPFILTER_LOOSE )) +if (rt->rt6i_idev->dev == dev || (flags &XT_RPFILTER_LOOSE )) ret = true; out:ip6_rt_put (rt);
net/ipv6/netfilter/nft_fib_ipv6.c +2 -3
@@ -41,9 +41,8 @@ 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 ) && - (netif_is_l3_master (dev) ||netif_is_l3_slave (dev))) { - fl6->flowi6_oif = dev->ifindex; + }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 )
Signature · 1 line
2.35.1
Florian Westphal
maintainerPATCH 3/3 selftests: netfilter: Fix nft_fib.sh for all.rp_filter=1
In reply to Florian WestphalFrom: Phil Sutter <[email protected]>
If net.ipv4.conf.all.rp_filter is set, it overrides the per-interface setting and thus defeats the fix from bbe4c0896d250 ("selftests:
netfilter: disable rp_filter on router"). Unset it as well to cover that case.
--- tools/testing/selftests/netfilter/nft_fib.sh | 1 + 1 file changed, 1 insertion(+)
tools/testing/selftests/netfilter/nft_fib.sh +1 -0
@@ -188,6 +188,7 @@ test_ping() { ip netns exec ${nsrouter} sysctl net.ipv6.conf.all.forwarding=1 > /dev/null ip netns exec ${nsrouter} sysctl net.ipv4.conf.veth0.forwarding=1 > /dev/null ip netns exec ${nsrouter} sysctl net.ipv4.conf.veth1.forwarding=1 > /dev/null +ip netns exec ${nsrouter} sysctl net.ipv4.conf.all.rp_filter=0 > /dev/null ip netns exec ${nsrouter} sysctl net.ipv4.conf.veth0.rp_filter=0 > /dev/null sleep 3
Signature · 1 line
2.35.1