Skip to content

pjsua: no probing connection for the Contact when a resolver may use DNS SRV - #5302

Merged
nanangizz merged 1 commit into
pjsip:masterfrom
vlaushkin:contact-probe-resolver
Oct 7, 2026
Merged

nanangizz merged 1 commit into
pjsip:masterfrom
vlaushkin:contact-probe-resolver

Conversation

@vlaushkin

Copy link
Copy Markdown
Contributor

A follow-up to #5293: using the DNS SRV failover with an external resolver showed this one.

With a TCP or TLS registrar, PJSUA takes the Contact address from a connection it opens to the host's A record on the default port. With DNS SRV the REGISTER goes to another server or port, so the connection is wasted and the Contact carries the port of an unrelated socket. The probe is already skipped with pjsua_config.nameserver; now also with a DNS or external resolver set on the endpoint, which resolve SRV the same way. Seen on iOS with an external resolver and SRV targets on port 5065: a connection to the host on 5060 before every REGISTER on 5065.

As with nameservers, the Contact then takes the listener's port, and PJSUA still registers once more with the port the registrar reports in rport; only SIP outbound avoids that.

Two getters for the external resolver are added. The test checks that the Contact takes the listener's port and no transport is created; it fails on the previous code.

Full pjsip-test passes on macOS and Linux with ASan/LSan.

@nanangizz nanangizz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change itself looks right to me. Checking the endpoint's resolver is also more accurate than nameserver_count now that nameservers can change at runtime (#5298 detaches the resolver when they are cleared). A few things, mostly in the test; details inline.

One more, outside the diff: the pjsua2 copy of this doc, contactUseSrcPort in pjsip/include/pjsua2/account.hpp (lines 779-785), still says the feature is turned off only "when nameserver is configured". It should get the same wording as the pjsua.h change here.

if (rc == 0)
rc = pjsua_ip_change_case(PJ_FALSE);
if (rc == 0)
rc = pjsua_contact_probe_case();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conflicts with master: #5298 added pjsua_keeps_option_case() and pjsua_restore_once_case() at this same spot and renamed restore_endpt() to restore_test_endpt(). Appending this case after pjsua_restore_once_case(PJ_TRUE) resolves it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased, the case follows the restore ones now.

Comment thread pjsip/src/test/srv_failover_test.c Outdated
PJ_LOG(3,(THIS_FILE, " Contact with an external resolver"));

if (pjsua_create() != PJ_SUCCESS)
return -3120;

@nanangizz nanangizz Oct 6, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-3120 to -3126 are already used earlier in this file (from line 1304 on), so a failure code wouldn't tell which test failed. -3180 and up look free on master (#5303 takes -3170 to -3177).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renumbered to -3180 .. -3187.

Comment thread pjsip/src/test/srv_failover_test.c Outdated
pjsua_destroy();
return -3121;
}
pjsip_endpt_set_ext_resolver(pjsua_get_pjsip_endpt(), &ext);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: the return value isn't checked. If it fails, the case would probe as before and report a Contact mismatch instead of the real cause.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked now.

Comment thread pjsip/src/test/srv_failover_test.c Outdated
pjsip_endpt_set_ext_resolver(pjsua_get_pjsip_endpt(), &ext);
pjsua_transport_config_default(&tcfg);
tcfg.port = 0;
if (pjsua_transport_create(PJSIP_TRANSPORT_TCP, &tcfg, &tp_id) != PJ_SUCCESS ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: 83 columns.

Suggested change
if (pjsua_transport_create(PJSIP_TRANSPORT_TCP, &tcfg, &tp_id) != PJ_SUCCESS ||
if (pjsua_transport_create(PJSIP_TRANSPORT_TCP, &tcfg,
&tp_id) != PJ_SUCCESS ||

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapped.

Comment thread pjsip/src/test/srv_failover_test.c Outdated
tpmgr = pjsip_endpt_get_tpmgr(pjsua_get_pjsip_endpt());
tp_cnt = pjsip_tpmgr_get_transport_count(tpmgr);
pool = pjsua_pool_create("probe", 512, 512);
if (pjsua_acc_create_uac_contact(pool, &contact, acc_id, &uri) != PJ_SUCCESS) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: 83 columns.

Suggested change
if (pjsua_acc_create_uac_contact(pool, &contact, acc_id, &uri) != PJ_SUCCESS) {
if (pjsua_acc_create_uac_contact(pool, &contact, acc_id,
&uri) != PJ_SUCCESS)
{

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapped.

@vlaushkin
vlaushkin force-pushed the contact-probe-resolver branch from 4cd33ca to c9fa394 Compare October 6, 2026 15:00
@vlaushkin

Copy link
Copy Markdown
Contributor Author

Thanks. Rebased on master, with the case after pjsua_restore_once_case(PJ_TRUE); the codes are -3180 to -3187, the result of pjsip_endpt_set_ext_resolver() is checked, the lines are wrapped, and the pjsua2 doc of contactUseSrcPort says the same as pjsua.h now.

@nanangizz
nanangizz requested a review from sauwming October 7, 2026 03:26
@nanangizz
nanangizz merged commit dbb41ec into pjsip:master Oct 7, 2026
67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants