run_test_nta 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #! /bin/sh
  2. #
  3. # Run nta_test with our own name server
  4. #
  5. # --------------------------------------------------------------------
  6. #
  7. # This file is part of the Sofia-SIP package
  8. #
  9. # Copyright (C) 2005 Nokia Corporation.
  10. #
  11. # Contact: Pekka Pessi <pekka.pessi@nokia.com>
  12. #
  13. # This library is free software; you can redistribute it and/or
  14. # modify it under the terms of the GNU Lesser General Public License
  15. # as published by the Free Software Foundation; either version 2.1 of
  16. # the License, or (at your option) any later version.
  17. #
  18. # This library is distributed in the hope that it will be useful, but
  19. # WITHOUT ANY WARRANTY; without even the implied warranty of
  20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. # Lesser General Public License for more details.
  22. #
  23. # You should have received a copy of the GNU Lesser General Public
  24. # License along with this library; if not, write to the Free Software
  25. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  26. # 02110-1301 USA
  27. #
  28. # --------------------------------------------------------------------
  29. #
  30. # Author: Pekka Pessi <Pekka.Pessi@nokia.com>.
  31. #
  32. #set -x
  33. s=${0%/*}
  34. resolvfile=.test$$.resolv.conf
  35. namedfile=.test$$.named.conf
  36. pidfile=.test$$.named.pid
  37. zonefile=.test$$.example.zone
  38. test x$s = x$0 && s=`pwd`
  39. test -z "$srcdir" && srcdir=$s
  40. export srcdir
  41. PATH=/usr/sbin:/usr/local/sbin:/sbin:$PATH
  42. export PATH
  43. me6="::1"
  44. if ../su/localinfo -6 -n -g -s > /dev/null 2>&1 ; then
  45. ipv6=true aaaa=aaaa v6flag=-6
  46. me6=$(../su/localinfo -6 -n -s -g | awk '{print $1; exit(0); }')
  47. else
  48. if ! ../su/localinfo '--help' > /dev/null 2>&1 ; then
  49. echo "warning: $0: missing 'localinfo', cannot test IPv6"
  50. else
  51. echo "warning: $0: no valid IPv6 addresses available"
  52. fi
  53. ipv6=false aaaa=a
  54. fi
  55. if type named > /dev/null 2>&1 && ./portbind --help > /dev/null 2>&1
  56. then
  57. port=$(./portbind $v6flag) sink=$port
  58. port=$(./portbind $v6flag $((port + 1))) down=$port
  59. port=$(./portbind $v6flag $((port + 1))) bind=$port
  60. port=$(./portbind $v6flag $((port + 1))) contact=$port
  61. port=$(./portbind $v6flag $((port + 1))) sips=$port
  62. # Disable IPv6 resolver for now
  63. if false && eval $ipv6 ; then
  64. listen="listen-on-v6 port $bind { any; };"
  65. ns=$me6
  66. else
  67. listen="listen-on port $bind { 127.0.0.1; };"
  68. ns="127.0.0.1"
  69. fi
  70. cat > $resolvfile <<EOF
  71. nameserver $ns
  72. domain example.com
  73. port $bind
  74. EOF
  75. cat > $namedfile <<EOF
  76. options {
  77. pid-file "$pidfile";
  78. $listen
  79. };
  80. zone "example.org" in {
  81. type master;
  82. file "$zonefile";
  83. };
  84. EOF
  85. cat > $zonefile << EOF
  86. ;
  87. ; Zone file for example.org
  88. ; SIP targets: example.org
  89. ; srv.example.org
  90. ; down.example.org
  91. ; na.example.org
  92. ; ipv6-20-80.example.org
  93. ; ipv.example.org
  94. ;
  95. \$TTL 60
  96. @ IN SOA ns root (
  97. 2002042901 ; SERIAL
  98. 7200 ; REFRESH
  99. 600 ; RETRY
  100. 36000000 ; EXPIRE
  101. 60 ; MINIMUM
  102. )
  103. NS ns
  104. ;; order pref flags service regexp replacement
  105. NAPTR 20 15 "s" "SIP+D2U" "" _sip._udp
  106. NAPTR 40 25 "s" "SIPS+D2T" "" _sips._tcp
  107. NAPTR 40 50 "s" "SIP+D2T" "" _sip._tcp
  108. ns AAAA $me6
  109. A 127.0.0.1
  110. _sip._udp SRV 1 100 $contact me
  111. _sips._tcp SRV 3 100 $sips me
  112. _sip._tcp SRV 2 100 $contact me
  113. _sip._udp.srv SRV 1 100 $contact a
  114. _sips._tcp.srv SRV 3 100 $sips a
  115. _sip._tcp.srv SRV 2 100 $contact $aaaa
  116. _sip._udp.srv2 SRV 1 200 $contact c
  117. SRV 1 100 $contact b
  118. SRV 1 50 $contact a
  119. me AAAA $me6
  120. A 127.0.0.1
  121. a A 127.0.0.1
  122. b A 0.0.0.2
  123. c A 0.0.0.3
  124. aaaa AAAA $me6
  125. ; Directly from NAPTR to A/AAAA (Test 1.6c)
  126. na NAPTR 20 15 "a" "SIP+D2T" "" a2
  127. ; No sensible NAPTR match (and we get 503)
  128. na503 NAPTR 20 15 "S" "SIP+D2F" "" a2
  129. ; No SIP NAPTR match
  130. nona NAPTR 20 15 "S" "ZIP+D2U" "" a2
  131. _sip._udp.nona SRV 1 10 $contact ip4
  132. ; First SIP SRV is not found
  133. nosrv NAPTR 20 1 "s" "SIP+D2U" "" _sip._udp.nosrv
  134. NAPTR 20 2 "s" "SIP+D2T" "" _sip._tcp.nosrv
  135. NAPTR 20 3 "s" "SIP+D2U" "" _sip._udp.srv
  136. NAPTR 20 4 "s" "SIP+D2T" "" _sip._tcp.srv
  137. ; Redirect with TLS
  138. ; This fails (and we get 503)
  139. a2 A 127.0.0.2
  140. ; IP6 should get 80%, IP4 20%
  141. ipv6-20-80 NAPTR 20 15 "s" "SIP+D2U" "" _sip._udp.ipv6-20-80
  142. _sip._udp.ipv6-20-80 SRV 1 80 $contact ip6
  143. SRV 1 20 $contact ip4
  144. _sip._udp.ipv SRV 1 100 $contact ip6
  145. _sip._udp.ipv SRV 1 100 $contact ip4
  146. ip6 AAAA $me6
  147. ip4 A 127.0.0.1
  148. ; SRV failover to me...
  149. down NAPTR 20 15 "s" "SIP+D2U" "" _sip._udp.down
  150. _sip._udp.down SRV 1 100 $down me
  151. _sip._udp.down SRV 2 100 $contact me
  152. ; A failover
  153. down2 A 0.0.0.2
  154. A 0.0.0.3
  155. A 127.0.0.1
  156. EOF
  157. # -g is also very nice option for named
  158. named -f -c $namedfile &
  159. pid=$!
  160. while ! test -r $pidfile && kill -0 $! 2>/dev/null
  161. do
  162. sleep 1
  163. done
  164. if test -r $pidfile ; then
  165. # export SOFIA_DEBUG=9
  166. sink=$sink down=$down \
  167. ipv6=$ipv6 \
  168. SIPCONTACT="sip:*:$contact;comp=sigcomp" \
  169. SIPSCONTACT="sips:*:$sips;comp=sigcomp" \
  170. TEST_NTA_CERTDIR=$srcdir/../tport/ \
  171. $VALGRIND ./test_nta "$@" - $resolvfile
  172. exit=$?
  173. kill $(cat $pidfile)
  174. rm $pidfile $zonefile $resolvfile $namedfile 2>/dev/null
  175. exit $exit
  176. else
  177. echo "$0: cannot start named (check apparmor/selinux)"
  178. ipv6=$ipv6 $VALGRIND exec ./test_nta "$@"
  179. fi
  180. else # not having BIND and portbind
  181. ipv6=$ipv6 $VALGRIND exec ./test_nta "$@"
  182. fi