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