Deleted Added
full compact
dhclient-script (175554) dhclient-script (177730)
1#!/bin/sh
2#
3# $OpenBSD: dhclient-script,v 1.6 2004/05/06 18:22:41 claudio Exp $
1#!/bin/sh
2#
3# $OpenBSD: dhclient-script,v 1.6 2004/05/06 18:22:41 claudio Exp $
4# $FreeBSD: head/sbin/dhclient/dhclient-script 175554 2008-01-21 23:54:57Z brooks $
4# $FreeBSD: head/sbin/dhclient/dhclient-script 177730 2008-03-30 02:42:39Z brooks $
5#
6# Copyright (c) 2003 Kenneth R Westerback <krw@openbsd.org>
7#
8# Permission to use, copy, modify, and distribute this software for any
9# purpose with or without fee is hereby granted, provided that the above
10# copyright notice and this permission notice appear in all copies.
11#
12# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19#
20#
21
22ARP=/usr/sbin/arp
5#
6# Copyright (c) 2003 Kenneth R Westerback <krw@openbsd.org>
7#
8# Permission to use, copy, modify, and distribute this software for any
9# purpose with or without fee is hereby granted, provided that the above
10# copyright notice and this permission notice appear in all copies.
11#
12# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19#
20#
21
22ARP=/usr/sbin/arp
23AWK=/usr/bin/awk
24HOSTNAME=/bin/hostname
25IFCONFIG='/sbin/ifconfig -n'
23HOSTNAME=/bin/hostname
24IFCONFIG='/sbin/ifconfig -n'
26NETSTAT=/usr/bin/netstat
27
28LOCALHOST=127.0.0.1
29
30if [ -x /usr/bin/logger ]; then
31 LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
32else
33 LOGGER=echo
34fi

--- 84 unchanged lines hidden (view full) ---

119 set $classless_routes
120 while [ $# -gt 1 ]; do
121 route delete "$1" "$2"
122 shift; shift
123 done
124 return 0;
125 fi
126
25
26LOCALHOST=127.0.0.1
27
28if [ -x /usr/bin/logger ]; then
29 LOGGER="/usr/bin/logger -s -p user.notice -t dhclient"
30else
31 LOGGER=echo
32fi

--- 84 unchanged lines hidden (view full) ---

117 set $classless_routes
118 while [ $# -gt 1 ]; do
119 route delete "$1" "$2"
120 shift; shift
121 done
122 return 0;
123 fi
124
127 for router in $old_routers; do
128 if [ $if_defaultroute = x -o $if_defaultroute = $interface ]; then
129 route delete default $route >/dev/null 2>&1
130 fi
131 done
125 # If we supported multiple default routes, we'd be removing each
126 # one here. We don't so just delete the default route if it's
127 # through our interface.
128 if is_default_interface; then
129 route delete default >/dev/null 2>&1
130 fi
132
133 if [ -n "$old_static_routes" ]; then
134 set $old_static_routes
135 while [ $# -gt 1 ]; do
136 route delete "$1" "$2"
137 shift; shift
138 done
139 fi

--- 24 unchanged lines hidden (view full) ---

164 route add "$1" "$2"
165 fi
166 shift; shift
167 done
168 return
169 fi
170
171 for router in $new_routers; do
131
132 if [ -n "$old_static_routes" ]; then
133 set $old_static_routes
134 while [ $# -gt 1 ]; do
135 route delete "$1" "$2"
136 shift; shift
137 done
138 fi

--- 24 unchanged lines hidden (view full) ---

163 route add "$1" "$2"
164 fi
165 shift; shift
166 done
167 return
168 fi
169
170 for router in $new_routers; do
172 if [ "$new_ip_address" = "$router" ]; then
173 route add default -iface $router >/dev/null 2>&1
174 else
175 route add default $router >/dev/null 2>&1
171 if is_default_interface; then
172
173 if [ "$new_ip_address" = "$router" ]; then
174 route add default -iface $router >/dev/null 2>&1
175 else
176 route add default $router >/dev/null 2>&1
177 fi
176 fi
177 # 2nd and subsequent default routers error out, so explicitly
178 # stop processing the list after the first one.
179 break
180 done
181
182 if [ -n "$new_static_routes" ]; then
183 $LOGGER "New Static Routes ($interface): $new_static_routes"

--- 65 unchanged lines hidden (view full) ---

249 exit_status=$1
250 if [ -f /etc/dhclient-exit-hooks ]; then
251 . /etc/dhclient-exit-hooks
252 fi
253 # probably should do something with exit status of the local script
254 exit $exit_status
255}
256
178 fi
179 # 2nd and subsequent default routers error out, so explicitly
180 # stop processing the list after the first one.
181 break
182 done
183
184 if [ -n "$new_static_routes" ]; then
185 $LOGGER "New Static Routes ($interface): $new_static_routes"

--- 65 unchanged lines hidden (view full) ---

251 exit_status=$1
252 if [ -f /etc/dhclient-exit-hooks ]; then
253 . /etc/dhclient-exit-hooks
254 fi
255 # probably should do something with exit status of the local script
256 exit $exit_status
257}
258
259# Get the interface with the current ipv4 default route on it using only
260# commands that are available prior to /usr being mounted.
261is_default_interface()
262{
263 routeget="`route get -inet default`"
264 oldifs="$IFS"
265 IFS="
266"
267 defif=
268 for line in $routeget ; do
269 case $line in
270 *interface:*)
271 defif=${line##*: }
272 ;;
273 esac
274 done
275 IFS=${oldifs}
276
277 if [ -z "$defif" -o "$defif" = "$interface" ]; then
278 return 0
279 else
280 return 1
281 fi
282}
283
257#
258# Start of active code.
259#
260
261# Invoke the local dhcp client enter hooks, if they exist.
262if [ -f /etc/dhclient-enter-hooks ]; then
263 exit_status=0
264 . /etc/dhclient-enter-hooks
265 # allow the local script to abort processing of this state
266 # local script must set exit_status variable to nonzero.
267 if [ $exit_status -ne 0 ]; then
268 exit $exit_status
269 fi
270fi
271
284#
285# Start of active code.
286#
287
288# Invoke the local dhcp client enter hooks, if they exist.
289if [ -f /etc/dhclient-enter-hooks ]; then
290 exit_status=0
291 . /etc/dhclient-enter-hooks
292 # allow the local script to abort processing of this state
293 # local script must set exit_status variable to nonzero.
294 if [ $exit_status -ne 0 ]; then
295 exit $exit_status
296 fi
297fi
298
272if [ -x $NETSTAT ]; then
273 if_defaultroute=`$NETSTAT -rnf inet | $AWK '{if ($1=="default") printf $6}'`
274else
275 if_defaultroute="x"
276fi
277
278case $reason in
279MEDIUM)
280 eval "$IFCONFIG $interface $medium"
281 eval "$IFCONFIG $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
282 sleep 1
283 ;;
284
285PREINIT)

