ungleich-tools/openwrt/openwrt-nat64-bootstrap.sh

78 lines
1.4 KiB
Bash
Raw Normal View History

#!/bin/sh
# Nico Schottelius, 2024-07-22
# This script assumes a clean/newly setup openwrt device
#
# Assumption:
# WAN = IPv4, dhcp provided externally
# LAN = IPv6, "clients" that want to reach IPv4 Internet
# Consequences
# - do not provide IPv4 or IPv6 dhcp/ra on any interface
if [ $# -lt 4 ] ; then
echo $0 "address hostname nat64prefix nat64route asn routerid iBGPpeer1 [iBGPpeer2...]"
exit 1
fi
address=$1; shift
hostname=$1; shift
nat64prefix=$1; shift
nat64route=$1; shift
asn=$1; shift
routerid=$1; shift
ibgp_peers="$@"
# Now $@ only contains iBGP peers
cat <<EOF | ssh -t "root@${address}"
set -x
opkg update
# add jool + bird2
opkg install jool-tools-netfilter bird2 bird2c
# Do not announce ULA - we have GUA
uci delete network.globals.ula_prefix
# Set hostname
uci set system.@system[0].hostname="${hostname}"
# Do something wireless (?)
# disable?
echo "Setting up bird ..."
cat > /etc/bird.conf <<BBB
log syslog all;
router id ${routerid};
protocol static static6 {
ipv6;
route ${nat64prefix} unreachable;
}
BBB
for ibgp_peer in ${ibgp_peers}; do
cat >> /etc/bird.conf <<BBB
protocol bgp {
local as ${asn};
neighbor \${ibgp_peer} as ${asn};
ipv6 {
import none;
export where source ~ [ RTS_STATIC ];
};
}
BBB
2024-07-23 11:41:54 +00:00
done
2024-07-23 11:51:05 +00:00
# TODO: configure jool
# TODO: start jool
# TODO: ensure jool is started at boot
# TODO: ensure bird is started at boot
2024-07-22 10:18:48 +00:00
uci commit
/etc/init.d/bird restart
2024-07-22 10:18:48 +00:00
EOF