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