imsd: a re-REGISTER that was sent has used its CSeq, answered or not

A re-REGISTER on the registration's Call-ID (the refresh, a reconnect's,
a resume's) was given the number after the last one that was answered
200: the number was recorded when the 200 came, and only then. So the
REGISTER after one that got no answer, or a refusal, carried that one's
number again. RFC 3261 10.2 has a UA increment the CSeq by one for each
REGISTER with the same Call-ID, and a registrar that took the unanswered
one, its answer lost on the way, has no use for the number a second time
(10.3 step 7: it aborts the update unless the CSeq is higher than the
one it stored).

On the dev phone (KPN, 2026-11-25, a test build with 1.2.4's code at
this place; the fp6 journal's 2026-11-25-refresh-answer-lost capture) a
refresh got no reply: the phone's firewall dropped the network's packets
for 20 s in a test. The reconnect's re-REGISTER, 10 s after the refresh
had failed, was refused "482 Loop Detected", and so was the next one
that reached the network, 66 s later. The recovery then began a fresh
registration and deferred it at a Security-Server with spi-s=0
("fresh-SA throttle active"); the next two re-REGISTERs that reached the
network were answered "480 Temporarily Unavailable" with a Retry-After
of 180, and the phone registered again 25 min 55 s after the refresh had
failed. The journal does not print the number of a REGISTER that fails:
that the two refused with 482 carried the unanswered one's is read from
the code.

The number is now used once the REGISTER is sent (Engine::Reregister,
which all three callers go through), and the state file has it then,
before the answer is waited for: a daemon that dies between a REGISTER
and its answer resumes with the next number, where the file's old one
sent the resume into the same refusal. That write is the one the callers
make after the 200, less the 200's own news. In a resume the file then
also has what the resume made up, which is what the next resume would
make up again. A REGISTER the kernel did not take (the send failed) uses
no number; a refused one's is used like an unanswered one's.

Tested on the workstation: the suites (none of them reaches the change,
which is the shell's), and the daemon of this commit and 1.2.4's against
a stand-in network that keeps the highest CSeq of the protected
REGISTERs it has taken per Call-ID, answers a protected REGISTER that is
not higher 482, and can take one refresh without answering it or refuse
one (the capture's bench/bench-cseq.sh). After a refresh whose answer is
lost this daemon's reconnect sends the next number on the same Call-ID,
is answered 200 and refreshes on; 1.2.4's sends the lost one's number
twice, is refused 482 twice and registers fresh. Killed under the wait
and started again, this daemon resumes with the next number; 1.2.4's
resume is refused 482 and it registers fresh. With either of the
change's two lines taken out the bench says so: without the count both
scenarios fail as 1.2.4 does, without the write the restart's does.
After a refresh the stand-in refuses (503) this daemon's reconnect sends
the next number, and 1.2.4's the refused one's again; the stand-in keeps
no number for a REGISTER it refuses and answers both 200. The stand-in
accepts the fresh registration at once, which KPN did not. And on the
dev phone (KPN, the daemon of this commit; the fp6 journal's
2026-11-25-through-sleep capture, phone/cseqtest-2-a and setup.log),
with the firewall's rule for ESP taken out and the connection tracker's
generic timeout at 0 around a refresh, so that its answer was dropped:
the refresh failed with no reply, the reconnect was answered 200 10 s
later, and the next start resumed from the reconnect's number, one above
the lost one's (that start was of a build with the next commit's change
on this one, in the form it then had, which touches none of this; an
earlier build of this change, with the next two commits' work in
progress on it, in the first capture's phone/, had the next refresh
answered with the number after that). Not run: the number after a
re-REGISTER whose send failed; a re-REGISTER's answer lost over UDP; a
restart after a daemon was told to stop (SIGTERM) under the wait, where
the bench kills it; a resume whose REGISTER gets no answer; a state file
torn by a kill during its write; and what a network makes of a number
that skips one, as a REGISTER that was sent and never arrived leaves it
(the stand-in took one; no phone run tells whether its network saw one).
This commit is contained in:
Jorijn van der Graaf 2026-11-29 14:30:43 +01:00
commit 83a9eb539d
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
2 changed files with 78 additions and 31 deletions

100
AGENTS.md
View file

@ -101,7 +101,9 @@ meanwhile and the routing of our reg-event SUBSCRIBE's final read there, the
12 s wait restarted on a provisional); the reregistration's headers and its 12 s wait restarted on a provisional); the reregistration's headers and its
answer to a challenge (`Reregister`: the stored challenge answer, or the empty answer to a challenge (`Reregister`: the stored challenge answer, or the empty
digest for a pre-0.3.11 state file, the new SPIs, `PortUcNext`; a 401 thrown digest for a pre-0.3.11 state file, the new SPIs, `PortUcNext`; a 401 thrown
as a refusal carrying its status); the state-file round trip as a refusal carrying its status; and, since 1.2.5, the number it takes,
used and written to the state file once the REGISTER is sent, §7.2
step 5 and §5); the state-file round trip
(`PersistState`/`LoadState`: the `security_server` key, written empty for a (`PersistState`/`LoadState`: the `security_server` key, written empty for a
value with a quote, a backslash or a newline — the choice between that list value with a quote, a backslash or a newline — the choice between that list
and the entry rebuilt from the SA is `Imsd:Ipsec`'s, with a test); the and the entry rebuilt from the SA is `Imsd:Ipsec`'s, with a test); the
@ -527,16 +529,9 @@ Rules:
pre-fix build that renewed that closure; the retry on this code, the pre-fix build that renewed that closure; the retry on this code, the
renewal firing, Timer F, the doubling, a SUBSCRIBE `Retry-After`, the renewal firing, Timer F, the doubling, a SUBSCRIBE `Retry-After`, the
renew arm and the back-off's survival across a refresh have run nowhere — renew arm and the back-off's survival across a refresh have run nowhere —
§3, §7.4); a `Retry-After` on a REGISTER has run in the field (one §3, §7.4); a `Dial` bringing a recovery step
report, a screenshot of 2026-10-08, O2, 0.3.10: a refresh's Retry-After
set the next step's time — `in 7 min`, then `in 13 min` — and the
refusals counted; the wait's length went unmeasured, the journal lines
on the screenshot carry no timestamps; KPN's refusals, all 403, carry
none) and a `Dial` bringing a recovery step
forward (imsd-ofonod refuses the `Dial` itself and imsd-dialerd forwards forward (imsd-ofonod refuses the `Dial` itself and imsd-dialerd forwards
it) is pinned in `tests/Engine` only; a 401 to a reregistration (the it) is pinned in `tests/Engine` only;
refreshes KPN accepted were never challenged — consecutive CSeqs on every
bench — and O2 has not run this shape) and
the escalation by one refused refresh that carries a `Retry-After` — the the escalation by one refused refresh that carries a `Retry-After` — the
escalation to a fresh registration is pinned in `tests/Engine` only; a escalation to a fresh registration is pinned in `tests/Engine` only; a
resume echoing a multi-mechanism Security-Server list on the wire (the resume echoing a multi-mechanism Security-Server list on the wire (the
@ -600,30 +595,20 @@ Rules:
a quote, a backslash or a newline — neither KPN's nor O2's list has a quote, a backslash or a newline — neither KPN's nor O2's list has
one; the resume of such a file ran with a hand-edited empty key, one; the resume of such a file ran with a hand-edited empty key,
2026-10-11); a state write of a standing registration after a fresh 2026-10-11); a state write of a standing registration after a fresh
attempt that aborted before its SA setup (`RegState::securityServer`, attempt that had its 401 and aborted before its SA setup
not the attempt's `ss_` — on KPN the old SA's retry after a throttled (`RegState::securityServer`,
attempt is refused 403, the throttled-attempt chain below, so no such not the attempt's `ss_`: since 1.2.5 the write is made when a
write follows here); the window that leaves a state file naming another re-REGISTER is sent, so on KPN it follows the old SA's first retry
after a throttled attempt, which KPN has answered 403, 2026-10-03, and
480, 2026-11-25; no daemon that writes at the send has had a throttled
attempt); the window that leaves a state file naming another
SA pair than the kernel's (a stop or a crash between a fresh attempt's SA pair than the kernel's (a stop or a crash between a fresh attempt's
SA setup and its 200's state write — the check is pinned in `tests/Ipsec` SA setup and its 200's state write — the check is pinned in `tests/Ipsec`
and ran on a hand-edited list, 2026-10-11; the window itself is not and ran on a hand-edited list, 2026-10-11; the window itself is not
staged); a staged); the write-off of the old
refused initial or fresh
REGISTER (403, 5xx) at bring-up or in recovery (KPN has only throttled or
stayed silent — pinned in `tests/Engine` only); the write-off of the old
registration by a recovery's fresh attempt that fails past the SA setup registration by a recovery's fresh attempt that fails past the SA setup
(such attempts are on record only as a bring-up's fatal exit, which does (such attempts are on record only as a bring-up's fatal exit, which does
not pass that arm — pinned in `tests/Engine` only); the escalation by not pass that arm — pinned in `tests/Engine` only); the address moves
two refused refreshes that carry no `Retry-After` (KPN refuses a refresh
only with the 403 that says the registration is gone — pinned in
`tests/Engine` only); of the throttled-attempt chain in recovery (a
throttled fresh attempt, the old SA retried once meanwhile with the stored
binding's Contact and refused 403, the deferred attempt accepted at the
hold's end — run 2026-10-03 on the series as it then stood) the deferred
attempt made by the
same process, since a restart inside the hold made it from the holds file
instead (the same process made it on 2026-09-24, on the build before the
policy's rework); the address moves
writing `old_gone` to the holds file (the move benches predate that writing `old_gone` to the holds file (the move benches predate that
field); a SUBSCRIBE final read inside a REGISTER wait (KPN answers within field); a SUBSCRIBE final read inside a REGISTER wait (KPN answers within
the second); the shell's handling of a NOTIFY that terminates our own the second); the shell's handling of a NOTIFY that terminates our own
@ -645,7 +630,9 @@ Rules:
session, or GNOME Calls' `Answer` through imsd-ofonod's gate (imsd's own session, or GNOME Calls' `Answer` through imsd-ofonod's gate (imsd's own
`Accept` gate has run: refused for an account without a seat session and `Accept` gate has run: refused for an account without a seat session and
for nobody, accepted for root, 2026-10-04); a refused for nobody, accepted for root, 2026-10-04); a refused
final carrying reason headers (KPN's 403s carry none — the rendering is pinned final carrying a `Warning`, a `Reason` or a `Server` header (KPN's 403s
and 482s carried none, its 480s of 2026-11-25 a `Retry-After` and no
other — the rendering of the three is pinned
in `tests/Sip` only); an `AUDIO_USER` pin in imsd's own environment that in `tests/Sip` only); an `AUDIO_USER` pin in imsd's own environment that
names no account (the logind fallback) or an account without a PipeWire names no account (the logind fallback) or an account without a PipeWire
socket (a silent call) — a pin naming an account with one ran, 2026-10-04. socket (a silent call) — a pin naming an account with one ran, 2026-10-04.
@ -1099,6 +1086,35 @@ Rules:
since. The flow was found dead 0.3 s after the repeat went out, the since. The flow was found dead 0.3 s after the repeat went out, the
recovery reconnected and re-registered 0.2 s after that, and the text recovery reconnected and re-registered 0.2 s after that, and the text
ended `failed`, its repeat lost with the flow. ended `failed`, its repeat lost with the flow.
- The CSeq of a re-REGISTER (§7.2 step 5) is the shell's, and no suite
reaches it. On the workstation the daemon ran against a stand-in network
that keeps the highest CSeq of the protected REGISTERs it has taken
per Call-ID, answers a protected REGISTER
that is not higher `482 Loop Detected`, and can take one refresh
without answering it or refuse one (the fp6 journal's
`2026-11-25-refresh-answer-lost`
capture, `bench/bench-cseq.sh`): after a refresh whose answer is lost
the reconnect's re-REGISTER carries the next number and is answered
200, where 1.2.4's carried the lost one's, was refused twice and
registered fresh; a daemon killed under the wait resumes with the next
number, the state file having it, where 1.2.4's resume was refused and
registered fresh; after a refresh the stand-in refused (503) the
reconnect's re-REGISTER carries the next number, where 1.2.4's carried
the refused one's again (the stand-in keeps no number for a REGISTER
it refuses, and answered both 200). On the dev phone (KPN,
2026-11-25, this commit's
daemon; the fp6 journal's `2026-11-25-through-sleep` capture,
`phone/cseqtest-2-a`), with the firewall's rule for ESP taken out and
the connection tracker's generic timeout at 0 around a refresh, so that
its answer was dropped: `keepalive re-REGISTER failed: no reply to
re-REGISTER`, and `reconnected + re-registered` 10 s later. Not run: the
number after a re-REGISTER whose send failed; a re-REGISTER's answer
lost over UDP; a restart after a daemon was told to stop (SIGTERM)
under the wait, where the bench kills it; a resume whose REGISTER gets
no answer; a state file torn by a kill during its write; and what a
network makes of a number that skips one, as a REGISTER that was sent
and never arrived leaves it (the stand-in took one; no phone run tells
whether its network saw one).
- `imsd-pcscf` ran on the dev phone (KPN) on 2026-10-11 against the live ims - `imsd-pcscf` ran on the dev phone (KPN) on 2026-10-11 against the live ims
bearer: the `--mux 1 --profile 2 -v` sequence, a plain run, and `OutOfCall` bearer: the `--mux 1 --profile 2 -v` sequence, a plain run, and `OutOfCall`
on an unbound mux (the fp6 journal's `2026-10-11-pcscf-pco-probe` capture, on an unbound mux (the fp6 journal's `2026-10-11-pcscf-pco-probe` capture,
@ -1385,7 +1401,11 @@ The daemon's own bring-up (`BringUp()` in `main.cpp`):
`tcp_retries2` of 15); until 1.2.3 a ping's were among those bytes `tcp_retries2` of 15); until 1.2.3 a ping's were among those bytes
every 30 s outside a call. The refresh of a every 30 s outside a call. The refresh of a
registration this process made fresh is a reregistration as TS 24.229 registration this process made fresh is a reregistration as TS 24.229
5.1.1.4.2 has it: the same Call-ID and Contact, CSeq+1, the 5.1.1.4.2 has it: the same Call-ID and Contact, the CSeq one above the
last REGISTER sent on that Call-ID, answered or not (RFC 3261 10.2;
the number is used, and in the state file, once the REGISTER is sent:
§13 has KPN's 482 to re-REGISTERs that, by 1.2.4's code, carried an
unanswered one's number), the
Authorization of the last successful authentication verbatim (the 401's Authorization of the last successful authentication verbatim (the 401's
nonce, our cnonce and response, kept in the state file), a nonce, our cnonce and response, kept in the state file), a
Security-Client with new SPIs and a new client port (`PortUcNext`, Security-Client with new SPIs and a new client port (`PortUcNext`,
@ -2959,6 +2979,24 @@ the related code.
21 min is the wait that has never been refused, not a measured minimum; 21 min is the wait that has never been refused, not a measured minimum;
imsd resumes rather than registers fresh wherever it can, since on a live imsd resumes rather than registers fresh wherever it can, since on a live
registration's address the attempt is refused and costs the registration. registration's address the attempt is refused and costs the registration.
- **KPN refused the two re-REGISTERs that followed an unanswered refresh
`482 Loop Detected`, before any fresh attempt, and answered 200 where
the next number was sent** (the dev phone, 2026-11-25; the fp6
journal's `2026-11-25-refresh-answer-lost` capture). A refresh's answer
did not reach the phone, whose firewall dropped the network's packets
for 20 s in a test. The reconnect's re-REGISTER was refused 482 10 s
after the refresh had failed, and the next one that reached the
network 66 s after that. That both carried the unanswered one's number
is read from the code, not seen: it was a test build with 1.2.4's code
at that place, and the journal prints no number for a REGISTER that
fails. The fresh registration that followed met the throttle above
(`spi-s=0`), re-REGISTERs after it were answered `480 Temporarily
Unavailable` with `Retry-After: 180` (by the same reading of the code
they carried the unanswered one's number too: the 482 came only
before the throttled attempt), and the phone registered again
25 min 55 s after the refresh had failed. With the next number, the
reconnect's re-REGISTER after a refresh whose answer was dropped the
same way was answered 200.
- **O2 UK, 2026-09-24:** a refresh refused 21 × 503 over 70 min, then 33 - **O2 UK, 2026-09-24:** a refresh refused 21 × 503 over 70 min, then 33
unanswered reconnect cycles; a fresh registration was accepted in one unanswered reconnect cycles; a fresh registration was accepted in one
second. The origin of `RegRecovery`. On 2026-10-08, under 0.3.10 (the second. The origin of `RegRecovery`. On 2026-10-08, under 0.3.10 (the

View file

@ -2544,6 +2544,15 @@ private:
do spiUs = rng_.UInt(0x10000, 0xFFFFFFF); while (spiUs == reg_.spiUc || spiUs == reg_.spiUs || spiUs == spiUc); do spiUs = rng_.UInt(0x10000, 0xFFFFFFF); while (spiUs == reg_.spiUc || spiUs == reg_.spiUs || spiUs == spiUc);
std::string reg = imsd::msg::BuildRegisterProtected(ctx_, callid, ftag, rng_.Token(16), cseq, spiUc, spiUs, auth, PortUcNext); std::string reg = imsd::msg::BuildRegisterProtected(ctx_, callid, ftag, rng_.Token(16), cseq, spiUc, spiUs, auth, PortUcNext);
if (!sip_.Send(reg)) throw std::runtime_error("send re-REGISTER failed"); if (!sip_.Send(reg)) throw std::runtime_error("send re-REGISTER failed");
// Sent, the number is used, whatever comes back: the next REGISTER
// on this Call-ID carries a higher one (RFC 3261 10.2), where a
// registrar that took this one and whose answer did not arrive
// refuses the same number (10.3 step 7; KPN answered 482 Loop
// Detected where, by 1.2.4's code, two re-REGISTERs carried an
// unanswered refresh's: the dev phone, 2026-11-25). After a restart
// too: the state file has the number before the answer is waited for.
reg_.cseq = cseq;
PersistState(reg_, route_, ppi_, ctx_.aor, ctx_.transport, pcscf_);
std::string m = AwaitFinal(callid, cseq, "re-REGISTER"); std::string m = AwaitFinal(callid, cseq, "re-REGISTER");
auto st = imsd::sip::Status(m); auto st = imsd::sip::Status(m);
if (st == 200) return {m, cseq}; if (st == 200) return {m, cseq};