Browse code

pv: $nh(i) returns ip address family version

- 4 for ipv4; 6 for ipv6; and 0 if next hop address is not an ip address

Daniel-Constantin Mierla authored on 13/06/2021 14:43:46
Showing 1 changed files
... ...
@@ -23,6 +23,7 @@
23 23
 #include "../../core/dset.h"
24 24
 #include "../../core/onsend.h"
25 25
 #include "../../core/socket_info.h"
26
+#include "../../core/resolve.h"
26 27
 
27 28
 #include "pv_core.h"
28 29
 #include "pv_branch.h"
... ...
@@ -735,6 +736,14 @@ int pv_get_nh_reply(struct sip_msg *msg, pv_param_t *param,
735 736
 			}
736 737
 			return pv_get_strintval(msg, param, res, &sproto,
737 738
 					(int)msg->via2->proto);
739
+		case 5: /* ip family */
740
+			if(str2ip(&host)!=NULL) {
741
+				return pv_get_uintval(msg, param, res, 4);
742
+			}
743
+			if(str2ip6(&host)!=NULL) {
744
+				return pv_get_uintval(msg, param, res, 6);
745
+			}
746
+			return pv_get_uintval(msg, param, res, 0);
738 747
 	}
739 748
 
740 749
 	LM_ERR("unknown specifier\n");
... ...
@@ -797,6 +806,17 @@ int pv_get_nh(struct sip_msg *msg, pv_param_t *param,
797 806
 			return pv_get_udp(msg, param, res);
798 807
 		return pv_get_strintval(msg, param, res, &parsed_uri.transport_val,
799 808
 				(int)parsed_uri.proto);
809
+	} else if(param->pvn.u.isname.name.n==5) /* ip family */ {
810
+		if(parsed_uri.host.s==NULL || parsed_uri.host.len<=0) {
811
+			return pv_get_uintval(msg, param, res, 0);
812
+		}
813
+		if(str2ip(&parsed_uri.host)!=NULL) {
814
+			return pv_get_uintval(msg, param, res, 4);
815
+		}
816
+		if(str2ip6(&parsed_uri.host)!=NULL) {
817
+			return pv_get_uintval(msg, param, res, 6);
818
+		}
819
+		return pv_get_uintval(msg, param, res, 0);
800 820
 	}
801 821
 	LM_ERR("unknown specifier\n");
802 822
 	return pv_get_null(msg, param, res);
... ...
@@ -820,6 +840,8 @@ int pv_parse_nh_name(pv_spec_p sp, str *in)
820 840
 				sp->pvp.pvn.u.isname.name.n = 3;
821 841
 			else if(strncmp(in->s, "P", 1)==0)
822 842
 				sp->pvp.pvn.u.isname.name.n = 4;
843
+			else if(strncmp(in->s, "i", 1)==0)
844
+				sp->pvp.pvn.u.isname.name.n = 5;
823 845
 			else goto error;
824 846
 		break;
825 847
 		default: