From a7733c579b25c8d5c30b77e76e21e5dc46a5420a Mon Sep 17 00:00:00 2001 From: Jonathan Rose Date: Thu, 17 May 2012 14:40:07 +0000 Subject: [PATCH] chan_sip: Fix missed locking of opposing pvt for directmedia acl from r366547 It also required deadlock avoidance since two sip_pvts structs needed to be locked simultaneously. Trunk handles it differently, so this is a 1.8 and 10 patch only. (issue AST-876) git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@366791 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_sip.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 93b191dfc7..7b89edb61b 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -29083,11 +29083,19 @@ static struct ast_udptl *sip_get_udptl_peer(struct ast_channel *chan) } sip_pvt_lock(p); + while (sip_pvt_trylock(opp)) { + sip_pvt_unlock(p); + usleep(1); + sip_pvt_lock(p); + } + if (p->udptl && ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA)) { if (apply_directmedia_ha(p, opp, "UDPTL T.38 data")) { udptl = p->udptl; } } + + sip_pvt_unlock(opp); sip_pvt_unlock(p); return udptl; } @@ -29153,7 +29161,14 @@ static enum ast_rtp_glue_result sip_get_rtp_peer(struct ast_channel *chan, struc } sip_pvt_lock(p); + while (sip_pvt_trylock(opp)) { + sip_pvt_unlock(p); + usleep(1); + sip_pvt_lock(p); + } + if (!(p->rtp)) { + sip_pvt_unlock(opp); sip_pvt_unlock(p); return AST_RTP_GLUE_RESULT_FORBID; } @@ -29172,6 +29187,8 @@ static enum ast_rtp_glue_result sip_get_rtp_peer(struct ast_channel *chan, struc res = AST_RTP_GLUE_RESULT_FORBID; } + sip_pvt_unlock(opp); + if (p->srtp) { res = AST_RTP_GLUE_RESULT_FORBID; } @@ -29199,7 +29216,14 @@ static enum ast_rtp_glue_result sip_get_vrtp_peer(struct ast_channel *chan, stru } sip_pvt_lock(p); + while (sip_pvt_trylock(opp)) { + sip_pvt_unlock(p); + usleep(1); + sip_pvt_lock(p); + } + if (!(p->vrtp)) { + sip_pvt_unlock(opp); sip_pvt_unlock(p); return AST_RTP_GLUE_RESULT_FORBID; } @@ -29214,6 +29238,7 @@ static enum ast_rtp_glue_result sip_get_vrtp_peer(struct ast_channel *chan, stru } } + sip_pvt_unlock(opp); sip_pvt_unlock(p); return res; @@ -29237,7 +29262,14 @@ static enum ast_rtp_glue_result sip_get_trtp_peer(struct ast_channel *chan, stru } sip_pvt_lock(p); + while (sip_pvt_trylock(opp)) { + sip_pvt_unlock(p); + usleep(1); + sip_pvt_lock(p); + } + if (!(p->trtp)) { + sip_pvt_unlock(opp); sip_pvt_unlock(p); return AST_RTP_GLUE_RESULT_FORBID; } @@ -29252,6 +29284,7 @@ static enum ast_rtp_glue_result sip_get_trtp_peer(struct ast_channel *chan, stru } } + sip_pvt_unlock(opp); sip_pvt_unlock(p); return res; -- 2.47.2