1 /*
2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
7 *
8 * See the COPYRIGHT file distributed with this work for additional
9 * information regarding copyright ownership.
10 */
11
12 /* RFC1183 */
13
14 #ifndef RDATA_GENERIC_X25_19_C
15 #define RDATA_GENERIC_X25_19_C
16
17 #define RRTYPE_X25_ATTRIBUTES (0)
18
19 static inline isc_result_t
fromtext_x25(ARGS_FROMTEXT)20 fromtext_x25(ARGS_FROMTEXT) {
21 isc_token_t token;
22 unsigned int i;
23
24 REQUIRE(type == dns_rdatatype_x25);
25
26 UNUSED(type);
27 UNUSED(rdclass);
28 UNUSED(origin);
29 UNUSED(options);
30 UNUSED(callbacks);
31
32 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
33 false));
34 if (token.value.as_textregion.length < 4) {
35 RETTOK(DNS_R_SYNTAX);
36 }
37 for (i = 0; i < token.value.as_textregion.length; i++) {
38 if (!isdigit((unsigned char)token.value.as_textregion.base[i]))
39 {
40 RETTOK(ISC_R_RANGE);
41 }
42 }
43 RETTOK(txt_fromtext(&token.value.as_textregion, target));
44 return (ISC_R_SUCCESS);
45 }
46
47 static inline isc_result_t
totext_x25(ARGS_TOTEXT)48 totext_x25(ARGS_TOTEXT) {
49 isc_region_t region;
50
51 UNUSED(tctx);
52
53 REQUIRE(rdata->type == dns_rdatatype_x25);
54 REQUIRE(rdata->length != 0);
55
56 dns_rdata_toregion(rdata, ®ion);
57 return (txt_totext(®ion, true, target));
58 }
59
60 static inline isc_result_t
fromwire_x25(ARGS_FROMWIRE)61 fromwire_x25(ARGS_FROMWIRE) {
62 isc_region_t sr;
63 unsigned int i;
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 || sr.base[0] != (sr.length - 1)) {
74 return (DNS_R_FORMERR);
75 }
76 for (i = 1; i < sr.length; i++) {
77 if (sr.base[i] < 0x30 || sr.base[i] > 0x39) {
78 return (DNS_R_FORMERR);
79 }
80 }
81 return (txt_fromwire(source, target));
82 }
83
84 static inline isc_result_t
towire_x25(ARGS_TOWIRE)85 towire_x25(ARGS_TOWIRE) {
86 UNUSED(cctx);
87
88 REQUIRE(rdata->type == dns_rdatatype_x25);
89 REQUIRE(rdata->length != 0);
90
91 return (mem_tobuffer(target, rdata->data, rdata->length));
92 }
93
94 static inline int
compare_x25(ARGS_COMPARE)95 compare_x25(ARGS_COMPARE) {
96 isc_region_t r1;
97 isc_region_t r2;
98
99 REQUIRE(rdata1->type == rdata2->type);
100 REQUIRE(rdata1->rdclass == rdata2->rdclass);
101 REQUIRE(rdata1->type == dns_rdatatype_x25);
102 REQUIRE(rdata1->length != 0);
103 REQUIRE(rdata2->length != 0);
104
105 dns_rdata_toregion(rdata1, &r1);
106 dns_rdata_toregion(rdata2, &r2);
107 return (isc_region_compare(&r1, &r2));
108 }
109
110 static inline isc_result_t
fromstruct_x25(ARGS_FROMSTRUCT)111 fromstruct_x25(ARGS_FROMSTRUCT) {
112 dns_rdata_x25_t *x25 = source;
113 uint8_t i;
114
115 REQUIRE(type == dns_rdatatype_x25);
116 REQUIRE(x25 != NULL);
117 REQUIRE(x25->common.rdtype == type);
118 REQUIRE(x25->common.rdclass == rdclass);
119 REQUIRE(x25->x25 != NULL && x25->x25_len != 0);
120
121 UNUSED(type);
122 UNUSED(rdclass);
123
124 if (x25->x25_len < 4) {
125 return (ISC_R_RANGE);
126 }
127
128 for (i = 0; i < x25->x25_len; i++) {
129 if (!isdigit((unsigned char)x25->x25[i])) {
130 return (ISC_R_RANGE);
131 }
132 }
133
134 RETERR(uint8_tobuffer(x25->x25_len, target));
135 return (mem_tobuffer(target, x25->x25, x25->x25_len));
136 }
137
138 static inline isc_result_t
tostruct_x25(ARGS_TOSTRUCT)139 tostruct_x25(ARGS_TOSTRUCT) {
140 dns_rdata_x25_t *x25 = target;
141 isc_region_t r;
142
143 REQUIRE(rdata->type == dns_rdatatype_x25);
144 REQUIRE(x25 != NULL);
145 REQUIRE(rdata->length != 0);
146
147 x25->common.rdclass = rdata->rdclass;
148 x25->common.rdtype = rdata->type;
149 ISC_LINK_INIT(&x25->common, link);
150
151 dns_rdata_toregion(rdata, &r);
152 x25->x25_len = uint8_fromregion(&r);
153 isc_region_consume(&r, 1);
154 x25->x25 = mem_maybedup(mctx, r.base, x25->x25_len);
155 if (x25->x25 == NULL) {
156 return (ISC_R_NOMEMORY);
157 }
158
159 x25->mctx = mctx;
160 return (ISC_R_SUCCESS);
161 }
162
163 static inline void
freestruct_x25(ARGS_FREESTRUCT)164 freestruct_x25(ARGS_FREESTRUCT) {
165 dns_rdata_x25_t *x25 = source;
166
167 REQUIRE(x25 != NULL);
168 REQUIRE(x25->common.rdtype == dns_rdatatype_x25);
169
170 if (x25->mctx == NULL) {
171 return;
172 }
173
174 if (x25->x25 != NULL) {
175 isc_mem_free(x25->mctx, x25->x25);
176 }
177 x25->mctx = NULL;
178 }
179
180 static inline isc_result_t
additionaldata_x25(ARGS_ADDLDATA)181 additionaldata_x25(ARGS_ADDLDATA) {
182 REQUIRE(rdata->type == dns_rdatatype_x25);
183
184 UNUSED(rdata);
185 UNUSED(owner);
186 UNUSED(add);
187 UNUSED(arg);
188
189 return (ISC_R_SUCCESS);
190 }
191
192 static inline isc_result_t
digest_x25(ARGS_DIGEST)193 digest_x25(ARGS_DIGEST) {
194 isc_region_t r;
195
196 REQUIRE(rdata->type == dns_rdatatype_x25);
197
198 dns_rdata_toregion(rdata, &r);
199
200 return ((digest)(arg, &r));
201 }
202
203 static inline bool
checkowner_x25(ARGS_CHECKOWNER)204 checkowner_x25(ARGS_CHECKOWNER) {
205 REQUIRE(type == dns_rdatatype_x25);
206
207 UNUSED(name);
208 UNUSED(type);
209 UNUSED(rdclass);
210 UNUSED(wildcard);
211
212 return (true);
213 }
214
215 static inline bool
checknames_x25(ARGS_CHECKNAMES)216 checknames_x25(ARGS_CHECKNAMES) {
217 REQUIRE(rdata->type == dns_rdatatype_x25);
218
219 UNUSED(rdata);
220 UNUSED(owner);
221 UNUSED(bad);
222
223 return (true);
224 }
225
226 static inline int
casecompare_x25(ARGS_COMPARE)227 casecompare_x25(ARGS_COMPARE) {
228 return (compare_x25(rdata1, rdata2));
229 }
230
231 #endif /* RDATA_GENERIC_X25_19_C */
232