Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 37122) +++ channels/chan_sip.c (working copy) @@ -4121,6 +4121,7 @@ char *tag = ""; /* note, tag is never NULL */ char totag[128]; char fromtag[128]; + int found; const char *callid = get_header(req, "Call-ID"); const char *from = get_header(req, "From"); const char *to = get_header(req, "To"); @@ -4149,7 +4150,7 @@ ast_mutex_lock(&iflock); for (p = iflist; p; p = p->next) { /* In pedantic, we do not want packets with bad syntax to be connected to a PVT */ - int found = FALSE; + found = FALSE; if (req->method == SIP_REGISTER) found = (!strcmp(p->callid, callid)); else @@ -4159,21 +4160,33 @@ if (option_debug > 4) ast_log(LOG_DEBUG, "= %s Their Call ID: %s Their Tag %s Our tag: %s\n", found ? "Found" : "No match", p->callid, p->theirtag, p->tag); - /* If we get a new request within an existing to-tag - check the to tag as well */ - if (pedanticsipchecking && found && req->method != SIP_RESPONSE) { /* SIP Request */ - if (p->tag[0] == '\0' && totag[0]) { - /* We have no to tag, but they have. Wrong dialog */ + /* If pedantic Check to and from tags to make sure we have the right dialog */ + if (pedanticsipchecking && found) { + if (!fromtag[0]) { + ast_log(LOG_WARNING, "Pedantic sip checking and no from tag for callid: %s method %s\n", callid, sip_methods[req->method].text); + break; + } + if (req->method == SIP_INVITE && totag[0] == '\0') { /* no to tag it's not a reinvite, create new chan */ found = FALSE; - } else if (totag[0]) { /* Both have tags, compare them */ - if (strcmp(totag, p->tag)) { - found = FALSE; /* This is not our packet */ + break; + } else if (req->method == SIP_CANCEL && totag[0] == '\0') { /* cancel has no to tag, check this isn't the originating chan */ + if (!strcmp(fromtag, p->tag)) { + found = FALSE; + continue; } } - 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 (req->method != SIP_RESPONSE) { /* request is for this chan if to tag matches */ + if (totag[0]) { + if (strcmp(totag, p->tag)) + found = FALSE; + } + } else { /* from tag matches us it's a response to request from this chan */ + if (strcmp(fromtag, p->tag)){ + found = FALSE; + } + } } - if (found) { /* Found the call */ ast_mutex_lock(&p->lock);