freebsd-nq/libexec/rc/rc.d/defaultroute
Bjoern A. Zeeb 0696600c41 Move the rc framework out of sbin/init into libexec/rc.
The reasons for this are forward looking to pkgbase:
 * /sbin/init is a special binary; try not to replace it with
   every package update because an rc script was touched.
   (a follow-up commit will make init its own package)
 * having rc in its own place will allow more easy replacement
   of the rc framework with alternatives, such as openrc.

Discussed with:		brd (during BSDCam), kmoore
Requested by:		cem, bz
PR:			231522
Approved by:		re (gjb)
2018-10-17 16:49:11 +00:00

75 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
#
# Wait for the default route to be up if DHCP is in use
#
# $FreeBSD$
#
# PROVIDE: defaultroute
# REQUIRE: devd netif stf
# KEYWORD: nojailvnet
. /etc/rc.subr
. /etc/network.subr
name="defaultroute"
desc="Setup default router"
start_cmd="defaultroute_start"
stop_cmd=":"
# 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}
}
defaultroute_start()
{
local nl waited
afexists inet || return 0
# 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
# Wait for a default route
waited=0
while [ ${waited} -lt ${defaultroute_delay} ]; do
defif=`get_default_if -inet`
if [ -n "${defif}" ]; then
if [ ${waited} -ne 0 ]; then
echo -n "($defif)"
nl=1
fi
break
fi
if [ ${waited} -eq 0 ]; then
echo -n "Waiting ${defaultroute_delay}s for the default route interface: "
else
echo -n .
fi
if [ ${waited} -eq ${defaultroute_carrier_delay} ] && ! defaultroute_carrier; then
echo -n "(no carrier)"
break
fi
nl=1
sleep 1
waited=$(($waited + 1))
done
[ -n "$nl" ] && echo
}
load_rc_config $name
run_rc_command "$1"