Summary:ASTERISK-26358: chan_sip: Contact is updated on re-200, but not on re-INVITE
Reporter:Walter Doekes (wdoekes)Labels:
Date Opened:2016-09-12 03:07:51Date Closed:2016-10-26 08:59:36
Versions:Frequency of
Description:*Problem:* chan_sip does not update a changed Contact from a reINVITE.

*Result:* when switching IP address mid-call, we can update the RTP
endpoint and succesfully resume the call on a different host/port, but
we cannot update the SIP endpoint. That, in turn, makes Asterisk unable
to hang up the call properly. It tries to send the BYE to the original
Contact, which is not listening anymore.

RFC3261, 12.2:
  Requests within a dialog MAY contain Record-Route and Contact header
  fields.  However, these requests do not cause the dialog's route set
  to be modified, although they may modify the remote target URI.
  Target refresh requests only update the dialog's remote target URI,
  and not the route set formed from the Record-Route.

Ergo, we're free to update the Contact, and when the UAS or UAC changes
source IP, we need to.

chan_sip already allows the Contact to be updated if it receives a 200
\[1\] (acts as UAC), but *not* if it receives an INVITE \[2\] (acts as
UAS). The latter appears to be an oversight.

       case 18X:
               parse_ok_contact(p, req);
       case 200:
               if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) { /* <-- should always be true */
                       parse_ok_contact(p, req);

               if (!p->owner) {        /* Not a re-invite */
                       if (req->debug)
                               ast_verbose("Using INVITE request as basis request - %s\n", p->callid);
                       if (newcall)
                               append_history(p, "Invite", "New call: %s", p->callid);
                       parse_ok_contact(p, req);
               } else {        /* Re-invite on existing call */
                       ast_clear_flag(&p->flags[0], SIP_OUTGOING);     /* This is now an inbound dialog */

*Suggested fix*: always parse_ok_contact() in handle_request_invite,
not only if this is a *new* dialog ({{!p->owner}}).

Then, the device which has updated its IP can send a reINVITE as a
target refresh and any new in-dialog messages from Asterisk -- e.g. a
BYE from Asterisk -- will get sent to the right destination.
Comments:By: Asterisk Team (asteriskteam) 2016-09-12 03:07:52.763-0500

Thanks for creating a report! The issue has entered the triage process. That means the issue will wait in this status until a Bug Marshal has an opportunity to review the issue. Once the issue has been reviewed you will receive comments regarding the next steps towards resolution.

A good first step is for you to review the [Asterisk Issue Guidelines|https://wiki.asterisk.org/wiki/display/AST/Asterisk+Issue+Guidelines] if you haven't already. The guidelines detail what is expected from an Asterisk issue report.

Then, if you are submitting a patch, please review the [Patch Contribution Process|https://wiki.asterisk.org/wiki/display/AST/Patch+Contribution+Process].