--- channels/chan_sip.c (Asterisk 13.18.3) +++ channels/chan_sip.c (working copy) @@ -34114,26 +34114,30 @@ static int peer_ipcmp_cb_full(void *obj, if (ast_sockaddr_cmp_addr(&peer->addr, &peer2->addr)) { /* IP doesn't match */ return 0; } + if (ast_sockaddr_port(&peer->addr) != ast_sockaddr_port(&peer2->addr)) { + /* IP matches but port doesn't match */ + return 0; + } + /* We matched the IP, check to see if we need to match by port as well. */ if ((peer->transports & peer2->transports) & (AST_TRANSPORT_TLS | AST_TRANSPORT_TCP)) { /* peer matching on port is not possible with TCP/TLS */ return CMP_MATCH | CMP_STOP; } else if (ast_test_flag(&peer2->flags[0], SIP_INSECURE_PORT)) { /* We are allowing match without port for peers configured that * way in this pass through the peers. */ return ast_test_flag(&peer->flags[0], SIP_INSECURE_PORT) ? (CMP_MATCH | CMP_STOP) : 0; } - /* Now only return a match if the port matches, as well. */ - return ast_sockaddr_port(&peer->addr) == ast_sockaddr_port(&peer2->addr) ? - (CMP_MATCH | CMP_STOP) : 0; + /* Port matches */ + return (CMP_MATCH | CMP_STOP); } static int peer_ipcmp_cb(void *obj, void *arg, int flags) { return peer_ipcmp_cb_full(obj, arg, NULL, flags); }