ims-pdn-up: the firewall accepts the ims PDN's ESP itself, not only as an answer to a packet of the phone's

A request the network starts (a call to the phone, a text, a NOTIFY)
reaches the phone as an ESP packet on the ims netdev. That packet passes
the firewall's input chain before the kernel decapsulates it, and what
it carried passes the chain again afterwards. The script opened the
chain for the second, imsd's two protected ports. For the first there
was no rule, and pmOS's chain then lets an ESP packet in only as an
answer to one the phone sent ("ct state established"): the connection
tracker has no tracker for ESP, and its generic one keeps the entry for
nf_conntrack_generic_timeout seconds after the last packet either way,
600 on the dev phone. A request the network starts later than that after
the phone's last ESP packet is dropped, and its retransmissions until
the phone next sends to that P-CSCF; imsd sees nothing of it.

What keeps the entry is the CRLF keepalive every 30 s, which goes out
over TCP and outside a call only.

The script now inserts a rule that accepts ESP on qmapmux*, under the
comment imsd-esp and with a check of its own, so that a ruleset which
carries the port rules already (fp6-img's 01_imsd.nft) gets it too. The
kernel drops an ESP packet no SA matches, and what an SA decapsulates
passes the chain again, under the rules a packet on qmapmux* meets
without ESP. Like the port rules the script inserts, the rule is in the
running ruleset only: a reload of the ruleset from its files removes it
until imsd next starts, so a ruleset whose files carry the port rules
has to carry this rule in them as well.

Tested: the script's firewall block by itself on the workstation against
nftables, in two network namespaces with an ESP SA pair between them and
the dev phone's ruleset as read from it (the fp6 journal's
2026-11-24-incoming-dropped-without-ping capture, bench-esp-rule.sh),
the tracker's timeout at 8 s: with 1.2.3's block a connection opened to
port 45062 from the network's side 11 s after the phone's last packet
got no answer, its ESP packets new to the tracker and none through the
chain; with this block the rule was inserted once and the same
connection accepted; an ESP packet with an SPI no SA has dropped by the
kernel behind the chain; a connection through the SA to another port
dropped by the chain; ESP on another interface and an AH packet not
accepted, ESP over IPv4 and ESP on a second qmapmux interface accepted;
the rule gone and the connection unanswered again after the ruleset was
loaded again from its file, and kept where the file carries the rule;
all three rules inserted on a ruleset without imsd's, and connections to
both ports accepted through them; nothing done where there is no inet
filter table. Eleven faults put into the block one at a time, ten in its
rule for ESP, that rule's check and its journal lines and one in a port
rule, were each caught by a step. On the dev phone on KPN the script
inserted the rule at imsd's start, above the port rules it found, and
the daemon resumed its registration; and with the tracker's timeout at 0
for the test, so that every ESP packet from the network came without an
entry, a text sent to the phone's own number was answered, reported and
delivered within a second with the rule (six such packets), and none of
the three reached the daemon in 20 s with the rule taken out (23 such
packets). Not met: a request the network starts after the entry has
lapsed of itself, 600 s after the phone's last ESP packet (a call to the
phone from another line).
This commit is contained in:
Jorijn van der Graaf 2026-11-25 11:30:30 +01:00
commit bc0e70a17f
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
2 changed files with 93 additions and 5 deletions

View file

