Skip to content

Commit

Permalink
[b2b_entities] Proper handling of overlaping transactions
Browse files Browse the repository at this point in the history
As per RFC3261, Section 14.2 :

   A UAS that receives a second INVITE before it sends the final
   response to a first INVITE with a lower CSeq sequence number on the
   same dialog MUST return a 500 (Server Internal Error) response to the
   second INVITE and MUST include a Retry-After header field with a
   randomly chosen value of between 0 and 10 seconds.

   A UAS that receives an INVITE on a dialog while an INVITE it had sent
   on that dialog is in progress MUST return a 491 (Request Pending)
   response to the received INVITE.

Changes:
* 491 is now generated when receiving a request while already having an outbound one - the old code was generating 491 upon receiving a request while having another INCOMING one :-/
* generate the 500 reply when receiving a new request while handing another incoming one.
  • Loading branch information
bogdan-iancu committed Sep 14, 2023
1 parent 881acb3 commit 712c2f2
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions modules/b2b_entities/dlg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1221,22 +1221,22 @@ int b2b_prescript_f(struct sip_msg *msg, void *uparam)
{
/* We have another UAS ongoing transaction on the dialog
* -> reject with 500, "Overlapping Requests" */
#define RETRY_AFTER_HDR "Retry-After: "
#define RETRY_AFTER_HDR_LEN (sizeof("Retry-After: ")-1)
char ra_s[RETRY_AFTER_HDR_LEN + 3 + CRLF_LEN];
str ra = {ra_s, 0};
str text = str_init("Overlapping Requests");
LM_DBG("Received another request when the previous "
"one was in process\n");
char ra_s[sizeof("Retry-After: ") + 3 + CRLF_LEN + 1];
int ra_len = 0;
memcpy( ra_s+ra_len, "Retry-After: ", sizeof("Retry-After: "));
ra_len += sizeof("Retry-After: ");
memcpy( ra.s+ra.len, RETRY_AFTER_HDR, RETRY_AFTER_HDR_LEN);
ra.len += RETRY_AFTER_HDR_LEN;
/* the retry value is between 0 and 10 */
ra_len += btostr( ra_s+ra_len,
(unsigned char)(((float)rand()/RAND_MAX)*10));
memcpy( ra_s+ra_len, CRLF, CRLF_LEN);
ra_len += CRLF_LEN;
add_lump_rpl( msg, ra_s, ra_len , 0 );
ra.len += btostr(ra.s+ra.len, (unsigned char)(rand()%10) );
memcpy( ra.s+ra.len, CRLF, CRLF_LEN);
ra.len += CRLF_LEN;
/* send reply */
str text = str_init("Overlapping Requests");
if(tmb.t_reply_with_body( tm_tran, 500,
&text, 0, 0, &to_tag) < 0)
&text, 0, &ra, &to_tag) < 0)
{
LM_ERR("failed to send reply with tm\n");
}
Expand Down

0 comments on commit 712c2f2

Please sign in to comment.