diff options
author | dvossel <dvossel@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-07-20 21:41:21 +0000 |
---|---|---|
committer | dvossel <dvossel@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-07-20 21:41:21 +0000 |
commit | 13f9f228f5891ee86bf7c75cb9305834d4482b5e (patch) | |
tree | bc897519597de55fef61b2ec2b2738ab0224679d /channels | |
parent | ce66b9de785c78d6d45825a83bbb5098fb65d426 (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: http://svn.digium.com/svn/asterisk/trunk@278234 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_sip.c | 21 |
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); |