ixfr_init.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. . /home/stephen/bind10/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. # \brief Check Arguments
  25. #
  26. # All functions take the name of the server as the firsrt argument and its IP
  27. # address as the second. This function is passed "$*" and just checks that
  28. # both $1 and $2 are defined.
  29. #
  30. # \arg $* Arguments passed to caller
  31. #
  32. # \return status 0 => $1 and $2 are defined, 1 => they are not.
  33. check_name_ip() {
  34. if [ "$1" = "" ];
  35. then
  36. echo "R:FAIL name of server not supplied"
  37. return 1
  38. fi
  39. if [ "$2" = "" ];
  40. then
  41. echo "R:FAIL IP address of server not supplied"
  42. return 1
  43. fi
  44. return 0
  45. }
  46. # \brief Perform RNDC Command
  47. #
  48. # Controls the BIND 9 IXFR server. Called do_rndc (instead of rndc) to avoid
  49. # confusion if rndc itself is in the search path.
  50. #
  51. # $1 - Name of the server (ns1, nsx2 etc.)
  52. # $2 - IP address of the server
  53. # $* - Command to execute (which may be multiple tokens)
  54. do_rndc () {
  55. # If the following checks fail, the code is wrong.
  56. check_name_ip $*
  57. if [ $? -ne 0 ];
  58. then
  59. echo "R:FAIL do_rndc - name or ip address of server not supplied"
  60. return 1
  61. fi
  62. name=$1
  63. shift
  64. ip=$1
  65. shift
  66. if [ "$1" = "" ];
  67. then
  68. echo "R:FAIL do_rndc - rndc command not supplied"
  69. return 1
  70. fi
  71. $RNDC -c $SYSTEM_TOP/common/rndc.conf -s $ip -p $RNDC_PORT $* 2>&1 \
  72. | sed "s/^/I:$name /"
  73. }
  74. # wait_for_update
  75. #
  76. # Given a serial number and a server, poll the nameserver until the SOA serial
  77. # number is different from that given. The poll takes place every five seconds
  78. # for a minute.
  79. #
  80. # $1 - Name of the server
  81. # $2 - IP address of the server
  82. # $3 - Serial number to check against
  83. #
  84. # Returns:
  85. # 0 - Serial number is different (requires another poll to obtain it)
  86. # 1 - Serial number has not changed
  87. wait_for_update() {
  88. # If the following checks fail, the code is wrong.
  89. check_name_ip $*
  90. if [ $? -ne 0 ];
  91. then
  92. echo "R:FAIL wait_for_update - name or ip address of system not supplied"
  93. return 1
  94. fi
  95. name=$1
  96. shift
  97. ip=$1
  98. shift
  99. serial=$1
  100. shift
  101. if [ "$serial" = "" ];
  102. then
  103. echo "R:FAIL wait_for_update - serial number not supplied"
  104. return 1
  105. fi
  106. # Now poll the server looking for the new serial number
  107. for i in 1 2 3 4 5 6 7 8 9 10 11 12
  108. do
  109. if [ $i -gt 1 ];
  110. then
  111. sleep 5
  112. fi
  113. new_serial=`$DIG_SOA @$ip | $AWK '{print $3}'`
  114. if [ "$new_serial" != "$serial" ];
  115. then
  116. return 0
  117. fi
  118. done
  119. echo "R:$name FAIL serial number has not updated"
  120. return 1
  121. }
  122. # update_server_zone
  123. #
  124. # Reloads the example. zone in the BIND 9 IXFR server and waits a maximum of
  125. # one minute for it to be served.
  126. #
  127. # $1 - Name of the server (ns1, nsx2 etc.)
  128. # $2 - IP address of the server
  129. # $3 - Zone file to load
  130. # $* - Command to execute (which may be multiple tokens)
  131. update_server_zone() {
  132. # If the following checks fail, the code is wrong.
  133. check_name_ip $*
  134. if [ $? -ne 0 ];
  135. then
  136. echo "R:FAIL update_server_zone - name or ip address of server not supplied"
  137. return 1
  138. fi
  139. name=$1
  140. shift
  141. ip=$1
  142. shift
  143. file=$1
  144. shift
  145. if [ "$file" = "" ];
  146. then
  147. echo "R:FAIL update_server_zone - new zone file not supplied"
  148. return 1
  149. fi
  150. if [ ! -e $file ];
  151. then
  152. echo "R:FAIL update_server_zone - zone file does not exist: $file"
  153. return 1
  154. fi
  155. old_serial=`$DIG_SOA @$ip | $AWK '{print $3}'`
  156. echo "I:$name IXFR server loading $1"
  157. cp $file $name/zone.db
  158. do_rndc $name $ip reload
  159. if [ $? -ne 0 ];
  160. then
  161. return 1 # Message will have already been output
  162. fi
  163. wait_for_update $name $ip $old_serial
  164. if [ $? -ne 0 ];
  165. then
  166. echo "R:$name FAIL IXFR server did not update zone after reload"
  167. return 1
  168. fi
  169. new_serial=`$DIG_SOA @$ip | $AWK '{print $3}'`
  170. echo "I:$name was at serial $old_serial, now at $new_serial"
  171. return 0
  172. }