]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
more comments on fields
authorAlan T. DeKok <aland@freeradius.org>
Wed, 24 Mar 2021 17:29:00 +0000 (13:29 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 31 Mar 2021 15:10:24 +0000 (16:10 +0100)
in preparation for separating out the meanings into different
fields.

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

index 7c03da27a07af13f718cc071bdb1a3a63a675f1b..4b4f0dd42c0e7fdc77728c2a5a15adf9c8bbefc2 100644 (file)
@@ -89,13 +89,21 @@ typedef struct {
 
        unsigned int            extra : 1;                      //!< really "subtype is used by dict, not by protocol"
 
-       uint8_t                 subtype;                        //!< for FR_TYPE_STRING encoding
+       uint8_t                 subtype;                        //!< protocol-specific values, OR key fields
 
        uint8_t                 length;                         //!< length of the attribute
+
+       /*
+        *      TLVs: 1, 2, or 4.
+        *      date / time types: fr_time_res_t, which has 4 possible values.
+        *      bit fields: offset in the byte where this bit field ends.
+        */
        uint8_t                 type_size;                      //!< For TLV2 and root attributes.
 } fr_dict_attr_flags_t;
 
 #define flag_time_res type_size
+#define flag_byte_offset type_size
+#define flag_struct_offset type_size
 
 /** subtype values for the dictionary when extra=1
  *
index d938a8a6eb1c2229e02147951191d22b4283b6f3..dda9b950933c9e1320fe03314542dce5c879e432 100644 (file)
@@ -247,7 +247,7 @@ static int dict_process_type_field(dict_tokenize_ctx_t *ctx, char const *name, f
                        /*
                         *      We track where on a byte boundary this bit field ends.
                         */
-                       flags->type_size = length;
+                       flags->flag_byte_offset = length;
 
                } else {
                        fr_strerror_const("Only 'octets' types can have a 'length' parameter");
@@ -948,11 +948,11 @@ static int dict_read_process_member(dict_tokenize_ctx_t *ctx, char **argv, int a
                         *      located.
                         */
                        if (flags.extra && (flags.subtype == FLAG_BIT_FIELD)) {
-                               flags.type_size += previous->flags.type_size;
-                               flags.type_size &= 0x07;
+                               flags.flag_byte_offset += previous->flags.flag_byte_offset;
+                               flags.flag_byte_offset &= 0x07;
 
                        } else {
-                               if (previous->flags.type_size != 0) {
+                               if (previous->flags.flag_byte_offset != 0) {
                                        fr_strerror_printf("Previous bitfield %s did not end on a byte boundary",
                                                           previous->name);
                                        return -1;
index bc698394e55a151bb16358ec93356794245b5b75..171f322b2e23099f50d647a0854dac982c351953 100644 (file)
@@ -358,8 +358,8 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
                }
 
                /*
-                *      Length isn't set, set it and type_size from
-                *      the parent.
+                *      Find an appropriate parent to copy the
+                *      TLV-specific fields from.
                 */
                for (v = parent; v != NULL; v = v->parent) {
                        if ((v->type == FR_TYPE_TLV) || (v->type == FR_TYPE_VENDOR)) {
@@ -626,7 +626,7 @@ bool dict_attr_fields_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
                 *      that the encoder doesn't have to do complex
                 *      checks.
                 */
-               if (*attr >= (1 << (8 * parent->flags.type_size))) flags->internal = true;
+               if ((uint64_t) *attr >= (((uint64_t)1) << (8 * parent->flags.type_size))) flags->internal = true;
        }
 
        /*
@@ -679,10 +679,9 @@ bool dict_attr_fields_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
        if ((*attr > UINT8_MAX) && !flags->internal) {
                for (v = parent; v != NULL; v = v->parent) {
                        if ((v->type == FR_TYPE_TLV) || (v->type == FR_TYPE_VENDOR)) {
-                               if ((v->flags.type_size < 4) &&
-                                   (*attr >= (1 << (8 * v->flags.type_size)))) {
-                                       fr_strerror_printf("Attributes must have value between 1..%u",
-                                                          (1 << (8 * v->flags.type_size)) - 1);
+                               if ((uint64_t) *attr >= (((uint64_t) 1) << (8 * v->flags.type_size))) {
+                                       fr_strerror_printf("Attributes must have value between 1..%llu",
+                                                          (((uint64_t) 1) << (8 * v->flags.type_size)) - 1);
                                        return false;
                                }
                                break;