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