@@ -251,11 +251,30 @@ static int dict_flag_class(fr_dict_attr_t **da_p, char const *value, UNUSED fr_d
251251 return 0 ;
252252}
253253
254- static int dict_flag_has_default (fr_dict_attr_t * * da_p , UNUSED char const * value , UNUSED fr_dict_flag_parser_rule_t const * rules )
254+ static int dict_flag_default_value (fr_dict_attr_t * * da_p , char const * value , UNUSED fr_dict_flag_parser_rule_t const * rules )
255255{
256256 fr_der_attr_flags_t * flags = fr_dict_attr_ext (* da_p , FR_DICT_ATTR_EXT_PROTOCOL_SPECIFIC );
257257
258- flags -> has_default = true;
258+ if (!fr_type_is_leaf ((* da_p )-> type )) {
259+ fr_strerror_printf ("Cannot set 'default=...' for attribute %s DER type %s" ,
260+ (* da_p )-> name , fr_der_tag_to_str (flags -> der_type ));
261+ return -1 ;
262+ }
263+
264+ /*
265+ * The default values are parented from the dict root. That way we don't need to copy the values
266+ * when we clone the attribute, we can just copy the pointer.
267+ */
268+ flags -> default_value = fr_value_box_alloc (fr_dict_unconst ((* da_p )-> dict ), (* da_p )-> type , NULL );
269+ if (!flags -> default_value ) return -1 ;
270+
271+ if (fr_value_box_from_str (flags -> default_value , flags -> default_value , (* da_p )-> type , NULL ,
272+ value , strlen (value ), NULL , false) < 0 ) {
273+ fr_strerror_printf ("Failed parsing 'value=...' - %s" , fr_strerror ());
274+ return -1 ;
275+ }
276+
277+ flags -> has_default_value = true;
259278
260279 return 0 ;
261280}
@@ -587,8 +606,8 @@ static int dict_flag_optional(fr_dict_attr_t **da_p, UNUSED char const *value, U
587606
588607static const fr_dict_flag_parser_t der_flags [] = {
589608 { L ("class" ), { .func = dict_flag_class } },
609+ { L ("default" ), { .func = dict_flag_default_value ,.needs_value = true } },
590610 { L ("der_type" ), { .func = dict_flag_der_type , .needs_value = true } },
591- { L ("has_default" ), { .func = dict_flag_has_default } },
592611 { L ("is_extensions" ), { .func = dict_flag_is_extensions } },
593612 { L ("is_oid_leaf" ), { .func = dict_flag_is_oid_leaf } },
594613 { L ("max" ), { .func = dict_flag_max , .needs_value = true } },
0 commit comments