[Asterisk-code-review] res hep: Capture actual transport type in use (asterisk[14])
Sean Bright
asteriskteam at digium.com
Tue Mar 21 10:18:11 CDT 2017
Sean Bright has uploaded a new change for review. ( https://gerrit.asterisk.org/5274 )
Change subject: res_hep: Capture actual transport type in use
......................................................................
res_hep: Capture actual transport type in use
Rather than hard-coding UDP, allow consumers of the HEP API to specify
which protocol is in use. Update the PJSIP provider to pass in the
current protocol type.
ASTERISK-26850 #close
Change-Id: I54bbb0a001cfe4c6a87ad4b6f2014af233349978
---
M include/asterisk/res_hep.h
M res/res_hep.c
M res/res_hep_pjsip.c
3 files changed, 35 insertions(+), 1 deletion(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/74/5274/1
diff --git a/include/asterisk/res_hep.h b/include/asterisk/res_hep.h
index cfd213a..dba86e8 100644
--- a/include/asterisk/res_hep.h
+++ b/include/asterisk/res_hep.h
@@ -72,6 +72,8 @@
size_t len;
/*! If non-zero, the payload accompanying this capture info will be compressed */
unsigned int zipped:1;
+ /*! The IPPROTO_* protocol where we captured the packet */
+ int protocol_id;
};
/*!
diff --git a/res/res_hep.c b/res/res_hep.c
index e79f2b6..13fcbaf 100644
--- a/res/res_hep.c
+++ b/res/res_hep.c
@@ -441,6 +441,9 @@
memcpy(info->payload, payload, len);
info->len = len;
+ // Set a reasonable default
+ info->protocol_id = IPPROTO_UDP;
+
return info;
}
@@ -472,7 +475,7 @@
/* Build HEPv3 header, capture info, and calculate the total packet size */
memcpy(hg_pkt.header.id, "\x48\x45\x50\x33", 4);
- INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.ip_proto, CHUNK_TYPE_IP_PROTOCOL_ID, 0x11);
+ INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.ip_proto, CHUNK_TYPE_IP_PROTOCOL_ID, capture_info->protocol_id);
INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.src_port, CHUNK_TYPE_SRC_PORT, htons(ast_sockaddr_port(&capture_info->src_addr)));
INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.dst_port, CHUNK_TYPE_DST_PORT, htons(ast_sockaddr_port(&capture_info->dst_addr)));
INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.time_sec, CHUNK_TYPE_TIMESTAMP_SEC, htonl(capture_info->capture_time.tv_sec));
diff --git a/res/res_hep_pjsip.c b/res/res_hep_pjsip.c
index a3a93e9..4362586 100644
--- a/res/res_hep_pjsip.c
+++ b/res/res_hep_pjsip.c
@@ -73,6 +73,32 @@
return uuid;
}
+static int transport_type_to_protocol_id(enum pjsip_transport_type_e type)
+{
+ switch (type) {
+ case PJSIP_TRANSPORT_TCP:
+ case PJSIP_TRANSPORT_TCP6:
+ case PJSIP_TRANSPORT_TLS:
+ case PJSIP_TRANSPORT_TLS6:
+ case PJSIP_TRANSPORT_LOOP:
+ return IPPROTO_TCP;
+ case PJSIP_TRANSPORT_SCTP:
+ return IPPROTO_SCTP;
+ case PJSIP_TRANSPORT_IPV6:
+ return IPPROTO_IPV6;
+ case PJSIP_TRANSPORT_UDP:
+ case PJSIP_TRANSPORT_UDP6:
+ case PJSIP_TRANSPORT_LOOP_DGRAM:
+ case PJSIP_TRANSPORT_UNSPECIFIED:
+ case PJSIP_TRANSPORT_START_OTHER:
+ return IPPROTO_UDP;
+ }
+
+ /* This will never be reached */
+ ast_assert(0);
+ return 0;
+}
+
static pj_status_t logging_on_tx_msg(pjsip_tx_data *tdata)
{
char local_buf[256];
@@ -126,6 +152,7 @@
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->protocol_id = transport_type_to_protocol_id(tdata->tp_info.transport->key.type);
capture_info->capture_time = ast_tvnow();
capture_info->capture_type = HEPV3_CAPTURE_TYPE_SIP;
capture_info->uuid = uuid;
@@ -185,6 +212,8 @@
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->protocol_id = transport_type_to_protocol_id(rdata->tp_info.transport->key.type);
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;
--
To view, visit https://gerrit.asterisk.org/5274
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I54bbb0a001cfe4c6a87ad4b6f2014af233349978
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 14
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
More information about the asterisk-code-review
mailing list