| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
make_resolv_conf() { |
| 4 |
if [ x"$new_domain_name_servers" != x ]; then |
| 5 |
cat /dev/null > /etc/resolv.conf.dhclient |
| 6 |
if [ x"$new_domain_search" != x ]; then |
| 7 |
echo search $new_domain_search >> /etc/resolv.conf.dhclient |
| 8 |
elif [ x"$new_domain_name" != x ]; then |
| 9 |
# Note that the DHCP 'Domain Name Option' is really just a domain |
| 10 |
# name, and that this practice of using the domain name option as |
| 11 |
# a search path is both nonstandard and deprecated. |
| 12 |
echo search $new_domain_name >> /etc/resolv.conf.dhclient |
| 13 |
fi |
| 14 |
for nameserver in $new_domain_name_servers; do |
| 15 |
echo nameserver $nameserver >>/etc/resolv.conf.dhclient |
| 16 |
done |
| 17 |
|
| 18 |
mv /etc/resolv.conf.dhclient /etc/resolv.conf |
| 19 |
fi |
| 20 |
} |
| 21 |
|
| 22 |
# Must be used on exit. Invokes the local dhcp client exit hooks, if any. |
| 23 |
exit_with_hooks() { |
| 24 |
exit_status=$1 |
| 25 |
if [ -f /etc/dhclient-exit-hooks ]; then |
| 26 |
. /etc/dhclient-exit-hooks |
| 27 |
fi |
| 28 |
# probably should do something with exit status of the local script |
| 29 |
exit $exit_status |
| 30 |
} |
| 31 |
|
| 32 |
# Invoke the local dhcp client enter hooks, if they exist. |
| 33 |
if [ -f /etc/dhclient-enter-hooks ]; then |
| 34 |
exit_status=0 |
| 35 |
. /etc/dhclient-enter-hooks |
| 36 |
# allow the local script to abort processing of this state |
| 37 |
# local script must set exit_status variable to nonzero. |
| 38 |
if [ $exit_status -ne 0 ]; then |
| 39 |
exit $exit_status |
| 40 |
fi |
| 41 |
fi |
| 42 |
|
| 43 |
if [ x$new_broadcast_address != x ]; then |
| 44 |
new_broadcast_arg="broadcast $new_broadcast_address" |
| 45 |
fi |
| 46 |
if [ x$old_broadcast_address != x ]; then |
| 47 |
old_broadcast_arg="broadcast $old_broadcast_address" |
| 48 |
fi |
| 49 |
if [ x$new_subnet_mask != x ]; then |
| 50 |
new_netmask_arg="netmask $new_subnet_mask" |
| 51 |
fi |
| 52 |
if [ x$old_subnet_mask != x ]; then |
| 53 |
old_netmask_arg="netmask $old_subnet_mask" |
| 54 |
fi |
| 55 |
if [ x$alias_subnet_mask != x ]; then |
| 56 |
alias_subnet_arg="netmask $alias_subnet_mask" |
| 57 |
fi |
| 58 |
if [ x$new_interface_mtu != x ]; then |
| 59 |
mtu_arg="mtu $new_interface_mtu" |
| 60 |
fi |
| 61 |
if [ x$IF_METRIC != x ]; then |
| 62 |
metric_arg="metric $IF_METRIC" |
| 63 |
fi |
| 64 |
|
| 65 |
ifconfig=/sbin/ifconfig |
| 66 |
|
| 67 |
release=`uname -r` |
| 68 |
release=`expr $release : '\(.*\)\..*'` |
| 69 |
relmajor=`echo $release |sed -e 's/^\([^\.]*\)\..*$/\1/'` |
| 70 |
relminor=`echo $release |sed -e 's/^.*\.\([^\.]*\)$/\1/'` |
| 71 |
|
| 72 |
if [ x$reason = xMEDIUM ]; then |
| 73 |
eval "$ifconfig $interface $medium" |
| 74 |
$ifconfig $interface |
| 75 |
sleep 1 |
| 76 |
exit_with_hooks 0 |
| 77 |
fi |
| 78 |
|
| 79 |
if [ x$reason = xPREINIT ]; then |
| 80 |
if [ x$alias_ip_address != x ]; then |
| 81 |
$ifconfig ${interface}:1 0 down > /dev/null 2>&1 |
| 82 |
route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1 |
| 83 |
fi |
| 84 |
if [ $relmajor -gt 5 ] || ( [ $relmajor -eq 5 ] && [ $relminor -ge 5 ] ) |
| 85 |
then |
| 86 |
# Turn the interface on |
| 87 |
$ifconfig $interface plumb |
| 88 |
$ifconfig $interface up |
| 89 |
else |
| 90 |
$ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \ |
| 91 |
broadcast 255.255.255.255 up |
| 92 |
fi |
| 93 |
exit_with_hooks 0 |
| 94 |
fi |
| 95 |
|
| 96 |
if [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then |
| 97 |
exit_with_hooks 0; |
| 98 |
fi |
| 99 |
|
| 100 |
if [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \ |
| 101 |
[ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then |
| 102 |
current_hostname=`hostname` |
| 103 |
if [ x$current_hostname = x ] || \ |
| 104 |
[ x$current_hostname = x$old_host_name ]; then |
| 105 |
if [ x$current_hostname = x ] || \ |
| 106 |
[ x$new_host_name != x$old_host_name ]; then |
| 107 |
hostname $new_host_name |
| 108 |
fi |
| 109 |
fi |
| 110 |
|
| 111 |
if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \ |
| 112 |
[ x$alias_ip_address != x$old_ip_address ]; then |
| 113 |
$ifconfig ${interface}:1 inet 0 down > /dev/null 2>&1 |
| 114 |
route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1 |
| 115 |
fi |
| 116 |
if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ]; then |
| 117 |
$ifconfig ${interface} inet 0 down |
| 118 |
route delete $old_ip_address 127.1 >/dev/null 2>&1 |
| 119 |
for router in $old_routers; do |
| 120 |
route delete default $router >/dev/null 2>&1 |
| 121 |
done |
| 122 |
fi |
| 123 |
if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \ |
| 124 |
[ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then |
| 125 |
eval "$ifconfig $interface inet $new_ip_address $new_netmask_arg \ |
| 126 |
$new_broadcast_arg $mtu_arg $metric_arg $medium" |
| 127 |
route add $new_ip_address 127.1 1 >/dev/null 2>&1 |
| 128 |
for router in $new_routers; do |
| 129 |
route add default $router 1 >/dev/null 2>&1 |
| 130 |
done |
| 131 |
else |
| 132 |
# we haven't changed the address, have we changed other options |
| 133 |
# that we wish to update? |
| 134 |
if [ x$new_routers != x ] && [ x$new_routers != x$old_routers ] ; then |
| 135 |
# if we've changed routers delete the old and add the new. |
| 136 |
$LOGGER "New Routers: $new_routers" |
| 137 |
for router in $old_routers; do |
| 138 |
route delete default $router >/dev/null 2>&1 |
| 139 |
done |
| 140 |
for router in $new_routers; do |
| 141 |
route add default $router 1 >/dev/null 2>&1 |
| 142 |
done |
| 143 |
fi |
| 144 |
fi |
| 145 |
if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ]; |
| 146 |
then |
| 147 |
$ifconfig ${interface}:1 inet $alias_ip_address $alias_subnet_arg |
| 148 |
route add $alias_ip_address 127.0.0.1 1 |
| 149 |
fi |
| 150 |
make_resolv_conf |
| 151 |
exit_with_hooks 0 |
| 152 |
fi |
| 153 |
|
| 154 |
if [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \ |
| 155 |
|| [ x$reason = xSTOP ]; then |
| 156 |
if [ x$alias_ip_address != x ]; then |
| 157 |
$ifconfig ${interface}:1 0 down > /dev/null 2>&1 |
| 158 |
route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1 |
| 159 |
fi |
| 160 |
if [ x$old_ip_address != x ]; then |
| 161 |
$ifconfig $interface inet 0 down |
| 162 |
route delete $old_ip_address 127.1 >/dev/null 2>&1 |
| 163 |
for router in $old_routers; do |
| 164 |
route delete default $router >/dev/null 2>&1 |
| 165 |
done |
| 166 |
fi |
| 167 |
if [ x$alias_ip_address != x ]; then |
| 168 |
$ifconfig ${interface}:1 inet $alias_ip_address $alias_subnet_arg |
| 169 |
route add $alias_ip_address 127.0.0.1 1 |
| 170 |
fi |
| 171 |
exit_with_hooks 0 |
| 172 |
fi |
| 173 |
|
| 174 |
if [ x$reason = xTIMEOUT ]; then |
| 175 |
if [ x$alias_ip_address != x ]; then |
| 176 |
$ifconfig ${interface}:1 0 down > /dev/null 2>&1 |
| 177 |
route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1 |
| 178 |
fi |
| 179 |
eval "$ifconfig $interface inet $new_ip_address $new_netmask_arg \ |
| 180 |
$new_broadcast_arg $mtu_arg $metric_arg $medium" |
| 181 |
sleep 1 |
| 182 |
set $new_routers |
| 183 |
if ping -s -n -I 1 $1 64 1; then |
| 184 |
if [ x$new_ip_address != x$alias_ip_address ] && \ |
| 185 |
[ x$alias_ip_address != x ]; then |
| 186 |
$ifconfig ${interface}:1 inet $alias_ip_address $alias_subnet_arg |
| 187 |
route add $alias_ip_address 127.0.0.1 1 |
| 188 |
fi |
| 189 |
route add $new_ip_address 127.1 1 >/dev/null 2>&1 |
| 190 |
for router in $new_routers; do |
| 191 |
route add default $router 1 >/dev/null 2>&1 |
| 192 |
done |
| 193 |
make_resolv_conf |
| 194 |
exit_with_hooks 0 |
| 195 |
fi |
| 196 |
$ifconfig $interface inet 0 down |
| 197 |
for router in $old_routers; do |
| 198 |
route delete default $router >/dev/null 2>&1 |
| 199 |
done |
| 200 |
exit_with_hooks 1 |
| 201 |
fi |
| 202 |
|
| 203 |
exit_with_hooks 0 |