1 /* 2 * Copyright (c) 2022 Apple Inc. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef DNS_OBJ_RR_PRIVATE_H 18 #define DNS_OBJ_RR_PRIVATE_H 19 20 //====================================================================================================================== 21 // MARK: - Headers 22 23 #include "dns_obj_rr.h" 24 #include "dns_obj.h" 25 #include "dns_common.h" 26 #include <stdint.h> 27 #include <stdbool.h> 28 29 #include "nullability.h" 30 31 //====================================================================================================================== 32 // MARK: - DNS Resource Record Kind Definition 33 34 typedef char * NULLABLE 35 (*dns_obj_rr_copy_rdata_rfc_description_f)(dns_obj_rr_t NONNULL record, dns_obj_error_t * NULLABLE out_error); 36 37 struct dns_obj_rr_s { 38 struct ref_count_obj_s base; // The reference count and kind support base. 39 dns_obj_domain_name_t NULLABLE name; // The name of the resource record. 40 union { 41 const uint8_t * NULLABLE const_rdata; // The pointer to the rdata that is valid for the life time of this resource record object. 42 uint8_t * NULLABLE allocated_rdata; // The pointer to the rdata that is allocated when initializing this resource record object. 43 } rdata_u; 44 uint16_t type; // The DNS data type of the record. 45 uint16_t class; // The DNS class of the record. 46 uint16_t rdata_len; // The length of the rdata. 47 bool allocated_memory; // Indicate whether the domain name labels in the name of 48 // the resource record and the rdata point to an external 49 // memory or is allocated. 50 uint32_t ttl; // The real TTL of the resource record. 51 uint32_t original_ttl; // The original TTL value specified by RRSIG. 52 uint8_t rrsig_labels; // The labels value specified by RRSIG 53 uint8_t * NULLABLE signed_data; // The signed data of the resource record that is used for DNSSEC validation. 54 size_t signed_data_len; // The length of the signed data above. 55 56 dns_obj_rr_copy_rdata_rfc_description_f NULLABLE copy_rdata_rfc_description_method; // The method that can be customized for each RR type to generate the rdata description. 57 }; 58 59 // The member initialization function to be called by the subkind of the resource record object. 60 typedef void 61 (*dns_obj_rr_init_fields_f)(dns_obj_rr_t NONNULL uninitialized_record, const uint8_t * NONNULL name, uint16_t type, 62 uint16_t class, const uint8_t * NULLABLE rdata, uint16_t rdata_len, bool allocate, 63 dns_obj_rr_copy_rdata_rfc_description_f NULLABLE copy_rdata_rfc_description_method, dns_obj_error_t * NULLABLE out_error); 64 65 void 66 dns_obj_rr_init_fields(dns_obj_rr_t NONNULL uninitialized_record, const uint8_t * NONNULL name, uint16_t type, 67 uint16_t class, const uint8_t * NULLABLE rdata, uint16_t rdata_len, bool allocate, 68 dns_obj_rr_copy_rdata_rfc_description_f NULLABLE copy_rdata_rfc_description_method, dns_obj_error_t * NULLABLE out_error); 69 70 // The resource record kind type for a subkind of the resource record object. 71 DNS_OBJECT_DEFINE_KIND_TYPE_FOR_SUBKIND(rr, 72 uint16_t rr_type; // Any subkind of the resource record should have a specific DNS type. 73 dns_obj_rr_copy_rdata_rfc_description_f NONNULL copy_rdata_rfc_description_method; 74 ); 75 76 #endif // DNS_OBJ_RR_PRIVATE_H 77