]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow "prefix=bits"
authorAlan T. DeKok <aland@freeradius.org>
Thu, 17 Mar 2022 22:55:36 +0000 (18:55 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 18 Mar 2022 13:16:28 +0000 (09:16 -0400)
for prefixes which are encoded as 8 bits of prefix, followed by
0..3 bytes of actual content

src/protocols/dhcpv4/base.c
src/protocols/dhcpv4/dhcpv4.h

index ae5e52c3dd0b998ed70581497b69af771b5e85c8..c899a62214e16c44f95cf38b5064a4323137e8ba 100644 (file)
@@ -747,6 +747,7 @@ static fr_table_num_ordered_t const subtype_table[] = {
        { L("dns_label"),                       FLAG_ENCODE_DNS_LABEL },
        { L("encode=dns_label"),                FLAG_ENCODE_DNS_LABEL },
        { L("prefix=split"),                    FLAG_ENCODE_SPLIT_PREFIX },
+       { L("prefix=bits"),                     FLAG_ENCODE_BITS_PREFIX },
        { L("encode=exists"),                   FLAG_ENCODE_BOOL_EXISTS },
 };
 
@@ -764,7 +765,8 @@ static bool attr_valid(UNUSED fr_dict_t *dict, UNUSED fr_dict_attr_t const *pare
                        fr_strerror_const("string/octets arrays require the 'length=uint8' flag");
                        return false;
                }
-       } else if (flags->array && !flags->length) {
+
+       } else if (flags->array && !flags->length && !flags->is_known_width) {
                fr_strerror_const("Variable length attributes cannot be marked as 'array'");
                return false;
        }
@@ -780,8 +782,9 @@ static bool attr_valid(UNUSED fr_dict_t *dict, UNUSED fr_dict_attr_t const *pare
                return false;
        }
 
-       if ((type != FR_TYPE_IPV4_PREFIX) && (flags->subtype == FLAG_ENCODE_SPLIT_PREFIX)) {
-               fr_strerror_const("The 'split' flag can only be used with attributes of type 'ipv4prefix'");
+       if ((type != FR_TYPE_IPV4_PREFIX) &&
+           ((flags->subtype == FLAG_ENCODE_SPLIT_PREFIX) || (flags->subtype == FLAG_ENCODE_BITS_PREFIX))) {
+               fr_strerror_const("The 'prefix=...' flag can only be used with attributes of type 'ipv4prefix'");
                return false;
        }
 
index 31262f466f3cc00a75a5d0ce2552034ea56deb72..807953398db119691f1fae41daa0e5cf92366096 100644 (file)
@@ -72,11 +72,13 @@ enum {
        FLAG_ENCODE_NONE = 0,                           //!< no particular encoding for DHCPv6 strings
        FLAG_ENCODE_DNS_LABEL,                          //!< encode as DNS label
        FLAG_ENCODE_SPLIT_PREFIX,                       //!< encode IPv4 prefixes as Policy-Filter, split into IP/mask
+       FLAG_ENCODE_BITS_PREFIX,                        //!< encode IPv4 prefixes as prefix bits, followed by IP.
        FLAG_ENCODE_BOOL_EXISTS,                        //!< bool as existence checks
 };
 
 #define da_is_dns_label(_da) (!(_da)->flags.extra && ((_da)->flags.subtype == FLAG_ENCODE_DNS_LABEL))
 #define da_is_split_prefix(_da) (!(_da)->flags.extra && ((_da)->flags.subtype == FLAG_ENCODE_SPLIT_PREFIX))
+#define da_is_bits_prefix(_da) (!(_da)->flags.extra && ((_da)->flags.subtype == FLAG_ENCODE_BITS_PREFIX))
 #define da_is_bool_exists(_da) (!(_da)->flags.extra && ((_da)->flags.subtype == FLAG_ENCODE_BOOL_EXISTS))
 
 typedef struct {