Skip to content

enhance message sending with buffer capture for tracing - #4228

Open
digipigeon wants to merge 2 commits into
OpenSIPS:masterfrom
connexcs:fix_459_ts_stateful_tracing
Open

enhance message sending with buffer capture for tracing#4228
digipigeon wants to merge 2 commits into
OpenSIPS:masterfrom
connexcs:fix_459_ts_stateful_tracing

Conversation

@digipigeon

Copy link
Copy Markdown

Summary

Fix stateful TM SIP tracing so outgoing HEP payloads contain the final plaintext SIP message after POST_RAW_PROCESSING transformations.

This ensures that the SIP payload recorded by tracer matches the message sent to the peer, including Call-ID changes made by topology_hiding.

Details

This is a bug fix for stateful transaction tracing.

Modules such as topology_hiding modify outgoing SIP messages using a POST_RAW_PROCESSING callback. These callbacks run inside msg_send(), after TM has prepared and stored its retransmission buffer.

The transformed buffer is passed to the transport and is therefore what the remote peer receives. However, after sending, TMCB_MSG_SENT_OUT callbacks were given the original TM buffer instead of the transformed buffer.

Consequently, tracer exported a HEP payload that did not always match the SIP message sent on the wire. For example, when topology_hiding("C") encoded the Call-ID:

  • The remote peer received the encoded Call-ID.
  • The outgoing HEP SIP payload contained the original Call-ID.
  • Retransmissions were affected in the same way.

This is particularly important for TLS and WebSocket transports. Capturing at the network level would expose encrypted or transport-framed data, while SIP tracing needs the final plaintext SIP message immediately before transport processing.

Other modules using POST_RAW_PROCESSING, such as compression, may have been affected by the same discrepancy.

The scope of this change is stateful TM tracing through TMCB_MSG_SENT_OUT. Stateless SL tracing does not use these callbacks and is not changed by this PR.

Solution

The send API can now optionally return the final outgoing plaintext buffer after all POST_RAW_PROCESSING callbacks have completed, but before transport framing or encryption.

TM requests this buffer when a TMCB_MSG_SENT_OUT observer is registered and supplies it to the callback for:

  • Initial forwarded requests
  • Request retransmissions
  • Relayed and locally generated replies
  • Reply retransmissions
  • Locally generated requests
  • Local CANCEL requests
  • Automatically generated ACK requests

The implementation avoids copying every traced SIP message:

  • If raw processing leaves the buffer unchanged, the callback temporarily borrows the original buffer.
  • If raw processing creates a replacement buffer, ownership is temporarily transferred to TM.
  • TM releases the replacement after the callback completes.

This avoids an additional allocation and full-message copy for every traced send. It also avoids an out-of-memory fallback that could otherwise cause tracing to use the incorrect pre-transformation payload.

HEP correlation remains based on the original transaction Call-ID. Only the captured SIP payload reflects the final Call-ID sent to the peer. This preserves transaction-level grouping while ensuring the displayed SIP message matches the outgoing plaintext message.

The change was tested with topology_hiding("C") and transaction tracing:

  • The outbound HEP payload Call-ID exactly matched the Call-ID received by the UAS.
  • Four UDP retransmissions were generated and all four HEP payloads contained the same encoded Call-ID.
  • No OpenSIPS runtime errors were reported.
  • The OpenSIPS core, TM, tracer, topology-hiding, proto_hep, dialog, signaling, and SL components compiled successfully.
  • All 2,564 available core unit tests passed.

Compatibility

No configuration or script migration is required.

There are no intended SIP interoperability changes. The SIP message sent to the remote peer is unchanged; this PR only corrects the buffer exposed to post-send TM observers.

Consumers of TMCB_MSG_SENT_OUT will now receive the actual post-raw-processing plaintext payload. This is an intentional behavior correction. A consumer that previously relied on the callback receiving the stale pre-transformation buffer may observe different payload content when modules such as topology_hiding or compression modify the message.

The HEP correlation identifier remains unchanged, preserving existing transaction correlation behavior.

Stateless SL tracing remains outside the scope of this change.

Closing issues

Closes #459

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SIP Trace does now show modified callid after topology_hiding

1 participant