pjsua: select dialog Via address toward the actual next hop#5060
Open
nanangizz wants to merge 1 commit into
Open
pjsua: select dialog Via address toward the actual next hop#5060nanangizz wants to merge 1 commit into
nanangizz wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refines how PJSUA selects the local Via sent-by address when an account is not using STUN/UPnP, ensuring the selection is made toward the dialog’s actual next hop (route set / remote target) rather than the account’s outbound proxy or id URI, and avoiding reliable-transport probing that can create unused TCP/TLS connections.
Changes:
- Refactors the core address-selection logic from
pjsua_acc_get_uac_addr()into a shared static helper and adds two internal dialog-oriented variants. - Updates incoming-call and incoming-SUBSCRIBE paths to compute the Via address toward the dialog’s effective next hop (route set top entry, else remote target).
- Updates outgoing-call dialog Via setup to use the dialog’s remote target (when no account outbound proxy is configured), while skipping reliable transports.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pjsip/src/pjsua-lib/pjsua_pres.c | Switches incoming SUBSCRIBE dialog Via selection to the new UAS next-hop-aware resolver. |
| pjsip/src/pjsua-lib/pjsua_call.c | Updates outgoing dialog Via selection and incoming-call Via selection to use next-hop-aware dialog resolvers. |
| pjsip/src/pjsua-lib/pjsua_acc.c | Factors out core SIP-URI-based address resolution and adds dialog (UAS/UAC) helpers that skip reliable transports. |
| pjsip/include/pjsua-lib/pjsua_internal.h | Declares the new internal dialog-oriented address selection functions. |
The UAS (incoming call / incoming SUBSCRIBE) and UAC (outgoing call) paths determined the local Via address via pjsua_acc_get_uac_addr(), which for a UAS dialog resolves the destination from the account outbound proxy or the passed target, and for the outgoing call passed acc->cfg.id (the account id URI). Neither reflects the request's real next hop, so on a multihomed host the Via could carry the wrong local interface. Factor the address-resolution body of pjsua_acc_get_uac_addr() into a shared static core get_uac_addr_for_sip_uri() (behavior for all existing UAC callers is unchanged), and add two dialog variants that compute the address toward the actual next hop and skip reliable transports (Via resolved at send time, returning PJ_ENOTFOUND so the caller leaves the Via untouched): - pjsua_acc_get_uas_addr(): next hop = dlg->route_set top (from the incoming Record-Route), else dlg->target. Used by pjsua_call_on_incoming() and pres_on_rx_request(). - pjsua_acc_get_uac_dlg_addr(): next hop = account outbound proxy when set, else the dialog's remote target (dlg->target) instead of acc->cfg.id. Used by dlg_set_via(). Keying the reliable-transport skip off the true next hop also fixes a corner case where a UDP next hop reached via a reliable target/proxy could get a STUN-mapped address in the Via (#1804 / #1412). Co-Authored-By Claude Code
c80f067 to
501f10d
Compare
sauwming
approved these changes
Jul 7, 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.
Follow-up to #5051 (now merged); this PR targets master and contains only its own change.
Problem
When an account is not using STUN/UPnP, pjsua selects the local Via
sent-byfor a dialog viapjsua_acc_get_uac_addr(). That function resolves the destination from the account's outbound proxy (acc->route_set) or the passed target URI. That reference is wrong for the request's actual next hop in two cases:dlg_set_via): the target passed wasacc->cfg.id(the account id URI), not the dialog's remote target. With no account proxy, the Via is computed toward the account domain instead of the actual callee.On a multihomed host these can put the wrong local interface in the Via.
Change
Factor the address-resolution body of
pjsua_acc_get_uac_addr()into a shared static coreget_uac_addr_for_sip_uri()— behavior for all existing UAC callers is unchanged — and add two dialog variants that compute the address toward the actual next hop and skip reliable transports (their Via is resolved from the real connection at send time; they returnPJ_ENOTFOUNDso the caller leaves the Via untouched):pjsua_acc_get_uas_addr()— next hop =dlg->route_settop (from the incoming Record-Route), elsedlg->target. Used bypjsua_call_on_incoming()andpres_on_rx_request().pjsua_acc_get_uac_dlg_addr()— next hop = account outbound proxy when set, else the dialog's remote target (dlg->target) rather thanacc->cfg.id. Used bydlg_set_via().Keying the reliable-transport skip off the true next hop also fixes a corner case where a UDP next hop reached via a reliable target/proxy could get a STUN-mapped address in the Via (#1804 / #1412).
Notes
dlg->target.pjsua_internal.h).Testing
Non-sanitizer build:
100_simple.py(UDP call) — pass200_tcp.py(TCP call) — pass(The
100_peertopeer.pypresence test fails identically on master and is a pre-existing environment issue, not related to this change.)