From: Victor Seva <vseva@sipwise.com>
Date: Wed, 27 Apr 2022 15:49:30 +0200
Subject: cfgt: skip_unknown

---
 src/modules/cfgt/cfgt_int.c         | 14 ++++++++++++++
 src/modules/cfgt/cfgt_mod.c         |  2 ++
 src/modules/cfgt/doc/cfgt_admin.xml | 20 ++++++++++++++++++++
 3 files changed, 36 insertions(+)

diff --git a/src/modules/cfgt/cfgt_int.c b/src/modules/cfgt/cfgt_int.c
index 489fdfe..4eda949 100644
--- a/src/modules/cfgt/cfgt_int.c
+++ b/src/modules/cfgt/cfgt_int.c
@@ -43,6 +43,7 @@ cfgt_hash_p _cfgt_uuid = NULL;
 str cfgt_hdr_prefix = {"NGCP%", 5};
 str cfgt_basedir = {"/tmp", 4};
 int cfgt_mask = CFGT_DP_ALL;
+int cfgt_skip_unknown = 0;
 int not_sip = 0;
 
 int _cfgt_get_filename(int msgid, str uuid, str *dest, int *dir);
@@ -384,6 +385,10 @@ void cfgt_save_node(cfgt_node_p node)
 	str dest = STR_NULL;
 	int dir = 0;
 	struct stat sb;
+	if(cfgt_skip_unknown && strncmp(_cfgt_node->uuid.s, "unknown", 7) == 0) {
+		LM_DBG("skip unknown\n");
+		return;
+	}
 	if(_cfgt_get_filename(node->msgid, node->uuid, &dest, &dir) < 0) {
 		LM_ERR("can't build filename\n");
 		return;
@@ -657,6 +662,9 @@ int cfgt_process_route(struct sip_msg *msg, struct action *a)
 		LM_ERR("node empty\n");
 		return -1;
 	}
+	if(cfgt_skip_unknown && strncmp(_cfgt_node->uuid.s, "unknown", 7) == 0) {
+			return 0;
+	}
 	if(a->rname == NULL) {
 		LM_DBG("no routename. type:%d\n", a->type);
 		return 0;
@@ -805,6 +813,9 @@ int cfgt_post(struct sip_msg *msg, unsigned int flags, void *bar)
 	str flowname = STR_NULL;
 
 	if(_cfgt_node) {
+		if(cfgt_skip_unknown && strncmp(_cfgt_node->uuid.s, "unknown", 7) == 0) {
+			return 1;
+		}
 		LM_DBG("dump last flow\n");
 		if(_cfgt_node->route == NULL
 				&& strncmp(_cfgt_node->uuid.s, "unknown", 7) == 0)
@@ -843,6 +854,9 @@ int cfgt_msgout(sr_event_param_t *evp)
 	}
 
 	if(_cfgt_node) {
+		if(cfgt_skip_unknown && strncmp(_cfgt_node->uuid.s, "unknown", 7) == 0) {
+			return 0;
+		}
 		jobj = srjson_CreateStr(&_cfgt_node->jdoc, buf->s, buf->len);
 		if(jobj == NULL) {
 			LM_ERR("cannot create json object\n");
diff --git a/src/modules/cfgt/cfgt_mod.c b/src/modules/cfgt/cfgt_mod.c
index 8806d0c..10b0889 100644
--- a/src/modules/cfgt/cfgt_mod.c
+++ b/src/modules/cfgt/cfgt_mod.c
@@ -42,6 +42,7 @@ unsigned int init_flag = 0;
 extern int cfgt_mask;
 extern str cfgt_basedir;
 extern str cfgt_hdr_prefix;
+extern int cfgt_skip_unknown;
 /* clang-format off */
 /*! \brief
  * Exported functions
@@ -58,6 +59,7 @@ static param_export_t params[] = {
 	{"basedir", PARAM_STR, &cfgt_basedir},
 	{"mask", INT_PARAM, &cfgt_mask},
 	{"callid_prefix", PARAM_STR, &cfgt_hdr_prefix},
+	{"skip_unknown", INT_PARAM, &cfgt_skip_unknown},
 	{0, 0, 0}
 };
 
diff --git a/src/modules/cfgt/doc/cfgt_admin.xml b/src/modules/cfgt/doc/cfgt_admin.xml
index 2a2b158..84d3df6 100644
--- a/src/modules/cfgt/doc/cfgt_admin.xml
+++ b/src/modules/cfgt/doc/cfgt_admin.xml
@@ -143,6 +143,26 @@ modparam("cfgt", "mask", 12)
 # using '%' as delimiter
 modparam("cfgt", "callid_prefix", "TEST-ID%")
 ...
+</programlisting>
+		</example>
+	</section>
+	<section id="cfg.p.skip_unknown">
+		<title><varname>skip_unknown</varname> (int)</title>
+		<para>
+			If enabled, value different from 0, cfgt will not generate the report
+			of any message that doesn't match the callid_prefix.
+		</para>
+		<para>
+		<emphasis>
+			Default value is <quote>0</quote>, false.
+		</emphasis>
+		</para>
+		<example>
+		<title>Set <varname>skip_unknown</varname> parameter</title>
+		<programlisting format="linespecific">
+...
+modparam("cfgt", "skip_unknown", "1")
+...
 </programlisting>
 		</example>
 	</section>
