<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10058">View Change</a></p><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>Instead, we use pjsip_tx_data.tp_info.dst_addr and<br>pjsip_rx_data.pkt_info.src_addr and pj_sockaddr_print() which includes<br>the brackets if the address is IPv6.<br><br>Change-Id: I5cfe997ced7883862a12b9c7d8551d76ae02fcf8<br>---<br>M include/asterisk/netsock2.h<br>M res/res_pjsip/pjsip_distributor.c<br>M res/res_pjsip_logger.c<br>M res/res_pjsip_session.c<br>4 files changed, 41 insertions(+), 15 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/58/10058/1</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 5c6c733..b6f2858 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/pjsip_distributor.c b/res/res_pjsip/pjsip_distributor.c</span><br><span>index f9e2997..9b3fcdc 100644</span><br><span>--- a/res/res_pjsip/pjsip_distributor.c</span><br><span>+++ b/res/res_pjsip/pjsip_distributor.c</span><br><span>@@ -638,16 +638,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 2e5c76c..fe23392 100644</span><br><span>--- a/res/res_pjsip_logger.c</span><br><span>+++ b/res/res_pjsip_logger.c</span><br><span>@@ -101,22 +101,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>@@ -125,12 +128,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_session.c b/res/res_pjsip_session.c</span><br><span>index ed637cd..ff40e55 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -2101,6 +2101,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>@@ -2128,8 +2129,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>@@ -2139,9 +2143,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></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10058">change 10058</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/10058"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I5cfe997ced7883862a12b9c7d8551d76ae02fcf8 </div>
<div style="display:none"> Gerrit-Change-Number: 10058 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>