Much of the core bits are initially ported.

This should be mostly independent of my configs, now.
This commit is contained in:
2026-05-09 03:26:53 -04:00
parent 6b02d9d58e
commit 4d30691ee6
16 changed files with 1278 additions and 2 deletions
Executable
+103
View File
@@ -0,0 +1,103 @@
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: localnet
# REQUIRE: dhcp6c
# BEFORE: named
# KEYWORD: shutdown
#
# The purpose of this script is to generate various ISP prefix dependent files.
#
# Specifically, the DNS (BIND) acls file for handling various views, a local ISP
# range address for the router itself (on a dedicated loopback device), and
# attach any static addresses for this machine to another loopback device.
. ${RC_ROUTER_HARNESS}/etc/rc.subr
name='localnet'
extra_commands="rebuild_zoneinfo"
start_cmd='localnet_start'
stop_cmd='localnet_stop'
rebuild_zoneinfo_cmd="localnet_build_zoneinfo"
rcvar='localnet_enable'
load_rc_config 'localnet'
localnet_build_zoneinfo()
{
compute_addrs
localnet_build_zoneinfo_impl
}
localnet_build_zoneinfo_impl()
{
#build_zoneinfo ${isp_prefix} 31 ${router_conf_dir}/namedb/local-machines.defs
build_zoneinfo ${isp_prefix} 31 ${rc_router_conf_dir}/namedb/local-machines.defs > ${rc_router_gen_dir}/zone.hosts.nerdland.org
}
localnet_build_acls()
{
gen_acls_dir=${rc_router_gen_dir}/namedb
mkdir -p ${gen_acls_dir}
cat ${rc_router_dir}/templates/named.acls.conf \
| sed \
-e "s/@ISP_PREFIX@/${isp_prefix}/g" \
-e "s/@ULA_PREFIX@/${secret_ip6_net}/g" \
> ${gen_acls_dir}/acls.conf
}
compute_addrs() {
loop=0
while [ -z "${v6addr}" -a ${loop} -lt 5 ]
do
[ ${loop} -ne 0 ] && sleep 5
# todo: Adjust our ipv6 hint... get from a var?
v6addr=$(ifconfig ${localnet_first_nic} | grep "inet6 [23]...:" | head -1 | awk '{print $2}')
echo "V6 addr is: ${v6addr}"
loop=$(( ${loop} + 1 ))
done
echo "V6 addr is: ${v6addr}"
three_quads=$(echo ${v6addr} | awk -F ':' '{print $1":"$2":"$3}')
echo "First three quads are: ${three_quads}"
last_quad=$(echo ${v6addr} | awk -F ':' '{print $4}')
echo "Last quad is: ${last_quad}"
last_prefix=$(echo ${last_quad} | rev | awk '{print $1"0000"}' | cut -c 3,4 | rev | sed -e 's/^0//')
echo "Last prefix is: ${last_prefix}"
isp_prefix="${three_quads}:${last_prefix}"
base_addr=" inet6 ${isp_prefix}ff::1"
}
localnet_start() {
cp ${rc_router_conf_dir}/resolv.conf.master ${rc_router_conf_dir}/resolv.conf
compute_addrs
ifconfig lo1 create ${base_addr} prefer_source
# DO NOT USE prefer_source for this address...
# It will cause confusion for the wireguard tunnels underneath...
# It also could cause DNS recursion to fail -- routing as the nested
# connections...
localnet_build_acls
localnet_build_zoneinfo_impl
}
localnet_stop() {
compute_addrs
ifconfig lo0 ${base_addr} delete
ifconfig lo1 destroy
}
run_rc_command "$1"
# vim: ft=bash