1 /* $NetBSD: eui48_108.c,v 1.1.1.4 2014/12/10 03:34:42 christos Exp $ */ 2 3 /* 4 * Copyright (C) 2013, 2014 Internet Systems Consortium, Inc. ("ISC") 5 * 6 * Permission to use, copy, modify, and/or distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 11 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 12 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 13 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 14 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 15 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef RDATA_GENERIC_EUI48_108_C 20 #define RDATA_GENERIC_EUI48_108_C 21 22 #include <string.h> 23 24 #define RRTYPE_EUI48_ATTRIBUTES (0) 25 26 static inline isc_result_t 27 fromtext_eui48(ARGS_FROMTEXT) { 28 isc_token_t token; 29 unsigned char eui48[6]; 30 unsigned int l0, l1, l2, l3, l4, l5; 31 int n; 32 33 REQUIRE(type == 108); 34 35 UNUSED(type); 36 UNUSED(rdclass); 37 UNUSED(origin); 38 UNUSED(options); 39 UNUSED(callbacks); 40 41 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, 42 ISC_FALSE)); 43 n = sscanf(DNS_AS_STR(token), "%2x-%2x-%2x-%2x-%2x-%2x", 44 &l0, &l1, &l2, &l3, &l4, &l5); 45 if (n != 6 || l0 > 255U || l1 > 255U || l2 > 255U || l3 > 255U || 46 l4 > 255U || l5 > 255U) 47 return (DNS_R_BADEUI); 48 49 eui48[0] = l0; 50 eui48[1] = l1; 51 eui48[2] = l2; 52 eui48[3] = l3; 53 eui48[4] = l4; 54 eui48[5] = l5; 55 return (mem_tobuffer(target, eui48, sizeof(eui48))); 56 } 57 58 static inline isc_result_t 59 totext_eui48(ARGS_TOTEXT) { 60 char buf[sizeof("xx-xx-xx-xx-xx-xx")]; 61 62 REQUIRE(rdata->type == 108); 63 REQUIRE(rdata->length == 6); 64 65 UNUSED(tctx); 66 67 (void)snprintf(buf, sizeof(buf), "%02x-%02x-%02x-%02x-%02x-%02x", 68 rdata->data[0], rdata->data[1], rdata->data[2], 69 rdata->data[3], rdata->data[4], rdata->data[5]); 70 return (str_totext(buf, target)); 71 } 72 73 static inline isc_result_t 74 fromwire_eui48(ARGS_FROMWIRE) { 75 isc_region_t sregion; 76 77 REQUIRE(type == 108); 78 79 UNUSED(type); 80 UNUSED(options); 81 UNUSED(rdclass); 82 UNUSED(dctx); 83 84 isc_buffer_activeregion(source, &sregion); 85 if (sregion.length != 6) 86 return (DNS_R_FORMERR); 87 isc_buffer_forward(source, sregion.length); 88 return (mem_tobuffer(target, sregion.base, sregion.length)); 89 } 90 91 static inline isc_result_t 92 towire_eui48(ARGS_TOWIRE) { 93 94 REQUIRE(rdata->type == 108); 95 REQUIRE(rdata->length == 6); 96 97 UNUSED(cctx); 98 99 return (mem_tobuffer(target, rdata->data, rdata->length)); 100 } 101 102 static inline int 103 compare_eui48(ARGS_COMPARE) { 104 isc_region_t region1; 105 isc_region_t region2; 106 107 REQUIRE(rdata1->type == rdata2->type); 108 REQUIRE(rdata1->rdclass == rdata2->rdclass); 109 REQUIRE(rdata1->type == 108); 110 REQUIRE(rdata1->length == 6); 111 REQUIRE(rdata2->length == 6); 112 113 dns_rdata_toregion(rdata1, ®ion1); 114 dns_rdata_toregion(rdata2, ®ion2); 115 return (isc_region_compare(®ion1, ®ion2)); 116 } 117 118 static inline isc_result_t 119 fromstruct_eui48(ARGS_FROMSTRUCT) { 120 dns_rdata_eui48_t *eui48 = source; 121 122 REQUIRE(type == 108); 123 REQUIRE(source != NULL); 124 REQUIRE(eui48->common.rdtype == type); 125 REQUIRE(eui48->common.rdclass == rdclass); 126 127 UNUSED(type); 128 UNUSED(rdclass); 129 130 return (mem_tobuffer(target, eui48->eui48, sizeof(eui48->eui48))); 131 } 132 133 static inline isc_result_t 134 tostruct_eui48(ARGS_TOSTRUCT) { 135 dns_rdata_eui48_t *eui48 = target; 136 137 REQUIRE(rdata->type == 108); 138 REQUIRE(target != NULL); 139 REQUIRE(rdata->length == 6); 140 141 UNUSED(mctx); 142 143 eui48->common.rdclass = rdata->rdclass; 144 eui48->common.rdtype = rdata->type; 145 ISC_LINK_INIT(&eui48->common, link); 146 147 memmove(eui48->eui48, rdata->data, rdata->length); 148 return (ISC_R_SUCCESS); 149 } 150 151 static inline void 152 freestruct_eui48(ARGS_FREESTRUCT) { 153 dns_rdata_eui48_t *eui48 = source; 154 155 REQUIRE(source != NULL); 156 REQUIRE(eui48->common.rdtype == 108); 157 158 return; 159 } 160 161 static inline isc_result_t 162 additionaldata_eui48(ARGS_ADDLDATA) { 163 164 REQUIRE(rdata->type == 108); 165 REQUIRE(rdata->length == 6); 166 167 UNUSED(rdata); 168 UNUSED(add); 169 UNUSED(arg); 170 171 return (ISC_R_SUCCESS); 172 } 173 174 static inline isc_result_t 175 digest_eui48(ARGS_DIGEST) { 176 isc_region_t r; 177 178 REQUIRE(rdata->type == 108); 179 REQUIRE(rdata->length == 6); 180 181 dns_rdata_toregion(rdata, &r); 182 183 return ((digest)(arg, &r)); 184 } 185 186 static inline isc_boolean_t 187 checkowner_eui48(ARGS_CHECKOWNER) { 188 189 REQUIRE(type == 108); 190 191 UNUSED(name); 192 UNUSED(type); 193 UNUSED(rdclass); 194 UNUSED(wildcard); 195 196 return (ISC_TRUE); 197 } 198 199 static inline isc_boolean_t 200 checknames_eui48(ARGS_CHECKNAMES) { 201 202 REQUIRE(rdata->type == 108); 203 REQUIRE(rdata->length == 6); 204 205 UNUSED(rdata); 206 UNUSED(owner); 207 UNUSED(bad); 208 209 return (ISC_TRUE); 210 } 211 212 static inline int 213 casecompare_eui48(ARGS_COMPARE) { 214 return (compare_eui48(rdata1, rdata2)); 215 } 216 217 #endif /* RDATA_GENERIC_EUI48_108_C */ 218