Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 118555) +++ channels/chan_sip.c (working copy) @@ -4633,8 +4633,6 @@ if (!found && option_debug > 4) ast_log(LOG_DEBUG, "= Being pedantic: This is not our match on request: Call ID: %s Ourtag Totag %s Method %s\n", p->callid, totag, sip_methods[req->method].text); } - - if (found) { /* Found the call */ ast_mutex_lock(&p->lock); @@ -13786,10 +13784,25 @@ being able to call yourself */ /* If pedantic is on, we need to check the tags. If they're different, this is in fact a forked call through a SIP proxy somewhere. */ - transmit_response(p, "482 Loop Detected", req); - p->invitestate = INV_COMPLETED; - sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); - return 0; + if (!strcmp(p->initreq.rlPart2, req->rlPart2)) { + transmit_response(p, "482 Loop Detected", req); + p->invitestate = INV_COMPLETED; + sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); + return 0; + } else { + /* This is a spiral. What we need to do is to just change the outgoing INVITE + * so that it now routes to the new Request URI. Since we created the INVITE ourselves + * that should be all we need to do. + */ + char *uri = ast_strdupa(req->rlPart2); + char *blah = strchr(uri, '@'); + ast_log(LOG_NOTICE, "Spiral detected\n"); + *blah = '\0'; + blah = strchr(uri, ':'); + *blah++ = '\0'; + create_addr(p, blah); + return transmit_invite(p, SIP_INVITE, 1, 2); + } } if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->pendinginvite) {