altnames.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. lib_dir=$(dirname $0)/forwarding
  4. ALL_TESTS="altnames_test"
  5. NUM_NETIFS=0
  6. source $lib_dir/lib.sh
  7. DUMMY_DEV=dummytest
  8. SHORT_NAME=shortname
  9. LONG_NAME=someveryveryveryveryveryverylongname
  10. altnames_test()
  11. {
  12. RET=0
  13. local output
  14. local name
  15. ip link property add $DUMMY_DEV altname $SHORT_NAME
  16. check_err $? "Failed to add short alternative name"
  17. output=$(ip -j -p link show $SHORT_NAME)
  18. check_err $? "Failed to do link show with short alternative name"
  19. name=$(echo $output | jq -e -r ".[0].altnames[0]")
  20. check_err $? "Failed to get short alternative name from link show JSON"
  21. [ "$name" == "$SHORT_NAME" ]
  22. check_err $? "Got unexpected short alternative name from link show JSON"
  23. ip -j -p link show $DUMMY_DEV &>/dev/null
  24. check_err $? "Failed to do link show with original name"
  25. ip link property add $DUMMY_DEV altname $LONG_NAME
  26. check_err $? "Failed to add long alternative name"
  27. output=$(ip -j -p link show $LONG_NAME)
  28. check_err $? "Failed to do link show with long alternative name"
  29. name=$(echo $output | jq -e -r ".[0].altnames[1]")
  30. check_err $? "Failed to get long alternative name from link show JSON"
  31. [ "$name" == "$LONG_NAME" ]
  32. check_err $? "Got unexpected long alternative name from link show JSON"
  33. ip link property del $DUMMY_DEV altname $SHORT_NAME
  34. check_err $? "Failed to delete short alternative name"
  35. ip -j -p link show $SHORT_NAME &>/dev/null
  36. check_fail $? "Unexpected success while trying to do link show with deleted short alternative name"
  37. # long name is left there on purpose to be removed alongside the device
  38. log_test "altnames test"
  39. }
  40. setup_prepare()
  41. {
  42. ip link add name $DUMMY_DEV type dummy
  43. }
  44. cleanup()
  45. {
  46. pre_cleanup
  47. ip link del name $DUMMY_DEV
  48. }
  49. trap cleanup EXIT
  50. setup_prepare
  51. tests_run
  52. exit $EXIT_STATUS