]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
clean up final uses of dict_attr_size
authorAlan T. DeKok <aland@freeradius.org>
Fri, 15 Jan 2021 19:26:37 +0000 (14:26 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 15 Jan 2021 19:26:37 +0000 (14:26 -0500)
the struct validation code now checks if (a) the da contains
a known fixed size, or (b) it's a FR_TYPE_VALUE.  That covers
the same situations as before.

It still doesn't allow for variable-sized fields like dns labels,
but that will have to be another step.

now that dict_attr_size isn't used, it's removed.

src/lib/util/dict.h
src/lib/util/dict_util.c
src/lib/util/dict_validate.c

index f2ee54d5285c8e91f3608e9a34676f933da8e0cd..e65f3573c44ce4383d3032f4f4804beb6179d80f 100644 (file)
@@ -109,15 +109,6 @@ enum {
 #define da_is_bit_field(_da) ((_da)->flags.extra && ((_da)->flags.subtype == FLAG_BIT_FIELD))
 #define da_is_length_field(_da) ((_da)->flags.extra && ((_da)->flags.subtype == FLAG_LENGTH_UINT16))
 
-extern const size_t dict_attr_sizes[FR_TYPE_MAX + 1][2];
-
-#define min_size(_type) (dict_attr_sizes[_type][0])
-#define max_size(_type) (dict_attr_sizes[_type][1])
-
-static inline bool is_fixed_size(fr_type_t type)
-{
-       return min_size(type) == max_size(type);
-}
 
 /** Extension identifier
  *
index 6252ebff38cc04b22702baac55165da1208840f2..974be909b63f96d717adcb2d1517c0ea871a7847 100644 (file)
@@ -56,42 +56,6 @@ fr_table_num_ordered_t const date_precision_table[] = {
 };
 size_t date_precision_table_len = NUM_ELEMENTS(date_precision_table);
 
-
-/** Map data types to min / max data sizes
- */
-size_t const dict_attr_sizes[FR_TYPE_MAX + 1][2] = {
-       [FR_TYPE_INVALID]       = {~0, 0},      //!< Ensure array starts at 0 (umm?)
-
-       [FR_TYPE_STRING]        = {0, ~0},
-       [FR_TYPE_OCTETS]        = {0, ~0},
-
-       [FR_TYPE_IPV4_ADDR]     = {4, 4},
-       [FR_TYPE_IPV4_PREFIX]   = {6, 6},
-       [FR_TYPE_IPV6_ADDR]     = {16, 16},
-       [FR_TYPE_IPV6_PREFIX]   = {2, 18},
-       [FR_TYPE_COMBO_IP_ADDR] = {4, 16},
-       [FR_TYPE_IFID]          = {8, 8},
-       [FR_TYPE_ETHERNET]      = {6, 6},
-
-       [FR_TYPE_BOOL]          = {1, 1},
-       [FR_TYPE_UINT8]         = {1, 1},
-       [FR_TYPE_UINT16]        = {2, 2},
-       [FR_TYPE_UINT32]        = {4, 4},
-       [FR_TYPE_UINT64]        = {8, 8},
-       [FR_TYPE_SIZE]          = {sizeof(size_t), sizeof(size_t)},
-       [FR_TYPE_INT32]         = {4, 4},
-
-       [FR_TYPE_DATE]          = {4, 4},
-       [FR_TYPE_TIME_DELTA]    = {4, 4},
-
-       [FR_TYPE_TLV]           = {2, ~0},
-       [FR_TYPE_STRUCT]        = {1, ~0},
-
-       [FR_TYPE_VSA]           = {4, ~0},
-
-       [FR_TYPE_MAX]           = {~0, 0}       //!< Ensure array covers all types.
-};
-
 /** Characters allowed in dictionary names
  *
  */
index e635dac54065df6e21b63d6e554b4b860298cbf2..e89b33d714e4c51f9ee7232bc7e58b869b1e502e 100644 (file)
@@ -506,8 +506,11 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
                         *      @todo - allow dns_label encoding as
                         *      the first member.
                         */
-                       if ((max_size(sibling->type) == ~(size_t) 0) &&
-                           (sibling->flags.length == 0)) {
+                       if (sibling->flags.length == 0) switch (sibling->type) {
+                       case FR_TYPE_VALUE:
+                               break;
+
+                       default:
                                fr_strerror_const("Only the last child of a 'struct' attribute can have variable length");
                                return false;
                        }