From: Alan T. DeKok Date: Thu, 17 Mar 2022 12:28:44 +0000 (-0400) Subject: switch to using macro for readability X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e23b17ca92f58a2cfb99f108f2bc72591661ef9;p=thirdparty%2Ffreeradius-server.git switch to using macro for readability --- diff --git a/src/protocols/dhcpv4/base.c b/src/protocols/dhcpv4/base.c index 724b4a13b1e..d06b81b37c3 100644 --- a/src/protocols/dhcpv4/base.c +++ b/src/protocols/dhcpv4/base.c @@ -236,8 +236,7 @@ size_t fr_dhcpv4_option_len(fr_pair_t const *vp) switch (vp->vp_type) { case FR_TYPE_VARIABLE_SIZE: #ifndef NDEBUG - if (!vp->da->flags.extra && - (vp->da->flags.subtype == FLAG_ENCODE_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; } @@ -769,7 +768,7 @@ static bool attr_valid(UNUSED fr_dict_t *dict, UNUSED fr_dict_attr_t const *pare */ if (flags->extra || !flags->subtype) return true; - if (type != FR_TYPE_STRING) { + if ((type != FR_TYPE_STRING) && (flags->subtype == FLAG_ENCODE_DNS_LABEL)) { fr_strerror_const("The 'dns_label' flag can only be used with attributes of type 'string'"); return false; } diff --git a/src/protocols/dhcpv4/decode.c b/src/protocols/dhcpv4/decode.c index bf5acc205e0..89673ec35cc 100644 --- a/src/protocols/dhcpv4/decode.c +++ b/src/protocols/dhcpv4/decode.c @@ -61,8 +61,7 @@ static ssize_t decode_value_trampoline(TALLOC_CTX *ctx, fr_pair_list_t *out, /* * @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)) { + if ((parent->type == FR_TYPE_STRING) && da_is_dns_label(parent)) { return decode_dns_labels(ctx, out, parent, data, data_len, decode_ctx); } @@ -641,8 +640,7 @@ static ssize_t decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out, } FR_PROTO_TRACE("decode context changed %s -> %s",da->parent->name, da->name); - if ((da->type == FR_TYPE_STRING) && !da->flags.extra && - (da->flags.subtype == FLAG_ENCODE_DNS_LABEL)) { + if ((da->type == FR_TYPE_STRING) && da_is_dns_label(da)) { fr_pair_list_t tmp; fr_pair_list_init(&tmp); diff --git a/src/protocols/dhcpv4/dhcpv4.h b/src/protocols/dhcpv4/dhcpv4.h index b2ed1b159c5..5743165027f 100644 --- a/src/protocols/dhcpv4/dhcpv4.h +++ b/src/protocols/dhcpv4/dhcpv4.h @@ -73,6 +73,9 @@ enum { FLAG_ENCODE_DNS_LABEL, //!< encode as DNS label }; +#define da_is_dns_label(_da) (!(_da)->flags.extra && ((_da)->flags.subtype == FLAG_ENCODE_DNS_LABEL)) + + typedef struct { uint8_t opcode; uint8_t htype; diff --git a/src/protocols/dhcpv4/encode.c b/src/protocols/dhcpv4/encode.c index 2fb49a8565f..981931cb41d 100644 --- a/src/protocols/dhcpv4/encode.c +++ b/src/protocols/dhcpv4/encode.c @@ -132,7 +132,7 @@ static ssize_t encode_value(fr_dbuff_t *dbuff, * * https://tools.ietf.org/html/rfc8415#section-10 */ - if (!da->flags.extra && (da->flags.subtype == FLAG_ENCODE_DNS_LABEL)) { + if (da_is_dns_label(da)) { fr_dbuff_marker_t last_byte, src; fr_dbuff_marker(&last_byte, &work_dbuff); @@ -177,7 +177,7 @@ static ssize_t encode_array(fr_dbuff_t *dbuff, * DNS labels have internalized length, so we don't need * length headers. */ - if ((da->type == FR_TYPE_STRING) && !da->flags.extra && (da->flags.subtype == FLAG_ENCODE_DNS_LABEL)) { + if ((da->type == FR_TYPE_STRING) && da_is_dns_label(da)) { while (fr_dbuff_extend(&work_dbuff)) { vp = fr_dcursor_current(cursor);