Browse code

siptrace: enable tracing of in-dialog ACKs and spiraled dialogs, analog to the setting of dialog module

Henning Westerholt authored on 08/08/2022 13:18:59
Showing 1 changed files
... ...
@@ -195,8 +195,8 @@ 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;
198
+int trace_dialog_ack = 1;
199
+int trace_dialog_spiral = 1;
200 200
 static int spiral_tracked;
201 201
 
202 202
 int pv_parse_siptrace_name(pv_spec_t *sp, str *in);
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 1 changed files
... ...
@@ -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");
Browse code

siptrace: add direction attribute to exported by module pseudo-variable

- Add direction attribute to event route siptrace pseudo-variable.

Dennis Yurasov authored on 22/03/2022 12:28:45 • Daniel-Constantin Mierla committed on 24/03/2022 13:08:09
Showing 1 changed files
... ...
@@ -2601,6 +2601,8 @@ int pv_get_siptrace(sip_msg_t *msg, pv_param_t *param,
2601 2601
 			return pv_get_strval(msg, param, res, &host);
2602 2602
 		case 9: /* dst_hostip */
2603 2603
 			return pv_get_strval(msg, param, res, &host);
2604
+		case 10: /* direction */
2605
+			return pv_get_strzval(msg, param, res, siptrace_event_data->dir);
2604 2606
 		default:
2605 2607
 			LM_ERR("unexpected config param\n");
2606 2608
 			return pv_get_null(msg, param, res);
... ...
@@ -2644,6 +2646,8 @@ int pv_parse_siptrace_name(pv_spec_t *sp, str *in)
2644 2646
 				sp->pvp.pvn.u.isname.name.n = 8;
2645 2647
 			else if(strncmp(in->s, "dst_hostip", 10)==0)
2646 2648
 				sp->pvp.pvn.u.isname.name.n = 9;
2649
+			else if(strncmp(in->s, "direction", 10)==0)
2650
+				sp->pvp.pvn.u.isname.name.n = 10;
2647 2651
 			else goto error;
2648 2652
 		break;
2649 2653
 		default:
Browse code

siptrace: fix pkg memory leak when module configured with core callbacks

- Correctly freeng pkg memory in core callbacks when body modifications take place with X-Siptrace headers,
also fix potential pkg_free with not dynamicaly allocated objects.

Dennis Yurasov authored on 21/03/2022 13:23:36 • Daniel-Constantin Mierla committed on 22/03/2022 07:24:47
Showing 1 changed files
... ...
@@ -2118,6 +2118,8 @@ int siptrace_net_data_recv(sr_event_param_t *evp)
2118 2118
 	sr_net_info_t *nd;
2119 2119
 	siptrace_data_t sto;
2120 2120
 	sip_msg_t tmsg;
2121
+	int evcb_ret;
2122
+	int ret = 0;
2121 2123
 
2122 2124
 	if(evp->data == 0)
2123 2125
 		return -1;
... ...
@@ -2160,10 +2162,15 @@ int siptrace_net_data_recv(sr_event_param_t *evp)
2160 2162
 
2161 2163
 	sto.dir = "in";
2162 2164
 
2163
-	if(siptrace_exec_evcb_msg(&sto) == DROP_R_F) {
2165
+	evcb_ret=siptrace_exec_evcb_msg(&sto);
2166
+	if(evcb_ret < 0) {
2167
+		ret = -1;
2168
+		goto finish;
2169
+	}
2170
+	if(evcb_ret == DROP_R_F) {
2164 2171
 		/* drop() used in event_route - all done */
2165 2172
 		LM_DBG("skipping processing message due to drop\n");
2166
-		return 0;
2173
+		goto finish;
2167 2174
 	}
2168 2175
 
2169 2176
 	LM_DBG("processing message mode %d\n", _siptrace_mode);
... ...
@@ -2223,7 +2230,11 @@ afterdb:
2223 2230
 		trace_send_duplicate(sto.body.s, sto.body.len, NULL);
2224 2231
 	}
2225 2232
 
2226
-	return 0;
2233
+finish:
2234
+	if(sip_trace_xheaders_free(&sto) != 0)
2235
+		return -1;
2236
+
2237
+	return ret;
2227 2238
 }
2228 2239
 
2229 2240
 /**
... ...
@@ -2236,6 +2247,8 @@ int siptrace_net_data_sent(sr_event_param_t *evp)
2236 2247
 	siptrace_data_t sto;
2237 2248
 	sip_msg_t tmsg;
2238 2249
 	int proto;
2250
+	int evcb_ret;
2251
+	int ret = 0;
2239 2252
 
2240 2253
 	if(evp->data == 0)
2241 2254
 		return -1;
... ...
@@ -2268,7 +2281,7 @@ int siptrace_net_data_sent(sr_event_param_t *evp)
2268 2281
 		if(new_dst.send_sock->sock_str.len>=SIPTRACE_ADDR_MAX-1) {
2269 2282
 			LM_ERR("socket string is too large: %d\n",
2270 2283
 					new_dst.send_sock->sock_str.len);
2271
-			goto error;
2284
+			return -1;
2272 2285
 		}
2273 2286
 		strncpy(sto.fromip_buff, new_dst.send_sock->sock_str.s,
2274 2287
 				new_dst.send_sock->sock_str.len);
... ...
@@ -2291,10 +2304,15 @@ int siptrace_net_data_sent(sr_event_param_t *evp)
2291 2304
 
2292 2305
 	sto.dir = "out";
2293 2306
 
2294
-	if(siptrace_exec_evcb_msg(&sto) == DROP_R_F) {
2307
+	evcb_ret=siptrace_exec_evcb_msg(&sto);
2308
+	if(evcb_ret < 0) {
2309
+		ret = -1;
2310
+		goto finish;
2311
+	}
2312
+	if(evcb_ret == DROP_R_F) {
2295 2313
 		/* drop() used in event_route - all done */
2296 2314
 		LM_DBG("skipping processing message due to drop\n");
2297
-		return 0;
2315
+		goto finish;
2298 2316
 	}
2299 2317
 
2300 2318
 	LM_DBG("processing message mode %d\n", _siptrace_mode);
