<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10060">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Michael L. Young: Looks good to me, but someone else must approve
Richard Mudgett: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip: Log IPv6 addresses correctly<br><br>Both pjsip_tx_data.tp_info.dst_name and pjsip_rx_data.pkt_info.src_name<br>store IPv6 addresses without enclosing brackets. This causes some log<br>output to be confusing because it is difficult to separate the IPv6<br>address from a port specification.<br><br>* Use pj_sockaddr_print() along with pjsip_tx_data.tp_info.dst_addr and<br> pjsip_rx_data.pkt_info.src_addr where possible for consistent IPv6<br> output.<br><br>* When a pj_sockaddr is not available, explicitly wrap IPv6 addresses<br> in brackets.<br><br>* When assigning pjsip_rx_data.pkt_info.src_name ourselves, make sure<br> to also set pjsip_rx_data.pkt_info.src_addr.<br><br>Change-Id: I5cfe997ced7883862a12b9c7d8551d76ae02fcf8<br>---<br>M include/asterisk/netsock2.h<br>M res/res_pjsip.c<br>M res/res_pjsip/pjsip_distributor.c<br>M res/res_pjsip_logger.c<br>M res/res_pjsip_outbound_authenticator_digest.c<br>M res/res_pjsip_session.c<br>M res/res_pjsip_transport_websocket.c<br>7 files changed, 62 insertions(+), 23 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/netsock2.h b/include/asterisk/netsock2.h</span><br><span>index fc3a0c0..3ba15a8 100644</span><br><span>--- a/include/asterisk/netsock2.h</span><br><span>+++ b/include/asterisk/netsock2.h</span><br><span>@@ -31,6 +31,18 @@</span><br><span> </span><br><span> #include <netinet/in.h></span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * String buffer size that can accommodate a fully stringified representation of a</span><br><span style="color: hsl(120, 100%, 40%);">+ * supported IP address & port:</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * - 45 bytes for an IPv6 address</span><br><span style="color: hsl(120, 100%, 40%);">+ * - 2 bytes for brackets around an IPv6 address</span><br><span style="color: hsl(120, 100%, 40%);">+ * - 1 byte for the port separator (a colon)</span><br><span style="color: hsl(120, 100%, 40%);">+ * - 5 bytes for the port</span><br><span style="color: hsl(120, 100%, 40%);">+ * - 1 byte for the zero-terminator</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+#define AST_SOCKADDR_BUFLEN (45 + 2 + 1 + 5 + 1)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*!</span><br><span> * Values for address families that we support. This is reproduced from socket.h</span><br><span> * because we do not want users to include that file. Only netsock2.c should</span><br><span>diff --git a/res/res_pjsip.c b/res/res_pjsip.c</span><br><span>index 49defab..c2e77cb 100644</span><br><span>--- a/res/res_pjsip.c</span><br><span>+++ b/res/res_pjsip.c</span><br><span>@@ -3674,6 +3674,8 @@</span><br><span> ast_copy_string(rdata->pkt_info.packet, packet, sizeof(rdata->pkt_info.packet));</span><br><span> ast_copy_string(rdata->pkt_info.src_name, src_name, sizeof(rdata->pkt_info.src_name));</span><br><span> rdata->pkt_info.src_port = src_port;</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_sockaddr_parse(pj_AF_UNSPEC(), 0, pj_cstr(&tmp, src_name), &rdata->pkt_info.src_addr);</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_sockaddr_set_port(&rdata->pkt_info.src_addr, src_port);</span><br><span> </span><br><span> pjsip_parse_rdata(packet, strlen(packet), rdata);</span><br><span> if (!rdata->msg_info.msg || !pj_list_empty(&rdata->msg_info.parse_err)) {</span><br><span>diff --git a/res/res_pjsip/pjsip_distributor.c b/res/res_pjsip/pjsip_distributor.c</span><br><span>index 626f07c..4bd3b00 100644</span><br><span>--- a/res/res_pjsip/pjsip_distributor.c</span><br><span>+++ b/res/res_pjsip/pjsip_distributor.c</span><br><span>@@ -648,16 +648,21 @@</span><br><span> char from_buf[PJSIP_MAX_URL_SIZE];</span><br><span> char callid_buf[PJSIP_MAX_URL_SIZE];</span><br><span> char method_buf[PJSIP_MAX_URL_SIZE];</span><br><span style="color: hsl(120, 100%, 40%);">+ char src_addr_buf[AST_SOCKADDR_BUFLEN];</span><br><span> pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, rdata->msg_info.from->uri, from_buf, PJSIP_MAX_URL_SIZE);</span><br><span> ast_copy_pj_str(callid_buf, &rdata->msg_info.cid->id, PJSIP_MAX_URL_SIZE);</span><br><span> ast_copy_pj_str(method_buf, &rdata->msg_info.msg->line.req.method.name, PJSIP_MAX_URL_SIZE);</span><br><span> if (count) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_NOTICE, "Request '%s' from '%s' failed for '%s:%d' (callid: %s) - %s"</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_NOTICE, "Request '%s' from '%s' failed for '%s' (callid: %s) - %s"</span><br><span> " after %u tries in %.3f ms\n",</span><br><span style="color: hsl(0, 100%, 40%);">- method_buf, from_buf, rdata->pkt_info.src_name, rdata->pkt_info.src_port, callid_buf, msg, count, period / 1000.0);</span><br><span style="color: hsl(120, 100%, 40%);">+ method_buf, from_buf,</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_sockaddr_print(&rdata->pkt_info.src_addr, src_addr_buf, sizeof(src_addr_buf), 3),</span><br><span style="color: hsl(120, 100%, 40%);">+ callid_buf, msg, count, period / 1000.0);</span><br><span> } else {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_NOTICE, "Request '%s' from '%s' failed for '%s:%d' (callid: %s) - %s\n",</span><br><span style="color: hsl(0, 100%, 40%);">- method_buf, from_buf, rdata->pkt_info.src_name, rdata->pkt_info.src_port, callid_buf, msg);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_NOTICE, "Request '%s' from '%s' failed for '%s' (callid: %s) - %s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ method_buf, from_buf,</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_sockaddr_print(&rdata->pkt_info.src_addr, src_addr_buf, sizeof(src_addr_buf), 3),</span><br><span style="color: hsl(120, 100%, 40%);">+ callid_buf, msg);</span><br><span> }</span><br><span> }</span><br><span> </span><br><span>diff --git a/res/res_pjsip_logger.c b/res/res_pjsip_logger.c</span><br><span>index fb58f2b..172deec 100644</span><br><span>--- a/res/res_pjsip_logger.c</span><br><span>+++ b/res/res_pjsip_logger.c</span><br><span>@@ -74,22 +74,25 @@</span><br><span> </span><br><span> static pj_status_t logging_on_tx_msg(pjsip_tx_data *tdata)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ char buffer[AST_SOCKADDR_BUFLEN];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (!pjsip_log_test_addr(tdata->tp_info.dst_name, tdata->tp_info.dst_port)) {</span><br><span> return PJ_SUCCESS;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_verbose("<--- Transmitting SIP %s (%d bytes) to %s:%s:%d --->\n%.*s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_verbose("<--- Transmitting SIP %s (%d bytes) to %s:%s --->\n%.*s\n",</span><br><span> tdata->msg->type == PJSIP_REQUEST_MSG ? "request" : "response",</span><br><span> (int) (tdata->buf.cur - tdata->buf.start),</span><br><span> tdata->tp_info.transport->type_name,</span><br><span style="color: hsl(0, 100%, 40%);">- tdata->tp_info.dst_name,</span><br><span style="color: hsl(0, 100%, 40%);">- tdata->tp_info.dst_port,</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_sockaddr_print(&tdata->tp_info.dst_addr, buffer, sizeof(buffer), 3),</span><br><span> (int) (tdata->buf.end - tdata->buf.start), tdata->buf.start);</span><br><span> return PJ_SUCCESS;</span><br><span> }</span><br><span> </span><br><span> static pj_bool_t logging_on_rx_msg(pjsip_rx_data *rdata)</span><br><span> {</span><br><span style="color: hsl(120, 100%, 40%);">+ char buffer[AST_SOCKADDR_BUFLEN];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (!pjsip_log_test_addr(rdata->pkt_info.src_name, rdata->pkt_info.src_port)) {</span><br><span> return PJ_FALSE;</span><br><span> }</span><br><span>@@ -98,12 +101,11 @@</span><br><span> return PJ_FALSE;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_verbose("<--- Received SIP %s (%d bytes) from %s:%s:%d --->\n%s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_verbose("<--- Received SIP %s (%d bytes) from %s:%s --->\n%s\n",</span><br><span> rdata->msg_info.msg->type == PJSIP_REQUEST_MSG ? "request" : "response",</span><br><span> rdata->msg_info.len,</span><br><span> rdata->tp_info.transport->type_name,</span><br><span style="color: hsl(0, 100%, 40%);">- rdata->pkt_info.src_name,</span><br><span style="color: hsl(0, 100%, 40%);">- rdata->pkt_info.src_port,</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_sockaddr_print(&rdata->pkt_info.src_addr, buffer, sizeof(buffer), 3),</span><br><span> rdata->pkt_info.packet);</span><br><span> return PJ_FALSE;</span><br><span> }</span><br><span>diff --git a/res/res_pjsip_outbound_authenticator_digest.c b/res/res_pjsip_outbound_authenticator_digest.c</span><br><span>index 063b4d3..5f6d994 100644</span><br><span>--- a/res/res_pjsip_outbound_authenticator_digest.c</span><br><span>+++ b/res/res_pjsip_outbound_authenticator_digest.c</span><br><span>@@ -118,8 +118,8 @@</span><br><span> }</span><br><span> /* If there was no dialog, then this is probably a REGISTER so no endpoint */</span><br><span> if (!id) {</span><br><span style="color: hsl(0, 100%, 40%);">- id = ast_alloca(strlen(challenge->pkt_info.src_name) + 7 /* ':' + port + NULL */);</span><br><span style="color: hsl(0, 100%, 40%);">- sprintf(id, "%s:%d", challenge->pkt_info.src_name, challenge->pkt_info.src_port);</span><br><span style="color: hsl(120, 100%, 40%);">+ id = ast_alloca(AST_SOCKADDR_BUFLEN);</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_sockaddr_print(&challenge->pkt_info.src_addr, id, AST_SOCKADDR_BUFLEN, 3);</span><br><span> id_type = "Host";</span><br><span> }</span><br><span> </span><br><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index 244b8cc..2b78cfa 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -2931,6 +2931,7 @@</span><br><span> pjsip_timer_setting timer;</span><br><span> pjsip_rdata_sdp_info *sdp_info;</span><br><span> pjmedia_sdp_session *local = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ char buffer[AST_SOCKADDR_BUFLEN];</span><br><span> </span><br><span> /* From this point on, any calls to pjsip_inv_terminate have the last argument as PJ_TRUE</span><br><span> * so that we will be notified so we can destroy the session properly</span><br><span>@@ -2958,8 +2959,11 @@</span><br><span> }</span><br><span> goto end;</span><br><span> case SIP_GET_DEST_EXTEN_PARTIAL:</span><br><span style="color: hsl(0, 100%, 40%);">- ast_debug(1, "Call from '%s' (%s:%s:%d) to extension '%s' - partial match\n", ast_sorcery_object_get_id(invite->session->endpoint),</span><br><span style="color: hsl(0, 100%, 40%);">- invite->rdata->tp_info.transport->type_name, invite->rdata->pkt_info.src_name, invite->rdata->pkt_info.src_port, invite->session->exten);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(1, "Call from '%s' (%s:%s) to extension '%s' - partial match\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_object_get_id(invite->session->endpoint),</span><br><span style="color: hsl(120, 100%, 40%);">+ invite->rdata->tp_info.transport->type_name,</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_sockaddr_print(&invite->rdata->pkt_info.src_addr, buffer, sizeof(buffer), 3),</span><br><span style="color: hsl(120, 100%, 40%);">+ invite->session->exten);</span><br><span> </span><br><span> if (pjsip_inv_initial_answer(invite->session->inv_session, invite->rdata, 484, NULL, NULL, &tdata) == PJ_SUCCESS) {</span><br><span> ast_sip_session_send_response(invite->session, tdata);</span><br><span>@@ -2969,9 +2973,12 @@</span><br><span> goto end;</span><br><span> case SIP_GET_DEST_EXTEN_NOT_FOUND:</span><br><span> default:</span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_NOTICE, "Call from '%s' (%s:%s:%d) to extension '%s' rejected because extension not found in context '%s'.\n",</span><br><span style="color: hsl(0, 100%, 40%);">- ast_sorcery_object_get_id(invite->session->endpoint), invite->rdata->tp_info.transport->type_name, invite->rdata->pkt_info.src_name,</span><br><span style="color: hsl(0, 100%, 40%);">- invite->rdata->pkt_info.src_port, invite->session->exten, invite->session->endpoint->context);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_NOTICE, "Call from '%s' (%s:%s) to extension '%s' rejected because extension not found in context '%s'.\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_object_get_id(invite->session->endpoint),</span><br><span style="color: hsl(120, 100%, 40%);">+ invite->rdata->tp_info.transport->type_name,</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_sockaddr_print(&invite->rdata->pkt_info.src_addr, buffer, sizeof(buffer), 3),</span><br><span style="color: hsl(120, 100%, 40%);">+ invite->session->exten,</span><br><span style="color: hsl(120, 100%, 40%);">+ invite->session->endpoint->context);</span><br><span> </span><br><span> if (pjsip_inv_initial_answer(invite->session->inv_session, invite->rdata, 404, NULL, NULL, &tdata) == PJ_SUCCESS) {</span><br><span> ast_sip_session_send_response(invite->session, tdata);</span><br><span>diff --git a/res/res_pjsip_transport_websocket.c b/res/res_pjsip_transport_websocket.c</span><br><span>index 75869f5..2abbf15 100644</span><br><span>--- a/res/res_pjsip_transport_websocket.c</span><br><span>+++ b/res/res_pjsip_transport_websocket.c</span><br><span>@@ -429,12 +429,23 @@</span><br><span> pjsip_sip_uri *uri = pjsip_uri_get_uri(contact->uri);</span><br><span> const pj_str_t *txp_str = &STR_WS;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_debug(4, "%s re-writing Contact URI from %.*s:%d%s%.*s to %s:%d;transport=%s\n",</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_rx_data_get_info(rdata),</span><br><span style="color: hsl(0, 100%, 40%);">- (int)pj_strlen(&uri->host), pj_strbuf(&uri->host), uri->port,</span><br><span style="color: hsl(0, 100%, 40%);">- pj_strlen(&uri->transport_param) ? ";transport=" : "",</span><br><span style="color: hsl(0, 100%, 40%);">- (int)pj_strlen(&uri->transport_param), pj_strbuf(&uri->transport_param),</span><br><span style="color: hsl(0, 100%, 40%);">- rdata->pkt_info.src_name ?: "", rdata->pkt_info.src_port, pj_strbuf(txp_str));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (DEBUG_ATLEAST(4)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ char src_addr_buffer[AST_SOCKADDR_BUFLEN];</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *ipv6_s = "", *ipv6_e = "";</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (pj_strchr(&uri->host, ':')) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ipv6_s = "[";</span><br><span style="color: hsl(120, 100%, 40%);">+ ipv6_e = "]";</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_DEBUG, "%s re-writing Contact URI from %s%.*s%s:%d%s%.*s to %s;transport=%s\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_rx_data_get_info(rdata),</span><br><span style="color: hsl(120, 100%, 40%);">+ ipv6_s, (int) pj_strlen(&uri->host), pj_strbuf(&uri->host), ipv6_e, uri->port,</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strlen(&uri->transport_param) ? ";transport=" : "",</span><br><span style="color: hsl(120, 100%, 40%);">+ (int) pj_strlen(&uri->transport_param), pj_strbuf(&uri->transport_param),</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_sockaddr_print(&rdata->pkt_info.src_addr, src_addr_buffer, sizeof(src_addr_buffer), 3),</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strbuf(txp_str));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> pj_cstr(&uri->host, rdata->pkt_info.src_name);</span><br><span> uri->port = rdata->pkt_info.src_port;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10060">change 10060</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/10060"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I5cfe997ced7883862a12b9c7d8551d76ae02fcf8 </div>
<div style="display:none"> Gerrit-Change-Number: 10060 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Michael L. Young <elgueromexicano@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>