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"
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
152 ifconfig
$interface inet
0.0.0.0 netmask
0.0.0.0 \
153 broadcast
255.255.255.255 up
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"
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"
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 \
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
217 if [ ! -z "$alias_ip_address" ]; then
218 ifconfig
$interface inet
-alias $alias_ip_address
221 if [ ! -z "$old_ip_address" ]; then
222 eval "ifconfig $interface inet -alias $old_ip_address $medium"
227 if [ ! -z "$alias_ip_address" ]; then
228 ifconfig
$interface inet
alias $alias_ip_address \
237 if [ ! -z "$alias_ip_address" ]; then
238 ifconfig
$interface inet
-alias $alias_ip_address
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"
257 if [ ! -z "$new_routers" ]; then
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" \
) ]
263 ifconfig
$interface inet
alias \
264 $alias_ip_address $alias_subnet_arg
273 eval "ifconfig $interface inet -alias $new_ip_address $medium"