[Home]

Summary:ASTERISK-24541: Code that adds Required: timers to a 200 OK response will not work
Reporter:David Woolley (davidw)Labels:
Date Opened:2014-11-20 10:51:23.000-0600Date Closed:
Priority:MinorRegression?No
Status:Open/NewComponents:Channels/chan_sip/General
Versions:SVN 1.8.32.0 11.14.0 12.7.0 13.0.0 Frequency of
Occurrence
Constant
Related
Issues:
Environment:Attachments:
Description:"Required:" headers fail to be added for UAS mode handling of session-timers=originate.  Instead "WARNING: Can't add more headers when lines have been added" is generated.

This is because transmit_response_with_sdp calls add_required_respheader after it has called add_sdp.
Comments:By: David Woolley (davidw) 2014-11-20 11:10:27.539-0600

Although I checked this on the branch 13 SVN, this appears to exist in all supported versions.

This is the original email to asterisk-dev, and Mark Michelson's response <[http://lists.digium.com/pipermail/asterisk-dev/2014-November/071396.html]>:

{quote}I don’t believe that the code that adds Required: timers to a 200 OK response will work, even in Asterisk 13, current branch version.

In my back port, it produces an error saying headers cannot be added after lines have been added.  The same conditions for this seem to apply in version 13:

In add_header:

{code}
       if (req->lines) {
              ast_log(LOG_WARNING, "Can't add more headers when lines have been added\n");
              return -1;
       }
{code}


In transmit_response_with_sdp:

{code}
       if (p->rtp) {
...
              if (p->t38.state == T38_ENABLED) {
                      add_sdp(&resp, p, oldsdp, TRUE, TRUE);
              } else {
                      add_sdp(&resp, p, oldsdp, TRUE, FALSE);
              }
       } else
              ast_log(LOG_ERROR, "Can't add SDP to response, since we have no RTP session allocated. Call-ID %s\n", p->callid);
       if (reliable && !p->pendinginvite)
              p->pendinginvite = seqno;             /* Buggy clients sends ACK on RINGING too */
           add_required_respheader(&resp);
{code}

Note that SDP is added, and therefore “req->lines” becomes non-zero, as the response now has a body, before add_required_respheader is called.

In add_required_respheader:

{code}
       if (ast_str_strlen(str) > 0) {
              add_header(req, "Require", ast_str_buffer(str));
       }
{code}

For information, the test setup for this was two Asterisk instances in tandem.  The first one uses session-timers=originate.  The second one uses sendrpid=true, session-timers=accept and session-refresher=uas.  The dialplan (after a delay) sets the connected line, to force a re-invite against the call setup direction (then goes into a long wait).  As the first Asterisk is UAS for the re-invite, but is in session timer originate mode, it is forced to use Require.  The test was trying to confirm that session timer role reversals worked.

---------

{color:green}
Agreed that this looks like a bug. Probably should be doing the add_required_respheader() call before adding the SDP.
{color}
{quote}

By: Matt Jordan (mjordan) 2014-12-01 11:36:04.023-0600

Looks like the fix would be relatively easy, if you'd like to provide the patch.