--- 20 unchanged lines hidden (view full) ---

306 [ -z "$old_ip_address" ] || \
307 [ "$old_ip_address" != "$new_ip_address" ]; then
308 add_new_address
309 add_new_routes
310 fi
311 if [ "$new_ip_address" != "$alias_ip_address" ]; then
312 add_new_alias
313 fi
299case $reason in
300MEDIUM)
301 eval "$IFCONFIG $interface $medium"
302 eval "$IFCONFIG $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
303 sleep 1
304 ;;
305
306PREINIT)

--- 20 unchanged lines hidden (view full) ---

327 [ -z "$old_ip_address" ] || \
328 [ "$old_ip_address" != "$new_ip_address" ]; then
329 add_new_address
330 add_new_routes
331 fi
332 if [ "$new_ip_address" != "$alias_ip_address" ]; then
333 add_new_alias
334 fi
314 add_new_resolv_conf
335 if is_default_interface; then
336 add_new_resolv_conf
337 fi
315 ;;
316
317EXPIRE|FAIL)
318 delete_old_alias
319 if [ -n "$old_ip_address" ]; then
320 delete_old_address
321 delete_old_routes
322 fi
323 if [ -x $ARP ]; then
324 $ARP -d -a -i $interface
325 fi
326 # XXX Why add alias we just deleted above?
327 add_new_alias
338 ;;
339
340EXPIRE|FAIL)
341 delete_old_alias
342 if [ -n "$old_ip_address" ]; then
343 delete_old_address
344 delete_old_routes
345 fi
346 if [ -x $ARP ]; then
347 $ARP -d -a -i $interface
348 fi
349 # XXX Why add alias we just deleted above?
350 add_new_alias
328 if [ -f /etc/resolv.conf.save ]; then
329 cat /etc/resolv.conf.save > /etc/resolv.conf
351 if is_default_interface; then
352 if [ -f /etc/resolv.conf.save ]; then
353 cat /etc/resolv.conf.save > /etc/resolv.conf
354 fi
330 fi
331 ;;
332
333TIMEOUT)
334 delete_old_alias
335 add_new_address
336 sleep 1
337 if [ -n "$new_routers" ]; then
338 $LOGGER "New Routers ($interface): $new_routers"
339 set "$new_routers"
340 if ping -q -c 1 -t 1 "$1"; then
341 if [ "$new_ip_address" != "$alias_ip_address" ]; then
342 add_new_alias
343 fi
344 add_new_routes
355 fi
356 ;;
357
358TIMEOUT)
359 delete_old_alias
360 add_new_address
361 sleep 1
362 if [ -n "$new_routers" ]; then
363 $LOGGER "New Routers ($interface): $new_routers"
364 set "$new_routers"
365 if ping -q -c 1 -t 1 "$1"; then
366 if [ "$new_ip_address" != "$alias_ip_address" ]; then
367 add_new_alias
368 fi
369 add_new_routes
370 if ! is_default_interface; then
371 exit_with_hooks 0
372 fi
345 if add_new_resolv_conf; then
346 exit_with_hooks 0
347 fi
348 fi
349 fi
350 eval "$IFCONFIG $interface inet -alias $new_ip_address $medium"
351 delete_old_routes
352 exit_with_hooks 1
353 ;;
354esac
355
356exit_with_hooks 0
373 if add_new_resolv_conf; then
374 exit_with_hooks 0
375 fi
376 fi
377 fi
378 eval "$IFCONFIG $interface inet -alias $new_ip_address $medium"
379 delete_old_routes
380 exit_with_hooks 1
381 ;;
382esac
383
384exit_with_hooks 0