1 /*
2 * Copyright (C) 2013-2015 Internet Systems Consortium, Inc. ("ISC")
3 *
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.
7 *
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.
15 */
16
17 #ifndef RDATA_GENERIC_EUI64_109_C
18 #define RDATA_GENERIC_EUI64_109_C
19
20 #include <string.h>
21
22 #define RRTYPE_EUI64_ATTRIBUTES (0)
23
24 static inline isc_result_t
fromtext_eui64(ARGS_FROMTEXT)25 fromtext_eui64(ARGS_FROMTEXT) {
26 isc_token_t token;
27 unsigned char eui64[8];
28 unsigned int l0, l1, l2, l3, l4, l5, l6, l7;
29 int n;
30
31 REQUIRE(type == dns_rdatatype_eui64);
32
33 UNUSED(type);
34 UNUSED(rdclass);
35 UNUSED(origin);
36 UNUSED(options);
37 UNUSED(callbacks);
38
39 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
40 ISC_FALSE));
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);
46
47 eui64[0] = l0;
48 eui64[1] = l1;
49 eui64[2] = l2;
50 eui64[3] = l3;
51 eui64[4] = l4;
52 eui64[5] = l5;
53 eui64[6] = l6;
54 eui64[7] = l7;
55 return (mem_tobuffer(target, eui64, sizeof(eui64)));
56 }
57
58 static inline isc_result_t
totext_eui64(ARGS_TOTEXT)59 totext_eui64(ARGS_TOTEXT) {
60 char buf[sizeof("xx-xx-xx-xx-xx-xx-xx-xx")];
61
62 REQUIRE(rdata->type == dns_rdatatype_eui64);
63 REQUIRE(rdata->length == 8);
64
65 UNUSED(tctx);
66
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));
74 }
75
76 static inline isc_result_t
fromwire_eui64(ARGS_FROMWIRE)77 fromwire_eui64(ARGS_FROMWIRE) {
78 isc_region_t sregion;
79
80 REQUIRE(type == dns_rdatatype_eui64);
81
82 UNUSED(type);
83 UNUSED(options);
84 UNUSED(rdclass);
85 UNUSED(dctx);
86
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));
92 }
93
94 static inline isc_result_t
towire_eui64(ARGS_TOWIRE)95 towire_eui64(ARGS_TOWIRE) {
96
97 REQUIRE(rdata->type == dns_rdatatype_eui64);
98 REQUIRE(rdata->length == 8);
99
100 UNUSED(cctx);
101
102 return (mem_tobuffer(target, rdata->data, rdata->length));
103 }
104
105 static inline int
compare_eui64(ARGS_COMPARE)106 compare_eui64(ARGS_COMPARE) {
107 isc_region_t region1;
108 isc_region_t region2;
109
110 REQUIRE(rdata1->type == rdata2->type);
111 REQUIRE(rdata1->rdclass == rdata2->rdclass);
112 REQUIRE(rdata1->type == dns_rdatatype_eui64);
113 REQUIRE(rdata1->length == 8);
114 REQUIRE(rdata2->length == 8);
115
116 dns_rdata_toregion(rdata1, ®ion1);
117 dns_rdata_toregion(rdata2, ®ion2);
118 return (isc_region_compare(®ion1, ®ion2));
119 }
120
121 static inline isc_result_t
fromstruct_eui64(ARGS_FROMSTRUCT)122 fromstruct_eui64(ARGS_FROMSTRUCT) {
123 dns_rdata_eui64_t *eui64 = source;
124
125 REQUIRE(type == dns_rdatatype_eui64);
126 REQUIRE(source != NULL);
127 REQUIRE(eui64->common.rdtype == type);
128 REQUIRE(eui64->common.rdclass == rdclass);
129
130 UNUSED(type);
131 UNUSED(rdclass);
132
133 return (mem_tobuffer(target, eui64->eui64, sizeof(eui64->eui64)));
134 }
135
136 static inline isc_result_t
tostruct_eui64(ARGS_TOSTRUCT)137 tostruct_eui64(ARGS_TOSTRUCT) {
138 dns_rdata_eui64_t *eui64 = target;
139
140 REQUIRE(rdata->type == dns_rdatatype_eui64);
141 REQUIRE(target != NULL);
142 REQUIRE(rdata->length == 8);
143
144 UNUSED(mctx);
145
146 eui64->common.rdclass = rdata->rdclass;
147 eui64->common.rdtype = rdata->type;
148 ISC_LINK_INIT(&eui64->common, link);
149
150 memmove(eui64->eui64, rdata->data, rdata->length);
151 return (ISC_R_SUCCESS);
152 }
153
154 static inline void
freestruct_eui64(ARGS_FREESTRUCT)155 freestruct_eui64(ARGS_FREESTRUCT) {
156 dns_rdata_eui64_t *eui64 = source;
157
158 REQUIRE(source != NULL);
159 REQUIRE(eui64->common.rdtype == dns_rdatatype_eui64);
160
161 return;
162 }
163
164 static inline isc_result_t
additionaldata_eui64(ARGS_ADDLDATA)165 additionaldata_eui64(ARGS_ADDLDATA) {
166
167 REQUIRE(rdata->type == dns_rdatatype_eui64);
168 REQUIRE(rdata->length == 8);
169
170 UNUSED(rdata);
171 UNUSED(add);
172 UNUSED(arg);
173
174 return (ISC_R_SUCCESS);
175 }
176
177 static inline isc_result_t
digest_eui64(ARGS_DIGEST)178 digest_eui64(ARGS_DIGEST) {
179 isc_region_t r;
180
181 REQUIRE(rdata->type == dns_rdatatype_eui64);
182 REQUIRE(rdata->length == 8);
183
184 dns_rdata_toregion(rdata, &r);
185
186 return ((digest)(arg, &r));
187 }
188
189 static inline isc_boolean_t
checkowner_eui64(ARGS_CHECKOWNER)190 checkowner_eui64(ARGS_CHECKOWNER) {
191
192 REQUIRE(type == dns_rdatatype_eui64);
193
194 UNUSED(name);
195 UNUSED(type);
196 UNUSED(rdclass);
197 UNUSED(wildcard);
198
199 return (ISC_TRUE);
200 }
201
202 static inline isc_boolean_t
checknames_eui64(ARGS_CHECKNAMES)203 checknames_eui64(ARGS_CHECKNAMES) {
204
205 REQUIRE(rdata->type == dns_rdatatype_eui64);
206 REQUIRE(rdata->length == 8);
207
208 UNUSED(rdata);
209 UNUSED(owner);
210 UNUSED(bad);
211
212 return (ISC_TRUE);
213 }
214
215 static inline int
casecompare_eui64(ARGS_COMPARE)216 casecompare_eui64(ARGS_COMPARE) {
217 return (compare_eui64(rdata1, rdata2));
218 }
219
220 #endif /* RDATA_GENERIC_EUI64_109_C */
221