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
*
* @note New extension structures should also be added to the to the appropriate table in dict_ext.c
* @todo - allow dns_label encoding as
* the first member.
*/
- if ((dict_attr_sizes[sibling->type][1] == ~(size_t) 0) &&
+ if ((max_size(sibling->type) == ~(size_t) 0) &&
(sibling->flags.length == 0)) {
fr_strerror_const("Only the last child of a 'struct' attribute can have variable length");
return false;
/*
* Set size for all fixed length attributes.
*/
- ret = dict_attr_sizes[*dst_type][1]; /* Max length */
+ ret = max_size(*dst_type);
/*
* Lookup any names before continuing
if (fr_inet_pton(&dst->vb_ip, in, inlen, AF_UNSPEC, fr_hostname_lookups, true) < 0) return -1;
switch (dst->vb_ip.af) {
case AF_INET:
- ret = dict_attr_sizes[FR_TYPE_COMBO_IP_ADDR][0]; /* size of IPv4 address */
+ ret = min_size(FR_TYPE_COMBO_IP_ADDR); /* size of IPv4 address */
*dst_type = FR_TYPE_IPV4_ADDR;
break;
case AF_INET6:
*dst_type = FR_TYPE_IPV6_ADDR;
- ret = dict_attr_sizes[FR_TYPE_COMBO_IP_ADDR][1]; /* size of IPv6 address */
+ ret = max_size(FR_TYPE_COMBO_IP_ADDR); /* size of IPv6 address */
break;
default:
/*
* Output must be a non-zero limited size.
*/
- if ((dict_attr_sizes[type][0] == 0) ||
- (dict_attr_sizes[type][0] != dict_attr_sizes[type][1])) {
+ if ((min_size(type) == 0) || !is_fixed_size(type)) {
REDEBUG("unpack requires fixed-size output type, not '%s'", data_type);
goto nothing;
}
- if (input_len < (offset + dict_attr_sizes[type][0])) {
+ if (input_len < (offset + min_size(type))) {
REDEBUG("Insufficient data to unpack '%s' from '%s'", data_type, data_name);
goto nothing;
}
MEM(cast = fr_pair_afrom_da(request, da));
- memcpy(&(cast->data), input + offset, dict_attr_sizes[type][0]);
+ memcpy(&(cast->data), input + offset, min_size(type));
/*
* Hacks
* then don't encode this VP.
*/
if (hdr[1] && vp->da->flags.array &&
- (dict_attr_sizes[vp->da->type][0] == dict_attr_sizes[vp->da->type][1]) &&
- (hdr[1] + dict_attr_sizes[vp->da->type][0]) > 255) {
+ is_fixed_size(vp->da->type) &&
+ (hdr[1] + min_size(vp->da->type)) > 255) {
break;
}