From: Alan T. DeKok Date: Tue, 3 May 2022 12:20:28 +0000 (+0200) Subject: add "counter" flag for unsigned integers. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f40e69ed1de1989a8768c76945a1ad6c68abe71;p=thirdparty%2Ffreeradius-server.git add "counter" flag for unsigned integers. to enable more SNMP, and internal stats, along with automatic aggregation of stats. --- diff --git a/src/lib/util/dict.h b/src/lib/util/dict.h index 8e2020c475f..aab9b28649b 100644 --- a/src/lib/util/dict.h +++ b/src/lib/util/dict.h @@ -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 diff --git a/src/lib/util/dict_tokenize.c b/src/lib/util/dict_tokenize.c index 38076d64a17..ddaa8ece810 100644 --- a/src/lib/util/dict_tokenize.c +++ b/src/lib/util/dict_tokenize.c @@ -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; diff --git a/src/lib/util/dict_validate.c b/src/lib/util/dict_validate.c index b2121a6abda..e4fa2964573 100644 --- a/src/lib/util/dict_validate.c +++ b/src/lib/util/dict_validate.c @@ -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. */