@ -991,6 +991,47 @@ Rules:
a P-CSCF that had dropped a flow's state, and one that had received
the first INVITE before the flow died; a reopen's connect that gets no
answer at all; the emergency chain on a network.
- The firewall's rule for ESP (§7.3, §13; 1.2.4) is the bring-up script's,
which no suite reaches. The script's firewall block ran by itself on the
workstation against nftables (2026-11-24 and -25, the fp6 journal's
`2026-11-24-incoming-dropped-without-ping` capture,
`bench/bench-esp-rule.sh`: two network namespaces, an ESP transport-mode
SA pair between them, the dev phone's ruleset as read from it loaded in
the one that stands for the phone, the connection tracker's generic
timeout at 8 s, plain TCP both ways and no imsd). 1.2.3's block left the
ruleset as it was, and a connection the network's side opened to port
45062 11 s after the phone's last packet got no answer: its three ESP
packets were new to the tracker and none passed the chain. This script's
block inserted the rule (`nftables: accepting ESP on qmapmux*`; a second
run inserted nothing), and the same connection, 11 s after the last
packet, was accepted. An ESP packet whose SPI no SA has passed the chain
and was dropped by the kernel (`XfrmInNoStates`); a connection through
the SA to another port got no answer, its SYNs dropped by the chain
after decapsulation. On that ruleset without imsd's rules the block
inserted all three above the chain's own; with no `inet filter` table it
did nothing. After the ruleset was loaded again from its file the
script's rule was gone and the connection unanswered again; a file that
carries the rule kept it. ESP on another interface was not accepted and
neither was an AH packet; ESP over IPv4 on `qmapmux0.0` was accepted,
and ESP on a second `qmapmux` interface. On that ruleset without imsd's
rules, as the block left it, connections to both ports were accepted.
Eleven faults put into the block one at a time, ten in its rule for ESP,
that rule's check and its journal lines and one in a port rule, were
each caught by a step (`bench/run-mutations-esp.sh`).
`bench/bench-esp-pinhole.sh` there has the gap without the script: the
network's connection accepted a second after the phone's own exchange
and under a packet of the phone's every 3 s, and unanswered 11 s after
the last packet. On the dev phone (KPN, the capture's `phone/`,
2026-11-25) the script, run at imsd's start, inserted the rule above the
two port rules it found, and the daemon resumed its registration. Then a
text was sent to the phone's own number with the tracker's timeout at 0
for the test, so that every ESP packet from the network came without an
entry: with the rule, six such packets came, and the answer to the
MESSAGE, the submit report and the text's delivery reached the daemon
within a second; with the rule taken out, 23 came in 20 s and none of
the three reached the daemon in those 20 s. Not met: a request the
network starts after the entry has lapsed of itself, 600 s after the
phone's last ESP packet (a call to the phone from another line).
- `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`
on an unbound mux (the fp6 journal's `2026-10-11-pcscf-pco-probe` capture,
@ -1424,7 +1465,12 @@ configures the muxed netdev. Idempotent; a non-zero exit fails the unit.
- Opens imsd's protected ports 45061–45062 (TCP and UDP) on `qmapmux*` in
nftables when a `inet filter` table exists (pmOS's default INPUT chain drops
inbound on `qmapmux*`, which silently killed every network-initiated
request after ESP decapsulation). Best-effort.
request after ESP decapsulation), and accepts ESP itself on `qmapmux*`
(the packet passes the chain before it is decapsulated too; §13). Each
under its own comment in the chain, `imsd-protected-ports` and `imsd-esp`,
and only where the chain has no rule under that comment. Best-effort,
and in the running ruleset only: what the script inserted is gone when
the ruleset is next loaded from its files (§13).
- Writes `/run/imsd.env`: `DEV=<netdev>`, `LOCAL=<PDN address>`,
`PCSCF_DISCOVERED=<list>` (comma-separated in the modem's order; empty when
nothing was discovered or `PCSCF` is set) and `PCSCF_DISCOVERY=found|none|failed|skipped`
@ -1979,7 +2025,9 @@ imsd to try again`, `wrote
(not usable on the IPv6-only ims PDN)`, `P-CSCF discovery: nothing usable
(…)`, `P-CSCF X configured: discovery skipped`, `host route to P-CSCF X dev
Y` (the configured address or the first discovered), `wrote
/run/imsd.env: DEV=… LOCAL=… PCSCF_DISCOVERED=… PCSCF_DISCOVERY=…` —,
/run/imsd.env: DEV=… LOCAL=… PCSCF_DISCOVERED=… PCSCF_DISCOVERY=…`,
`nftables: opened protected ports 45061-45062 on qmapmux*` and `nftables:
accepting ESP on qmapmux*` where the script inserted the rule —,
`imsd-handover: …`, `imsd-ofono-restart-calls: …`.
### 7.9 SMS over IP (TS 24.341)
@ -2734,7 +2782,10 @@ only the imsd side of its bus choice.
(§7.2 step 3). Nothing else is routed over it.
A change that routes anything else over it needs a reason and a bench.
- The fixed protected ports (45061/45062) are opened in nftables for
`qmapmux*` only, by the bring-up script.
`qmapmux*` only, by the bring-up script, and ESP is accepted there: the
kernel drops an ESP packet no SA matches, and what an SA decapsulates
passes the chain again, under the same rules as a packet that came
without ESP.
- Short messages (§7.9): `Send` is behind `net.catcrafts.IMS1.Messaging`
(an ungated `Send` would let any local account text from the
subscriber's number); the journal names a delivered message's sender, size and
@ -2852,8 +2903,28 @@ the related code.
whether that shape is the phone's or the network's interworking,
nothing on disk says.
- **pmOS's default nftables** drops inbound on `qmapmux*`; without the
protected-port rule every network-initiated request (NOTIFY, MT INVITE)
dies after ESP decapsulation and MT calls fall back to CS.
protected-port rule every network-initiated request (NOTIFY, MT
INVITE) dies after ESP decapsulation and MT calls fall back to CS. The
ESP packet passes the same chain before it is decapsulated, and
without a rule for it the chain accepts it only as an answer to a
packet the phone sent (`ct state established`): the connection tracker
has no tracker for ESP, and its generic one keeps the entry for
`nf_conntrack_generic_timeout` seconds after the last packet either
way, 600 on the dev phone. A request the network starts later than
that after the phone's last ESP packet is then dropped, and its
retransmissions until the phone next sends to that P-CSCF. A CRLF
keepalive every 30 s keeps the entry (over TCP and outside a call
only: `SendKeepalive` sends none over UDP, and the shell's loop calls
it only while no call is up); the bring-up script's rule for ESP
(§7.3, 1.2.4) makes the entry needless. Shown on the workstation with
the dev phone's ruleset, and on the dev phone for a text with the
tracker's timeout at 0 (§5). A firewall without an `inet filter` table
with an `input` chain gets no rule from the script and needs its own.
And the script's rules are in the running ruleset only: a reload of
the ruleset from its files (the nftables unit's `flush ruleset`, and
the one in `/etc/nftables.nft`) removes them until imsd next starts,
so a ruleset whose files carry the port rules (fp6-img's
`01_imsd.nft`) has to carry the rule for ESP in them too.
- **The kernel's temporary SLAAC address** on the ims netdev is listed first
and retired after about two days; a registration bound to it dies with it.
- **systemd reads `EnvironmentFile=` per spawned command** (systemd 262~rc3