netns_breakns.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. #==============================================================================
  3. # Copyright (c) 2015 Red Hat, Inc.
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of version 2 the GNU General Public License as
  7. # published by the Free Software Foundation.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #
  17. # Written by Matus Marhefka <mmarhefk@redhat.com>
  18. #
  19. #==============================================================================
  20. #
  21. # SYNOPSIS:
  22. # netns_breakns.sh <NS_EXEC_PROGRAM> <IP_VERSION> <COMM_TYPE>
  23. #
  24. # OPTIONS:
  25. # * NS_EXEC_PROGRAM (ns_exec|ip)
  26. # Program which will be used to enter and run other commands
  27. # inside a network namespace.
  28. # * IP_VERSION (ipv4|ipv6)
  29. # Version of IP. (ipv4|ipv6)
  30. # * COMM_TYPE (netlink|ioctl)
  31. # Communication type between kernel and user space
  32. # for basic setup: enabling and assigning IP addresses
  33. # to the virtual ethernet devices. (Uses 'ip' command for netlink
  34. # and 'ifconfig' for ioctl.)
  35. #
  36. # Tests communication with ip (uses netlink) and ifconfig (uses ioctl)
  37. # over a device which is not visible from the current network namespace.
  38. #
  39. # There are two test cases which are trying to set an ip address on the veth1
  40. # device which is not inside the network namespace referred to by NS_HANDLE0:
  41. # 1. using netlink (ip command).
  42. # 2. using ioctl (ifconfig command).
  43. #==============================================================================
  44. TCID="netns_breakns_$1_$2_$3"
  45. TST_TOTAL=2
  46. . netns_helper.sh
  47. # SETUP
  48. netns_setup $1 $2 $3 "192.168.0.2" "192.168.0.3" "fd00::2" "fd00::3"
  49. tst_resm TINFO "NS interaction: $1 | devices setup: $3"
  50. # TEST CASE #1
  51. $NS_EXEC $NS_HANDLE0 $NS_TYPE ip address add $IP1/$NETMASK dev veth1 2>/dev/null
  52. if [ $? -ne 0 ]; then
  53. tst_resm TPASS "controlling device over netlink"
  54. else
  55. tst_resm TFAIL "controlling device over netlink"
  56. fi
  57. # TEST CASE #2
  58. tst_require_cmds ifconfig
  59. $NS_EXEC $NS_HANDLE0 $NS_TYPE ifconfig veth1 $IFCONF_IN6_ARG $IP1/$NETMASK 2>/dev/null
  60. if [ $? -ne 0 ]; then
  61. tst_resm TPASS "controlling device over ioctl"
  62. else
  63. tst_resm TFAIL "controlling device over ioctl"
  64. fi
  65. tst_exit