2 * Copyright (C) 2013, 2014 Internet Systems Consortium, Inc. ("ISC")
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
17 #ifndef RDATA_GENERIC_EUI64_109_C
18 #define RDATA_GENERIC_EUI64_109_C
22 #define RRTYPE_EUI64_ATTRIBUTES (0)
24 static inline isc_result_t
25 fromtext_eui64(ARGS_FROMTEXT) {
27 unsigned char eui64[8];
28 unsigned int l0, l1, l2, l3, l4, l5, l6, l7;
39 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
41 n = sscanf(DNS_AS_STR(token), "%2x-%2x-%2x-%2x-%2x-%2x-%2x-%2x",
42 &l0, &l1, &l2, &l3, &l4, &l5, &l6, &l7);
43 if (n != 8 || l0 > 255U || l1 > 255U || l2 > 255U || l3 > 255U ||
44 l4 > 255U || l5 > 255U || l6 > 255U || l7 > 255U)
45 return (DNS_R_BADEUI);
55 return (mem_tobuffer(target, eui64, sizeof(eui64)));
58 static inline isc_result_t
59 totext_eui64(ARGS_TOTEXT) {
60 char buf[sizeof("xx-xx-xx-xx-xx-xx-xx-xx")];
62 REQUIRE(rdata->type == 109);
63 REQUIRE(rdata->length == 8);
67 (void)snprintf(buf, sizeof(buf),
68 "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
69 rdata->data[0], rdata->data[1],
70 rdata->data[2], rdata->data[3],
71 rdata->data[4], rdata->data[5],
72 rdata->data[6], rdata->data[7]);
73 return (str_totext(buf, target));
76 static inline isc_result_t
77 fromwire_eui64(ARGS_FROMWIRE) {
87 isc_buffer_activeregion(source, &sregion);
88 if (sregion.length != 8)
89 return (DNS_R_FORMERR);
90 isc_buffer_forward(source, sregion.length);
91 return (mem_tobuffer(target, sregion.base, sregion.length));
94 static inline isc_result_t
95 towire_eui64(ARGS_TOWIRE) {
97 REQUIRE(rdata->type == 109);
98 REQUIRE(rdata->length == 8);
102 return (mem_tobuffer(target, rdata->data, rdata->length));
106 compare_eui64(ARGS_COMPARE) {
107 isc_region_t region1;
108 isc_region_t region2;
110 REQUIRE(rdata1->type == rdata2->type);
111 REQUIRE(rdata1->rdclass == rdata2->rdclass);
112 REQUIRE(rdata1->type == 109);
113 REQUIRE(rdata1->length == 8);
114 REQUIRE(rdata2->length == 8);
116 dns_rdata_toregion(rdata1, ®ion1);
117 dns_rdata_toregion(rdata2, ®ion2);
118 return (isc_region_compare(®ion1, ®ion2));
121 static inline isc_result_t
122 fromstruct_eui64(ARGS_FROMSTRUCT) {
123 dns_rdata_eui64_t *eui64 = source;
125 REQUIRE(type == 109);
126 REQUIRE(source != NULL);
127 REQUIRE(eui64->common.rdtype == type);
128 REQUIRE(eui64->common.rdclass == rdclass);
133 return (mem_tobuffer(target, eui64->eui64, sizeof(eui64->eui64)));
136 static inline isc_result_t
137 tostruct_eui64(ARGS_TOSTRUCT) {
138 dns_rdata_eui64_t *eui64 = target;
140 REQUIRE(rdata->type == 109);
141 REQUIRE(target != NULL);
142 REQUIRE(rdata->length == 8);
146 eui64->common.rdclass = rdata->rdclass;
147 eui64->common.rdtype = rdata->type;
148 ISC_LINK_INIT(&eui64->common, link);
150 memmove(eui64->eui64, rdata->data, rdata->length);
151 return (ISC_R_SUCCESS);
155 freestruct_eui64(ARGS_FREESTRUCT) {
156 dns_rdata_eui64_t *eui64 = source;
158 REQUIRE(source != NULL);
159 REQUIRE(eui64->common.rdtype == 109);
164 static inline isc_result_t
165 additionaldata_eui64(ARGS_ADDLDATA) {
167 REQUIRE(rdata->type == 109);
168 REQUIRE(rdata->length == 8);
174 return (ISC_R_SUCCESS);
177 static inline isc_result_t
178 digest_eui64(ARGS_DIGEST) {
181 REQUIRE(rdata->type == 109);
182 REQUIRE(rdata->length == 8);
184 dns_rdata_toregion(rdata, &r);
186 return ((digest)(arg, &r));
189 static inline isc_boolean_t
190 checkowner_eui64(ARGS_CHECKOWNER) {
192 REQUIRE(type == 109);
202 static inline isc_boolean_t
203 checknames_eui64(ARGS_CHECKNAMES) {
205 REQUIRE(rdata->type == 109);
206 REQUIRE(rdata->length == 8);
216 casecompare_eui64(ARGS_COMPARE) {
217 return (compare_eui64(rdata1, rdata2));
220 #endif /* RDATA_GENERIC_EUI64_109_C */