1#!/bin/sh
2
3# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
4#
5# SPDX-License-Identifier: MPL-2.0
6#
7# This Source Code Form is subject to the terms of the Mozilla Public
8# License, v. 2.0.  If a copy of the MPL was not distributed with this
9# file, you can obtain one at https://mozilla.org/MPL/2.0/.
10#
11# See the COPYRIGHT file distributed with this work for additional
12# information regarding copyright ownership.
13
14#
15# Set up interface aliases for bind9 system tests.
16#
17# IPv4: 10.53.0.{1..10}				RFC 1918
18#       10.53.1.{1..2}
19#       10.53.2.{1..2}
20# IPv6: fd92:7065:b8e:ffff::{1..10}		ULA
21#       fd92:7065:b8e:99ff::{1..2}
22#       fd92:7065:b8e:ff::{1..2}
23#
24# We also set the MTU on the 1500 bytes to match the default MTU on physical
25# interfaces, so we can properly test the cases with packets bigger than
26# interface MTU.
27
28SYSTEMTESTTOP="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
29. "$SYSTEMTESTTOP/conf.sh"
30
31export SYSTEMTESTTOP
32
33sys=$($SHELL "$TOP/config.guess")
34
35use_ip=
36case "$sys" in
37        *-*-linux*)
38                if type ip > /dev/null; then
39                        use_ip=yes
40                elif type ifconfig > /dev/null; then
41                        :
42                else
43                        echo "$0: can't find ip or ifconfig" >&2
44                        exit 1
45                fi
46                ;;
47esac
48
49case "$1" in
50
51    start|up)
52	for i in 0 1 2
53	do
54		case $i in
55		  0) ipv6="ff" ;;
56		  1) ipv6="99" ;;
57		  2) ipv6="00" ;;
58		  *) ipv6="" ;;
59		esac
60		for ns in 1 2 3 4 5 6 7 8 9 10
61		do
62			[ $i -gt 0 -a $ns -gt 2 ] && break
63			int=`expr $i \* 10 + $ns`
64			case "$sys" in
65			    *-pc-solaris2.5.1)
66				ifconfig lo0:$int 10.53.$i.$ns \
67					netmask 0xffffffff up
68				;;
69			    *-sun-solaris2.[6-7])
70				ifconfig lo0:$int 10.53.$i.$ns \
71					netmask 0xffffffff up
72				;;
73			    *-*-solaris2.[8-9]|*-*-solaris2.1[0-9])
74				/sbin/ifconfig lo0:$int plumb
75				/sbin/ifconfig lo0:$int 10.53.$i.$ns up
76				/sbin/ifconfig lo0:$int mtu 1500
77				/sbin/ifconfig lo0:$int inet6 plumb
78				[ "$ipv6" ] && /sbin/ifconfig lo0:$int \
79					inet6 fd92:7065:b8e:${ipv6}ff::$ns up
80				;;
81			    *-*-linux*)
82                                if [ $use_ip ]; then
83                                        ip address add 10.53.$i.$ns/24 \
84                                            dev lo:$int
85                                        ip link set dev lo:$int mtu 1500
86                                        [ "$ipv6" ] && ip address add \
87                                            fd92:7065:b8e:${ipv6}ff::$ns/64 \
88                                            dev lo
89                                else
90                                        ifconfig lo:$int 10.53.$i.$ns up \
91                                                netmask 255.255.255.0 \
92                                                mtu 1500
93                                        [ "$ipv6" ] && ifconfig lo inet6 add \
94                                                fd92:7065:b8e:${ipv6}ff::$ns/64
95                                fi
96				;;
97			    *-unknown-freebsd*)
98				ifconfig lo0 10.53.$i.$ns alias \
99					netmask 0xffffffff \
100					mtu 1500
101				[ "$ipv6" ] && ifconfig lo0 inet6 \
102					fd92:7065:b8e:${ipv6}ff::$ns alias
103				;;
104			    *-unknown-dragonfly*|*-unknown-netbsd*|*-unknown-openbsd*)
105				ifconfig lo0 10.53.$i.$ns alias \
106					netmask 255.255.255.0 \
107					mtu 1500
108				[ "$ipv6" ] && ifconfig lo0 inet6 \
109					fd92:7065:b8e:${ipv6}ff::$ns alias
110				;;
111			    *-*-bsdi[3-5].*)
112				ifconfig lo0 add 10.53.$i.$ns \
113					netmask 255.255.255.0
114				;;
115			    *-dec-osf[4-5].*)
116				ifconfig lo0 alias 10.53.$i.$ns
117				;;
118			    *-sgi-irix6.*)
119				ifconfig lo0 alias 10.53.$i.$ns
120				;;
121			    *-*-sysv5uw7*|*-*-sysv*UnixWare*|*-*-sysv*OpenUNIX*)
122				ifconfig lo0 10.53.$i.$ns alias \
123					netmask 0xffffffff
124				;;
125			    *-ibm-aix4.*|*-ibm-aix5.*)
126				ifconfig lo0 alias 10.53.$i.$ns
127				[ "$ipv6" ] && ifconfig lo0 inet6 alias -dad \
128					fd92:7065:b8e:${ipv6}ff::$ns/64
129				;;
130			    hpux)
131				ifconfig lo0:$int 10.53.$i.$ns \
132					netmask 255.255.255.0 up
133				[ "$ipv6" ] && ifconfig lo0:$int inet6 \
134					fd92:7065:b8e:${ipv6}ff::$ns up
135				;;
136			    *-sco3.2v*)
137				ifconfig lo0 alias 10.53.$i.$ns
138				;;
139			    *-darwin*)
140				ifconfig lo0 alias 10.53.$i.$ns
141				[ "$ipv6" ] && ifconfig lo0 inet6 \
142					fd92:7065:b8e:${ipv6}ff::$ns alias
143				;;
144			    *-cygwin*)
145			        echo "Please run ifconfig.bat as Administrator."
146			        exit 1
147			        ;;
148			    *)
149				echo "Don't know how to set up interface.  Giving up."
150				exit 1
151			esac
152		done
153	done
154	;;
155
156    stop|down)
157	for i in 0 1 2
158	do
159		case $i in
160		  0) ipv6="ff" ;;
161		  1) ipv6="99" ;;
162		  2) ipv6="00" ;;
163		  *) ipv6="" ;;
164		esac
165		for ns in 10 9 8 7 6 5 4 3 2 1
166		do
167			[ $i -gt 0 -a $ns -gt 2 ] && continue
168			int=`expr $i \* 10 + $ns - 1`
169			case "$sys" in
170			    *-pc-solaris2.5.1)
171				ifconfig lo0:$int 0.0.0.0 down
172				;;
173			    *-sun-solaris2.[6-7])
174				ifconfig lo0:$int 10.53.$i.$ns down
175				;;
176			    *-*-solaris2.[8-9]|*-*-solaris2.1[0-9])
177				ifconfig lo0:$int 10.53.$i.$ns down
178				ifconfig lo0:$int 10.53.$i.$ns unplumb
179				ifconfig lo0:$int inet6 down
180				ifconfig lo0:$int inet6 unplumb
181				;;
182			    *-*-linux*)
183                                if [ $use_ip ]; then
184                                        ip address del 10.53.$i.$ns/24 \
185                                            dev lo:$int
186                                        [ "$ipv6" ] && ip address del \
187                                            fd92:7065:b8e:${ipv6}ff::$ns/64 \
188                                            dev lo
189                                else
190                                        ifconfig lo:$int 10.53.$i.$ns down
191                                        [ "$ipv6" ] && ifconfig lo inet6 \
192                                            del fd92:7065:b8e:${ipv6}ff::$ns/64
193                                fi
194				;;
195			    *-unknown-freebsd*)
196				ifconfig lo0 10.53.$i.$ns delete
197				[ "$ipv6" ] && ifconfig lo0 inet6 \
198					fd92:7065:b8e:${ipv6}ff::$ns delete
199				;;
200			    *-unknown-netbsd*)
201				ifconfig lo0 10.53.$i.$ns delete
202				[ "$ipv6" ] && ifconfig lo0 inet6 \
203					fd92:7065:b8e:${ipv6}ff::$ns delete
204				;;
205			    *-unknown-openbsd*)
206				ifconfig lo0 10.53.$i.$ns delete
207				[ "$ipv6" ] && ifconfig lo0 inet6 \
208					fd92:7065:b8e:${ipv6}ff::$ns delete
209				;;
210			    *-*-bsdi[3-5].*)
211				ifconfig lo0 remove 10.53.$i.$ns
212				;;
213			    *-dec-osf[4-5].*)
214				ifconfig lo0 -alias 10.53.$i.$ns
215				;;
216			    *-sgi-irix6.*)
217				ifconfig lo0 -alias 10.53.$i.$ns
218				;;
219			    *-*-sysv5uw7*|*-*-sysv*UnixWare*|*-*-sysv*OpenUNIX*)
220				ifconfig lo0 -alias 10.53.$i.$ns
221				;;
222			    *-ibm-aix4.*|*-ibm-aix5.*)
223				ifconfig lo0 delete 10.53.$i.$ns
224				[ "$ipv6" ] && ifconfig lo0 delete inet6 \
225					fd92:7065:b8e:${ipv6}ff::$ns/64
226				;;
227			    hpux)
228				ifconfig lo0:$int 0.0.0.0
229				ifconfig lo0:$int inet6 ::
230				;;
231			    *-sco3.2v*)
232				ifconfig lo0 -alias 10.53.$i.$ns
233				;;
234			    *darwin*)
235				ifconfig lo0 -alias 10.53.$i.$ns
236				[ "$ipv6" ] && ifconfig lo0 inet6 \
237					fd92:7065:b8e:${ipv6}ff::$ns delete
238				;;
239			    *-cygwin*)
240			        echo "Please run ifconfig.bat as Administrator."
241			        exit 1
242			        ;;
243			    *)
244				echo "Don't know how to destroy interface.  Giving up."
245				exit 1
246			esac
247		done
248	done
249	;;
250
251	*)
252		echo "Usage: $0 { up | down }"
253		exit 1
254esac
255