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 elif [ "x${new_dhcp6_name_servers}" != x ] ; then 20*6fb29d29Schristos cat /dev/null > /etc/resolv.conf.dhclient6 21*6fb29d29Schristos chmod 644 /etc/resolv.conf.dhclient6 22*6fb29d29Schristos 23*6fb29d29Schristos if [ "x${new_dhcp6_domain_search}" != x ] ; then 24*6fb29d29Schristos echo search ${new_dhcp6_domain_search} >> /etc/resolv.conf.dhclient6 25*6fb29d29Schristos fi 26*6fb29d29Schristos for nameserver in ${new_dhcp6_name_servers} ; do 27*6fb29d29Schristos # If the nameserver has a link-local address 28*6fb29d29Schristos # add a <zone_id> (interface name) to it. 29*6fb29d29Schristos case $nameserver in 30*6fb29d29Schristos fe80:*) zone_id="%$interface";; 31*6fb29d29Schristos FE80:*) zone_id="%$interface";; 32*6fb29d29Schristos *) zone_id="";; 33*6fb29d29Schristos esac 34*6fb29d29Schristos echo nameserver ${nameserver}$zone_id >> /etc/resolv.conf.dhclient6 35*6fb29d29Schristos done 36*6fb29d29Schristos 37*6fb29d29Schristos mv /etc/resolv.conf.dhclient6 /etc/resolv.conf 38*6fb29d29Schristos fi 39*6fb29d29Schristos} 40*6fb29d29Schristos 41*6fb29d29Schristos# Must be used on exit. Invokes the local dhcp client exit hooks, if any. 42*6fb29d29Schristosexit_with_hooks() { 43*6fb29d29Schristos exit_status=$1 44*6fb29d29Schristos if [ -f /etc/dhclient-exit-hooks ]; then 45*6fb29d29Schristos . /etc/dhclient-exit-hooks 46*6fb29d29Schristos fi 47*6fb29d29Schristos# probably should do something with exit status of the local script 48*6fb29d29Schristos exit $exit_status 49*6fb29d29Schristos} 50*6fb29d29Schristos 51*6fb29d29Schristos# Invoke the local dhcp client enter hooks, if they exist. 52*6fb29d29Schristosif [ -f /etc/dhclient-enter-hooks ]; then 53*6fb29d29Schristos exit_status=0 54*6fb29d29Schristos . /etc/dhclient-enter-hooks 55*6fb29d29Schristos # allow the local script to abort processing of this state 56*6fb29d29Schristos # local script must set exit_status variable to nonzero. 57*6fb29d29Schristos if [ $exit_status -ne 0 ]; then 58*6fb29d29Schristos exit $exit_status 59*6fb29d29Schristos fi 60*6fb29d29Schristosfi 61*6fb29d29Schristos 62*6fb29d29Schristosif [ x$new_network_number != x ]; then 63*6fb29d29Schristos echo New Network Number: $new_network_number 64*6fb29d29Schristosfi 65*6fb29d29Schristos 66*6fb29d29Schristosif [ x$new_broadcast_address != x ]; then 67*6fb29d29Schristos echo New Broadcast Address: $new_broadcast_address 68*6fb29d29Schristos new_broadcast_arg="broadcast $new_broadcast_address" 69*6fb29d29Schristosfi 70*6fb29d29Schristosif [ x$old_broadcast_address != x ]; then 71*6fb29d29Schristos old_broadcast_arg="broadcast $old_broadcast_address" 72*6fb29d29Schristosfi 73*6fb29d29Schristosif [ x$new_subnet_mask != x ]; then 74*6fb29d29Schristos new_netmask_arg="netmask $new_subnet_mask" 75*6fb29d29Schristosfi 76*6fb29d29Schristosif [ x$old_subnet_mask != x ]; then 77*6fb29d29Schristos old_netmask_arg="netmask $old_subnet_mask" 78*6fb29d29Schristosfi 79*6fb29d29Schristosif [ x$alias_subnet_mask != x ]; then 80*6fb29d29Schristos alias_subnet_arg="netmask $alias_subnet_mask" 81*6fb29d29Schristosfi 82*6fb29d29Schristosif [ x$new_interface_mtu != x ]; then 83*6fb29d29Schristos mtu_arg="mtu $new_interface_mtu" 84*6fb29d29Schristosfi 85*6fb29d29Schristosif [ x$IF_METRIC != x ]; then 86*6fb29d29Schristos metric_arg="metric $IF_METRIC" 87*6fb29d29Schristosfi 88*6fb29d29Schristos 89*6fb29d29Schristosif [ x$reason = xMEDIUM ]; then 90*6fb29d29Schristos eval "ifconfig $interface $medium" 91*6fb29d29Schristos eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1 92*6fb29d29Schristos sleep 1 93*6fb29d29Schristos exit_with_hooks 0 94*6fb29d29Schristosfi 95*6fb29d29Schristos 96*6fb29d29Schristos### 97*6fb29d29Schristos### DHCPv4 Handlers 98*6fb29d29Schristos### 99*6fb29d29Schristos 100*6fb29d29Schristosif [ x$reason = xPREINIT ]; then 101*6fb29d29Schristos if [ x$alias_ip_address != x ]; then 102*6fb29d29Schristos ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1 103*6fb29d29Schristos route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1 104*6fb29d29Schristos fi 105*6fb29d29Schristos ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \ 106*6fb29d29Schristos broadcast 255.255.255.255 up 107*6fb29d29Schristos exit_with_hooks 0 108*6fb29d29Schristosfi 109*6fb29d29Schristos 110*6fb29d29Schristosif [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then 111*6fb29d29Schristos exit_with_hooks 0; 112*6fb29d29Schristosfi 113*6fb29d29Schristos 114*6fb29d29Schristosif [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \ 115*6fb29d29Schristos [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then 116*6fb29d29Schristos current_hostname=`hostname` 117*6fb29d29Schristos if [ x$current_hostname = x ] || \ 118*6fb29d29Schristos [ x$current_hostname = x$old_host_name ]; then 119*6fb29d29Schristos if [ x$current_hostname = x ] || \ 120*6fb29d29Schristos [ x$new_host_name != x$old_host_name ]; then 121*6fb29d29Schristos hostname $new_host_name 122*6fb29d29Schristos fi 123*6fb29d29Schristos fi 124*6fb29d29Schristos 125*6fb29d29Schristos if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \ 126*6fb29d29Schristos [ x$alias_ip_address != x$old_ip_address ]; then 127*6fb29d29Schristos ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1 128*6fb29d29Schristos route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1 129*6fb29d29Schristos fi 130*6fb29d29Schristos if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ] 131*6fb29d29Schristos then 132*6fb29d29Schristos eval "ifconfig $interface inet -alias $old_ip_address $medium" 133*6fb29d29Schristos route delete $old_ip_address 127.1 >/dev/null 2>&1 134*6fb29d29Schristos for router in $old_routers; do 135*6fb29d29Schristos route delete default $router >/dev/null 2>&1 136*6fb29d29Schristos done 137*6fb29d29Schristos if [ "$old_static_routes" != "" ]; then 138*6fb29d29Schristos set $old_static_routes 139*6fb29d29Schristos while [ $# -gt 1 ]; do 140*6fb29d29Schristos route delete $1 $2 141*6fb29d29Schristos shift; shift 142*6fb29d29Schristos done 143*6fb29d29Schristos fi 144*6fb29d29Schristos arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -n -d \1/p' |sh 145*6fb29d29Schristos fi 146*6fb29d29Schristos if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \ 147*6fb29d29Schristos [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then 148*6fb29d29Schristos eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \ 149*6fb29d29Schristos $new_broadcast_arg $mtu_arg $metric_arg $medium" 150*6fb29d29Schristos route add $new_ip_address 127.1 >/dev/null 2>&1 151*6fb29d29Schristos for router in $new_routers; do 152*6fb29d29Schristos route add default $router >/dev/null 2>&1 153*6fb29d29Schristos done 154*6fb29d29Schristos if [ "$new_static_routes" != "" ]; then 155*6fb29d29Schristos set $new_static_routes 156*6fb29d29Schristos while [ $# -gt 1 ]; do 157*6fb29d29Schristos route add $1 $2 158*6fb29d29Schristos shift; shift 159*6fb29d29Schristos done 160*6fb29d29Schristos fi 161*6fb29d29Schristos else 162*6fb29d29Schristos # we haven't changed the address, have we changed other options 163*6fb29d29Schristos # that we wish to update? 164*6fb29d29Schristos if [ x$new_routers != x ] && [ x$new_routers != x$old_routers ] ; then 165*6fb29d29Schristos # if we've changed routers delete the old and add the new. 166*6fb29d29Schristos $LOGGER "New Routers: $new_routers" 167*6fb29d29Schristos for router in $old_routers; do 168*6fb29d29Schristos route delete default $router >/dev/null 2>&1 169*6fb29d29Schristos done 170*6fb29d29Schristos for router in $new_routers; do 171*6fb29d29Schristos route add default $router >/dev/null 2>&1 172*6fb29d29Schristos done 173*6fb29d29Schristos fi 174*6fb29d29Schristos fi 175*6fb29d29Schristos if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ]; 176*6fb29d29Schristos then 177*6fb29d29Schristos ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg 178*6fb29d29Schristos route add $alias_ip_address 127.0.0.1 179*6fb29d29Schristos fi 180*6fb29d29Schristos make_resolv_conf 181*6fb29d29Schristos exit_with_hooks 0 182*6fb29d29Schristosfi 183*6fb29d29Schristos 184*6fb29d29Schristosif [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \ 185*6fb29d29Schristos || [ x$reason = xSTOP ]; then 186*6fb29d29Schristos if [ x$alias_ip_address != x ]; then 187*6fb29d29Schristos ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1 188*6fb29d29Schristos route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1 189*6fb29d29Schristos fi 190*6fb29d29Schristos if [ x$old_ip_address != x ]; then 191*6fb29d29Schristos eval "ifconfig $interface inet -alias $old_ip_address $medium" 192*6fb29d29Schristos route delete $old_ip_address 127.1 >/dev/null 2>&1 193*6fb29d29Schristos for router in $old_routers; do 194*6fb29d29Schristos route delete default $router >/dev/null 2>&1 195*6fb29d29Schristos done 196*6fb29d29Schristos if [ "$old_static_routes" != "" ]; then 197*6fb29d29Schristos set $old_static_routes 198*6fb29d29Schristos while [ $# -gt 1 ]; do 199*6fb29d29Schristos route delete $1 $2 200*6fb29d29Schristos shift; shift 201*6fb29d29Schristos done 202*6fb29d29Schristos fi 203*6fb29d29Schristos arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -n -d \1/p' \ 204*6fb29d29Schristos |sh >/dev/null 2>&1 205*6fb29d29Schristos fi 206*6fb29d29Schristos if [ x$alias_ip_address != x ]; then 207*6fb29d29Schristos ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg 208*6fb29d29Schristos route add $alias_ip_address 127.0.0.1 209*6fb29d29Schristos fi 210*6fb29d29Schristos exit_with_hooks 0 211*6fb29d29Schristosfi 212*6fb29d29Schristos 213*6fb29d29Schristosif [ x$reason = xTIMEOUT ]; then 214*6fb29d29Schristos if [ x$alias_ip_address != x ]; then 215*6fb29d29Schristos ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1 216*6fb29d29Schristos route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1 217*6fb29d29Schristos fi 218*6fb29d29Schristos eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \ 219*6fb29d29Schristos $new_broadcast_arg $mtu_arg $metric_arg $medium" 220*6fb29d29Schristos sleep 1 221*6fb29d29Schristos if [ "$new_routers" != "" ]; then 222*6fb29d29Schristos set $new_routers 223*6fb29d29Schristos if ping -q -c 1 -w 1 $1; then 224*6fb29d29Schristos if [ x$new_ip_address != x$alias_ip_address ] && \ 225*6fb29d29Schristos [ x$alias_ip_address != x ]; then 226*6fb29d29Schristos ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg 227*6fb29d29Schristos route add $alias_ip_address 127.0.0.1 228*6fb29d29Schristos fi 229*6fb29d29Schristos route add $new_ip_address 127.1 >/dev/null 2>&1 230*6fb29d29Schristos for router in $new_routers; do 231*6fb29d29Schristos route add default $router >/dev/null 2>&1 232*6fb29d29Schristos done 233*6fb29d29Schristos set $new_static_routes 234*6fb29d29Schristos while [ $# -gt 1 ]; do 235*6fb29d29Schristos route add $0 $1 236*6fb29d29Schristos shift; shift 237*6fb29d29Schristos done 238*6fb29d29Schristos make_resolv_conf 239*6fb29d29Schristos exit_with_hooks 0 240*6fb29d29Schristos fi 241*6fb29d29Schristos fi 242*6fb29d29Schristos eval "ifconfig $interface inet -alias $new_ip_address $medium" 243*6fb29d29Schristos for router in $old_routers; do 244*6fb29d29Schristos route delete default $router >/dev/null 2>&1 245*6fb29d29Schristos done 246*6fb29d29Schristos if [ "$old_static_routes" != "" ]; then 247*6fb29d29Schristos set $old_static_routes 248*6fb29d29Schristos while [ $# -gt 1 ]; do 249*6fb29d29Schristos route delete $1 $2 250*6fb29d29Schristos shift; shift 251*6fb29d29Schristos done 252*6fb29d29Schristos fi 253*6fb29d29Schristos arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -n -d \1/p' \ 254*6fb29d29Schristos |sh >/dev/null 2>&1 255*6fb29d29Schristos exit_with_hooks 1 256*6fb29d29Schristosfi 257*6fb29d29Schristos 258*6fb29d29Schristos### 259*6fb29d29Schristos### DHCPv6 Handlers 260*6fb29d29Schristos### 261*6fb29d29Schristos 262*6fb29d29Schristosif [ ${reason} = PREINIT6 ] ; then 263*6fb29d29Schristos # Ensure interface is up. 264*6fb29d29Schristos ifconfig ${interface} up 265*6fb29d29Schristos 266*6fb29d29Schristos # XXX: Remove any stale addresses from aborted clients. 267*6fb29d29Schristos 268*6fb29d29Schristos exit_with_hooks 0 269*6fb29d29Schristosfi 270*6fb29d29Schristos 271*6fb29d29Schristosif [ x${old_ip6_prefix} != x ] || [ x${new_ip6_prefix} != x ] ; then 272*6fb29d29Schristos echo Prefix ${reason} old=${old_ip6_prefix} new=${new_ip6_prefix} 273*6fb29d29Schristos 274*6fb29d29Schristos exit_with_hooks 0 275*6fb29d29Schristosfi 276*6fb29d29Schristos 277*6fb29d29Schristosif [ ${reason} = BOUND6 ] ; then 278*6fb29d29Schristos if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then 279*6fb29d29Schristos exit_with_hooks 2; 280*6fb29d29Schristos fi 281*6fb29d29Schristos 282*6fb29d29Schristos ifconfig ${interface} inet6 add ${new_ip6_address}/${new_ip6_prefixlen} 283*6fb29d29Schristos 284*6fb29d29Schristos # Check for nameserver options. 285*6fb29d29Schristos make_resolv_conf 286*6fb29d29Schristos 287*6fb29d29Schristos exit_with_hooks 0 288*6fb29d29Schristosfi 289*6fb29d29Schristos 290*6fb29d29Schristosif [ ${reason} = RENEW6 ] || [ ${reason} = REBIND6 ] ; then 291*6fb29d29Schristos # Make sure nothing has moved around on us. 292*6fb29d29Schristos 293*6fb29d29Schristos # Nameservers/domains/etc. 294*6fb29d29Schristos if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] || 295*6fb29d29Schristos [ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ] ; then 296*6fb29d29Schristos make_resolv_conf 297*6fb29d29Schristos fi 298*6fb29d29Schristos 299*6fb29d29Schristos exit_with_hooks 0 300*6fb29d29Schristosfi 301*6fb29d29Schristos 302*6fb29d29Schristosif [ ${reason} = DEPREF6 ] ; then 303*6fb29d29Schristos if [ x${new_ip6_prefixlen} = x ] ; then 304*6fb29d29Schristos exit_with_hooks 2; 305*6fb29d29Schristos fi 306*6fb29d29Schristos 307*6fb29d29Schristos # XXX: 308*6fb29d29Schristos # There doesn't appear to be a way to update an addr to indicate 309*6fb29d29Schristos # preference. 310*6fb29d29Schristos 311*6fb29d29Schristos exit_with_hooks 0 312*6fb29d29Schristosfi 313*6fb29d29Schristos 314*6fb29d29Schristosif [ ${reason} = EXPIRE6 -o ${reason} = RELEASE6 -o ${reason} = STOP6 ] ; then 315*6fb29d29Schristos if [ x${old_ip6_address} = x ] || [ x${old_ip6_prefixlen} = x ] ; then 316*6fb29d29Schristos exit_with_hooks 2; 317*6fb29d29Schristos fi 318*6fb29d29Schristos 319*6fb29d29Schristos ifconfig ${interface} inet6 delete ${old_ip6_address}/${old_ip6_prefixlen} 320*6fb29d29Schristos 321*6fb29d29Schristos exit_with_hooks 0 322*6fb29d29Schristosfi 323*6fb29d29Schristos 324*6fb29d29Schristosexit_with_hooks 0 325