linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v3 0/2] net: ipv4: allow directed broadcast routes to use dst hint
@ 2025-08-19 17:46 Oscar Maes
  2025-08-19 17:46 ` [PATCH net-next v3 1/2] " Oscar Maes
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Oscar Maes @ 2025-08-19 17:46 UTC (permalink / raw)
  To: netdev
  Cc: davem, dsahern, edumazet, kuba, pabeni, horms, shuah,
	linux-kernel, Oscar Maes

Currently, ip_extract_route_hint uses RTN_BROADCAST to decide
whether to use the route dst hint mechanism.

This check is too strict, as it prevents directed broadcast
routes from using the hint, resulting in poor performance
during bursts of directed broadcast traffic.

This series fixes this, and adds a new selftest to ensure
this does not regress.

Changes in v3:
 - Improved selftest
 - Use ipv4_is_zeronet to check daddr

Changes in v2:
 - Removed unused variable
 - Fixed formatting
 - Added new selftest

Link to v2: https://lore.kernel.org/netdev/20250814140309.3742-1-oscmaes92@gmail.com/

Oscar Maes (2):
  net: ipv4: allow directed broadcast routes to use dst hint
  selftests: net: add test for dst hint mechanism with directed
    broadcast addresses

 net/ipv4/ip_input.c                       | 11 ++--
 net/ipv4/route.c                          |  2 +-
 tools/testing/selftests/net/Makefile      |  1 +
 tools/testing/selftests/net/route_hint.sh | 79 +++++++++++++++++++++++
 4 files changed, 88 insertions(+), 5 deletions(-)
 create mode 100755 tools/testing/selftests/net/route_hint.sh

-- 
2.39.5


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

* [PATCH net-next v3 1/2] net: ipv4: allow directed broadcast routes to use dst hint
  2025-08-19 17:46 [PATCH net-next v3 0/2] net: ipv4: allow directed broadcast routes to use dst hint Oscar Maes
@ 2025-08-19 17:46 ` Oscar Maes
  2025-08-20 14:19   ` David Ahern
  2025-08-19 17:46 ` [PATCH net-next v3 2/2] selftests: net: add test for dst hint mechanism with directed broadcast addresses Oscar Maes
  2025-08-25 23:30 ` [PATCH net-next v3 0/2] net: ipv4: allow directed broadcast routes to use dst hint patchwork-bot+netdevbpf
  2 siblings, 1 reply; 5+ messages in thread
From: Oscar Maes @ 2025-08-19 17:46 UTC (permalink / raw)
  To: netdev
  Cc: davem, dsahern, edumazet, kuba, pabeni, horms, shuah,
	linux-kernel, Oscar Maes

Currently, ip_extract_route_hint uses RTN_BROADCAST to decide
whether to use the route dst hint mechanism.

This check is too strict, as it prevents directed broadcast
routes from using the hint, resulting in poor performance
during bursts of directed broadcast traffic.

Fix this in ip_extract_route_hint and modify ip_route_use_hint
to preserve the intended behaviour.

Signed-off-by: Oscar Maes <oscmaes92@gmail.com>
---
 net/ipv4/ip_input.c | 11 +++++++----
 net/ipv4/route.c    |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index fc323994b1fa..a09aca2c8567 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -587,9 +587,13 @@ static void ip_sublist_rcv_finish(struct list_head *head)
 }
 
 static struct sk_buff *ip_extract_route_hint(const struct net *net,
-					     struct sk_buff *skb, int rt_type)
+					     struct sk_buff *skb)
 {
-	if (fib4_has_custom_rules(net) || rt_type == RTN_BROADCAST ||
+	const struct iphdr *iph = ip_hdr(skb);
+
+	if (fib4_has_custom_rules(net) ||
+	    ipv4_is_lbcast(iph->daddr) ||
+	    ipv4_is_zeronet(iph->daddr) ||
 	    IPCB(skb)->flags & IPSKB_MULTIPATH)
 		return NULL;
 
@@ -618,8 +622,7 @@ static void ip_list_rcv_finish(struct net *net, struct list_head *head)
 
 		dst = skb_dst(skb);
 		if (curr_dst != dst) {
-			hint = ip_extract_route_hint(net, skb,
-						     dst_rtable(dst)->rt_type);
+			hint = ip_extract_route_hint(net, skb);
 
 			/* dispatch old sublist */
 			if (!list_empty(&sublist))
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index f639a2ae881a..1f212b2ce4c6 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -2210,7 +2210,7 @@ ip_route_use_hint(struct sk_buff *skb, __be32 daddr, __be32 saddr,
 		goto martian_source;
 	}
 
-	if (rt->rt_type != RTN_LOCAL)
+	if (!(rt->rt_flags & RTCF_LOCAL))
 		goto skip_validate_source;
 
 	reason = fib_validate_source_reason(skb, saddr, daddr, dscp, 0, dev,
-- 
2.39.5


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

* [PATCH net-next v3 2/2] selftests: net: add test for dst hint mechanism with directed broadcast addresses
  2025-08-19 17:46 [PATCH net-next v3 0/2] net: ipv4: allow directed broadcast routes to use dst hint Oscar Maes
  2025-08-19 17:46 ` [PATCH net-next v3 1/2] " Oscar Maes
