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;
}
}
}
P.S. Regarding latest discussion on bugs/features.... it can be seen as "bug" because port was allowed to be compared to AVP, but ip not. I'm sorry for any inconvinience. ;-)
... | ... |
@@ -1283,6 +1283,10 @@ exp_elem: |
1283 | 1283 |
onsend_check("snd_ip"); |
1284 | 1284 |
$$=mk_elem($2, SNDIP_O, 0, STRING_ST, $3); |
1285 | 1285 |
} |
1286 |
+ | SNDIP equalop attr_id_val { |
|
1287 |
+ onsend_check("snd_ip"); |
|
1288 |
+ $$=mk_elem($2, SNDIP_O, 0, AVP_ST, (void*)$3 ); |
|
1289 |
+ } |
|
1286 | 1290 |
| SNDIP equalop MYSELF { |
1287 | 1291 |
onsend_check("snd_ip"); |
1288 | 1292 |
$$=mk_elem($2, SNDIP_O, 0, MYSELF_ST, 0); |
... | ... |
@@ -1310,6 +1314,10 @@ exp_elem: |
1310 | 1314 |
onsend_check("to_ip"); |
1311 | 1315 |
$$=mk_elem($2, TOIP_O, 0, STRING_ST, $3); |
1312 | 1316 |
} |
1317 |
+ | TOIP equalop attr_id_val { |
|
1318 |
+ onsend_check("to_ip"); |
|
1319 |
+ $$=mk_elem($2, TOIP_O, 0, AVP_ST, (void*)$3 ); |
|
1320 |
+ } |
|
1313 | 1321 |
| TOIP equalop MYSELF { |
1314 | 1322 |
onsend_check("to_ip"); |
1315 | 1323 |
$$=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 | 885 |
goto error_op; |
875 | 886 |
} |
876 | 887 |
break; |
888 |
+ case AVP_ST: |
|
877 | 889 |
case STRING_ST: |
878 | 890 |
case RE_ST: |
879 | 891 |
switch(op){ |