From: Alan T. DeKok Date: Sat, 17 Oct 2015 20:37:31 +0000 (-0400) Subject: Automatically cast IP to IP_PREFIX comparisons X-Git-Tag: release_3_0_11~247 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bf5e514ce32584639af29876b8d46b3da95d0c42;p=thirdparty%2Ffreeradius-server.git Automatically cast IP to IP_PREFIX comparisons --- diff --git a/src/main/parser.c b/src/main/parser.c index a0d3c688cc7..abe9db638f4 100644 --- a/src/main/parser.c +++ b/src/main/parser.c @@ -436,6 +436,22 @@ static bool condition_check_types(fr_cond_t *c, PW_TYPE lhs_type) return true; } + /* + * Same checks as above, but with the types swapped, and + * with explicit cast for the interpretor. + */ + if ((lhs_type == PW_TYPE_IPV4_ADDR) && + (c->data.map->rhs->tmpl_da->type == PW_TYPE_IPV4_PREFIX)) { + c->cast = c->data.map->rhs->tmpl_da; + return true; + } + + if ((lhs_type == PW_TYPE_IPV6_ADDR) && + (c->data.map->rhs->tmpl_da->type == PW_TYPE_IPV6_PREFIX)) { + c->cast = c->data.map->rhs->tmpl_da; + return true; + } + return false; } @@ -1094,10 +1110,12 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *st switch (c->data.map->lhs->tmpl_da->type) { case PW_TYPE_IPV4_ADDR: type = PW_TYPE_IPV4_PREFIX; + c->cast = dict_attrbyvalue(PW_CAST_BASE + type, 0); break; case PW_TYPE_IPV6_ADDR: type = PW_TYPE_IPV6_PREFIX; + c->cast = dict_attrbyvalue(PW_CAST_BASE + type, 0); break; default: diff --git a/src/tests/unit/condition.txt b/src/tests/unit/condition.txt index f7d055c21fb..122f048fc26 100644 --- a/src/tests/unit/condition.txt +++ b/src/tests/unit/condition.txt @@ -662,3 +662,12 @@ data &NAS-IP-Address == 192.168.0.0/24 condition 192.168.0.0/24 > &NAS-IP-Address data 192.168.0.0/24 > &NAS-IP-Address + +# +# We add casts to the LHS if necessary +# +condition &NAS-IP-Address < &PMIP6-Home-IPv4-HoA +data &NAS-IP-Address < &PMIP6-Home-IPv4-HoA + +condition &NAS-IP-Address < 192.168/16 +data &Framed-IP-Address <= 192.168.0.0/16