@ 2025-08-19 17:46 ` Oscar Maes
  2025-08-25 23:30 ` [PATCH net-next v3 0/2] net: ipv4: allow directed broadcast routes to use dst hint patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: Oscar Maes @ 2025-08-19 17:46 UTC (permalink / raw)
  To: netdev
  Cc: davem, dsahern, edumazet, kuba, pabeni, horms, shuah,
	linux-kernel, Oscar Maes

Add a test for ensuring that the dst hint mechanism is used for
directed broadcast addresses.

This test relies on mausezahn for sending directed broadcast packets.
Additionally, a high GRO flush timeout is set to ensure that packets
will be received as lists.

The test determines if the hint mechanism was used by checking
the in_brd statistic using lnstat.

Signed-off-by: Oscar Maes <oscmaes92@gmail.com>
---
 tools/testing/selftests/net/Makefile      |  1 +
 tools/testing/selftests/net/route_hint.sh | 79 +++++++++++++++++++++++
 2 files changed, 80 insertions(+)
 create mode 100755 tools/testing/selftests/net/route_hint.sh

diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index b31a71f2b372..eef0b8f8a7b0 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -117,6 +117,7 @@ TEST_GEN_FILES += tfo
 TEST_PROGS += tfo_passive.sh
 TEST_PROGS += broadcast_pmtu.sh
 TEST_PROGS += ipv6_force_forwarding.sh
+TEST_PROGS += route_hint.sh
 
 # YNL files, must be before "include ..lib.mk"
 YNL_GEN_FILES := busy_poller netlink-dumps
diff --git a/tools/testing/selftests/net/route_hint.sh b/tools/testing/selftests/net/route_hint.sh
new file mode 100755
index 000000000000..2db01ece0cc1
--- /dev/null
+++ b/tools/testing/selftests/net/route_hint.sh
@@ -0,0 +1,79 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+# This test ensures directed broadcast routes use dst hint mechanism
+
+source lib.sh
+
+CLIENT_IP4="192.168.0.1"
+SERVER_IP4="192.168.0.2"
+BROADCAST_ADDRESS="192.168.0.255"
+
+setup() {
+	setup_ns CLIENT_NS SERVER_NS
+
+	ip -net "${SERVER_NS}" link add link1 type veth peer name link0 netns "${CLIENT_NS}"
+
+	ip -net "${CLIENT_NS}" link set link0 up
+	ip -net "${CLIENT_NS}" addr add "${CLIENT_IP4}/24" dev link0
+
+	ip -net "${SERVER_NS}" link set link1 up
+	ip -net "${SERVER_NS}" addr add "${SERVER_IP4}/24" dev link1
+
+	ip netns exec "${CLIENT_NS}" ethtool -K link0 tcp-segmentation-offload off
+	ip netns exec "${SERVER_NS}" sh -c "echo 500000000 > /sys/class/net/link1/gro_flush_timeout"
+	ip netns exec "${SERVER_NS}" sh -c "echo 1 > /sys/class/net/link1/napi_defer_hard_irqs"
+	ip netns exec "${SERVER_NS}" ethtool -K link1 generic-receive-offload on
+}
+
+cleanup() {
+	ip -net "${SERVER_NS}" link del link1
+	cleanup_ns "${CLIENT_NS}" "${SERVER_NS}"
+}
+
+directed_bcast_hint_test()
+{
+	local rc=0
+
+	echo "Testing for directed broadcast route hint"
+
+	orig_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -j -i1 -c1 | jq '.in_brd')
+	ip netns exec "${CLIENT_NS}" mausezahn link0 -a own -b bcast -A "${CLIENT_IP4}" \
+		-B "${BROADCAST_ADDRESS}" -c1 -t tcp "sp=1-100,dp=1234,s=1,a=0" -p 5 -q
+	sleep 1
+	new_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -j -i1 -c1 | jq '.in_brd')
+
+	res=$(echo "${new_in_brd} - ${orig_in_brd}" | bc)
+
+	if [ "${res}" -lt 100 ]; then
+		echo "[ OK ]"
+		rc="${ksft_pass}"
+	else
+		echo "[FAIL] expected in_brd to be under 100, got ${res}"
+		rc="${ksft_fail}"
+	fi
+
+	return "${rc}"
+}
+
+if [ ! -x "$(command -v mausezahn)" ]; then
+	echo "SKIP: Could not run test without mausezahn tool"
+	exit "${ksft_skip}"
+fi
+
+if [ ! -x "$(command -v jq)" ]; then
+	echo "SKIP: Could not run test without jq tool"
+	exit "${ksft_skip}"
+fi
+
+if [ ! -x "$(command -v bc)" ]; then
+	echo "SKIP: Could not run test without bc tool"
+	exit "${ksft_skip}"
+fi
+
+trap cleanup EXIT
+
+setup
+
+directed_bcast_hint_test
+exit $?
-- 
2.39.5


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

