run_test_nta 4.87 KB
Newer Older
1
#! /bin/sh
Pekka Pessi's avatar
Pekka Pessi committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#
# Run nta_test with our own name server
#
# --------------------------------------------------------------------
#
# This file is part of the Sofia-SIP package
#
# Copyright (C) 2005 Nokia Corporation.
#
# Contact: Pekka Pessi <pekka.pessi@nokia.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
#
# --------------------------------------------------------------------
#
# Author: Pekka Pessi <Pekka.Pessi@nokia.com>.
#

#set -x

s=${0%/*}

resolvfile=.test$$.resolv.conf
namedfile=.test$$.named.conf
pidfile=.test$$.named.pid
zonefile=.test$$.example.zone

test x$s = x$0 && s=`pwd`

44 45 46
test -z "$srcdir" && srcdir=$s
export srcdir

Pekka Pessi's avatar
Pekka Pessi committed
47 48 49 50 51 52
PATH=/usr/sbin:/usr/local/sbin:/sbin:$PATH

export PATH

me6="::1"

53
if ../su/localinfo -6 -n -g -s > /dev/null 2>&1 ; then
54
    ipv6=true aaaa=aaaa v6flag=-6
Pekka Pessi's avatar
Pekka Pessi committed
55 56
    me6=$(../su/localinfo -6 -n -s -g | awk '{print $1; exit(0); }')
else
57
    if ! ../su/localinfo '--help' > /dev/null 2>&1 ; then
Pekka Pessi's avatar
Pekka Pessi committed
58 59 60 61 62 63 64
	echo "warning: $0: missing 'localinfo', cannot test IPv6"
    else
	echo "warning: $0: no valid IPv6 addresses available"
    fi
    ipv6=false aaaa=a
fi

65
if type named > /dev/null 2>&1 && ./portbind --help > /dev/null 2>&1
Pekka Pessi's avatar
Pekka Pessi committed
66 67
then

68 69 70 71
port=$(./portbind $v6flag) sink=$port
port=$(./portbind $v6flag $((port + 1))) down=$port
port=$(./portbind $v6flag $((port + 1))) bind=$port
port=$(./portbind $v6flag $((port + 1))) contact=$port
Pekka Pessi's avatar
Pekka Pessi committed
72

73
# Disable IPv6 resolver for now
74
if false && eval $ipv6 ; then
Pekka Pessi's avatar
Pekka Pessi committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
    listen="listen-on-v6 port $bind { any; };"
    ns=$me6
else
    listen="listen-on port $bind { 127.0.0.1; };"
    ns="127.0.0.1"
fi

cat > $resolvfile <<EOF
nameserver $ns
domain example.com
port $bind
EOF

cat > $namedfile <<EOF
options {
	pid-file "$pidfile";
	$listen
};

zone "example.org" in {
        type master;
        file "$zonefile";
};
EOF

cat > $zonefile << EOF
;
; Zone file for example.org
; SIP targets: example.org
;              srv.example.org
;		down.example.org
;              na.example.org
;              ipv6-20-80.example.org
;              ipv.example.org
;
\$TTL     60
@ 	IN SOA ns root (
	    2002042901 ; SERIAL
	    7200       ; REFRESH
	    600        ; RETRY
	    36000000   ; EXPIRE
	    60         ; MINIMUM
	    )
	NS	ns
	;;  order pref flags service           regexp  replacement
        NAPTR 20 15 "s" "SIP+D2U" "" _sip._udp
        NAPTR 40 25 "s" "SIPS+D2T" "" _sips._tcp
        NAPTR 40 50 "s" "SIP+D2T" "" _sip._tcp

ns	AAAA	$me6
	A	127.0.0.1

_sip._udp	SRV 1 100 $contact me
_sips._tcp	SRV 3 100 $contact me
_sip._tcp	SRV 2 100 $contact me

_sip._udp.srv	SRV 1 100 $contact a
_sips._tcp.srv	SRV 3 100 $contact a
_sip._tcp.srv	SRV 2 100 $contact $aaaa

_sip._udp.srv2	SRV 1 200 $contact c
	        SRV 1 100 $contact b
	        SRV 1 50 $contact a

me	AAAA	$me6
	A	127.0.0.1

a	A	127.0.0.1
b	A	0.0.0.2
c	A	0.0.0.3

aaaa	AAAA	$me6

; Directly from NAPTR to A/AAAA (Test 1.6c)
na      NAPTR 20 15 "a" "SIP+D2T" "" a2

; No sensible NAPTR match (and we get 503)
na503   NAPTR 20 15 "S" "SIP+D2F" "" a2

154
; No SIP NAPTR match
Pekka Pessi's avatar
Pekka Pessi committed
155 156 157
nona   NAPTR 20 15 "S" "ZIP+D2U" "" a2
_sip._udp.nona   SRV 1 10 $contact ip4

158
; No SIP SRV match
Pekka Pessi's avatar
Pekka Pessi committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
nosrv	NAPTR 20 1 "s" "SIP+D2U" "" _sip._udp.nosrv
        NAPTR 20 2 "s" "SIP+D2U" "" _sip._udp.srv

; This fails (and we get 503)
a2	A	127.0.0.2

; IP6 should get 80%, IP4 20%
ipv6-20-80 NAPTR 20 15 "s" "SIP+D2U" "" _sip._udp.ipv6-20-80

_sip._udp.ipv6-20-80 SRV 1 80 $contact ip6
		     SRV 1 20 $contact ip4

_sip._udp.ipv	SRV 1 100 $contact ip6
_sip._udp.ipv	SRV 1 100 $contact ip4

ip6	AAAA	$me6
ip4	A	127.0.0.1

; SRV failover to me...
down	NAPTR 20 15 "s" "SIP+D2U" "" _sip._udp.down
_sip._udp.down	SRV 1 100 $down me
_sip._udp.down	SRV 2 100 $contact me

; A failover
down2	A	0.0.0.2
	A	0.0.0.3
	A	127.0.0.1
EOF

# -g is also very nice option for named
named -f -c $namedfile &
pid=$!
while ! test -r $pidfile && kill -0 $!
192
do
Pekka Pessi's avatar
Pekka Pessi committed
193 194 195 196 197 198 199 200
    sleep 1
done

if test -r $pidfile ; then
# export SOFIA_DEBUG=9
    sink=$sink down=$down \
    ipv6=$ipv6 \
    SIPCONTACT="sip:*:$contact;comp=sigcomp" \
201
    $VALGRIND ./test_nta "$@" - $resolvfile
Pekka Pessi's avatar
Pekka Pessi committed
202 203 204 205
    exit=$?
    kill $(cat $pidfile)
    rm $pidfile $zonefile $resolvfile $namedfile 2>/dev/null
    exit $exit
206 207 208
else
    echo "$0: cannot start named (check apparmor/selinux)"
    exit 77
Pekka Pessi's avatar
Pekka Pessi committed
209 210 211 212
fi

else # not having BIND and portbind

213
ipv6=$ipv6 $VALGRIND ./test_nta "$@"
Pekka Pessi's avatar
Pekka Pessi committed
214 215 216
exit $?
fi