]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
switch to using macro for readability
authorAlan T. DeKok <aland@freeradius.org>
Thu, 17 Mar 2022 12:28:44 +0000 (08:28 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 17 Mar 2022 14:46:54 +0000 (10:46 -0400)
src/protocols/dhcpv4/base.c
src/protocols/dhcpv4/decode.c
src/protocols/dhcpv4/dhcpv4.h
src/protocols/dhcpv4/encode.c

index 724b4a13b1e156444331dc758e37e470ded51761..d06b81b37c3fbd2d0d2f7fb497082d8e3554acd7 100644 (file)
@@ -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;
        }
index bf5acc205e02d15858de6c4b0440f89f4466537d..89673ec35cc270c7b11bb9b6bdcb235b801f4715 100644 (file)
@@ -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);
index b2ed1b159c58a9a23c39c71d455bb9a41bf7cfba..5743165027fb46345ad2e42c131dc62e455246d2 100644 (file)
@@ -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;
index 2fb49a8565f1845a773f224ec79f0375b38e9cbd..981931cb41d8fe0ab2b168190262bf85ac4d7a09 100644 (file)
@@ -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);