xref: /netbsd-src/external/mpl/dhcp/bind/dist/lib/dns/rdata/generic/l64_106.c (revision 4afad4b7fa6d4a0d3dedf41d1587a7250710ae54)
1 /*	$NetBSD: l64_106.c,v 1.1 2024/02/18 20:57:42 christos Exp $	*/
2 
3 /*
4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5  *
6  * SPDX-License-Identifier: MPL-2.0
7  *
8  * This Source Code Form is subject to the terms of the Mozilla Public
9  * License, v. 2.0. If a copy of the MPL was not distributed with this
10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11  *
12  * See the COPYRIGHT file distributed with this work for additional
13  * information regarding copyright ownership.
14  */
15 
16 #ifndef RDATA_GENERIC_L64_106_C
17 #define RDATA_GENERIC_L64_106_C
18 
19 #include <string.h>
20 
21 #include <isc/net.h>
22 
23 #define RRTYPE_L64_ATTRIBUTES (0)
24 
25 static isc_result_t
fromtext_l64(ARGS_FROMTEXT)26 fromtext_l64(ARGS_FROMTEXT) {
27 	isc_token_t token;
28 	unsigned char locator[NS_LOCATORSZ];
29 
30 	REQUIRE(type == dns_rdatatype_l64);
31 
32 	UNUSED(type);
33 	UNUSED(rdclass);
34 	UNUSED(origin);
35 	UNUSED(options);
36 	UNUSED(callbacks);
37 
38 	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
39 				      false));
40 	if (token.value.as_ulong > 0xffffU) {
41 		RETTOK(ISC_R_RANGE);
42 	}
43 	RETERR(uint16_tobuffer(token.value.as_ulong, target));
44 
45 	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
46 				      false));
47 
48 	if (locator_pton(DNS_AS_STR(token), locator) != 1) {
49 		RETTOK(DNS_R_SYNTAX);
50 	}
51 	return (mem_tobuffer(target, locator, NS_LOCATORSZ));
52 }
53 
54 static isc_result_t
totext_l64(ARGS_TOTEXT)55 totext_l64(ARGS_TOTEXT) {
56 	isc_region_t region;
57 	char buf[sizeof("xxxx:xxxx:xxxx:xxxx")];
58 	unsigned short num;
59 
60 	REQUIRE(rdata->type == dns_rdatatype_l64);
61 	REQUIRE(rdata->length == 10);
62 
63 	UNUSED(tctx);
64 
65 	dns_rdata_toregion(rdata, &region);
66 	num = uint16_fromregion(&region);
67 	isc_region_consume(&region, 2);
68 	snprintf(buf, sizeof(buf), "%u", num);
69 	RETERR(str_totext(buf, target));
70 
71 	RETERR(str_totext(" ", target));
72 
73 	snprintf(buf, sizeof(buf), "%x:%x:%x:%x",
74 		 region.base[0] << 8 | region.base[1],
75 		 region.base[2] << 8 | region.base[3],
76 		 region.base[4] << 8 | region.base[5],
77 		 region.base[6] << 8 | region.base[7]);
78 	return (str_totext(buf, target));
79 }
80 
81 static isc_result_t
fromwire_l64(ARGS_FROMWIRE)82 fromwire_l64(ARGS_FROMWIRE) {
83 	isc_region_t sregion;
84 
85 	REQUIRE(type == dns_rdatatype_l64);
86 
87 	UNUSED(type);
88 	UNUSED(options);
89 	UNUSED(rdclass);
90 	UNUSED(dctx);
91 
92 	isc_buffer_activeregion(source, &sregion);
93 	if (sregion.length != 10) {
94 		return (DNS_R_FORMERR);
95 	}
96 	isc_buffer_forward(source, sregion.length);
97 	return (mem_tobuffer(target, sregion.base, sregion.length));
98 }
99 
100 static isc_result_t
towire_l64(ARGS_TOWIRE)101 towire_l64(ARGS_TOWIRE) {
102 	REQUIRE(rdata->type == dns_rdatatype_l64);
103 	REQUIRE(rdata->length == 10);
104 
105 	UNUSED(cctx);
106 
107 	return (mem_tobuffer(target, rdata->data, rdata->length));
108 }
109 
110 static int
compare_l64(ARGS_COMPARE)111 compare_l64(ARGS_COMPARE) {
112 	isc_region_t region1;
113 	isc_region_t region2;
114 
115 	REQUIRE(rdata1->type == rdata2->type);
116 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
117 	REQUIRE(rdata1->type == dns_rdatatype_l64);
118 	REQUIRE(rdata1->length == 10);
119 	REQUIRE(rdata2->length == 10);
120 
121 	dns_rdata_toregion(rdata1, &region1);
122 	dns_rdata_toregion(rdata2, &region2);
123 	return (isc_region_compare(&region1, &region2));
124 }
125 
126 static isc_result_t
fromstruct_l64(ARGS_FROMSTRUCT)127 fromstruct_l64(ARGS_FROMSTRUCT) {
128 	dns_rdata_l64_t *l64 = source;
129 
130 	REQUIRE(type == dns_rdatatype_l64);
131 	REQUIRE(l64 != NULL);
132 	REQUIRE(l64->common.rdtype == type);
133 	REQUIRE(l64->common.rdclass == rdclass);
134 
135 	UNUSED(type);
136 	UNUSED(rdclass);
137 
138 	RETERR(uint16_tobuffer(l64->pref, target));
139 	return (mem_tobuffer(target, l64->l64, sizeof(l64->l64)));
140 }
141 
142 static isc_result_t
tostruct_l64(ARGS_TOSTRUCT)143 tostruct_l64(ARGS_TOSTRUCT) {
144 	isc_region_t region;
145 	dns_rdata_l64_t *l64 = target;
146 
147 	REQUIRE(rdata->type == dns_rdatatype_l64);
148 	REQUIRE(l64 != NULL);
149 	REQUIRE(rdata->length == 10);
150 
151 	UNUSED(mctx);
152 
153 	l64->common.rdclass = rdata->rdclass;
154 	l64->common.rdtype = rdata->type;
155 	ISC_LINK_INIT(&l64->common, link);
156 
157 	dns_rdata_toregion(rdata, &region);
158 	l64->pref = uint16_fromregion(&region);
159 	memmove(l64->l64, region.base, region.length);
160 	return (ISC_R_SUCCESS);
161 }
162 
163 static void
freestruct_l64(ARGS_FREESTRUCT)164 freestruct_l64(ARGS_FREESTRUCT) {
165 	dns_rdata_l64_t *l64 = source;
166 
167 	REQUIRE(l64 != NULL);
168 	REQUIRE(l64->common.rdtype == dns_rdatatype_l64);
169 
170 	return;
171 }
172 
173 static isc_result_t
additionaldata_l64(ARGS_ADDLDATA)174 additionaldata_l64(ARGS_ADDLDATA) {
175 	REQUIRE(rdata->type == dns_rdatatype_l64);
176 	REQUIRE(rdata->length == 10);
177 
178 	UNUSED(rdata);
179 	UNUSED(add);
180 	UNUSED(arg);
181 
182 	return (ISC_R_SUCCESS);
183 }
184 
185 static isc_result_t
digest_l64(ARGS_DIGEST)186 digest_l64(ARGS_DIGEST) {
187 	isc_region_t r;
188 
189 	REQUIRE(rdata->type == dns_rdatatype_l64);
190 	REQUIRE(rdata->length == 10);
191 
192 	dns_rdata_toregion(rdata, &r);
193 
194 	return ((digest)(arg, &r));
195 }
196 
197 static bool
checkowner_l64(ARGS_CHECKOWNER)198 checkowner_l64(ARGS_CHECKOWNER) {
199 	REQUIRE(type == dns_rdatatype_l64);
200 
201 	UNUSED(name);
202 	UNUSED(type);
203 	UNUSED(rdclass);
204 	UNUSED(wildcard);
205 
206 	return (true);
207 }
208 
209 static bool
checknames_l64(ARGS_CHECKNAMES)210 checknames_l64(ARGS_CHECKNAMES) {
211 	REQUIRE(rdata->type == dns_rdatatype_l64);
212 	REQUIRE(rdata->length == 10);
213 
214 	UNUSED(rdata);
215 	UNUSED(owner);
216 	UNUSED(bad);
217 
218 	return (true);
219 }
220 
221 static int
casecompare_l64(ARGS_COMPARE)222 casecompare_l64(ARGS_COMPARE) {
223 	return (compare_l64(rdata1, rdata2));
224 }
225 
226 #endif /* RDATA_GENERIC_L64_106_C */
227