]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add "counter" flag for unsigned integers.
authorAlan T. DeKok <aland@freeradius.org>
Tue, 3 May 2022 12:20:28 +0000 (14:20 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 3 May 2022 12:29:15 +0000 (14:29 +0200)
to enable more SNMP, and internal stats, along with automatic
aggregation of stats.

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

index 8e2020c475faba21df9858d1139bf5b6c3dac7e9..aab9b28649bf0fd7ae3f8457cd34edac93afe7ed 100644 (file)
@@ -93,6 +93,8 @@ typedef struct {
 
        unsigned int            is_unsigned : 1;                //!< hackity hack for dates and time deltas
 
+       unsigned int            is_counter : 1;                 //!< integer attribute is actually an impulse / counter
+
        /*
         *      @todo - if we want to clean these fields up, make
         *      "subtype" and "type_size" both 4-bit bitfields.  That
index 38076d64a17dd383f2b36094913064634023f124..ddaa8ece810596c9901c3af98a99a21d6ae87570 100644 (file)
@@ -370,6 +370,9 @@ static int dict_process_flag_field(dict_tokenize_ctx_t *ctx, char *name, fr_type
                } else if (strcmp(key, "array") == 0) {
                        flags->array = 1;
 
+               } else if (strcmp(key, "counter") == 0) {
+                       flags->is_counter = 1;
+
                } else if (strcmp(key, "virtual") == 0) {
                        flags->virtual = 1;
 
index b2121a6abda09fd673a8079d20985f58e67f977e..e4fa2964573853e1f864fb57f6897bfb63b8dead 100644 (file)
@@ -45,6 +45,7 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
        uint32_t shift_is_root, shift_internal;
        uint32_t shift_array, shift_has_value;
        uint32_t shift_virtual, shift_subtype, shift_extra;
+       uint32_t shift_is_counter;
        fr_dict_attr_t const *v;
 
        /*
@@ -61,6 +62,7 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
        SET_FLAG(has_value);
        SET_FLAG(virtual);
        SET_FLAG(extra);
+       SET_FLAG(is_counter);
        SET_FLAG(subtype);
 
 #define FORBID_OTHER_FLAGS(_flag) do { if (all_flags & ~shift_ ## _flag) { fr_strerror_printf("The '" STRINGIFY(_flag) "' flag cannot be used with any other flag"); return false; } } while (0)
@@ -486,6 +488,18 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
                }
        }
 
+       /*
+        *      Only numerical types can be counter
+        */
+       if (flags->is_counter) {
+               if (fr_type_is_numeric(type) && !fr_type_is_signed(type)) {
+                       ALLOW_FLAG(is_counter);
+               } else {
+                       fr_strerror_printf("The 'counter' flag cannot be used with '%s'", fr_type_to_str(type));
+                       return false;
+               }
+       }
+
        /*
         *      Check flags against the parent attribute.
         */