xref: /netbsd-src/external/mpl/dhcp/bind/dist/lib/dns/rdata/generic/x25_19.c (revision 4afad4b7fa6d4a0d3dedf41d1587a7250710ae54)
1 /*	$NetBSD: x25_19.c,v 1.1 2024/02/18 20:57:45 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 /* RFC1183 */
17 
18 #ifndef RDATA_GENERIC_X25_19_C
19 #define RDATA_GENERIC_X25_19_C
20 
21 #define RRTYPE_X25_ATTRIBUTES (0)
22 
23 static isc_result_t
fromtext_x25(ARGS_FROMTEXT)24 fromtext_x25(ARGS_FROMTEXT) {
25 	isc_token_t token;
26 	unsigned int i;
27 
28 	REQUIRE(type == dns_rdatatype_x25);
29 
30 	UNUSED(type);
31 	UNUSED(rdclass);
32 	UNUSED(origin);
33 	UNUSED(options);
34 	UNUSED(callbacks);
35 
36 	RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
37 				      false));
38 	if (token.value.as_textregion.length < 4) {
39 		RETTOK(DNS_R_SYNTAX);
40 	}
41 	for (i = 0; i < token.value.as_textregion.length; i++) {
42 		if (!isdigit((unsigned char)token.value.as_textregion.base[i]))
43 		{
44 			RETTOK(ISC_R_RANGE);
45 		}
46 	}
47 	RETTOK(txt_fromtext(&token.value.as_textregion, target));
48 	return (ISC_R_SUCCESS);
49 }
50 
51 static isc_result_t
totext_x25(ARGS_TOTEXT)52 totext_x25(ARGS_TOTEXT) {
53 	isc_region_t region;
54 
55 	UNUSED(tctx);
56 
57 	REQUIRE(rdata->type == dns_rdatatype_x25);
58 	REQUIRE(rdata->length != 0);
59 
60 	dns_rdata_toregion(rdata, &region);
61 	return (txt_totext(&region, true, target));
62 }
63 
64 static isc_result_t
fromwire_x25(ARGS_FROMWIRE)65 fromwire_x25(ARGS_FROMWIRE) {
66 	isc_region_t sr;
67 	unsigned int i;
68 
69 	REQUIRE(type == dns_rdatatype_x25);
70 
71 	UNUSED(type);
72 	UNUSED(dctx);
73 	UNUSED(rdclass);
74 	UNUSED(options);
75 
76 	isc_buffer_activeregion(source, &sr);
77 	if (sr.length < 5 || sr.base[0] != (sr.length - 1)) {
78 		return (DNS_R_FORMERR);
79 	}
80 	for (i = 1; i < sr.length; i++) {
81 		if (sr.base[i] < 0x30 || sr.base[i] > 0x39) {
82 			return (DNS_R_FORMERR);
83 		}
84 	}
85 	return (txt_fromwire(source, target));
86 }
87 
88 static isc_result_t
towire_x25(ARGS_TOWIRE)89 towire_x25(ARGS_TOWIRE) {
90 	UNUSED(cctx);
91 
92 	REQUIRE(rdata->type == dns_rdatatype_x25);
93 	REQUIRE(rdata->length != 0);
94 
95 	return (mem_tobuffer(target, rdata->data, rdata->length));
96 }
97 
98 static int
compare_x25(ARGS_COMPARE)99 compare_x25(ARGS_COMPARE) {
100 	isc_region_t r1;
101 	isc_region_t r2;
102 
103 	REQUIRE(rdata1->type == rdata2->type);
104 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
105 	REQUIRE(rdata1->type == dns_rdatatype_x25);
106 	REQUIRE(rdata1->length != 0);
107 	REQUIRE(rdata2->length != 0);
108 
109 	dns_rdata_toregion(rdata1, &r1);
110 	dns_rdata_toregion(rdata2, &r2);
111 	return (isc_region_compare(&r1, &r2));
112 }
113 
114 static isc_result_t
fromstruct_x25(ARGS_FROMSTRUCT)115 fromstruct_x25(ARGS_FROMSTRUCT) {
116 	dns_rdata_x25_t *x25 = source;
117 	uint8_t i;
118 
119 	REQUIRE(type == dns_rdatatype_x25);
120 	REQUIRE(x25 != NULL);
121 	REQUIRE(x25->common.rdtype == type);
122 	REQUIRE(x25->common.rdclass == rdclass);
123 	REQUIRE(x25->x25 != NULL && x25->x25_len != 0);
124 
125 	UNUSED(type);
126 	UNUSED(rdclass);
127 
128 	if (x25->x25_len < 4) {
129 		return (ISC_R_RANGE);
130 	}
131 
132 	for (i = 0; i < x25->x25_len; i++) {
133 		if (!isdigit((unsigned char)x25->x25[i])) {
134 			return (ISC_R_RANGE);
135 		}
136 	}
137 
138 	RETERR(uint8_tobuffer(x25->x25_len, target));
139 	return (mem_tobuffer(target, x25->x25, x25->x25_len));
140 }
141 
142 static isc_result_t
tostruct_x25(ARGS_TOSTRUCT)143 tostruct_x25(ARGS_TOSTRUCT) {
144 	dns_rdata_x25_t *x25 = target;
145 	isc_region_t r;
146 
147 	REQUIRE(rdata->type == dns_rdatatype_x25);
148 	REQUIRE(x25 != NULL);
149 	REQUIRE(rdata->length != 0);
150 
151 	x25->common.rdclass = rdata->rdclass;
152 	x25->common.rdtype = rdata->type;
153 	ISC_LINK_INIT(&x25->common, link);
154 
155 	dns_rdata_toregion(rdata, &r);
156 	x25->x25_len = uint8_fromregion(&r);
157 	isc_region_consume(&r, 1);
158 	x25->x25 = mem_maybedup(mctx, r.base, x25->x25_len);
159 	if (x25->x25 == NULL) {
160 		return (ISC_R_NOMEMORY);
161 	}
162 
163 	x25->mctx = mctx;
164 	return (ISC_R_SUCCESS);
165 }
166 
167 static void
freestruct_x25(ARGS_FREESTRUCT)168 freestruct_x25(ARGS_FREESTRUCT) {
169 	dns_rdata_x25_t *x25 = source;
170 
171 	REQUIRE(x25 != NULL);
172 	REQUIRE(x25->common.rdtype == dns_rdatatype_x25);
173 
174 	if (x25->mctx == NULL) {
175 		return;
176 	}
177 
178 	if (x25->x25 != NULL) {
179 		isc_mem_free(x25->mctx, x25->x25);
180 	}
181 	x25->mctx = NULL;
182 }
183 
184 static isc_result_t
additionaldata_x25(ARGS_ADDLDATA)185 additionaldata_x25(ARGS_ADDLDATA) {
186 	REQUIRE(rdata->type == dns_rdatatype_x25);
187 
188 	UNUSED(rdata);
189 	UNUSED(add);
190 	UNUSED(arg);
191 
192 	return (ISC_R_SUCCESS);
193 }
194 
195 static isc_result_t
digest_x25(ARGS_DIGEST)196 digest_x25(ARGS_DIGEST) {
197 	isc_region_t r;
198 
199 	REQUIRE(rdata->type == dns_rdatatype_x25);
200 
201 	dns_rdata_toregion(rdata, &r);
202 
203 	return ((digest)(arg, &r));
204 }
205 
206 static bool
checkowner_x25(ARGS_CHECKOWNER)207 checkowner_x25(ARGS_CHECKOWNER) {
208 	REQUIRE(type == dns_rdatatype_x25);
209 
210 	UNUSED(name);
211 	UNUSED(type);
212 	UNUSED(rdclass);
213 	UNUSED(wildcard);
214 
215 	return (true);
216 }
217 
218 static bool
checknames_x25(ARGS_CHECKNAMES)219 checknames_x25(ARGS_CHECKNAMES) {
220 	REQUIRE(rdata->type == dns_rdatatype_x25);
221 
222 	UNUSED(rdata);
223 	UNUSED(owner);
224 	UNUSED(bad);
225 
226 	return (true);
227 }
228 
229 static int
casecompare_x25(ARGS_COMPARE)230 casecompare_x25(ARGS_COMPARE) {
231 	return (compare_x25(rdata1, rdata2));
232 }
233 
234 #endif /* RDATA_GENERIC_X25_19_C */
235