From: Arran Cudbard-Bell Date: Wed, 14 Dec 2022 23:54:11 +0000 (-0600) Subject: Move size_t into a struct with the variable length value fields X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da36e0d4624f7a24852700042ae809f5ac2c077c;p=thirdparty%2Ffreeradius-server.git Move size_t into a struct with the variable length value fields Re-arrange fields in fr_value_box_t to take size from 104 bytes -> 64bytes --- diff --git a/src/bin/radsizes.c b/src/bin/radsizes.c index 3cf3bdd1dbe..def8746033b 100644 --- a/src/bin/radsizes.c +++ b/src/bin/radsizes.c @@ -24,7 +24,10 @@ int main(UNUSED int argc, UNUSED char **argv) SIZEOF(fr_tlist_t); SIZEOF(fr_tlist_head_t); + SIZEOF(fr_type_t); SIZEOF(fr_value_box_t); + SIZEOF(fr_value_box_datum_t); + SIZEOF(fr_ipaddr_t); SIZEOF(tmpl_t); SIZEOF(tmpl_attr_rules_t); diff --git a/src/lib/util/value.h b/src/lib/util/value.h index 13150e485db..b8c10e0d1c3 100644 --- a/src/lib/util/value.h +++ b/src/lib/util/value.h @@ -92,67 +92,76 @@ FR_DLIST_TYPES(fr_value_box_list) FR_DCURSOR_DLIST_TYPES(fr_value_box_dcursor, fr_value_box_list, fr_value_box_t) /** @} */ -/** Union containing all data types supported by the server - * - * This union contains all data types that can be represented by fr_pair_ts. It may also be used in other parts - * of the server where values of different types need to be stored. - * - * fr_type_t should be an enumeration of the values in this union. - */ -struct value_box_s { - fr_type_t _CONST type; //!< Type of this value-box, at the start, see pair.h +typedef union { + /* + * Variable length values + */ + struct { + union { + char const * _CONST strvalue; //!< Pointer to UTF-8 string. + uint8_t const * _CONST octets; //!< Pointer to binary string. + void * _CONST ptr; //!< generic pointer. + }; + size_t length; //!< Only these types are variable length. + }; - union { - /* - * Variable length values - */ - char const * _CONST strvalue; //!< Pointer to UTF-8 string. - uint8_t const * _CONST octets; //!< Pointer to binary string. - void * _CONST ptr; //!< generic pointer. + /* + * Fixed length values + */ + fr_ipaddr_t ip; //!< IPv4/6 address/prefix. - /* - * Fixed length values - */ - fr_ipaddr_t ip; //!< IPv4/6 address/prefix. + fr_ifid_t ifid; //!< IPv6 interface ID. + fr_ethernet_t ether; //!< Ethernet (MAC) address. - fr_ifid_t ifid; //!< IPv6 interface ID. - fr_ethernet_t ether; //!< Ethernet (MAC) address. + bool boolean; //!< A truth value. - bool boolean; //!< A truth value. + uint8_t uint8; //!< 8bit unsigned integer. + uint16_t uint16; //!< 16bit unsigned integer. + uint32_t uint32; //!< 32bit unsigned integer. + uint64_t uint64; //!< 64bit unsigned integer. + uint128_t uint128; //!< 128bit unsigned integer. - uint8_t uint8; //!< 8bit unsigned integer. - uint16_t uint16; //!< 16bit unsigned integer. - uint32_t uint32; //!< 32bit unsigned integer. - uint64_t uint64; //!< 64bit unsigned integer. - uint128_t uint128; //!< 128bit unsigned integer. + int8_t int8; //!< 8bit signed integer. + int16_t int16; //!< 16bit signed integer. + int32_t int32; //!< 32bit signed integer. + int64_t int64; //!< 64bit signed integer; - int8_t int8; //!< 8bit signed integer. - int16_t int16; //!< 16bit signed integer. - int32_t int32; //!< 32bit signed integer. - int64_t int64; //!< 64bit signed integer; + float float32; //!< Single precision float. + double float64; //!< Double precision float. - float float32; //!< Single precision float. - double float64; //!< Double precision float. + fr_unix_time_t date; //!< Date internal format in nanoseconds - fr_unix_time_t date; //!< Date internal format in nanoseconds + /* + * System specific - Used for runtime configuration only. + */ + size_t size; //!< System specific file/memory size. + fr_time_delta_t time_delta; //!< a delta time in nanoseconds - /* - * System specific - Used for runtime configuration only. - */ - size_t size; //!< System specific file/memory size. - fr_time_delta_t time_delta; //!< a delta time in nanoseconds + FR_DLIST_HEAD(fr_value_box_list) children; //!< for groups +} fr_value_box_datum_t; - FR_DLIST_HEAD(fr_value_box_list) children; //!< for groups - } datum; +/** Union containing all data types supported by the server + * + * This union contains all data types that can be represented by fr_pair_ts. It may also be used in other parts + * of the server where values of different types need to be stored. + * + * fr_type_t should be an enumeration of the values in this union. + * + * Don't change the order of the fields below without checing that the output of radsize doesn't change. + */ +struct value_box_s { + FR_DLIST_ENTRY(fr_value_box_list) entry; //!< Doubly linked list entry. Should be first for efficiently + ///< traversing linked items. - size_t length; + fr_value_box_datum_t datum; //!< The value held by the value box. + /** Type and flags should appear together for packing efficiency + */ + fr_type_t _CONST type; //!< Type of this value-box, at the start, see pair.h bool tainted; //!< i.e. did it come from an untrusted source - uint16_t _CONST safe; //!< more detailed safety + uint16_t _CONST safe; //!< more detailed safety fr_dict_attr_t const *enumv; //!< Enumeration values. - - FR_DLIST_ENTRY(fr_value_box_list) entry; //!< Doubly linked list entry. }; /** @name List and cursor function definitions @@ -220,7 +229,7 @@ typedef enum { #define vb_timeval datum.timeval #define vb_time_delta datum.time_delta -#define vb_length length +#define vb_length datum.length /** @} */ /** @name Argument boxing macros