ixfr_init.sh.in 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2011 Internet Software Consortium.
  4. #
  5. # Permission to use, copy, modify, and/or distribute this software for any
  6. # purpose with or without fee is hereby granted, provided that the above
  7. # copyright notice and this permission notice appear in all copies.
  8. #
  9. # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  10. # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11. # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  13. # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  14. # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. # PERFORMANCE OF THIS SOFTWARE.
  16. # \file
  17. # This file should be run by all IXFR tests before going anything else. It
  18. # includes the main configuration script that defines the various environment
  19. # variables, as well as defining useful shell subroutines.
  20. . @abs_top_builddir@/tests/system/conf.sh
  21. # Useful symbols used in the IXFR tests.
  22. # Short-hand for getting SOA - just supply address of the server
  23. DIG_SOA="$DIG +norecurse +short -p $DNS_PORT example. SOA"
  24. # All IXFR tests use a BIND 9 server serving a BIND 10 client
  25. SERVER_NAME=ns1
  26. SERVER_IP=10.53.0.1 # BIND 9
  27. CLIENT_NAME=nsx2
  28. CLIENT_IP=10.53.0.2 # BIND 10
  29. # \brief Check Arguments
  30. #
  31. # All functions take the name of the server as the firsrt argument and its IP
  32. # address as the second. This function is passed "$*" and just checks that
  33. # both $1 and $2 are defined.
  34. #
  35. # \arg $* Arguments passed to caller
  36. #
  37. # \return status 0 => $1 and $2 are defined, 1 => they are not.
  38. check_name_ip() {
  39. if [ "$1" = "" ];
  40. then
  41. echo "R:FAIL name of server not supplied"
  42. return 1
  43. fi
  44. if [ "$2" = "" ];
  45. then
  46. echo "R:FAIL IP address of server not supplied"
  47. return 1
  48. fi
  49. return 0
  50. }
  51. # \brief Perform RNDC Command
  52. #
  53. # Controls the BIND 9 IXFR server. Called do_rndc (instead of rndc) to avoid
  54. # confusion if rndc itself is in the search path.
  55. #
  56. # $1 - Name of the server (ns1, nsx2 etc.)
  57. # $2 - IP address of the server
  58. # $* - Command to execute (which may be multiple tokens)
  59. do_rndc () {
  60. # If the following checks fail, the code is wrong.
  61. check_name_ip $*
  62. if [ $? -ne 0 ];
  63. then
  64. echo "R:FAIL do_rndc - name or ip address of server not supplied"
  65. return 1
  66. fi
  67. name=$1
  68. shift
  69. ip=$1
  70. shift
  71. if [ "$1" = "" ];
  72. then
  73. echo "R:FAIL do_rndc - rndc command not supplied"
  74. return 1
  75. fi
  76. $RNDC -c $SYSTEM_TOP/common/rndc.conf -s $ip -p $RNDC_PORT $* 2>&1 \
  77. | sed "s/^/I:$name /"
  78. }
  79. # wait_for_update
  80. #
  81. # Given a serial number and a server, poll the nameserver until the SOA serial
  82. # number is different from that given. The poll takes place every five seconds
  83. # for a minute.
  84. #
  85. # $1 - Name of the server
  86. # $2 - IP address of the server
  87. # $3 - Serial number to check against
  88. #
  89. # Returns:
  90. # 0 - Serial number is different (requires another poll to obtain it)
  91. # 1 - Serial number has not changed
  92. wait_for_update() {
  93. # If the following checks fail, the code is wrong.
  94. check_name_ip $*
  95. if [ $? -ne 0 ];
  96. then
  97. echo "R:FAIL wait_for_update - name or ip address of system not supplied"
  98. return 1
  99. fi
  100. name=$1
  101. shift
  102. ip=$1
  103. shift
  104. serial=$1
  105. shift
  106. if [ "$serial" = "" ];
  107. then
  108. echo "R:FAIL wait_for_update - serial number not supplied"
  109. return 1
  110. fi
  111. # Now poll the server looking for the new serial number
  112. for i in 1 2 3 4 5 6 7 8 9 10 11 12
  113. do
  114. if [ $i -gt 1 ];
  115. then
  116. sleep 5
  117. fi
  118. new_serial=`$DIG_SOA @$ip | $AWK '{print $3}'`
  119. if [ "$new_serial" != "$serial" ];
  120. then
  121. return 0
  122. fi
  123. done
  124. echo "R:$name FAIL serial number has not updated"
  125. return 1
  126. }
  127. # update_server_zone
  128. #
  129. # Reloads the example. zone in the BIND 9 IXFR server and waits a maximum of
  130. # one minute for it to be served.
  131. #
  132. # $1 - Name of the server (ns1, nsx2 etc.)
  133. # $2 - IP address of the server
  134. # $3 - Zone file to load
  135. # $* - Command to execute (which may be multiple tokens)
  136. update_server_zone() {
  137. # If the following checks fail, the code is wrong.
  138. check_name_ip $*
  139. if [ $? -ne 0 ];
  140. then
  141. echo "R:FAIL update_server_zone - name or ip address of server not supplied"
  142. return 1
  143. fi
  144. name=$1
  145. shift
  146. ip=$1
  147. shift
  148. file=$1
  149. shift
  150. if [ "$file" = "" ];
  151. then
  152. echo "R:FAIL update_server_zone - new zone file not supplied"
  153. return 1
  154. fi
  155. if [ ! -e $file ];
  156. then
  157. echo "R:FAIL update_server_zone - zone file does not exist: $file"
  158. return 1
  159. fi
  160. old_serial=`$DIG_SOA @$ip | $AWK '{print $3}'`
  161. echo "I:$name IXFR server loading $1"
  162. cp $file $name/db.example
  163. do_rndc $name $ip reload
  164. if [ $? -ne 0 ];
  165. then
  166. return 1 # Message will have already been output
  167. fi
  168. wait_for_update $name $ip $old_serial
  169. if [ $? -ne 0 ];
  170. then
  171. echo "R:$name FAIL IXFR server did not update zone after reload"
  172. return 1
  173. fi
  174. new_serial=`$DIG_SOA @$ip | $AWK '{print $3}'`
  175. echo "I:$name was at serial $old_serial, now at $new_serial"
  176. return 0
  177. }
  178. # \brief Compare client and server SOAs
  179. #
  180. # Checks the SOAs of two systems and reports if they are not equal.
  181. #
  182. # \arg $1 Name of the IXFR server
  183. # \arg $2 IP of the IXFR server
  184. # \arg $3 Name of the IXFR client
  185. # \arg $4 IP of the IXFR client
  186. #
  187. # \return 0 if the systems have the same SOA, 1 if not. In the latter case,
  188. # an error will be output.
  189. compare_soa() {
  190. # If the following checks fail, the code is wrong.
  191. check_name_ip $*
  192. if [ $? -ne 0 ];
  193. then
  194. echo "R:FAIL compare_soa - name or ip address of server not supplied"
  195. return 1
  196. fi
  197. server_name=$1
  198. shift
  199. server_ip=$1
  200. shift
  201. check_name_ip $*
  202. if [ $? -ne 0 ];
  203. then
  204. echo "R:FAIL compare_soa - name or ip address of client not supplied"
  205. return 1
  206. fi
  207. client_name=$1
  208. shift
  209. client_ip=$1
  210. shift
  211. client_serial=`$DIG_SOA @$client_ip | $AWK '{print $3}'`
  212. server_serial=`$DIG_SOA @$server_ip | $AWK '{print $3}'`
  213. if [ "$client_serial" != "$server_serial" ];
  214. then
  215. echo "R:FAIL client $client_name serial $client_serial not same as server $server_name serial $server_serial"
  216. return 1
  217. fi
  218. return 0
  219. }