freebsd-src/libexec/rc/rc.d/defaultroute
Alexander Leidinger f99f0ee14e rc.d: add a service jails config to all base system services
This gives more permissions to services (e.g. network access to
services which require this) when they are started as an automatic
service jail.

The sshd patch is important for the sshd-related functionality as
described in the man-page in the service jails part.

The location of the added env vars is supposed to allow overriding them
in rc.conf, and to hard-disable the use of svcj for some parts where it
doesn't make sense or will not work.

Only a subset of all of the services are fully tested (I'm running this
since more than a year with various services started as service jails).
The untested parts should be most of the time ok, in some edge-cases
more permissions are needed inside the service jail.
Differential Revision:	https://reviews.freebsd.org/D40371
2024-05-22 15:41:49 +02:00

78 lines
1.5 KiB
Bash
Executable file

#!/bin/sh
#
# Wait for the default route to be up if DHCP is in use
#
#
# 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
# doesn't make sense to run in a svcj: config setting
defaultroute_svcj="NO"
run_rc_command "$1"