3 # $OpenBSD: dhclient-script,v 1.12 2007/08/11 17:58:55 krw Exp $
4 # $DragonFly: src/sbin/dhclient/dhclient-script,v 1.1 2008/08/30 16:07:58 hasso Exp $
6 # Copyright (c) 2003 Kenneth R Westerback <krw@openbsd.org>
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.
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.
23 # Helper functions that implement common actions.
26 delete_old_address
() {
27 if [ -n "$old_ip_address" ]; then
28 ifconfig
$interface inet
$old_ip_address delete
$medium
29 route delete
"$old_ip_address" 127.0.0.1 >/dev
/null
2>&1
35 inet
$new_ip_address \
36 netmask
$new_subnet_mask \
37 broadcast
$new_broadcast_address \
40 # XXX Original TIMEOUT code did not do this unless $new_routers was set?
41 route add
$new_ip_address 127.0.0.1 >/dev
/null
2>&1
45 if [ -n "$alias_ip_address" ]; then
46 ifconfig
$interface inet
$alias_ip_address delete
> /dev
/null
2>&1
47 route delete
$alias_ip_address 127.0.0.1 > /dev
/null
2>&1
52 if [ -n "$alias_ip_address" ]; then
53 ifconfig
$interface inet
$alias_ip_address alias netmask \
55 route add
$alias_ip_address 127.0.0.1
60 # Delete existing default route. We only allow one, so no need to
61 # process $old_routers list.
62 route delete default
>/dev
/null
2>&1
64 if [ -n "$old_static_routes" ]; then
65 set $old_static_routes
66 while [ $# -gt 1 ]; do
67 route delete
"$1" "$2"
76 route delete default
>/dev
/null
2>&1
77 for router
in $new_routers; do
78 if [ "$new_ip_address" = "$router" ]; then
79 route add default
-iface $router >/dev
/null
2>&1
81 route add default
$router >/dev
/null
2>&1
83 # 2nd and subsequent default routers error out, so explicitly
84 # stop processing the list after the first one.
88 if [ -n "$new_static_routes" ]; then
89 set $new_static_routes
90 while [ $# -gt 1 ]; do
97 add_new_resolv_conf
() {
98 # XXX Old code did not create/update resolv.conf unless both
99 # $new_domain_name and $new_domain_name_servers were provided. PR
100 # #3135 reported some ISPs only provide $new_domain_name_servers and
101 # thus broke the script. This code creates the resolv.conf if either
104 rm -f /etc
/resolv.conf.std
106 if [ -n "$new_domain_name" ]; then
107 echo "search $new_domain_name" >>/etc
/resolv.conf.std
110 if [ -n "$new_domain_name_servers" ]; then
111 for nameserver
in $new_domain_name_servers; do
112 echo "nameserver $nameserver" >>/etc
/resolv.conf.std
116 if [ -f /etc
/resolv.conf.std
]; then
117 if [ -f /etc
/resolv.conf.
tail ]; then
118 cat /etc
/resolv.conf.
tail >>/etc
/resolv.conf.std
121 # In case (e.g. during OpenBSD installs) /etc/resolv.conf
122 # is a symbolic link, take care to preserve the link and write
123 # the new data in the correct location.
125 if [ -f /etc
/resolv.conf
]; then
126 cat /etc
/resolv.conf
> /etc
/resolv.conf.save
128 cat /etc
/resolv.conf.std
> /etc
/resolv.conf
129 rm -f /etc
/resolv.conf.std
131 # Try to ensure correct ownership and permissions.
132 chown
-RL root
:wheel
/etc
/resolv.conf
133 chmod -RL 644 /etc
/resolv.conf
142 # Start of active code.
147 ifconfig
$interface $medium
153 ifconfig
$interface up
159 BOUND|RENEW|REBIND|REBOOT
)
160 if [ -n "$old_ip_address" ]; then
161 if [ "$old_ip_address" != "$alias_ip_address" ]; then
164 if [ "$old_ip_address" != "$new_ip_address" ]; then
169 if [ "$reason" = BOUND
] ||
170 [ "$reason" = REBOOT
] ||
171 [ -z "$old_ip_address" ] ||
172 [ "$old_ip_address" != "$new_ip_address" ]; then
176 if [ "$new_ip_address" != "$alias_ip_address" ]; then
184 if [ -n "$old_ip_address" ]; then
188 # XXX Why add alias we just deleted above?
190 if [ -f /etc
/resolv.conf.save
]; then
191 cat /etc
/resolv.conf.save
> /etc
/resolv.conf
199 if [ -n "$new_routers" ]; then
201 if ping -q -c 1 -w 1 "$1"; then
202 if [ "$new_ip_address" != "$alias_ip_address" ]; then
206 if add_new_resolv_conf
; then
211 ifconfig
$interface inet
$new_ip_address delete
$medium
212 # XXX Why not a delete_old_address as before all other invocations of