2014-03-28 18:32:50 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 - 2014, Digium, Inc.
|
|
|
|
*
|
|
|
|
* Matt Jordan <mjordan@digium.com>
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \file
|
|
|
|
* \brief PJSIP logging with Homer
|
|
|
|
*
|
|
|
|
* \author Matt Jordan <mjordan@digium.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*** MODULEINFO
|
|
|
|
<depend>pjproject</depend>
|
|
|
|
<depend>res_pjsip</depend>
|
2014-04-10 21:28:08 +00:00
|
|
|
<depend>res_pjsip_session</depend>
|
2014-03-28 18:32:50 +00:00
|
|
|
<depend>res_hep</depend>
|
|
|
|
<support_level>extended</support_level>
|
|
|
|
***/
|
|
|
|
|
|
|
|
#include "asterisk.h"
|
|
|
|
|
git migration: Refactor the ASTERISK_FILE_VERSION macro
Git does not support the ability to replace a token with a version
string during check-in. While it does have support for replacing a
token on clone, this is somewhat sub-optimal: the token is replaced
with the object hash, which is not particularly easy for human
consumption. What's more, in practice, the source file version was often
not terribly useful. Generally, when triaging bugs, the overall version
of Asterisk is far more useful than an individual SVN version of a file. As a
result, this patch removes Asterisk's support for showing source file
versions.
Specifically, it does the following:
* Rename ASTERISK_FILE_VERSION macro to ASTERISK_REGISTER_FILE, and
remove passing the version in with the macro. Other facilities
than 'core show file version' make use of the file names, such as
setting a debug level only on a specific file. As such, the act of
registering source files with the Asterisk core still has use. The
macro rename now reflects the new macro purpose.
* main/asterisk:
- Refactor the file_version structure to reflect that it no longer
tracks a version field.
- Remove the "core show file version" CLI command. Without the file
version, it is no longer useful.
- Remove the ast_file_version_find function. The file version is no
longer tracked.
- Rename ast_register_file_version/ast_unregister_file_version to
ast_register_file/ast_unregister_file, respectively.
* main/manager: Remove value from the Version key of the ModuleCheck
Action. The actual key itself has not been removed, as doing so would
absolutely constitute a backwards incompatible change. However, since
the file version is no longer tracked, there is no need to attempt to
include it in the Version key.
* UPGRADE: Add notes for:
- Modification to the ModuleCheck AMI Action
- Removal of the "core show file version" CLI command
Change-Id: I6cf0ff280e1668bf4957dc21f32a5ff43444a40e
2015-04-11 21:38:22 -05:00
|
|
|
ASTERISK_REGISTER_FILE()
|
2014-03-28 18:32:50 +00:00
|
|
|
|
|
|
|
#include <pjsip.h>
|
2014-04-10 21:28:08 +00:00
|
|
|
#include <pjsip_ua.h>
|
|
|
|
#include <pjlib.h>
|
2014-03-28 18:32:50 +00:00
|
|
|
|
|
|
|
#include "asterisk/res_pjsip.h"
|
2014-04-10 21:28:08 +00:00
|
|
|
#include "asterisk/res_pjsip_session.h"
|
2014-03-28 18:32:50 +00:00
|
|
|
#include "asterisk/res_hep.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/netsock2.h"
|
|
|
|
|
2014-04-10 21:28:08 +00:00
|
|
|
static char *assign_uuid(const pj_str_t *call_id, const pj_str_t *local_tag, const pj_str_t *remote_tag)
|
|
|
|
{
|
|
|
|
RAII_VAR(struct ast_sip_session *, session, NULL, ao2_cleanup);
|
|
|
|
pjsip_dialog *dlg;
|
|
|
|
char *uuid = NULL;
|
res_hep: Provide an option to pick the UUID type
At one point in time, it seemed like a good idea to use the Asterisk
channel name as the HEP correlation UUID. In particular, it felt like
this would be a useful identifier to tie PJSIP messages and RTCP
messages together, along with whatever other data we may eventually send
to Homer. This also had the benefit of keeping the correlation UUID
channel technology agnostic.
In practice, it isn't as useful as hoped, for two reasons:
1) The first INVITE request received doesn't have a channel. As a
result, there is always an 'odd message out', leading it to be
potentially uncorrelated in Homer.
2) Other systems sending capture packets (Kamailio) use the SIP Call-ID.
This causes RTCP information to be uncorrelated to the SIP message
traffic seen by those capture nodes.
In order to support both (in case someone is trying to use res_hep_rtcp
with a non-PJSIP channel), this patch adds a new option, uuid_type, with
two valid values - 'call-id' and 'channel'. The uuid_type option is used
by a module to determine the preferred UUID type. When available, that
source of a correlation UUID is used; when not, the more readily available
source is used.
For res_hep_pjsip:
- uuid_type = call-id: the module uses the SIP Call-ID header value
- uuid_type = channel: the module uses the channel name if available,
falling back to SIP Call-ID if not
For res_hep_rtcp:
- uuid_type = call-id: the module uses the SIP Call-ID header if the
channel type is PJSIP and we have a channel,
falling back to the Stasis event provided
channel name if not
- uuid_type = channel: the module uses the channel name
ASTERISK-25352 #close
Change-Id: Ide67e59a52d9c806e3cc0a797ea1a4b88a00122c
2016-05-11 20:17:15 -05:00
|
|
|
enum hep_uuid_type uuid_type = hepv3_get_uuid_type();
|
2014-04-10 21:28:08 +00:00
|
|
|
|
res_hep: Provide an option to pick the UUID type
At one point in time, it seemed like a good idea to use the Asterisk
channel name as the HEP correlation UUID. In particular, it felt like
this would be a useful identifier to tie PJSIP messages and RTCP
messages together, along with whatever other data we may eventually send
to Homer. This also had the benefit of keeping the correlation UUID
channel technology agnostic.
In practice, it isn't as useful as hoped, for two reasons:
1) The first INVITE request received doesn't have a channel. As a
result, there is always an 'odd message out', leading it to be
potentially uncorrelated in Homer.
2) Other systems sending capture packets (Kamailio) use the SIP Call-ID.
This causes RTCP information to be uncorrelated to the SIP message
traffic seen by those capture nodes.
In order to support both (in case someone is trying to use res_hep_rtcp
with a non-PJSIP channel), this patch adds a new option, uuid_type, with
two valid values - 'call-id' and 'channel'. The uuid_type option is used
by a module to determine the preferred UUID type. When available, that
source of a correlation UUID is used; when not, the more readily available
source is used.
For res_hep_pjsip:
- uuid_type = call-id: the module uses the SIP Call-ID header value
- uuid_type = channel: the module uses the channel name if available,
falling back to SIP Call-ID if not
For res_hep_rtcp:
- uuid_type = call-id: the module uses the SIP Call-ID header if the
channel type is PJSIP and we have a channel,
falling back to the Stasis event provided
channel name if not
- uuid_type = channel: the module uses the channel name
ASTERISK-25352 #close
Change-Id: Ide67e59a52d9c806e3cc0a797ea1a4b88a00122c
2016-05-11 20:17:15 -05:00
|
|
|
if ((uuid_type == HEP_UUID_TYPE_CHANNEL)
|
|
|
|
&& (dlg = pjsip_ua_find_dialog(call_id, local_tag, remote_tag, PJ_FALSE))
|
2014-04-10 21:28:08 +00:00
|
|
|
&& (session = ast_sip_dialog_get_session(dlg))
|
|
|
|
&& (session->channel)) {
|
|
|
|
|
|
|
|
uuid = ast_strdup(ast_channel_name(session->channel));
|
res_hep: Provide an option to pick the UUID type
At one point in time, it seemed like a good idea to use the Asterisk
channel name as the HEP correlation UUID. In particular, it felt like
this would be a useful identifier to tie PJSIP messages and RTCP
messages together, along with whatever other data we may eventually send
to Homer. This also had the benefit of keeping the correlation UUID
channel technology agnostic.
In practice, it isn't as useful as hoped, for two reasons:
1) The first INVITE request received doesn't have a channel. As a
result, there is always an 'odd message out', leading it to be
potentially uncorrelated in Homer.
2) Other systems sending capture packets (Kamailio) use the SIP Call-ID.
This causes RTCP information to be uncorrelated to the SIP message
traffic seen by those capture nodes.
In order to support both (in case someone is trying to use res_hep_rtcp
with a non-PJSIP channel), this patch adds a new option, uuid_type, with
two valid values - 'call-id' and 'channel'. The uuid_type option is used
by a module to determine the preferred UUID type. When available, that
source of a correlation UUID is used; when not, the more readily available
source is used.
For res_hep_pjsip:
- uuid_type = call-id: the module uses the SIP Call-ID header value
- uuid_type = channel: the module uses the channel name if available,
falling back to SIP Call-ID if not
For res_hep_rtcp:
- uuid_type = call-id: the module uses the SIP Call-ID header if the
channel type is PJSIP and we have a channel,
falling back to the Stasis event provided
channel name if not
- uuid_type = channel: the module uses the channel name
ASTERISK-25352 #close
Change-Id: Ide67e59a52d9c806e3cc0a797ea1a4b88a00122c
2016-05-11 20:17:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If we couldn't get the channel or we never wanted it, default to the call-id */
|
|
|
|
if (!uuid) {
|
2014-04-10 21:28:08 +00:00
|
|
|
|
|
|
|
uuid = ast_malloc(pj_strlen(call_id) + 1);
|
|
|
|
if (uuid) {
|
|
|
|
ast_copy_pj_str(uuid, call_id, pj_strlen(call_id) + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
|
2014-03-28 18:32:50 +00:00
|
|
|
static pj_status_t logging_on_tx_msg(pjsip_tx_data *tdata)
|
|
|
|
{
|
|
|
|
char local_buf[256];
|
|
|
|
char remote_buf[256];
|
|
|
|
char *uuid;
|
|
|
|
struct hepv3_capture_info *capture_info;
|
|
|
|
pjsip_cid_hdr *cid_hdr;
|
2014-04-10 21:28:08 +00:00
|
|
|
pjsip_from_hdr *from_hdr;
|
|
|
|
pjsip_to_hdr *to_hdr;
|
2016-05-12 07:08:08 -05:00
|
|
|
pjsip_tpmgr_fla2_param prm;
|
2014-03-28 18:32:50 +00:00
|
|
|
|
|
|
|
capture_info = hepv3_create_capture_info(tdata->buf.start, (size_t)(tdata->buf.cur - tdata->buf.start));
|
|
|
|
if (!capture_info) {
|
|
|
|
return PJ_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-05-12 07:08:08 -05:00
|
|
|
/* Attempt to determine what IP address will we send this packet out of */
|
|
|
|
pjsip_tpmgr_fla2_param_default(&prm);
|
|
|
|
prm.tp_type = tdata->tp_info.transport->key.type;
|
|
|
|
pj_strset2(&prm.dst_host, tdata->tp_info.dst_name);
|
|
|
|
prm.local_if = PJ_TRUE;
|
|
|
|
|
|
|
|
/* If we can't get the local address use what we have already */
|
|
|
|
if (pjsip_tpmgr_find_local_addr2(pjsip_endpt_get_tpmgr(ast_sip_get_pjsip_endpoint()), tdata->pool, &prm) != PJ_SUCCESS) {
|
|
|
|
pj_sockaddr_print(&tdata->tp_info.transport->local_addr, local_buf, sizeof(local_buf), 3);
|
|
|
|
} else {
|
|
|
|
if (prm.tp_type & PJSIP_TRANSPORT_IPV6) {
|
|
|
|
snprintf(local_buf, sizeof(local_buf), "[%.*s]:%hu",
|
|
|
|
(int)pj_strlen(&prm.ret_addr),
|
|
|
|
pj_strbuf(&prm.ret_addr),
|
|
|
|
prm.ret_port);
|
|
|
|
} else {
|
|
|
|
snprintf(local_buf, sizeof(local_buf), "%.*s:%hu",
|
|
|
|
(int)pj_strlen(&prm.ret_addr),
|
|
|
|
pj_strbuf(&prm.ret_addr),
|
|
|
|
prm.ret_port);
|
|
|
|
}
|
|
|
|
}
|
2014-03-28 18:32:50 +00:00
|
|
|
pj_sockaddr_print(&tdata->tp_info.dst_addr, remote_buf, sizeof(remote_buf), 3);
|
|
|
|
|
|
|
|
cid_hdr = PJSIP_MSG_CID_HDR(tdata->msg);
|
2014-04-10 21:28:08 +00:00
|
|
|
from_hdr = PJSIP_MSG_FROM_HDR(tdata->msg);
|
|
|
|
to_hdr = PJSIP_MSG_TO_HDR(tdata->msg);
|
|
|
|
|
|
|
|
uuid = assign_uuid(&cid_hdr->id, &to_hdr->tag, &from_hdr->tag);
|
2014-03-28 18:32:50 +00:00
|
|
|
if (!uuid) {
|
|
|
|
ao2_ref(capture_info, -1);
|
|
|
|
return PJ_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_sockaddr_parse(&capture_info->src_addr, local_buf, PARSE_PORT_REQUIRE);
|
|
|
|
ast_sockaddr_parse(&capture_info->dst_addr, remote_buf, PARSE_PORT_REQUIRE);
|
|
|
|
|
|
|
|
capture_info->capture_time = ast_tvnow();
|
|
|
|
capture_info->capture_type = HEPV3_CAPTURE_TYPE_SIP;
|
|
|
|
capture_info->uuid = uuid;
|
|
|
|
capture_info->zipped = 0;
|
|
|
|
|
|
|
|
hepv3_send_packet(capture_info);
|
|
|
|
|
|
|
|
return PJ_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static pj_bool_t logging_on_rx_msg(pjsip_rx_data *rdata)
|
|
|
|
{
|
|
|
|
char local_buf[256];
|
|
|
|
char remote_buf[256];
|
|
|
|
char *uuid;
|
|
|
|
struct hepv3_capture_info *capture_info;
|
2016-05-12 07:08:08 -05:00
|
|
|
pjsip_tpmgr_fla2_param prm;
|
2014-03-28 18:32:50 +00:00
|
|
|
|
|
|
|
capture_info = hepv3_create_capture_info(&rdata->pkt_info.packet, rdata->pkt_info.len);
|
|
|
|
if (!capture_info) {
|
|
|
|
return PJ_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2016-05-12 07:08:08 -05:00
|
|
|
if (!rdata->pkt_info.src_addr_len) {
|
|
|
|
return PJ_SUCCESS;
|
2014-10-06 00:31:48 +00:00
|
|
|
}
|
2016-05-12 07:08:08 -05:00
|
|
|
pj_sockaddr_print(&rdata->pkt_info.src_addr, remote_buf, sizeof(remote_buf), 3);
|
|
|
|
|
|
|
|
/* Attempt to determine what IP address we probably received this packet on */
|
|
|
|
pjsip_tpmgr_fla2_param_default(&prm);
|
|
|
|
prm.tp_type = rdata->tp_info.transport->key.type;
|
|
|
|
pj_strset2(&prm.dst_host, rdata->pkt_info.src_name);
|
|
|
|
prm.local_if = PJ_TRUE;
|
|
|
|
|
|
|
|
/* If we can't get the local address use what we have already */
|
|
|
|
if (pjsip_tpmgr_find_local_addr2(pjsip_endpt_get_tpmgr(ast_sip_get_pjsip_endpoint()), rdata->tp_info.pool, &prm) != PJ_SUCCESS) {
|
|
|
|
pj_sockaddr_print(&rdata->tp_info.transport->local_addr, local_buf, sizeof(local_buf), 3);
|
|
|
|
} else {
|
|
|
|
if (prm.tp_type & PJSIP_TRANSPORT_IPV6) {
|
|
|
|
snprintf(local_buf, sizeof(local_buf), "[%.*s]:%hu",
|
|
|
|
(int)pj_strlen(&prm.ret_addr),
|
|
|
|
pj_strbuf(&prm.ret_addr),
|
|
|
|
prm.ret_port);
|
|
|
|
} else {
|
|
|
|
snprintf(local_buf, sizeof(local_buf), "%.*s:%hu",
|
|
|
|
(int)pj_strlen(&prm.ret_addr),
|
|
|
|
pj_strbuf(&prm.ret_addr),
|
|
|
|
prm.ret_port);
|
|
|
|
}
|
2014-10-06 00:31:48 +00:00
|
|
|
}
|
2014-03-28 18:32:50 +00:00
|
|
|
|
2014-04-10 21:28:08 +00:00
|
|
|
uuid = assign_uuid(&rdata->msg_info.cid->id, &rdata->msg_info.to->tag, &rdata->msg_info.from->tag);
|
2014-03-28 18:32:50 +00:00
|
|
|
if (!uuid) {
|
|
|
|
ao2_ref(capture_info, -1);
|
|
|
|
return PJ_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ast_sockaddr_parse(&capture_info->src_addr, remote_buf, PARSE_PORT_REQUIRE);
|
|
|
|
ast_sockaddr_parse(&capture_info->dst_addr, local_buf, PARSE_PORT_REQUIRE);
|
|
|
|
capture_info->capture_time.tv_sec = rdata->pkt_info.timestamp.sec;
|
|
|
|
capture_info->capture_time.tv_usec = rdata->pkt_info.timestamp.msec * 1000;
|
|
|
|
capture_info->capture_type = HEPV3_CAPTURE_TYPE_SIP;
|
|
|
|
capture_info->uuid = uuid;
|
|
|
|
capture_info->zipped = 0;
|
|
|
|
|
|
|
|
hepv3_send_packet(capture_info);
|
|
|
|
|
|
|
|
return PJ_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static pjsip_module logging_module = {
|
|
|
|
.name = { "HEPv3 Logging Module", 20 },
|
|
|
|
.priority = 0,
|
|
|
|
.on_rx_request = logging_on_rx_msg,
|
|
|
|
.on_rx_response = logging_on_rx_msg,
|
|
|
|
.on_tx_request = logging_on_tx_msg,
|
|
|
|
.on_tx_response = logging_on_tx_msg,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int load_module(void)
|
|
|
|
{
|
2014-10-16 16:32:25 +00:00
|
|
|
CHECK_PJSIP_MODULE_LOADED();
|
|
|
|
|
2016-06-08 12:26:29 -05:00
|
|
|
if (!ast_module_check("res_hep.so") || !hepv3_is_loaded()) {
|
|
|
|
ast_log(AST_LOG_WARNING, "res_hep is not loaded or running; declining module load\n");
|
|
|
|
return AST_MODULE_LOAD_DECLINE;
|
|
|
|
}
|
|
|
|
|
2014-03-28 18:32:50 +00:00
|
|
|
ast_sip_register_service(&logging_module);
|
|
|
|
return AST_MODULE_LOAD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int unload_module(void)
|
|
|
|
{
|
|
|
|
ast_sip_unregister_service(&logging_module);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP HEPv3 Logger",
|
2015-05-05 20:49:04 -04:00
|
|
|
.support_level = AST_MODULE_SUPPORT_EXTENDED,
|
|
|
|
.load = load_module,
|
|
|
|
.unload = unload_module,
|
|
|
|
.load_pri = AST_MODPRI_DEFAULT,
|
|
|
|
);
|