/src/bind9/lib/dns/rdata/generic/eui64_109.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) Internet Systems Consortium, Inc. ("ISC") |
3 | | * |
4 | | * SPDX-License-Identifier: MPL-2.0 |
5 | | * |
6 | | * This Source Code Form is subject to the terms of the Mozilla Public |
7 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
8 | | * file, you can obtain one at https://mozilla.org/MPL/2.0/. |
9 | | * |
10 | | * See the COPYRIGHT file distributed with this work for additional |
11 | | * information regarding copyright ownership. |
12 | | */ |
13 | | |
14 | | #ifndef RDATA_GENERIC_EUI64_109_C |
15 | | #define RDATA_GENERIC_EUI64_109_C |
16 | | |
17 | | #include <string.h> |
18 | | |
19 | 8.67k | #define RRTYPE_EUI64_ATTRIBUTES (0) |
20 | | |
21 | | static isc_result_t |
22 | 177 | fromtext_eui64(ARGS_FROMTEXT) { |
23 | 177 | isc_token_t token; |
24 | 177 | unsigned char eui64[8]; |
25 | 177 | unsigned int l0, l1, l2, l3, l4, l5, l6, l7; |
26 | 177 | char buf[sizeof("xx-xx-xx-xx-xx-xx-xx-xx")]; |
27 | 177 | int n; |
28 | | |
29 | 177 | REQUIRE(type == dns_rdatatype_eui64); |
30 | | |
31 | 177 | UNUSED(type); |
32 | 177 | UNUSED(rdclass); |
33 | 177 | UNUSED(origin); |
34 | 177 | UNUSED(options); |
35 | 177 | UNUSED(callbacks); |
36 | | |
37 | 177 | RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, |
38 | 177 | false)); |
39 | 174 | n = sscanf(DNS_AS_STR(token), "%2x-%2x-%2x-%2x-%2x-%2x-%2x-%2x", &l0, |
40 | 174 | &l1, &l2, &l3, &l4, &l5, &l6, &l7); |
41 | 174 | if (n != 8 || l0 > 255U || l1 > 255U || l2 > 255U || l3 > 255U || |
42 | 157 | l4 > 255U || l5 > 255U || l6 > 255U || l7 > 255U) |
43 | 29 | { |
44 | 29 | return DNS_R_BADEUI; |
45 | 29 | } |
46 | | |
47 | | /* |
48 | | * Check that leading zeros were present and that there wasn't |
49 | | * trailing garbage. |
50 | | */ |
51 | 145 | n = snprintf(buf, sizeof(buf), |
52 | 145 | "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", l0, l1, l2, l3, |
53 | 145 | l4, l5, l6, l7); |
54 | 145 | if (n != sizeof(buf) - 1 || strcasecmp(DNS_AS_STR(token), buf) != 0) { |
55 | 96 | return DNS_R_BADEUI; |
56 | 96 | } |
57 | | |
58 | 49 | eui64[0] = l0; |
59 | 49 | eui64[1] = l1; |
60 | 49 | eui64[2] = l2; |
61 | 49 | eui64[3] = l3; |
62 | 49 | eui64[4] = l4; |
63 | 49 | eui64[5] = l5; |
64 | 49 | eui64[6] = l6; |
65 | 49 | eui64[7] = l7; |
66 | 49 | return mem_tobuffer(target, eui64, sizeof(eui64)); |
67 | 145 | } |
68 | | |
69 | | static isc_result_t |
70 | 768 | totext_eui64(ARGS_TOTEXT) { |
71 | 768 | char buf[sizeof("xx-xx-xx-xx-xx-xx-xx-xx")]; |
72 | | |
73 | 768 | REQUIRE(rdata->type == dns_rdatatype_eui64); |
74 | 768 | REQUIRE(rdata->length == 8); |
75 | | |
76 | 768 | UNUSED(tctx); |
77 | | |
78 | 768 | (void)snprintf( |
79 | 768 | buf, sizeof(buf), "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", |
80 | 768 | rdata->data[0], rdata->data[1], rdata->data[2], rdata->data[3], |
81 | 768 | rdata->data[4], rdata->data[5], rdata->data[6], rdata->data[7]); |
82 | 768 | return str_totext(buf, target); |
83 | 768 | } |
84 | | |
85 | | static isc_result_t |
86 | 1.18k | fromwire_eui64(ARGS_FROMWIRE) { |
87 | 1.18k | isc_region_t sregion; |
88 | | |
89 | 1.18k | REQUIRE(type == dns_rdatatype_eui64); |
90 | | |
91 | 1.18k | UNUSED(type); |
92 | 1.18k | UNUSED(rdclass); |
93 | 1.18k | UNUSED(dctx); |
94 | | |
95 | 1.18k | isc_buffer_activeregion(source, &sregion); |
96 | 1.18k | if (sregion.length != 8) { |
97 | 40 | return DNS_R_FORMERR; |
98 | 40 | } |
99 | 1.14k | isc_buffer_forward(source, sregion.length); |
100 | 1.14k | return mem_tobuffer(target, sregion.base, sregion.length); |
101 | 1.18k | } |
102 | | |
103 | | static isc_result_t |
104 | 387 | towire_eui64(ARGS_TOWIRE) { |
105 | 387 | REQUIRE(rdata->type == dns_rdatatype_eui64); |
106 | 387 | REQUIRE(rdata->length == 8); |
107 | | |
108 | 387 | UNUSED(cctx); |
109 | | |
110 | 387 | return mem_tobuffer(target, rdata->data, rdata->length); |
111 | 387 | } |
112 | | |
113 | | static int |
114 | 0 | compare_eui64(ARGS_COMPARE) { |
115 | 0 | isc_region_t region1; |
116 | 0 | isc_region_t region2; |
117 | |
|
118 | 0 | REQUIRE(rdata1->type == rdata2->type); |
119 | 0 | REQUIRE(rdata1->rdclass == rdata2->rdclass); |
120 | 0 | REQUIRE(rdata1->type == dns_rdatatype_eui64); |
121 | 0 | REQUIRE(rdata1->length == 8); |
122 | 0 | REQUIRE(rdata2->length == 8); |
123 | |
|
124 | 0 | dns_rdata_toregion(rdata1, ®ion1); |
125 | 0 | dns_rdata_toregion(rdata2, ®ion2); |
126 | 0 | return isc_region_compare(®ion1, ®ion2); |
127 | 0 | } |
128 | | |
129 | | static isc_result_t |
130 | 0 | fromstruct_eui64(ARGS_FROMSTRUCT) { |
131 | 0 | dns_rdata_eui64_t *eui64 = source; |
132 | |
|
133 | 0 | REQUIRE(type == dns_rdatatype_eui64); |
134 | 0 | REQUIRE(eui64 != NULL); |
135 | 0 | REQUIRE(eui64->common.rdtype == type); |
136 | 0 | REQUIRE(eui64->common.rdclass == rdclass); |
137 | |
|
138 | 0 | UNUSED(type); |
139 | 0 | UNUSED(rdclass); |
140 | |
|
141 | 0 | return mem_tobuffer(target, eui64->eui64, sizeof(eui64->eui64)); |
142 | 0 | } |
143 | | |
144 | | static isc_result_t |
145 | 0 | tostruct_eui64(ARGS_TOSTRUCT) { |
146 | 0 | dns_rdata_eui64_t *eui64 = target; |
147 | |
|
148 | 0 | REQUIRE(rdata->type == dns_rdatatype_eui64); |
149 | 0 | REQUIRE(eui64 != NULL); |
150 | 0 | REQUIRE(rdata->length == 8); |
151 | |
|
152 | 0 | UNUSED(mctx); |
153 | |
|
154 | 0 | DNS_RDATACOMMON_INIT(eui64, rdata->type, rdata->rdclass); |
155 | |
|
156 | 0 | memmove(eui64->eui64, rdata->data, rdata->length); |
157 | 0 | return ISC_R_SUCCESS; |
158 | 0 | } |
159 | | |
160 | | static void |
161 | 0 | freestruct_eui64(ARGS_FREESTRUCT) { |
162 | 0 | dns_rdata_eui64_t *eui64 = source; |
163 | |
|
164 | 0 | REQUIRE(eui64 != NULL); |
165 | 0 | REQUIRE(eui64->common.rdtype == dns_rdatatype_eui64); |
166 | |
|
167 | 0 | return; |
168 | 0 | } |
169 | | |
170 | | static isc_result_t |
171 | 0 | additionaldata_eui64(ARGS_ADDLDATA) { |
172 | 0 | REQUIRE(rdata->type == dns_rdatatype_eui64); |
173 | 0 | REQUIRE(rdata->length == 8); |
174 | |
|
175 | 0 | UNUSED(rdata); |
176 | 0 | UNUSED(owner); |
177 | 0 | UNUSED(add); |
178 | 0 | UNUSED(arg); |
179 | |
|
180 | 0 | return ISC_R_SUCCESS; |
181 | 0 | } |
182 | | |
183 | | static isc_result_t |
184 | 0 | digest_eui64(ARGS_DIGEST) { |
185 | 0 | isc_region_t r; |
186 | |
|
187 | 0 | REQUIRE(rdata->type == dns_rdatatype_eui64); |
188 | 0 | REQUIRE(rdata->length == 8); |
189 | |
|
190 | 0 | dns_rdata_toregion(rdata, &r); |
191 | |
|
192 | 0 | return (digest)(arg, &r); |
193 | 0 | } |
194 | | |
195 | | static bool |
196 | 0 | checkowner_eui64(ARGS_CHECKOWNER) { |
197 | 0 | REQUIRE(type == dns_rdatatype_eui64); |
198 | |
|
199 | 0 | UNUSED(name); |
200 | 0 | UNUSED(type); |
201 | 0 | UNUSED(rdclass); |
202 | 0 | UNUSED(wildcard); |
203 | |
|
204 | 0 | return true; |
205 | 0 | } |
206 | | |
207 | | static bool |
208 | 0 | checknames_eui64(ARGS_CHECKNAMES) { |
209 | 0 | REQUIRE(rdata->type == dns_rdatatype_eui64); |
210 | 0 | REQUIRE(rdata->length == 8); |
211 | |
|
212 | 0 | UNUSED(rdata); |
213 | 0 | UNUSED(owner); |
214 | 0 | UNUSED(bad); |
215 | |
|
216 | 0 | return true; |
217 | 0 | } |
218 | | |
219 | | static int |
220 | 0 | casecompare_eui64(ARGS_COMPARE) { |
221 | 0 | return compare_eui64(rdata1, rdata2); |
222 | 0 | } |
223 | | |
224 | | #endif /* RDATA_GENERIC_EUI64_109_C */ |