2008-06-05 17:26:47 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2010-09-29 13:08:23 +00:00
|
|
|
# Wait for the default route to be up if DHCP is in use
|
2008-06-05 17:26:47 +00:00
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: defaultroute
|
2014-11-09 21:33:01 +00:00
|
|
|
# REQUIRE: devd netif stf
|
2008-06-05 17:26:47 +00:00
|
|
|
# KEYWORD: nojail
|
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
. /etc/network.subr
|
|
|
|
|
|
|
|
name="defaultroute"
|
|
|
|
start_cmd="defaultroute_start"
|
|
|
|
stop_cmd=":"
|
|
|
|
|
2010-09-29 13:08:23 +00:00
|
|
|
# Does any interface have a carrier?
|
|
|
|
defaultroute_carrier()
|
|
|
|
{
|
|
|
|
local carrier nocarrier
|
|
|
|
|
|
|
|
carrier=1
|
|
|
|
for _if in ${dhcp_interfaces}; do
|
|
|
|
output=`/sbin/ifconfig ${_if}`
|
|
|
|
nocarrier=`expr "${output}" : '.*[[:blank:]]status: \(no carrier\)'`
|
|
|
|
[ -z "${nocarrier}" ] && carrier=0
|
|
|
|
done
|
|
|
|
return ${carrier}
|
|
|
|
}
|
|
|
|
|
2008-06-05 17:26:47 +00:00
|
|
|
defaultroute_start()
|
|
|
|
{
|
2010-09-29 13:08:23 +00:00
|
|
|
local nl waited
|
2009-02-02 15:33:22 +00:00
|
|
|
|
2009-10-02 02:24:25 +00:00
|
|
|
afexists inet || return 0
|
|
|
|
|
2009-02-02 15:33:22 +00:00
|
|
|
# Return without waiting if we don't have dhcp interfaces or
|
|
|
|
# if none of the dhcp interfaces is plugged in.
|
|
|
|
dhcp_interfaces=`list_net_interfaces dhcp`
|
|
|
|
[ -z "${dhcp_interfaces}" ] && return
|
2008-06-05 17:26:47 +00:00
|
|
|
|
|
|
|
# Wait for a default route
|
2010-09-29 13:08:23 +00:00
|
|
|
waited=0
|
|
|
|
while [ ${waited} -lt ${defaultroute_delay} ]; do
|
2008-06-05 17:26:47 +00:00
|
|
|
defif=`get_default_if -inet`
|
|
|
|
if [ -n "${defif}" ]; then
|
2010-09-29 13:08:23 +00:00
|
|
|
if [ ${waited} -ne 0 ]; then
|
2008-12-17 17:35:14 +00:00
|
|
|
echo -n "($defif)"
|
2009-09-12 22:13:41 +00:00
|
|
|
nl=1
|
2008-06-05 17:26:47 +00:00
|
|
|
fi
|
|
|
|
break
|
|
|
|
fi
|
2010-09-29 13:08:23 +00:00
|
|
|
if [ ${waited} -eq 0 ]; then
|
|
|
|
echo -n "Waiting ${defaultroute_delay}s for the default route interface: "
|
2008-06-05 17:26:47 +00:00
|
|
|
else
|
|
|
|
echo -n .
|
|
|
|
fi
|
2010-09-29 13:08:23 +00:00
|
|
|
if [ ${waited} -eq ${defaultroute_carrier_delay} ] && ! defaultroute_carrier; then
|
|
|
|
echo -n "(no carrier)"
|
|
|
|
break
|
|
|
|
fi
|
2009-09-12 22:13:41 +00:00
|
|
|
nl=1
|
2008-06-05 17:26:47 +00:00
|
|
|
sleep 1
|
2010-09-29 13:08:23 +00:00
|
|
|
waited=$(($waited + 1))
|
2008-06-05 17:26:47 +00:00
|
|
|
done
|
2008-12-17 17:35:14 +00:00
|
|
|
|
2009-09-12 22:13:41 +00:00
|
|
|
[ -n "$nl" ] && echo
|
2008-06-05 17:26:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
load_rc_config $name
|
|
|
|
run_rc_command "$1"
|