Repository navigation
Conversation
Behind a NAT the local address in the REGISTER Contact is not reachable from the registrar, so requests to the registered contact never arrive unless the server rewrites the Contact itself. sipreg_set_contact_rewrite() makes the client register the address the registrar reports in the received and rport parameters of the 2xx's top Via (RFC 3261 18.2.1, RFC 3581): when it differs from the address in the Contact, the client sends a new REGISTER with that address and removes the stale binding (expires=0) in the same request. Two addresses taking turns are capped at two consecutive rewrites. sipreg_contact_addr() returns the address currently in the Contact, so an application can use it for its dialogs too. Off by default. The test puts the mock NAT in front of the mock registrar and checks the second REGISTER. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
qfiber
force-pushed
the
sipreg-contact-rewrite
branch
from
October 3, 2026 08:26
b8eaf15 to
96f2857
Compare
qfiber
added a commit
to qfiber/baresip
that referenced
this pull request
Oct 3, 2026
Behind a NAT the local address in the Contact is not reachable from the registrar. Registrars that rewrite the Contact from the request's source (Asterisk rewrite_contact, Kamailio fix_nated_register, SBCs) hide this; the rest can never send the client a request. With sipnat=rport the registration uses re's Contact rewrite (sipreg_set_contact_rewrite()): it registers the address the registrar reports in the received and rport parameters of its responses. The UA then uses that address in the Contact of its dialogs as well (ua_cuser(), after a public GRUU), so in-dialog requests from the far end reach it too. Needs baresip/re#1628 (sipreg_set_contact_rewrite, sipreg_contact_addr). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
qfiber
added a commit
to qfiber/baresip
that referenced
this pull request
Oct 5, 2026
cspiel1
reviewed
Oct 7, 2026
cspiel1
reviewed
Oct 7, 2026
cspiel1
reviewed
Oct 7, 2026
cspiel1
reviewed
Oct 7, 2026
cspiel1
reviewed
Oct 7, 2026
Rename contact_rewrite() to rewrite_contact(), drop the comments on the static helpers, cite RFC 3261 18.2.1 and RFC 3581 in the API doc of sipreg_set_contact_rewrite(), and use doxygen style for the test's comment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
Thanks for the review, and sorry for the extra work. I'm new to contributing here, so apologies for the mistakes. All done in 7e4fd4c: renamed to |
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.
Behind a NAT the local address in the REGISTER Contact is not reachable from the registrar. Registrars that rewrite the Contact from the request's source hide this; with the rest, requests to the registered contact never arrive.
This adds an opt-in Contact rewrite to sipreg, based on the address the registrar reports in the
receivedandrportparameters of the 2xx's top Via (RFC 3261 18.2.1, RFC 3581):sipreg_set_contact_rewrite(reg, true)enables it (off by default, so nothing changes for existing users).Contact: ...;expires=0in the same request.sipreg_contact_addr()returns the address currently in the Contact (the learned one when rewritten, otherwiseladdr), so an application can use it in the Contact of its dialogs as well. A baresip PR using this follows.The test puts the mock NAT (
NAT_INBOUND_SNAT) on the mock registrar's UDP socket (via the newsip_transp_udp_sock()), so the registrar sees the client at 192.0.2.10, and checks the second REGISTER: the stale local binding withexpires=0, then the public one. It fails without the rewrite enabled.retest -rpasses, also under ASan, and ccheck is clean.Tested against Asterisk 22 behind a home NAT: the client registers its private address, re-registers with the public one and removes the private binding.