Skip to contentSkip to conversation

net: ipv4: allow directed broadcast routes to use dst hint

PATCH Applied Oscar Maes 3 participants 5 messages Aug 19, 2025 – Aug 25, 2025

Subsystems (4)
lore
Share & tools
lore

Oscar Maes

author
#0 lore raw

v3 cover net: ipv4: allow directed broadcast routes to use dst hint

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/[email protected]/

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
Signature · 1 line
2.39.5
author
#1 lore raw

PATCH v3 1/2 net: ipv4: allow directed broadcast routes to use dst hint

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.

---
 net/ipv4/ip_input.c | 11 +++++++----
 net/ipv4/route.c    |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)
net/ipv4/ip_input.c +7 -4
index fc323994b1fa..a09aca2c8567 100644
@@ -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))
net/ipv4/route.c +1 -1
index f639a2ae881a..1f212b2ce4c6 100644
@@ -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,
Signature · 1 line
2.39.5
maintainer Reviewed-by on v3 1/2
#2 lore raw
Quoted 26 lines · 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.

---
 net/ipv4/ip_input.c | 11 +++++++----
 net/ipv4/route.c    |  2 +-
 2 files changed, 8 insertions(+), 5 deletions(-)
net/ipv4/ip_input.c +1 -1
index fc323994b1fa..a09aca2c8567 100644
@@ -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)

net/ipv4/ip_input.c static void ip_sublist_rcv_finish(struct list_head *head) · line 599

Quoted 10 lines
net/ipv4/ip_input.c +5 -1
 {
-	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.

author
#3 lore raw

PATCH v3 2/2 selftests: net: add test for dst hint mechanism with directed broadcast addresses

In reply to 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.

---
 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
tools/testing/selftests/net/Makefile +1 -0
index b31a71f2b372..eef0b8f8a7b0 100644
@@ -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
tools/testing/selftests/net/route_hint.sh new file +79 -0

79 lines not on this page · raw message

Signature · 1 line
2.39.5
#4 lore raw
In reply to Oscar Maes
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · 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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html