Home | History | Annotate | Line # | Download | only in generic
      1 /*	$NetBSD: eui64_109.c,v 1.10 2026/01/29 18:37:52 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_GENERIC_EUI64_109_C
     17 #define RDATA_GENERIC_EUI64_109_C
     18 
     19 #include <string.h>
     20 
     21 #define RRTYPE_EUI64_ATTRIBUTES (0)
     22 
     23 static isc_result_t
     24 fromtext_eui64(ARGS_FROMTEXT) {
     25 	isc_token_t token;
     26 	unsigned char eui64[8];
     27 	unsigned int l0, l1, l2, l3, l4, l5, l6, l7;
     28 	int n;
     29 
     30 	REQUIRE(type == dns_rdatatype_eui64);
     31 
     32 	UNUSED(type);
     33 	UNUSED(rdclass);
     34 	UNUSED(origin);
     35 	UNUSED(options);
     36 	UNUSED(callbacks);
     37 
     38 	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
     39 				      false));
     40 	n = sscanf(DNS_AS_STR(token), "%2x-%2x-%2x-%2x-%2x-%2x-%2x-%2x", &l0,
     41 		   &l1, &l2, &l3, &l4, &l5, &l6, &l7);
     42 	if (n != 8 || l0 > 255U || l1 > 255U || l2 > 255U || l3 > 255U ||
     43 	    l4 > 255U || l5 > 255U || l6 > 255U || l7 > 255U)
     44 	{
     45 		return DNS_R_BADEUI;
     46 	}
     47 
     48 	eui64[0] = l0;
     49 	eui64[1] = l1;
     50 	eui64[2] = l2;
     51 	eui64[3] = l3;
     52 	eui64[4] = l4;
     53 	eui64[5] = l5;
     54 	eui64[6] = l6;
     55 	eui64[7] = l7;
     56 	return mem_tobuffer(target, eui64, sizeof(eui64));
     57 }
     58 
     59 static isc_result_t
     60 totext_eui64(ARGS_TOTEXT) {
     61 	char buf[sizeof("xx-xx-xx-xx-xx-xx-xx-xx")];
     62 
     63 	REQUIRE(rdata->type == dns_rdatatype_eui64);
     64 	REQUIRE(rdata->length == 8);
     65 
     66 	UNUSED(tctx);
     67 
     68 	(void)snprintf(
     69 		buf, sizeof(buf), "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
     70 		rdata->data[0], rdata->data[1], rdata->data[2], rdata->data[3],
     71 		rdata->data[4], rdata->data[5], rdata->data[6], rdata->data[7]);
     72 	return str_totext(buf, target);
     73 }
     74 
     75 static isc_result_t
     76 fromwire_eui64(ARGS_FROMWIRE) {
     77 	isc_region_t sregion;
     78 
     79 	REQUIRE(type == dns_rdatatype_eui64);
     80 
     81 	UNUSED(type);
     82 	UNUSED(rdclass);
     83 	UNUSED(dctx);
     84 
     85 	isc_buffer_activeregion(source, &sregion);
     86 	if (sregion.length != 8) {
     87 		return DNS_R_FORMERR;
     88 	}
     89 	isc_buffer_forward(source, sregion.length);
     90 	return mem_tobuffer(target, sregion.base, sregion.length);
     91 }
     92 
     93 static isc_result_t
     94 towire_eui64(ARGS_TOWIRE) {
     95 	REQUIRE(rdata->type == dns_rdatatype_eui64);
     96 	REQUIRE(rdata->length == 8);
     97 
     98 	UNUSED(cctx);
     99 
    100 	return mem_tobuffer(target, rdata->data, rdata->length);
    101 }
    102 
    103 static int
    104 compare_eui64(ARGS_COMPARE) {
    105 	isc_region_t region1;
    106 	isc_region_t region2;
    107 
    108 	REQUIRE(rdata1->type == rdata2->type);
    109 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
    110 	REQUIRE(rdata1->type == dns_rdatatype_eui64);
    111 	REQUIRE(rdata1->length == 8);
    112 	REQUIRE(rdata2->length == 8);
    113 
    114 	dns_rdata_toregion(rdata1, &region1);
    115 	dns_rdata_toregion(rdata2, &region2);
    116 	return isc_region_compare(&region1, &region2);
    117 }
    118 
    119 static isc_result_t
    120 fromstruct_eui64(ARGS_FROMSTRUCT) {
    121 	dns_rdata_eui64_t *eui64 = source;
    122 
    123 	REQUIRE(type == dns_rdatatype_eui64);
    124 	REQUIRE(eui64 != NULL);
    125 	REQUIRE(eui64->common.rdtype == type);
    126 	REQUIRE(eui64->common.rdclass == rdclass);
    127 
    128 	UNUSED(type);
    129 	UNUSED(rdclass);
    130 
    131 	return mem_tobuffer(target, eui64->eui64, sizeof(eui64->eui64));
    132 }
    133 
    134 static isc_result_t
    135 tostruct_eui64(ARGS_TOSTRUCT) {
    136 	dns_rdata_eui64_t *eui64 = target;
    137 
    138 	REQUIRE(rdata->type == dns_rdatatype_eui64);
    139 	REQUIRE(eui64 != NULL);
    140 	REQUIRE(rdata->length == 8);
    141 
    142 	UNUSED(mctx);
    143 
    144 	DNS_RDATACOMMON_INIT(eui64, rdata->type, rdata->rdclass);
    145 
    146 	memmove(eui64->eui64, rdata->data, rdata->length);
    147 	return ISC_R_SUCCESS;
    148 }
    149 
    150 static void
    151 freestruct_eui64(ARGS_FREESTRUCT) {
    152 	dns_rdata_eui64_t *eui64 = source;
    153 
    154 	REQUIRE(eui64 != NULL);
    155 	REQUIRE(eui64->common.rdtype == dns_rdatatype_eui64);
    156 
    157 	return;
    158 }
    159 
    160 static isc_result_t
    161 additionaldata_eui64(ARGS_ADDLDATA) {
    162 	REQUIRE(rdata->type == dns_rdatatype_eui64);
    163 	REQUIRE(rdata->length == 8);
    164 
    165 	UNUSED(rdata);
    166 	UNUSED(owner);
    167 	UNUSED(add);
    168 	UNUSED(arg);
    169 
    170 	return ISC_R_SUCCESS;
    171 }
    172 
    173 static isc_result_t
    174 digest_eui64(ARGS_DIGEST) {
    175 	isc_region_t r;
    176 
    177 	REQUIRE(rdata->type == dns_rdatatype_eui64);
    178 	REQUIRE(rdata->length == 8);
    179 
    180 	dns_rdata_toregion(rdata, &r);
    181 
    182 	return (digest)(arg, &r);
    183 }
    184 
    185 static bool
    186 checkowner_eui64(ARGS_CHECKOWNER) {
    187 	REQUIRE(type == dns_rdatatype_eui64);
    188 
    189 	UNUSED(name);
    190 	UNUSED(type);
    191 	UNUSED(rdclass);
    192 	UNUSED(wildcard);
    193 
    194 	return true;
    195 }
    196 
    197 static bool
    198 checknames_eui64(ARGS_CHECKNAMES) {
    199 	REQUIRE(rdata->type == dns_rdatatype_eui64);
    200 	REQUIRE(rdata->length == 8);
    201 
    202 	UNUSED(rdata);
    203 	UNUSED(owner);
    204 	UNUSED(bad);
    205 
    206 	return true;
    207 }
    208 
    209 static int
    210 casecompare_eui64(ARGS_COMPARE) {
    211 	return compare_eui64(rdata1, rdata2);
    212 }
    213 
    214 #endif /* RDATA_GENERIC_EUI64_109_C */
    215