ifconfig.test 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. [ -f testing.sh ] && . testing.sh
  22. if [ "$(id -u)" -ne 0 ]
  23. then
  24. echo "$SHOWSKIP: ifconfig (not root)"
  25. return 2>/dev/null
  26. exit
  27. fi
  28. #testing "name" "command" "result" "infile" "stdin"
  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. # Test Description: Disable the dummy0 interface
  38. # Results Expected: After calling ifconfig, no lines with dummy0 are displayed
  39. testing "dummy0 down and if config /-only" \
  40. "ifconfig dummy0 down && ifconfig | grep dummy | wc -l" \
  41. "0\n" "" ""
  42. # Test Description: Enable the dummy0 interface
  43. # Results Expected: After calling ifconfig, one line with dummy0 is displayed
  44. testing "dummy0 up" \
  45. "ifconfig dummy0 up && ifconfig dummy0 | grep dummy | wc -l" \
  46. "1\n" "" ""
  47. # Test Description: Set the ip address of the dummy0 interface
  48. # Results Expected: After calling ifconfig dummy0, one line displays the ip
  49. # address selected
  50. testing "dummy0 10.240.240.240" \
  51. "ifconfig dummy0 10.240.240.240 && ifconfig dummy0 | grep 10\.240\.240\.240 | wc -l" \
  52. "1\n" "" ""
  53. # Test Description: Change the netmask to the interface
  54. # Results Expected: After calling ifconfig dummy0, one line displays the
  55. # netmask selected
  56. testing "dummy0 netmask 255.255.240.0" \
  57. "ifconfig dummy0 netmask 255.255.240.0 && ifconfig dummy0 | grep 255\.255\.240\.0 | wc -l" \
  58. "1\n" "" ""
  59. # Test Description: Change the broadcast address to the interface
  60. # Results Expected: After calling ifconfig dummy0, one line displays the
  61. # broadcast address selected
  62. testing "dummy0 broadcast 10.240.240.255" \
  63. "ifconfig dummy0 broadcast 10.240.240.255 && ifconfig dummy0 | grep 10\.240\.240\.255 | wc -l" \
  64. "1\n" "" ""
  65. # Test Description: Revert to the default ip address
  66. # Results Expected: After calling ifconfig dummy0, there are no lines
  67. # displaying the ip address previously selected
  68. testing "dummy0 default" \
  69. "ifconfig dummy0 default && ifconfig dummy0 | grep 10\.240\.240\.240 | wc -l" \
  70. "0\n" "" ""
  71. # Test Description: Change the Maximum transmission unit (MTU) of the interface
  72. # Results Expected: After calling ifconfig dummy0, there is one line with the
  73. # selected MTU
  74. testing "dummy0 mtu 1269" \
  75. "ifconfig dummy0 mtu 1269 && ifconfig dummy0 | grep 1269 | wc -l" \
  76. "1\n" "" ""
  77. # Test Description: ifconfig add for IPv6 fails with an mtu too small for IPv6.
  78. # Results Expected: Failure. No check for the exact error because old kernels
  79. # used ENOBUFS but 5.4 uses EINVAL.
  80. testing "dummy0 add ::2 -- too small mtu" \
  81. "ifconfig dummy0 add ::2 2>/dev/null || echo expected" "expected\n" "" ""
  82. # Test Description: Change the Maximum transmission unit (MTU) of the interface
  83. # Results Expected: After calling ifconfig dummy0, there is one line with the
  84. # selected MTU
  85. testing "dummy0 mtu 2000" \
  86. "ifconfig dummy0 mtu 2000 && ifconfig dummy0 | grep 2000 | wc -l" \
  87. "1\n" "" ""
  88. # Test Description: Verify ifconfig add succeeds with a larger mtu
  89. # Results Expected: after calling ifconfig dummy0, there is one line with the
  90. # selected ip address
  91. testing "dummy0 add ::2" \
  92. "ifconfig dummy0 add ::2/126 && ifconfig dummy0 | grep \:\:2/126 | wc -l" \
  93. "1\n" "" ""
  94. # Test Description: Verify ifconfig del removes the selected ip6 address
  95. # Results Expected: after calling ifconfig dummy0, there are no lines with the
  96. # selected ip address
  97. testing "dummy0 del ::2" \
  98. "ifconfig dummy0 del ::2/126 && ifconfig dummy0 | grep \:\:2/126 | wc -l" \
  99. "0\n" "" ""
  100. # Test Description: Remove the noarp flag and bring the interface down in
  101. # preparation for the next test
  102. # Results Expected: After calling ifconfig dummy0, there are no lines with the
  103. # NOARP flag
  104. testing "dummy0 arp down" \
  105. "ifconfig dummy0 arp down && ifconfig dummy0 | grep -i NOARP | wc -l" \
  106. "0\n" "" ""
  107. # Test Description: Call the pointopoint option with no argument
  108. # Results Expected: After calling ifconfig dummy0, there is one line with the
  109. # NOARP and UP flags
  110. # TODO: http://lists.landley.net/pipermail/toybox-landley.net/2014-November/003795.html
  111. #testing "dummy0 pointopoint" \
  112. #"ifconfig dummy0 pointopoint && ifconfig dummy0 | grep -i NOARP | grep -i UP | wc -l" \
  113. #"1\n" "" ""
  114. # Test Description: Test the pointopoint option and set the ipaddress
  115. # Results Expected: After calling ifconfig dummy0, there is one line with the
  116. # word inet and the selected ip address
  117. # TODO: http://lists.landley.net/pipermail/toybox-landley.net/2014-November/003795.html
  118. #testing "dummy0 pointopoint 127.0.0.2" \
  119. #"ifconfig dummy0 pointopoint 127.0.0.2 && ifconfig dummy0 | grep -i inet | grep -i 127\.0\.0\.2 | wc -l" \
  120. #"1\n" "" ""
  121. ####### Flags you can set on an interface (or -remove by prefixing with -): ###############
  122. # Test Description: Enable allmulti mode on the interface
  123. # Results Expected: After calling ifconfig dummy0, there is one line with the
  124. # allmulti flag
  125. testing "dummy0 allmulti" \
  126. "ifconfig dummy0 allmulti && ifconfig dummy0 | grep -i allmulti | wc -l" "1\n" \
  127. "" ""
  128. # Test Description: Disable multicast mode the interface
  129. # Results Expected: After calling ifconfig dummy0, there are no lines with the
  130. # allmulti flag
  131. testing "dummy0 -allmulti" \
  132. "ifconfig dummy0 -allmulti && ifconfig dummy0 | grep -i allmulti | wc -l" "0\n" \
  133. "" ""
  134. # Test Description: Disable NOARP mode on the interface
  135. # Results Expected: After calling ifconfig dummy0, there are no lines with the
  136. # NOARP flag
  137. testing "dummy0 arp" \
  138. "ifconfig dummy0 arp && ifconfig dummy0 | grep -i NOARP | wc -l" "0\n" \
  139. "" ""
  140. # Test Description: Enable NOARP mode on the interface
  141. # Results Expected: After calling ifconfig dummy0, there is one line with the
  142. # NOARP flag
  143. testing "dummy0 -arp" \
  144. "ifconfig dummy0 -arp && ifconfig dummy0 | grep -i NOARP | wc -l" "1\n" \
  145. "" ""
  146. # Test Description: Enable multicast mode on the interface
  147. # Results Expected: After calling ifconfig dummy0, there is one line with the
  148. # multicast flag
  149. testing "dummy0 multicast" \
  150. "ifconfig dummy0 multicast && ifconfig dummy0 | grep -i multicast | wc -l" \
  151. "1\n" "" ""
  152. # Test Description: Disable multicast mode the interface
  153. # Results Expected: After calling ifconfig dummy0, there are no lines with the
  154. # multicast flag
  155. testing "dummy0 -multicast" \
  156. "ifconfig dummy0 -multicast && ifconfig dummy0 | grep -i multicast | wc -l" \
  157. "0\n" "" ""
  158. # Test Description: Enable promiscuous mode the interface
  159. # Results Expected: After calling ifconfig dummy0, there is one line with the
  160. # promisc flag
  161. testing "dummy0 promisc" \
  162. "ifconfig dummy0 promisc && ifconfig dummy0 | grep -i promisc | wc -l" "1\n" \
  163. "" ""
  164. # Disable promiscuous mode the interface
  165. # Results Expected: After calling ifconfig dummy0, there are no lines with the
  166. # promisc flag
  167. testing "dummy0 -promisc" \
  168. "ifconfig dummy0 -promisc && ifconfig dummy0 | grep -i promisc | wc -l" "0\n" \
  169. "" ""
  170. # Disable the dummy interface
  171. ifconfig dummy0 down