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