... ...
@@ -2353,11 +2371,11 @@ afterdb:
2353 2371
 	if(_siptrace_mode & SIPTRACE_MODE_URI) {
2354 2372
 		trace_send_duplicate(sto.body.s, sto.body.len, NULL);
2355 2373
 	}
2374
+finish:
2375
+	if(sip_trace_xheaders_free(&sto) != 0)
2376
+		return -1;
2356 2377
 
2357
-	return 0;
2358
-
2359
-error:
2360
-	return -1;
2378
+	return ret;
2361 2379
 }
2362 2380
 
2363 2381
 /**
Browse code

siptrace: add X-Siptrace headers when configured core callback mode and SIP URI traffic mirroring

- Added X-Siptrace headers in core callback mode for SIP URI traffic duplication,
headers also available in event route for filtering purporses.

Dennis Yurasov authored on 05/03/2022 08:36:29 • Daniel-Constantin Mierla committed on 10/03/2022 09:48:59
Showing 1 changed files
... ...
@@ -2070,6 +2070,11 @@ static int siptrace_exec_evcb_msg(siptrace_data_t *sto)
2070 2070
 		return -1;
2071 2071
 	}
2072 2072
 
2073
+	if(_siptrace_mode & SIPTRACE_MODE_URI) {
2074
+		if(sip_trace_xheaders_write(sto) != 0)
2075
+			return -1;
2076
+	}
2077
+
2073 2078
 	memset(&msg, 0, sizeof(sip_msg_t));
2074 2079
 	msg.buf = sto->body.s;
2075 2080
 	msg.len = sto->body.len;
Browse code

siptrace: added extra params to $siptrace() pseudo-variable

for more details check GH #2777

Sergey Safarov authored on 10/06/2021 16:41:07 • Daniel-Constantin Mierla committed on 23/06/2021 07:56:51
Showing 1 changed files
... ...
@@ -2505,16 +2505,82 @@ static sr_kemi_t sr_kemi_siptrace_exports[] = {
2505 2505
 int pv_get_siptrace(sip_msg_t *msg, pv_param_t *param,
2506 2506
 		pv_value_t *res)
2507 2507
 {
2508
+	str host;
2509
+	int port;
2510
+	int proto;
2511
+	str sproto;
2508 2512
 	if (siptrace_event_data==NULL) {
2509 2513
 		return pv_get_null(msg, param, res);
2510 2514
 	}
2511 2515
 
2512 2516
 	switch(param->pvn.u.isname.name.n) {
2513
-		case 1: /* dst_uri*/
2517
+		case 2: /* src_host */
2518
+		case 4: /* src_port */
2519
+		case 6: /* src_proto */
2520
+		case 8: /* src_hostip */
2521
+			if (parse_phostport(siptrace_event_data->fromip.s, &host.s, &host.len, &port, &proto)!=0) {
2522
+				LM_ERR("invalid src_addr: %.*s\n", siptrace_event_data->fromip.len, siptrace_event_data->fromip.s);
2523
+				return pv_get_null(msg, param, res);
2524
+			}
2525
+		break;
2526
+		case 3: /* dst_host */
2527
+		case 5: /* dst_port */
2528
+		case 7: /* dst_proto */
2529
+		case 9: /* dst_hostip */
2530
+			if (parse_phostport(siptrace_event_data->toip.s, &host.s, &host.len, &port, &proto)!=0) {
2531
+				LM_ERR("invalid dst_addr: %.*s\n", siptrace_event_data->toip.len, siptrace_event_data->toip.s);
2532
+				return pv_get_null(msg, param, res);
2533
+			}
2534
+		break;
2535
+	}
2536
+
2537
+	switch(param->pvn.u.isname.name.n) {
2538
+		case 6: /* src_proto */
2539
+		case 7: /* dst_proto */
2540
+			if(get_valid_proto_string(proto, 0, 0, &sproto)<0)
2541
+			{
2542
+				sproto.s = "none";
2543
+				sproto.len = 4;
2544
+			}
2545
+		break;
2546
+	}
2547
+
2548
+	switch(param->pvn.u.isname.name.n) {
2549
+		case 8: /* src_hostip */
2550
+		case 9: /* dst_hostip */
2551
+
2552
+			/* now IPv6 address has brakets that not wanted in IP address operations */
2553
+			if(host.s[0] == '[' && host.s[host.len-1] == ']') {
2554
+				host.s++;
2555
+				host.len = host.len - 2;
2556
+			}
2557
+		break;
2558
+	}
2559
+
2560
+	switch(param->pvn.u.isname.name.n) {
2561
+		case 0: /* src_addr */
2562
+			return pv_get_strval(msg, param, res, &siptrace_event_data->fromip);
2563
+		case 1: /* dst_addr */
2514 2564
 			return pv_get_strval(msg, param, res, &siptrace_event_data->toip);
2565
+		case 2: /* src_host */
2566
+			return pv_get_strval(msg, param, res, &host);
2567
+		case 3: /* dst_host */
2568
+			return pv_get_strval(msg, param, res, &host);
2569
+		case 4: /* src_port */
2570
+			return pv_get_sintval(msg, param, res, port);
2571
+		case 5: /* dst_port */
2572
+			return pv_get_sintval(msg, param, res, port);
2573
+		case 6: /* src_proto */
2574
+			return pv_get_strintval(msg, param, res, &sproto, proto);
2575
+		case 7: /* dst_proto */
2576
+			return pv_get_strintval(msg, param, res, &sproto, proto);
2577
+		case 8: /* src_hostip */
2578
+			return pv_get_strval(msg, param, res, &host);
2579
+		case 9: /* dst_hostip */
2580
+			return pv_get_strval(msg, param, res, &host);
2515 2581
 		default:
2516
-			/* 0 - src_uri */
2517
-			return pv_get_strval(msg, param, res, &siptrace_event_data->fromip);
2582
+			LM_ERR("unexpected config param\n");
2583
+			return pv_get_null(msg, param, res);
2518 2584
 	}
2519 2585
 }
2520 2586
 
