]>
git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/dnssec_v2/dnssec_v2_helper.h
5 // Copyright (c) 2020 Apple Inc. All rights reserved.
8 #ifndef DNSSEC_v2_HELPER_H
9 #define DNSSEC_v2_HELPER_H
11 #pragma mark - Includes
12 #include "mDNSEmbeddedAPI.h"
13 #if MDNSRESPONDER_SUPPORTS(APPLE, DNSSECv2)
19 // Used to get the primary question from the current request, it is possible that the current request is started by
20 // the DNSSEC handler to follow the CNAME, so the primary question should be get from primary_dnssec_context field.
21 #define GET_PRIMARY_DNSSEC_CONTEXT(C) ((C)->primary_dnssec_context == mDNSNULL) ? \
22 (C) : ((C)->primary_dnssec_context)
23 #define GET_PRIMARY_REQUEST(C) (GET_PRIMARY_DNSSEC_CONTEXT(C))->me
24 #define GET_PRIMARY_QUESTION(C) (&((GET_PRIMARY_REQUEST(C))->op.q))
25 #define GET_REQUEST_ID(C) ((GET_PRIMARY_REQUEST(C))->op.reqID)
26 #define GET_QUESTION(C) (&((C)->me->op.q))
27 #define GET_QUESTION_ID_FROM_Q(Q) (mDNSVal16((Q)->TargetQID))
28 #define GET_QUESTION_ID(C) (GET_QUESTION_ID_FROM_Q(GET_QUESTION(C)))
31 #define DOMAIN_NAME_EQUALS(A, B) SameDomainName((const domainname *)(A), (const domainname *)(B))
32 #define DOMAIN_NAME_LENGTH(NAME) DomainNameLength((const domainname *)(NAME))
33 #define IS_UPPER_CASE(CH) ((CH) >= 'A') && ((CH) <= 'Z')
34 #define IS_LOWER_CASE(CH) ((CH) >= 'a') && ((CH) <= 'z')
35 #define TO_LOWER_CASE(CH) ((CH) + ('a' - 'A'))
38 #define DNS_TYPE_STR(TYPE) DNSTypeName((TYPE))
39 #define NUM_OF_SPACES_PER_TAB 4
40 #define TAB_STR "%{public}*s"
41 #define TAB_PARAM(NUM_OF_TABS) ((NUM_OF_TABS) * (NUM_OF_SPACES_PER_TAB)), ""
42 // BASE64_STR should be used with BASE64_PARAM
43 #define BASE64_STR "%{private, mask.hash}.10s%s"
44 #define BASE64_PARAM(BASE64) (BASE64), strlen(BASE64) < 11 ? "" : "..."
46 #pragma mark - Functions
50 #pragma mark deep_copy_resource_record
53 * Deep copy the record including the name and the rdata.
55 * The copy destination.
59 * Returns mStatus_NoError if no error occurs, other error codes if error occurs
61 * Remember to free the malloced ResourceRecord->name and ResourceRecord->rdata.
64 deep_copy_resource_record(ResourceRecord
* const _Nonnull dst
, const ResourceRecord
* const _Nonnull src
);
66 #pragma mark free_resource_record_deep_copied
69 * Free the malloced memory in the ResourceRecord.
71 * The ResourceRecord that has malloced memory inside.
73 * It will only free malloced fields in ResourceRecord, remember to free ResourceRecord itself.
76 free_resource_record_deep_copied(ResourceRecord
* const _Nonnull rr
);
78 #pragma mark is_root_domain
81 * Given a DNS format DNS name, determine if it is root.
83 * The DNS format domain name.
85 * Returns true if the domain is root, otherwise return false.
88 is_root_domain(const mDNSu8
* const _Nonnull domain_name
);
90 #pragma mark is_a_subdomain_of_b
93 * Determine if a_name is a sub domain of b_name
95 * The child zone or sub domain.
99 * Returns true if a_name is a subdomain of b_name
102 is_a_subdomain_of_b(const mDNSu8
* const _Nonnull a_name
, const mDNSu8
* const _Nonnull b_name
);
104 #pragma mark resource_records_equal
107 * Determine if two records are identical.
109 * Returns true if two records are identical, false if they are not equal.
112 resource_records_equal(
113 const mDNSu16 rr_type_0
, const mDNSu16 rr_type_1
,
114 const mDNSu16 rr_class_0
, const mDNSu16 rr_clasee_1
,
115 const mDNSu16 rdata_length_0
, const mDNSu16 rdata_length_1
,
116 const mDNSu32 name_hash_0
, const mDNSu32 name_hash_1
,
117 const mDNSu32 rdata_hash_0
, const mDNSu32 rdata_hash_1
,
118 const mDNSu8
* const _Nonnull name_0
, const mDNSu8
* const _Nonnull name_1
,
119 const mDNSu8
* const _Nonnull rdata_0
, const mDNSu8
* const _Nonnull rdata_1
);
121 #pragma mark dnssec_algorithm_value_to_string
124 * Convert DNSKEY type to string description.
128 * The corresponding string description of the DNSKEY type.
130 mDNSexport
const char * _Nonnull
131 dnssec_algorithm_value_to_string(const mDNSu8 algorithm
);
133 #pragma mark dnssec_dnskey_flags_to_string
136 * Convert DS hash type to string description.
138 * The DS digest type.
140 * The corresponding string description of the DS digest type.
142 mDNSexport
const char * _Nonnull
143 dnssec_digest_type_value_to_string(const mDNSu8 digest_type
);
145 #pragma mark deep_copy_resource_record
148 * Convert DNSKEY flags to string description.
150 * The DNSKEY flags field
152 * The string buffer that stores the converted string description.
154 * The total size of the buffer.
156 * The pointer to the start of the buffer, aka the start of the description.
158 mDNSexport
const char * _Nonnull
159 dnssec_dnskey_flags_to_string(const mDNSu16 flags
, char * const _Nonnull buffer
, const mDNSu32 buffer_size
);
161 #pragma mark dnssec_epoch_time_to_date_string
164 * Convert epoch time field in RRSIG to string description.
168 * The string buffer that stores the converted string description.
170 * The total size of the buffer.
172 * The pointer to the start of the buffer, aka the start of the description.
174 mDNSexport
const char * _Nonnull
175 dnssec_epoch_time_to_date_string(const mDNSu32 epoch
, char * const _Nonnull buffer
, const mDNSu32 buffer_size
);
177 #pragma mark dnssec_nsec3_flags_to_string
180 * Convert NSEC3 flags to string description.
182 * The DNSKEY flags field
184 * The string buffer that stores the converted string description.
186 * The total size of the buffer.
188 * The pointer to the start of the buffer, aka the start of the description.
190 mDNSexport
const char * _Nonnull
191 dnssec_nsec3_flags_to_string(const mDNSu8 flags
, char * const _Nonnull buffer
, const mDNSu32 buffer_size
);
193 #pragma mark get_number_of_labels
196 * Count the number of labels for the given DNS format name.
198 * The DNS format name.
200 * The number of labels.
203 get_number_of_labels(const mDNSu8
* _Nonnull name
);
205 #pragma mark to_lowercase_if_char
208 * Convert the character to lower string if it is alphbeta.
212 * The converted character.
215 to_lowercase_if_char(const mDNSu8 ch
);
217 #endif // MDNSRESPONDER_SUPPORTS(APPLE, DNSSECv2)
218 #endif // DNSSEC_v2_HELPER_H