Capture HEP messages after parsing instead of per recv#324
Merged
Conversation
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`.
andywolk
approved these changes
Jun 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
recvreturns 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 withmsg_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, sotport_msg_alloc()setsMSG_DO_EXTRACT_COPYwhile the capture socket is open; atp_rcapturedmarker dedupes the per-message delivery, mirroringtp_rlogged.