]> git.ipfire.org Git - thirdparty/asterisk.git/commit
res_pjsip_nat: Restore original contact for REGISTER responses
authorGeorge Joseph <gjoseph@digium.com>
Mon, 26 Aug 2019 02:20:13 +0000 (20:20 -0600)
committerGeorge Joseph <gjoseph@digium.com>
Fri, 6 Dec 2019 18:47:54 +0000 (11:47 -0700)
commit02576bfef709a378589372b39eb4aa34452a9cfe
treecf1b46b2d4d66ff59e6111a7324c9de6972468ae
parent5554082d883856a10f1c37c962e5de17a888c690
res_pjsip_nat: Restore original contact for REGISTER responses

RFC3261 Section 10 "Registrations", specifically paragraph
"10.2.4: Refreshing Bindings", states that a user agent compares
each contact address (in a 200 REGISTER response) to see if it
created the contact.  If the Asterisk endpoint has the
rewrite_contact option set however, the contact host and port sent
back in the 200 response will be the rewritten one and not the
one sent by the user agent.  This prevents the user agent from
matching its own contact.  Some user agents get very upset when
this happens and will not consider the registration successful.
While this is rare, it is acceptable behavior especially if more
than 1 user agent is allowed to register to a single endpoint/aor.

This commit updates res_pjsip_nat (where rewrite_contact is
implemented) to store the original incoming Contact header in
a new "x-ast-orig-host" URI parameter before rewriting it, and to
restore the original host and port to the Contact headers in the
outgoing response.

This is only done if the request is a REGISTER and rewrite_contact
is enabled.

pjsip_message_filter was also updated to ensure that if a request
comes in with any existing x-ast-* URI parameters, we remove them
so they don't conflict.  Asterisk will never send a request
with those headers in it but someone might just decide to add them
to a request they craft and send to Asterisk.

NOTE: If a device changes its contact address and registers again,
it's a NEW registration.  If the device didn't unregister the
original registration then all existing behavior based
on aor/remove_existing and aor/max_contacts apply.

ASTERISK-28502
Reported-by: Ross Beer
Change-Id: Idc263ad2d2d7bd8faa047e5804d96a5fe1cd282e
res/res_pjsip/pjsip_message_filter.c
res/res_pjsip_nat.c