xref: /netbsd-src/external/mpl/bind/dist/bin/tests/system/ifconfig.sh.in (revision 355482d41fd8ca96252d7ba0160296c8d2d6dc14)
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..11}				RFC 1918
18#       10.53.1.{1..2}
19#       10.53.2.{1..2}
20# IPv6: fd92:7065:b8e:ffff::{1..11}		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#
28# See also org.isc.bind.system (a version of this script for use on macOS)
29# and testsock.pl (which checks the interfaces are configured)
30#
31
32top_srcdir=@abs_top_srcdir@
33
34sys=$(@SHELL@ "$top_srcdir/config.guess")
35
36use_ip=
37case "$sys" in
38  *-*-linux*)
39    if type ip >/dev/null; then
40      use_ip=yes
41    elif type ifconfig >/dev/null; then
42      :
43    else
44      echo "$0: can't find ip or ifconfig" >&2
45      exit 1
46    fi
47    ;;
48esac
49
50up() {
51  case "$sys" in
52    *-pc-solaris2.5.1)
53      [ "$a" ] && ifconfig lo0:$int $a netmask 0xffffffff up
54      ;;
55    *-sun-solaris2.[6-7])
56      [ "$a" ] && ifconfig lo0:$int $a netmask 0xffffffff up
57      ;;
58    *-*-solaris2.[8-9] | *-*-solaris2.10)
59      [ "$a" ] && {
60        /sbin/ifconfig lo0:$int plumb
61        /sbin/ifconfig lo0:$int $a up
62        /sbin/ifconfig lo0:$int mtu 1500
63      }
64      [ "$aaaa" ] && {
65        /sbin/ifconfig lo0:$int inet6 plumb
66        /sbin/ifconfig lo0:$int inet6 $aaaa up
67      }
68      ;;
69    *-*-solaris2.1[1-9])
70      [ "$a" ] && {
71        /sbin/ipadm create-addr -t -T static \
72          -a $a lo0/bind9v4$int \
73          || echo failed lo0/bind9v4$int
74      }
75      [ "$aaaa" ] && {
76        /sbin/ipadm create-addr -t -T static \
77          -a $aaaa lo0/bind9v6$int \
78          || echo failed lo0/bind9v6$int
79      }
80      ;;
81    *-*-linux*)
82      if [ "$use_ip" ]; then
83        ip address add $a/24 dev lo:$int
84        ip link set dev lo:$int mtu 1500
85        [ "$aaaa" ] && ip address add $aaaa/64 dev lo
86      else
87        ifconfig lo:$int $a up netmask 255.255.255.0 mtu 1500
88        [ "$aaaa" ] && ifconfig lo inet6 add $aaaa/64
89      fi
90      ;;
91    *-unknown-freebsd*)
92      [ "$a" ] && ifconfig lo0 $a alias netmask 0xffffffff mtu 1500
93      [ "$aaaa" ] && ifconfig lo0 inet6 $aaaa alias
94      ;;
95    *-unknown-dragonfly* | *-unknown-netbsd* | *-unknown-openbsd*)
96      [ "$a" ] && ifconfig lo0 $a alias netmask 255.255.255.0 mtu 1500
97      [ "$aaaa" ] && ifconfig lo0 inet6 $aaaa alias
98      ;;
99    *-*-bsdi[3-5].*)
100      [ "$a" ] && ifconfig lo0 add $a netmask 255.255.255.0
101      ;;
102    *-dec-osf[4-5].*)
103      [ "$a" ] && ifconfig lo0 alias $a
104      ;;
105    *-sgi-irix6.*)
106      [ "$a" ] && ifconfig lo0 alias $a
107      ;;
108    *-*-sysv5uw7* | *-*-sysv*UnixWare* | *-*-sysv*OpenUNIX*)
109      [ "$a" ] && ifconfig lo0 $a alias netmask 0xffffffff
110      ;;
111    *-ibm-aix4.* | *-ibm-aix5.*)
112      [ "$a" ] && ifconfig lo0 alias $a
113      [ "$aaaa" ] && ifconfig lo0 inet6 alias -dad $aaaa/64
114      ;;
115    hpux)
116      [ "$a" ] && ifconfig lo0:$int $a netmask 255.255.255.0 up
117      [ "$aaaa" ] && ifconfig lo0:$int inet6 $aaaa up
118      ;;
119    *-sco3.2v*)
120      [ "$a" ] && ifconfig lo0 alias $a
121      ;;
122    *-darwin*)
123      [ "$a" ] && ifconfig lo0 alias $a
124      [ "$aaaa" ] && ifconfig lo0 inet6 $aaaa alias
125      ;;
126    *)
127      echo "Don't know how to set up interface.  Giving up."
128      exit 1
129      ;;
130  esac
131}
132
133down() {
134  case "$sys" in
135    *-pc-solaris2.5.1)
136      [ "$a" ] && ifconfig lo0:$int 0.0.0.0 down
137      ;;
138    *-sun-solaris2.[6-7])
139      [ "$a" ] && ifconfig lo0:$int $a down
140      ;;
141    *-*-solaris2.[8-9] | *-*-solaris2.10)
142      [ "$a" ] && {
143        ifconfig lo0:$int $a down
144        ifconfig lo0:$int $a unplumb
145      }
146      [ "$aaaa" ] && {
147        ifconfig lo0:$int inet6 down
148        ifconfig lo0:$int inet6 unplumb
149      }
150      ;;
151    *-*-solaris2.1[1-9])
152      [ "$a" ] && {
153        ipadm delete-addr lo0/bind9v4$int \
154          || echo failed lo0/bind9v4$int
155      }
156      [ "$aaaa" ] && {
157        ipadm delete-addr lo0/bind9v6$int \
158          || echo failed lo0/bind9v6$int
159      }
160      ;;
161
162    *-*-linux*)
163      if [ "$use_ip" ]; then
164        [ "$a" ] && ip address del $a/24 dev lo:$int
165        [ "$aaaa" ] && ip address del $aaaa/64 dev lo
166      else
167        [ "$a" ] && ifconfig lo:$int $a down
168        [ "$aaaa" ] && ifconfig lo inet6 del $aaaa/64
169      fi
170      ;;
171    *-unknown-freebsd*)
172      [ "$a" ] && ifconfig lo0 $a delete
173      [ "$aaaa" ] && ifconfig lo0 inet6 $aaaa delete
174      ;;
175    *-unknown-netbsd*)
176      [ "$a" ] && ifconfig lo0 $a delete
177      [ "$aaaa" ] && ifconfig lo0 inet6 $aaaa delete
178      ;;
179    *-unknown-openbsd*)
180      [ "$a" ] && ifconfig lo0 $a delete
181      [ "$aaaa" ] && ifconfig lo0 inet6 $aaaa delete
182      ;;
183    *-*-bsdi[3-5].*)
184      [ "$a" ] && ifconfig lo0 remove $a
185      ;;
186    *-dec-osf[4-5].*)
187      [ "$a" ] && ifconfig lo0 -alias $a
188      ;;
189    *-sgi-irix6.*)
190      [ "$a" ] && ifconfig lo0 -alias $a
191      ;;
192    *-*-sysv5uw7* | *-*-sysv*UnixWare* | *-*-sysv*OpenUNIX*)
193      [ "$a" ] && ifconfig lo0 -alias $a
194      ;;
195    *-ibm-aix4.* | *-ibm-aix5.*)
196      [ "$a" ] && ifconfig lo0 delete $a
197      [ "$aaaa" ] && ifconfig lo0 delete inet6 $aaaa/64
198      ;;
199    hpux)
200      [ "$a" ] && ifconfig lo0:$int 0.0.0.0
201      [ "$aaaa" ] && ifconfig lo0:$int inet6 ::
202      ;;
203    *-sco3.2v*)
204      [ "$a" ] && ifconfig lo0 -alias $a
205      ;;
206    *darwin*)
207      [ "$a" ] && ifconfig lo0 -alias $a
208      [ "$aaaa" ] && ifconfig lo0 inet6 $aaaa delete
209      ;;
210    *)
211      echo "Don't know how to destroy interface.  Giving up."
212      exit 1
213      ;;
214  esac
215}
216
217sequence() (
218  awk -v s=$1 -v e=$2 '
219		BEGIN {
220			for (i = s ; i <= e; i++) { print i; }
221			exit;
222		}'
223)
224
225#
226# 'max', 'i' and 'ns' are used to compute the interface identifier for
227# systems that need it and must be unique for each interface (e.g. lo:$int).
228#
229#	int=$((i * max + ns))
230#
231# 'max' is the number of nameservers configured in the inner loop.
232# 'i' is the outer loop counter.
233# 'ns' in the namserver being configured.
234# 'int' interface identifier.
235#
236# See also `org.isc.bind.system`.
237#
238# This `max` setting is grepped out for use by testsock.pl
239#
240max=11
241case $1 in
242  start | up | stop | down)
243    for i in $(sequence 0 2); do
244      case $i in
245        0) ipv6="ff" ;;
246        1) ipv6="99" ;;
247        2) ipv6="00" ;;
248        *) ipv6="" ;;
249      esac
250      for ns in $(sequence 1 $max); do
251        [ $i -gt 0 -a $ns -gt 2 ] && break
252        int=$((i * max + ns))
253        a=10.53.$i.$ns
254        aaaa=fd92:7065:b8e:${ipv6}ff::$ns
255        case "$1" in
256          start | up) up ;;
257          stop | down) down ;;
258        esac
259      done
260    done
261    ;;
262  *)
263    echo "Usage: $0 { up | down }"
264    exit 1
265    ;;
266esac
267