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

selftests: netdevsim: Test route offload failure notifications

Add cases to verify that when debugfs variable "fail_route_offload" is
set, notification with "rt_offload_failed" flag is received.

Extend the existing cases to verify that when sysctl
"fib_notify_on_flag_change" is set to 2, the kernel emits notifications
only for failed route installation.

$ ./fib_notifications.sh
TEST: IPv4 route addition [ OK ]
TEST: IPv4 route deletion [ OK ]
TEST: IPv4 route replacement [ OK ]
TEST: IPv4 route offload failed [ OK ]
TEST: IPv6 route addition [ OK ]
TEST: IPv6 route deletion [ OK ]
TEST: IPv6 route replacement [ OK ]
TEST: IPv6 route offload failed [ OK ]

Signed-off-by: Amit Cohen <amcohen@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Amit Cohen and committed by
David S. Miller
9ee53e37 a4cb1c02

+132 -2
+132 -2
tools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh
··· 7 7 ipv4_route_addition_test 8 8 ipv4_route_deletion_test 9 9 ipv4_route_replacement_test 10 + ipv4_route_offload_failed_test 10 11 ipv6_route_addition_test 11 12 ipv6_route_deletion_test 12 13 ipv6_route_replacement_test 14 + ipv6_route_offload_failed_test 13 15 " 14 16 15 17 NETDEVSIM_PATH=/sys/bus/netdevsim/ ··· 19 17 DEV=netdevsim${DEV_ADDR} 20 18 DEVLINK_DEV=netdevsim/${DEV} 21 19 SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV/net/ 20 + DEBUGFS_DIR=/sys/kernel/debug/netdevsim/$DEV/ 22 21 NUM_NETIFS=0 23 22 source $lib_dir/lib.sh 23 + 24 + check_rt_offload_failed() 25 + { 26 + local outfile=$1; shift 27 + local line 28 + 29 + # Make sure that the first notification was emitted without 30 + # RTM_F_OFFLOAD_FAILED flag and the second with RTM_F_OFFLOAD_FAILED 31 + # flag 32 + head -n 1 $outfile | grep -q "rt_offload_failed" 33 + if [[ $? -eq 0 ]]; then 34 + return 1 35 + fi 36 + 37 + head -n 2 $outfile | tail -n 1 | grep -q "rt_offload_failed" 38 + } 24 39 25 40 check_rt_trap() 26 41 { ··· 58 39 { 59 40 local outfile=$1; shift 60 41 local expected_num_lines=$1; shift 42 + local offload_failed=${1:-0}; shift 61 43 62 44 # check the monitor results 63 45 lines=`wc -l $outfile | cut "-d " -f1` 64 46 test $lines -eq $expected_num_lines 65 47 check_err $? "$expected_num_lines notifications were expected but $lines were received" 66 48 67 - if [[ $expected_num_lines -eq 2 ]]; then 49 + if [[ $expected_num_lines -eq 1 ]]; then 50 + return 51 + fi 52 + 53 + if [[ $offload_failed -eq 0 ]]; then 68 54 check_rt_trap $outfile 69 55 check_err $? "Wrong RTM_F_TRAP flags in notifications" 56 + else 57 + check_rt_offload_failed $outfile 58 + check_err $? "Wrong RTM_F_OFFLOAD_FAILED flags in notifications" 70 59 fi 71 60 } 72 61 ··· 84 57 local notify=$1; shift 85 58 local route=$1; shift 86 59 local expected_num_notifications=$1; shift 60 + local offload_failed=${1:-0}; shift 87 61 88 62 ip netns exec testns1 sysctl -qw net.$ip.fib_notify_on_flag_change=$notify 89 63 ··· 96 68 sleep 1 97 69 kill %% && wait %% &> /dev/null 98 70 99 - route_notify_check $outfile $expected_num_notifications 71 + route_notify_check $outfile $expected_num_notifications $offload_failed 100 72 rm -f $outfile 101 73 102 74 $IP route del $route dev dummy1 ··· 119 91 # Make sure two notifications will be emitted for the programmed route. 120 92 notify=1 121 93 expected_num_notifications=2 94 + route_addition_check $ip $notify $route $expected_num_notifications 95 + 96 + # notify=2 means emit notifications only for failed route installation, 97 + # make sure a single notification will be emitted for the programmed 98 + # route. 99 + notify=2 100 + expected_num_notifications=1 122 101 route_addition_check $ip $notify $route $expected_num_notifications 123 102 124 103 log_test "IPv4 route addition" ··· 220 185 expected_num_notifications=2 221 186 route_replacement_check $ip $notify $route $expected_num_notifications 222 187 188 + # notify=2 means emit notifications only for failed route installation, 189 + # make sure a single notification will be emitted for the new route. 190 + notify=2 191 + expected_num_notifications=1 192 + route_replacement_check $ip $notify $route $expected_num_notifications 193 + 223 194 $IP link del name dummy2 224 195 225 196 log_test "IPv4 route replacement" 197 + } 198 + 199 + ipv4_route_offload_failed_test() 200 + { 201 + 202 + RET=0 203 + 204 + local ip="ipv4" 205 + local route=192.0.2.0/24 206 + local offload_failed=1 207 + 208 + echo "y"> $DEBUGFS_DIR/fib/fail_route_offload 209 + check_err $? "Failed to setup route offload to fail" 210 + 211 + # Make sure a single notification will be emitted for the programmed 212 + # route. 213 + local notify=0 214 + local expected_num_notifications=1 215 + route_addition_check $ip $notify $route $expected_num_notifications \ 216 + $offload_failed 217 + 218 + # Make sure two notifications will be emitted for the new route. 219 + notify=1 220 + expected_num_notifications=2 221 + route_addition_check $ip $notify $route $expected_num_notifications \ 222 + $offload_failed 223 + 224 + # notify=2 means emit notifications only for failed route installation, 225 + # make sure two notifications will be emitted for the new route. 226 + notify=2 227 + expected_num_notifications=2 228 + route_addition_check $ip $notify $route $expected_num_notifications \ 229 + $offload_failed 230 + 231 + echo "n"> $DEBUGFS_DIR/fib/fail_route_offload 232 + check_err $? "Failed to setup route offload not to fail" 233 + 234 + log_test "IPv4 route offload failed" 226 235 } 227 236 228 237 ipv6_route_addition_test() ··· 285 206 # Make sure two notifications will be emitted for the programmed route. 286 207 notify=1 287 208 expected_num_notifications=2 209 + route_addition_check $ip $notify $route $expected_num_notifications 210 + 211 + # notify=2 means emit notifications only for failed route installation, 212 + # make sure a single notification will be emitted for the programmed 213 + # route. 214 + notify=2 215 + expected_num_notifications=1 288 216 route_addition_check $ip $notify $route $expected_num_notifications 289 217 290 218 log_test "IPv6 route addition" ··· 336 250 expected_num_notifications=2 337 251 route_replacement_check $ip $notify $route $expected_num_notifications 338 252 253 + # notify=2 means emit notifications only for failed route installation, 254 + # make sure a single notification will be emitted for the new route. 255 + notify=2 256 + expected_num_notifications=1 257 + route_replacement_check $ip $notify $route $expected_num_notifications 258 + 339 259 $IP link del name dummy2 340 260 341 261 log_test "IPv6 route replacement" 262 + } 263 + 264 + ipv6_route_offload_failed_test() 265 + { 266 + 267 + RET=0 268 + 269 + local ip="ipv6" 270 + local route=2001:db8:1::/64 271 + local offload_failed=1 272 + 273 + echo "y"> $DEBUGFS_DIR/fib/fail_route_offload 274 + check_err $? "Failed to setup route offload to fail" 275 + 276 + # Make sure a single notification will be emitted for the programmed 277 + # route. 278 + local notify=0 279 + local expected_num_notifications=1 280 + route_addition_check $ip $notify $route $expected_num_notifications \ 281 + $offload_failed 282 + 283 + # Make sure two notifications will be emitted for the new route. 284 + notify=1 285 + expected_num_notifications=2 286 + route_addition_check $ip $notify $route $expected_num_notifications \ 287 + $offload_failed 288 + 289 + # notify=2 means emit notifications only for failed route installation, 290 + # make sure two notifications will be emitted for the new route. 291 + notify=2 292 + expected_num_notifications=2 293 + route_addition_check $ip $notify $route $expected_num_notifications \ 294 + $offload_failed 295 + 296 + echo "n"> $DEBUGFS_DIR/fib/fail_route_offload 297 + check_err $? "Failed to setup route offload not to fail" 298 + 299 + log_test "IPv6 route offload failed" 342 300 } 343 301 344 302 setup_prepare()