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 if [ -n "$old_static_routes" ]; then
61 set $old_static_routes
62 while [ $# -gt 1 ]; do
63 route delete "$1" "$2"
72 for router in $new_routers; do
73 route -q delete default
74 if [ "$new_ip_address" = "$router" ]; then
75 route -q add default -iface $router
77 route -q add default $router
79 # 2nd and subsequent default routers error out, so explicitly
80 # stop processing the list after the first one.
84 if [ -n "$new_static_routes" ]; then
85 set $new_static_routes
86 while [ $# -gt 1 ]; do
93 add_new_resolv_conf() {
94 # XXX Old code did not create/update resolv.conf unless both
95 # $new_domain_name and $new_domain_name_servers were provided. PR
96 # #3135 reported some ISPs only provide $new_domain_name_servers and
97 # thus broke the script. This code creates the resolv.conf if either
100 rm -f /etc/resolv.conf.std
102 if [ -n "$new_domain_name" ]; then
103 echo "search $new_domain_name" >>/etc/resolv.conf.std
106 if [ -n "$new_domain_name_servers" ]; then
107 for nameserver in $new_domain_name_servers; do
108 echo "nameserver $nameserver" >>/etc/resolv.conf.std
112 if [ -f /etc/resolv.conf.std ]; then
113 if [ -f /etc/resolv.conf.tail ]; then
114 cat /etc/resolv.conf.tail >>/etc/resolv.conf.std
117 # In case (e.g. during OpenBSD installs) /etc/resolv.conf
118 # is a symbolic link, take care to preserve the link and write
119 # the new data in the correct location.
121 if [ -f /etc/resolv.conf ]; then
122 cat /etc/resolv.conf > /etc/resolv.conf.save
124 cat /etc/resolv.conf.std > /etc/resolv.conf
125 rm -f /etc/resolv.conf.std
127 # Try to ensure correct ownership and permissions.
128 chown -RL root:wheel /etc/resolv.conf
129 chmod -RL 644 /etc/resolv.conf
138 # Start of active code.
143 ifconfig $interface $medium
149 ifconfig $interface up
155 BOUND|RENEW|REBIND|REBOOT)
156 if [ -n "$old_ip_address" ]; then
157 if [ "$old_ip_address" != "$alias_ip_address" ]; then
160 if [ "$old_ip_address" != "$new_ip_address" ]; then
165 if [ "$reason" = BOUND ] ||
166 [ "$reason" = REBOOT ] ||
167 [ -z "$old_ip_address" ] ||
168 [ "$old_ip_address" != "$new_ip_address" ]; then
172 if [ "$new_ip_address" != "$alias_ip_address" ]; then
180 if [ -n "$old_ip_address" ]; then
184 # XXX Why add alias we just deleted above?
186 if [ -f /etc/resolv.conf.save ]; then
187 cat /etc/resolv.conf.save > /etc/resolv.conf
195 if [ -n "$new_routers" ]; then
197 if ping -q -c 1 -w 1 "$1"; then
198 if [ "$new_ip_address" != "$alias_ip_address" ]; then
202 if add_new_resolv_conf; then
207 ifconfig $interface inet $new_ip_address delete $medium
208 # XXX Why not a delete_old_address as before all other invocations of