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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'net-ipv4-allow-directed-broadcast-routes-to-use-dst-hint'

Oscar Maes says:

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

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

Link: https://patch.msgid.link/20250819174642.5148-1-oscmaes92@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+88 -5
+7 -4
net/ipv4/ip_input.c
··· 587 587 } 588 588 589 589 static struct sk_buff *ip_extract_route_hint(const struct net *net, 590 - struct sk_buff *skb, int rt_type) 590 + struct sk_buff *skb) 591 591 { 592 - if (fib4_has_custom_rules(net) || rt_type == RTN_BROADCAST || 592 + const struct iphdr *iph = ip_hdr(skb); 593 + 594 + if (fib4_has_custom_rules(net) || 595 + ipv4_is_lbcast(iph->daddr) || 596 + ipv4_is_zeronet(iph->daddr) || 593 597 IPCB(skb)->flags & IPSKB_MULTIPATH) 594 598 return NULL; 595 599 ··· 622 618 623 619 dst = skb_dst(skb); 624 620 if (curr_dst != dst) { 625 - hint = ip_extract_route_hint(net, skb, 626 - dst_rtable(dst)->rt_type); 621 + hint = ip_extract_route_hint(net, skb); 627 622 628 623 /* dispatch old sublist */ 629 624 if (!list_empty(&sublist))
+1 -1
net/ipv4/route.c
··· 2210 2210 goto martian_source; 2211 2211 } 2212 2212 2213 - if (rt->rt_type != RTN_LOCAL) 2213 + if (!(rt->rt_flags & RTCF_LOCAL)) 2214 2214 goto skip_validate_source; 2215 2215 2216 2216 reason = fib_validate_source_reason(skb, saddr, daddr, dscp, 0, dev,
+1
tools/testing/selftests/net/Makefile
··· 117 117 TEST_PROGS += tfo_passive.sh 118 118 TEST_PROGS += broadcast_pmtu.sh 119 119 TEST_PROGS += ipv6_force_forwarding.sh 120 + TEST_PROGS += route_hint.sh 120 121 121 122 # YNL files, must be before "include ..lib.mk" 122 123 YNL_GEN_FILES := busy_poller netlink-dumps
+79
tools/testing/selftests/net/route_hint.sh
··· 1 + #!/bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + # This test ensures directed broadcast routes use dst hint mechanism 5 + 6 + source lib.sh 7 + 8 + CLIENT_IP4="192.168.0.1" 9 + SERVER_IP4="192.168.0.2" 10 + BROADCAST_ADDRESS="192.168.0.255" 11 + 12 + setup() { 13 + setup_ns CLIENT_NS SERVER_NS 14 + 15 + ip -net "${SERVER_NS}" link add link1 type veth peer name link0 netns "${CLIENT_NS}" 16 + 17 + ip -net "${CLIENT_NS}" link set link0 up 18 + ip -net "${CLIENT_NS}" addr add "${CLIENT_IP4}/24" dev link0 19 + 20 + ip -net "${SERVER_NS}" link set link1 up 21 + ip -net "${SERVER_NS}" addr add "${SERVER_IP4}/24" dev link1 22 + 23 + ip netns exec "${CLIENT_NS}" ethtool -K link0 tcp-segmentation-offload off 24 + ip netns exec "${SERVER_NS}" sh -c "echo 500000000 > /sys/class/net/link1/gro_flush_timeout" 25 + ip netns exec "${SERVER_NS}" sh -c "echo 1 > /sys/class/net/link1/napi_defer_hard_irqs" 26 + ip netns exec "${SERVER_NS}" ethtool -K link1 generic-receive-offload on 27 + } 28 + 29 + cleanup() { 30 + ip -net "${SERVER_NS}" link del link1 31 + cleanup_ns "${CLIENT_NS}" "${SERVER_NS}" 32 + } 33 + 34 + directed_bcast_hint_test() 35 + { 36 + local rc=0 37 + 38 + echo "Testing for directed broadcast route hint" 39 + 40 + orig_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -j -i1 -c1 | jq '.in_brd') 41 + ip netns exec "${CLIENT_NS}" mausezahn link0 -a own -b bcast -A "${CLIENT_IP4}" \ 42 + -B "${BROADCAST_ADDRESS}" -c1 -t tcp "sp=1-100,dp=1234,s=1,a=0" -p 5 -q 43 + sleep 1 44 + new_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -j -i1 -c1 | jq '.in_brd') 45 + 46 + res=$(echo "${new_in_brd} - ${orig_in_brd}" | bc) 47 + 48 + if [ "${res}" -lt 100 ]; then 49 + echo "[ OK ]" 50 + rc="${ksft_pass}" 51 + else 52 + echo "[FAIL] expected in_brd to be under 100, got ${res}" 53 + rc="${ksft_fail}" 54 + fi 55 + 56 + return "${rc}" 57 + } 58 + 59 + if [ ! -x "$(command -v mausezahn)" ]; then 60 + echo "SKIP: Could not run test without mausezahn tool" 61 + exit "${ksft_skip}" 62 + fi 63 + 64 + if [ ! -x "$(command -v jq)" ]; then 65 + echo "SKIP: Could not run test without jq tool" 66 + exit "${ksft_skip}" 67 + fi 68 + 69 + if [ ! -x "$(command -v bc)" ]; then 70 + echo "SKIP: Could not run test without bc tool" 71 + exit "${ksft_skip}" 72 + fi 73 + 74 + trap cleanup EXIT 75 + 76 + setup 77 + 78 + directed_bcast_hint_test 79 + exit $?