Four changes to an IMS I did not write

Most of the CSCF logic in this repository is upstream Kamailio adapted by colleagues; this is an account of the four parts that are mine.

Telecom

The repository holds a VoLTE IMS core — a P-CSCF, an I-CSCF and an S-CSCF in one container, plus a DNS service and a MySQL image — built from a fork of Kamailio's IMS modules (5.6, 24 modules in the include list). It is worth being exact about authorship before anything else. Of 144 commits on main, one colleague has 100 and another 18; mine are 19, and almost all of those sit outside the call-handling paths. The registration flow, the Cx/Dx Diameter wiring, the memory tuning (shared memory 1 GB to 4 GB) and the folding of five included route files back into the main config are someone else's work.

Describing how an IMS registration works is explanation. Claiming to have designed it would be a lie, and the standard is 3GPP's anyway. What follows is the four things I actually changed.

Metrics that were stuck behind an ifdef

Kamailio exports Prometheus metrics through xhttp_prom, and none of the three CSCFs could. Two reasons, in the order they surfaced: xhttp and xhttp_prom were absent from the Dockerfile's include_modules list, so neither module was ever compiled; and loadmodule "xhttp.so" sat inside #!ifdef WITH_WEBSOCKET, which is off. Two names added to a build argument, one line moved out of a conditional (CW-2805, 27 October 2025).

Each CSCF then got one event route and a dedicated port (8081 for P, 8082 for S, 8083 for I, each overridable by env var):

event_route[xhttp:request] {
    if ($Rp != 8081) {
        xhttp_reply("404", "Not Found", "text/plain", "");
        exit;
    }
    if (prom_check_uri()) { prom_dispatch(); }
    else { xhttp_reply("404", "Not Found", "text/plain", ""); }
}

The guard on $Rp matters: an event route fires for any HTTP request the proxy accepts, so without the port check the SIP listeners would serve /metrics too. The detail that made it work at all is tcp_accept_no_cl=yes, set for all three (P, S and I) — a scraper's GET carries no Content-Length, and Kamailio drops such a request over TCP by default.

IPsec without the knob that does it

GSMA IR.92 wants integrity protection on the Gm interface, with encryption optional. Integrity-only is selected in ims_ipsec_pcscf through ipsec_preferred_alg and ipsec_preferred_ealg, and those parameters arrived in Kamailio 5.7. This build is 5.6, so both sit in the config commented out, with the version note beside them. Nothing in CW-2840 configures a null cipher, and nothing could have.

The failure path was the worse problem anyway. The register route answered 503 Service Unavailable (Create ipsec failed) whenever ipsec_create("location") returned anything but 1 — so one handset that could not negotiate a tunnel got no service at all, unprotected service included. Now the failure is logged, stamped into a table ($sht(ipsec_failures=>$fu) = $Ts, size 8, autoexpire 3600 seconds), and the registration continues.

Two more holes closed with it. ipsec_forward("location") is now called only when that contact actually appears in ipsec_clients, instead of unconditionally. And a de-registration — $(T_req($expires(min))) == 0 — calls ipsec_destroy("location") and clears the failure stamp, so a tunnel does not outlive the registration that created it.

A guard that matched an address, not a host

The S-CSCF normalises the Request-URI and To header on initial INVITEs from the telephony engine, under a four-part guard. One part read $rd == CONTAINER_IP, and $rd is the Request-URI's domain. So the transform ran when the engine addressed the S-CSCF by literal address and silently did nothing when it used the service's FQDN — the INVITE went through unnormalised, carrying a domain outside the home realm. The fix (CW-2834) is one alternation added to the guard. Two lines changed, one of them a log message.

The DNS the CSCFs ask

3GPP naming is mechanical: pcscf.ims.mnc<2-3 digits>.mcc<3 digits>.3gppnetwork.org, the same for icscf, scscf and hss, plus an EPC tree beside it. Under BIND each MNC/MCC pair needed its own named.conf stanza and zone file. CW-2801 replaced BIND with CoreDNS 1.11.1 (pinned, no local patches) and made the common case a regex instead, with the MNC and MCC capture groups reused in both the answer and the SRV additional section.

Specific pairs still get real override zone files; the wildcard handles the rest. The last three blocks of the Corefile are the part worth copying — valid 3GPP names fall through to be answered, anything matching 3gpp that is malformed returns SERVFAIL, and everything else returns NXDOMAIN. A malformed realm and an absent realm are different faults (one is a provisioning bug, the other a typo), and a resolver that answers NXDOMAIN to both hides the first.

Two things bit on the way. The zone files are rendered with envsubst, which eats $ORIGIN and $TTL because they look like shell variables; the templates now carry __ORIGIN__ and __TTL__, and the entrypoint pipes envsubst through two sed calls (one per directive) to put them back. And the SOA record has to be on one line for CoreDNS, which BIND never required.

Forwarding took two tries in one day. The first templated a four-nameserver /etc/resolv.conf into the IMS container (embedded Docker resolver, DNS container, two corporate resolvers). Five hours later it was commented out, and the same forwarding went into the DNS container's Corefile as three stub zones (cache 30, prometheus :9153). Wrong layer: the CSCFs already resolve through that container, so what else resolves is its business, not theirs.