Home | History | Annotate | Line # | Download | only in hs_4
      1 /*	$NetBSD: a_1.c,v 1.1 2024/02/18 20:57:45 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      5  *
      6  * SPDX-License-Identifier: MPL-2.0
      7  *
      8  * This Source Code Form is subject to the terms of the Mozilla Public
      9  * License, v. 2.0. If a copy of the MPL was not distributed with this
     10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
     11  *
     12  * See the COPYRIGHT file distributed with this work for additional
     13  * information regarding copyright ownership.
     14  */
     15 
     16 #ifndef RDATA_HS_4_A_1_C
     17 #define RDATA_HS_4_A_1_C
     18 
     19 #include <isc/net.h>
     20 
     21 #define RRTYPE_A_ATTRIBUTES (0)
     22 
     23 static isc_result_t
     24 fromtext_hs_a(ARGS_FROMTEXT) {
     25 	isc_token_t token;
     26 	struct in_addr addr;
     27 	isc_region_t region;
     28 
     29 	REQUIRE(type == dns_rdatatype_a);
     30 	REQUIRE(rdclass == dns_rdataclass_hs);
     31 
     32 	UNUSED(type);
     33 	UNUSED(origin);
     34 	UNUSED(options);
     35 	UNUSED(rdclass);
     36 	UNUSED(callbacks);
     37 
     38 	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
     39 				      false));
     40 
     41 	if (inet_pton(AF_INET, DNS_AS_STR(token), &addr) != 1) {
     42 		RETTOK(DNS_R_BADDOTTEDQUAD);
     43 	}
     44 	isc_buffer_availableregion(target, &region);
     45 	if (region.length < 4) {
     46 		return (ISC_R_NOSPACE);
     47 	}
     48 	memmove(region.base, &addr, 4);
     49 	isc_buffer_add(target, 4);
     50 	return (ISC_R_SUCCESS);
     51 }
     52 
     53 static isc_result_t
     54 totext_hs_a(ARGS_TOTEXT) {
     55 	isc_region_t region;
     56 
     57 	REQUIRE(rdata->type == dns_rdatatype_a);
     58 	REQUIRE(rdata->rdclass == dns_rdataclass_hs);
     59 	REQUIRE(rdata->length == 4);
     60 
     61 	UNUSED(tctx);
     62 
     63 	dns_rdata_toregion(rdata, &region);
     64 	return (inet_totext(AF_INET, tctx->flags, &region, target));
     65 }
     66 
     67 static isc_result_t
     68 fromwire_hs_a(ARGS_FROMWIRE) {
     69 	isc_region_t sregion;
     70 	isc_region_t tregion;
     71 
     72 	REQUIRE(type == dns_rdatatype_a);
     73 	REQUIRE(rdclass == dns_rdataclass_hs);
     74 
     75 	UNUSED(type);
     76 	UNUSED(dctx);
     77 	UNUSED(options);
     78 	UNUSED(rdclass);
     79 
     80 	isc_buffer_activeregion(source, &sregion);
     81 	isc_buffer_availableregion(target, &tregion);
     82 	if (sregion.length < 4) {
     83 		return (ISC_R_UNEXPECTEDEND);
     84 	}
     85 	if (tregion.length < 4) {
     86 		return (ISC_R_NOSPACE);
     87 	}
     88 
     89 	memmove(tregion.base, sregion.base, 4);
     90 	isc_buffer_forward(source, 4);
     91 	isc_buffer_add(target, 4);
     92 	return (ISC_R_SUCCESS);
     93 }
     94 
     95 static isc_result_t
     96 towire_hs_a(ARGS_TOWIRE) {
     97 	isc_region_t region;
     98 
     99 	REQUIRE(rdata->type == dns_rdatatype_a);
    100 	REQUIRE(rdata->rdclass == dns_rdataclass_hs);
    101 	REQUIRE(rdata->length == 4);
    102 
    103 	UNUSED(cctx);
    104 
    105 	isc_buffer_availableregion(target, &region);
    106 	if (region.length < rdata->length) {
    107 		return (ISC_R_NOSPACE);
    108 	}
    109 	memmove(region.base, rdata->data, rdata->length);
    110 	isc_buffer_add(target, 4);
    111 	return (ISC_R_SUCCESS);
    112 }
    113 
    114 static int
    115 compare_hs_a(ARGS_COMPARE) {
    116 	int order;
    117 
    118 	REQUIRE(rdata1->type == rdata2->type);
    119 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
    120 	REQUIRE(rdata1->type == dns_rdatatype_a);
    121 	REQUIRE(rdata1->rdclass == dns_rdataclass_hs);
    122 	REQUIRE(rdata1->length == 4);
    123 	REQUIRE(rdata2->length == 4);
    124 
    125 	order = memcmp(rdata1->data, rdata2->data, 4);
    126 	if (order != 0) {
    127 		order = (order < 0) ? -1 : 1;
    128 	}
    129 
    130 	return (order);
    131 }
    132 
    133 static isc_result_t
    134 fromstruct_hs_a(ARGS_FROMSTRUCT) {
    135 	dns_rdata_hs_a_t *a = source;
    136 	uint32_t n;
    137 
    138 	REQUIRE(type == dns_rdatatype_a);
    139 	REQUIRE(rdclass == dns_rdataclass_hs);
    140 	REQUIRE(a != NULL);
    141 	REQUIRE(a->common.rdtype == type);
    142 	REQUIRE(a->common.rdclass == rdclass);
    143 
    144 	UNUSED(type);
    145 	UNUSED(rdclass);
    146 
    147 	n = ntohl(a->in_addr.s_addr);
    148 
    149 	return (uint32_tobuffer(n, target));
    150 }
    151 
    152 static isc_result_t
    153 tostruct_hs_a(ARGS_TOSTRUCT) {
    154 	dns_rdata_hs_a_t *a = target;
    155 	uint32_t n;
    156 	isc_region_t region;
    157 
    158 	REQUIRE(rdata->type == dns_rdatatype_a);
    159 	REQUIRE(rdata->rdclass == dns_rdataclass_hs);
    160 	REQUIRE(rdata->length == 4);
    161 	REQUIRE(a != NULL);
    162 
    163 	UNUSED(mctx);
    164 
    165 	a->common.rdclass = rdata->rdclass;
    166 	a->common.rdtype = rdata->type;
    167 	ISC_LINK_INIT(&a->common, link);
    168 
    169 	dns_rdata_toregion(rdata, &region);
    170 	n = uint32_fromregion(&region);
    171 	a->in_addr.s_addr = htonl(n);
    172 
    173 	return (ISC_R_SUCCESS);
    174 }
    175 
    176 static void
    177 freestruct_hs_a(ARGS_FREESTRUCT) {
    178 	UNUSED(source);
    179 
    180 	REQUIRE(source != NULL);
    181 }
    182 
    183 static isc_result_t
    184 additionaldata_hs_a(ARGS_ADDLDATA) {
    185 	REQUIRE(rdata->type == dns_rdatatype_a);
    186 	REQUIRE(rdata->rdclass == dns_rdataclass_hs);
    187 
    188 	UNUSED(rdata);
    189 	UNUSED(add);
    190 	UNUSED(arg);
    191 
    192 	return (ISC_R_SUCCESS);
    193 }
    194 
    195 static isc_result_t
    196 digest_hs_a(ARGS_DIGEST) {
    197 	isc_region_t r;
    198 
    199 	REQUIRE(rdata->type == dns_rdatatype_a);
    200 	REQUIRE(rdata->rdclass == dns_rdataclass_hs);
    201 
    202 	dns_rdata_toregion(rdata, &r);
    203 
    204 	return ((digest)(arg, &r));
    205 }
    206 
    207 static bool
    208 checkowner_hs_a(ARGS_CHECKOWNER) {
    209 	REQUIRE(type == dns_rdatatype_a);
    210 	REQUIRE(rdclass == dns_rdataclass_hs);
    211 
    212 	UNUSED(name);
    213 	UNUSED(type);
    214 	UNUSED(rdclass);
    215 	UNUSED(wildcard);
    216 
    217 	return (true);
    218 }
    219 
    220 static bool
    221 checknames_hs_a(ARGS_CHECKNAMES) {
    222 	REQUIRE(rdata->type == dns_rdatatype_a);
    223 	REQUIRE(rdata->rdclass == dns_rdataclass_hs);
    224 
    225 	UNUSED(rdata);
    226 	UNUSED(owner);
    227 	UNUSED(bad);
    228 
    229 	return (true);
    230 }
    231 
    232 static int
    233 casecompare_hs_a(ARGS_COMPARE) {
    234 	return (compare_hs_a(rdata1, rdata2));
    235 }
    236 
    237 #endif /* RDATA_HS_4_A_1_C */
    238