3 #############################################################################
5 # Copyright (c) 1999, MindStep Corporation
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #############################################################################
32 # This script was written by Patrick Bihan-Faou, patrick@mindstep.com,
33 # Please contact us for bug reports, etc.
35 #############################################################################
36 # $MindStep_Id: dhclient-script.sh,v 1.8 1999/12/07 22:11:08 patrick Exp $
37 # $MindStep_Tag: CONTRIB_19991207 $
38 # $FreeBSD: src/sbin/dhclient/dhclient-script.sh,v 1.2.2.1 2002/04/11 10:21:20 murray Exp $
39 # $DragonFly: src/sbin/dhclient/Attic/dhclient-script.sh,v 1.2 2003/06/17 04:27:32 dillon Exp $
40 #############################################################################
43 #############################################################################
44 # hook functions prototypes
46 # The "pre_state_XXX_hook" functions are called before the main
47 # work is done for the state XXX
49 # The "post_state_XXX_hook" functions are called after the main
50 # work is done for the state XXX
52 # These functions are meant to be overridden by the user's
53 # dhclient-enter-hooks file
54 #############################################################################
56 pre_state_MEDIUM_hook
() { }
57 pre_state_PREINIT_hook
() { }
58 pre_state_ARPCHECK_hook
() { }
59 pre_state_ARPSEND_hook
() { }
60 pre_state_RENEW_hook
() { }
61 pre_state_REBIND_hook
() { }
62 pre_state_BOUND_hook
() { }
63 pre_state_REBOOT_hook
() { }
64 pre_state_EXPIRE_hook
() { }
65 pre_state_FAIL_hook
() { }
66 pre_state_TIMEOUT_hook
() { }
67 post_state_MEDIUM_hook
() { }
68 post_state_PREINIT_hook
() { }
69 post_state_ARPCHECK_hook
() { }
70 post_state_ARPSEND_hook
() { }
71 post_state_RENEW_hook
() { }
72 post_state_REBIND_hook
() { }
73 post_state_BOUND_hook
() { }
74 post_state_REBOOT_hook
() { }
75 post_state_EXPIRE_hook
() { }
76 post_state_FAIL_hook
() { }
77 post_state_TIMEOUT_hook
() { }
79 #############################################################################
82 # This function is called to update the information related to the
83 # DNS configuration (the resolver part)
84 #############################################################################
87 if [ "x$new_domain_name" != x
] && [ "x$new_domain_name_servers" != x
]; then
88 echo search
$new_domain_name >/etc
/resolv.conf
89 for nameserver
in $new_domain_name_servers; do
90 echo nameserver
$nameserver >>/etc
/resolv.conf
95 # Must be used on exit. Invokes the local dhcp client exit hooks, if any.
98 if [ -x /etc
/dhclient-exit-hooks
]; then
99 .
/etc
/dhclient-exit-hooks
101 # probably should do something with exit status of the local script
105 #############################################################################
109 # These function each deal with one particular setting.
110 # They are OS dependent and may be overridden in the
111 # dhclient-enter-hooks file if needed.
113 # These functions are called with either "new" or "old" to indicate which
114 # set of variables to use (new_ip_address or old_ip_address...)
116 #############################################################################
120 local current_hostname
=`/bin/hostname`
121 if [ "$current_hostname" = "" ] || \
122 [ "$current_hostname" = "$old_host_name" ]
124 if [ "$new_host_name" != "$old_host_name" ]
126 $LOGGER "New Hostname: $new_host_name"
127 hostname
$new_host_name
143 eval ip
="\$${1}_ip_address"
144 eval mask
="\$${1}_subnet_mask"
145 eval bcast
="\$${1}_broadcast_address"
149 ifconfig
$interface inet
$ip netmask
$mask broadcast
$bcast $medium
150 # route add $ip 127.0.0.1 > /dev/null 2>&1
163 eval ip
="\$${1}_ip_address"
167 ifconfig
$interface inet
-alias $ip $medium
168 # route delete $ip 127.0.0.1 > /dev/null 2>&1
174 if [ "$alias_ip_address" != "" ]
176 ifconfig
$interface inet
alias $alias_ip_address netmask
$alias_subnet_mask
177 # route add $alias_ip_address 127.0.0.1
183 if [ "$alias_ip_address" != "" ]
185 ifconfig
$interface inet
-alias $alias_ip_address > /dev
/null
2>&1
186 # route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
199 eval router_list
="\$${1}_routers"
201 for router
in $router_list
203 route add default
$router >/dev
/null
2>&1
216 eval router_list
="\$${1}_routers"
218 for router
in $router_list
220 route delete default
$router >/dev
/null
2>&1
233 eval static_routes
="\$${1}_static_routes"
239 $LOGGER "New Static Route: $1 -> $2"
245 unset_static_routes
()
254 eval static_routes
="\$${1}_static_routes"
265 #############################################################################
267 # utility functions grouping what needs to be done in logical units.
269 #############################################################################
275 set_static_routes new
277 if [ "$new_ip_address" != "$alias_ip_address" ]
296 if [ "$alias_ip_address" != "$old_ip_address" ]
301 if [ "$old_ip_address" != "" ]
305 unset_static_routes old
332 #############################################################################
333 # Main State functions.
335 # There is a state function for each state of the DHCP client
336 # These functions are OS specific and should be be tampered with.
337 #############################################################################
341 ifconfig
$interface $medium
342 ifconfig
$interface inet
-alias 0.0.0.0 $medium >/dev
/null
2>&1
351 ifconfig
$interface inet
0.0.0.0 netmask
0.0.0.0 \
352 broadcast
255.255.255.255 up
368 if [ "$old_ip_address" != "$new_ip_address" ]
411 $LOGGER "No good lease information in TIMEOUT state"
417 #############################################################################
420 # dhclient_script_init() parses the optional "enter_hooks" script which can
421 # override any of the state functions
423 # This function also parses the variables and notifies the detected changes.
424 #############################################################################
425 dhclient_script_init
()
427 if [ -x /usr
/bin
/logger
]; then
428 LOGGER
="/usr/bin/logger -s -p user.notice -t dhclient"
433 # Invoke the local dhcp client enter hooks, if they exist.
434 if [ -x /etc
/dhclient-enter-hooks
]
437 .
/etc
/dhclient-enter-hooks
438 # allow the local script to abort processing of this state
439 # local script must set exit_status variable to nonzero.
440 if [ $exit_status -ne 0 ]
446 if [ "$new_network_number" != "" ]
448 $LOGGER "New Network Number: $new_network_number"
451 if [ "$new_ip_address" != "" ]
453 $LOGGER "New IP Address: $new_ip_address"
456 if [ "$new_broadcast_address" != "" ]
458 $LOGGER "New Broadcast Address: $new_broadcast_address"
461 if [ "$new_subnet_mask" != "" ]
463 $LOGGER "New Subnet Mask for $interface: $new_subnet_mask"
466 if [ "$alias_subnet_mask" != "" ]
471 #############################################################################
472 # dhclient_main() does the appropriate work depending on the state of
474 #############################################################################
475 dhclient_script_main
()
492 pre_state_
${reason}_hook
494 post_state_
${reason}_hook
497 $LOGGER "dhclient-script called with invalid reason $reason"
502 exit_with_hooks
$exit_status
505 #############################################################################
506 # Let's do the work...
507 #############################################################################
513 #############################################################################
515 #############################################################################