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