Home | History | Annotate | Line # | Download | only in objs
      1 /*
      2  * Copyright (c) 2021-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 //======================================================================================================================
     18 // MARK: - Headers
     19 
     20 #include "dns_obj_log.h"
     21 #include "dns_obj_rr_soa.h"
     22 #include "dns_obj_rr_private.h"
     23 #include "dns_obj.h"
     24 #include "dns_common.h"
     25 #include "rdata_parser.h"
     26 
     27 #include "dns_assert_macros.h"
     28 #include "mdns_strict.h"
     29 
     30 //======================================================================================================================
     31 // MARK: - DNSSEC SOA Resource Record Kind Definition
     32 
     33 struct dns_obj_rr_soa_s {
     34 	struct dns_obj_rr_s	base; // The reference count and kind support base.
     35 };
     36 
     37 // dns_obj_rr_soa_t is a subkind of dns_obj_rr_t, and it always have DNS type: kDNSRecordType_SOA.
     38 DNS_OBJECT_SUBKIND_DEFINE_ABSTRUCT(rr, soa,
     39 	.rr_type = kDNSRecordType_SOA,
     40 	.copy_rdata_rfc_description_method = NULL
     41 );
     42 
     43 //======================================================================================================================
     44 // MARK: - DNSSEC SOA Resource Record Public Methods
     45 
     46 dns_obj_rr_soa_t
     47 dns_obj_rr_soa_create(const uint8_t * const name, const uint8_t * const rdata, const uint16_t rdata_len,
     48 	const bool allocate, dns_obj_error_t * const out_error)
     49 {
     50 	dns_obj_error_t err;
     51 	dns_obj_rr_soa_t soa = NULL;
     52 	dns_obj_rr_soa_t obj = NULL;
     53 
     54 	const bool valid = rdata_parser_soa_check_validity(rdata, rdata_len);
     55 	require_action(valid, exit, err = DNS_OBJ_ERROR_PARAM_ERR);
     56 
     57 	obj = _dns_obj_rr_soa_new();
     58 	require_action(obj != NULL, exit, err = DNS_OBJ_ERROR_NO_MEMORY);
     59 
     60 	_dns_obj_rr_soa_kind.dns_obj_rr_init_fields(&obj->base, name, _dns_obj_rr_soa_kind.rr_type,
     61 		kDNSClassType_IN, rdata, rdata_len, allocate, _dns_obj_rr_soa_kind.copy_rdata_rfc_description_method, &err);
     62 	require_noerr(err, exit);
     63 
     64 	soa = obj;
     65 	obj = NULL;
     66 	err = DNS_OBJ_ERROR_NO_ERROR;
     67 
     68 exit:
     69 	if (out_error != NULL) {
     70 		*out_error = err;
     71 	}
     72 	MDNS_DISPOSE_DNS_OBJ(obj);
     73 	return soa;
     74 }
     75 
     76 //======================================================================================================================
     77 
     78 uint32_t
     79 dns_obj_rr_soa_get_minimum_ttl(const dns_obj_rr_soa_t me)
     80 {
     81 	const uint8_t * const rdata = dns_obj_rr_get_rdata(me);
     82 	return rdata_parser_soa_get_minimum_ttl(rdata);
     83 }
     84