net: ipv4: allow directed broadcast routes to use dst hint
Subsystems (4)
v2 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 v2:
- Removed unused variable
- Fixed formatting
- Added new selftest
Link to v1: 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/route_hint.sh | 58 +++++++++++++++++++++++ 3 files changed, 66 insertions(+), 5 deletions(-) create mode 100755 tools/testing/selftests/net/route_hint.sh
Signature · 1 line
2.39.5
PATCH v2 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
@@ -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) || + (iph->daddr ==0 && iph->saddr ==0 ) ||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
@@ -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
Paolo Abeni
maintainerQuoted 7 lines · Oscar Maes
net/ipv4/ip_input.c +0
-0@@ -587,9 +587,13 @@ static void ip_sublist_rcv_finish(struct list_head *head) }
net/ipv4/ip_input.c static void ip_sublist_rcv_finish(struct list_head *head) · line 596
Quoted 10 lines
net/ipv4/ip_input.c +6
-2static 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) || + (iph->daddr == 0 && iph->saddr == 0) ||
ipv4_is_zeronet(iph->daddr) is preferred for the daddr check, and it's not clear why the new check for the saddr is needed here.
/P
Quoted 22 lines · Paolo Abeni
Quoted 7 lines · Oscar Maes
net/ipv4/ip_input.c +0
-0@@ -587,9 +587,13 @@ static void ip_sublist_rcv_finish(struct list_head *head) }net/ipv4/ip_input.c static void ip_sublist_rcv_finish(struct list_head *head) · line 596
Quoted 10 lines
net/ipv4/ip_input.c +6
-2static 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) || + (iph->daddr == 0 && iph->saddr == 0) ||
ipv4_is_zeronet(iph->daddr)is preferred for the daddr check, and it's not clear why the new check for the saddr is needed here.
Quoted 2 lines
/P
Will change.
PATCH v2 2/2 selftests: net: add test for dst hint mechanism with directed broadcast addresses
In reply to Oscar MaesAdd 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/route_hint.sh | 58 +++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 tools/testing/selftests/net/route_hint.sh
tools/testing/selftests/net/route_hint.sh new file +58 -0
@@ -0,0 +1,58 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +# This test ensures directed broadcast routes use dst hint mechanism + +CLIENT_NS=$(mktemp -u client-XXXXXXXX) +CLIENT_IP4="192.168.0.1" + +SERVER_NS=$(mktemp -u server-XXXXXXXX) +SERVER_IP4="192.168.0.2" + +BROADCAST_ADDRESS="192.168.0.255" + +setup() { + ip netns add "${CLIENT_NS}" + ip netns add "${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 + ip netns del "${CLIENT_NS}" + ip netns del "${SERVER_NS}" +} + +directed_bcast_hint_test() +{ + echo "Testing for directed broadcast route hint" + + orig_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -k in_brd -s0 -i1 -c1 | tr -d ' |') + 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 -k in_brd -s0 -i1 -c1 | tr -d ' |') + + res=$(echo "${new_in_brd} - ${orig_in_brd}" | bc) + + [ "${res}" -lt 100 ] +} + +trap cleanup EXIT + +setup + +directed_bcast_hint_test +exit $?
Signature · 1 line
2.39.5
Paolo Abeni
maintainerRe: [PATCH net-next v2 2/2] selftests: net: add test for dst hint mechanism with directed broadcast addresses
Quoted 3 lines · Oscar Maes
tools/testing/selftests/net/route_hint.sh | 58 +++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 tools/testing/selftests/net/route_hint.sh
You must additionally update the net selftest Makefile to include the new test.
Quoted 14 lines
tools/testing/selftests/net/route_hint.sh new file +7
-0@@ -0,0 +1,58 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +# This test ensures directed broadcast routes use dst hint mechanism + +CLIENT_NS=$(mktemp -u client-XXXXXXXX) +CLIENT_IP4="192.168.0.1"
tools/testing/selftests/net/route_hint.sh line 16
Quoted 10 lines
tools/testing/selftests/net/route_hint.sh new file +9
-0+ +SERVER_NS=$(mktemp -u server-XXXXXXXX) +SERVER_IP4="192.168.0.2" + +BROADCAST_ADDRESS="192.168.0.255" + +setup() { + ip netns add "${CLIENT_NS}" + ip netns add "${SERVER_NS}"
You can/should use setup_ns() from lib.sh to avoid some duplicate code
Quoted 16 lines
tools/testing/selftests/net/route_hint.sh new file +16
-0+ + 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() {
tools/testing/selftests/net/route_hint.sh line 42
Quoted 10 lines
tools/testing/selftests/net/route_hint.sh new file +10
-0+ ip -net "${SERVER_NS}" link del link1 + ip netns del "${CLIENT_NS}" + ip netns del "${SERVER_NS}" +} + +directed_bcast_hint_test() +{ + echo "Testing for directed broadcast route hint" + + orig_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -k in_brd -s0 -i1 -c1 | tr -d ' |')
Likely using the '--json' argument and 'jq' will make the parsing more clear.
tools/testing/selftests/net/route_hint.sh line 44
Quoted 2 lines
tools/testing/selftests/net/route_hint.sh new file +2
-0+ 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
You should check for mausezahn presence and ev. error out with error code 4 (ksft_skip)
tools/testing/selftests/net/route_hint.sh line 50
Quoted 6 lines
tools/testing/selftests/net/route_hint.sh new file +6
-0+ sleep 1 + new_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -k in_brd -s0 -i1 -c1 | tr -d ' |') + + res=$(echo "${new_in_brd} - ${orig_in_brd}" | bc) + + [ "${res}" -lt 100 ]
It would be helpful additionally printing the test result: '[ ok ]' / '[fail] expected ... found ...'
/P
Re: [PATCH net-next v2 2/2] selftests: net: add test for dst hint mechanism with directed broadcast addresses
Quoted 8 lines · Paolo Abeni
Quoted 3 lines · Oscar Maes
tools/testing/selftests/net/route_hint.sh | 58 +++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 tools/testing/selftests/net/route_hint.shYou must additionally update the net selftest
Makefileto include the new test.
My bad.
Quoted 73 lines
Quoted 14 lines
tools/testing/selftests/net/route_hint.sh new file +7
-0@@ -0,0 +1,58 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +# This test ensures directed broadcast routes use dst hint mechanism + +CLIENT_NS=$(mktemp -u client-XXXXXXXX) +CLIENT_IP4="192.168.0.1"tools/testing/selftests/net/route_hint.sh line 16
Quoted 10 lines
tools/testing/selftests/net/route_hint.sh new file +9
-0+ +SERVER_NS=$(mktemp -u server-XXXXXXXX) +SERVER_IP4="192.168.0.2" + +BROADCAST_ADDRESS="192.168.0.255" + +setup() { + ip netns add "${CLIENT_NS}" + ip netns add "${SERVER_NS}"You can/should use
setup_ns()fromlib.shto avoid some duplicate codeQuoted 16 lines
tools/testing/selftests/net/route_hint.sh new file +16
-0+ + 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() {tools/testing/selftests/net/route_hint.sh line 42
Quoted 10 lines
tools/testing/selftests/net/route_hint.sh new file +10
-0+ ip -net "${SERVER_NS}" link del link1 + ip netns del "${CLIENT_NS}" + ip netns del "${SERVER_NS}" +} + +directed_bcast_hint_test() +{ + echo "Testing for directed broadcast route hint" + + orig_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -k in_brd -s0 -i1 -c1 | tr -d ' |')Likely using the '--json' argument and 'jq' will make the parsing more clear.
tools/testing/selftests/net/route_hint.sh line 44
Quoted 2 lines
tools/testing/selftests/net/route_hint.sh new file +2
-0+ 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 -qYou should check for mausezahn presence and ev. error out with error code 4 (
ksft_skip)tools/testing/selftests/net/route_hint.sh line 50
Quoted 6 lines
tools/testing/selftests/net/route_hint.sh new file +6
-0+ sleep 1 + new_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -k in_brd -s0 -i1 -c1 | tr -d ' |') + + res=$(echo "${new_in_brd} - ${orig_in_brd}" | bc) + + [ "${res}" -lt 100 ]It would be helpful additionally printing the test result: '[ ok ]' / '[fail] expected ... found ...'
Quoted 2 lines
/P
Will fix everything in v3 and resend shortly.