Browse code

Merge f53b5e1f08680bac019980897c6ea79ae540cd2c into e87fd9ce381c73d3733c38812c86e467cf966089

sergey-safarov authored on 17/06/2021 23:58:17 • GitHub committed on 17/06/2021 23:58:17
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: