From: Alan T. DeKok Date: Sun, 18 Oct 2015 16:17:01 +0000 (-0400) Subject: Allow IP addrs to compare to prefixes for xlat, too X-Git-Tag: release_3_0_11~243 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1361fa50c6697c501951551f78d133e1d1d7abc7;p=thirdparty%2Ffreeradius-server.git Allow IP addrs to compare to prefixes for xlat, too We don't know what the RHS is... so we cast the LHS to a prefix for v4/v6 addresses --- diff --git a/src/main/parser.c b/src/main/parser.c index c80548c23c0..5fab262fdc2 100644 --- a/src/main/parser.c +++ b/src/main/parser.c @@ -1169,6 +1169,23 @@ static ssize_t condition_tokenize(TALLOC_CTX *ctx, CONF_ITEM *ci, char const *st } } /* attr to literal comparison */ + /* + * The RHS will turn into... something. Allow for prefixes + * there, too. + */ + if ((c->data.map->lhs->type == TMPL_TYPE_ATTR) && + ((c->data.map->rhs->type == TMPL_TYPE_XLAT) || + (c->data.map->rhs->type == TMPL_TYPE_XLAT_STRUCT) || + (c->data.map->rhs->type == TMPL_TYPE_EXEC))) { + if (c->data.map->lhs->tmpl_da->type == PW_TYPE_IPV4_ADDR) { + c->cast = dict_attrbyvalue(PW_CAST_BASE + PW_TYPE_IPV4_PREFIX, 0); + } + + if (c->data.map->lhs->tmpl_da->type == PW_TYPE_IPV6_ADDR) { + c->cast = dict_attrbyvalue(PW_CAST_BASE + PW_TYPE_IPV6_PREFIX, 0); + } + } + /* * If the LHS is a bare word, AND it looks like * an attribute, try to parse it as such. diff --git a/src/tests/unit/condition.txt b/src/tests/unit/condition.txt index 536450b4da9..bbe24d2bc49 100644 --- a/src/tests/unit/condition.txt +++ b/src/tests/unit/condition.txt @@ -671,3 +671,9 @@ data &NAS-IP-Address < &PMIP6-Home-IPv4-HoA condition &NAS-IP-Address < 192.168/16 data &NAS-IP-Address < 192.168.0.0/16 + +condition &NAS-IP-Address < "%{echo: 192.168/16}" +data &NAS-IP-Address < "%{echo: 192.168/16}" + +condition &NAS-IP-Address < `/bin/echo 192.168/16` +data &NAS-IP-Address < `/bin/echo 192.168/16`