1#!/bin/sh 2# 3# Wait for the default route to be up if DHCP is in use 4# 5# 6 7# PROVIDE: defaultroute 8# REQUIRE: devd netif stf 9# KEYWORD: nojailvnet 10 11. /etc/rc.subr 12. /etc/network.subr 13 14name="defaultroute" 15desc="Setup default router" 16start_cmd="defaultroute_start" 17stop_cmd=":" 18 19# Does any interface have a carrier? 20defaultroute_carrier() 21{ 22 local carrier nocarrier 23 24 carrier=1 25 for _if in ${dhcp_interfaces}; do 26 output=`/sbin/ifconfig ${_if}` 27 nocarrier=`expr "${output}" : '.*[[:blank:]]status: \(no carrier\)'` 28 [ -z "${nocarrier}" ] && carrier=0 29 done 30 return ${carrier} 31} 32 33defaultroute_start() 34{ 35 local nl waited 36 37 afexists inet || return 0 38 39 # Return without waiting if we don't have dhcp interfaces or 40 # if none of the dhcp interfaces is plugged in. 41 dhcp_interfaces=`list_net_interfaces dhcp` 42 [ -z "${dhcp_interfaces}" ] && return 43 44 # Wait for a default route 45 waited=0 46 while [ ${waited} -lt ${defaultroute_delay} ]; do 47 defif=`get_default_if -inet` 48 if [ -n "${defif}" ]; then 49 if [ ${waited} -ne 0 ]; then 50 echo -n "($defif)" 51 nl=1 52 fi 53 break 54 fi 55 if [ ${waited} -eq 0 ]; then 56 echo -n "Waiting ${defaultroute_delay}s for the default route interface: " 57 else 58 echo -n . 59 fi 60 if [ ${waited} -eq ${defaultroute_carrier_delay} ] && ! defaultroute_carrier; then 61 echo -n "(no carrier)" 62 break 63 fi 64 nl=1 65 sleep 1 66 waited=$(($waited + 1)) 67 done 68 69 [ -n "$nl" ] && echo 70} 71 72load_rc_config $name 73 74# doesn't make sense to run in a svcj: config setting 75defaultroute_svcj="NO" 76 77run_rc_command "$1" 78