aboutsummaryrefslogtreecommitdiffstats
path: root/channels
diff options
context:
space:
mode:
authorfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2006-06-21 16:50:24 +0000
committerfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2006-06-21 16:50:24 +0000
commit6ceeba67f19ca8e2a7a559266c4131eb3524bf1a (patch)
tree78ff864912211d78b54fb0da1a37bc44bc25d9ba /channels
parent8420c9b6003a408411b4a74a33872a3636aabced (diff)
Fix timing issue (race) with poke/pong for very close peers that can cause a peer to be declared unreachable (issue #7396 reported by stevedavies)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@35264 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_iax2.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 7442a06b3..c98514adc 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -336,7 +336,7 @@ struct iax2_peer {
/* Qualification */
int callno; /*!< Call number of POKE request */
- int pokeexpire; /*!< When to expire poke */
+ int pokeexpire; /*!< Scheduled qualification-related task (ie iax2_poke_peer_s or iax2_poke_noanswer) */
int lastms; /*!< How long last response took (in ms), or -1 for no response */
int maxms; /*!< Max ms we will accept for the host to be up, 0 to not monitor */
@@ -7143,18 +7143,21 @@ retryowner2:
else
peer->historicms = iaxs[fr->callno]->pingtime;
+ /* Remove scheduled iax2_poke_noanswer */
if (peer->pokeexpire > -1)
ast_sched_del(sched, peer->pokeexpire);
- send_command_immediate(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr->ts, NULL, 0,fr->iseqno);
- iax2_destroy_nolock(fr->callno);
- peer->callno = 0;
- /* Try again eventually */
- if (option_debug)
- ast_log(LOG_DEBUG, "Peer lastms %d, historicms %d, maxms %d\n", peer->lastms, peer->historicms, peer->maxms);
+ /* Schedule the next cycle */
if ((peer->lastms < 0) || (peer->historicms > peer->maxms))
peer->pokeexpire = ast_sched_add(sched, peer->pokefreqnotok, iax2_poke_peer_s, peer);
else
peer->pokeexpire = ast_sched_add(sched, peer->pokefreqok, iax2_poke_peer_s, peer);
+ /* and finally send the ack */
+ send_command_immediate(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr->ts, NULL, 0,fr->iseqno);
+ /* And wrap up the qualify call */
+ iax2_destroy_nolock(fr->callno);
+ peer->callno = 0;
+ if (option_debug)
+ ast_log(LOG_DEBUG, "Peer %s: got pong, lastms %d, historicms %d, maxms %d\n", peer->name, peer->lastms, peer->historicms, peer->maxms);
}
break;
case IAX_COMMAND_LAGRQ:
@@ -7955,7 +7958,7 @@ static int iax2_poke_peer(struct iax2_peer *peer, int heldcall)
{
if (!peer->maxms || !peer->addr.sin_addr.s_addr) {
/* IF we have no IP, or this isn't to be monitored, return
- imeediately after clearing things out */
+ immediately after clearing things out */
peer->lastms = 0;
peer->historicms = 0;
peer->pokeexpire = -1;
@@ -7975,19 +7978,25 @@ static int iax2_poke_peer(struct iax2_peer *peer, int heldcall)
ast_log(LOG_WARNING, "Unable to allocate call for poking peer '%s'\n", peer->name);
return -1;
}
- if (peer->pokeexpire > -1)
- ast_sched_del(sched, peer->pokeexpire);
- /* Speed up retransmission times */
+
+ /* Speed up retransmission times for this qualify call */
iaxs[peer->callno]->pingtime = peer->maxms / 4 + 1;
iaxs[peer->callno]->peerpoke = peer;
- send_command(iaxs[peer->callno], AST_FRAME_IAX, IAX_COMMAND_POKE, 0, NULL, 0, -1);
+ /* Remove any pending pokeexpire task */
+ if (peer->pokeexpire > -1)
+ ast_sched_del(sched, peer->pokeexpire);
+
+ /* Queue up a new task to handle no reply */
/* If the host is already unreachable then use the unreachable interval instead */
if (peer->lastms < 0) {
peer->pokeexpire = ast_sched_add(sched, peer->pokefreqnotok, iax2_poke_noanswer, peer);
} else
peer->pokeexpire = ast_sched_add(sched, DEFAULT_MAXMS * 2, iax2_poke_noanswer, peer);
+ /* And send the poke */
+ send_command(iaxs[peer->callno], AST_FRAME_IAX, IAX_COMMAND_POKE, 0, NULL, 0, -1);
+
return 0;
}