Here’s mine; simpler because it just assumes the last announcement TBR will work. And I run the container in host mode, so no need to run commands inside docker.
#!/bin/sh
set -e
IFACE="eth0"
RDISC_OUTPUT=$(rdisc6 "$IFACE")
echo "🔍 Extracting ULA routes..."
echo "$RDISC_OUTPUT" | awk '
BEGIN { prefix = ""; from = "" }
/^ Prefix|^ Route/ && $3 ~ /^fd/ { route = $3 }
/^ from / { from = $2; print route, from; route = "" }
' | sort -u | while read -r prefix router; do
[ -z "$prefix" ] && continue
[ -z "$router" ] && continue
echo "📡 ULA/Route: $prefix via $router"
ip -6 route show | grep -q "$prefix" && {
echo "🧹 Removing existing route to $prefix"
ip -6 route del "$prefix" 2>/dev/null || true
}
echo "➕ Adding route to $prefix via $router on $IFACE"
ip -6 route add "$prefix" via "$router" dev "$IFACE" && echo "✅ Added"
done