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
 	}