From: Ronan Pigott Date: Mon, 18 Dec 2023 04:30:03 +0000 (-0700) Subject: dns: remove some magic numbers X-Git-Tag: v256-rc1~1318^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=980cb160ebe7b058c601577cf72cbd2162d7d054;p=thirdparty%2Fsystemd.git dns: remove some magic numbers Let's use enum values for the EDNS codes now that we have them, for readability. --- diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c index 3729bef1ae5..8eb75082cd3 100644 --- a/src/resolve/resolved-dns-packet.c +++ b/src/resolve/resolved-dns-packet.c @@ -775,7 +775,7 @@ int dns_packet_append_opt( static const uint8_t rfc6975[] = { - 0, 5, /* OPTION_CODE: DAU */ + 0, DNS_EDNS_OPT_DAU, /* OPTION_CODE */ #if PREFER_OPENSSL || (HAVE_GCRYPT && GCRYPT_VERSION_NUMBER >= 0x010600) 0, 7, /* LIST_LENGTH */ #else @@ -791,13 +791,13 @@ int dns_packet_append_opt( DNSSEC_ALGORITHM_ED25519, #endif - 0, 6, /* OPTION_CODE: DHU */ + 0, DNS_EDNS_OPT_DHU, /* OPTION_CODE */ 0, 3, /* LIST_LENGTH */ DNSSEC_DIGEST_SHA1, DNSSEC_DIGEST_SHA256, DNSSEC_DIGEST_SHA384, - 0, 7, /* OPTION_CODE: N3U */ + 0, DNS_EDNS_OPT_N3U, /* OPTION_CODE */ 0, 1, /* LIST_LENGTH */ NSEC3_ALGORITHM_SHA1, }; @@ -2180,7 +2180,7 @@ static bool opt_is_good(DnsResourceRecord *rr, bool *rfc6975) { return false; /* RFC 6975 DAU, DHU or N3U fields found. */ - if (IN_SET(option_code, 5, 6, 7)) + if (IN_SET(option_code, DNS_EDNS_OPT_DAU, DNS_EDNS_OPT_DHU, DNS_EDNS_OPT_N3U)) found_dau_dhu_n3u = true; p += option_length + 4U; @@ -2597,7 +2597,7 @@ int dns_packet_has_nsid_request(DnsPacket *p) { return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG), "Truncated option in EDNS0 variable part."); - if (code == 3) { + if (code == DNS_EDNS_OPT_NSID) { if (has_nsid) return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG), "Duplicate NSID option in EDNS0 variable part.");