sip: a header is found under its compact form, and with white space before the colon
RFC 3261 7.3.3 lets a sender write a header name in its one-letter form at any time and has every implementation accept both forms. The text layer matched the long name only, so to every reader a header sent in compact form was absent: the TCP framer took no body length from `l:` and read the body as the start of the next message, a response with `i:` matched no transaction and a request no call, the finals imsd builds left out a Via, From, To or Call-ID that came in compact form, and a short message whose content type came as `c:` was answered 200 and logged instead of taken (issue #2). MatchHeaderLine now takes a line under the name it is asked for or under that name's compact form: the ten RFC 3261 defines, and `o` for Event (RFC 6665) and `x` for Session-Expires (RFC 4028), the two extension headers imsd reads that have one. Every reader goes through it — Header, Headers, the framer, DatagramMessage — so no reader changes for it. It also takes white space between the name and the colon, which the same grammar allows (25.1's HCOLON; 7.3.1's "Subject : lunch") and the matcher refused. A value folded onto further lines is still read by its first line. One reader is changed for the rows it is now handed. ViaResponsePort gives the port the top Via names, to which the answer to a request that came in a datagram on a server port goes (RFC 3261 18.2.2), and none where that Via carries `rport` (RFC 3581): the answer then goes back to the port the request came from. It took `rport` for present where those five letters, in lower case, stood anywhere behind the row's first semicolon. Parameter names are case-insensitive (7.3.1), and a request whose top Via came as `v: …;RPORT`, a row 1.2.0 passed over, would have been answered to the port that Via names, its `rport` not seen. ViaResponsePort now reads the Via's parameters one by one, each to the next semicolon outside a quoted string, and `rport` is one by its name, in any case: not those letters in a value or in a longer name. Read so, the last parameter of the top value would run on into the next value where a row holds a list — `rport, SIP/2.0/UDP …` is no `rport`, and 1.2.0's search of the letters found it —, so the top value is cut from the row first, at the first comma outside a quoted string. With that cut a lower value's `rport` no longer counts for the top one's, as it did in 1.2.0 for a list on one line. Tested by the suites: tests/Sip pins each of the twelve forms through Header, in lower and in upper case, and through Headers, `l:` through the framer and DatagramMessage, 7.3.1's four spellings of the colon, and ViaResponsePort's reading of a Via row, `rport` by its name and of a list on one line the top value alone; tests/Engine drives an incoming call from an INVITE in compact form, an outgoing call from responses in compact form and a delivered MESSAGE in compact form through the reducers; tests/Messages builds BuildResponse, BuildResponse200 and BuildInviteResponse for a request in compact form. On the workstation's loopback (the fp6 journal's 2026-11-20-issues-2-5 capture, server-ports, at this commit and at the one before) a request on a server port whose Via row is a list on one line with `rport` on its lower value is answered from the client-port socket, the way to the port its top value names, where the commit before answered it from the socket it had come on. On the dev phone the binary of this range's last commit answered a MESSAGE the phone sent to its own protected server port from the client-port socket where its Via row was such a list, and from the socket it had come on where its one Via came as `v: …;RPORT` (the capture's phone-form6, inject-bench.log).
This commit is contained in:
parent
5c1fca12b9
commit
1267fe1ada
6 changed files with 367 additions and 48 deletions
51
AGENTS.md
51
AGENTS.md
|
|
@ -41,13 +41,13 @@ PipeWire. The verified device/carrier combinations are in the README.
|
|||
| `project.cpp` | The canonical build description, for [Crafter Build](https://forgejo.catcrafts.net/Catcrafts/Crafter.Build). Chooses the product by `--product=`. |
|
||||
| `interfaces/Imsd.cppm` | The primary module interface of `imsd-core`: `export import`s the nine partitions below. |
|
||||
| `interfaces/Imsd-Util.cppm` | `imsd::util` — SIP tokens, IPv6 host/port formatting, the RFC 5952 §4 IPv6 text (`CanonicalIp6`/`CanonicalAddr`; an IPv4-mapped address spelled in hex stays hex, where §5 and `inet_ntop` write it dotted) and the comma-separated address-list parser (`ParseAddressList`), hex/base64, MD5 (RFC 1321), the fixed protected ports `PortUc`/`PortUs` (45061/45062). |
|
||||
| `interfaces/Imsd-Sip.cppm` | `imsd::sip` — SIP as a text layer plus TCP framing: header extraction (from the header section only: a read ends at the first empty line after the start line, empty lines before it skipped; `HeaderUri`: the party a header names; `Body`, moved here out of `CallMachine`), status codes, the granted lifetime, `ResponseOf` transaction matching. Not a full RFC 3261 parser, deliberately. |
|
||||
| `interfaces/Imsd-Sip.cppm` | `imsd::sip` — SIP as a text layer plus TCP framing: header extraction (from the header section only: a read ends at the first empty line after the start line, empty lines before it skipped; a header is asked for by its long name and found under that or its compact form — RFC 3261 7.3.3: the RFC's ten, and `o` for Event and `x` for Session-Expires — with or without white space before the colon; `HeaderUri`: the party a header names; `Body`, moved here out of `CallMachine`), status codes, the granted lifetime, `ResponseOf` transaction matching. Not a full RFC 3261 parser, deliberately. |
|
||||
| `interfaces/Imsd-Sdp.cppm` | `imsd::sdp` — SDP offer/answer: the AMR-WB + AMR + telephone-event offer (optional IR.92 preconditions; `OfferedTelephoneEventPt` names its telephone-event numbers), the parser the media plane needs (the codec, its payload type and mode, and the telephone-event payload type the m-line lists at that codec's clock), `BuildAnswer` for the terminating side, the `CODECS` override. |
|
||||
| `interfaces/Imsd-Sms.cppm` | `imsd::sms` — the short message codecs SMS over IP rides on (TS 24.341 carries the bytes a 2G/3G phone puts in an RP-DATA, in a SIP MESSAGE body): the GSM 7-bit default alphabet with its extension table and the septet packing, UCS-2 (TS 23.038); the SM-TL PDUs (TS 23.040: SMS-SUBMIT built, one per segment with the concatenation header when the text needs more than one; SMS-DELIVER, SMS-STATUS-REPORT and SMS-SUBMIT-REPORT parsed; the SMS-DELIVER-REPORT that acknowledges a delivery; the user-data header — concatenation, application ports — and the `Reassembler` of a concatenated message); the SM-RL messages (TS 24.011: RP-DATA, RP-ACK, RP-ERROR in both directions, the cause values); EF_SMSP (TS 31.102 §4.2.27), where the (U)SIM names the service centre, and qmicli's hex dump of it. Byte-level only: no SIP, no clock, no I/O. |
|
||||
| `interfaces/Imsd-Aka.cppm` | `imsd::aka` — USIM AKA glue: the AKAv1-MD5 digest (RFC 3310), IMPI/IMPU/realm from IMSI + MCC/MNC, parsers for `qmicli --uim-get-card-status` and `mmcli` output, the AUTHENTICATE APDU and its response. |
|
||||
| `interfaces/Imsd-Ipsec.cppm` | `imsd::ipsec` — the two ESP SA pairs (TS 33.203) as `ip xfrm` argv lists, the Security-Server mechanism selection, and the reader that reconstructs SPIs/ports from `ip xfrm state`/`policy` text for a warm resume, and (1.0.0) `SaPeer`, the P-CSCF the kernel's pair is to, read from the `dir out` policies that carry imsd's fingerprint, `OwnXfrmDeleteCommands`, the deletes by exact key of what two rules select — the policies carrying imsd's fingerprint and the reqid-1/2 transport-mode ESP states in their direction or on the UE's ims-PDN address, whoever installed them (§12), and `FileNamesAnotherPair`, whether a state file's `spi_uc`/`spi_us` name the kernel's pair (unknown on either side decides nothing). |
|
||||
| `interfaces/Imsd-Messages.cppm` | `imsd::msg` — every SIP request and response imsd sends, built from an explicit `Context` and per-request variables so the builders are pure functions; `tests/Messages` is their suite, which calls every builder but `BuildInviteResponse` (`tests/Engine` checks the responses `CallMachine` builds with it). Also `IsEmergency`. Since 1.2.0 the SIP MESSAGE of SMS over IP (`BuildMessageSms`: an RP-DATA to the service centre's PSI, or an RP-ACK/RP-ERROR to the IP-SM-GW with In-Reply-To — TS 24.341 5.3.1.2 and 5.3.2.4), the `+g.3gpp.smsip` Contact tag behind `Context::smsOverIp`, `BuildResponse`, the final for an inbound MESSAGE outside a call's dialog (the 200, the 480, the 488): each `Via:` line echoed in order (the text layer reads long header names only, not RFC 3261 7.3.3's compact forms) and the To echoed with a tag added unless it already holds `tag=` (RFC 3261 8.2.6.2); in-dialog requests, a MESSAGE among them, and the shell's answers to any other request outside a call — a NOTIFY, an OPTIONS, a method it does not handle; not an INVITE, whose 486 while a call exists is `BuildInviteResponse`'s — keep `BuildResponse200`'s hop-by-hop shape; and `ScPsi`, the service centre's PSI from its international number — never a dialled-number guess. |
|
||||
| `interfaces/Imsd-Engine.cppm` | `imsd::engine` — the decisions as pure reducers: `CallMachine` (one call's dialog, returning `Action`s for the shell), `RegRecovery` (the registration recovery policy, §7.4) and, since 1.2.0, SMS over IP (§7.9): `SmsOutbound` (one short message of ours on its way to the service centre, segment by segment, returning `SmsAction`s) and `OnSmsMessage` (what an inbound MESSAGE outside a call's dialog leads to: its final, the message or status report it delivered, the delivery report to send), and `RecentTransactions` (an inbound request's retransmission — the same Call-ID, CSeq and Via branch within 32 s (`TimerJ`), the branch being the value of the first `branch=` of its first `Via:` line and a request with none or an empty one never matched — answered with the same final and not handled again); `SameRecipient` and `StatusReportBook`, a status report's match to the message that asked for one — TP-MR and recipient — and its word for the whole message, with `SmsWordOrder`, the order of a message's words: the submission's first, a report's held until then (§7.9); `RunToken`, `SentSmsId` and `ReceivedSmsId`, the ids (§8.4); `StoredSms` with `FormatStoredSms`/`ParseStoredSms`, the record codec of the received-message store, and `StoredSmsBefore`, `List`'s order. |
|
||||
| `interfaces/Imsd-Messages.cppm` | `imsd::msg` — every SIP request and response imsd sends, built from an explicit `Context` and per-request variables so the builders are pure functions; `tests/Messages` is their suite. Also `IsEmergency`. Since 1.2.0 the SIP MESSAGE of SMS over IP (`BuildMessageSms`: an RP-DATA to the service centre's PSI, or an RP-ACK/RP-ERROR to the IP-SM-GW with In-Reply-To — TS 24.341 5.3.1.2 and 5.3.2.4), the `+g.3gpp.smsip` Contact tag behind `Context::smsOverIp`, `BuildResponse`, the final for an inbound MESSAGE outside a call's dialog (the 200, the 480, the 488): each Via row echoed in order and the To echoed with a tag added unless it already holds `tag=` (RFC 3261 8.2.6.2); in-dialog requests, a MESSAGE among them, and the shell's answers to any other request outside a call — a NOTIFY, an OPTIONS, a method it does not handle; not an INVITE, whose 486 while a call exists is `BuildInviteResponse`'s — keep `BuildResponse200`'s hop-by-hop shape; and `ScPsi`, the service centre's PSI from its international number — never a dialled-number guess. |
|
||||
| `interfaces/Imsd-Engine.cppm` | `imsd::engine` — the decisions as pure reducers: `CallMachine` (one call's dialog, returning `Action`s for the shell), `RegRecovery` (the registration recovery policy, §7.4) and, since 1.2.0, SMS over IP (§7.9): `SmsOutbound` (one short message of ours on its way to the service centre, segment by segment, returning `SmsAction`s) and `OnSmsMessage` (what an inbound MESSAGE outside a call's dialog leads to: its final, the message or status report it delivered, the delivery report to send), and `RecentTransactions` (an inbound request's retransmission — the same Call-ID, CSeq and Via branch within 32 s (`TimerJ`), the branch being the value of the first `branch=` of its first Via row and a request with none or an empty one never matched — answered with the same final and not handled again); `SameRecipient` and `StatusReportBook`, a status report's match to the message that asked for one — TP-MR and recipient — and its word for the whole message, with `SmsWordOrder`, the order of a message's words: the submission's first, a report's held until then (§7.9); `RunToken`, `SentSmsId` and `ReceivedSmsId`, the ids (§8.4); `StoredSms` with `FormatStoredSms`/`ParseStoredSms`, the record codec of the received-message store, and `StoredSmsBefore`, `List`'s order. |
|
||||
| `interfaces/Imsd-Qmi.cppm` | `imsd::qmi` — the QMI WDS request bytes `imsd-pcscf` sends (Bind Mux Data Port, Set IP Family, Get Packet Service Status, Get Current Settings, Get Profile Settings), the message/TLV parser, the P-CSCF list readers (0x22 flag, 0x23 IPv4, 0x24 FQDN, 0x2E IPv6 — the last one libqmi does not model). |
|
||||
| `interfaces/ImsdBus.cppm` | `imsd::bus` — the polkit gate in front of call control and messaging (`Gated`'s `Action` parameter names the action), shared by imsd and imsd-ofonod. GLib, so outside `imsd-core`. |
|
||||
| `implementations/main.cpp` | The `imsd` daemon shell: GLib main loop, GDBus service, sockets, subprocesses, the registration sequence and the run loop that pumps the core. |
|
||||
|
|
@ -280,15 +280,31 @@ What the suites pin:
|
|||
- `Messages` — the outgoing SIP messages: the initial and the protected
|
||||
REGISTER, the reg-event SUBSCRIBE and the INVITEs byte-for-byte, their
|
||||
variants, the in-dialog requests, the ACKs, the CANCEL and
|
||||
`BuildResponse200` by their lines, `BuildInviteResponse` not there
|
||||
(`tests/Engine` checks the responses `CallMachine` builds with it); the
|
||||
`BuildResponse200` by their lines, `BuildInviteResponse` by the lines of
|
||||
one 180 and by a 486 without a Record-Route (`tests/Engine` checks the
|
||||
responses `CallMachine` builds with it); the
|
||||
SMS over IP shapes (the
|
||||
`+g.3gpp.smsip` tag, the MESSAGE with an RP-DATA, the delivery report
|
||||
with In-Reply-To, a 488) pinned against TS 24.341's clauses.
|
||||
with In-Reply-To, a 488) pinned against TS 24.341's clauses; `BuildResponse`,
|
||||
`BuildResponse200` and `BuildInviteResponse` on a request whose header
|
||||
names come in compact form.
|
||||
- `Sip` — the text layer's edge cases (empty header values, line anchoring,
|
||||
keepalive discards, a header read that stops at the first empty line — a
|
||||
body line spelling a header name picks nothing, leading empty lines are
|
||||
skipped), `ResponseOf`, refused finals with reason headers,
|
||||
skipped), the twelve compact forms (each through `Header`, in lower and
|
||||
in upper case, and through `Headers`; no other letter taken for a
|
||||
header name the suite lists; `l:` through the framer and
|
||||
`DatagramMessage`), `ViaResponsePort`'s reading of a Via row — `rport` by its name (in
|
||||
another case, with white space around it, with a value; those letters
|
||||
in a value, in a longer name or in a quoted string not; a quoted string
|
||||
ended by its closing quote — not by a quoted pair in it, and by the
|
||||
quote behind an escaped backslash —), and of a row that holds a list
|
||||
the top value alone (its port, a later value's `rport` and port not
|
||||
counted, its own `rport` counted, last before the comma too; a comma
|
||||
in a quoted string no end of it, the comma behind the closing quote
|
||||
its end) —, white space before the colon (RFC 3261 7.3.1's four
|
||||
spellings),
|
||||
`ResponseOf`, refused finals with reason headers,
|
||||
reginfo documents, `HeaderUri` and `Body`. A change that flips one of
|
||||
those tests is a behaviour change, not a cleanup.
|
||||
- `Sdp` — the offer's exact bytes, the parser (the telephone-event payload
|
||||
|
|
@ -323,7 +339,8 @@ What the suites pin:
|
|||
call, without the negotiation, for a character that is no tone or for a
|
||||
string past `DtmfMaxTones`; the receive payload type: our offer's on a
|
||||
renumbered answer, the answer's when the audio took ours, the echoed
|
||||
offer's on an incoming call) and
|
||||
offer's on an incoming call; an incoming call from an INVITE, and an
|
||||
outgoing call from responses, whose header names come in compact form) and
|
||||
`RegRecovery` (thresholds, backoffs, the throttle
|
||||
schedule, Retry-After, which waits a Dial may cut short, when the old
|
||||
registration counts as gone, the holds a restart takes over, a binding the
|
||||
|
|
@ -342,6 +359,10 @@ What the suites pin:
|
|||
In-Reply-To for no message, an unusable TPDU acknowledged with an
|
||||
RP-ERROR, a body that is no RP message, a page-mode text 200'd and
|
||||
logged, a short message while SMS over IP is off refused with 480;
|
||||
a delivered MESSAGE whose header names come in compact form — the 200 and
|
||||
the delivery report of its long form, its retransmission key, the 480
|
||||
while SMS over IP is off — and a final in compact form taken by the
|
||||
message in flight;
|
||||
a submit report before the MESSAGE's own final taken — the message sent
|
||||
and the late final nobody's; with two segments the second goes out under
|
||||
its own Call-ID — a text past 255 segments failed at once naming the fit,
|
||||
|
|
@ -1561,15 +1582,15 @@ unmeasured.
|
|||
A MESSAGE outside a call's dialog whose `Content-Type` does not contain
|
||||
`application/vnd.3gpp.sms`, letter case ignored — a page-mode MESSAGE — is
|
||||
still answered 200 and logged with its body: the 200 is `BuildResponse`'s
|
||||
now and the line names the content type (§7.8). Every header of a MESSAGE
|
||||
is read by its long name, on one line with the colon straight after the
|
||||
name: a compact form (RFC 3261 7.3.3) is not seen, so
|
||||
a `c:` line is no `Content-Type`, an `i:` line no Call-ID and a `v:` line
|
||||
no `Via`; nor is a name with white space before its colon, and of a value
|
||||
folded onto further lines the first is read (7.3.1 allows both).
|
||||
now and the line names the content type (§7.8). A header imsd reads is
|
||||
found under its long name or, where it has one, its compact form (RFC
|
||||
3261 7.3.3: a `c:` line is a `Content-Type`, an `i:` line a Call-ID, a
|
||||
`v:` line a Via), with or without white space before the colon; of a
|
||||
value folded onto further lines the first line is read (7.3.1 allows the
|
||||
fold).
|
||||
|
||||
- **A retransmitted MESSAGE** (the same Call-ID, CSeq and Via branch — the
|
||||
value of the first `branch=` of its first `Via:` line; a MESSAGE with none
|
||||
value of the first `branch=` of its first Via row; a MESSAGE with none
|
||||
or an empty one is never taken for a copy — within 32 s of our final:
|
||||
`RecentTransactions`, standing in for RFC 3261 17.2.2's server
|
||||
transaction) gets that final again and is not
|
||||
|
|
|
|||
Loading…
Reference in a new issue