1f95e6c9cSJiri Pirko#!/bin/bash 2f95e6c9cSJiri Pirko# SPDX-License-Identifier: GPL-2.0 3f95e6c9cSJiri Pirko 4f95e6c9cSJiri Pirkolib_dir=$(dirname $0)/forwarding 5f95e6c9cSJiri Pirko 6f95e6c9cSJiri PirkoALL_TESTS="altnames_test" 7f95e6c9cSJiri PirkoNUM_NETIFS=0 8f95e6c9cSJiri Pirkosource $lib_dir/lib.sh 9f95e6c9cSJiri Pirko 10f95e6c9cSJiri PirkoDUMMY_DEV=dummytest 11f95e6c9cSJiri PirkoSHORT_NAME=shortname 12f95e6c9cSJiri PirkoLONG_NAME=someveryveryveryveryveryverylongname 13f95e6c9cSJiri Pirko 14f95e6c9cSJiri Pirkoaltnames_test() 15f95e6c9cSJiri Pirko{ 16f95e6c9cSJiri Pirko RET=0 17f95e6c9cSJiri Pirko local output 18f95e6c9cSJiri Pirko local name 19f95e6c9cSJiri Pirko 20f95e6c9cSJiri Pirko ip link property add $DUMMY_DEV altname $SHORT_NAME 21f95e6c9cSJiri Pirko check_err $? "Failed to add short alternative name" 22f95e6c9cSJiri Pirko 23f95e6c9cSJiri Pirko output=$(ip -j -p link show $SHORT_NAME) 24f95e6c9cSJiri Pirko check_err $? "Failed to do link show with short alternative name" 25f95e6c9cSJiri Pirko 26f95e6c9cSJiri Pirko name=$(echo $output | jq -e -r ".[0].altnames[0]") 27f95e6c9cSJiri Pirko check_err $? "Failed to get short alternative name from link show JSON" 28f95e6c9cSJiri Pirko 29f95e6c9cSJiri Pirko [ "$name" == "$SHORT_NAME" ] 30f95e6c9cSJiri Pirko check_err $? "Got unexpected short alternative name from link show JSON" 31f95e6c9cSJiri Pirko 32f95e6c9cSJiri Pirko ip -j -p link show $DUMMY_DEV &>/dev/null 33f95e6c9cSJiri Pirko check_err $? "Failed to do link show with original name" 34f95e6c9cSJiri Pirko 35f95e6c9cSJiri Pirko ip link property add $DUMMY_DEV altname $LONG_NAME 36f95e6c9cSJiri Pirko check_err $? "Failed to add long alternative name" 37f95e6c9cSJiri Pirko 38f95e6c9cSJiri Pirko output=$(ip -j -p link show $LONG_NAME) 39f95e6c9cSJiri Pirko check_err $? "Failed to do link show with long alternative name" 40f95e6c9cSJiri Pirko 41f95e6c9cSJiri Pirko name=$(echo $output | jq -e -r ".[0].altnames[1]") 42f95e6c9cSJiri Pirko check_err $? "Failed to get long alternative name from link show JSON" 43f95e6c9cSJiri Pirko 44f95e6c9cSJiri Pirko [ "$name" == "$LONG_NAME" ] 45f95e6c9cSJiri Pirko check_err $? "Got unexpected long alternative name from link show JSON" 46f95e6c9cSJiri Pirko 47f95e6c9cSJiri Pirko ip link property del $DUMMY_DEV altname $SHORT_NAME 48*1b704b27SAndrea Claudi check_err $? "Failed to delete short alternative name" 49f95e6c9cSJiri Pirko 50f95e6c9cSJiri Pirko ip -j -p link show $SHORT_NAME &>/dev/null 51f95e6c9cSJiri Pirko check_fail $? "Unexpected success while trying to do link show with deleted short alternative name" 52f95e6c9cSJiri Pirko 53f95e6c9cSJiri Pirko # long name is left there on purpose to be removed alongside the device 54f95e6c9cSJiri Pirko 55f95e6c9cSJiri Pirko log_test "altnames test" 56f95e6c9cSJiri Pirko} 57f95e6c9cSJiri Pirko 58f95e6c9cSJiri Pirkosetup_prepare() 59f95e6c9cSJiri Pirko{ 60f95e6c9cSJiri Pirko ip link add name $DUMMY_DEV type dummy 61f95e6c9cSJiri Pirko} 62f95e6c9cSJiri Pirko 63f95e6c9cSJiri Pirkocleanup() 64f95e6c9cSJiri Pirko{ 65f95e6c9cSJiri Pirko pre_cleanup 66f95e6c9cSJiri Pirko ip link del name $DUMMY_DEV 67f95e6c9cSJiri Pirko} 68f95e6c9cSJiri Pirko 69f95e6c9cSJiri Pirkotrap cleanup EXIT 70f95e6c9cSJiri Pirko 71f95e6c9cSJiri Pirkosetup_prepare 72f95e6c9cSJiri Pirko 73f95e6c9cSJiri Pirkotests_run 74f95e6c9cSJiri Pirko 75f95e6c9cSJiri Pirkoexit $EXIT_STATUS 76