return -1;
}
+ /*
+ * Internally we can add aliases to STRUCTs. But the poor user can't.
+ *
+ * This limitation is mainly so that we can differentiate automatically added aliases (which
+ * point to unions), from ones added by users. If we make dict_attr_acopy_aliases() a little
+ * smarter, then we can relax those checks.
+ */
+ switch (parent->type) {
+ case FR_TYPE_TLV:
+ case FR_TYPE_VSA:
+ case FR_TYPE_VENDOR:
+ break;
+
+ default:
+ fr_strerror_printf("ALIAS cannot be added to data type '%s'", fr_type_to_str(parent->type));
+ return -1;
+ }
+
/*
* Relative refs get resolved from the current namespace.
*/
break;
default:
- fr_strerror_printf("Cannot add ALIAS to %s of data type '%s'",
+ fr_strerror_printf("Cannot add ALIAS to parent attribute %s of data type '%s'",
parent->name, fr_type_to_str(parent->type));
return -1;
}
+ if ((ref->type == FR_TYPE_UNION) || fr_dict_attr_is_key_field(ref)) {
+ fr_strerror_printf("Cannot add ALIAS to target attribute %s of data type '%s'",
+ ref->name, fr_type_to_str(ref->type));
+ return -1;
+ }
+
da = dict_attr_by_name(NULL, parent, alias);
if (da) {
fr_strerror_printf("ALIAS '%s' conflicts with another attribute in namespace %s",