summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vossel <dvossel@digium.com>2010-07-20 21:41:21 +0000
committerDavid Vossel <dvossel@digium.com>2010-07-20 21:41:21 +0000
commitc26791d5f862a7169cee8fb5a6ee51e5601d53d2 (patch)
treebc897519597de55fef61b2ec2b2738ab0224679d
parentc149b851b36d99db634df90c1f0ce35dda32ecb1 (diff)
fixes sip CANCEL race condition
If Asterisk sends a 4xx error and the other side sends a CANCEl before receiving the 4xx and responding with the ACK, Asterisk will process the CANCEL and send a 487 Request Terminated as a new final response to the INVITE. Since we are issuing a new final response to the INVITE, the old one must be pretend_acked else it will keep retransmitting. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@278234 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--channels/chan_sip.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index e2db51a3b..f5e6a7544 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -22131,26 +22131,27 @@ static int handle_request_refer(struct sip_pvt *p, struct sip_request *req, int
/*! \brief Handle incoming CANCEL request */
static int handle_request_cancel(struct sip_pvt *p, struct sip_request *req)
{
-
+
check_via(p, req);
sip_alreadygone(p);
+ if (p->owner && p->owner->_state == AST_STATE_UP) {
+ /* This call is up, cancel is ignored, we need a bye */
+ transmit_response(p, "200 OK", req);
+ ast_debug(1, "Got CANCEL on an answered call. Ignoring... \n");
+ return 0;
+ }
+
/* At this point, we could have cancelled the invite at the same time
as the other side sends a CANCEL. Our final reply with error code
might not have been received by the other side before the CANCEL
was sent, so let's just give up retransmissions and waiting for
ACK on our error code. The call is hanging up any way. */
- if (p->invitestate == INV_TERMINATED)
+ if (p->invitestate == INV_TERMINATED || p->invitestate == INV_COMPLETED) {
__sip_pretend_ack(p);
- else
- p->invitestate = INV_CANCELLED;
-
- if (p->owner && p->owner->_state == AST_STATE_UP) {
- /* This call is up, cancel is ignored, we need a bye */
- transmit_response(p, "200 OK", req);
- ast_debug(1, "Got CANCEL on an answered call. Ignoring... \n");
- return 0;
}
+ if (p->invitestate != INV_TERMINATED)
+ p->invitestate = INV_CANCELLED;
if (ast_test_flag(&p->flags[0], SIP_INC_COUNT) || ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD))
update_call_counter(p, DEC_CALL_LIMIT);