A DNS container that advertises its own addresses

The BGP here is iBGP to the site's own signalling router, not peering with a partner's autonomous system — and the hard part was a templating engine that cannot iterate a list.

Infra

The APN DNS containers bind their service addresses themselves and announce them with FRR from inside the same container (one process tree, supervised by s6). That is why the image sits on the FRR base layer, with two flags turning off the base image's own address handling:

ENV CONTAINER_ROUTER_SKIP_SET_HOSTNAME=true
ENV CONTAINER_ROUTER_SKIP_IP_ADD=true

The generated config is unremarkable, and worth reading for what it leaves out:

hostname <host>
!
router bgp 64661
 neighbor <signalling-router> remote-as 64661
 neighbor <signalling-router> advertisement-interval 1
 neighbor <signalling-router> timers 3 12
 !
 address-family ipv4 unicast
  neighbor <signalling-router> activate
  network 203.0.113.10/32
  network 203.0.113.11/32
 exit-address-family
!
ip route 10.0.0.0/8     <bridge-router>
ip route 172.16.0.0/12  <bridge-router>
ip route 192.168.0.0/16 <bridge-router>
!
line vty

remote-as equals the local ASN (64661, both sides), so this is iBGP to the signalling router in the same site. No route-maps, no communities, no prefix-lists, no MD5. Two values are tuned (timers 3 12 and advertisement-interval 1), and they exist so a withdrawn /32 moves inside fifteen seconds. The three static routes send every RFC 1918 destination back out through the host bridge, because the container's default route points at the external side. SIGNALLING_ROUTER_IP is optional; with it unset, the whole neighbour block is skipped (addresses bound, nothing advertised).

The templating engine will not iterate

The base image's FRR service renders envtpl /etc/templates/frr.conf.tpl > /etc/frr/frr.conf at startup. The address list arrives as EXTERNAL_SIGNALLING_IPS (a comma-separated string, always set by the deployment generator), and envtpl does not split a CSV variable into an iterable slice — so there is no {{ range }} to write. One network X/32 line per address cannot be expressed in the template at all, only in the shell.

The way out is to render the template before the service that renders it runs. /etc/cont-init.d/02-multi-ip-config runs during container init (before any service), parses the CSV once, adds each address as a /32 on eth0, then writes a fully resolved frr.conf.tpl with the loop already unrolled:

for addr in "${EXT_IPS[@]}"; do
    echo "  network ${addr}/32"
done

envtpl then runs over a file with no variables left in it (wasteful, and completely reliable). The same CSV feeds 01-render-corefile, which converts commas to spaces because CoreDNS's bind directive takes a whitespace-separated list — one variable drives two renderers and two normalisations (xargs in one, a bash array in the other).

The failure mode worth engineering against

A BGP container that comes up with an empty router bgp block is worse than one that crashes outright — the crash is the only outcome an operator can act on. The session establishes, the neighbour reports an up peer, and zero routes are advertised — a black hole that every dashboard reads as healthy. Three guards exist for that one case (sentinel, variable check, counted write).

First, the committed template is a sentinel. It is invalid FRR config on purpose, and says so in its own banner:

! ============================================================================
! SENTINEL TEMPLATE — should never be rendered as-is.
! If you are reading this content in /etc/frr/frr.conf, 02-multi-ip-config
! DID NOT RUN. FRR will refuse the syntax below — that's intentional.
! ============================================================================
! ERROR: 02-multi-ip-config did not run — refusing to advertise routes.

If the init script is removed, loses its exec bit, or exits early (three modes the banner names), FRR rejects the file and the container fails where someone will see it.

Second, the required variables are checked with parameter expansion instead of left to render empty:

: "${SERVER_HOSTNAME:?SERVER_HOSTNAME must be set}"
: "${SITE_ASN:?SITE_ASN must be set}"

A blank SITE_ASN renders router bgp with no number; FRR rejects that in some paths and accepts it into a nothing-advertised state in others. Failing before any write removes the ambiguity.

Third, the rewrite is atomic and counted. The script builds the config into frr.conf.tpl.tmp, counts the ^ network lines it produced, compares that to the number of addresses it parsed (one line per address, exactly), and only then mvs the file into place:

actual_count=$(grep -c '^  network ' "${FRR_TEMPLATE_TMP}" || true)
if [ "${actual_count}" -ne "${expected_count}" ]; then
    cat "${FRR_TEMPLATE_TMP}" >&2
    rm -f "${FRR_TEMPLATE_TMP}"
    exit 1
fi

A truncated write (signal, full disk, anything) otherwise leaves a short template that renders a valid-looking config advertising a subset of the addresses — the same silent failure in a quieter form.

What it cost

Multi-IP support went in on 26 May 2026 as one commit, and every guard above arrived the next day in a second one (harden FRR/CoreDNS pipeline, after a review pass). The pattern itself was borrowed — the same pre-render trick was already running in the GTP proxy deployment, and copying it was most of the design work.

Two weeks later one site went back to a single address (reverting an earlier dual-bind setup), and the deployment config records why in a comment next to the value. The code path did not change: the single-IP case still goes through EXTERNAL_SIGNALLING_IPS with one entry, because a special case for one address is a second code path that only one deployment exercises.