]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Automatically cast IP to IP_PREFIX comparisons
authorAlan T. DeKok <aland@freeradius.org>
Sat, 17 Oct 2015 20:37:31 +0000 (16:37 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 17 Oct 2015 20:37:31 +0000 (16:37 -0400)
src/main/parser.c
src/tests/unit/condition.txt

index a0d3c688cc7187c95daf7573a6ddd383022e626a..abe9db638f41ece9309ed736bab6e91a28eb928e 100644 (file)
@@ -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:
index f7d055c21fb5ba3ad9f2d15f7b378222bdb4016f..122f048fc2630245c2b8eaf7506bdd761d010d62 100644 (file)
@@ -662,3 +662,12 @@ data <ipv4prefix>&NAS-IP-Address == 192.168.0.0/24
 
 condition <ipv4prefix>192.168.0.0/24 > &NAS-IP-Address
 data <ipv4prefix>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 <ipv4prefix>&NAS-IP-Address < &PMIP6-Home-IPv4-HoA
+
+condition &NAS-IP-Address < 192.168/16
+data <ipv4prefix>&Framed-IP-Address <= 192.168.0.0/16