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

Capture HEP messages after parsing instead of per recv#324
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
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