]> 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:39:33 +0000 (08:39 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 17 Mar 2022 14:46:55 +0000 (10:46 -0400)
src/protocols/dhcpv6/base.c
src/protocols/dhcpv6/decode.c
src/protocols/dhcpv6/dhcpv6.h
src/protocols/dhcpv6/encode.c

index 600d103f680b9ba9b10649c6075a47f48b754ea7..d809e791492c478482f197ede88f62be5c9f3b14 100644 (file)
@@ -147,9 +147,7 @@ size_t fr_dhcpv6_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) ||
-                    (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;
                }
@@ -1041,7 +1039,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) || (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;
        }
index b35cd1a830a6efbc677bce437b9dbfd047bfca83..66671a99291629ad74b7e3f12903a5c6ce30a6dd 100644 (file)
@@ -113,12 +113,7 @@ static ssize_t decode_value_trampoline(TALLOC_CTX *ctx, fr_pair_list_t *out,
                                       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);
        }
 
@@ -575,9 +570,7 @@ static ssize_t decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out,
 
                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);
index d60cbdb16640f64bb53e46ac04bae4888b790252..3d500ced124e24b5ce6f4727276069282f9d4b30 100644 (file)
@@ -117,6 +117,8 @@ enum {
        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];
index eb552ec79f798683476425ab4c2ae3c6b2100ad4..e3755127d6715ed9fc27be6eec52064f12b90d07 100644 (file)
@@ -168,9 +168,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) ||
-                    (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);