]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_hep: Capture actual transport type in use
authorSean Bright <sean.bright@gmail.com>
Tue, 21 Mar 2017 11:59:12 +0000 (07:59 -0400)
committerSean Bright <sean.bright@gmail.com>
Tue, 21 Mar 2017 19:40:24 +0000 (13:40 -0600)
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

include/asterisk/res_hep.h
res/res_hep.c
res/res_hep_pjsip.c

index cfd213ad7b43fbf4880e46cf73962fda11be1350..dba86e88b33f12ab39b1c2baa4a600d72e0d4d15 100644 (file)
@@ -72,6 +72,8 @@ struct hepv3_capture_info {
        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;
 };
 
 /*!
index e79f2b67abc0ba72f115e2912fa6d083e8ab7535..d9fbaca77e94625b0d8ba1df5fa2d28cb10ac623 100644 (file)
@@ -441,6 +441,9 @@ struct hepv3_capture_info *hepv3_create_capture_info(const void *payload, size_t
        memcpy(info->payload, payload, len);
        info->len = len;
 
+       /* Set a reasonable default */
+       info->protocol_id = IPPROTO_UDP;
+
        return info;
 }
 
@@ -472,7 +475,7 @@ static int hep_queue_cb(void *data)
        /* 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));
index a3a93e9b28a2ef8ce3308bdb164b978681cef898..8ea7b716684fa20dbe2669ea7467e5685585717f 100644 (file)
@@ -73,6 +73,15 @@ static char *assign_uuid(const pj_str_t *call_id, const pj_str_t *local_tag, con
        return uuid;
 }
 
+static int transport_to_protocol_id(pjsip_transport *tp)
+{
+       /* XXX If we ever add SCTP support, we'll need to revisit */
+       if (tp->flag & PJSIP_TRANSPORT_RELIABLE) {
+               return IPPROTO_TCP;
+       }
+       return IPPROTO_UDP;
+}
+
 static pj_status_t logging_on_tx_msg(pjsip_tx_data *tdata)
 {
        char local_buf[256];
@@ -126,6 +135,7 @@ static pj_status_t logging_on_tx_msg(pjsip_tx_data *tdata)
        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_to_protocol_id(tdata->tp_info.transport);
        capture_info->capture_time = ast_tvnow();
        capture_info->capture_type = HEPV3_CAPTURE_TYPE_SIP;
        capture_info->uuid = uuid;
@@ -185,6 +195,8 @@ static pj_bool_t logging_on_rx_msg(pjsip_rx_data *rdata)
 
        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_to_protocol_id(rdata->tp_info.transport);
        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;