Browse code

siptrace: use the send socket also for duplication via sip

- it was ignored, being used only for duplication via hep

Daniel-Constantin Mierla authored on 07/04/2020 15:58:02
Showing 1 changed files
... ...
@@ -277,13 +277,15 @@ int sip_trace_xheaders_free(struct _siptrace_data *sto)
277 277
 /**
278 278
  *
279 279
  */
280
-int trace_send_duplicate(char *buf, int len, struct dest_info *dst2)
280
+int trace_send_duplicate(char *buf, int len, dest_info_t *dst2)
281 281
 {
282
-	struct dest_info dst;
283
-	struct proxy_l *p = NULL;
282
+	dest_info_t dst;
283
+	dest_info_t pdst;
284
+	proxy_l_t *p = NULL;
284 285
 
285
-	if(buf == NULL || len <= 0)
286
+	if(buf == NULL || len <= 0) {
286 287
 		return -1;
288
+	}
287 289
 
288 290
 	/* either modparam dup_uri or siptrace param dst2 */
289 291
 	if((trace_dup_uri_str.s == 0 || trace_dup_uri == NULL) && (dst2 == NULL)) {
... ...
@@ -304,17 +306,39 @@ int trace_send_duplicate(char *buf, int len, struct dest_info *dst2)
304 306
 		}
305 307
 		hostent2su(
306 308
 				&dst.to, &p->host, p->addr_idx, (p->port) ? p->port : SIP_PORT);
309
+		pdst = &dst;
310
+	} else {
311
+		pdst = dst2;
312
+	}
313
+
314
+	if(pdst->send_sock == NULL) {
315
+		if(trace_send_sock_str.s) {
316
+			LM_DBG("send sock activated, grep for the sock_info\n");
317
+			pdst->send_sock = grep_sock_info(&trace_send_sock_uri->host,
318
+					trace_send_sock_uri->port_no,
319
+					trace_send_sock_uri->proto);
320
+			if(!pdst->send_sock) {
321
+				LM_WARN("cannot grep socket info\n");
322
+			} else {
323
+				LM_DBG("found socket while grep: [%.*s] [%.*s]\n",
324
+						pdst->send_sock->name.len,
325
+						pdst->send_sock->name.s, pdst->send_sock->address_str.len,
326
+						pdst->send_sock->address_str.s);
327
+			}
328
+		}
329
+	}
307 330
 
308
-		dst.send_sock = get_send_socket(0, &dst.to, dst.proto);
309
-		if(dst.send_sock == 0) {
310
-			LM_ERR("can't forward to af %d, proto %d no corresponding"
331
+	if(pdst->send_sock == NULL) {
332
+		pdst->send_sock = get_send_socket(0, &pdst->to, pdst->proto);
333
+		if(pdst->send_sock == 0) {
334
+			LM_ERR("cannot forward to af %d, proto %d - no corresponding"
311 335
 				   " listening socket\n",
312
-					dst.to.s.sa_family, dst.proto);
336
+					pdst->to.s.sa_family, pdst->proto);
313 337
 			goto error;
314 338
 		}
315 339
 	}
316 340
 
317
-	if(msg_send((dst2) ? dst2 : &dst, buf, len) < 0) {
341
+	if(msg_send(pdst, buf, len) < 0) {
318 342
 		LM_ERR("cannot send duplicate message\n");
319 343
 		goto error;
320 344
 	}