summaryrefslogtreecommitdiff
path: root/channels
diff options
context:
space:
mode:
authorSean Bright <sean@malleable.com>2013-01-28 21:09:52 +0000
committerSean Bright <sean@malleable.com>2013-01-28 21:09:52 +0000
commit986c2a18181de3a5e475dfcb1e93aa9ddeebfe65 (patch)
tree5e1da4b1a8edd68d666d284ff66fab1f28581690 /channels
parent5d41d316213486d8f62d998e249b96c3f2645d91 (diff)
Correct the number of available call numbers in IAX2.
There is currently an edge case where call number 32768 might be allocated for a call, even though the IAX2 protocol requires call numbers be only 15 bits. This resulted in some unpredictable behavior when call number 32678 is chosen. This patch was mostly written by Richard Mudgett via ReviewBoard. I'm just committing it. Review: https://reviewboard.asterisk.org/r/2293/ ........ Merged revisions 380254 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 380255 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@380256 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_iax2.c10
-rw-r--r--channels/iax2.h8
2 files changed, 11 insertions, 7 deletions
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 0b37a786f..b8ce29dd9 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -874,7 +874,7 @@ static const unsigned int CALLNO_POOL_BUCKETS = 2699;
*
* \note Contents protected by the iaxsl[] locks
*/
-static AST_LIST_HEAD_NOLOCK(, iax_frame) frame_queue[IAX_MAX_CALLS + 1];
+static AST_LIST_HEAD_NOLOCK(, iax_frame) frame_queue[IAX_MAX_CALLS];
static struct ast_taskprocessor *transmit_processor;
@@ -1076,7 +1076,7 @@ static void signal_condition(ast_mutex_t *lock, ast_cond_t *cond)
* based on the local call number. The local call number is used as the
* index into the array where the associated pvt structure is stored.
*/
-static struct chan_iax2_pvt *iaxs[IAX_MAX_CALLS + 1];
+static struct chan_iax2_pvt *iaxs[IAX_MAX_CALLS];
static struct ast_callid *iax_pvt_callid_get(int callno)
{
@@ -1133,7 +1133,7 @@ static struct ao2_container *iax_transfercallno_pvts;
/* Flag to use with trunk calls, keeping these calls high up. It halves our effective use
but keeps the division between trunked and non-trunked better. */
-#define TRUNK_CALL_START IAX_MAX_CALLS / 2
+#define TRUNK_CALL_START (IAX_MAX_CALLS / 2)
/* Debug routines... */
static struct sockaddr_in debugaddr;
@@ -2152,7 +2152,7 @@ static int make_trunk(unsigned short callno, int locked)
ast_log(LOG_WARNING, "Can't make trunk once a call has started!\n");
return -1;
}
- if (callno & TRUNK_CALL_START) {
+ if (callno >= TRUNK_CALL_START) {
ast_log(LOG_WARNING, "Call %d is already a trunk\n", callno);
return -1;
}
@@ -2803,7 +2803,7 @@ static int create_callno_pools(void)
}
/* start at 2, 0 and 1 are reserved */
- for (i = 2; i <= IAX_MAX_CALLS; i++) {
+ for (i = 2; i < IAX_MAX_CALLS; i++) {
struct callno_entry *callno_entry;
if (!(callno_entry = ao2_alloc(sizeof(*callno_entry), NULL))) {
diff --git a/channels/iax2.h b/channels/iax2.h
index c064b1fcb..ca9ab74dd 100644
--- a/channels/iax2.h
+++ b/channels/iax2.h
@@ -26,9 +26,13 @@
/* Max version of IAX protocol we support */
#define IAX_PROTO_VERSION 2
-/* NOTE: IT IS CRITICAL THAT IAX_MAX_CALLS BE A POWER OF 2. */
+/* NOTE: It is recommended that IAX_MAX_CALLS be a power of 2, but it is not
+ * required. The maximum number of calls supported by the protocol is 32768.
+ *
+ * For LOW_MEMORY, we use 2049 for compatibility with earlier code because
+ * callno 2048 leaked out when the intended callno range was 2 - 2047. */
#if defined(LOW_MEMORY)
-#define IAX_MAX_CALLS 2048
+#define IAX_MAX_CALLS 2049
#else
#define IAX_MAX_CALLS 32768
#endif