Drop main() prototype. Syncs with NetBSD-8
[minix.git] / external / bsd / dhcp / bin / clientscript / dhclient-script
blobc092e8ddd801fb1c527e56fb175805ca1344c38d
1 #!/bin/sh
3 # $NetBSD: dhclient-script,v 1.2 2015/02/26 09:59:55 roy Exp $
5 ENTERHOOKS=/etc/dhclient-enter-hooks
6 EXITHOOKS=/etc/dhclient-exit-hooks
7 RESOLV=/etc/resolv.conf
8 SIGNATURE="# Created by dhclient from"
9 INTSIG="$SIGNATURE $interface"
11 echo_resolv_conf() {
12 echo "$INTSIG"
13 echo search $new_domain_name
14 for nameserver in $new_domain_name_servers; do
15 echo nameserver $nameserver
16 done
19 make_resolv_conf() {
20 if [ ! -z "$new_domain_name_servers" ]; then
21 if [ -x /sbin/resolvconf ]; then
22 echo_resolv_conf | /sbin/resolvconf -a $interface
23 else
24 if [ -f $RESOLV ]; then
25 while read line; do
26 case $line in
27 "$SIGNATURE"*)
30 mv $RESOLV $RESOLV.save;;
31 esac
32 break
33 done < $RESOLV
35 echo_resolv_conf > $RESOLV
40 restore_resolv_conf() {
41 if [ -x /sbin/resolvconf ]; then
42 /sbin/resolvconf -d $interface
43 elif [ -f $RESOLV.save -a -f $RESOLV ]; then
44 while read line; do
45 case $line in
46 "$INTSIG"*)
47 mv $RESOLV.save $RESOLV;;
48 esac
49 break
50 done < $RESOLV
54 # Must be used on exit. Invokes the local dhcp client exit hooks, if any.
55 exit_with_hooks() {
56 exit_status=$1
57 if [ -f "$EXITHOOKS" ]; then
58 . "$EXITHOOKS"
60 # probably should do something with exit status of the local script
61 exit $exit_status
65 add_new_routes() {
66 for router in $new_routers; do
67 route add default $router
68 done >/dev/null 2>&1
70 set -- $new_static_routes
71 while [ $# -gt 1 ]; do
72 route add $1 $2
73 shift; shift
74 done
77 delete_old_routes() {
78 for router in $old_routers; do
79 route delete default $router
80 done >/dev/null 2>&1
82 set -- $old_static_routes
83 while [ $# -gt 1 ]; do
84 route delete $1 $2
85 shift; shift
86 done
88 route -n flush -inet -llinfo -host
91 # Invoke the local dhcp client enter hooks, if they exist.
92 if [ -f $ENTERHOOKS ]; then
93 exit_status=0
94 . $ENTERHOOKS
95 # allow the local script to abort processing of this state
96 # local script must set exit_status variable to nonzero.
97 if [ $exit_status -ne 0 ]; then
98 exit $exit_status
102 #if [ ! -z "$new_host_name" ]; then
103 # echo New Host Name: $new_host_name
106 #if [ ! -z "$new_nis_domain" ]; then
107 # echo New NIS Domain: $new_nis_domain
110 #if [ ! -z "$new_network_number" ]; then
111 # echo New Network Number: $new_network_number
114 if [ ! -z "$new_broadcast_address" ]; then
115 # echo New Broadcast Address: $new_broadcast_address
116 new_broadcast_arg="broadcast $new_broadcast_address"
119 if [ ! -z "$old_broadcast_address" ]; then
120 old_broadcast_arg="broadcast $old_broadcast_address"
123 if [ ! -z "$new_subnet_mask" ]; then
124 new_netmask_arg="netmask $new_subnet_mask"
127 if [ ! -z "$old_subnet_mask" ]; then
128 old_netmask_arg="netmask $old_subnet_mask"
131 if [ ! -z "$alias_subnet_mask" ]; then
132 alias_subnet_arg="netmask $alias_subnet_mask"
135 case "$reason" in
136 MEDIUM)
137 test -z "$medium" && exit_with_hooks 0
138 eval "ifconfig $interface $medium"
139 eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
141 sleep 1
143 exit_with_hooks 0
146 PREINIT)
147 if [ ! -z "$alias_ip_address" ]; then
148 ifconfig $interface inet \
149 -alias $alias_ip_address >/dev/null 2>&1
152 ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \
153 broadcast 255.255.255.255 up
155 exit_with_hooks 0
158 ARPCHECK|ARPSEND)
159 exit_with_hooks 0
162 BOUND|RENEW|REBIND|REBOOT)
163 if [ ! -z "$new_nis_domain" ]; then
164 if type domainname > /dev/null 2>&1; then
165 domainname $new_nis_domain
169 if type hostname > /dev/null 2>&1; then
170 if [ \( -z "$current_hostname" \) -o \
171 \( "x$new_host_name" = "x$old_hostname" \) ]; then
172 current_hostname=`hostname`
174 if [ \( -z "$current_hostname" \) -o \
175 \( "x$new_host_name" != "x$old_hostname" \) ]; then
176 hostname $new_host_name
180 if [ \( ! -z "$old_ip_address" \) -a \( ! -z "$alias_ip_address" \) -a \
181 \( "x$alias_ip_address" != "x$old_ip_address" \) ]; then
182 ifconfig $interface inet \
183 -alias $alias_ip_address > /dev/null 2>&1
186 if [ \( ! -z "$old_ip_address" \) -a \
187 \( "x$old_ip_address" != "x$new_ip_address" \) ]; then
188 eval "ifconfig $interface inet -alias $old_ip_address $medium"
189 delete_old_routes
192 if [ \( -z "$old_ip_address" \) -o \
193 \( "x$old_ip_address" != "x$new_ip_address" \) -o \
194 \( "x$reason" = "xBOUND" \) -o \( "x$reason" = "xREBOOT" \) ]; then
195 eval "ifconfig $interface inet $new_ip_address \
196 $new_netmask_arg $new_broadcast_arg $medium"
197 add_new_routes
200 if [ \( ! -z "$alias_ip_address" \) -a \
201 \( "x$new_ip_address" != "x$alias_ip_address" \) ]; then
202 ifconfig $interface inet alias $alias_ip_address \
203 $alias_subnet_arg
205 make_resolv_conf
206 exit_with_hooks 0
209 EXPIRE|FAIL|RELEASE|STOP)
210 if [ ! -z "$old_nis_domain" ]; then
211 if type domainname > /dev/null 2>&1; then
212 # delete the old nis domain name
213 domainname ""
217 if [ ! -z "$alias_ip_address" ]; then
218 ifconfig $interface inet -alias $alias_ip_address
219 fi > /dev/null 2>&1
221 if [ ! -z "$old_ip_address" ]; then
222 eval "ifconfig $interface inet -alias $old_ip_address $medium"
223 delete_old_routes
227 if [ ! -z "$alias_ip_address" ]; then
228 ifconfig $interface inet alias $alias_ip_address \
229 $alias_subnet_arg
232 restore_resolv_conf
233 exit_with_hooks 0
236 TIMEOUT)
237 if [ ! -z "$alias_ip_address" ]; then
238 ifconfig $interface inet -alias $alias_ip_address
239 fi > /dev/null 2>&1
241 if [ ! -z "$new_host_name" ]; then
242 if type hostname > /dev/null 2>&1; then
243 hostname $new_host_name
247 if [ ! -z "$new_nis_domain" ]; then
248 if type domainname > /dev/null 2>&1; then
249 domainname $new_nis_domain
253 eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
254 $new_broadcast_arg $medium"
255 sleep 1
257 if [ ! -z "$new_routers" ]; then
258 set -- $new_routers
259 if ping -n -q -c 1 -w 1 $1; then
260 if [ \( ! -z "$alias_ip_address" \) -a \
261 \( "x$new_ip_address" != "x$alias_ip_address" \) ]
262 then
263 ifconfig $interface inet alias \
264 $alias_ip_address $alias_subnet_arg
267 add_new_routes
268 make_resolv_conf
269 exit_with_hooks 0
273 eval "ifconfig $interface inet -alias $new_ip_address $medium"
275 delete_old_routes
277 exit_with_hooks 1
280 exit_with_hooks 0
282 esac