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