[asterisk-commits] mmichelson: branch mmichelson/imap_consistency_trunk r135438 - in /team/mmich...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Aug 4 09:52:45 CDT 2008
Author: mmichelson
Date: Mon Aug 4 09:52:44 2008
New Revision: 135438
URL: http://svn.digium.com/view/asterisk?view=rev&rev=135438
Log:
Resolve a conflict and reset automerge!
Added:
team/mmichelson/imap_consistency_trunk/doc/hoard.txt
- copied unchanged from r135405, trunk/doc/hoard.txt
Modified:
team/mmichelson/imap_consistency_trunk/ (props changed)
team/mmichelson/imap_consistency_trunk/CHANGES
team/mmichelson/imap_consistency_trunk/apps/app_ices.c
team/mmichelson/imap_consistency_trunk/apps/app_voicemail.c
team/mmichelson/imap_consistency_trunk/build_tools/cflags.xml
team/mmichelson/imap_consistency_trunk/build_tools/menuselect-deps.in
team/mmichelson/imap_consistency_trunk/channels/chan_iax2.c
team/mmichelson/imap_consistency_trunk/channels/chan_mgcp.c
team/mmichelson/imap_consistency_trunk/channels/chan_sip.c
team/mmichelson/imap_consistency_trunk/channels/chan_skinny.c
team/mmichelson/imap_consistency_trunk/channels/iax2-parser.c
team/mmichelson/imap_consistency_trunk/channels/iax2.h
team/mmichelson/imap_consistency_trunk/configs/iax.conf.sample
team/mmichelson/imap_consistency_trunk/configs/sip.conf.sample
team/mmichelson/imap_consistency_trunk/configs/voicemail.conf.sample
team/mmichelson/imap_consistency_trunk/configure
team/mmichelson/imap_consistency_trunk/configure.ac
team/mmichelson/imap_consistency_trunk/contrib/scripts/safe_asterisk
team/mmichelson/imap_consistency_trunk/include/asterisk/autoconfig.h.in
team/mmichelson/imap_consistency_trunk/main/Makefile
team/mmichelson/imap_consistency_trunk/main/features.c
team/mmichelson/imap_consistency_trunk/main/http.c
team/mmichelson/imap_consistency_trunk/main/pbx.c
team/mmichelson/imap_consistency_trunk/makeopts.in
team/mmichelson/imap_consistency_trunk/res/res_http_post.c
Propchange: team/mmichelson/imap_consistency_trunk/
------------------------------------------------------------------------------
automerge = *
Propchange: team/mmichelson/imap_consistency_trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.
Propchange: team/mmichelson/imap_consistency_trunk/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Aug 4 09:52:44 2008
@@ -1,1 +1,1 @@
-/trunk:1-135047
+/trunk:1-135437
Modified: team/mmichelson/imap_consistency_trunk/CHANGES
URL: http://svn.digium.com/view/asterisk/team/mmichelson/imap_consistency_trunk/CHANGES?view=diff&rev=135438&r1=135437&r2=135438
==============================================================================
--- team/mmichelson/imap_consistency_trunk/CHANGES (original)
+++ team/mmichelson/imap_consistency_trunk/CHANGES Mon Aug 4 09:52:44 2008
@@ -137,6 +137,10 @@
IAX Changes
-----------
* Existing DNS manager lookups extended to check for SRV records.
+ * IAX2 encryption support has been improved to support periodic key rotation
+ within a call for enhanced security. The option "keyrotate" has been
+ provided to disable this functionality to preserve backwards compatibility
+ with older versions of IAX2 that do not support key rotation.
CLI Changes
-----------
@@ -193,6 +197,8 @@
the 'setvar' option to cause a given audio file to be played upon completion
of an attended transfer. Currently it works for DAHDI, IAX2, SIP, and
Skinny channels only.
+ * You can now compile Asterisk against the Hoard Memory Allocator, see doc/hoard.txt
+ for more information.
------------------------------------------------------------------------------
--- Functionality changes from Asterisk 1.4.X to Asterisk 1.6.0 -------------
Modified: team/mmichelson/imap_consistency_trunk/apps/app_ices.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/imap_consistency_trunk/apps/app_ices.c?view=diff&rev=135438&r1=135437&r2=135438
==============================================================================
--- team/mmichelson/imap_consistency_trunk/apps/app_ices.c (original)
+++ team/mmichelson/imap_consistency_trunk/apps/app_ices.c Mon Aug 4 09:52:44 2008
@@ -80,15 +80,15 @@
* But many places has it in /usr/bin
* As a last-ditch effort, try to use PATH
*/
- execl(path_LOCAL "ices2", "ices", filename, NULL);
- execl(path_BIN "ices2", "ices", filename, NULL);
- execlp("ices2", "ices", filename, NULL);
+ execl(path_LOCAL "ices2", "ices", filename, SENTINEL);
+ execl(path_BIN "ices2", "ices", filename, SENTINEL);
+ execlp("ices2", "ices", filename, SENTINEL);
ast_debug(1, "Couldn't find ices version 2, attempting to use ices version 1.");
- execl(path_LOCAL "ices", "ices", filename, NULL);
- execl(path_BIN "ices", "ices", filename, NULL);
- execlp("ices", "ices", filename, NULL);
+ execl(path_LOCAL "ices", "ices", filename, SENTINEL);
+ execl(path_BIN "ices", "ices", filename, SENTINEL);
+ execlp("ices", "ices", filename, SENTINEL);
ast_log(LOG_WARNING, "Execute of ices failed, could not find command.\n");
close(fd);
Modified: team/mmichelson/imap_consistency_trunk/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/imap_consistency_trunk/apps/app_voicemail.c?view=diff&rev=135438&r1=135437&r2=135438
==============================================================================
--- team/mmichelson/imap_consistency_trunk/apps/app_voicemail.c (original)
+++ team/mmichelson/imap_consistency_trunk/apps/app_voicemail.c Mon Aug 4 09:52:44 2008
@@ -125,6 +125,7 @@
static char imapport[8];
static char imapflags[128];
static char imapfolder[64];
+static char imapparentfolder[64] = "\0";
static char greetingfolder[64];
static char authuser[32];
static char authpassword[42];
@@ -1988,13 +1989,18 @@
/* End with username */
ast_build_string(&t, &left, "/user=%s}", vms->imapuser);
-
if (box == NEW_FOLDER || box == OLD_FOLDER)
snprintf(spec, len, "%s%s", tmp, use_folder? imapfolder: "INBOX");
else if (box == GREETINGS_FOLDER)
snprintf(spec, len, "%s%s", tmp, greetingfolder);
- else
- snprintf(spec, len, "%s%s%c%s", tmp, imapfolder, delimiter, mbox(box));
+ else { /* Other folders such as Friends, Family, etc... */
+ if (!ast_strlen_zero(imapparentfolder)) {
+ /* imapparentfolder would typically be set to INBOX */
+ snprintf(spec, len, "%s%s%c%s", tmp, imapparentfolder, delimiter, mbox(box));
+ } else {
+ snprintf(spec, len, "%s%s", tmp, mbox(box));
+ }
+ }
}
static int init_mailstream(struct vm_state *vms, int box)
@@ -9919,7 +9925,9 @@
ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
ucfg = ast_config_load("users.conf", config_flags);
}
-
+#ifdef IMAP_STORAGE
+ ast_copy_string(imapparentfolder, "\0", sizeof(imapparentfolder));
+#endif
/* set audio control prompts */
strcpy(listen_control_forward_key,DEFAULT_LISTEN_CONTROL_FORWARD_KEY);
strcpy(listen_control_reverse_key,DEFAULT_LISTEN_CONTROL_REVERSE_KEY);
@@ -10073,6 +10081,9 @@
ast_copy_string(imapfolder, val, sizeof(imapfolder));
} else {
ast_copy_string(imapfolder,"INBOX", sizeof(imapfolder));
+ }
+ if ((val = ast_variable_retrieve(cfg, "general", "imapparentfolder"))) {
+ ast_copy_string(imapparentfolder, val, sizeof(imapparentfolder));
}
if ((val = ast_variable_retrieve(cfg, "general", "imapgreetings"))) {
imapgreetings = ast_true(val);
Modified: team/mmichelson/imap_consistency_trunk/build_tools/cflags.xml
URL: http://svn.digium.com/view/asterisk/team/mmichelson/imap_consistency_trunk/build_tools/cflags.xml?view=diff&rev=135438&r1=135437&r2=135438
==============================================================================
--- team/mmichelson/imap_consistency_trunk/build_tools/cflags.xml (original)
+++ team/mmichelson/imap_consistency_trunk/build_tools/cflags.xml Mon Aug 4 09:52:44 2008
@@ -9,6 +9,10 @@
<defaultenabled>yes</defaultenabled>
</member>
<member name="LOW_MEMORY" displayname="Optimize for Low Memory Usage">
+ </member>
+ <member name="USE_HOARD_ALLOCATOR" displayname="Use the Hoard Memory Allocator instead of the default system one">
+ <defaultenabled>no</defaultenabled>
+ <depend>hoard</depend>
</member>
<member name="LOTS_OF_SPANS" displayname="More than 32 DAHDI spans">
</member>
Modified: team/mmichelson/imap_consistency_trunk/build_tools/menuselect-deps.in
URL: http://svn.digium.com/view/asterisk/team/mmichelson/imap_consistency_trunk/build_tools/menuselect-deps.in?view=diff&rev=135438&r1=135437&r2=135438
==============================================================================
--- team/mmichelson/imap_consistency_trunk/build_tools/menuselect-deps.in (original)
+++ team/mmichelson/imap_consistency_trunk/build_tools/menuselect-deps.in Mon Aug 4 09:52:44 2008
@@ -9,6 +9,7 @@
GTK2=@PBX_GTK2@
GTK=@PBX_GTK@
H323=@PBX_H323@
+HOARD=@PBX_HOARD@
ICONV=@PBX_ICONV@
IKSEMEL=@PBX_IKSEMEL@
IMAP_TK=@PBX_IMAP_TK@
Modified: team/mmichelson/imap_consistency_trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/imap_consistency_trunk/channels/chan_iax2.c?view=diff&rev=135438&r1=135437&r2=135438
==============================================================================
--- team/mmichelson/imap_consistency_trunk/channels/chan_iax2.c (original)
+++ team/mmichelson/imap_consistency_trunk/channels/chan_iax2.c Mon Aug 4 09:52:44 2008
@@ -203,6 +203,23 @@
#define DEFAULT_FREQ_OK 60 * 1000 /* How often to check for the host to be up */
#define DEFAULT_FREQ_NOTOK 10 * 1000 /* How often to check, if the host is down... */
+/* if a pvt has encryption setup done and is running on the call */
+#define IAX_CALLENCRYPTED(pvt) \
+ (ast_test_flag(pvt, IAX_ENCRYPTED) && ast_test_flag(pvt, IAX_KEYPOPULATED))
+
+#define IAX_DEBUGDIGEST(msg, key) do { \
+ int idx; \
+ char digest[33] = ""; \
+ \
+ if (!iaxdebug) \
+ break; \
+ \
+ for (idx = 0; idx < 16; idx++) \
+ sprintf(digest + (idx << 1), "%2.2x", (unsigned char) key[idx]); \
+ \
+ ast_log(LOG_NOTICE, msg " IAX_COMMAND_RTKEY to rotate key to '%s'\n", digest); \
+ } while(0)
+
static struct io_context *io;
static struct sched_context *sched;
@@ -277,6 +294,7 @@
response, so that we've achieved a three-way handshake with
them before sending voice or anything else*/
IAX_ALLOWFWDOWNLOAD = (1 << 26), /*!< Allow the FWDOWNL command? */
+ IAX_NOKEYROTATE = (1 << 27), /*!< Disable key rotation with encryption */
};
static int global_rtautoclear = 120;
@@ -588,6 +606,9 @@
ast_aes_encrypt_key ecx;
/*! Decryption AES-128 Key */
ast_aes_decrypt_key dcx;
+ /*! scheduler id associated with iax_key_rotate
+ * for encrypted calls*/
+ int keyrotateid;
/*! 32 bytes of semi-random data */
unsigned char semirand[32];
/*! Associated registry */
@@ -1411,6 +1432,7 @@
AST_SCHED_DEL(sched, pvt->authid);
AST_SCHED_DEL(sched, pvt->initid);
AST_SCHED_DEL(sched, pvt->jbid);
+ AST_SCHED_DEL(sched, pvt->keyrotateid);
}
static void iax2_frame_free(struct iax_frame *fr)
@@ -1479,6 +1501,7 @@
tmp->autoid = -1;
tmp->authid = -1;
tmp->initid = -1;
+ tmp->keyrotateid = -1;
ast_string_field_set(tmp,exten, "s");
ast_string_field_set(tmp,host, host);
@@ -1768,7 +1791,7 @@
iaxs[x]->pingid = iax2_sched_add(sched, ping_time * 1000, send_ping, (void *)(long)x);
iaxs[x]->lagid = iax2_sched_add(sched, lagrq_time * 1000, send_lagrq, (void *)(long)x);
iaxs[x]->amaflags = amaflags;
- ast_copy_flags(iaxs[x], (&globalflags), IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);
+ ast_copy_flags(iaxs[x], &globalflags, IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_NOKEYROTATE);
ast_string_field_set(iaxs[x], accountcode, accountcode);
ast_string_field_set(iaxs[x], mohinterpret, mohinterpret);
@@ -3384,7 +3407,7 @@
if (peer->maxms && ((peer->lastms > peer->maxms) || (peer->lastms < 0)))
goto return_unref;
- ast_copy_flags(cai, peer, IAX_SENDANI | IAX_TRUNK | IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);
+ ast_copy_flags(cai, peer, IAX_SENDANI | IAX_TRUNK | IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_NOKEYROTATE);
cai->maxtime = peer->maxms;
cai->capability = peer->capability;
cai->encmethods = peer->encmethods;
@@ -3808,12 +3831,54 @@
return &ast_null_frame;
}
+static int iax2_key_rotate(const void *vpvt)
+{
+ int res = 0;
+ struct chan_iax2_pvt *pvt = (void *) vpvt;
+ struct MD5Context md5;
+ char key[17] = "";
+ struct iax_ie_data ied = {
+ .pos = 0,
+ };
+
+ ast_mutex_lock(&iaxsl[pvt->callno]);
+
+ pvt->keyrotateid =
+ ast_sched_add(sched, 120000 + (ast_random() % 180001), iax2_key_rotate, vpvt);
+
+ snprintf(key, sizeof(key), "%lX", ast_random());
+
+ MD5Init(&md5);
+ MD5Update(&md5, (unsigned char *) key, strlen(key));
+ MD5Final((unsigned char *) key, &md5);
+
+ IAX_DEBUGDIGEST("Sending", key);
+
+ iax_ie_append_raw(&ied, IAX_IE_CHALLENGE, key, 16);
+
+ res = send_command(pvt, AST_FRAME_IAX, IAX_COMMAND_RTKEY, 0, ied.buf, ied.pos, -1);
+
+ ast_aes_encrypt_key((unsigned char *) key, &pvt->ecx);
+
+ ast_mutex_unlock(&iaxsl[pvt->callno]);
+
+ return res;
+}
+
static int iax2_start_transfer(unsigned short callno0, unsigned short callno1, int mediaonly)
{
int res;
struct iax_ie_data ied0;
struct iax_ie_data ied1;
unsigned int transferid = (unsigned int)ast_random();
+
+ if (IAX_CALLENCRYPTED(iaxs[callno0]) || IAX_CALLENCRYPTED(iaxs[callno1])) {
+ ast_debug(1, "transfers are not supported for encrypted calls at this time");
+ ast_set_flag(iaxs[callno0], IAX_NOTRANSFER);
+ ast_set_flag(iaxs[callno1], IAX_NOTRANSFER);
+ return 0;
+ }
+
memset(&ied0, 0, sizeof(ied0));
iaxs[callno0]->transferid = transferid;
iax_ie_append_addr(&ied0, IAX_IE_APPARENT_ADDR, &iaxs[callno1]->addr);
@@ -4720,8 +4785,23 @@
* (the endpoint should detect the lost packet itself). But, we want to do this here, so that we
* increment the "predicted timestamps" for voice, if we're predicting */
if(f->frametype == AST_FRAME_VOICE && f->datalen == 0)
- return 0;
-
+ return 0;
+#if 0
+ ast_log(LOG_NOTICE,
+ "f->frametype %c= AST_FRAME_VOICE, %sencrypted, %srotation scheduled...\n",
+ *("=!" + (f->frametype == AST_FRAME_VOICE)),
+ IAX_CALLENCRYPTED(pvt) ? "" : "not ",
+ pvt->keyrotateid != -1 ? "" : "no "
+ );
+#endif
+
+ if (pvt->keyrotateid == -1 && f->frametype == AST_FRAME_VOICE && IAX_CALLENCRYPTED(pvt)) {
+ if (ast_test_flag(pvt, IAX_NOKEYROTATE)) {
+ pvt->keyrotateid = -2;
+ } else {
+ iax2_key_rotate(pvt);
+ }
+ }
if ((ast_test_flag(pvt, IAX_TRUNK) ||
(((fts & 0xFFFF0000L) == (lastsent & 0xFFFF0000L)) ||
@@ -5896,6 +5976,7 @@
ast_copy_flags(iaxs[callno], user, IAX_CODEC_USER_FIRST);
ast_copy_flags(iaxs[callno], user, IAX_CODEC_NOPREFS);
ast_copy_flags(iaxs[callno], user, IAX_CODEC_NOCAP);
+ ast_copy_flags(iaxs[callno], user, IAX_NOKEYROTATE);
iaxs[callno]->encmethods = user->encmethods;
/* Store the requested username if not specified */
if (ast_strlen_zero(iaxs[callno]->username))
@@ -9394,7 +9475,20 @@
iaxs[fr->callno]->transferring = TRANSFER_NONE;
iaxs[fr->callno]->mediareleased = 1;
}
- break;
+ break;
+ case IAX_COMMAND_RTKEY:
+ if (!IAX_CALLENCRYPTED(iaxs[fr->callno])) {
+ ast_log(LOG_WARNING,
+ "we've been told to rotate our encryption key, "
+ "but this isn't an encrypted call. bad things will happen.\n"
+ );
+ break;
+ }
+
+ IAX_DEBUGDIGEST("Receiving", ies.challenge);
+
+ ast_aes_decrypt_key((unsigned char *) ies.challenge, &iaxs[fr->callno]->dcx);
+ break;
case IAX_COMMAND_DPREP:
complete_dpreply(iaxs[fr->callno], &ies);
break;
@@ -9993,7 +10087,7 @@
memset(&cai, 0, sizeof(cai));
cai.capability = iax2_capability;
- ast_copy_flags(&cai, &globalflags, IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);
+ ast_copy_flags(&cai, &globalflags, IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_NOKEYROTATE);
/* Populate our address from the given */
if (create_addr(pds.peer, NULL, &sin, &cai)) {
@@ -10012,7 +10106,7 @@
}
/* If this is a trunk, update it now */
- ast_copy_flags(iaxs[callno], &cai, IAX_TRUNK | IAX_SENDANI | IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);
+ ast_copy_flags(iaxs[callno], &cai, IAX_TRUNK | IAX_SENDANI | IAX_NOTRANSFER | IAX_TRANSFERMEDIA | IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_NOKEYROTATE);
if (ast_test_flag(&cai, IAX_TRUNK)) {
int new_callno;
if ((new_callno = make_trunk(callno, 1)) != -1)
@@ -10353,6 +10447,9 @@
if (peer) {
if (firstpass) {
+ if (ast_test_flag(&globalflags, IAX_NOKEYROTATE)) {
+ ast_copy_flags(peer, &globalflags, IAX_NOKEYROTATE);
+ }
ast_copy_flags(peer, &globalflags, IAX_USEJITTERBUF | IAX_FORCEJITTERBUF);
peer->encmethods = iax2_encryption;
peer->adsi = adsi;
@@ -10403,6 +10500,11 @@
peer->authmethods = get_auth_methods(v->value);
} else if (!strcasecmp(v->name, "encryption")) {
peer->encmethods = get_encrypt_methods(v->value);
+ } else if (!strcasecmp(v->name, "keyrotate")) {
+ if (ast_false(v->value))
+ ast_set_flag(peer, IAX_NOKEYROTATE);
+ else
+ ast_clear_flag(peer, IAX_NOKEYROTATE);
} else if (!strcasecmp(v->name, "transfer")) {
if (!strcasecmp(v->value, "mediaonly")) {
ast_set_flags_to(peer, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_TRANSFERMEDIA);
@@ -10625,7 +10727,7 @@
user->adsi = adsi;
ast_string_field_set(user, name, name);
ast_string_field_set(user, language, language);
- ast_copy_flags(user, &globalflags, IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_CODEC_USER_FIRST | IAX_CODEC_NOPREFS | IAX_CODEC_NOCAP);
+ ast_copy_flags(user, &globalflags, IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_CODEC_USER_FIRST | IAX_CODEC_NOPREFS | IAX_CODEC_NOCAP | IAX_NOKEYROTATE);
ast_clear_flag(user, IAX_HASCALLERID);
ast_string_field_set(user, cid_name, "");
ast_string_field_set(user, cid_num, "");
@@ -10671,6 +10773,11 @@
user->authmethods = get_auth_methods(v->value);
} else if (!strcasecmp(v->name, "encryption")) {
user->encmethods = get_encrypt_methods(v->value);
+ } else if (!strcasecmp(v->name, "keyrotate")) {
+ if (ast_false(v->value))
+ ast_set_flag(user, IAX_NOKEYROTATE);
+ else
+ ast_clear_flag(user, IAX_NOKEYROTATE);
} else if (!strcasecmp(v->name, "transfer")) {
if (!strcasecmp(v->value, "mediaonly")) {
ast_set_flags_to(user, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_TRANSFERMEDIA);
@@ -11032,7 +11139,12 @@
authdebug = ast_true(v->value);
else if (!strcasecmp(v->name, "encryption"))
iax2_encryption = get_encrypt_methods(v->value);
- else if (!strcasecmp(v->name, "transfer")) {
+ else if (!strcasecmp(v->name, "keyrotate")) {
+ if (ast_false(v->value))
+ ast_set_flag((&globalflags), IAX_NOKEYROTATE);
+ else
+ ast_clear_flag((&globalflags), IAX_NOKEYROTATE);
+ } else if (!strcasecmp(v->name, "transfer")) {
if (!strcasecmp(v->value, "mediaonly")) {
ast_set_flags_to((&globalflags), IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_TRANSFERMEDIA);
} else if (ast_true(v->value)) {
Modified: team/mmichelson/imap_consistency_trunk/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/imap_consistency_trunk/channels/chan_mgcp.c?view=diff&rev=135438&r1=135437&r2=135438
==============================================================================
--- team/mmichelson/imap_consistency_trunk/channels/chan_mgcp.c (original)
+++ team/mmichelson/imap_consistency_trunk/channels/chan_mgcp.c Mon Aug 4 09:52:44 2008
@@ -2167,12 +2167,8 @@
char local[256];
char tmp[80];
int x;
- int capability;
struct mgcp_endpoint *p = sub->parent;
- capability = p->capability;
- if (codecs)
- capability = codecs;
if (ast_strlen_zero(sub->cxident) && rtp) {
/* We don't have a CXident yet, store the destination and
wait a bit */
Modified: team/mmichelson/imap_consistency_trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/imap_consistency_trunk/channels/chan_sip.c?view=diff&rev=135438&r1=135437&r2=135438
==============================================================================
--- team/mmichelson/imap_consistency_trunk/channels/chan_sip.c (original)
+++ team/mmichelson/imap_consistency_trunk/channels/chan_sip.c Mon Aug 4 09:52:44 2008
@@ -1950,6 +1950,37 @@
static int sip_refer_allocate(struct sip_pvt *p);
static void ast_quiet_chan(struct ast_channel *chan);
static int attempt_transfer(struct sip_dual *transferer, struct sip_dual *target);
+/*!
+ * \brief generic function for determining if a correct transport is being
+ * used to contact a peer
+ *
+ * this is done as a macro so that the "tmpl" var can be passed either a
+ * sip_request or a sip_peer
+ */
+#define check_request_transport(peer, tmpl) ({ \
+ int ret = 0; \
+ if (peer->socket.type == tmpl->socket.type) \
+ ; \
+ else if (!(peer->transports & tmpl->socket.type)) {\
+ ast_log(LOG_ERROR, \
+ "'%s' is not a valid transport for '%s'. we only use '%s'! ending call.\n", \
+ get_transport(tmpl->socket.type), peer->name, get_transport_list(peer) \
+ ); \
+ ret = 1; \
+ } else if (peer->socket.type & SIP_TRANSPORT_TLS) { \
+ ast_log(LOG_WARNING, \
+ "peer '%s' HAS NOT USED (OR SWITCHED TO) TLS in favor of '%s' (but this was allowed in sip.conf)!\n", \
+ peer->name, get_transport(tmpl->socket.type) \
+ ); \
+ } else { \
+ ast_debug(1, \
+ "peer '%s' has contacted us over %s even though we prefer %s.\n", \
+ peer->name, get_transport(tmpl->socket.type), get_transport(peer->socket.type) \
+ ); \
+ }\
+ (ret); \
+})
+
/*--- Device monitoring and Device/extension state/event handling */
static int cb_extensionstate(char *context, char* exten, int state, void *data);
@@ -2103,7 +2134,7 @@
static const struct sockaddr_in *sip_real_dst(const struct sip_pvt *p);
static void build_via(struct sip_pvt *p);
static int create_addr_from_peer(struct sip_pvt *r, struct sip_peer *peer);
-static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin);
+static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin, int newdialog);
static char *generate_random_string(char *buf, size_t size);
static void build_callid_pvt(struct sip_pvt *pvt);
static void build_callid_registry(struct sip_registry *reg, struct in_addr ourip, const char *fromdomain);
@@ -4135,6 +4166,11 @@
*/
static int create_addr_from_peer(struct sip_pvt *dialog, struct sip_peer *peer)
{
+ /* this checks that the dialog is contacting the peer on a valid
+ * transport type based on the peers transport configuration,
+ * otherwise, this function bails out */
+ if (dialog->socket.type && check_request_transport(peer, dialog))
+ return -1;
copy_socket_data(&dialog->socket, &peer->socket);
if ((peer->addr.sin_addr.s_addr || peer->defaddr.sin_addr.s_addr) &&
@@ -4260,10 +4296,11 @@
return 0;
}
+
/*! \brief create address structure from device name
* Or, if peer not found, find it in the global DNS
* returns TRUE (-1) on failure, FALSE on success */
-static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin)
+static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin, int newdialog)
{
struct hostent *hp;
struct ast_hostent ahp;
@@ -4284,13 +4321,12 @@
peer = find_peer(peername, NULL, TRUE, TRUE);
if (peer) {
- int res = create_addr_from_peer(dialog, peer);
+ int res;
+ if (newdialog)
+ dialog->socket.type = 0;
+ res = create_addr_from_peer(dialog, peer);
unref_peer(peer, "create_addr: unref peer from find_peer hashtab lookup");
return res;
- } else {
- /* Setup default parameters for this dialog's socket. Currently we only support regular UDP SIP as the default */
- dialog->socket.type = SIP_TRANSPORT_UDP;
- dialog->socket.port = bindaddr.sin_port;
}
ast_string_field_set(dialog, tohost, peername);
@@ -4306,7 +4342,10 @@
if (sin) {
memcpy(&dialog->sa.sin_addr, &sin->sin_addr, sizeof(dialog->sa.sin_addr));
if (!sin->sin_port) {
- portno = port ? atoi(port) : (dialog->socket.type & SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT;
+ if (ast_strlen_zero(port) || sscanf(port, "%u", &portno) != 1) {
+ portno = dialog->socket.type & SIP_TRANSPORT_TLS ?
+ STANDARD_TLS_PORT : STANDARD_SIP_PORT;
+ }
} else {
portno = ntohs(sin->sin_port);
}
@@ -4339,6 +4378,8 @@
memcpy(&dialog->sa.sin_addr, hp->h_addr, sizeof(dialog->sa.sin_addr));
}
+ if (!dialog->socket.type)
+ dialog->socket.type = SIP_TRANSPORT_UDP;
dialog->sa.sin_port = htons(portno);
dialog->recv = dialog->sa;
return 0;
@@ -4375,7 +4416,7 @@
struct sip_pvt *p = ast->tech_pvt; /* chan is locked, so the reference cannot go away */
struct varshead *headp;
struct ast_var_t *current;
- const char *referer = NULL; /* SIP referrer */
+ const char *referer = NULL; /* SIP referrer */
if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
ast_log(LOG_WARNING, "sip_call called on %s, neither down nor reserved\n", ast->name);
@@ -4406,9 +4447,8 @@
p->t38.state = T38_LOCAL_DIRECT;
ast_debug(1, "T38State change to %d on channel %s\n", p->t38.state, ast->name);
}
-
- }
-
+ }
+
res = 0;
ast_set_flag(&p->flags[0], SIP_OUTGOING);
@@ -9442,7 +9482,7 @@
return -1;
}
- if (create_addr(p, channame, NULL)) {
+ if (create_addr(p, channame, NULL, 0)) {
/* Maybe they're not registered, etc. */
dialog_unlink_all(p, TRUE, TRUE);
dialog_unref(p, "unref dialog inside for loop" );
@@ -9654,7 +9694,7 @@
r->us.sin_port = htons(r->portno);
/* Find address to hostname */
- if (create_addr(p, r->hostname, &r->us)) {
+ if (create_addr(p, r->hostname, &r->us, 0)) {
/* we have what we hope is a temporary network error,
* probably DNS. We need to reschedule a registration try */
dialog_unlink_all(p, TRUE, TRUE);
@@ -10852,27 +10892,10 @@
break;
}
- if (peer->socket.type != req->socket.type ) {
- if (!(peer->transports & req->socket.type)) {
- ast_log(LOG_ERROR,
- "peer '%s' has contacted us over %s, but we only accept '%s' for this peer! ending call.\n",
- peer->name, get_transport(req->socket.type), get_transport_list(peer)
- );
-
- ast_set_flag(&p->flags[0], SIP_PENDINGBYE);
- transmit_response_with_date(p, "403 Forbidden", req);
- res = AUTH_BAD_TRANSPORT;
- } else if (peer->socket.type & SIP_TRANSPORT_TLS) {
- ast_log(LOG_WARNING,
- "peer '%s' HAS STOPPED USING TLS in favor of '%s' (but this was allowed in sip.conf)!\n",
- peer->name, get_transport(req->socket.type)
- );
- } else {
- ast_log(LOG_DEBUG,
- "peer '%s' has contacted us over %s even though we prefer %s.\n",
- peer->name, get_transport(req->socket.type), get_transport(peer->socket.type)
- );
- }
+ if (check_request_transport(peer, req)) {
+ ast_set_flag(&p->flags[0], SIP_PENDINGBYE);
+ transmit_response_with_date(p, "403 Forbidden", req);
+ res = AUTH_BAD_TRANSPORT;
}
}
}
@@ -14423,7 +14446,7 @@
return CLI_FAILURE;
}
- if (create_addr(p, a->argv[i], NULL)) {
+ if (create_addr(p, a->argv[i], NULL, 0)) {
/* Maybe they're not registered, etc. */
dialog_unlink_all(p, TRUE, TRUE);
dialog_unref(p, "unref dialog inside for loop" );
@@ -14996,13 +15019,41 @@
static void parse_moved_contact(struct sip_pvt *p, struct sip_request *req)
{
char tmp[SIPBUFSIZE];
- char *s, *e, *t;
+ char *s, *e, *t, *trans;
char *domain;
+ enum sip_transport transport = SIP_TRANSPORT_UDP;
ast_copy_string(tmp, get_header(req, "Contact"), sizeof(tmp));
if ((t = strchr(tmp, ',')))
*t = '\0';
- s = remove_uri_parameters(get_in_brackets(tmp));
+
+ s = get_in_brackets(tmp);
+ if ((trans = strcasestr(s, ";transport="))) do {
+ trans += 11;
+
+ if ((e = strchr(trans, ';')))
+ *e = '\0';
+
+ if (!strncasecmp(trans, "tcp", 3))
+ transport = SIP_TRANSPORT_TCP;
+ else if (!strncasecmp(trans, "tls", 3))
+ transport = SIP_TRANSPORT_TLS;
+ else {
+ if (strncasecmp(trans, "udp", 3))
+ ast_debug(1, "received contact with an invalid transport, '%s'\n", s);
+ transport = SIP_TRANSPORT_UDP;
+ }
+ } while(0);
+ s = remove_uri_parameters(s);
+
+ if (p->socket.ser) {
+ ao2_ref(p->socket.ser, -1);
+ p->socket.ser = NULL;
+ }
+
+ p->socket.fd = -1;
+ p->socket.type = transport;
+
if (ast_test_flag(&p->flags[0], SIP_PROMISCREDIR)) {
if (!strncasecmp(s, "sip:", 4))
s += 4;
@@ -15011,9 +15062,9 @@
e = strchr(s, '/');
if (e)
*e = '\0';
- ast_debug(2, "Found promiscuous redirection to 'SIP/%s'\n", s);
+ ast_debug(2, "Found promiscuous redirection to 'SIP/::::%s@%s'\n", get_transport(transport), s);
if (p->owner)
- ast_string_field_build(p->owner, call_forward, "SIP/%s", s);
+ ast_string_field_build(p->owner, call_forward, "SIP/::::%s@%s", get_transport(transport), s);
} else {
e = strchr(tmp, '@');
if (e) {
@@ -17095,7 +17146,7 @@
if ((peerorhost = strchr(uri, ':'))) {
*peerorhost++ = '\0';
}
- create_addr(p, peerorhost, NULL);
+ create_addr(p, peerorhost, NULL, 0);
ast_string_field_set(p, theirtag, NULL);
for (pkt = p->packets; pkt; pkt = pkt->next) {
if (pkt->seqno == p->icseq && pkt->method == SIP_INVITE) {
@@ -20061,13 +20112,15 @@
{
struct sip_pvt *p;
struct ast_channel *tmpc = NULL;
- char *ext, *host;
+ char *ext = NULL, *host;
char tmp[256];
char *dest = data;
char *dnid;
char *secret = NULL;
char *md5secret = NULL;
char *authname = NULL;
+ char *trans = NULL;
+ enum sip_transport transport = 0;
int oldformat = format;
/* mask request with some set of allowed formats.
@@ -20119,29 +20172,48 @@
*host++ = '\0';
ext = tmp;
secret = strchr(ext, ':');
- if (secret) {
- *secret++ = '\0';
- md5secret = strchr(secret, ':');
- if (md5secret) {
- *md5secret++ = '\0';
- authname = strchr(md5secret, ':');
- if (authname)
- *authname++ = '\0';
- }
- }
- } else {
+ }
+ if (secret) {
+ *secret++ = '\0';
+ md5secret = strchr(secret, ':');
+ }
+ if (md5secret) {
+ *md5secret++ = '\0';
+ authname = strchr(md5secret, ':');
+ }
+ if (authname) {
+ *authname++ = '\0';
+ trans = strchr(authname, ':');
+ }
+ if (trans) {
+ *trans++ = '\0';
+ if (!strcasecmp(trans, "tcp"))
+ transport = SIP_TRANSPORT_TCP;
+ else if (!strcasecmp(trans, "tls"))
+ transport = SIP_TRANSPORT_TLS;
+ else {
+ if (strcasecmp(trans, "udp"))
+ ast_log(LOG_WARNING, "'%s' is not a valid transport option to Dial() for SIP calls, using udp by default.\n", trans);
+ transport = SIP_TRANSPORT_UDP;
+ }
+ }
+
+ if (!host) {
ext = strchr(tmp, '/');
if (ext)
*ext++ = '\0';
host = tmp;
}
+
+ p->socket.fd = -1;
+ p->socket.type = transport;
/* We now have
host = peer name, DNS host name or DNS domain (for SRV)
ext = extension (user part of URI)
dnid = destination of the call (applies to the To: header)
*/
- if (create_addr(p, host, NULL)) {
+ if (create_addr(p, host, NULL, 1)) {
*cause = AST_CAUSE_UNREGISTERED;
ast_debug(3, "Cant create SIP call - target device not registred\n");
dialog_unlink_all(p, TRUE, TRUE);
Modified: team/mmichelson/imap_consistency_trunk/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/imap_consistency_trunk/channels/chan_skinny.c?view=diff&rev=135438&r1=135437&r2=135438
==============================================================================
--- team/mmichelson/imap_consistency_trunk/channels/chan_skinny.c (original)
+++ team/mmichelson/imap_consistency_trunk/channels/chan_skinny.c Mon Aug 4 09:52:44 2008
@@ -1823,8 +1823,9 @@
return -1; /* main loop will destroy the session */
}
-static int transmit_response(struct skinnysession *s, struct skinny_req *req)
-{
+static int transmit_response(struct skinny_device *d, struct skinny_req *req)
+{
+ struct skinnysession *s = d->session;
int res = 0;
if (!s) {
@@ -1839,10 +1840,11 @@
if (letohl(req->len > SKINNY_MAX_PACKET) || letohl(req->len < 0)) {
ast_log(LOG_WARNING, "transmit_response: the length of the request is out of bounds\n");
+ ast_mutex_unlock(&s->lock);
return -1;
}
- memset(s->outbuf,0,sizeof(s->outbuf));
+ memset(s->outbuf, 0, sizeof(s->outbuf));
memcpy(s->outbuf, req, skinny_header_size);
memcpy(s->outbuf+skinny_header_size, &req->data, letohl(req->len));
@@ -1862,7 +1864,7 @@
return 1;
}
-static void transmit_speaker_mode(struct skinnysession *s, int mode)
+static void transmit_speaker_mode(struct skinny_device *d, int mode)
{
struct skinny_req *req;
@@ -1870,10 +1872,10 @@
return;
req->data.setspeaker.mode = htolel(mode);
- transmit_response(s, req);
+ transmit_response(d, req);
}
/*
-static void transmit_microphone_mode(struct skinnysession *s, int mode)
+static void transmit_microphone_mode(struct skinny_device *d, int mode)
{
struct skinny_req *req;
@@ -1881,23 +1883,23 @@
return;
req->data.setmicrophone.mode = htolel(mode);
- transmit_response(s, req);
+ transmit_response(d, req);
}
*/
-static void transmit_callinfo(struct skinnysession *s, const char *fromname, const char *fromnum, const char *toname, const char *tonum, int instance, int callid, int calltype)
+static void transmit_callinfo(struct skinny_device *d, const char *fromname, const char *fromnum, const char *toname, const char *tonum, int instance, int callid, int calltype)
{
struct skinny_req *req;
- /* We should not be able to get here without a session */
- if (!s)
+ /* We should not be able to get here without a device */
+ if (!d)
return;
if (!(req = req_alloc(sizeof(struct call_info_message), CALL_INFO_MESSAGE)))
return;
if (skinnydebug)
- ast_verb(1, "Setting Callinfo to %s(%s) from %s(%s) on %s(%d)\n", fromname, fromnum, toname, tonum, s->device->name, instance);
+ ast_verb(1, "Setting Callinfo to %s(%s) from %s(%s) on %s(%d)\n", fromname, fromnum, toname, tonum, d->name, instance);
if (fromname) {
ast_copy_string(req->data.callinfo.callingPartyName, fromname, sizeof(req->data.callinfo.callingPartyName));
@@ -1914,10 +1916,10 @@
req->data.callinfo.instance = htolel(instance);
req->data.callinfo.reference = htolel(callid);
req->data.callinfo.type = htolel(calltype);
- transmit_response(s, req);
-}
-
-static void transmit_connect(struct skinnysession *s, struct skinny_subchannel *sub)
+ transmit_response(d, req);
+}
+
+static void transmit_connect(struct skinny_device *d, struct skinny_subchannel *sub)
{
struct skinny_req *req;
struct skinny_line *l = sub->parent;
@@ -1934,10 +1936,10 @@
req->data.openreceivechannel.capability = htolel(codec_ast2skinny(fmt.bits));
req->data.openreceivechannel.echo = htolel(0);
req->data.openreceivechannel.bitrate = htolel(0);
- transmit_response(s, req);
-}
-
-static void transmit_tone(struct skinnysession *s, int tone, int instance, int reference)
+ transmit_response(d, req);
+}
+
+static void transmit_tone(struct skinny_device *d, int tone, int instance, int reference)
{
struct skinny_req *req;
@@ -1962,10 +1964,10 @@
if (tone > 0) {
req->data.starttone.tone = htolel(tone);
}
- transmit_response(s, req);
-}
-
-static void transmit_selectsoftkeys(struct skinnysession *s, int instance, int callid, int softkey)
+ transmit_response(d, req);
+}
+
+static void transmit_selectsoftkeys(struct skinny_device *d, int instance, int callid, int softkey)
{
struct skinny_req *req;
@@ -1976,10 +1978,10 @@
req->data.selectsoftkey.reference = htolel(callid);
req->data.selectsoftkey.softKeySetIndex = htolel(softkey);
req->data.selectsoftkey.validKeyMask = htolel(0xFFFFFFFF);
- transmit_response(s, req);
-}
-
-static void transmit_lamp_indication(struct skinnysession *s, int stimulus, int instance, int indication)
+ transmit_response(d, req);
+}
+
+static void transmit_lamp_indication(struct skinny_device *d, int stimulus, int instance, int indication)
{
struct skinny_req *req;
@@ -1989,10 +1991,10 @@
req->data.setlamp.stimulus = htolel(stimulus);
req->data.setlamp.stimulusInstance = htolel(instance);
req->data.setlamp.deviceStimulus = htolel(indication);
- transmit_response(s, req);
-}
-
-static void transmit_ringer_mode(struct skinnysession *s, int mode)
+ transmit_response(d, req);
+}
+
+static void transmit_ringer_mode(struct skinny_device *d, int mode)
{
struct skinny_req *req;
@@ -2014,10 +2016,10 @@
/* XXX the value here doesn't seem to change anything. Must be higher than 0.
Perhaps a packet capture can shed some light on this. */
req->data.setringer.unknown2 = htolel(1);
- transmit_response(s, req);
-}
-
-static void transmit_displaymessage(struct skinnysession *s, const char *text, int instance, int reference)
+ transmit_response(d, req);
+}
+
+static void transmit_displaymessage(struct skinny_device *d, const char *text, int instance, int reference)
{
struct skinny_req *req;
@@ -2039,10 +2041,10 @@
ast_verb(1, "Displaying message '%s'\n", req->data.displaytext.text);
}
- transmit_response(s, req);
-}
-
-static void transmit_displaynotify(struct skinnysession *s, const char *text, int t)
+ transmit_response(d, req);
+}
+
+static void transmit_displaynotify(struct skinny_device *d, const char *text, int t)
{
struct skinny_req *req;
@@ -2055,10 +2057,10 @@
if (skinnydebug)
ast_verb(1, "Displaying notify '%s'\n", text);
- transmit_response(s, req);
-}
-
-static void transmit_displaypromptstatus(struct skinnysession *s, const char *text, int t, int instance, int callid)
+ transmit_response(d, req);
+}
+
+static void transmit_displaypromptstatus(struct skinny_device *d, const char *text, int t, int instance, int callid)
{
struct skinny_req *req;
@@ -2084,10 +2086,10 @@
ast_verb(1, "Displaying Prompt Status '%s'\n", text);
}
- transmit_response(s, req);
-}
-
-static void transmit_dialednumber(struct skinnysession *s, const char *text, int instance, int callid)
+ transmit_response(d, req);
+}
+
+static void transmit_dialednumber(struct skinny_device *d, const char *text, int instance, int callid)
{
struct skinny_req *req;
@@ -2098,10 +2100,10 @@
req->data.dialednumber.lineInstance = htolel(instance);
req->data.dialednumber.callReference = htolel(callid);
- transmit_response(s, req);
-}
-
-static void transmit_closereceivechannel(struct skinnysession *s, struct skinny_subchannel *sub)
+ transmit_response(d, req);
+}
+
+static void transmit_closereceivechannel(struct skinny_device *d, struct skinny_subchannel *sub)
{
struct skinny_req *req;
@@ -2110,10 +2112,10 @@
req->data.closereceivechannel.conferenceId = htolel(0);
req->data.closereceivechannel.partyId = htolel(sub->callid);
- transmit_response(s, req);
-}
-
-static void transmit_stopmediatransmission(struct skinnysession *s, struct skinny_subchannel *sub)
+ transmit_response(d, req);
+}
+
+static void transmit_stopmediatransmission(struct skinny_device *d, struct skinny_subchannel *sub)
{
struct skinny_req *req;
@@ -2122,10 +2124,10 @@
req->data.stopmedia.conferenceId = htolel(0);
req->data.stopmedia.passThruPartyId = htolel(sub->callid);
- transmit_response(s, req);
-}
-
-static void transmit_activatecallplane(struct skinnysession *s, struct skinny_line *l)
+ transmit_response(d, req);
+}
+
+static void transmit_activatecallplane(struct skinny_device *d, struct skinny_line *l)
{
struct skinny_req *req;
@@ -2133,10 +2135,10 @@
return;
req->data.activatecallplane.lineInstance = htolel(l->instance);
[... 1552 lines stripped ...]
More information about the asterisk-commits
mailing list