1 /* $NetBSD: eui64_109.c,v 1.9 2025/01/26 16:25:31 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, ®ion1); 115 dns_rdata_toregion(rdata2, ®ion2); 116 return isc_region_compare(®ion1, ®ion2); 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 eui64->common.rdclass = rdata->rdclass; 145 eui64->common.rdtype = rdata->type; 146 ISC_LINK_INIT(&eui64->common, link); 147 148 memmove(eui64->eui64, rdata->data, rdata->length); 149 return ISC_R_SUCCESS; 150 } 151 152 static void 153 freestruct_eui64(ARGS_FREESTRUCT) { 154 dns_rdata_eui64_t *eui64 = source; 155 156 REQUIRE(eui64 != NULL); 157 REQUIRE(eui64->common.rdtype == dns_rdatatype_eui64); 158 159 return; 160 } 161 162 static isc_result_t 163 additionaldata_eui64(ARGS_ADDLDATA) { 164 REQUIRE(rdata->type == dns_rdatatype_eui64); 165 REQUIRE(rdata->length == 8); 166 167 UNUSED(rdata); 168 UNUSED(owner); 169 UNUSED(add); 170 UNUSED(arg); 171 172 return ISC_R_SUCCESS; 173 } 174 175 static isc_result_t 176 digest_eui64(ARGS_DIGEST) { 177 isc_region_t r; 178 179 REQUIRE(rdata->type == dns_rdatatype_eui64); 180 REQUIRE(rdata->length == 8); 181 182 dns_rdata_toregion(rdata, &r); 183 184 return (digest)(arg, &r); 185 } 186 187 static bool 188 checkowner_eui64(ARGS_CHECKOWNER) { 189 REQUIRE(type == dns_rdatatype_eui64); 190 191 UNUSED(name); 192 UNUSED(type); 193 UNUSED(rdclass); 194 UNUSED(wildcard); 195 196 return true; 197 } 198 199 static bool 200 checknames_eui64(ARGS_CHECKNAMES) { 201 REQUIRE(rdata->type == dns_rdatatype_eui64); 202 REQUIRE(rdata->length == 8); 203 204 UNUSED(rdata); 205 UNUSED(owner); 206 UNUSED(bad); 207 208 return true; 209 } 210 211 static int 212 casecompare_eui64(ARGS_COMPARE) { 213 return compare_eui64(rdata1, rdata2); 214 } 215 216 #endif /* RDATA_GENERIC_EUI64_109_C */ 217