3 # $NetBSD: dhclient-script,v 1.12 2006/10/08 17:09:32 riz 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"
13 echo search
$new_domain_name
14 for nameserver
in $new_domain_name_servers; do
15 echo nameserver
$nameserver
20 if [ ! -z "$new_domain_name_servers" ]; then
21 if [ -x /sbin
/resolvconf
]; then
22 echo_resolv_conf |
/sbin
/resolvconf
-a $interface
24 if [ -f $RESOLV ]; then
30 mv $RESOLV $RESOLV.save
;;
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
47 mv $RESOLV.save
$RESOLV;;
54 # Must be used on exit. Invokes the local dhcp client exit hooks, if any.
57 if [ -f "$EXITHOOKS" ]; then
60 # probably should do something with exit status of the local script
66 for router
in $new_routers; do
67 route add default
$router
70 set -- $new_static_routes
71 while [ $# -gt 1 ]; do
78 for router
in $old_routers; do
79 route delete default
$router
82 set -- $old_static_routes
83 while [ $# -gt 1 ]; do
88 route
-n flush
-inet -llinfo -host
91 # Invoke the local dhcp client enter hooks, if they exist.
92 if [ -f $ENTERHOOKS ]; then
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
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"
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
147 if [ ! -z "$alias_ip_address" ]; then
148 ifconfig
$interface inet \
149 -alias $alias_ip_address >/dev
/null
2>&1
150 route delete
$alias_ip_address 127.0.0.1 > /dev
/null
2>&1
153 ifconfig
$interface inet
0.0.0.0 netmask
0.0.0.0 \
154 broadcast
255.255.255.255 up
163 BOUND|RENEW|REBIND|REBOOT
)
164 if [ ! -z "$new_nis_domain" ]; then
165 if type domainname
> /dev
/null
2>&1; then
166 domainname
$new_nis_domain
170 if type hostname
> /dev
/null
2>&1; then
171 if [ \
( -z "$current_hostname" \
) -o \
172 \
( "x$new_host_name" = "x$old_hostname" \
) ]; then
173 current_hostname
=`hostname`
175 if [ \
( -z "$current_hostname" \
) -o \
176 \
( "x$new_host_name" != "x$old_hostname" \
) ]; then
177 hostname
$new_host_name
181 if [ \
( ! -z "$old_ip_address" \
) -a \
( ! -z "$alias_ip_address" \
) -a \
182 \
( "x$alias_ip_address" != "x$old_ip_address" \
) ]; then
183 ifconfig
$interface inet \
184 -alias $alias_ip_address > /dev
/null
2>&1
185 route delete
$alias_ip_address 127.0.0.1 > /dev
/null
2>&1
188 if [ \
( ! -z "$old_ip_address" \
) -a \
189 \
( "x$old_ip_address" != "x$new_ip_address" \
) ]; then
190 eval "ifconfig $interface inet -alias $old_ip_address $medium"
191 route delete
$old_ip_address 127.0.0.1 >/dev
/null
2>&1
196 if [ \
( -z "$old_ip_address" \
) -o \
197 \
( "x$old_ip_address" != "x$new_ip_address" \
) -o \
198 \
( "x$reason" = "xBOUND" \
) -o \
( "x$reason" = "xREBOOT" \
) ]; then
199 eval "ifconfig $interface inet $new_ip_address \
200 $new_netmask_arg $new_broadcast_arg $medium"
201 route add
$new_ip_address 127.0.0.1 >/dev
/null
2>&1
206 if [ \
( ! -z "$alias_ip_address" \
) -a \
207 \
( "x$new_ip_address" != "x$alias_ip_address" \
) ]; then
208 ifconfig
$interface inet
alias $alias_ip_address \
210 route add
$alias_ip_address 127.0.0.1
216 EXPIRE|FAIL|RELEASE|STOP
)
217 if [ ! -z "$old_nis_domain" ]; then
218 if type domainname
> /dev
/null
2>&1; then
219 # delete the old nis domain name
224 if [ ! -z "$alias_ip_address" ]; then
225 ifconfig
$interface inet
-alias $alias_ip_address
226 route delete
$alias_ip_address 127.0.0.1
229 if [ ! -z "$old_ip_address" ]; then
230 eval "ifconfig $interface inet -alias $old_ip_address $medium"
231 route delete
$old_ip_address 127.0.0.1 >/dev
/null
2>&1
236 if [ ! -z "$alias_ip_address" ]; then
237 ifconfig
$interface inet
alias $alias_ip_address \
239 route add
$alias_ip_address 127.0.0.1
247 if [ ! -z "$alias_ip_address" ]; then
248 ifconfig
$interface inet
-alias $alias_ip_address
249 route delete
$alias_ip_address 127.0.0.1
252 if [ ! -z "$new_host_name" ]; then
253 if type hostname
> /dev
/null
2>&1; then
254 hostname
$new_host_name
258 if [ ! -z "$new_nis_domain" ]; then
259 if type domainname
> /dev
/null
2>&1; then
260 domainname
$new_nis_domain
264 eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \
265 $new_broadcast_arg $medium"
268 if [ ! -z "$new_routers" ]; then
270 if ping -n -q -c 1 -w 1 $1; then
271 if [ \
( ! -z "$alias_ip_address" \
) -a \
272 \
( "x$new_ip_address" != "x$alias_ip_address" \
) ]
274 ifconfig
$interface inet
alias \
275 $alias_ip_address $alias_subnet_arg
276 route add
$alias_ip_address 127.0.0.1
279 route add
$new_ip_address 127.0.0.1 >/dev
/null
2>&1
287 eval "ifconfig $interface inet -alias $new_ip_address $medium"