Browse code

Merge 2fb611dc0de13bb02ca0e0a9418feca8928559e8 into 13e876e45ad34a9d567d41293450307816bdf107

sergey-safarov authored on 14/06/2021 13:10:38 • GitHub committed on 14/06/2021 13:10:38
Showing 1 changed files
... ...
@@ -2505,16 +2505,76 @@ 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 1: /* src_host */
2518
+		case 2: /* src_port */
2519
+		case 3: /* src_proto */
2520
+			if (parse_phostport(siptrace_event_data->fromip.s, &host.s, &host.len, &port, &proto)!=0) {
2521
+				LM_ERR("invalid src_addr: %.*s\n", siptrace_event_data->fromip.len, siptrace_event_data->fromip.s);
2522
+				return pv_get_null(msg, param, res);
2523
+			}
2524
+		break;
2525
+		case 5: /* dst_host */
2526
+		case 6: /* dst_port */
2527
+		case 7: /* dst_proto */
2528
+			if (parse_phostport(siptrace_event_data->toip.s, &host.s, &host.len, &port, &proto)!=0) {
2529
+				LM_ERR("invalid dst_addr: %.*s\n", siptrace_event_data->toip.len, siptrace_event_data->toip.s);
2530
+				return pv_get_null(msg, param, res);
2531
+			}
2532
+		break;
2533
+	}
2534
+
2535
+	switch(param->pvn.u.isname.name.n) {
2536
+		case 3: /* src_proto */
2537
+		case 7: /* dst_proto */
2538
+			if(get_valid_proto_string(proto, 0, 0, &sproto)<0)
2539
+			{
2540
+				sproto.s = "none";
2541
+				sproto.len = 4;
2542
+			}
2543
+		break;
2544
+	}
2545
+
2546
+	switch(param->pvn.u.isname.name.n) {
2547
+		case 1: /* src_host */
2548
+		case 5: /* dst_host */
2549
+
2550
+			/* now IPv6 address has brakets that not wanted in IP address operations */
2551
+			if(host.s[0] == '[' && host.s[host.len-1] == ']') {
2552
+				host.s++;
2553
+				host.len = host.len - 2;
2554
+			}
2555
+		break;
2556
+	}
2557
+
2558
+	switch(param->pvn.u.isname.name.n) {
2559
+		case 0: /* src_addr */
2560
+			return pv_get_strval(msg, param, res, &siptrace_event_data->fromip);
2561
+		case 1: /* src_host */
2562
+			return pv_get_strval(msg, param, res, &host);
2563
+		case 2: /* src_port */
2564
+			return pv_get_sintval(msg, param, res, port);
2565
+		case 3: /* src_proto */
2566
+			return pv_get_strintval(msg, param, res, &sproto, proto);
2567
+		case 4: /* dst_addr */
2514 2568
 			return pv_get_strval(msg, param, res, &siptrace_event_data->toip);
2569
+		case 5: /* dst_host */
2570
+			return pv_get_strval(msg, param, res, &host);
2571
+		case 6: /* dst_port */
2572
+			return pv_get_sintval(msg, param, res, port);
2573
+		case 7: /* dst_proto */
2574
+			return pv_get_strintval(msg, param, res, &sproto, proto);
2515 2575
 		default:
2516
-			/* 0 - src_uri */
2517
-			return pv_get_strval(msg, param, res, &siptrace_event_data->fromip);
2576
+			LM_ERR("unexpected config param\n");
2577
+			return pv_get_null(msg, param, res);
2518 2578
 	}
2519 2579
 }
2520 2580
 
... ...
@@ -2531,8 +2591,23 @@ int pv_parse_siptrace_name(pv_spec_t *sp, str *in)
2531 2591
 		case 8:
2532 2592
 			if(strncmp(in->s, "src_addr", 8)==0)
2533 2593
 				sp->pvp.pvn.u.isname.name.n = 0;
2534
-			else if(strncmp(in->s, "dst_addr", 8)==0)
2594
+			else if(strncmp(in->s, "src_host", 8)==0)
2535 2595
 				sp->pvp.pvn.u.isname.name.n = 1;
2596
+			else if(strncmp(in->s, "src_port", 8)==0)
2597
+				sp->pvp.pvn.u.isname.name.n = 2;
2598
+			else if(strncmp(in->s, "dst_addr", 8)==0)
2599
+				sp->pvp.pvn.u.isname.name.n = 4;
2600
+			else if(strncmp(in->s, "dst_host", 8)==0)
2601
+				sp->pvp.pvn.u.isname.name.n = 5;
2602
+			else if(strncmp(in->s, "dst_port", 8)==0)
2603
+				sp->pvp.pvn.u.isname.name.n = 6;
2604
+			else goto error;
2605
+		break;
2606
+		case 9:
2607
+			if(strncmp(in->s, "src_proto", 8)==0)
2608
+				sp->pvp.pvn.u.isname.name.n = 3;
2609
+			else if(strncmp(in->s, "dst_proto", 8)==0)
2610
+				sp->pvp.pvn.u.isname.name.n = 7;
2536 2611
 			else goto error;
2537 2612
 		break;
2538 2613
 		default: