switch (vp->vp_type) {
case FR_TYPE_VARIABLE_SIZE:
#ifndef NDEBUG
- if (!vp->da->flags.extra &&
- ((vp->da->flags.subtype == FLAG_ENCODE_DNS_LABEL) ||
- (vp->da->flags.subtype == FLAG_ENCODE_PARTIAL_DNS_LABEL))) {
+ if (da_is_dns_label(vp->da)) {
fr_assert_fail("DNS labels MUST be encoded/decoded with their own function, and not with generic 'string' functions");
return 0;
}
*/
if (flags->extra || !flags->subtype) return true;
- if (type != FR_TYPE_STRING) {
+ if ((type != FR_TYPE_STRING) && ((flags->subtype == FLAG_ENCODE_DNS_LABEL) || (flags->subtype == FLAG_ENCODE_PARTIAL_DNS_LABEL))) {
fr_strerror_const("The 'dns_label' flag can only be used with attributes of type 'string'");
return false;
}
fr_dict_attr_t const *parent,
uint8_t const *data, size_t const data_len, void *decode_ctx)
{
- /*
- * @todo - we might need to limit this to only one DNS label.
- */
- if ((parent->type == FR_TYPE_STRING) && !parent->flags.extra &&
- ((parent->flags.subtype == FLAG_ENCODE_DNS_LABEL) ||
- (parent->flags.subtype == FLAG_ENCODE_PARTIAL_DNS_LABEL))) {
+ if ((parent->type == FR_TYPE_STRING) && da_is_dns_label(parent)) {
return decode_dns_labels(ctx, out, parent, data, data_len, decode_ctx);
}
fr_pair_append(out, vp);
- } else if ((da->type == FR_TYPE_STRING) && !da->flags.extra &&
- ((da->flags.subtype == FLAG_ENCODE_DNS_LABEL) ||
- (da->flags.subtype == FLAG_ENCODE_PARTIAL_DNS_LABEL))) {
+ } else if ((da->type == FR_TYPE_STRING) && da_is_dns_label(da)) {
fr_pair_list_t tmp;
fr_pair_list_init(&tmp);
FLAG_ENCODE_PARTIAL_DNS_LABEL, //!< encode as a partial DNS label
};
+#define da_is_dns_label(_da) (!(_da)->flags.extra && (((_da)->flags.subtype == FLAG_ENCODE_DNS_LABEL) || ((_da)->flags.subtype == FLAG_ENCODE_PARTIAL_DNS_LABEL)))
+
typedef struct CC_HINT(__packed__) {
uint8_t code;
uint8_t transaction_id[3];
*
* https://tools.ietf.org/html/rfc8415#section-10
*/
- if (!da->flags.extra &&
- ((da->flags.subtype == FLAG_ENCODE_DNS_LABEL) ||
- (da->flags.subtype == FLAG_ENCODE_PARTIAL_DNS_LABEL))) {
+ if (da_is_dns_label(da)) {
fr_dbuff_marker_t last_byte, src;
fr_dbuff_marker(&last_byte, &work_dbuff);