imsd: no CRLF keepalive on the idle flow unless CRLF_KEEPALIVE names an interval
imsd sent a double CRLF, the ping of RFC 5626 4.4.1, on its idle TCP flow to the P-CSCF every 30 seconds. On a phone that costs far more than four bytes. The modem brings the ims bearer up for it; 11 to 13 s later the bearer goes dormant, which the modem reports to ModemManager, and 90 s after that the modem makes a file-system request to rmtfs. Each of the two can wake a phone that has gone back to sleep: in a loop of suspends on the dev phone (KPN, 2026-11-20, the fp6 journal's 2026-11-20-modem-echo-wakes capture) the modem ended 29 sleeps of 29, 15 with the report and 14 with that request, and none reached its 150-second alarm; with imsd held still all six did. Awake and idle on a USB port the phone's battery lost 140 mA with the ping and 59 mA without it (2026-11-24, one window of 40 min and one of 33). No registration of imsd's negotiates keep-alives: its REGISTER has no "outbound" in Supported and no reg-id (RFC 5626 4.2.1), and no "keep" in the Via (RFC 6223). The ping is now sent only where CRLF_KEEPALIVE=<whole seconds> names an interval. An empty value is as none; any other that is no whole number of seconds is reported in the journal and sends none (imsd::util::WholeSeconds). What a ping does for a flow, outside a call: sent more often than a P-CSCF's timer for a flow it hears nothing on, it keeps that P-CSCF from dropping the flow, and it draws the reset of a P-CSCF that has lost the flow. The setting is for such a network. On the phone the ping also kept the connection tracker's entry for the P-CSCF's ESP, without which the firewall dropped what the network started; the commit before this one gives the firewall a rule for ESP instead. Without the ping, a close by the network is answered, outside a call, with a reconnect and a re-REGISTER. A flow the network has dropped without closing, where it answers the next bytes on it with a reset, is found at those bytes: where they are the refresh's, it fails once and the same reconnect follows; where they are a call's INVITE, the flow is reopened for the call; where they are a call's BYE, the BYE is lost: imsd sends no BYE again, as before. Where they are a text's MESSAGE, it is lost with the flow and the text's wait decides. An incoming call sends no request on the flow before its BYE, and without the ping the flow can have been silent, or dropped without a close, since long before such a call came (AGENTS.md §7.6). A flow that died with no close and no reset reaching the phone is noticed when the refresh's re-REGISTER gets no answer, or sooner where TCP gives up on bytes imsd sent on it before that (924.6 s or more after them by the kernel's default tcp_retries2), and until 1.2.3 a ping's were among those every 30 s outside a call; a bearer that left under a registered daemon was noticed at the refresh under the ping as well (2026-10-02, AGENTS.md §7.2). Tested: the suites, WholeSeconds in tests/Util; the daemon of this commit and 1.2.3's on the workstation against a stand-in network that prints every ping and can close a silent flow or forget it (the fp6 journal's 2026-11-24-crlf-keepalive capture, bench-keepalive.sh: no ping by default, with CRLF_KEEPALIVE=0 or with an empty value, 1.2.3's three in 100 s, the setting's, none over UDP, a value that is no number, the reconnect at each close, the failed refresh and the reconnect on a forgotten flow, neither a close nor a forgotten flow under the setting or under 1.2.3's pings, a ping of 1.2.3's reset on a forgotten flow; and bench-hangup.sh of the 2026-11-24-bye-resend capture: a placed call's BYE not delivered where the network had forgotten or closed the flow under the call, by this daemon as by 1.2.3's on the forgetting one). On the dev phone on KPN, the binary of the range's tip: no packet on the ims netdev in two idle minutes where 1.2.3 put one each way every 30 s, the setting's start line and its pings, the line for a value that is no number. And there, with builds of this change from before the commit of the call's resend was put under it: the refresh after 1800 awake seconds answered on the flow, silent until then, twice; and two loops of suspends with no packet on the netdev, of six sleeps, none ended by the modem, and of seven, one ended by it, for a file-system request no packet had preceded (with the pings and the same ModemManager the modem ended 5 of 8 on 2026-11-20). No network that closes or forgets an idle flow has been met.
This commit is contained in:
parent
bc0e70a17f
commit
c93df591f1
5 changed files with 227 additions and 37 deletions
|
|
@ -1512,6 +1512,16 @@ public:
|
|||
sipPolicy_ = "auto";
|
||||
}
|
||||
transport_ = sipPolicy_ == "udp" ? Transport::Udp : Transport::Tcp;
|
||||
// CRLF_KEEPALIVE=<seconds>: an RFC 5626 4.4.1 ping that often on the
|
||||
// idle TCP flow, for a P-CSCF that drops a flow it hears nothing on.
|
||||
// None by default (until 1.2.3: one every 30 s): no registration of
|
||||
// imsd's negotiates them, and a ping can wake a suspended phone
|
||||
// afterwards (AGENTS.md §13). An empty value is as none; any other
|
||||
// that is no whole number of seconds is reported and sends none.
|
||||
if (std::string v = EnvOr("CRLF_KEEPALIVE", ""); !v.empty()) {
|
||||
if (auto s = imsd::util::WholeSeconds(v)) crlfKeepalive_ = *s;
|
||||
else Log(std::format("CRLF_KEEPALIVE={} is not a whole number of seconds; no CRLF keepalive", v));
|
||||
}
|
||||
mediaBin_ = ResolveMediaBin();
|
||||
// CODECS: restrict + reorder the codecs we offer and accept (bench
|
||||
// knob — a gateway that transcodes every caller up to AMR-WB never
|
||||
|
|
@ -1670,7 +1680,7 @@ public:
|
|||
MaybeReconnect();
|
||||
MaybeResubscribe();
|
||||
MaybeResendInvite();
|
||||
if (!call_ && sip_.Alive() && Mono() - lastKa_ > 30) { sip_.SendKeepalive(); lastKa_ = Mono(); }
|
||||
if (crlfKeepalive_ > 0 && !call_ && sip_.Alive() && Mono() - lastKa_ > crlfKeepalive_) { sip_.SendKeepalive(); lastKa_ = Mono(); }
|
||||
ReapMedia();
|
||||
if (call_ && call_->State() != imsd::engine::CallState::Active && Mono() > deadline_) {
|
||||
Execute(call_->OnDeadline());
|
||||
|
|
@ -1773,6 +1783,7 @@ private:
|
|||
|
||||
// config
|
||||
std::string pcscf_, dev_, outDir_, local_, mediaBin_;
|
||||
long crlfKeepalive_ = 0; // CRLF_KEEPALIVE=: seconds between pings on the idle TCP flow; 0: none
|
||||
std::vector<std::string> ealgOffer_; // the ESP ciphers offered, in order
|
||||
// The P-CSCF a fresh registration goes to (PCSCF=, else the first of
|
||||
// PCSCF_DISCOVERED=) and the whole discovered list. pcscf_ is the one in
|
||||
|
|
@ -1935,6 +1946,7 @@ private:
|
|||
ctx_.ealgOffer = ealgOffer_;
|
||||
SetTransport(transport_);
|
||||
Log(std::format("SIP transport: {} ({})", TransportName(transport_), sipPolicy_));
|
||||
if (crlfKeepalive_ > 0) Log(std::format("CRLF keepalive: every {} s on an idle TCP flow (CRLF_KEEPALIVE)", crlfKeepalive_));
|
||||
{
|
||||
std::string list;
|
||||
for (const std::string& e : ealgOffer_) list += (list.empty() ? "" : ", ") + e;
|
||||
|
|
@ -2660,8 +2672,8 @@ private:
|
|||
}
|
||||
|
||||
// The protected client flow can die under us while the SA and the
|
||||
// registration stay valid — a CSFB excursion resets it, the P-CSCF drops
|
||||
// idle flows — which is exactly the state a daemon restart resumes from
|
||||
// registration stay valid — a CSFB excursion resets it, a P-CSCF may drop
|
||||
// an idle flow — which is exactly the state a daemon restart resumes from
|
||||
// (s51: "restart-to-recover"). Do what the restart does, in place:
|
||||
// reconnect the TCP leg over the existing SA and true-refresh. When that
|
||||
// keeps failing — the network refuses the refresh, or nothing answers —
|
||||
|
|
|
|||
Loading…
Reference in a new issue