Add several important startup services

This commit is contained in:
2026-05-12 01:17:20 -04:00
parent bdd387b11c
commit f402f728e5
7 changed files with 319 additions and 10 deletions
+46
View File
@@ -0,0 +1,46 @@
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: allow_hosts
# REQUIRE: named
# KEYWORD: shutdown
#
. ${RC_ROUTER_HARNESS}/etc/rc.subr
name="allow_hosts"
desc="Allow hosts by DNS (from local DNS)"
start_cmd='allow_hosts_start'
stop_cmd='allow_hosts_stop'
rcvar='allow_hosts_enable'
load_rc_config 'allow_hosts'
if [ -z "${allow_hosts_rules}" ]
then
echo "Must have a route policy target file"
exit 1
fi
allow_hosts_start()
{
echo "Running allow hosts"
echo "include \"${allow_hosts_rules}\"" > /etc/router-conf/gen/pf.rules.conf
pfctl -a allow-hosts -f ${allow_hosts_rules}
}
allow_hosts_stop()
{
true
}
################ Epilogue
run_rc_command "$1"
# vim: ft=bash
+50
View File
@@ -0,0 +1,50 @@
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: clear_route_policy
# BEFORE: pf
# KEYWORD: shutdown
#
. ${RC_ROUTER_HARNESS}/etc/rc.subr
name="clear_route_policy"
desc="Policy Based Routing Reset"
start_cmd='clear_route_policy_start'
stop_cmd='clear_route_policy_stop'
rcvar='route_policy_enable'
load_rc_config 'route_policy'
if [ -z "${route_policy_file}" ]
then
echo "Must have a route policy target file"
exit 1
fi
clear_route_policy_start()
{
echo "" > ${route_policy_file}
pfctl -a allow-hosts -f /dev/null
clear_all_policies
#pfctl -a route-policies -f ${route_policy_file}
}
clear_route_policy_stop()
{
echo "" > ${route_policy_file}
pfctl -a allow-hosts -f /dev/null
clear_all_policies
#pfctl -a route-policies -f ${route_policy_file}
}
################ Epilogue
run_rc_command "$1"
# vim: ft=bash
Executable
+42
View File
@@ -0,0 +1,42 @@
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: fib_setup
# BEFORE: sysctl
#
. ${RC_ROUTER_HARNESS}/etc/rc.subr
name="fib_setup"
desc="Calculate and respect the fib count"
start_cmd='fib_setup_start'
stop_cmd='fib_setup_stop'
rcvar='fib_setup_enable'
load_rc_config 'fib_setup'
fib_setup_start()
{
echo "Running fib_setup"
fib_count=$(( ${rc_router_fibs} ))
max_fibs=$(( ${fib_count} + 1 ))
cp ${rc_router_dir}/templates/sysctl.conf ${rc_router_gen_dir}/
echo "net.fibs=${fib_count}" >> ${rc_router_gen_dir}/sysctl.conf
}
fib_setup_stop()
{
true
}
################ Epilogue
run_rc_command "$1"
# vim: ft=bash
+86
View File
@@ -0,0 +1,86 @@
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: route_policy
# REQUIRE: wireguard
# KEYWORD: shutdown
#
. ${RC_ROUTER_HARNESS}/etc/rc.subr
name="route_policy"
desc="Policy Based Routing Installer"
start_cmd='route_policy_start'
stop_cmd='route_policy_stop'
rcvar='route_policy_enable'
load_rc_config 'route_policy'
if [ -z "${route_policy_file}" ]
then
echo "Must have a route policy target file"
exit 1
fi
do_all_routes()
{
while [ -n "$1" ]
do
install_route_policy $1
shift 1
done
}
do_all_routes_v4()
{
while [ -n "$1" ]
do
install_route_policy_v4 $1
shift 1
done
}
route_policy_start()
{
clear_all_policies
echo "# This file is generated." >> ${route_policy_file}
echo "# Do not edit." >> ${route_policy_file}
echo "" >> ${route_policy_file}
# TODO: Record the policies one-per-line via a helper loop subroutine?
echo "# (Generated with \`${route_policies}\`, at `date`.)" >> ${route_policy_file}
echo "# (Generated with \`${route_policies_v4}\`, at `date`.)" >> ${route_policy_file}
echo "" >> ${route_policy_file}
echo "" >> ${route_policy_file}
do_all_routes ${route_policies}
do_all_routes_v4 ${route_policies_v4}
echo "" >> ${route_policy_file}
echo -n "# v" >> ${route_policy_file}
echo "im: ft=pf" >> ${route_policy_file}
#pfctl -a "route-policies" -f ${route_policy_file}
#pfctl -f ${pf_rules}
# UGLY hack/workaround because of a kernel panic bug from
# rtable rules in files included in `pf` anchors in FreeBSD 15
/etc/rc.d/pf reload
}
route_policy_stop()
{
clear_all_policies
}
################ Epilogue
run_rc_command "$1"
# vim: ft=bash
Executable
+80
View File
@@ -0,0 +1,80 @@
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: tayga
# REQUIRE: SERVERS
# KEYWORD: shutdown
#
. ${RC_ROUTER_HARNESS}/etc/rc.subr
name='tayga'
start_cmd='tayga_start'
stop_cmd='tayga_stop'
rcvar='tayga_enable'
load_rc_config 'tayga'
pidfile="/var/run/${name}.pid"
command="/usr/local/sbin/${name}"
# Confirm necessary variables are set
check_vars()
{
[ -z "$tayga_ipv4_addr" ] && err 3 "Must set tayga_ipv4_addr to the address that the tayga server lives on"
[ -z "$tayga_ipv4_endpoint" ] && err 3 "Must set tayga_ipv4_endpoint to the address that the tunnel lives on"
[ -z "$tayga_ipv4_net" ] && err 3 "Must set tayga_ipv4_net to the network that the tunnel lives on"
[ -z "$tayga_ipv6_endpoint" ] && err 3 "Must set tayga_ipv6_endpoint to the address that the tunnel lives on"
[ -z "$tayga_ipv6_net" ] && err 3 "Must set tayga_ipv6_net to the network that the tunnel provides"
}
[ -z "$tayga_config" ] && tayga_config="/usr/local/etc/tayga.conf"
command_args="-p ${pidfile} -c ${tayga_config}"
[ -z "$tayga_enable" ] && tayga_enable='YES'
tayga_start()
{
check_vars
"$command" $command_args
while ! ifconfig 'nat64'; do sleep 1; done
ifconfig 'nat64' inet "${tayga_ipv4_endpoint}/32" "${tayga_ipv4_addr}"
if [ ! -z "${tayga_group}" ] ; then ifconfig 'nat64' group ${tayga_group} ; fi
ifconfig 'nat64' inet6 "${tayga_ipv6_endpoint}/128"
#echo Add route 4
route -4 add "${tayga_ipv4_net}" -interface 'nat64'
#echo Add route 6 for endpoint from net
#route -6 add "${tayga_ipv6_endpoint}" -iface 'nat64' #-fib 0-7
route -6 add "${tayga_ipv6_net}" "${tayga_ipv6_endpoint}" #-fib 0-7
#echo Add route 6 for endpoint subnet
route -6 add "${tayga_ipv6_endpoint}/64" "${tayga_ipv6_endpoint}" #-fib 0-7
for prefix in ${tayga_v4_prefixes}
do
route add ${prefix} ${tayga_ipv4_addr} -fib 0-${max_fib}
done
}
tayga_stop()
{
if [ -n "$rc_pid" ]; then
check_vars
for prefix in tayga_v4_prefixes
do
route del ${prefix} ${tayga_ipv4_addr} -fib 0-${max_fib}
done
echo 'stopping tayga'
kill -2 "${rc_pid}"
route -6 del "${tayga_ipv6_net}" -interface 'nat64'
route -4 del "${tayga_ipv4_net}" -interface 'nat64'
ifconfig 'nat64' destroy
else
echo "${name} is not running."
fi
}
run_rc_command "$1"