... ...
@@ -2533,6 +2599,28 @@ int pv_parse_siptrace_name(pv_spec_t *sp, str *in)
2533 2599
 				sp->pvp.pvn.u.isname.name.n = 0;
2534 2600
 			else if(strncmp(in->s, "dst_addr", 8)==0)
2535 2601
 				sp->pvp.pvn.u.isname.name.n = 1;
2602
+			else if(strncmp(in->s, "src_host", 8)==0)
2603
+				sp->pvp.pvn.u.isname.name.n = 2;
2604
+			else if(strncmp(in->s, "dst_host", 8)==0)
2605
+				sp->pvp.pvn.u.isname.name.n = 3;
2606
+			else if(strncmp(in->s, "src_port", 8)==0)
2607
+				sp->pvp.pvn.u.isname.name.n = 4;
2608
+			else if(strncmp(in->s, "dst_port", 8)==0)
2609
+				sp->pvp.pvn.u.isname.name.n = 5;
2610
+			else goto error;
2611
+		break;
2612
+		case 9:
2613
+			if(strncmp(in->s, "src_proto", 9)==0)
2614
+				sp->pvp.pvn.u.isname.name.n = 6;
2615
+			else if(strncmp(in->s, "dst_proto", 9)==0)
2616
+				sp->pvp.pvn.u.isname.name.n = 7;
2617
+			else goto error;
2618
+		break;
2619
+		case 10:
2620
+			if(strncmp(in->s, "src_hostip", 10)==0)
2621
+				sp->pvp.pvn.u.isname.name.n = 8;
2622
+			else if(strncmp(in->s, "dst_hostip", 10)==0)
2623
+				sp->pvp.pvn.u.isname.name.n = 9;
2536 2624
 			else goto error;
2537 2625
 		break;
2538 2626
 		default:
Browse code

siptrace: fixed IPv6 without brackets

more details GH #2775

Sergey Safarov authored on 10/06/2021 09:17:54 • Daniel-Constantin Mierla committed on 10/06/2021 10:05:49
Showing 1 changed files
... ...
@@ -2133,7 +2133,7 @@ int siptrace_net_data_recv(sr_event_param_t *evp)
2133 2133
 
2134 2134
 	sto.fromip.len = snprintf(sto.fromip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d",
2135 2135
 			siptrace_proto_name(nd->rcv->proto),
2136
-			ip_addr2a(&nd->rcv->src_ip), (int)nd->rcv->src_port);
2136
+			ip_addr2strz(&nd->rcv->src_ip), (int)nd->rcv->src_port);
2137 2137
 	if(sto.fromip.len<0 || sto.fromip.len>=SIPTRACE_ADDR_MAX) {
2138 2138
 		LM_ERR("failed to format toip buffer (%d)\n", sto.fromip.len);
2139 2139
 		sto.fromip.s = SIPTRACE_ANYADDR;
... ...
@@ -2143,7 +2143,7 @@ int siptrace_net_data_recv(sr_event_param_t *evp)
2143 2143
 	}
2144 2144
 
2145 2145
 	sto.toip.len = snprintf(sto.toip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d",
2146
-			siptrace_proto_name(nd->rcv->proto), ip_addr2a(&nd->rcv->dst_ip),
2146
+			siptrace_proto_name(nd->rcv->proto), ip_addr2strz(&nd->rcv->dst_ip),
2147 2147
 			(int)nd->rcv->dst_port);
