3 # $OpenBSD: src/sbin/dhclient/dhclient-script,v 1.13 2009/01/24 13:59:43 krw Exp $
5 # Copyright (c) 2003 Kenneth R Westerback <krw@openbsd.org>
7 # Permission to use, copy, modify, and distribute this software for any
8 # purpose with or without fee is hereby granted, provided that the above
9 # copyright notice and this permission notice appear in all copies.
11 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 # Helper functions that implement common actions.
25 delete_old_address() {
26 if [ -n "$old_ip_address" ]; then
27 ifconfig $interface inet $old_ip_address delete $medium
28 #route delete "$old_ip_address" 127.0.0.1 >/dev/null 2>&1
34 inet $new_ip_address \
35 netmask $new_subnet_mask \
36 broadcast $new_broadcast_address \
39 # XXX Original TIMEOUT code did not do this unless $new_routers was set?
40 #route add $new_ip_address 127.0.0.1 >/dev/null 2>&1
44 if [ -n "$alias_ip_address" ]; then
45 ifconfig $interface inet $alias_ip_address delete > /dev/null 2>&1
46 # #route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1
51 if [ -n "$alias_ip_address" ]; then
52 ifconfig $interface inet $alias_ip_address alias netmask \
54 #route add $alias_ip_address 127.0.0.1
59 if [ -n "$old_static_routes" ]; then
60 set $old_static_routes
61 while [ $# -gt 1 ]; do
62 route delete "$1" "$2"
71 for router in $new_routers; do
72 route -q delete default
73 if [ "$new_ip_address" = "$router" ]; then
74 route -q add default -iface $router
76 route -q add default $router
78 # 2nd and subsequent default routers error out, so explicitly
79 # stop processing the list after the first one.
83 if [ -n "$new_static_routes" ]; then
84 set $new_static_routes
85 while [ $# -gt 1 ]; do
92 add_new_resolv_conf() {
93 # Create resolv.conf when either $new_domain_name_servers or
94 # $new_domain_name are provided. As reported in PR#3135, some ISPs
95 # provide only $new_domain_name_servers.
97 rm -f /etc/resolv.conf.std
99 if [ -n "$new_domain_name" ]; then
100 echo "search $new_domain_name" >>/etc/resolv.conf.std
103 if [ -n "$new_domain_name_servers" ]; then
104 for nameserver in $new_domain_name_servers; do
105 echo "nameserver $nameserver" >>/etc/resolv.conf.std
109 if [ -f /etc/resolv.conf.std ]; then
110 if [ -f /etc/resolv.conf.tail ]; then
111 cat /etc/resolv.conf.tail >>/etc/resolv.conf.std
114 # In case (e.g. during OpenBSD installs) /etc/resolv.conf
115 # is a symbolic link, take care to preserve the link and write
116 # the new data in the correct location.
118 if [ -f /etc/resolv.conf ]; then
119 cat /etc/resolv.conf > /etc/resolv.conf.save
121 cat /etc/resolv.conf.std > /etc/resolv.conf
122 rm -f /etc/resolv.conf.std
124 # Try to ensure correct ownership and permissions.
125 chown -RL root:wheel /etc/resolv.conf
126 chmod -RL 644 /etc/resolv.conf
135 # Start of active code.
140 ifconfig $interface $medium
146 ifconfig $interface up
152 BOUND|RENEW|REBIND|REBOOT)
153 if [ -n "$old_ip_address" ]; then
154 if [ "$old_ip_address" != "$alias_ip_address" ]; then
157 if [ "$old_ip_address" != "$new_ip_address" ]; then
162 if [ "$reason" = BOUND ] ||
163 [ "$reason" = REBOOT ] ||
164 [ -z "$old_ip_address" ] ||
165 [ "$old_ip_address" != "$new_ip_address" ]; then
169 if [ "$new_ip_address" != "$alias_ip_address" ]; then
177 if [ -n "$old_ip_address" ]; then
181 # XXX Why add alias we just deleted above?
183 if [ -f /etc/resolv.conf.save ]; then
184 cat /etc/resolv.conf.save > /etc/resolv.conf
192 if [ -n "$new_routers" ]; then
194 if ping -q -c 1 -w 1 "$1"; then
195 if [ "$new_ip_address" != "$alias_ip_address" ]; then
199 if add_new_resolv_conf; then
204 ifconfig $interface inet $new_ip_address delete $medium
205 # XXX Why not a delete_old_address as before all other invocations of