1*6fb29d29Schristos#!/bin/sh 2*6fb29d29Schristos# 3*6fb29d29Schristos# Id: freebsd,v 1.24 2011/05/18 19:55:44 sar Exp 4*6fb29d29Schristos# 5*6fb29d29Schristos# $FreeBSD$ 6*6fb29d29Schristos 7*6fb29d29Schristosif [ -x /usr/bin/logger ]; then 8*6fb29d29Schristos LOGGER="/usr/bin/logger -s -p user.notice -t dhclient" 9*6fb29d29Schristoselse 10*6fb29d29Schristos LOGGER=echo 11*6fb29d29Schristosfi 12*6fb29d29Schristos 13*6fb29d29Schristosmake_resolv_conf() { 14*6fb29d29Schristos if [ x"$new_domain_name_servers" != x ]; then 15*6fb29d29Schristos ( cat /dev/null > /etc/resolv.conf.dhclient ) 16*6fb29d29Schristos exit_status=$? 17*6fb29d29Schristos if [ $exit_status -ne 0 ]; then 18*6fb29d29Schristos $LOGGER "Unable to create /etc/resolv.conf.dhclient: Error $exit_status" 19*6fb29d29Schristos else 20*6fb29d29Schristos if [ "x$new_domain_search" != x ]; then 21*6fb29d29Schristos ( echo search $new_domain_search >> /etc/resolv.conf.dhclient ) 22*6fb29d29Schristos exit_status=$? 23*6fb29d29Schristos elif [ "x$new_domain_name" != x ]; then 24*6fb29d29Schristos # Note that the DHCP 'Domain Name Option' is really just a domain 25*6fb29d29Schristos # name, and that this practice of using the domain name option as 26*6fb29d29Schristos # a search path is both nonstandard and deprecated. 27*6fb29d29Schristos ( echo search $new_domain_name >> /etc/resolv.conf.dhclient ) 28*6fb29d29Schristos exit_status=$? 29*6fb29d29Schristos fi 30*6fb29d29Schristos for nameserver in $new_domain_name_servers; do 31*6fb29d29Schristos if [ $exit_status -ne 0 ]; then 32*6fb29d29Schristos break 33*6fb29d29Schristos fi 34*6fb29d29Schristos ( echo nameserver $nameserver >>/etc/resolv.conf.dhclient ) 35*6fb29d29Schristos exit_status=$? 36*6fb29d29Schristos done 37*6fb29d29Schristos 38*6fb29d29Schristos # If there were no errors, attempt to mv the new file into place. 39*6fb29d29Schristos if [ $exit_status -eq 0 ]; then 40*6fb29d29Schristos ( mv /etc/resolv.conf.dhclient /etc/resolv.conf ) 41*6fb29d29Schristos exit_status=$? 42*6fb29d29Schristos fi 43*6fb29d29Schristos 44*6fb29d29Schristos if [ $exit_status -ne 0 ]; then 45*6fb29d29Schristos $LOGGER "Error while writing new /etc/resolv.conf." 46*6fb29d29Schristos fi 47*6fb29d29Schristos fi 48*6fb29d29Schristos elif [ "x${new_dhcp6_name_servers}" != x ] ; then 49*6fb29d29Schristos ( cat /dev/null > /etc/resolv.conf.dhclient6 ) 50*6fb29d29Schristos exit_status=$? 51*6fb29d29Schristos if [ $exit_status -ne 0 ] ; then 52*6fb29d29Schristos $LOGGER "Unable to create /etc/resolv.conf.dhclient6: Error $exit_status" 53*6fb29d29Schristos else 54*6fb29d29Schristos if [ "x${new_dhcp6_domain_search}" != x ] ; then 55*6fb29d29Schristos ( echo search ${new_dhcp6_domain_search} >> /etc/resolv.conf.dhclient6 ) 56*6fb29d29Schristos exit_status=$? 57*6fb29d29Schristos fi 58*6fb29d29Schristos for nameserver in ${new_dhcp6_name_servers} ; do 59*6fb29d29Schristos if [ $exit_status -ne 0 ] ; then 60*6fb29d29Schristos break 61*6fb29d29Schristos fi 62*6fb29d29Schristos # If the nameserver has a link-local address 63*6fb29d29Schristos # add a <zone_id> (interface name) to it. 64*6fb29d29Schristos case $nameserver in 65*6fb29d29Schristos fe80:*) zone_id="%$interface";; 66*6fb29d29Schristos FE80:*) zone_id="%$interface";; 67*6fb29d29Schristos *) zone_id="";; 68*6fb29d29Schristos esac 69*6fb29d29Schristos ( echo nameserver ${nameserver}$zone_id >> /etc/resolv.conf.dhclient6 ) 70*6fb29d29Schristos exit_status=$? 71*6fb29d29Schristos done 72*6fb29d29Schristos 73*6fb29d29Schristos if [ $exit_status -eq 0 ] ; then 74*6fb29d29Schristos ( mv /etc/resolv.conf.dhclient6 /etc/resolv.conf ) 75*6fb29d29Schristos exit_status=$? 76*6fb29d29Schristos fi 77*6fb29d29Schristos 78*6fb29d29Schristos if [ $exit_status -ne 0 ] ; then 79*6fb29d29Schristos $LOGGER "Error while writing new /etc/resolv.conf." 80*6fb29d29Schristos fi 81*6fb29d29Schristos fi 82*6fb29d29Schristos fi 83*6fb29d29Schristos} 84*6fb29d29Schristos 85*6fb29d29Schristos# Must be used on exit. Invokes the local dhcp client exit hooks, if any. 86*6fb29d29Schristosexit_with_hooks() { 87*6fb29d29Schristos exit_status=$1 88*6fb29d29Schristos if [ -f /etc/dhclient-exit-hooks ]; then 89*6fb29d29Schristos . /etc/dhclient-exit-hooks 90*6fb29d29Schristos fi 91*6fb29d29Schristos# probably should do something with exit status of the local script 92*6fb29d29Schristos exit $exit_status 93*6fb29d29Schristos} 94*6fb29d29Schristos 95*6fb29d29Schristos# This function was largely borrowed from dhclient-script that 96*6fb29d29Schristos# ships with Centos, authored by Jiri Popelka and David Cantrell 97*6fb29d29Schristos# of Redhat. Thanks guys. 98*6fb29d29Schristosadd_ipv6_addr_with_DAD() { 99*6fb29d29Schristos ifconfig ${interface} inet6 ${new_ip6_address}/${new_ip6_prefixlen} alias 100*6fb29d29Schristos 101*6fb29d29Schristos if [ ${dad_wait_time} -le 0 ] 102*6fb29d29Schristos then 103*6fb29d29Schristos # if we're not waiting for DAD, assume we're good 104*6fb29d29Schristos return 0 105*6fb29d29Schristos fi 106*6fb29d29Schristos 107*6fb29d29Schristos # Repeatedly test whether newly added address passed 108*6fb29d29Schristos # duplicate address detection (DAD) 109*6fb29d29Schristos for i in $(seq 1 ${dad_wait_time}); do 110*6fb29d29Schristos sleep 1 # give the DAD some time 111*6fb29d29Schristos 112*6fb29d29Schristos addr=$(ifconfig ${interface} \ 113*6fb29d29Schristos | grep "${new_ip6_address} prefixlen ${new_ip6_prefixlen}") 114*6fb29d29Schristos 115*6fb29d29Schristos # tentative flag == DAD is still not complete 116*6fb29d29Schristos tentative=$(echo "${addr}" | grep tentative) 117*6fb29d29Schristos # dadfailed flag == address is already in use somewhere else 118*6fb29d29Schristos dadfailed=$(echo "${addr}" | grep duplicated) 119*6fb29d29Schristos 120*6fb29d29Schristos if [ -n "${dadfailed}" ] ; then 121*6fb29d29Schristos # dad failed, remove the address 122*6fb29d29Schristos ifconfig ${interface} inet6 ${new_ip6_address}/${new_ip6_prefixlen} -alias 123*6fb29d29Schristos exit_with_hooks 3 124*6fb29d29Schristos fi 125*6fb29d29Schristos 126*6fb29d29Schristos if [ -z "${tentative}" ] ; then 127*6fb29d29Schristos if [ -n "${addr}" ]; then 128*6fb29d29Schristos # DAD is over 129*6fb29d29Schristos return 0 130*6fb29d29Schristos else 131*6fb29d29Schristos # address was auto-removed (or not added at all) 132*6fb29d29Schristos exit_with_hooks 3 133*6fb29d29Schristos fi 134*6fb29d29Schristos fi 135*6fb29d29Schristos done 136*6fb29d29Schristos 137*6fb29d29Schristos return 0 138*6fb29d29Schristos} 139*6fb29d29Schristos 140*6fb29d29Schristos# Invoke the local dhcp client enter hooks, if they exist. 141*6fb29d29Schristosif [ -f /etc/dhclient-enter-hooks ]; then 142*6fb29d29Schristos exit_status=0 143*6fb29d29Schristos . /etc/dhclient-enter-hooks 144*6fb29d29Schristos # allow the local script to abort processing of this state 145*6fb29d29Schristos # local script must set exit_status variable to nonzero. 146*6fb29d29Schristos if [ $exit_status -ne 0 ]; then 147*6fb29d29Schristos exit $exit_status 148*6fb29d29Schristos fi 149*6fb29d29Schristosfi 150*6fb29d29Schristos 151*6fb29d29Schristosif [ x$new_network_number != x ]; then 152*6fb29d29Schristos $LOGGER New Network Number: $new_network_number 153*6fb29d29Schristosfi 154*6fb29d29Schristos 155*6fb29d29Schristosif [ x$new_broadcast_address != x ]; then 156*6fb29d29Schristos $LOGGER New Broadcast Address: $new_broadcast_address 157*6fb29d29Schristos new_broadcast_arg="broadcast $new_broadcast_address" 158*6fb29d29Schristosfi 159*6fb29d29Schristosif [ x$old_broadcast_address != x ]; then 160*6fb29d29Schristos old_broadcast_arg="broadcast $old_broadcast_address" 161*6fb29d29Schristosfi 162*6fb29d29Schristosif [ x$new_subnet_mask != x ]; then 163*6fb29d29Schristos new_netmask_arg="netmask $new_subnet_mask" 164*6fb29d29Schristosfi 165*6fb29d29Schristosif [ x$old_subnet_mask != x ]; then 166*6fb29d29Schristos old_netmask_arg="netmask $old_subnet_mask" 167*6fb29d29Schristosfi 168*6fb29d29Schristosif [ x$alias_subnet_mask != x ]; then 169*6fb29d29Schristos alias_subnet_arg="netmask $alias_subnet_mask" 170*6fb29d29Schristosfi 171*6fb29d29Schristosif [ x$new_interface_mtu != x ]; then 172*6fb29d29Schristos mtu_arg="mtu $new_interface_mtu" 173*6fb29d29Schristosfi 174*6fb29d29Schristosif [ x$IF_METRIC != x ]; then 175*6fb29d29Schristos metric_arg="metric $IF_METRIC" 176*6fb29d29Schristosfi 177*6fb29d29Schristos 178*6fb29d29Schristosif [ x$reason = xMEDIUM ]; then 179*6fb29d29Schristos eval "ifconfig $interface $medium" 180*6fb29d29Schristos eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1 181*6fb29d29Schristos sleep 1 182*6fb29d29Schristos exit_with_hooks 0 183*6fb29d29Schristosfi 184*6fb29d29Schristos 185*6fb29d29Schristos### 186*6fb29d29Schristos### DHCPv4 Handlers 187*6fb29d29Schristos### 188*6fb29d29Schristos 189*6fb29d29Schristosif [ x$reason = xPREINIT ]; then 190*6fb29d29Schristos if [ x$alias_ip_address != x ]; then 191*6fb29d29Schristos ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1 192*6fb29d29Schristos route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1 193*6fb29d29Schristos fi 194*6fb29d29Schristos ifconfig $interface inet 0.0.0.0 netmask 0.0.0.0 \ 195*6fb29d29Schristos broadcast 255.255.255.255 up 196*6fb29d29Schristos exit_with_hooks 0 197*6fb29d29Schristosfi 198*6fb29d29Schristos 199*6fb29d29Schristosif [ x$reason = xARPCHECK ] || [ x$reason = xARPSEND ]; then 200*6fb29d29Schristos exit_with_hooks 0; 201*6fb29d29Schristosfi 202*6fb29d29Schristos 203*6fb29d29Schristosif [ x$reason = xBOUND ] || [ x$reason = xRENEW ] || \ 204*6fb29d29Schristos [ x$reason = xREBIND ] || [ x$reason = xREBOOT ]; then 205*6fb29d29Schristos current_hostname=`/bin/hostname` 206*6fb29d29Schristos if [ x$current_hostname = x ] || \ 207*6fb29d29Schristos [ x$current_hostname = x$old_host_name ]; then 208*6fb29d29Schristos if [ x$current_hostname = x ] || \ 209*6fb29d29Schristos [ x$new_host_name != x$old_host_name ]; then 210*6fb29d29Schristos $LOGGER "New Hostname: $new_host_name" 211*6fb29d29Schristos hostname $new_host_name 212*6fb29d29Schristos fi 213*6fb29d29Schristos fi 214*6fb29d29Schristos if [ x$old_ip_address != x ] && [ x$alias_ip_address != x ] && \ 215*6fb29d29Schristos [ x$alias_ip_address != x$old_ip_address ]; then 216*6fb29d29Schristos ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1 217*6fb29d29Schristos route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1 218*6fb29d29Schristos fi 219*6fb29d29Schristos if [ x$old_ip_address != x ] && [ x$old_ip_address != x$new_ip_address ] 220*6fb29d29Schristos then 221*6fb29d29Schristos eval "ifconfig $interface inet -alias $old_ip_address $medium" 222*6fb29d29Schristos route delete $old_ip_address 127.1 >/dev/null 2>&1 223*6fb29d29Schristos for router in $old_routers; do 224*6fb29d29Schristos route delete default $router >/dev/null 2>&1 225*6fb29d29Schristos done 226*6fb29d29Schristos if [ -n "$old_static_routes" ]; then 227*6fb29d29Schristos set -- $old_static_routes 228*6fb29d29Schristos while [ $# -gt 1 ]; do 229*6fb29d29Schristos route delete $1 $2 230*6fb29d29Schristos shift; shift 231*6fb29d29Schristos done 232*6fb29d29Schristos fi 233*6fb29d29Schristos arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' |sh 234*6fb29d29Schristos fi 235*6fb29d29Schristos if [ x$old_ip_address = x ] || [ x$old_ip_address != x$new_ip_address ] || \ 236*6fb29d29Schristos [ x$reason = xBOUND ] || [ x$reason = xREBOOT ]; then 237*6fb29d29Schristos eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \ 238*6fb29d29Schristos $new_broadcast_arg $mtu_arg $metric_arg $medium" 239*6fb29d29Schristos $LOGGER "New IP Address ($interface): $new_ip_address" 240*6fb29d29Schristos $LOGGER "New Subnet Mask ($interface): $new_subnet_mask" 241*6fb29d29Schristos $LOGGER "New Broadcast Address ($interface): $new_broadcast_address" 242*6fb29d29Schristos if [ -n "$new_routers" ]; then 243*6fb29d29Schristos $LOGGER "New Routers: $new_routers" 244*6fb29d29Schristos fi 245*6fb29d29Schristos route add $new_ip_address 127.1 >/dev/null 2>&1 246*6fb29d29Schristos for router in $new_routers; do 247*6fb29d29Schristos # If the subnet is captive, eg the netmask is /32 but the default 248*6fb29d29Schristos # gateway is (obviously) outside of this, then we need to produce a 249*6fb29d29Schristos # host route to reach the gateway. 250*6fb29d29Schristos if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then 251*6fb29d29Schristos route add -host $router -interface $interface 252*6fb29d29Schristos fi 253*6fb29d29Schristos route add default $router >/dev/null 2>&1 254*6fb29d29Schristos done 255*6fb29d29Schristos if [ -n "$new_static_routes" ]; then 256*6fb29d29Schristos $LOGGER "New Static Routes: $new_static_routes" 257*6fb29d29Schristos set -- $new_static_routes 258*6fb29d29Schristos while [ $# -gt 1 ]; do 259*6fb29d29Schristos route add $1 $2 260*6fb29d29Schristos shift; shift 261*6fb29d29Schristos done 262*6fb29d29Schristos fi 263*6fb29d29Schristos else 264*6fb29d29Schristos # we haven't changed the address, have we changed other options 265*6fb29d29Schristos # that we wish to update? 266*6fb29d29Schristos if [ x$new_routers != x ] && [ x$new_routers != x$old_routers ] ; then 267*6fb29d29Schristos # if we've changed routers delete the old and add the new. 268*6fb29d29Schristos $LOGGER "New Routers: $new_routers" 269*6fb29d29Schristos for router in $old_routers; do 270*6fb29d29Schristos route delete default $router >/dev/null 2>&1 271*6fb29d29Schristos done 272*6fb29d29Schristos for router in $new_routers; do 273*6fb29d29Schristos # If the subnet is captive, eg the netmask is /32 but the default 274*6fb29d29Schristos # gateway is (obviously) outside of this, then we need to produce a 275*6fb29d29Schristos # host route to reach the gateway. 276*6fb29d29Schristos if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then 277*6fb29d29Schristos route add -host $router -interface $interface 278*6fb29d29Schristos fi 279*6fb29d29Schristos route add default $router >/dev/null 2>&1 280*6fb29d29Schristos done 281*6fb29d29Schristos fi 282*6fb29d29Schristos fi 283*6fb29d29Schristos if [ x$new_ip_address != x$alias_ip_address ] && [ x$alias_ip_address != x ]; 284*6fb29d29Schristos then 285*6fb29d29Schristos ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg 286*6fb29d29Schristos route add $alias_ip_address 127.0.0.1 287*6fb29d29Schristos fi 288*6fb29d29Schristos make_resolv_conf 289*6fb29d29Schristos exit_with_hooks 0 290*6fb29d29Schristosfi 291*6fb29d29Schristos 292*6fb29d29Schristosif [ x$reason = xEXPIRE ] || [ x$reason = xFAIL ] || [ x$reason = xRELEASE ] \ 293*6fb29d29Schristos || [ x$reason = xSTOP ]; then 294*6fb29d29Schristos if [ x$alias_ip_address != x ]; then 295*6fb29d29Schristos ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1 296*6fb29d29Schristos route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1 297*6fb29d29Schristos fi 298*6fb29d29Schristos if [ x$old_ip_address != x ]; then 299*6fb29d29Schristos eval "ifconfig $interface inet -alias $old_ip_address $medium" 300*6fb29d29Schristos route delete $old_ip_address 127.1 >/dev/null 2>&1 301*6fb29d29Schristos for router in $old_routers; do 302*6fb29d29Schristos route delete default $router >/dev/null 2>&1 303*6fb29d29Schristos done 304*6fb29d29Schristos if [ -n "$old_static_routes" ]; then 305*6fb29d29Schristos set -- $old_static_routes 306*6fb29d29Schristos while [ $# -gt 1 ]; do 307*6fb29d29Schristos route delete $1 $2 308*6fb29d29Schristos shift; shift 309*6fb29d29Schristos done 310*6fb29d29Schristos fi 311*6fb29d29Schristos arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' \ 312*6fb29d29Schristos |sh >/dev/null 2>&1 313*6fb29d29Schristos fi 314*6fb29d29Schristos if [ x$alias_ip_address != x ]; then 315*6fb29d29Schristos ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg 316*6fb29d29Schristos route add $alias_ip_address 127.0.0.1 317*6fb29d29Schristos fi 318*6fb29d29Schristos exit_with_hooks 0 319*6fb29d29Schristosfi 320*6fb29d29Schristos 321*6fb29d29Schristosif [ x$reason = xTIMEOUT ]; then 322*6fb29d29Schristos if [ x$alias_ip_address != x ]; then 323*6fb29d29Schristos ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1 324*6fb29d29Schristos route delete $alias_ip_address 127.0.0.1 > /dev/null 2>&1 325*6fb29d29Schristos fi 326*6fb29d29Schristos eval "ifconfig $interface inet $new_ip_address $new_netmask_arg \ 327*6fb29d29Schristos $new_broadcast_arg $mtu_arg $metric_arg $medium" 328*6fb29d29Schristos $LOGGER "New IP Address ($interface): $new_ip_address" 329*6fb29d29Schristos $LOGGER "New Subnet Mask ($interface): $new_subnet_mask" 330*6fb29d29Schristos $LOGGER "New Broadcast Address ($interface): $new_broadcast_address" 331*6fb29d29Schristos sleep 1 332*6fb29d29Schristos if [ -n "$new_routers" ]; then 333*6fb29d29Schristos $LOGGER "New Routers: $new_routers" 334*6fb29d29Schristos set -- $new_routers 335*6fb29d29Schristos if ping -q -c 1 $1; then 336*6fb29d29Schristos if [ x$new_ip_address != x$alias_ip_address ] && \ 337*6fb29d29Schristos [ x$alias_ip_address != x ]; then 338*6fb29d29Schristos ifconfig $interface inet alias $alias_ip_address $alias_subnet_arg 339*6fb29d29Schristos route add $alias_ip_address 127.0.0.1 340*6fb29d29Schristos fi 341*6fb29d29Schristos route add $new_ip_address 127.1 >/dev/null 2>&1 342*6fb29d29Schristos for router in $new_routers; do 343*6fb29d29Schristos if [ "x$new_subnet_mask" = "x255.255.255.255" ] ; then 344*6fb29d29Schristos route add -host $router -interface $interface 345*6fb29d29Schristos fi 346*6fb29d29Schristos route add default $router >/dev/null 2>&1 347*6fb29d29Schristos done 348*6fb29d29Schristos set -- $new_static_routes 349*6fb29d29Schristos while [ $# -gt 1 ]; do 350*6fb29d29Schristos route add $1 $2 351*6fb29d29Schristos shift; shift 352*6fb29d29Schristos done 353*6fb29d29Schristos make_resolv_conf 354*6fb29d29Schristos exit_with_hooks 0 355*6fb29d29Schristos fi 356*6fb29d29Schristos fi 357*6fb29d29Schristos eval "ifconfig $interface inet -alias $new_ip_address $medium" 358*6fb29d29Schristos for router in $old_routers; do 359*6fb29d29Schristos route delete default $router >/dev/null 2>&1 360*6fb29d29Schristos done 361*6fb29d29Schristos if [ -n "$old_static_routes" ]; then 362*6fb29d29Schristos set -- $old_static_routes 363*6fb29d29Schristos while [ $# -gt 1 ]; do 364*6fb29d29Schristos route delete $1 $2 365*6fb29d29Schristos shift; shift 366*6fb29d29Schristos done 367*6fb29d29Schristos fi 368*6fb29d29Schristos arp -n -a | sed -n -e 's/^.*(\(.*\)) at .*$/arp -d \1/p' \ 369*6fb29d29Schristos |sh >/dev/null 2>&1 370*6fb29d29Schristos exit_with_hooks 1 371*6fb29d29Schristosfi 372*6fb29d29Schristos 373*6fb29d29Schristos### 374*6fb29d29Schristos### DHCPv6 Handlers 375*6fb29d29Schristos### 376*6fb29d29Schristos 377*6fb29d29Schristosif [ ${reason} = PREINIT6 ] ; then 378*6fb29d29Schristos # Ensure interface is up. 379*6fb29d29Schristos ifconfig ${interface} up 380*6fb29d29Schristos 381*6fb29d29Schristos # XXX: Remove any stale addresses from aborted clients. 382*6fb29d29Schristos 383*6fb29d29Schristos # We need to give the kernel some time to active interface 384*6fb29d29Schristos interface_up_wait_time=5 385*6fb29d29Schristos for i in $(seq 0 ${interface_up_wait_time}) 386*6fb29d29Schristos do 387*6fb29d29Schristos ifconfig ${interface} | grep inactive >/dev/null 2>&1 388*6fb29d29Schristos if [ $? -ne 0 ]; then 389*6fb29d29Schristos break; 390*6fb29d29Schristos fi 391*6fb29d29Schristos sleep 1 392*6fb29d29Schristos done 393*6fb29d29Schristos 394*6fb29d29Schristos # Wait for duplicate address detection for this interface if the 395*6fb29d29Schristos # --dad-wait-time parameter has been specified and is greater than 396*6fb29d29Schristos # zero. 397*6fb29d29Schristos if [ ${dad_wait_time} -gt 0 ]; then 398*6fb29d29Schristos # Check if any IPv6 address on this interface is marked as 399*6fb29d29Schristos # tentative. 400*6fb29d29Schristos ifconfig ${interface} | grep inet6 | grep tentative \ 401*6fb29d29Schristos >/dev/null 2>&1 402*6fb29d29Schristos if [ $? -eq 0 ]; then 403*6fb29d29Schristos # Wait for duplicate address detection to complete or for 404*6fb29d29Schristos # the timeout specified as --dad-wait-time. 405*6fb29d29Schristos for i in $(seq 0 $dad_wait_time) 406*6fb29d29Schristos do 407*6fb29d29Schristos # We're going to poll for the tentative flag every second. 408*6fb29d29Schristos sleep 1 409*6fb29d29Schristos ifconfig ${interface} | grep inet6 | grep tentative \ 410*6fb29d29Schristos >/dev/null 2>&1 411*6fb29d29Schristos if [ $? -ne 0 ]; then 412*6fb29d29Schristos break; 413*6fb29d29Schristos fi 414*6fb29d29Schristos done 415*6fb29d29Schristos fi 416*6fb29d29Schristos fi 417*6fb29d29Schristos 418*6fb29d29Schristos 419*6fb29d29Schristos exit_with_hooks 0 420*6fb29d29Schristosfi 421*6fb29d29Schristos 422*6fb29d29Schristosif [ x${old_ip6_prefix} != x ] || [ x${new_ip6_prefix} != x ] ; then 423*6fb29d29Schristos echo Prefix ${reason} old=${old_ip6_prefix} new=${new_ip6_prefix} 424*6fb29d29Schristos 425*6fb29d29Schristos exit_with_hooks 0 426*6fb29d29Schristosfi 427*6fb29d29Schristos 428*6fb29d29Schristosif [ ${reason} = BOUND6 ] ; then 429*6fb29d29Schristos if [ x${new_ip6_address} = x ] || [ x${new_ip6_prefixlen} = x ] ; then 430*6fb29d29Schristos exit_with_hooks 2; 431*6fb29d29Schristos fi 432*6fb29d29Schristos 433*6fb29d29Schristos # Add address to interface, check for DAD if dad_wait_time > 0 434*6fb29d29Schristos add_ipv6_addr_with_DAD 435*6fb29d29Schristos 436*6fb29d29Schristos # Check for nameserver options. 437*6fb29d29Schristos make_resolv_conf 438*6fb29d29Schristos 439*6fb29d29Schristos exit_with_hooks 0 440*6fb29d29Schristosfi 441*6fb29d29Schristos 442*6fb29d29Schristosif [ ${reason} = RENEW6 ] || [ ${reason} = REBIND6 ] ; then 443*6fb29d29Schristos # Make sure nothing has moved around on us. 444*6fb29d29Schristos 445*6fb29d29Schristos # Nameservers/domains/etc. 446*6fb29d29Schristos if [ "x${new_dhcp6_name_servers}" != "x${old_dhcp6_name_servers}" ] || 447*6fb29d29Schristos [ "x${new_dhcp6_domain_search}" != "x${old_dhcp6_domain_search}" ] ; then 448*6fb29d29Schristos make_resolv_conf 449*6fb29d29Schristos fi 450*6fb29d29Schristos 451*6fb29d29Schristos exit_with_hooks 0 452*6fb29d29Schristosfi 453*6fb29d29Schristos 454*6fb29d29Schristosif [ ${reason} = DEPREF6 ] ; then 455*6fb29d29Schristos if [ x${new_ip6_address} = x ] ; then 456*6fb29d29Schristos exit_with_hooks 2; 457*6fb29d29Schristos fi 458*6fb29d29Schristos 459*6fb29d29Schristos ifconfig ${interface} inet6 ${new_ip6_address} deprecated 460*6fb29d29Schristos 461*6fb29d29Schristos exit_with_hooks 0 462*6fb29d29Schristosfi 463*6fb29d29Schristos 464*6fb29d29Schristosif [ ${reason} = EXPIRE6 -o ${reason} = RELEASE6 -o ${reason} = STOP6 ] ; then 465*6fb29d29Schristos if [ x${old_ip6_address} = x ] || [ x${old_ip6_prefixlen} = x ] ; then 466*6fb29d29Schristos exit_with_hooks 2; 467*6fb29d29Schristos fi 468*6fb29d29Schristos 469*6fb29d29Schristos ifconfig ${interface} inet6 ${old_ip6_address}/${old_ip6_prefixlen} -alias 470*6fb29d29Schristos 471*6fb29d29Schristos exit_with_hooks 0 472*6fb29d29Schristosfi 473*6fb29d29Schristos 474*6fb29d29Schristosexit_with_hooks 0 475