From 24f023e73317947a7648e7ff5bb3a73c210f45f4 Mon Sep 17 00:00:00 2001 From: kpfleming Date: Wed, 23 May 2007 20:30:24 +0000 Subject: [PATCH] don't start a PBX on a new incoming IAX2 channel until we have some sort of response to our ACCEPT (ACK or anything else) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@65679 614ede4d-c843-0410-af14-a771ab80d22e --- channels/chan_iax2.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index 10c79f31b..57ff20b5e 100644 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -268,6 +268,9 @@ enum { IAX_TRUNKTIMESTAMPS = (1 << 22), /*!< Send trunk timestamps */ IAX_TRANSFERMEDIA = (1 << 23), /*!< When doing IAX2 transfers, transfer media only */ IAX_MAXAUTHREQ = (1 << 24), /*!< Maximum outstanding AUTHREQ restriction is in place */ + IAX_DELAYPBXSTART = (1 << 25), /*!< Don't start a PBX on the channel until the peer sends us a + response, so that we've achieved a three-way handshake with + them before sending voice or anything else*/ } iax2_flags; static int global_rtautoclear = 120; @@ -3258,7 +3261,7 @@ static int iax2_getpeertrunk(struct sockaddr_in sin) } /*! \brief Create new call, interface with the PBX core */ -static struct ast_channel *ast_iax2_new(int callno, int state, int capability) +static struct ast_channel *ast_iax2_new(int callno, int state, int capability, unsigned int delaypbx) { struct ast_channel *tmp; struct chan_iax2_pvt *i; @@ -3313,7 +3316,9 @@ static struct ast_channel *ast_iax2_new(int callno, int state, int capability) for (v = i->vars ; v ; v = v->next) pbx_builtin_setvar_helper(tmp, v->name, v->value); - if (state != AST_STATE_DOWN) { + if (delaypbx) { + ast_set_flag(i, IAX_DELAYPBXSTART); + } else if (state != AST_STATE_DOWN) { if (ast_pbx_start(tmp)) { ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); ast_hangup(tmp); @@ -6708,6 +6713,16 @@ retryowner: ast_log(LOG_DEBUG, "For call=%d, set last=%d\n", fr->callno, fr->ts); } + if (ast_test_flag(iaxs[fr->callno], IAX_DELAYPBXSTART)) { + if (ast_pbx_start(iaxs[fr->callno]->owner)) { + ast_log(LOG_WARNING, "Unable to start PBX on %s\n", iaxs[fr->callno]->owner->name); + ast_hangup(iaxs[fr->callno]->owner); + iaxs[fr->callno]->owner = NULL; + ast_mutex_unlock(&iaxsl[fr->callno]); + return 1; + } + } + switch(f.subclass) { case IAX_COMMAND_ACK: /* Do nothing */ @@ -6916,7 +6931,7 @@ retryowner: VERBOSE_PREFIX_4, using_prefs); - if(!(c = ast_iax2_new(fr->callno, AST_STATE_RING, format))) + if(!(c = ast_iax2_new(fr->callno, AST_STATE_RING, format, 1))) iax2_destroy(fr->callno); } else { ast_set_flag(&iaxs[fr->callno]->state, IAX_STATE_TBD); @@ -7298,7 +7313,7 @@ retryowner2: using_prefs); ast_set_flag(&iaxs[fr->callno]->state, IAX_STATE_STARTED); - if(!(c = ast_iax2_new(fr->callno, AST_STATE_RING, format))) + if(!(c = ast_iax2_new(fr->callno, AST_STATE_RING, format, 0))) iax2_destroy(fr->callno); } else { ast_set_flag(&iaxs[fr->callno]->state, IAX_STATE_TBD); @@ -7326,7 +7341,7 @@ retryowner2: ast_verbose(VERBOSE_PREFIX_3 "Accepting DIAL from %s, formats = 0x%x\n", ast_inet_ntoa(sin.sin_addr), iaxs[fr->callno]->peerformat); ast_set_flag(&iaxs[fr->callno]->state, IAX_STATE_STARTED); send_command(iaxs[fr->callno], AST_FRAME_CONTROL, AST_CONTROL_PROGRESS, 0, NULL, 0, -1); - if(!(c = ast_iax2_new(fr->callno, AST_STATE_RING, iaxs[fr->callno]->peerformat))) + if(!(c = ast_iax2_new(fr->callno, AST_STATE_RING, iaxs[fr->callno]->peerformat, 0))) iax2_destroy(fr->callno); } } @@ -8015,7 +8030,7 @@ static struct ast_channel *iax2_request(const char *type, int format, void *data if (cai.found) ast_string_field_set(iaxs[callno], host, pds.peer); - c = ast_iax2_new(callno, AST_STATE_DOWN, cai.capability); + c = ast_iax2_new(callno, AST_STATE_DOWN, cai.capability, 0); ast_mutex_unlock(&iaxsl[callno]); -- 2.11.4.GIT