Skip to content

Commit f6e1dcd

Browse files
liuhangbinPaolo Abeni
authored andcommitted
selftests/rtnetlink.sh: add mngtempaddr test
Add a test to check the temporary address could be added/removed correctly when mngtempaddr is set or removed/unmanaged. Signed-off-by: Sam Edwards <[email protected]> Signed-off-by: Hangbin Liu <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 00b5b7a commit f6e1dcd

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

tools/testing/selftests/net/rtnetlink.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ALL_TESTS="
2929
kci_test_bridge_parent_id
3030
kci_test_address_proto
3131
kci_test_enslave_bonding
32+
kci_test_mngtmpaddr
3233
"
3334

3435
devdummy="test-dummy0"
@@ -44,6 +45,7 @@ check_err()
4445
if [ $ret -eq 0 ]; then
4546
ret=$1
4647
fi
48+
[ -n "$2" ] && echo "$2"
4749
}
4850

4951
# same but inverted -- used when command must fail for test to pass
@@ -1239,6 +1241,99 @@ kci_test_enslave_bonding()
12391241
ip netns del "$testns"
12401242
}
12411243

1244+
# Called to validate the addresses on $IFNAME:
1245+
#
1246+
# 1. Every `temporary` address must have a matching `mngtmpaddr`
1247+
# 2. Every `mngtmpaddr` address must have some un`deprecated` `temporary`
1248+
#
1249+
# If the mngtmpaddr or tempaddr checking failed, return 0 and stop slowwait
1250+
validate_mngtmpaddr()
1251+
{
1252+
local dev=$1
1253+
local prefix=""
1254+
local addr_list=$(ip -j -n $testns addr show dev ${dev})
1255+
local temp_addrs=$(echo ${addr_list} | \
1256+
jq -r '.[].addr_info[] | select(.temporary == true) | .local')
1257+
local mng_prefixes=$(echo ${addr_list} | \
1258+
jq -r '.[].addr_info[] | select(.mngtmpaddr == true) | .local' | \
1259+
cut -d: -f1-4 | tr '\n' ' ')
1260+
local undep_prefixes=$(echo ${addr_list} | \
1261+
jq -r '.[].addr_info[] | select(.temporary == true and .deprecated != true) | .local' | \
1262+
cut -d: -f1-4 | tr '\n' ' ')
1263+
1264+
# 1. All temporary addresses (temp and dep) must have a matching mngtmpaddr
1265+
for address in ${temp_addrs}; do
1266+
prefix=$(echo ${address} | cut -d: -f1-4)
1267+
if [[ ! " ${mng_prefixes} " =~ " $prefix " ]]; then
1268+
check_err 1 "FAIL: Temporary $address with no matching mngtmpaddr!";
1269+
return 0
1270+
fi
1271+
done
1272+
1273+
# 2. All mngtmpaddr addresses must have a temporary address (not dep)
1274+
for prefix in ${mng_prefixes}; do
1275+
if [[ ! " ${undep_prefixes} " =~ " $prefix " ]]; then
1276+
check_err 1 "FAIL: No undeprecated temporary in $prefix!";
1277+
return 0
1278+
fi
1279+
done
1280+
1281+
return 1
1282+
}
1283+
1284+
kci_test_mngtmpaddr()
1285+
{
1286+
local ret=0
1287+
1288+
setup_ns testns
1289+
if [ $? -ne 0 ]; then
1290+
end_test "SKIP mngtmpaddr tests: cannot add net namespace $testns"
1291+
return $ksft_skip
1292+
fi
1293+
1294+
# 1. Create a dummy Ethernet interface
1295+
run_cmd ip -n $testns link add ${devdummy} type dummy
1296+
run_cmd ip -n $testns link set ${devdummy} up
1297+
run_cmd ip netns exec $testns sysctl -w net.ipv6.conf.${devdummy}.use_tempaddr=1
1298+
run_cmd ip netns exec $testns sysctl -w net.ipv6.conf.${devdummy}.temp_prefered_lft=10
1299+
run_cmd ip netns exec $testns sysctl -w net.ipv6.conf.${devdummy}.temp_valid_lft=25
1300+
run_cmd ip netns exec $testns sysctl -w net.ipv6.conf.${devdummy}.max_desync_factor=1
1301+
1302+
# 2. Create several mngtmpaddr addresses on that interface.
1303+
# with temp_*_lft configured to be pretty short (10 and 35 seconds
1304+
# for prefer/valid respectively)
1305+
for i in $(seq 1 9); do
1306+
run_cmd ip -n $testns addr add 2001:db8:7e57:${i}::1/64 mngtmpaddr dev ${devdummy}
1307+
done
1308+
1309+
# 3. Confirm that a preferred temporary address exists for each mngtmpaddr
1310+
# address at all times, polling once per second for 30 seconds.
1311+
slowwait 30 validate_mngtmpaddr ${devdummy}
1312+
1313+
# 4. Delete each mngtmpaddr address, one at a time (alternating between
1314+
# deleting and merely un-mngtmpaddr-ing), and confirm that the other
1315+
# mngtmpaddr addresses still have preferred temporaries.
1316+
for i in $(seq 1 9); do
1317+
(( $i % 4 == 0 )) && mng_flag="mngtmpaddr" || mng_flag=""
1318+
if (( $i % 2 == 0 )); then
1319+
run_cmd ip -n $testns addr del 2001:db8:7e57:${i}::1/64 $mng_flag dev ${devdummy}
1320+
else
1321+
run_cmd ip -n $testns addr change 2001:db8:7e57:${i}::1/64 dev ${devdummy}
1322+
fi
1323+
# the temp addr should be deleted
1324+
validate_mngtmpaddr ${devdummy}
1325+
done
1326+
1327+
if [ $ret -ne 0 ]; then
1328+
end_test "FAIL: mngtmpaddr add/remove incorrect"
1329+
else
1330+
end_test "PASS: mngtmpaddr add/remove correctly"
1331+
fi
1332+
1333+
ip netns del "$testns"
1334+
return $ret
1335+
}
1336+
12421337
kci_test_rtnl()
12431338
{
12441339
local current_test

0 commit comments

Comments
 (0)