]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Allow IP addrs to compare to prefixes for xlat, too
authorAlan T. DeKok <aland@freeradius.org>
Sun, 18 Oct 2015 16:17:01 +0000 (12:17 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 18 Oct 2015 16:17:36 +0000 (12:17 -0400)
We don't know what the RHS is... so we cast the LHS to a prefix
for v4/v6 addresses

src/main/parser.c
src/tests/unit/condition.txt

index c80548c23c0416bee37137ba9179b5f9ff19c733..5fab262fdc2c77b050a5e62fd5dc3b7fb3bc4c73 100644 (file)
@@ -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.
index 536450b4da9919de3adce7e1621c8f4e2b6b40ee..bbe24d2bc490e7351a5b382c7800b8623ca63c7f 100644 (file)
@@ -671,3 +671,9 @@ data <ipv4prefix>&NAS-IP-Address < &PMIP6-Home-IPv4-HoA
 
 condition &NAS-IP-Address < 192.168/16
 data <ipv4prefix>&NAS-IP-Address < 192.168.0.0/16
+
+condition &NAS-IP-Address < "%{echo: 192.168/16}"
+data <ipv4prefix>&NAS-IP-Address < "%{echo: 192.168/16}"
+
+condition &NAS-IP-Address < `/bin/echo 192.168/16`
+data <ipv4prefix>&NAS-IP-Address < `/bin/echo 192.168/16`