ifconfig.test 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #!/bin/bash
  2. # Copyright 2014 Cynthia Rempel <cynthia@rtems.org>
  3. #
  4. # Brief: Some cursery coverage tests of ifconfig...
  5. # Note: requires permissions to run modprobe and all ifconfig options
  6. # Commands used: grep, grep -i, ip link, ip tuntap, wc -l
  7. #
  8. # Possible improvements:
  9. # 1. Verify the dummy interface actually has the modified characteristics
  10. # instead of relying on ifconfig output
  11. # 2. Introduce more error cases, to verify ifconfig fails gracefully
  12. # 3. Do more complex calls to ifconfig, while mixing the order of the
  13. # arguments
  14. # 4. Cover more ifconfig options:
  15. # hw ether|infiniband ADDRESS - set LAN hardware address (AA:BB:CC...)
  16. # txqueuelen LEN - number of buffered packets before output blocks
  17. # Obsolete fields included for historical purposes:
  18. # irq|io_addr|mem_start ADDR - micromanage obsolete hardware
  19. # outfill|keepalive INTEGER - SLIP analog dialup line quality monitoring
  20. # metric INTEGER - added to Linux 0.9.10 with comment "never used", still true
  21. #testing "name" "command" "result" "infile" "stdin"
  22. [ -f testing.sh ] && . testing.sh
  23. if [ "$(id -u)" -ne 0 ]
  24. then
  25. echo "$SHOWSKIP: ifconfig (not root)"
  26. return 2>/dev/null
  27. exit
  28. fi
  29. # Add a dummy interface to test with
  30. modprobe dummy 2>/dev/null
  31. if ! ifconfig dummy0 up 2>/dev/null
  32. then
  33. echo "$SHOWSKIP: ifconfig dummy0 up failed"
  34. return 2>/dev/null
  35. exit
  36. fi
  37. # Results Expected: After calling ifconfig, no lines with dummy0 are displayed
  38. testing "Disable the dummy0 interface"
  39. "ifconfig dummy0 down && ifconfig | grep dummy | wc -l" "0\n" "" ""
  40. # Results Expected: After calling ifconfig, one line with dummy0 is displayed
  41. testing "Enable the dummy0 interface" \
  42. "ifconfig dummy0 up && ifconfig dummy0 | grep dummy | wc -l" "1\n" "" ""
  43. # Results Expected: After calling ifconfig dummy0, one line displays the ip
  44. # address selected
  45. testing "Set the ip address of the dummy0 interface" \
  46. "ifconfig dummy0 10.240.240.240 && ifconfig dummy0 | grep 10\.240\.240\.240 | wc -l" \
  47. "1\n" "" ""
  48. # Results Expected: After calling ifconfig dummy0, one line displays the
  49. # netmask selected
  50. testing "Change the netmask to the interface" \
  51. "ifconfig dummy0 netmask 255.255.240.0 && ifconfig dummy0 | grep 255\.255\.240\.0 | wc -l" \
  52. "1\n" "" ""
  53. # Results Expected: After calling ifconfig dummy0, one line displays the
  54. # broadcast address selected
  55. testing "Change the broadcast address to the interface" \
  56. "ifconfig dummy0 broadcast 10.240.240.255 && ifconfig dummy0 | grep 10\.240\.240\.255 | wc -l" \
  57. "1\n" "" ""
  58. # Test Description: Revert to the default ip address
  59. # Results Expected: After calling ifconfig dummy0, there are no lines
  60. # displaying the ip address previously selected
  61. testing "dummy0 default" \
  62. "ifconfig dummy0 default && ifconfig dummy0 | grep 10\.240\.240\.240 | wc -l" \
  63. "0\n" "" ""
  64. # Test Description: Change the Maximum transmission unit (MTU) of the interface
  65. # Results Expected: After calling ifconfig dummy0, there is one line with the
  66. # selected MTU
  67. testing "dummy0 mtu 1269" \
  68. "ifconfig dummy0 mtu 1269 && ifconfig dummy0 | grep 1269 | wc -l" \
  69. "1\n" "" ""
  70. # Test Description: ifconfig add for IPv6 fails with an mtu too small for IPv6.
  71. # Results Expected: Failure. No check for the exact error because old kernels
  72. # used ENOBUFS but 5.4 uses EINVAL.
  73. testing "dummy0 add ::2 -- too small mtu" \
  74. "ifconfig dummy0 add ::2 2>/dev/null || echo expected" "expected\n" "" ""
  75. # Test Description: Change the Maximum transmission unit (MTU) of the interface
  76. # Results Expected: After calling ifconfig dummy0, there is one line with the
  77. # selected MTU
  78. testing "dummy0 mtu 2000" \
  79. "ifconfig dummy0 mtu 2000 && ifconfig dummy0 | grep 2000 | wc -l" \
  80. "1\n" "" ""
  81. # Test Description: Verify ifconfig add succeeds with a larger mtu
  82. # Results Expected: after calling ifconfig dummy0, there is one line with the
  83. # selected ip address
  84. testing "dummy0 add ::2" \
  85. "ifconfig dummy0 add ::2/126 && ifconfig dummy0 | grep \:\:2/126 | wc -l" \
  86. "1\n" "" ""
  87. # Test Description: Verify ifconfig del removes the selected ip6 address
  88. # Results Expected: after calling ifconfig dummy0, there are no lines with the
  89. # selected ip address
  90. testing "dummy0 del ::2" \
  91. "ifconfig dummy0 del ::2/126 && ifconfig dummy0 | grep \:\:2/126 | wc -l" \
  92. "0\n" "" ""
  93. # Test Description: Remove the noarp flag and bring the interface down in
  94. # preparation for the next test
  95. # Results Expected: After calling ifconfig dummy0, there are no lines with the
  96. # NOARP flag
  97. testing "dummy0 arp down" \
  98. "ifconfig dummy0 arp down && ifconfig dummy0 | grep -i NOARP | wc -l" \
  99. "0\n" "" ""
  100. # Test Description: Call the pointopoint option with no argument
  101. # Results Expected: After calling ifconfig dummy0, there is one line with the
  102. # NOARP and UP flags
  103. # TODO: http://lists.landley.net/pipermail/toybox-landley.net/2014-November/003795.html
  104. #testing "dummy0 pointopoint" \
  105. #"ifconfig dummy0 pointopoint && ifconfig dummy0 | grep -i NOARP | grep -i UP | wc -l" \
  106. #"1\n" "" ""
  107. # Test Description: Test the pointopoint option and set the ipaddress
  108. # Results Expected: After calling ifconfig dummy0, there is one line with the
  109. # word inet and the selected ip address
  110. # TODO: http://lists.landley.net/pipermail/toybox-landley.net/2014-November/003795.html
  111. #testing "dummy0 pointopoint 127.0.0.2" \
  112. #"ifconfig dummy0 pointopoint 127.0.0.2 && ifconfig dummy0 | grep -i inet | grep -i 127\.0\.0\.2 | wc -l" \
  113. #"1\n" "" ""
  114. ####### Flags you can set on an interface (or -remove by prefixing with -): ###############
  115. # Test Description: Enable allmulti mode on the interface
  116. # Results Expected: After calling ifconfig dummy0, there is one line with the
  117. # allmulti flag
  118. testing "dummy0 allmulti" \
  119. "ifconfig dummy0 allmulti && ifconfig dummy0 | grep -i allmulti | wc -l" "1\n" \
  120. "" ""
  121. # Test Description: Disable multicast mode the interface
  122. # Results Expected: After calling ifconfig dummy0, there are no lines with the
  123. # allmulti flag
  124. testing "dummy0 -allmulti" \
  125. "ifconfig dummy0 -allmulti && ifconfig dummy0 | grep -i allmulti | wc -l" "0\n" \
  126. "" ""
  127. # Test Description: Disable NOARP mode on the interface
  128. # Results Expected: After calling ifconfig dummy0, there are no lines with the
  129. # NOARP flag
  130. testing "dummy0 arp" \
  131. "ifconfig dummy0 arp && ifconfig dummy0 | grep -i NOARP | wc -l" "0\n" \
  132. "" ""
  133. # Test Description: Enable NOARP mode on the interface
  134. # Results Expected: After calling ifconfig dummy0, there is one line with the
  135. # NOARP flag
  136. testing "dummy0 -arp" \
  137. "ifconfig dummy0 -arp && ifconfig dummy0 | grep -i NOARP | wc -l" "1\n" \
  138. "" ""
  139. # Test Description: Enable multicast mode on the interface
  140. # Results Expected: After calling ifconfig dummy0, there is one line with the
  141. # multicast flag
  142. testing "dummy0 multicast" \
  143. "ifconfig dummy0 multicast && ifconfig dummy0 | grep -i multicast | wc -l" \
  144. "1\n" "" ""
  145. # Test Description: Disable multicast mode the interface
  146. # Results Expected: After calling ifconfig dummy0, there are no lines with the
  147. # multicast flag
  148. testing "dummy0 -multicast" \
  149. "ifconfig dummy0 -multicast && ifconfig dummy0 | grep -i multicast | wc -l" \
  150. "0\n" "" ""
  151. # Test Description: Enable promiscuous mode the interface
  152. # Results Expected: After calling ifconfig dummy0, there is one line with the
  153. # promisc flag
  154. testing "dummy0 promisc" \
  155. "ifconfig dummy0 promisc && ifconfig dummy0 | grep -i promisc | wc -l" "1\n" \
  156. "" ""
  157. # Disable promiscuous mode the interface
  158. # Results Expected: After calling ifconfig dummy0, there are no lines with the
  159. # promisc flag
  160. testing "dummy0 -promisc" \
  161. "ifconfig dummy0 -promisc && ifconfig dummy0 | grep -i promisc | wc -l" "0\n" \
  162. "" ""
  163. # Disable the dummy interface
  164. ifconfig dummy0 down