0001
0002
0003
0004
0005
0006 lib_dir=$(dirname $0)/../../../net/forwarding
0007
0008 ALL_TESTS="
0009 ipv4_identical_routes
0010 ipv4_tos
0011 ipv4_metric
0012 ipv4_replace
0013 ipv4_delete
0014 ipv4_plen
0015 ipv4_replay
0016 ipv4_flush
0017 ipv4_local_replace
0018 ipv6_add
0019 ipv6_metric
0020 ipv6_append_single
0021 ipv6_replace_single
0022 ipv6_metric_multipath
0023 ipv6_append_multipath
0024 ipv6_replace_multipath
0025 ipv6_append_multipath_to_single
0026 ipv6_delete_single
0027 ipv6_delete_multipath
0028 ipv6_replay_single
0029 ipv6_replay_multipath
0030 ipv6_local_replace
0031 "
0032 NUM_NETIFS=0
0033 source $lib_dir/lib.sh
0034 source $lib_dir/devlink_lib.sh
0035 source $lib_dir/fib_offload_lib.sh
0036
0037 ipv4_identical_routes()
0038 {
0039 fib_ipv4_identical_routes_test "testns1"
0040 }
0041
0042 ipv4_tos()
0043 {
0044 fib_ipv4_tos_test "testns1"
0045 }
0046
0047 ipv4_metric()
0048 {
0049 fib_ipv4_metric_test "testns1"
0050 }
0051
0052 ipv4_replace()
0053 {
0054 fib_ipv4_replace_test "testns1"
0055 }
0056
0057 ipv4_delete()
0058 {
0059 fib_ipv4_delete_test "testns1"
0060 }
0061
0062 ipv4_plen()
0063 {
0064 fib_ipv4_plen_test "testns1"
0065 }
0066
0067 ipv4_replay_metric()
0068 {
0069 fib_ipv4_replay_metric_test "testns1" "$DEVLINK_DEV"
0070 }
0071
0072 ipv4_replay_tos()
0073 {
0074 fib_ipv4_replay_tos_test "testns1" "$DEVLINK_DEV"
0075 }
0076
0077 ipv4_replay_plen()
0078 {
0079 fib_ipv4_replay_plen_test "testns1" "$DEVLINK_DEV"
0080 }
0081
0082 ipv4_replay()
0083 {
0084 ipv4_replay_metric
0085 ipv4_replay_tos
0086 ipv4_replay_plen
0087 }
0088
0089 ipv4_flush()
0090 {
0091 fib_ipv4_flush_test "testns1"
0092 }
0093
0094 ipv4_local_replace()
0095 {
0096 local ns="testns1"
0097
0098 RET=0
0099
0100 ip -n $ns link add name dummy1 type dummy
0101 ip -n $ns link set dev dummy1 up
0102
0103 ip -n $ns route add table local 192.0.2.1/32 dev dummy1
0104 fib4_trap_check $ns "table local 192.0.2.1/32 dev dummy1" false
0105 check_err $? "Local table route not in hardware when should"
0106
0107 ip -n $ns route add table main 192.0.2.1/32 dev dummy1
0108 fib4_trap_check $ns "table main 192.0.2.1/32 dev dummy1" true
0109 check_err $? "Main table route in hardware when should not"
0110
0111 fib4_trap_check $ns "table local 192.0.2.1/32 dev dummy1" false
0112 check_err $? "Local table route was replaced when should not"
0113
0114
0115 ip -n $ns route add table main 192.0.2.2/32 dev dummy1
0116 fib4_trap_check $ns "table main 192.0.2.2/32 dev dummy1" false
0117 check_err $? "Main table route not in hardware when should"
0118
0119 ip -n $ns route add table local 192.0.2.2/32 dev dummy1
0120 fib4_trap_check $ns "table local 192.0.2.2/32 dev dummy1" false
0121 check_err $? "Local table route did not replace route in main table when should"
0122
0123 fib4_trap_check $ns "table main 192.0.2.2/32 dev dummy1" true
0124 check_err $? "Main table route was not replaced when should"
0125
0126 log_test "IPv4 local table route replacement"
0127
0128 ip -n $ns link del dev dummy1
0129 }
0130
0131 ipv6_add()
0132 {
0133 fib_ipv6_add_test "testns1"
0134 }
0135
0136 ipv6_metric()
0137 {
0138 fib_ipv6_metric_test "testns1"
0139 }
0140
0141 ipv6_append_single()
0142 {
0143 fib_ipv6_append_single_test "testns1"
0144 }
0145
0146 ipv6_replace_single()
0147 {
0148 fib_ipv6_replace_single_test "testns1"
0149 }
0150
0151 ipv6_metric_multipath()
0152 {
0153 fib_ipv6_metric_multipath_test "testns1"
0154 }
0155
0156 ipv6_append_multipath()
0157 {
0158 fib_ipv6_append_multipath_test "testns1"
0159 }
0160
0161 ipv6_replace_multipath()
0162 {
0163 fib_ipv6_replace_multipath_test "testns1"
0164 }
0165
0166 ipv6_append_multipath_to_single()
0167 {
0168 fib_ipv6_append_multipath_to_single_test "testns1"
0169 }
0170
0171 ipv6_delete_single()
0172 {
0173 fib_ipv6_delete_single_test "testns1"
0174 }
0175
0176 ipv6_delete_multipath()
0177 {
0178 fib_ipv6_delete_multipath_test "testns1"
0179 }
0180
0181 ipv6_replay_single()
0182 {
0183 fib_ipv6_replay_single_test "testns1" "$DEVLINK_DEV"
0184 }
0185
0186 ipv6_replay_multipath()
0187 {
0188 fib_ipv6_replay_multipath_test "testns1" "$DEVLINK_DEV"
0189 }
0190
0191 ipv6_local_replace()
0192 {
0193 local ns="testns1"
0194
0195 RET=0
0196
0197 ip -n $ns link add name dummy1 type dummy
0198 ip -n $ns link set dev dummy1 up
0199
0200 ip -n $ns route add table local 2001:db8:1::1/128 dev dummy1
0201 fib6_trap_check $ns "table local 2001:db8:1::1/128 dev dummy1" false
0202 check_err $? "Local table route not in hardware when should"
0203
0204 ip -n $ns route add table main 2001:db8:1::1/128 dev dummy1
0205 fib6_trap_check $ns "table main 2001:db8:1::1/128 dev dummy1" true
0206 check_err $? "Main table route in hardware when should not"
0207
0208 fib6_trap_check $ns "table local 2001:db8:1::1/128 dev dummy1" false
0209 check_err $? "Local table route was replaced when should not"
0210
0211
0212 ip -n $ns route add table main 2001:db8:1::2/128 dev dummy1
0213 fib6_trap_check $ns "table main 2001:db8:1::2/128 dev dummy1" false
0214 check_err $? "Main table route not in hardware when should"
0215
0216 ip -n $ns route add table local 2001:db8:1::2/128 dev dummy1
0217 fib6_trap_check $ns "table local 2001:db8:1::2/128 dev dummy1" false
0218 check_err $? "Local route route did not replace route in main table when should"
0219
0220 fib6_trap_check $ns "table main 2001:db8:1::2/128 dev dummy1" true
0221 check_err $? "Main table route was not replaced when should"
0222
0223 log_test "IPv6 local table route replacement"
0224
0225 ip -n $ns link del dev dummy1
0226 }
0227
0228 fib_notify_on_flag_change_set()
0229 {
0230 local notify=$1; shift
0231
0232 ip netns exec testns1 sysctl -qw net.ipv4.fib_notify_on_flag_change=$notify
0233 ip netns exec testns1 sysctl -qw net.ipv6.fib_notify_on_flag_change=$notify
0234
0235 log_info "Set fib_notify_on_flag_change to $notify"
0236 }
0237
0238 setup_prepare()
0239 {
0240 ip netns add testns1
0241 if [ $? -ne 0 ]; then
0242 echo "Failed to add netns \"testns1\""
0243 exit 1
0244 fi
0245
0246 devlink dev reload $DEVLINK_DEV netns testns1
0247 if [ $? -ne 0 ]; then
0248 echo "Failed to reload into netns \"testns1\""
0249 exit 1
0250 fi
0251 }
0252
0253 cleanup()
0254 {
0255 pre_cleanup
0256 devlink -N testns1 dev reload $DEVLINK_DEV netns $$
0257 ip netns del testns1
0258 }
0259
0260 trap cleanup EXIT
0261
0262 setup_prepare
0263
0264 fib_notify_on_flag_change_set 1
0265 tests_run
0266
0267 fib_notify_on_flag_change_set 0
0268 tests_run
0269
0270 exit $EXIT_STATUS