2148 2148
 	if(sto.toip.len<0 || sto.toip.len>=SIPTRACE_ADDR_MAX) {
2149 2149
 		LM_ERR("failed to format toip buffer (%d)\n", sto.toip.len);
Browse code

siptrace: use src/dst_addr instead src/dst_uri for $siptrace(...) vars

- the format is proto:ip:proto, not a sip uri

Daniel-Constantin Mierla authored on 09/06/2021 10:31:31
Showing 1 changed files
... ...
@@ -2528,10 +2528,10 @@ int pv_parse_siptrace_name(pv_spec_t *sp, str *in)
2528 2528
 
2529 2529
 	switch(in->len)
2530 2530
 	{
2531
-		case 7:
2532
-			if(strncmp(in->s, "src_uri", 7)==0)
2531
+		case 8:
2532
+			if(strncmp(in->s, "src_addr", 8)==0)
2533 2533
 				sp->pvp.pvn.u.isname.name.n = 0;
2534
-			else if(strncmp(in->s, "dst_uri", 7)==0)
2534
+			else if(strncmp(in->s, "dst_addr", 8)==0)
2535 2535
 				sp->pvp.pvn.u.isname.name.n = 1;
2536 2536
 			else goto error;
2537 2537
 		break;
Browse code

siptrace: aadded siptrace pseudo var

Sergey Safarov authored on 29/05/2021 17:10:39 • Daniel-Constantin Mierla committed on 09/06/2021 07:21:16
Showing 1 changed files
... ...
@@ -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 pv_parse_siptrace_name(pv_spec_t *sp, str *in);
199
+int pv_get_siptrace(sip_msg_t *msg, pv_param_t *param,
200
+		pv_value_t *res);
201
+
198 202
 /*! \brief
199 203
  * Exported functions
200 204
  */
... ...
@@ -276,6 +280,14 @@ stat_export_t siptrace_stats[] = {
276 280
 /* clang-format on */
277 281
 #endif
278 282
 
283
+static pv_export_t mod_pvs[] = {
284
+
285
+	{ {"siptrace", (sizeof("siptrace")-1)}, PVT_OTHER, pv_get_siptrace, 0,
286
+		pv_parse_siptrace_name, 0, 0, 0 },
287
+
288
+	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
289
+};
290
+
279 291
 /*! \brief module exports */
280 292
 /* clang-format off */
281 293
 struct module_exports exports = {
... ...
@@ -283,9 +295,9 @@ struct module_exports exports = {
283 295
 	DEFAULT_DLFLAGS, /*!< dlopen flags */
284 296
 	cmds,			/*!< exported functions */
285 297
 	params,			/*!< exported parameters */
286
-	0,				/*!< exported rpc functions */
287
-	0,				/*!< exported pseudo-variables */
288
-	0,				/*!< response function */
298
+	0,			/*!< exported rpc functions */
299
+	mod_pvs,		/*!< exported pseudo-variables */
300
+	0,			/*!< response function */
289 301
 	mod_init,		/*!< module initialization function */
290 302
 	child_init,		/*!< child initialization function */
291 303
 	destroy			/*!< destroy function */
... ...
@@ -2039,6 +2051,8 @@ static void trace_free_info(void* trace_info)
2039 2051
 	shm_free(trace_info);
2040 2052
 }
2041 2053
 
2054
+static siptrace_data_t* siptrace_event_data = NULL;
2055
+
2042 2056
 static int siptrace_exec_evcb_msg(siptrace_data_t *sto)
2043 2057
 {
2044 2058
 	int backup_rt;
... ...
@@ -2068,6 +2082,7 @@ static int siptrace_exec_evcb_msg(siptrace_data_t *sto)
2068 2082
 	set_route_type(EVENT_ROUTE);
2069 2083
 	init_run_actions_ctx(&ctx);
2070 2084
 
2085
+	siptrace_event_data = sto;
2071 2086
 	if(_siptrace_evrt_msg_idx>=0) {
2072 2087
 		run_top_route(event_rt.rlist[_siptrace_evrt_msg_idx], &msg, &ctx);
2073 2088
 	} else {
... ...
@@ -2080,6 +2095,7 @@ static int siptrace_exec_evcb_msg(siptrace_data_t *sto)
2080 2095
 			sr_kemi_act_ctx_set(bctx);
2081 2096
 		}
2082 2097
 	}
2098
+	siptrace_event_data = NULL;
2083 2099
 
2084 2100
 	free_sip_msg(&msg);
2085 2101
 	set_route_type(backup_rt);
... ...
@@ -2482,6 +2498,56 @@ static sr_kemi_t sr_kemi_siptrace_exports[] = {
2482 2498
 
2483 2499
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
2484 2500
 };
2501
+
2502
+/**
2503
+ *
2504
+ */
2505
+int pv_get_siptrace(sip_msg_t *msg, pv_param_t *param,
2506
+		pv_value_t *res)
2507
+{
2508
+	if (siptrace_event_data==NULL) {
2509
+		return pv_get_null(msg, param, res);
2510
+	}
2511
+
2512
+	switch(param->pvn.u.isname.name.n) {
2513
+		case 1: /* dst_uri*/
2514
+			return pv_get_strval(msg, param, res, &siptrace_event_data->toip);
2515
+		default:
2516
+			/* 0 - src_uri */
2517
+			return pv_get_strval(msg, param, res, &siptrace_event_data->fromip);
2518
+	}
2519
+}
2520
+
2521
+/**
2522
+ *
2523
+ */
2524
+int pv_parse_siptrace_name(pv_spec_t *sp, str *in)
2525
+{
2526
+	if(sp==NULL || in==NULL || in->len<=0)
2527
+		return -1;
2528
+
2529
+	switch(in->len)
2530
+	{
2531
+		case 7:
2532
+			if(strncmp(in->s, "src_uri", 7)==0)
2533
+				sp->pvp.pvn.u.isname.name.n = 0;
2534
+			else if(strncmp(in->s, "dst_uri", 7)==0)
2535
+				sp->pvp.pvn.u.isname.name.n = 1;
2536
+			else goto error;
2537
+		break;
2538
+		default:
2539
+			goto error;
2540
+	}
2541
+	sp->pvp.pvn.type = PV_NAME_INTSTR;
2542
+	sp->pvp.pvn.u.isname.type = 0;
2543
+
2544
+	return 0;
2545
+
2546
+error:
2547
+	LM_ERR("unknown PV snd name %.*s\n", in->len, in->s);
2548
+	return -1;
2549
+}
2550
+
2485 2551
 /* clang-format on */
2486 2552
 
2487 2553
 /**
Browse code

siptrace: debug messages on net data callbacks

Daniel-Constantin Mierla authored on 04/05/2021 12:08:59
Showing 1 changed files
... ...
@@ -2141,9 +2141,12 @@ int siptrace_net_data_recv(sr_event_param_t *evp)
2141 2141
 
2142 2142
 	if(siptrace_exec_evcb_msg(&sto) == DROP_R_F) {
2143 2143
 		/* drop() used in event_route - all done */
2144
+		LM_DBG("skipping processing message due to drop\n");
2144 2145
 		return 0;
2145 2146
 	}
2146 2147
 
2148
+	LM_DBG("processing message mode %d\n", _siptrace_mode);
2149
+
2147 2150
 	if(_siptrace_mode & SIPTRACE_MODE_HEP) {
2148 2151
 		trace_send_hep_duplicate(&sto.body, &sto.fromip, &sto.toip, NULL, NULL);
2149 2152
 	}
... ...
@@ -2269,9 +2272,12 @@ int siptrace_net_data_sent(sr_event_param_t *evp)
2269 2272
 
2270 2273
 	if(siptrace_exec_evcb_msg(&sto) == DROP_R_F) {
2271 2274
 		/* drop() used in event_route - all done */
2275
+		LM_DBG("skipping processing message due to drop\n");
2272 2276
 		return 0;
2273 2277
 	}
2274 2278
 
2279
+	LM_DBG("processing message mode %d\n", _siptrace_mode);
2280
+
2275 2281
 	if(_siptrace_mode & SIPTRACE_MODE_HEP) {
2276 2282
 		trace_send_hep_duplicate(&sto.body, &sto.fromip, &sto.toip, NULL, NULL);
2277 2283
 	}
Browse code

siptrace: fallback to udp if send sock is not set

Daniel-Constantin Mierla authored on 09/04/2021 14:37:30
Showing 1 changed files
... ...
@@ -2211,6 +2211,7 @@ int siptrace_net_data_sent(sr_event_param_t *evp)
2211 2211
 	dest_info_t new_dst;
2212 2212
 	siptrace_data_t sto;
2213 2213
 	sip_msg_t tmsg;
2214
+	int proto;
2214 2215
 
2215 2216
 	if(evp->data == 0)
2216 2217
 		return -1;
... ...
@@ -2238,6 +2239,7 @@ int siptrace_net_data_sent(sr_event_param_t *evp)
2238 2239
 		LM_WARN("no sending socket found\n");
2239 2240
 		strcpy(sto.fromip_buff, SIPTRACE_ANYADDR);
2240 2241
 		sto.fromip.len = SIPTRACE_ANYADDR_LEN;
2242
+		proto = PROTO_UDP;
2241 2243
 	} else {
2242 2244
 		if(new_dst.send_sock->sock_str.len>=SIPTRACE_ADDR_MAX-1) {
2243 2245
 			LM_ERR("socket string is too large: %d\n",
... ...
@@ -2247,11 +2249,12 @@ int siptrace_net_data_sent(sr_event_param_t *evp)
2247 2249
 		strncpy(sto.fromip_buff, new_dst.send_sock->sock_str.s,
2248 2250
 				new_dst.send_sock->sock_str.len);
2249 2251
 		sto.fromip.len = new_dst.send_sock->sock_str.len;
2252
+		proto = new_dst.send_sock->proto;
2250 2253
 	}
2251 2254
 	sto.fromip.s = sto.fromip_buff;
2252 2255
 
2253 2256
 	sto.toip.len = snprintf(sto.toip_buff, SIPTRACE_ADDR_MAX, "%s:%s:%d",
2254
-			siptrace_proto_name(new_dst.send_sock->proto),
2257
+			siptrace_proto_name(proto),
2255 2258
 			suip2a(&new_dst.to, sizeof(new_dst.to)),
2256 2259
 			(int)su_getport(&new_dst.to));
2257 2260
 	if(sto.toip.len<0 || sto.toip.len>=SIPTRACE_ADDR_MAX) {
Browse code

siptrace: properly terminate logs with '\n'

Ovidiu Sas authored on 24/03/2021 23:35:11
Showing 1 changed files
... ...
@@ -319,7 +319,7 @@ static int mod_init(void)
319 319
 	}
320 320
 
321 321
 	if(hep_version != 1 && hep_version != 2 && hep_version != 3) {
322
-		LM_ERR("unsupported version of HEP");
322
+		LM_ERR("unsupported version of HEP\n");
323 323
 		return -1;
324 324
 	}
325 325
 
... ...
@@ -2154,7 +2154,7 @@ int siptrace_net_data_recv(sr_event_param_t *evp)
2154 2154
 		tmsg.len = sto.body.len;
2155 2155
 
2156 2156
 		if (parse_msg(tmsg.buf, tmsg.len, &tmsg)!=0) {
2157
-			LM_DBG("msg buffer parsing failed!");
2157
+			LM_DBG("msg buffer parsing failed!\n");
2158 2158
 			goto afterdb;
2159 2159
 		}
2160 2160
 
... ...
@@ -2279,7 +2279,7 @@ int siptrace_net_data_sent(sr_event_param_t *evp)
2279 2279
 		tmsg.len = sto.body.len;
2280 2280
 
2281 2281
 		if (parse_msg(tmsg.buf, tmsg.len, &tmsg)!=0) {
2282
-			LM_DBG("msg buffer parsing failed!");
2282
+			LM_DBG("msg buffer parsing failed!\n");
2283 2283
 			goto afterdb;
2284 2284
 		}
2285 2285
 
Browse code

siptrace: renamed SREV_NET_DATA_SEND to SREV_NET_DATA_SENT

Daniel-Constantin Mierla authored on 24/03/2021 08:05:55
Showing 1 changed files
... ...
@@ -119,7 +119,7 @@ static int  trace_add_info_xavp(siptrace_info_t* info);
119 119
 static inline int trace_parse_raw_uri(siptrace_info_t* info);
120 120
 
121 121
 int siptrace_net_data_recv(sr_event_param_t *evp);
122
-int siptrace_net_data_send(sr_event_param_t *evp);
122
+int siptrace_net_data_sent(sr_event_param_t *evp);
123 123
 
124 124
 #define SIPTRACE_INIT_MODE_ALL 0
125 125
 #define SIPTRACE_INIT_MODE_CORECB 1
... ...
@@ -481,7 +481,7 @@ static int mod_init(void)
481 481
 			|| _siptrace_init_mode==SIPTRACE_INIT_MODE_CORECB) {
482 482
 		if(_siptrace_mode != SIPTRACE_MODE_NONE) {
483 483
 			sr_event_register_cb(SREV_NET_DATA_RECV, siptrace_net_data_recv);
484
-			sr_event_register_cb(SREV_NET_DATA_SEND, siptrace_net_data_send);
484
+			sr_event_register_cb(SREV_NET_DATA_SENT, siptrace_net_data_sent);
485 485
 		} else if(_siptrace_init_mode==SIPTRACE_INIT_MODE_CORECB) {
486 486
 			LM_ERR("invalid config options for core callbacks tracing\n");
487 487
 			return -1;
... ...
@@ -2205,7 +2205,7 @@ afterdb:
2205 2205
 /**
2206 2206
  *
2207 2207
  */
2208
-int siptrace_net_data_send(sr_event_param_t *evp)
2208
+int siptrace_net_data_sent(sr_event_param_t *evp)
2209 2209
 {
2210 2210
 	sr_net_info_t *nd;
2211 2211
 	dest_info_t new_dst;
Browse code

modules/siptrace: fix regression preventing variables to be used (#2588)

* modules/siptrace: fix regression preventing variables to be used

Commit fa7eb2a switched the 2 parameter version of sip_trace from
using the builtin fixup_spve_spve to the custom fixup method to
using the custom fixup_siptrace. As it is a custom fixup method,
the corresponding free method can not be auto-detected causing the
config parser to require the parameters to be a constant. This
patch adds a free method, allowing variables to be once again passed
as the 2nd parameter of this method (as well as fixing a memory leak
for the 3rd parameter).

* change free for parameter 3

Co-authored-by: Torrey Searle <tsearle@voxbone.com>

tsearle authored on 16/12/2020 20:47:11 • GitHub committed on 16/12/2020 20:47:11
Showing 1 changed files
... ...
@@ -91,6 +91,7 @@ static int w_sip_trace1(struct sip_msg *, char *dest, char *p2);
91 91
 static int w_sip_trace2(struct sip_msg *, char *dest, char *correlation_id);
92 92
 static int w_sip_trace3(struct sip_msg *, char *dest, char *correlation_id, char *trace_type);
93 93
 static int fixup_siptrace(void **param, int param_no);
94
+static int fixup_free_siptrace(void **param, int param_no);
94 95
 static int w_sip_trace_mode(sip_msg_t *msg, char *pmode, char *p2);
95 96
 
96 97
 static int siptrace_parse_uri(str* duri, dest_info_t* dst);
... ...
@@ -203,9 +204,9 @@ static cmd_export_t cmds[] = {
203 204
 		ANY_ROUTE},
204 205
 	{"sip_trace", (cmd_function)w_sip_trace1, 1, fixup_siptrace, 0,
205 206
 		ANY_ROUTE},
206
-	{"sip_trace", (cmd_function)w_sip_trace2, 2, fixup_siptrace, 0,
207
+	{"sip_trace", (cmd_function)w_sip_trace2, 2, fixup_siptrace, fixup_free_siptrace,
207 208
 		ANY_ROUTE},
208
-	{"sip_trace", (cmd_function)w_sip_trace3, 3, fixup_siptrace, 0,
209
+	{"sip_trace", (cmd_function)w_sip_trace3, 3, fixup_siptrace, fixup_free_siptrace,
209 210
 		ANY_ROUTE},
210 211
 	{"hlog", (cmd_function)w_hlog1, 1, fixup_spve_null, 0,
211 212
 		ANY_ROUTE},
... ...
@@ -785,6 +786,21 @@ static int fixup_siptrace(void **param, int param_no)
785 786
 	return 0;
786 787
 }
787 788
 
789
+static int fixup_free_siptrace(void **param, int param_no)
790
+{
791
+	if (param_no == 1 || param_no == 2) {
792
+		/* correlation id */
793
+		return fixup_free_spve_all(param, param_no);
794
+	} if (param_no == 3) {
795
+		/* tracing type; string only */
796
+		if (*param) {
797
+			pkg_free(*param);
798
+		}
799
+	}
800
+
801
+	return 0;
802
+}
803
+
788 804
 
789 805
 /**
790 806
  *
Browse code

siptrace: fix run_top_route() call to set ctx

- fix drop() usage in siptrace:msg event route

Nuno Ferreira authored on 07/08/2020 18:20:00
Showing 1 changed files
... ...
@@ -2053,7 +2053,7 @@ static int siptrace_exec_evcb_msg(siptrace_data_t *sto)
2053 2053
 	init_run_actions_ctx(&ctx);
2054 2054
 
2055 2055
 	if(_siptrace_evrt_msg_idx>=0) {
2056
-		run_top_route(event_rt.rlist[_siptrace_evrt_msg_idx], &msg, 0);
2056
+		run_top_route(event_rt.rlist[_siptrace_evrt_msg_idx], &msg, &ctx);
2057 2057
 	} else {
2058 2058
 		keng = sr_kemi_eng_get();
2059 2059
 		if (keng!=NULL) {
Browse code

siptrace: exec event_route[siptrace:msg] on message replication with core events

- new parameter evcb_msg to set the kemi function name to be executed
for this event callback
- alternative to GH #2374

Daniel-Constantin Mierla authored on 13/07/2020 10:24:44
Showing 1 changed files
... ...
@@ -178,6 +178,9 @@ socket_info_t *trace_send_sock_info = 0;
178 178
 str trace_dup_uri_str = {0, 0};
179 179
 sip_uri_t *trace_dup_uri = 0;
180 180
 
181
+static str _siptrace_evcb_msg = STR_NULL;
182
+static int _siptrace_evrt_msg_idx = -1;
183
+
181 184
 static unsigned short traced_user_avp_type = 0;
182 185
 static int_str traced_user_avp;
183 186
 static str traced_user_avp_str = {NULL, 0};
... ...
@@ -254,6 +257,7 @@ static param_export_t params[] = {
254 257
 	{"trace_db_mode", INT_PARAM, &trace_db_mode},
255 258
 	{"trace_init_mode", PARAM_INT, &_siptrace_init_mode},
256 259
 	{"trace_mode", PARAM_INT, &_siptrace_mode},
260
+	{"evcb_msg", PARAM_STR, &_siptrace_evcb_msg},
257 261
 	{0, 0, 0}
258 262
 };
259 263
 /* clang-format on */
... ...
@@ -302,6 +306,8 @@ static int mod_init(void)
302 306
 	}
303 307
 #endif
304 308
 
309
+	_siptrace_evrt_msg_idx = route_lookup(&event_rt, "siptrace:msg");
310
+
305 311
 	if(trace_db_delayed!=0) {
306 312
 		trace_db_mode = 1;
307 313
 	}
... ...
@@ -2017,6 +2023,56 @@ static void trace_free_info(void* trace_info)
2017 2023
 	shm_free(trace_info);
2018 2024
 }
2019 2025
 
2026
+static int siptrace_exec_evcb_msg(siptrace_data_t *sto)
2027
+{
2028
+	int backup_rt;
2029
+	run_act_ctx_t ctx;
2030
+	run_act_ctx_t *bctx;
2031
+	sr_kemi_eng_t *keng = NULL;
2032
+	str evname = str_init("siptrace:msg");
2033
+	sip_msg_t msg;
2034
+
2035
+	if(_siptrace_evrt_msg_idx < 0 && _siptrace_evcb_msg.len<=0) {
2036
+		return 0;
2037
+	}
2038
+
2039
+	if(sto == NULL || sto->body.s == NULL || sto->body.len <= 0) {
2040
+		return -1;
2041
+	}
2042
+
2043
+	memset(&msg, 0, sizeof(sip_msg_t));
2044
+	msg.buf = sto->body.s;
2045
+	msg.len = sto->body.len;
2046
+	if(parse_msg(msg.buf, msg.len, &msg) != 0) {
2047
+		LM_DBG("parse_msg failed\n");
2048
+		return -1;
2049
+	}
2050
+
2051
+	backup_rt = get_route_type();
2052
+	set_route_type(EVENT_ROUTE);
2053
+	init_run_actions_ctx(&ctx);
2054
+
2055
+	if(_siptrace_evrt_msg_idx>=0) {
2056
+		run_top_route(event_rt.rlist[_siptrace_evrt_msg_idx], &msg, 0);
2057
+	} else {
2058
+		keng = sr_kemi_eng_get();
2059
+		if (keng!=NULL) {
2060
+			bctx = sr_kemi_act_ctx_get();
2061
+			sr_kemi_act_ctx_set(&ctx);
2062
+			(void)sr_kemi_route(keng, &msg, EVENT_ROUTE,
2063
+						&_siptrace_evcb_msg, &evname);
2064
+			sr_kemi_act_ctx_set(bctx);
2065
+		}
2066
+	}
2067
+
2068
+	free_sip_msg(&msg);
2069
+	set_route_type(backup_rt);
2070
+	if(ctx.run_flags & DROP_R_F) {
2071
+		return DROP_R_F;
2072
+	}
2073
+	return RETURN_R_F;
2074
+}
2075
+
2020 2076
 /**
2021 2077
  *
2022 2078
  */
... ...
@@ -2067,6 +2123,11 @@ int siptrace_net_data_recv(sr_event_param_t *evp)
2067 2123
 
2068 2124
 	sto.dir = "in";
2069 2125
 
2126
+	if(siptrace_exec_evcb_msg(&sto) == DROP_R_F) {
2127
+		/* drop() used in event_route - all done */
2128
+		return 0;
2129
+	}
2130
+
2070 2131
 	if(_siptrace_mode & SIPTRACE_MODE_HEP) {
2071 2132
 		trace_send_hep_duplicate(&sto.body, &sto.fromip, &sto.toip, NULL, NULL);
2072 2133
 	}
... ...
@@ -2187,6 +2248,11 @@ int siptrace_net_data_send(sr_event_param_t *evp)
2187 2248
 
2188 2249
 	sto.dir = "out";
2189 2250
 
2251
+	if(siptrace_exec_evcb_msg(&sto) == DROP_R_F) {
2252
+		/* drop() used in event_route - all done */
2253
+		return 0;
2254
+	}
2255
+
2190 2256
 	if(_siptrace_mode & SIPTRACE_MODE_HEP) {
2191 2257
 		trace_send_hep_duplicate(&sto.body, &sto.fromip, &sto.toip, NULL, NULL);
2192 2258
 	}
Browse code

siptrace: fix regression introduced from 4e9a760123c for siptrace(), sip_trace_mode()

- fix regression introduced from 4e9a760123c for siptrace(), sip_trace_mode()
- it was not working properly without destination uri in non-HEP mode

Henning Westerholt authored on 05/06/2020 09:25:04
Showing 1 changed files
... ...
@@ -562,7 +562,8 @@ static int sip_trace_store(siptrace_data_t *sto, dest_info_t *dst,
562 562
 		trace_send_hep_duplicate(
563 563
 				&sto->body, &sto->fromip, &sto->toip, dst, correlation_id_str);
564 564
 	} else {
565
-		if(dst) {
565
+		/* sip_trace_mode() will not set a destination, uses duplicate_uri */
566
+		if(dst || trace_to_database == 0) {
566 567
 			trace_send_duplicate(sto->body.s, sto->body.len, dst);
567 568
 		}
568 569
 	}
... ...
@@ -1070,10 +1071,13 @@ static int w_sip_trace3(sip_msg_t *msg, char *dest, char *correlation_id, char *
1070 1071
 	dest_info_t dest_info;
1071 1072
 	enum siptrace_type_t trace_type;
1072 1073
 
1073
-	if (dest) {
1074
-		if(fixup_get_svalue(msg, (gparam_t *)dest, &dup_uri_param_str) != 0) {
1075
-			LM_ERR("unable to parse the dest URI string\n");
1076
-			return -1;
1074
+	/* to support tracing to database without destination parameter - old mode */
1075
+	if (dest || trace_to_database == 0) {
1076
+		if (dest) {
1077
+			if(fixup_get_svalue(msg, (gparam_t *)dest, &dup_uri_param_str) != 0) {
1078
+				LM_ERR("unable to parse the dest URI string\n");
1079
+				return -1;
1080
+			}
1077 1081
 		}
1078 1082
 
1079 1083
 		if (dup_uri_param_str.s == 0 || (is_null_pv(dup_uri_param_str))) {
Browse code

siptrace: skip non-sip traffic for db storage using core callbacks

Daniel-Constantin Mierla authored on 02/05/2020 13:02:55
Showing 1 changed files
... ...
@@ -2077,6 +2077,24 @@ int siptrace_net_data_recv(sr_event_param_t *evp)
2077 2077
 			goto afterdb;
2078 2078
 		}
2079 2079
 
2080
+		if(tmsg.first_line.type==SIP_REQUEST) {
2081
+			if(!IS_SIP(&tmsg)) {
2082
+				LM_DBG("non sip request message\n");
2083
+				free_sip_msg(&tmsg);
2084
+				goto afterdb;
2085
+			}
2086
+		} else if(tmsg.first_line.type==SIP_REPLY) {
2087
+			if(!IS_SIP_REPLY(&tmsg)) {
2088
+				LM_DBG("non sip reply message\n");
2089
+				free_sip_msg(&tmsg);
2090
+				goto afterdb;
2091
+			}
2092
+		} else {
2093
+			LM_DBG("unknown sip message type %d\n", tmsg.first_line.type);
2094
+			free_sip_msg(&tmsg);
2095
+			goto afterdb;
2096
+		}
2097
+
2080 2098
 		if(sip_trace_msg_attrs(&tmsg, &sto) < 0) {
2081 2099
 			free_sip_msg(&tmsg);
2082 2100
 			goto afterdb;
... ...
@@ -2179,6 +2197,24 @@ int siptrace_net_data_send(sr_event_param_t *evp)
2179 2197
 			goto afterdb;
2180 2198
 		}
2181 2199
 
2200
+		if(tmsg.first_line.type==SIP_REQUEST) {
2201
+			if(!IS_SIP(&tmsg)) {
2202
+				LM_DBG("non sip request message\n");
2203
+				free_sip_msg(&tmsg);
2204
+				goto afterdb;
2205
+			}
2206
+		} else if(tmsg.first_line.type==SIP_REPLY) {
2207
+			if(!IS_SIP_REPLY(&tmsg)) {
2208
+				LM_DBG("non sip reply message\n");
2209
+				free_sip_msg(&tmsg);
2210
+				goto afterdb;
2211
+			}
2212
+		} else {
2213
+			LM_DBG("unknown sip message type %d\n", tmsg.first_line.type);
2214
+			free_sip_msg(&tmsg);
2215
+			goto afterdb;
2216
+		}
2217
+
2182 2218
 		if(sip_trace_msg_attrs(&tmsg, &sto) < 0) {
2183 2219
 			free_sip_msg(&tmsg);
2184 2220
 			goto afterdb;
Browse code

siptrace: free parsed from in case of errors

Federico Cabiddu authored on 22/04/2020 09:40:58
Showing 1 changed files
... ...
@@ -1383,7 +1383,7 @@ static void trace_onreq_out(struct cell *t, int type, struct tmcb_params *ps)
1383 1383
 	}
1384 1384
 
1385 1385
 	if(sip_trace_msg_attrs(msg, &sto) < 0) {
1386
-		return;
1386
+		return; 
1387 1387
 	}
1388 1388
 
1389 1389
 	if(ps->send_buf.len > 0) {
... ...
@@ -1616,7 +1616,7 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps)
1616 1616
 	}
1617 1617
 
1618 1618
 	if(sip_trace_msg_attrs(msg, &sto) < 0) {
1619
-		return;
1619
+		goto end;
1620 1620
 	}
1621 1621
 
1622 1622
 	if(faked == 0) {
... ...
@@ -1662,7 +1662,7 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps)
1662 1662
 	sto.status.s = int2strbuf(ps->code, statusbuf, INT2STR_MAX_LEN, &sto.status.len);
1663 1663
 	if(sto.status.s == 0) {
1664 1664
 		LM_ERR("failure to get the status string\n");
1665
-		return;
1665
+		goto end;
1666 1666
 	}
1667 1667
 
1668 1668
 	memset(&to_ip, 0, sizeof(struct ip_addr));
... ...
@@ -1700,7 +1700,7 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps)
1700 1700
 end:
1701 1701
 	if (faked && parsed_f) {
1702 1702
 		free_from(msg->from->parsed);
1703
-    msg->from->parsed = NULL;
1703
+		msg->from->parsed = NULL;
1704 1704
 	}
1705 1705
 }
1706 1706
 
Browse code

siptrace: siptrace: fix memory leak in fake replies tracing

Federico Cabiddu authored on 22/04/2020 07:34:20
Showing 1 changed files
... ...
@@ -1569,6 +1569,7 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps)
1569 1569
 	siptrace_data_t sto;
1570 1570
 	siptrace_info_t* info;
1571 1571
 	int faked = 0;
1572
+	int parsed_f = 0;
1572 1573
 	struct sip_msg *msg;
1573 1574
 	struct sip_msg *req;
1574 1575
 	struct ip_addr to_ip;
... ...
@@ -1607,6 +1608,11 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps)
1607 1608
 	if(msg == NULL || msg == FAKED_REPLY) {
1608 1609
 		msg = t->uas.request;
1609 1610
 		faked = 1;
1611
+		/* check if from header has been already parsed.
1612
+		 * If not we have to parse it in pkg memory and free it at the end.
1613
+		 */
1614
+		if (msg->from && msg->from->parsed == NULL)
1615
+			parsed_f = 1;
1610 1616
 	}
1611 1617
 
1612 1618
 	if(sip_trace_msg_attrs(msg, &sto) < 0) {
... ...
@@ -1686,10 +1692,16 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps)
1686 1692
 
1687 1693
 	if (info->uriState == STRACE_RAW_URI) {
1688 1694
 		LM_BUG("uriState must be either UNUSED or PARSED here! must be a bug! Message won't be traced!\n");
1689
-		return;
1695
+		goto end;
1690 1696
 	}
1691 1697
 
1692 1698
 	sip_trace_store(&sto, info->uriState == STRACE_PARSED_URI ? &info->u.dest_info : NULL, NULL);
1699
+
1700
+end:
1701
+	if (faked && parsed_f) {
1702
+		free_from(msg->from->parsed);
1703
+    msg->from->parsed = NULL;
1704
+	}
1693 1705
 }
1694 1706
 
1695 1707
 static void trace_tm_neg_ack_in(struct cell *t, int type, struct tmcb_params *ps)
Browse code

siptrace: helper function to link sip msg attributes

Daniel-Constantin Mierla authored on 10/04/2020 09:02:55
Showing 1 changed files
... ...
@@ -577,12 +577,12 @@ static int sip_trace_insert_db(db_key_t *db_keys, db_val_t *db_vals,
577 577
 		int db_nkeys, char *dtext)
578 578
 {
579 579
 	LM_DBG("storing info - %s\n", dtext);
580
-	if(trace_db_mode = 2 && db_funcs.insert_async != NULL) {
580
+	if(trace_db_mode == 2 && db_funcs.insert_async != NULL) {
581 581
 		if(db_funcs.insert_async(db_con, db_keys, db_vals, db_nkeys) < 0) {
582 582
 			LM_ERR("error storing trace - async - %s\n", dtext);
583 583
 			return -1;
584 584
 		}
585
-	} else if(trace_db_mode != 1 && db_funcs.insert_delayed != NULL) {
585
+	} else if(trace_db_mode == 1 && db_funcs.insert_delayed != NULL) {
586 586
 		if(db_funcs.insert_delayed(db_con, db_keys, db_vals, db_nkeys) < 0) {
587 587
 			LM_ERR("error storing trace - delayed - %s\n", dtext);
588 588
 			return -1;
... ...
@@ -907,7 +907,8 @@ static int sip_trace_helper(sip_msg_t *msg, dest_info_t *dst, str *duri,
907 907