3 # $OpenBSD: src/sbin/dhclient/Attic/dhclient-script,v 1.23 2012/09/18 18:27:55 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
28 #route delete "$old_ip_address" 127.0.0.1 >/dev/null 2>&1
30 if [ -n "$old_classless_routes" ]; then
31 fill_classless_routes
"$old_classless_routes"
33 while [ $# -gt 1 ]; do
34 route delete
"$1" "$2"
43 inet
$new_ip_address \
44 netmask
$new_subnet_mask \
45 broadcast
$new_broadcast_address
47 # XXX Original TIMEOUT code did not do this unless $new_routers was set?
48 #route add $new_ip_address 127.0.0.1 >/dev/null 2>&1
51 fill_classless_routes
() {
53 while [ $# -ge 5 ]; do
56 elif [ $1 -le 8 ]; then
59 elif [ $1 -le 16 ]; then
62 elif [ $1 -le 24 ]; then
66 route
="$2.$3.$4.$5/$1"
67 shift; shift; shift; shift
71 classless_routes
="$classless_routes $route $router"
72 shift; shift; shift; shift
81 # RFC 3442: If the DHCP server returns both a Classless Static
82 # Routes option and a Router option, the DHCP client MUST ignore
85 # DHCP clients that support this option (Classless Static Routes)
86 # MUST NOT install the routes specified in the Static Routes
87 # option (option code 33) if both a Static Routes option and the
88 # Classless Static Routes option are provided.
90 if [ -n "$new_classless_routes" ]; then
91 fill_classless_routes
"$new_classless_routes"
92 $LOGGER "New Classless Static Routes ($interface): $classless_routes"
94 while [ $# -gt 1 ]; do
95 if [ "0.0.0.0" = "$2" ]; then
96 route add
"$1" -iface "$interface"
105 for router
in $new_routers; do
106 route
-q delete default
107 if [ "$new_ip_address" = "$router" ]; then
108 route
-q add default
-iface $router
110 route
-q add default
$router
112 # 2nd and subsequent default routers error out, so explicitly
113 # stop processing the list after the first one.
118 add_new_resolv_conf
() {
119 # Create resolv.conf when either $new_domain_name_servers or
120 # $new_domain_name are provided. As reported in PR#3135, some ISPs
121 # provide only $new_domain_name_servers.
123 rm -f /etc
/resolv.conf.std
125 if [ -n "$new_domain_name" ]; then
126 echo "search $new_domain_name" >>/etc
/resolv.conf.std
129 if [ -n "$new_domain_name_servers" ]; then
130 for nameserver
in $new_domain_name_servers; do
131 echo "nameserver $nameserver" >>/etc
/resolv.conf.std
135 if [ -f /etc
/resolv.conf.std
]; then
136 if [ -f /etc
/resolv.conf.
tail ]; then
137 cat /etc
/resolv.conf.
tail >>/etc
/resolv.conf.std
140 # In case (e.g. during OpenBSD installs) /etc/resolv.conf
141 # is a symbolic link, take care to preserve the link and write
142 # the new data in the correct location.
144 if [ -f /etc
/resolv.conf
]; then
145 cat /etc
/resolv.conf
> /etc
/resolv.conf.save
147 cat /etc
/resolv.conf.std
> /etc
/resolv.conf
148 rm -f /etc
/resolv.conf.std
150 # Try to ensure correct ownership and permissions.
151 chown
-RL root
:wheel
/etc
/resolv.conf
152 chmod -RL 644 /etc
/resolv.conf
161 # Start of active code.
166 # Not called by OpenBSD dhclient(8).
170 # Not called by OpenBSD dhclient(8).
174 # Not called by OpenBSD dhclient(8).
179 # Not called by OpenBSD dhclient(8).
180 # Always succeed. i.e. accept lease.
183 BOUND|RENEW|REBIND|REBOOT
)
184 if [ -n "$old_ip_address" ]; then
185 if [ "$old_ip_address" != "$new_ip_address" ]; then
190 if [ "$reason" = BOUND
] ||
191 [ "$reason" = REBOOT
] ||
192 [ -z "$old_ip_address" ] ||
193 [ "$old_ip_address" != "$new_ip_address" ]; then
201 if [ -n "$old_ip_address" ]; then
205 if [ -f /etc
/resolv.conf.save
]; then
206 cat /etc
/resolv.conf.save
> /etc
/resolv.conf
207 rm -f /etc
/resolv.conf.save
214 if [ -n "$new_routers" ]; then
216 if ping -q -c 1 -w 1 "$1"; then
218 if add_new_resolv_conf
; then
223 ifconfig
$interface inet
$new_ip_address delete
224 # XXX Why not a delete_old_address as before all other invocations of