]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow combo-ip/prefix to be input types
authorAlan T. DeKok <aland@freeradius.org>
Fri, 8 Dec 2023 16:07:10 +0000 (11:07 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 8 Dec 2023 19:01:33 +0000 (14:01 -0500)
src/lib/util/calc.c
src/tests/unit/calc.txt

index b22830d76b23b93882157da5f97d08f5e874a818..d5ad61012c779e3480418b074b3dea4ade030994 100644 (file)
@@ -1115,16 +1115,32 @@ static int cast_ipv4_addr(fr_value_box_t *out, fr_value_box_t const *in)
                                   fr_type_to_str(in->type));
                return -1;
 
+       case FR_TYPE_COMBO_IP_ADDR:
+               if (in->vb_ip.af == AF_INET6) goto cast_ipv6_addr;
+
+               fr_value_box_init(out, FR_TYPE_IPV4_ADDR, NULL, in->tainted);
+               out->vb_ip = in->vb_ip;
+               break;
+
+       case FR_TYPE_COMBO_IP_PREFIX:
+               if (in->vb_ip.af == AF_INET6) goto cast_ipv6_prefix;
+
+               fr_value_box_init(out, FR_TYPE_IPV4_PREFIX, NULL, in->tainted);
+               out->vb_ip = in->vb_ip;
+               break;
+
        case FR_TYPE_IPV4_PREFIX:
        case FR_TYPE_IPV4_ADDR:
                fr_value_box_copy(NULL, out, in);
                break;
 
        case FR_TYPE_IPV6_ADDR:
+       cast_ipv6_addr:
                if (fr_value_box_cast(NULL, out, FR_TYPE_IPV4_ADDR, NULL, in) < 0) return -1;
                break;
 
        case FR_TYPE_IPV6_PREFIX:
+       cast_ipv6_prefix:
                if (fr_value_box_cast(NULL, out, FR_TYPE_IPV4_PREFIX, NULL, in) < 0) return -1;
                break;
 
@@ -1295,16 +1311,33 @@ static int cast_ipv6_addr(fr_value_box_t *out, fr_value_box_t const *in)
                                   fr_type_to_str(in->type));
                return -1;
 
+       case FR_TYPE_COMBO_IP_ADDR:
+               if (in->vb_ip.af == AF_INET) goto cast_ipv4_addr;
+
+               fr_value_box_init(out, FR_TYPE_IPV4_ADDR, NULL, in->tainted);
+               out->vb_ip = in->vb_ip;
+               break;
+
+       case FR_TYPE_COMBO_IP_PREFIX:
+               if (in->vb_ip.af == AF_INET) goto cast_ipv4_prefix;
+
+               fr_value_box_init(out, FR_TYPE_IPV4_PREFIX, NULL, in->tainted);
+               out->vb_ip = in->vb_ip;
+               break;
+
+
        case FR_TYPE_IPV6_PREFIX:
        case FR_TYPE_IPV6_ADDR:
                fr_value_box_copy(NULL, out, in);
                break;
 
        case FR_TYPE_IPV4_ADDR:
+       cast_ipv4_addr:
                if (fr_value_box_cast(NULL, out, FR_TYPE_IPV6_ADDR, NULL, in) < 0) return -1;
                break;
 
        case FR_TYPE_IPV4_PREFIX:
+       cast_ipv4_prefix:
                if (fr_value_box_cast(NULL, out, FR_TYPE_IPV6_PREFIX, NULL, in) < 0) return -1;
                break;
 
index 1418d418b4e164e973f0c82223de0a58a9bcfc20..b6b4f580c2cf52a076502b59bd05a55c1d84a12c 100644 (file)
@@ -170,6 +170,9 @@ match no
 calc combo-prefix 127/8 > ipv6addr 2001:DB8::1 -> bool
 match Cannot compare IPv4 with IPv6 address
 
+calc combo-prefix 127/8 + uint8 1 -> ipaddr
+match 127.0.0.1
+
 ######################################################################
 #
 #  Float
@@ -200,4 +203,4 @@ calc string "2" += string "test"
 match 2test
 
 count
-match 90
+match 92