Skip to content

Capture HEP messages after parsing instead of per recv - #324

Merged
andywolk merged 1 commit into
masterfrom
dmitry/fix_hep_segmented
Jun 18, 2026
Merged

andywolk merged 1 commit into
masterfrom
dmitry/fix_hep_segmented

Conversation

@morbit85

Copy link
Copy Markdown
Collaborator

HEP capture fired in each transport's recv hook, on the raw recv buffer. For a datagram that buffer is a whole message, but on a stream (TCP/TLS/WS/SCTP) one recv returns an arbitrary slice of the byte stream, so capture emitted byte fragments that did not align with SIP message boundaries: several HEP packets per message, each starting mid-message.

Move capture into tport_deliver(), which runs once per fully parsed message, and rebuild the wire image with msg_iovec(). The five per-transport capture calls are removed. Now every transport produces exactly one HEP packet per SIP message, starting at the request or status line.

For msg_iovec() to reproduce the header bytes the parser must keep the wire image, so tport_msg_alloc() sets MSG_DO_EXTRACT_COPY while the capture socket is open; a tp_rcaptured marker dedupes the per-message delivery, mirroring tp_rlogged.

HEP capture fired in each transport's recv hook, on the raw recv
buffer. For a datagram that buffer is a whole message, but on a stream
(TCP/TLS/WS/SCTP) one `recv` returns an arbitrary slice of the byte
stream, so capture emitted byte fragments that did not align with SIP
message boundaries: several HEP packets per message, each starting
mid-message.

Move capture into `tport_deliver()`, which runs once per fully parsed
message, and rebuild the wire image with `msg_iovec()`. The five
per-transport capture calls are removed. Now every transport produces
exactly one HEP packet per SIP message, starting at the request or
status line.

For `msg_iovec()` to reproduce the header bytes the parser must keep
the wire image, so `tport_msg_alloc()` sets `MSG_DO_EXTRACT_COPY` while
the capture socket is open; a `tp_rcaptured` marker dedupes the
per-message delivery, mirroring `tp_rlogged`.
@morbit85
morbit85 requested a review from andywolk June 18, 2026 12:57
@morbit85 morbit85 added the bug Something isn't working label Jun 18, 2026
@andywolk
andywolk merged commit 7333682 into master Jun 18, 2026
11 checks passed
@andywolk
andywolk deleted the dmitry/fix_hep_segmented branch June 18, 2026 15:31
damirn added a commit to team-telnyx/sofia-sip that referenced this pull request Nov 4, 2026
Required because FreeSWITCH v1.11.2 raises its configure floor to
sofia-sip-ua >= 1.13.18 (upstream a75491a318).

Branched off the previous upstream sync branch rather than master, because
that branch has already absorbed upstream master up to 54981e1. That makes
the merge base 54981e1 and reduces this sync to the remaining 9 upstream
commits, instead of re-resolving the whole earlier delta:

  bd16af3 Make HEP capture buffer size configurable via `bufsize=` (freeswitch#320)
  addf02c Clamp HEP capture payload to the buffer instead of dropping chunks (freeswitch#321)
  7333682 Capture HEP messages after parsing instead of per recv (freeswitch#324)
  1da05d8 [GHA] Skip mirror and meta jobs on public forks (freeswitch#322)
  704c49d [GHA] Skip artifacts upload on public forks (freeswitch#323)
  a404c31 / 8492b0f / 67866d7  Merge commit from fork (ws.c transport hardening)
  ad36ac8 Version bump to 1.13.18

One conflict:

  .github/workflows/build.yml   modify/delete -> kept deleted

The previous sync removed upstream's CI in b70ecb1 ("Keep Telnyx .github,
drop upstream CI changes from sync") so the fork keeps
.github/workflows/all.yml as its only workflow. v1.13.18 modified build.yml
again via the two [GHA] commits above, raising a modify/delete. Resolved the
same way - kept deleted. Verified .github now contains exactly all.yml,
unchanged from the previous sync branch.

Everything else auto-merged: the HEP capture rework and the ws.c/ws.h
transport hardening land in tport/, which the fork does not customise.

configure.ac now reads AC_INIT([sofia-sip], [1.13.18]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants