Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 112128) +++ channels/chan_sip.c (working copy) @@ -1233,7 +1233,7 @@ /*--- Transmitting responses and requests */ static int sipsock_read(int *id, int fd, short events, void *ignore); -static int __sip_xmit(struct sip_pvt *p, char *data, int len); +static int __sip_xmit(struct sip_pvt *p, char *data, int len, int response); static int __sip_reliable_xmit(struct sip_pvt *p, int seqno, int resp, char *data, int len, int fatal, int sipmethod); static int __transmit_response(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable); static int retrans_pkt(const void *data); @@ -1490,7 +1490,7 @@ static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod); static int init_resp(struct sip_request *resp, const char *msg); static int respprep(struct sip_request *resp, struct sip_pvt *p, const char *msg, const struct sip_request *req); -static const struct sockaddr_in *sip_real_dst(const struct sip_pvt *p); +static const struct sockaddr_in *sip_real_dst(const struct sip_pvt *p, int response); 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); @@ -1746,9 +1746,9 @@ } /*! \brief The real destination address for a write */ -static const struct sockaddr_in *sip_real_dst(const struct sip_pvt *p) +static const struct sockaddr_in *sip_real_dst(const struct sip_pvt *p, int response) { - return ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE ? &p->recv : &p->sa; + return (ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE || response) ? &p->recv : &p->sa; } /*! \brief Display SIP nat mode */ @@ -1762,14 +1762,20 @@ { if (!sipdebug) return 0; - return sip_debug_test_addr(sip_real_dst(p)); + /* XXX Assume 0 for the "response" parameter for sip_real_dst + * for now since this typically isn't used for actual routing purposes. + * + * This may need to be modified if it causes problems with + * debugging (i.e. not getting/not getting debug messages when expected) + */ + return sip_debug_test_addr(sip_real_dst(p,0)); } /*! \brief Transmit SIP message */ -static int __sip_xmit(struct sip_pvt *p, char *data, int len) +static int __sip_xmit(struct sip_pvt *p, char *data, int len, int response) { int res; - const struct sockaddr_in *dst = sip_real_dst(p); + const struct sockaddr_in *dst = sip_real_dst(p, response); res = sendto(sipsock, data, len, 0, (const struct sockaddr *)dst, sizeof(struct sockaddr_in)); if (res == -1) { @@ -1927,7 +1933,7 @@ } if (sip_debug_test_pvt(pkt->owner)) { - const struct sockaddr_in *dst = sip_real_dst(pkt->owner); + const struct sockaddr_in *dst = sip_real_dst(pkt->owner, pkt->method == SIP_RESPONSE); ast_verbose("Retransmitting #%d (%s) to %s:%d:\n%s\n---\n", pkt->retrans, sip_nat_mode(pkt->owner), ast_inet_ntoa(dst->sin_addr), @@ -1935,7 +1941,7 @@ } append_history(pkt->owner, "ReTx", "%d %s", reschedule, pkt->data); - xmitres = __sip_xmit(pkt->owner, pkt->data, pkt->packetlen); + xmitres = __sip_xmit(pkt->owner, pkt->data, pkt->packetlen, pkt->method == SIP_RESPONSE); ast_mutex_unlock(&pkt->owner->lock); if (xmitres == XMIT_ERROR) ast_log(LOG_WARNING, "Network error on retransmit in dialog %s\n", pkt->owner->callid); @@ -2050,7 +2056,7 @@ p->pendinginvite = seqno; } - xmitres = __sip_xmit(pkt->owner, pkt->data, pkt->packetlen); /* Send packet */ + xmitres = __sip_xmit(pkt->owner, pkt->data, pkt->packetlen, pkt->method == SIP_RESPONSE); /* Send packet */ if (xmitres == XMIT_ERROR) { /* Serious network trouble, no need to try again */ append_history(pkt->owner, "XmitErr", "%s", (ast_test_flag(pkt, FLAG_FATAL)) ? "(Critical)" : "(Non-critical)"); @@ -2264,7 +2270,7 @@ add_blank(req); if (sip_debug_test_pvt(p)) { - const struct sockaddr_in *dst = sip_real_dst(p); + const struct sockaddr_in *dst = sip_real_dst(p, req->method == SIP_RESPONSE); ast_verbose("\n<--- %sTransmitting (%s) to %s:%d --->\n%s\n<------------>\n", reliable ? "Reliably " : "", sip_nat_mode(p), @@ -2279,7 +2285,7 @@ } res = (reliable) ? __sip_reliable_xmit(p, seqno, 1, req->data, req->len, (reliable == XMIT_CRITICAL), req->method) : - __sip_xmit(p, req->data, req->len); + __sip_xmit(p, req->data, req->len, req->method == SIP_RESPONSE); if (res > 0) return 0; return res; @@ -2304,7 +2310,7 @@ } res = (reliable) ? __sip_reliable_xmit(p, seqno, 0, req->data, req->len, (reliable == XMIT_CRITICAL), req->method) : - __sip_xmit(p, req->data, req->len); + __sip_xmit(p, req->data, req->len, req->method == SIP_RESPONSE); return res; } @@ -9238,7 +9244,7 @@ p->sa.sin_port = htons(pt ? atoi(pt) : STANDARD_SIP_PORT); if (sip_debug_test_pvt(p)) { - const struct sockaddr_in *dst = sip_real_dst(p); + const struct sockaddr_in *dst = sip_real_dst(p, req->method == SIP_RESPONSE); ast_verbose("Sending to %s : %d (%s)\n", ast_inet_ntoa(dst->sin_addr), ntohs(dst->sin_port), sip_nat_mode(p)); } }