* Re: [PATCH net-next v3 1/2] net: ipv4: allow directed broadcast routes to use dst hint
  2025-08-19 17:46 ` [PATCH net-next v3 1/2] " Oscar Maes
@ 2025-08-20 14:19   ` David Ahern
  0 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2025-08-20 14:19 UTC (permalink / raw)
  To: Oscar Maes, netdev
  Cc: davem, edumazet, kuba, pabeni, horms, shuah, linux-kernel

On 8/19/25 11:46 AM, Oscar Maes wrote:
> Currently, ip_extract_route_hint uses RTN_BROADCAST to decide
> whether to use the route dst hint mechanism.
> 
> This check is too strict, as it prevents directed broadcast
> routes from using the hint, resulting in poor performance
> during bursts of directed broadcast traffic.
> 
> Fix this in ip_extract_route_hint and modify ip_route_use_hint
> to preserve the intended behaviour.
> 
> Signed-off-by: Oscar Maes <oscmaes92@gmail.com>
> ---
>  net/ipv4/ip_input.c | 11 +++++++----
>  net/ipv4/route.c    |  2 +-
>  2 files changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
> index fc323994b1fa..a09aca2c8567 100644
> --- a/net/ipv4/ip_input.c
> +++ b/net/ipv4/ip_input.c
> @@ -587,9 +587,13 @@ static void ip_sublist_rcv_finish(struct list_head *head)
>  }
>  
>  static struct sk_buff *ip_extract_route_hint(const struct net *net,
> -					     struct sk_buff *skb, int rt_type)
> +					     struct sk_buff *skb)
>  {
> -	if (fib4_has_custom_rules(net) || rt_type == RTN_BROADCAST ||
> +	const struct iphdr *iph = ip_hdr(skb);
> +
> +	if (fib4_has_custom_rules(net) ||
> +	    ipv4_is_lbcast(iph->daddr) ||
> +	    ipv4_is_zeronet(iph->daddr) ||
>  	    IPCB(skb)->flags & IPSKB_MULTIPATH)
>  		return NULL;
>  

seems ok to me.

Reviewed-by: David Ahern <dsahern@kernel.org>



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

* Re: [PATCH net-next v3 0/2] net: ipv4: allow directed broadcast routes to use dst hint
  2025-08-19 17:46 [PATCH net-next v3 0/2] net: ipv4: allow directed broadcast routes to use dst hint Oscar Maes
  2025-08-19 17:46 ` [PATCH net-next v3 1/2] " Oscar Maes
  2025-08-19 17:46 ` [PATCH net-next v3 2/2] selftests: net: add test for dst hint mechanism with directed broadcast addresses Oscar Maes
@ 2025-08-25 23:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-08-25 23:30 UTC (permalink / raw)
  To: Oscar Maes
  Cc: netdev, davem, dsahern, edumazet, kuba, pabeni, horms, shuah,
	linux-kernel

Hello:

This series was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 19 Aug 2025 19:46:40 +0200 you wrote:
> Currently, ip_extract_route_hint uses RTN_BROADCAST to decide
> whether to use the route dst hint mechanism.
> 
> This check is too strict, as it prevents directed broadcast
> routes from using the hint, resulting in poor performance
> during bursts of directed broadcast traffic.
> 
> [...]

Here is the summary with links:
  - [net-next,v3,1/2] net: ipv4: allow directed broadcast routes to use dst hint
    https://git.kernel.org/netdev/net-next/c/1b8c5fa0cb35
  - [net-next,v3,2/2] selftests: net: add test for dst hint mechanism with directed broadcast addresses
    https://git.kernel.org/netdev/net-next/c/bd0d9e751b9b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2025-08-25 23:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-19 17:46 [PATCH net-next v3 0/2] net: ipv4: allow directed broadcast routes to use dst hint Oscar Maes
2025-08-19 17:46 ` [PATCH net-next v3 1/2] " Oscar Maes
2025-08-20 14:19   ` David Ahern
2025-08-19 17:46 ` [PATCH net-next v3 2/2] selftests: net: add test for dst hint mechanism with directed broadcast addresses Oscar Maes
2025-08-25 23:30 ` [PATCH net-next v3 0/2] net: ipv4: allow directed broadcast routes to use dst hint patchwork-bot+netdevbpf

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).