Browse code

Allow to compare the snd_ip and to_ip with the AVP value. (Was allowed for ports, not ips.) For performance purist: I did not measure which code is faster; whether finding the AVP in the list or using DNS name resolution. Using AVP (track and) domain prefix makes the search faster, when AVP is in fallback domains, e.g. for global AVP.

Following code now allowed:
onsend_route{
if (isflagset(GATEWAY)) {
if (to_ip!=$g.gw_ip) {
log(1,"Bad gateway IP");
drop;
}
}
}

Michal Matyska authored on 10/09/2007 19:29:44
Showing 2 changed files
... ...
@@ -1358,6 +1358,10 @@ exp_elem:
1358 1358
 		onsend_check("snd_ip");
1359 1359
 		$$=mk_elem($2, SNDIP_O, 0, STRING_ST, $3);
1360 1360
 	}
1361
+	| SNDIP equalop attr_id_val	{
1362
+		onsend_check("snd_ip");
1363
+	    $$=mk_elem($2, SNDIP_O, 0, AVP_ST, (void*)$3 ); 
1364
+	}
1361 1365
 	| SNDIP equalop MYSELF  {
1362 1366
 		onsend_check("snd_ip");
1363 1367
 		$$=mk_elem($2, SNDIP_O, 0, MYSELF_ST, 0);
... ...
@@ -1385,6 +1389,10 @@ exp_elem:
1385 1385
 		onsend_check("to_ip");
1386 1386
 		$$=mk_elem($2, TOIP_O, 0, STRING_ST, $3);
1387 1387
 	}
1388
+	| TOIP equalop attr_id_val	{
1389
+		onsend_check("to_ip");
1390
+	    $$=mk_elem($2, TOIP_O, 0, AVP_ST, (void*)$3 ); 
1391
+	}
1388 1392
 	| TOIP equalop MYSELF  {
1389 1393
 		onsend_check("to_ip");
1390 1394
 		$$=mk_elem($2, TOIP_O, 0, MYSELF_ST, 0);
... ...
@@ -703,24 +703,35 @@ error:
703 703
 inline static int comp_string(int op, char* left, int rtype, union exp_op* r)
704 704
 {
705 705
 	int ret;
706
+	int_str val;
707
+	avp_t* avp;
708
+	char* right;
706 709
 
707 710
 	ret=-1;
711
+	if (rtype == AVP_ST) {
712
+		avp = search_avp_by_index(r->attr->type, r->attr->name, &val, r->attr->index);
713
+		if (avp && (avp->flags & AVP_VAL_STR)) right = val.s.s;
714
+		else return 0; /* Always fail */
715
+	} else if (rtype == STRING_ST) {
716
+		right = r->str.s;
717
+	}
718
+
708 719
 	switch(op){
709 720
 		case EQUAL_OP:
710
-			if (rtype!=STRING_ST){
721
+			if (rtype!=STRING_ST && rtype!=AVP_ST){
711 722
 				LOG(L_CRIT, "BUG: comp_string: bad type %d, "
712
-						"string expected\n", rtype);
723
+						"string or attr expected\n", rtype);
713 724
 				goto error;
714 725
 			}
715
-			ret=(strcasecmp(left, r->str.s)==0);
726
+			ret=(strcasecmp(left, right)==0);
716 727
 			break;
717 728
 		case DIFF_OP:
718
-			if (rtype!=STRING_ST){
729
+			if (rtype!=STRING_ST && rtype!=AVP_ST){
719 730
 				LOG(L_CRIT, "BUG: comp_string: bad type %d, "
720
-						"string expected\n", rtype);
731
+						"string or attr expected\n", rtype);
721 732
 				goto error;
722 733
 			}
723
-			ret=(strcasecmp(left, r->str.s)!=0);
734
+			ret=(strcasecmp(left, right)!=0);
724 735
 			break;
725 736
 		case MATCH_OP:
726 737
 			if (rtype!=RE_ST){
... ...
@@ -874,6 +885,7 @@ inline static int comp_ip(int op, struct ip_addr* ip, int rtype, union exp_op* r
874 874
 					goto error_op;
875 875
 			}
876 876
 			break;
877
+		case AVP_ST:
877 878
 		case STRING_ST:
878 879
 		case RE_ST:
879 880
 			switch(op){