messages, imsd: P-Access-Network-Info in responses and in requests within a dialog
imsd named the serving cell in its REGISTERs, the reg-event SUBSCRIBE, an INVITE and a MESSAGE. TS 24.229 5.1.2A.1.1 and 5.1.2A.2 have a UE insert the header into a request within a dialog as well, and into a response within a dialog, to a request for a dialog and to a standalone method: not into a CANCEL nor into a response to one, and into an ACK at its choice. A PRACK and a BYE carry it now, and every response imsd builds but a 100 Trying, the 200 to a CANCEL and the transport's 400 to a request cut short. The server ports (the protected ports' TCP listeners and UDP sockets) take a request from any source (AGENTS.md §12), and the header is the phone's cell. What they send in answer keeps it only on the two paths of the SA pair the shell has on record, and loses it anywhere else. Tested: the suites, and the daemon of this commit on the workstation against a stand-in network that asks it from both sides of those paths (the fp6 journal's 2026-12-04-pani-in-dialog capture, bench/), and on the dev phone on KPN, where its answers to a text's two requests and a call's 180 and 200 carried the header inside the SA pair (the journal's 2026-12-04-imsd-1.2.7-range-on-dev-phone capture).
This commit is contained in:
parent
6d05aaed0d
commit
a65724a252
11 changed files with 460 additions and 38 deletions
|
|
@ -753,6 +753,15 @@ struct Inbound {
|
|||
|
||||
class ServerPorts {
|
||||
public:
|
||||
// Whether a packet from `own` to `peer` runs on a path of the SA pair:
|
||||
// the shell answers, from its record of the pair (Engine::InsideSa).
|
||||
// These ports take a request from any source (AGENTS.md §12); an
|
||||
// answer they send that runs on neither path goes without
|
||||
// P-Access-Network-Info, which names the serving cell (RFC 7315 4.4.2:
|
||||
// a UA inserts it into what "is going to be securely sent" to its
|
||||
// proxy).
|
||||
void SetInsideSa(std::function<bool(const sockaddr_storage&, const sockaddr_storage&)> f) { insideSa_ = std::move(f); }
|
||||
|
||||
void Open(const std::string& local) {
|
||||
int fam = Is6(local) ? AF_INET6 : AF_INET;
|
||||
for (int port : {PortUc, PortUs}) {
|
||||
|
|
@ -859,7 +868,8 @@ public:
|
|||
auto reply = [this, uc = rs == udpUc_, s, sll](const std::string& r) mutable {
|
||||
const int from = uc ? udpUc_ : udpUs_;
|
||||
if (from < 0) return;
|
||||
sendto(from, r.data(), r.size(), 0, reinterpret_cast<sockaddr*>(&s), sll);
|
||||
const std::string o = Leaving(r, NameOf(from), s);
|
||||
sendto(from, o.data(), o.size(), 0, reinterpret_cast<sockaddr*>(&s), sll);
|
||||
};
|
||||
if (cutShort) {
|
||||
Log(std::format("UDP: {} on server socket {} — answered 400", why, us == udpUc_ ? PortUc : PortUs));
|
||||
|
|
@ -892,7 +902,8 @@ public:
|
|||
out.push_back({*m, [this, port = it->port, peer = it->peer](const std::string& r) {
|
||||
const Conn* c = Find(port, peer);
|
||||
if (!c) { Gone(port, peer); return; }
|
||||
(void)!write(c->fd, r.data(), r.size());
|
||||
const std::string o = Leaving(r, NameOf(c->fd), c->peer);
|
||||
(void)!write(c->fd, o.data(), o.size());
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
|
@ -923,6 +934,18 @@ private:
|
|||
return found;
|
||||
}
|
||||
|
||||
// `r` as it leaves from `own` to `peer` (SetInsideSa).
|
||||
std::string Leaving(const std::string& r, const sockaddr_storage& own, const sockaddr_storage& peer) {
|
||||
if (insideSa_ && insideSa_(own, peer)) return r;
|
||||
std::string bare = imsd::sip::WithoutHeader(r, "P-Access-Network-Info");
|
||||
if (bare.size() != r.size() && !saidOutside_) {
|
||||
saidOutside_ = true;
|
||||
Log(std::format("an answer from port {} to {} is on neither path of the SA pair on record: it goes without P-Access-Network-Info, as every such answer does (said once)", PortOf(own),
|
||||
imsd::util::HostPort(HostOf(peer), PortOf(peer))));
|
||||
}
|
||||
return bare;
|
||||
}
|
||||
|
||||
// An answer with no connection to go out on.
|
||||
void Gone(int port, const sockaddr_storage& peer) {
|
||||
if (!saidClosed_) Log(std::format("an answer from port {} to {} is not sent: no connection from that peer to that port is held (said once)", port,
|
||||
|
|
@ -930,6 +953,8 @@ private:
|
|||
saidClosed_ = true;
|
||||
}
|
||||
|
||||
std::function<bool(const sockaddr_storage&, const sockaddr_storage&)> insideSa_;
|
||||
bool saidOutside_ = false;
|
||||
bool saidClosed_ = false;
|
||||
int udpUc_ = -1, udpUs_ = -1;
|
||||
std::vector<int> listeners_, udp_;
|
||||
|
|
@ -1817,6 +1842,7 @@ public:
|
|||
return;
|
||||
}
|
||||
}
|
||||
server_.SetInsideSa([this](const sockaddr_storage& own, const sockaddr_storage& peer) { return InsideSa(own, peer); });
|
||||
try { server_.Open(local_); }
|
||||
catch (...) { Log("server ports unavailable; remote hangup/incoming not seen"); }
|
||||
OnRegistered();
|
||||
|
|
@ -2019,6 +2045,7 @@ private:
|
|||
double subRenewAt_ = 0; // the live subscription is subscribed anew at this time on the boot clock, ahead of its granted expiry (0: none)
|
||||
double subRetryDelay_ = 60; // 60 s doubling to 10 min between failed SUBSCRIBEs
|
||||
int portPs_ = 0; // P-CSCF protected server port (reconnect target)
|
||||
imsd::ipsec::SaPaths saPaths_; // the SA pair this run set up without an error or resumed, until it takes that pair out of the kernel: what InsideSa judges by
|
||||
imsd::engine::RegRecovery recovery_; // what to do when the registration stops working
|
||||
bool saReplaced_ = false; // the running fresh attempt got past the SA setup (the old registration's SAs are gone)
|
||||
|
||||
|
|
@ -2220,6 +2247,14 @@ private:
|
|||
return "/usr/libexec/imsd-media";
|
||||
}
|
||||
|
||||
// Whether a packet from `own` to `peer` runs on one of the two paths of
|
||||
// the SA pair on record (imsd::ipsec::OnSaPath). The record is the
|
||||
// shell's own: of the pair it set up without an error or read back from
|
||||
// the kernel's tables at a resume. It does not ask the kernel again.
|
||||
bool InsideSa(const sockaddr_storage& own, const sockaddr_storage& peer) const {
|
||||
return imsd::ipsec::OnSaPath(saPaths_, HostOf(own), PortOf(own), HostOf(peer), PortOf(peer));
|
||||
}
|
||||
|
||||
// Refresh P-Access-Network-Info from the live serving cell (mmcli 3GPP
|
||||
// location). Serving cell changes as the phone moves, so this runs
|
||||
// before every REGISTER/INVITE-carrying step; on failure the previous
|
||||
|
|
@ -2355,7 +2390,7 @@ private:
|
|||
// P-CSCF and nothing is configured, a fact until a boot or a
|
||||
// start. A discovery that FAILED (the reader did not answer) is
|
||||
// no fact: the fatal, and the restart runs it again.
|
||||
if (outcome == ResumeOutcome::Dead) { recovery_.OldGone(); RemoveDeadPair(pdnLocal_); }
|
||||
if (outcome == ResumeOutcome::Dead) { recovery_.OldGone(); RemoveDeadPair(pdnLocal_); saPaths_ = {}; }
|
||||
KeepHolds();
|
||||
if (outcome == ResumeOutcome::Failed || DiscoveryFailed()) throw std::runtime_error(std::string(NoFreshPcscf));
|
||||
RequestIdle(std::string(NoPcscfIdleText)); throw Stopping{};
|
||||
|
|
@ -2501,6 +2536,7 @@ private:
|
|||
Log(std::format("RESUME via existing SA (cseq {})", ps->cseq.value_or(1)));
|
||||
|
||||
portPs_ = sa->portPs;
|
||||
saPaths_ = {local_, pcscf_, sa->portPs, sa->portPc};
|
||||
SetTransport(t);
|
||||
// Local refusals (TIME_WAIT after a restart) keep retrying; two
|
||||
// silences mean the flow is not coming back — fresh instead.
|
||||
|
|
@ -2668,16 +2704,19 @@ private:
|
|||
sp.ealg = ealg;
|
||||
// imsd's previous pair out first, each entry by its key — not `ip xfrm …
|
||||
// flush`: another IPsec user's entries (a policy-based VPN's) stay (§12)
|
||||
saPaths_ = {};
|
||||
{
|
||||
auto state = RunCapture({"ip", "xfrm", "state"});
|
||||
auto policy = RunCapture({"ip", "xfrm", "policy"});
|
||||
RunOwnXfrmDeletes(imsd::ipsec::OwnXfrmDeleteCommands(state.out, policy.out, local_));
|
||||
}
|
||||
saReplaced_ = true; // from here on the old registration's SAs are gone
|
||||
bool installed = true;
|
||||
for (auto& cmd : imsd::ipsec::BuildSetupCommands(sp)) {
|
||||
int rc = RunCmd(cmd);
|
||||
if (rc != 0) Log(std::format("{} -> rc {}", RedactKeys(cmd), rc));
|
||||
if (rc != 0) { Log(std::format("{} -> rc {}", RedactKeys(cmd), rc)); installed = false; }
|
||||
}
|
||||
if (installed) saPaths_ = {local_, pcscf_, portPs, portPc};
|
||||
|
||||
ctx_.securityServer = ss_;
|
||||
portPs_ = portPs;
|
||||
|
|
|
|||
Loading…
Reference in a new issue