Skip to content

tracer: use the outgoing connection for stateless request traces - #4531

Open
Th0masL wants to merge 1 commit into
OpenSIPS:masterfrom
Th0masL:fix/tracer-stateless-outgoing-connection
Open

Th0masL wants to merge 1 commit into
OpenSIPS:masterfrom
Th0masL:fix/tracer-stateless-outgoing-connection

Conversation

@Th0masL

@Th0masL Th0masL commented Dec 3, 2026

Copy link
Copy Markdown

Summary

Fix incorrect destination metadata in traces of statelessly forwarded requests, including end-to-end ACKs for INVITE 200 OK responses.

Details

When a request arrives over connection A and is forwarded over connection B, trace_slreq_out() currently passes the incoming tracing context directly to trace_msg_out().

That context carries connection A's ID. When resolving the outgoing trace destination, trace_msg_out() uses that connection's peer address, causing the trace to identify the caller instead of the callee.

This affects tracing metadata only. The SIP request reaches the correct destination.

Solution

Copy the tracing context onto the stack and select the outgoing connection ID before generating the trace:

  • For TCP-based transports, use last_outgoing_tcp_id.
  • For other transports, use 0 so destination resolution uses the supplied destination.
  • Return safely if no tracing context exists.

The copy preserves the original context. The transport check matches the condition used by msg_send() to reset the outgoing connection ID, avoiding stale TCP IDs for non-TCP transports such as SCTP.

Validated with a real OpenSIPS build and loopback SIP peers, using a TCP caller and TCP/TLS callees:

Tracer Trace mode Callee transport Outgoing ACK trace destination
Before Transaction / dialog TCP Caller — incorrect
Before Transaction / dialog TLS Caller — incorrect
After Transaction / dialog TCP Callee — correct
After Transaction / dialog TLS Callee — correct

The callee received the ACK in every case. Stateful BYE traces in dialog mode remained correct. The revised module compiled and linked successfully.

Testing was performed on Linux ARM64. UDP, WS/WSS and SCTP callees, NAT, PROXY protocol, and AMD64 were not exercised. Transport correlation was not independently verified from HEP chunks.

Compatibility

No configuration migration is required. SIP forwarding, trace instance selection, and caller/callee filtering are unchanged.

The change corrects outgoing trace destination and connection attribution while preserving the original tracing context.

Closing issues

Closes #4477

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.

[BUG] tracer: forwarded 2xx ACK has incorrect HEP destination over TLS

1 participant