From 3ffbd3796cc8507480ccb666e724725c06b901ca Mon Sep 17 00:00:00 2001 From: Bastian Triller Date: Sun, 16 Apr 2017 13:36:44 +0200 Subject: [PATCH 1/9] sipcapture: fix HEP3 capture-id >= 2^16 (cherry picked from commit dbd57c3eac30e1de54d98eb2ba8f608a17f7adbf) --- src/modules/sipcapture/sipcapture.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/sipcapture/sipcapture.c b/src/modules/sipcapture/sipcapture.c index 7167cf3053a..1111b9da65b 100644 --- a/src/modules/sipcapture/sipcapture.c +++ b/src/modules/sipcapture/sipcapture.c @@ -271,7 +271,7 @@ enum hash_source source = hs_error; //unsigned int rr_idx = 0; -struct hep_timehdr* heptime; +struct hep_timeinfo* heptime; /*! \brief * Exported functions @@ -1150,7 +1150,7 @@ static int child_init(int rank) } - heptime = (struct hep_timehdr*)pkg_malloc(sizeof(struct hep_timehdr)); + heptime = (struct hep_timeinfo*)pkg_malloc(sizeof(struct hep_timeinfo)); if(heptime==NULL) { LM_ERR("no more pkg memory left\n"); return -1; From 1e5eb8bb8ae5fe4f2a8e8940462bdd67ea760d43 Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Tue, 25 Jul 2017 15:53:52 +0300 Subject: [PATCH 2/9] modules/sipcapture: improve nonsip_hook documentation (cherry picked from commit 2f872dcc684a345cff09a437ae4a3767613b5529) --- .../sipcapture/doc/sipcapture_admin.xml | 20 +++++++++++++++++++ src/modules/sipcapture/examples/kamailio.cfg | 20 +++++++++---------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/modules/sipcapture/doc/sipcapture_admin.xml b/src/modules/sipcapture/doc/sipcapture_admin.xml index 8916317cb0a..d9d47ccedae 100644 --- a/src/modules/sipcapture/doc/sipcapture_admin.xml +++ b/src/modules/sipcapture/doc/sipcapture_admin.xml @@ -493,6 +493,26 @@ modparam("sipcapture", "topoh_unmask", 1) + +
+ <varname>nonsip_hook</varname> (int) + + If set to 1, event route sipcapture:siprequest is + run when HEP message is received. + + + Default value is 0. + + + Set <varname>nonsip_hook</varname> parameter + +... +modparam("sipcapture", "nonsip_hook", 1) +... + + +
+
Functions diff --git a/src/modules/sipcapture/examples/kamailio.cfg b/src/modules/sipcapture/examples/kamailio.cfg index 3d42a78f47f..14a5641a1c9 100644 --- a/src/modules/sipcapture/examples/kamailio.cfg +++ b/src/modules/sipcapture/examples/kamailio.cfg @@ -861,10 +861,6 @@ route[STORE] { sip_capture("$var(a)"); } -event_route[sipcapture:request] { - xlog("received sipcapture request from $si:$sp\r\n"); -} - #!ifdef WITH_HOMER_CUSTOM_STATS event_route[xhttp:request] { set_reply_close(); @@ -908,12 +904,14 @@ event_route[xhttp:request] { event_route[sipcapture:request] { - xlog("HEP Request!\n"); - xlog("received sipcapture request from $si:$sp\r\n"); - xlog("HEP VERSION $hep(version) request from $si:$sp\r\n"); - xlog("HEP CHUNK Source IP $hep(0x002) request from $si:$sp\r\n"); + xlog("HEP Request!\n"); + xlog("received sipcapture request from $si:$sp\n"); + xlog("HEP VERSION $hep(version) request from $si:$sp\n"); + xlog("HEP CHUNK Source IP $hep(0x002) request from $si:$sp\n"); + #Is it SIP ? - if($hep(0x00b) == 1){ + if($hep(0x00b) == 1) + { #Do parsing internal return 1; @@ -921,8 +919,8 @@ event_route[sipcapture:request] { else { #If report lets proceed here with payload - xlog("HEP CHUNK PAYLOAD $hep(0x00f) request from $si:$sp\r\n"); - return 0; + xlog("HEP CHUNK PAYLOAD $hep(0x00f) request from $si:$sp\n"); + return 0; } } From 97b5af5d5ac874c848f698136645dd1b92d0030a Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Thu, 27 Jul 2017 22:37:03 +0300 Subject: [PATCH 3/9] sipcapture: remove excess byte order conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - buffer pointer `tmp` in hepv3_get_chunk() was assigned to hg->time_(ยต)sec - therefore everytime route script calls pseudovariables, part of original `buf` was byte converted (cherry picked from commit 6e43bf84a2afc4e83ce33b7a416d7b81f7dd5658) --- src/modules/sipcapture/hep.c | 44 +++++++++++++----------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/src/modules/sipcapture/hep.c b/src/modules/sipcapture/hep.c index 11d2049470b..5382e5817ef 100644 --- a/src/modules/sipcapture/hep.c +++ b/src/modules/sipcapture/hep.c @@ -372,16 +372,14 @@ int parsing_hepv3_message(char *buf, unsigned int len) { break; case 9: hg->time_sec = (hep_chunk_uint32_t *) (tmp); - hg->time_sec->data = ntohl(hg->time_sec->data); - heptime->tv_sec = hg->time_sec->data; + heptime->tv_sec = ntohl(hg->time_sec->data); i+=chunk_length; totelem++; - break; - + break; + case 10: hg->time_usec = (hep_chunk_uint32_t *) (tmp); - hg->time_usec->data = ntohl(hg->time_usec->data); - heptime->tv_usec = hg->time_usec->data; + heptime->tv_usec = ntohl(hg->time_usec->data); i+=chunk_length; totelem++; break; @@ -394,8 +392,8 @@ int parsing_hepv3_message(char *buf, unsigned int len) { case 12: hg->capt_id = (hep_chunk_uint32_t *) (tmp); - i+=chunk_length; heptime->captid = ntohl(hg->capt_id->data); + i+=chunk_length; totelem++; break; @@ -483,13 +481,6 @@ int parsing_hepv3_message(char *buf, unsigned int len) { si->name.s = si->address_str.s; ri.bind_address=si; - - /*TIME*/ - heptime->tv_sec = hg->time_sec->data; - heptime->tv_usec = hg->time_usec->data; - heptime->captid = ntohl(hg->capt_id->data); - - if(payload != NULL ) { /* and now recieve message */ if (hg->proto_t->data == 5) receive_logging_json_msg(payload, payload_len, hg, "rtcp_capture"); @@ -646,19 +637,17 @@ int hepv3_message_parse(char *buf, unsigned int len, sip_msg_t* msg) { break; case 9: hg->time_sec = (hep_chunk_uint32_t *) (tmp); - hg->time_sec->data = ntohl(hg->time_sec->data); - heptime->tv_sec = hg->time_sec->data; + heptime->tv_sec = ntohl(hg->time_sec->data); i+=chunk_length; totelem++; - break; - + break; + case 10: hg->time_usec = (hep_chunk_uint32_t *) (tmp); - hg->time_usec->data = ntohl(hg->time_usec->data); - heptime->tv_usec = hg->time_usec->data; + heptime->tv_usec = ntohl(hg->time_usec->data); i+=chunk_length; totelem++; - break; + break; case 11: hg->proto_t = (hep_chunk_uint8_t *) (tmp); @@ -728,10 +717,10 @@ int hepv3_message_parse(char *buf, unsigned int len, sip_msg_t* msg) { if(payload != NULL) ret = len - payload_len; - /*TIME*/ - heptime->tv_sec = hg->time_sec->data; - heptime->tv_usec = hg->time_usec->data; - heptime->captid = ntohl(hg->capt_id->data); + + + + done: @@ -987,11 +976,10 @@ int hepv3_get_chunk(struct sip_msg *msg, char *buf, unsigned int len, int req_ch hg->time_sec->data = ntohl(hg->time_sec->data); ret = pv_get_uintval(msg, param, res, hg->time_sec->data); goto done; - + case 10: hg->time_usec = (hep_chunk_uint32_t *) (tmp); - hg->time_usec->data = ntohl(hg->time_usec->data); - ret = pv_get_uintval(msg, param, res, hg->time_usec->data); + ret = pv_get_uintval(msg, param, res, ntohl(hg->time_usec->data)); goto done; case 11: From 1ecac0c9eb4c328c9b69ae048817e1b13813b134 Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Thu, 27 Jul 2017 22:43:04 +0300 Subject: [PATCH 4/9] sipcapture: add missing or invalid byte order conversion (cherry picked from commit dac238ac3fdf2d0f47d6915508160b8160e9ab11) --- src/modules/sipcapture/hep.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/sipcapture/hep.c b/src/modules/sipcapture/hep.c index 5382e5817ef..cd3338317cb 100644 --- a/src/modules/sipcapture/hep.c +++ b/src/modules/sipcapture/hep.c @@ -989,13 +989,14 @@ int hepv3_get_chunk(struct sip_msg *msg, char *buf, unsigned int len, int req_ch case 12: hg->capt_id = (hep_chunk_uint32_t *) (tmp); - ret = pv_get_uintval(msg, param, res, ntohs(hg->capt_id->data)); + ret = pv_get_uintval(msg, param, res, ntohl(hg->capt_id->data)); goto done; case 13: hg->keep_tm = (hep_chunk_uint16_t *) (tmp); - ret = pv_get_uintval(msg, param, res, hg->keep_tm->data); + ret = pv_get_uintval(msg, param, res, ntohs(hg->keep_tm->data)); goto done; + case 14: tmpstr.s = (char *) tmp + sizeof(hep_chunk_t); tmpstr.len = chunk_length - sizeof(hep_chunk_t); From 1c944f3fb1d67dbeb97879d3177171af8d8aecd7 Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Fri, 28 Jul 2017 10:51:38 +0300 Subject: [PATCH 5/9] sipcapture: fix custom field variable naming (cherry picked from commit c8a804f5e3c3b12b64871d3989a87d79d8627afe) --- src/modules/sipcapture/sipcapture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/sipcapture/sipcapture.c b/src/modules/sipcapture/sipcapture.c index 1111b9da65b..3e6d28793fc 100644 --- a/src/modules/sipcapture/sipcapture.c +++ b/src/modules/sipcapture/sipcapture.c @@ -1887,7 +1887,7 @@ static int sip_capture(struct sip_msg *msg, str *_table, _capture_mode_data_t * else { EMPTY_STR(sco.custom1); } /* Custom - field2 */ - if(custom_field3_header.len > 0 && (tmphdr[5] = get_hdr_by_name(msg,custom_field2_header.s, custom_field2_header.len)) != NULL) { + if(custom_field2_header.len > 0 && (tmphdr[5] = get_hdr_by_name(msg,custom_field2_header.s, custom_field2_header.len)) != NULL) { sco.custom2 = tmphdr[5]->body; } else { EMPTY_STR(sco.custom2); } From f909250081f06c5b9dfd96792cc7960ff00c9f32 Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Fri, 28 Jul 2017 10:51:38 +0300 Subject: [PATCH 6/9] sipcapture: free allocated process memory before return (cherry picked from commit ecf1ad77a2b9f69d5ae4f68fdc71cb1b10ebe729) --- src/modules/sipcapture/sipcapture.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/sipcapture/sipcapture.c b/src/modules/sipcapture/sipcapture.c index 3e6d28793fc..a901236f46a 100644 --- a/src/modules/sipcapture/sipcapture.c +++ b/src/modules/sipcapture/sipcapture.c @@ -446,6 +446,7 @@ int parse_table_names (str table_name, str ** table_names){ names = (str*)pkg_malloc(sizeof(str) * no_tables); if(names == NULL) { LM_ERR("no more pkg memory left\n"); + pkg_free(table_name_cpy); return -1; } p = strtok (table_name_cpy,"| \t"); From 5274a0f9e5a5b74bbc37a6d74504b517d9dbfebe Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Mon, 31 Jul 2017 13:08:58 +0300 Subject: [PATCH 7/9] sipcapture: keep hep buffer unmodified while getting PV $hep(NNN) - addition to GH PR #1191 (cherry picked from commit 2140d0141b5a7551ebbd072d801ce2339020dac0) --- src/modules/sipcapture/hep.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/modules/sipcapture/hep.c b/src/modules/sipcapture/hep.c index cd3338317cb..6eaf13ab2b2 100644 --- a/src/modules/sipcapture/hep.c +++ b/src/modules/sipcapture/hep.c @@ -973,8 +973,7 @@ int hepv3_get_chunk(struct sip_msg *msg, char *buf, unsigned int len, int req_ch goto done; case 9: hg->time_sec = (hep_chunk_uint32_t *) (tmp); - hg->time_sec->data = ntohl(hg->time_sec->data); - ret = pv_get_uintval(msg, param, res, hg->time_sec->data); + ret = pv_get_uintval(msg, param, res, ntohl(hg->time_sec->data)); goto done; case 10: From a3d53389992f2ca7798a530d24677206b8be668b Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Sun, 13 Aug 2017 11:07:42 +0200 Subject: [PATCH 8/9] sipcapture: safety checks for values inside w_float2int() (cherry picked from commit 97d8ebc966aba71efb3a964e71b00736db51401b) --- src/modules/sipcapture/sipcapture.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/modules/sipcapture/sipcapture.c b/src/modules/sipcapture/sipcapture.c index a901236f46a..99a1844c205 100644 --- a/src/modules/sipcapture/sipcapture.c +++ b/src/modules/sipcapture/sipcapture.c @@ -1039,6 +1039,9 @@ static int w_float2int(struct sip_msg* _m, char* _val, char* _coof, char* s2) return -1; } + if(value.s==NULL || coof.s==NULL) + return -1; + ret = (int) (atof (value.s) * atoi(coof.s)); return ret ? ret : -1; From 055ad1cb61f61d9996f0018727adfcb92fa98912 Mon Sep 17 00:00:00 2001 From: Mikko Lehto Date: Thu, 27 Jul 2017 19:03:42 +0300 Subject: [PATCH 9/9] sipcapture: documentation typo (cherry picked from commit 6452e86bcc3e4b927a2e511f3c7a9f464a69ac66) --- src/modules/sipcapture/doc/sipcapture_admin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/sipcapture/doc/sipcapture_admin.xml b/src/modules/sipcapture/doc/sipcapture_admin.xml index d9d47ccedae..c5590b3c1c5 100644 --- a/src/modules/sipcapture/doc/sipcapture_admin.xml +++ b/src/modules/sipcapture/doc/sipcapture_admin.xml @@ -185,7 +185,7 @@ modparam("sipcapture", "db_insert_mode", 1)
<varname>capture_on</varname> (integer) - Parameter to enable/disable capture globaly (on(1)/off(0)) + Parameter to enable/disable capture globally (on(1)/off(0))