1 /* $NetBSD: eui48_108.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_EUI48_108_C 17 #define RDATA_GENERIC_EUI48_108_C 18 19 #include <string.h> 20 21 #define RRTYPE_EUI48_ATTRIBUTES (0) 22 23 static isc_result_t 24 fromtext_eui48(ARGS_FROMTEXT) { 25 isc_token_t token; 26 unsigned char eui48[6]; 27 unsigned int l0, l1, l2, l3, l4, l5; 28 int n; 29 30 REQUIRE(type == dns_rdatatype_eui48); 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", &l0, &l1, &l2, 41 &l3, &l4, &l5); 42 if (n != 6 || l0 > 255U || l1 > 255U || l2 > 255U || l3 > 255U || 43 l4 > 255U || l5 > 255U) 44 { 45 return DNS_R_BADEUI; 46 } 47 48 eui48[0] = l0; 49 eui48[1] = l1; 50 eui48[2] = l2; 51 eui48[3] = l3; 52 eui48[4] = l4; 53 eui48[5] = l5; 54 return mem_tobuffer(target, eui48, sizeof(eui48)); 55 } 56 57 static isc_result_t 58 totext_eui48(ARGS_TOTEXT) { 59 char buf[sizeof("xx-xx-xx-xx-xx-xx")]; 60 61 REQUIRE(rdata->type == dns_rdatatype_eui48); 62 REQUIRE(rdata->length == 6); 63 64 UNUSED(tctx); 65 66 (void)snprintf(buf, sizeof(buf), "%02x-%02x-%02x-%02x-%02x-%02x", 67 rdata->data[0], rdata->data[1], rdata->data[2], 68 rdata->data[3], rdata->data[4], rdata->data[5]); 69 return str_totext(buf, target); 70 } 71 72 static isc_result_t 73 fromwire_eui48(ARGS_FROMWIRE) { 74 isc_region_t sregion; 75 76 REQUIRE(type == dns_rdatatype_eui48); 77 78 UNUSED(type); 79 UNUSED(rdclass); 80 UNUSED(dctx); 81 82 isc_buffer_activeregion(source, &sregion); 83 if (sregion.length != 6) { 84 return DNS_R_FORMERR; 85 } 86 isc_buffer_forward(source, sregion.length); 87 return mem_tobuffer(target, sregion.base, sregion.length); 88 } 89 90 static isc_result_t 91 towire_eui48(ARGS_TOWIRE) { 92 REQUIRE(rdata->type == dns_rdatatype_eui48); 93 REQUIRE(rdata->length == 6); 94 95 UNUSED(cctx); 96 97 return mem_tobuffer(target, rdata->data, rdata->length); 98 } 99 100 static int 101 compare_eui48(ARGS_COMPARE) { 102 isc_region_t region1; 103 isc_region_t region2; 104 105 REQUIRE(rdata1->type == rdata2->type); 106 REQUIRE(rdata1->rdclass == rdata2->rdclass); 107 REQUIRE(rdata1->type == dns_rdatatype_eui48); 108 REQUIRE(rdata1->length == 6); 109 REQUIRE(rdata2->length == 6); 110 111 dns_rdata_toregion(rdata1, ®ion1); 112 dns_rdata_toregion(rdata2, ®ion2); 113 return isc_region_compare(®ion1, ®ion2); 114 } 115 116 static isc_result_t 117 fromstruct_eui48(ARGS_FROMSTRUCT) { 118 dns_rdata_eui48_t *eui48 = source; 119 120 REQUIRE(type == dns_rdatatype_eui48); 121 REQUIRE(eui48 != NULL); 122 REQUIRE(eui48->common.rdtype == type); 123 REQUIRE(eui48->common.rdclass == rdclass); 124 125 UNUSED(type); 126 UNUSED(rdclass); 127 128 return mem_tobuffer(target, eui48->eui48, sizeof(eui48->eui48)); 129 } 130 131 static isc_result_t 132 tostruct_eui48(ARGS_TOSTRUCT) { 133 dns_rdata_eui48_t *eui48 = target; 134 135 REQUIRE(rdata->type == dns_rdatatype_eui48); 136 REQUIRE(eui48 != NULL); 137 REQUIRE(rdata->length == 6); 138 139 UNUSED(mctx); 140 141 DNS_RDATACOMMON_INIT(eui48, rdata->type, rdata->rdclass); 142 143 memmove(eui48->eui48, rdata->data, rdata->length); 144 return ISC_R_SUCCESS; 145 } 146 147 static void 148 freestruct_eui48(ARGS_FREESTRUCT) { 149 dns_rdata_eui48_t *eui48 = source; 150 151 REQUIRE(eui48 != NULL); 152 REQUIRE(eui48->common.rdtype == dns_rdatatype_eui48); 153 154 return; 155 } 156 157 static isc_result_t 158 additionaldata_eui48(ARGS_ADDLDATA) { 159 REQUIRE(rdata->type == dns_rdatatype_eui48); 160 REQUIRE(rdata->length == 6); 161 162 UNUSED(rdata); 163 UNUSED(owner); 164 UNUSED(add); 165 UNUSED(arg); 166 167 return ISC_R_SUCCESS; 168 } 169 170 static isc_result_t 171 digest_eui48(ARGS_DIGEST) { 172 isc_region_t r; 173 174 REQUIRE(rdata->type == dns_rdatatype_eui48); 175 REQUIRE(rdata->length == 6); 176 177 dns_rdata_toregion(rdata, &r); 178 179 return (digest)(arg, &r); 180 } 181 182 static bool 183 checkowner_eui48(ARGS_CHECKOWNER) { 184 REQUIRE(type == dns_rdatatype_eui48); 185 186 UNUSED(name); 187 UNUSED(type); 188 UNUSED(rdclass); 189 UNUSED(wildcard); 190 191 return true; 192 } 193 194 static bool 195 checknames_eui48(ARGS_CHECKNAMES) { 196 REQUIRE(rdata->type == dns_rdatatype_eui48); 197 REQUIRE(rdata->length == 6); 198 199 UNUSED(rdata); 200 UNUSED(owner); 201 UNUSED(bad); 202 203 return true; 204 } 205 206 static int 207 casecompare_eui48(ARGS_COMPARE) { 208 return compare_eui48(rdata1, rdata2); 209 } 210 211 #endif /* RDATA_GENERIC_EUI48_108_C */ 212