Browse code

siptrace: Trace in-dialog ACK and dialog spirals

Enable behavior via 2 new modparams.

Stefan Mititelu authored on 02/08/2022 13:01:55 • Henning Westerholt committed on 08/08/2022 13:16:34
Showing 2 changed files
... ...
@@ -651,6 +651,43 @@ modparam("siptrace", "evcb_msg", "ksr_siptrace_msg")
651 651
 </programlisting>
652 652
                 </example>
653 653
         </section>
654
+
655
+	<section id="siptrace.p.trace_dialog_ack">
656
+                <title><varname>trace_dialog_ack</varname> (str)</title>
657
+                <para>
658
+			Enable tracing of in-dialog ACK.
659
+                </para>
660
+                <para>
661
+			Default value is 0 (disabled).
662
+                </para>
663
+                <example>
664
+			<title>Set <varname>trace_dialog_ack</varname> parameter</title>
665
+<programlisting format="linespecific">
666
+...
667
+modparam("siptrace", "trace_dialog_ack", 1)
668
+...
669
+</programlisting>
670
+                </example>
671
+        </section>
672
+
673
+	<section id="siptrace.p.trace_dialog_spiral">
674
+                <title><varname>trace_dialog_spiral</varname> (str)</title>
675
+                <para>
676
+			Enable tracing of dialog spirals.
677
+                </para>
678
+                <para>
679
+			Default value is 0 (disabled).
680
+                </para>
681
+                <example>
682
+			<title>Set <varname>trace_dialog_spiral</varname> parameter</title>
683
+<programlisting format="linespecific">
684
+...
685
+modparam("siptrace", "trace_dialog_spiral", 1)
686
+...
687
+</programlisting>
688
+                </example>
689
+        </section>
690
+
654 691
 	</section>
655 692
 
656 693
 	<section>
... ...
@@ -195,6 +195,10 @@ static str trace_local_ip = {NULL, 0};
195 195
 static db1_con_t *db_con = NULL; /*!< database connection */
196 196
 static db_func_t db_funcs;		  /*!< Database functions */
197 197
 
198
+int trace_dialog_ack = 0;
199
+int trace_dialog_spiral = 0;
200
+static int spiral_tracked;
201
+
198 202
 int pv_parse_siptrace_name(pv_spec_t *sp, str *in);
199 203
 int pv_get_siptrace(sip_msg_t *msg, pv_param_t *param,
200 204
 		pv_value_t *res);
... ...
@@ -263,6 +267,8 @@ static param_export_t params[] = {
263 267
 	{"trace_init_mode", PARAM_INT, &_siptrace_init_mode},
264 268
 	{"trace_mode", PARAM_INT, &_siptrace_mode},
265 269
 	{"evcb_msg", PARAM_STR, &_siptrace_evcb_msg},
270
+	{"trace_dialog_ack", PARAM_INT, &trace_dialog_ack},
271
+	{"trace_dialog_spiral", PARAM_INT, &trace_dialog_spiral},
266 272
 	{0, 0, 0}
267 273
 };
268 274
 /* clang-format on */
... ...
@@ -1979,12 +1985,19 @@ static void trace_dialog(struct dlg_cell* dlg, int type, struct dlg_cb_params *p
1979 1985
 	}
1980 1986
 
1981 1987
 	/* request - params->req */
1982
-	if (params == NULL || params->req == NULL) {
1988
+	if (params == NULL || (!trace_dialog_spiral && params->req == NULL)) {
1983 1989
 		LM_ERR("Invalid args!\n");
1984 1990
 		return;
1985 1991
 	}
1986 1992
 
1987
-	if (!(params->req->msg_flags & FL_SIPTRACE)) {
1993
+	if (trace_dialog_spiral && *params->param == NULL) {
1994
+		LM_DBG("Spiraled dialog!\n");
1995
+		if (dlgb.register_dlgcb(dlg, DLGCB_SPIRALED, trace_dialog, &spiral_tracked, NULL) != 0) {
1996
+			LM_ERR("could not register consider_exporting() for dialog event DLGCB_SPIRALED\n");
1997
+		}
1998
+	}
1999
+
2000
+	if (!trace_dialog_spiral && !(params->req->msg_flags & FL_SIPTRACE)) {
1988 2001
 		LM_DBG("Trace is off for this request...\n");
1989 2002
 		return;
1990 2003
 	}
... ...
@@ -2007,6 +2020,13 @@ static void trace_dialog(struct dlg_cell* dlg, int type, struct dlg_cb_params *p
2007 2020
 		return;
2008 2021
 	}
2009 2022
 
2023
+	/* this will trace in-dialog ACK */
2024
+	if(trace_dialog_ack && dlgb.register_dlgcb(dlg, DLGCB_CONFIRMED,
2025
+				trace_dialog_transaction, xavp->val.v.vptr, 0) != 0) {
2026
+		LM_ERR("Failed to register DLGCB_CONFIRMED callback!\n");
2027
+		return;
2028
+	}
2029
+
2010 2030
 	if(dlgb.register_dlgcb(dlg, DLGCB_TERMINATED,
2011 2031
 				trace_dialog_transaction, xavp->val.v.vptr, trace_free_info) != 0) {
2012 2032
 		LM_ERR("Failed to register DLGCB_TERMINATED callback!\n");