run_test_sresolv 4.48 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
#
# Run sresolv_test using 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(s): Pekka Pessi <Pekka.Pessi@nokia.com>.
#

33 34
s=`dirname $0`
test x$s = x. && s=`pwd`
Pekka Pessi's avatar
Pekka Pessi committed
35 36

PATH=/usr/sbin:/usr/local/sbin:/sbin:$PATH
37
export PATH
Pekka Pessi's avatar
Pekka Pessi committed
38

39
# Test for support for IPv6 on Linux. This probably fails on everything else.
40
ipv6='sysctl net.ipv6.conf.default.mtu >/dev/null 2>&1'
41 42
# Bind not working with IPv6 on RHEL 4:
# client.c:1325: unexpected error: failed to get request's destination: failure
43 44 45
#ipv6=false

port=`expr $$ % \( 65536 - 1024 \) + 1024`
Pekka Pessi's avatar
Pekka Pessi committed
46 47 48

# Try to find a free port
if netstat --ip >/dev/null 2>&1 ; then
49
    while netstat --ip -n -a | fgrep ":$port " > /dev/null
Pekka Pessi's avatar
Pekka Pessi committed
50
    do
51 52
	port=`expr $port + 1`
	if test $port = 65536 ; then
Pekka Pessi's avatar
Pekka Pessi committed
53 54 55 56 57
	    port=1024
	fi
    done
fi

58
# No BIND 9, no fun
59 60
{ type named >/dev/null &&
  named -v | grep BIND.*9 > /dev/null
61 62
} || {
echo test_sresolv: there is no BIND 9 named in you path, skipping
63
exit 77
64
}
Pekka Pessi's avatar
Pekka Pessi committed
65

66
if eval $ipv6
67
then
68
    # Figure out nice IPv6 address for us
69
    ns=`ip addr ls | awk '
70
    /^[0-9]:/ { up = ($3 ~ /UP/) && ($3 !~ /LOOPBACK/); }
71
    /inet6 fe80::/ { next; } # no link-local
72
    up && $1 ~ /inet6/ { sub(/\/.*$/, "", $2); print $2; exit 0; }'`
73 74 75 76

    # Nothing found, use localnode ::1
    if test -z "$ns"; then ns=::1 ; fi

Pekka Pessi's avatar
Pekka Pessi committed
77
    listen6="listen-on-v6 port $port { any; };"
78 79 80
else
    ns="127.0.0.1"
    listen4="listen-on port $port { 127.0.0.1; };"
Pekka Pessi's avatar
Pekka Pessi committed
81 82
fi

83
#
84
# Set up configuration. First, nice tmpdir
85
#
86
t=${TMPDIR:-/tmp}/sofia-sip-sresolv-$USER-$$
87

88 89 90 91
mkdir $t || exit 77

# Main resolv.conf (with primary nameserver not answering)
cat > $t/resolv.conf <<EOF
Pekka Pessi's avatar
Pekka Pessi committed
92
# Zeroconf subnet, reserved range - no-one should answer this
93 94 95 96 97 98 99
#nameserver 169.254.0.2
#...but bind9 listens to it if using IPv6 ... and chokes on it.

# 00:10:c6:e3:da:7f belongs to a Nokia WLAN card tucked safely in my closet
nameserver fe80::10:c6ff:fee3:da7f

# This is bind we set up
Pekka Pessi's avatar
Pekka Pessi committed
100
nameserver $ns
101

Pekka Pessi's avatar
Pekka Pessi committed
102
domain example.com
103 104

# This is our addition
Pekka Pessi's avatar
Pekka Pessi committed
105 106 107
port $port
EOF

108 109
# Resolv.conf with bad namserver addresses
cat > $t/error.conf <<EOF
Pekka Pessi's avatar
Pekka Pessi committed
110 111 112 113 114 115
nameserver 0.0.0.2
nameserver 1.1.1.1.1
search example.com
port $port
EOF

116 117
absolute=`cd $s; pwd`

118
cat > $t/named.conf <<EOF
Pekka Pessi's avatar
Pekka Pessi committed
119
options {
120
	directory "$absolute";
121
	pid-file "$t/named.pid";
Pekka Pessi's avatar
Pekka Pessi committed
122 123
	notify no;
	$listen4
124
	$listen6
Pekka Pessi's avatar
Pekka Pessi committed
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
};

zone "example.com" in {
        type master;
        file "example.com";
};

zone "." in {
        type master;
        file "root.zone";
};

zone "188.2.194.in-addr.arpa" in {
        type master;
	file "194.2.188";
};

zone "0.0.127.in-addr.arpa" in {
        type master;
	file "127.zone";
};

zone "0.0.0.c.2.1.0.3.0.0.2.1.e.f.f.3.ip6.int" in {
        type master;
	file "3.f.f.e.1.2.0.0.3.0.1.2.c.0.0.0";
};

152 153 154 155 156
zone "0.0.0.c.2.1.0.3.0.0.2.1.e.f.f.3.ip6.arpa" in {
        type master;
	file "3.f.f.e.1.2.0.0.3.0.1.2.c.0.0.0.arpa";
};

Pekka Pessi's avatar
Pekka Pessi committed
157 158
EOF

159
named -f -d 999 -c $t/named.conf &
Pekka Pessi's avatar
Pekka Pessi committed
160

161 162
echo $0: started named pid $!
for i in 1 2 3 4 5; do
163
    test -r $t/named.pid && break
164
    sleep 1;
165 166
done

167 168
test -r $t/named.pid || {
    echo $0: cannot start named >&2 ;
169
    if fgrep -i -e SELINUX=enforcing /etc/selinux/config >/dev/null 2>&1 ; then
170
	echo $0: perhaps you have to disable SELinux protection for named
171 172 173 174
    elif test -d /etc/apparmor.d ; then
	echo $0: perhaps you have to disable apparmor protection for named
    else
	echo $0: perhaps you have to disable apparmor or SELinux
175 176 177
    fi
    exit 77
}
Pekka Pessi's avatar
Pekka Pessi committed
178

179
kill_named ()
Pekka Pessi's avatar
Pekka Pessi committed
180
{
181
    kill `cat $t/named.pid`
182
    rm $t/named.conf $t/resolv.conf $t/error.conf $t/named.pid 2>/dev/null
183
    rmdir $t
Pekka Pessi's avatar
Pekka Pessi committed
184 185 186 187 188
}
trap kill_named EXIT

# export SOFIA_DEBUG=9

189
$VALGRIND ./test_sresolv "$@" - $t/resolv.conf $t/error.conf || exit 1
Pekka Pessi's avatar
Pekka Pessi committed
190 191

exit 0