Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / lib / dns / rdata / generic / rt_21.c
blob9a5248ea9eabf159e59ef4ca404d720255acb128
1 /* $NetBSD: rt_21.c,v 1.5 2014/12/10 04:37:59 christos Exp $ */
3 /*
4 * Copyright (C) 2004, 2005, 2007, 2009, 2014 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1999-2001, 2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: rt_21.c,v 1.48 2009/12/04 22:06:37 tbox Exp */
22 /* reviewed: Thu Mar 16 15:02:31 PST 2000 by brister */
24 /* RFC1183 */
26 #ifndef RDATA_GENERIC_RT_21_C
27 #define RDATA_GENERIC_RT_21_C
29 #define RRTYPE_RT_ATTRIBUTES (0)
31 static inline isc_result_t
32 fromtext_rt(ARGS_FROMTEXT) {
33 isc_token_t token;
34 dns_name_t name;
35 isc_buffer_t buffer;
36 isc_boolean_t ok;
38 REQUIRE(type == 21);
40 UNUSED(type);
41 UNUSED(rdclass);
42 UNUSED(callbacks);
44 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
45 ISC_FALSE));
46 if (token.value.as_ulong > 0xffffU)
47 RETTOK(ISC_R_RANGE);
48 RETERR(uint16_tobuffer(token.value.as_ulong, target));
50 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
51 ISC_FALSE));
53 dns_name_init(&name, NULL);
54 buffer_fromregion(&buffer, &token.value.as_region);
55 origin = (origin != NULL) ? origin : dns_rootname;
56 RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
57 ok = ISC_TRUE;
58 if ((options & DNS_RDATA_CHECKNAMES) != 0)
59 ok = dns_name_ishostname(&name, ISC_FALSE);
60 if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
61 RETTOK(DNS_R_BADNAME);
62 if (!ok && callbacks != NULL)
63 warn_badname(&name, lexer, callbacks);
64 return (ISC_R_SUCCESS);
67 static inline isc_result_t
68 totext_rt(ARGS_TOTEXT) {
69 isc_region_t region;
70 dns_name_t name;
71 dns_name_t prefix;
72 isc_boolean_t sub;
73 char buf[sizeof("64000")];
74 unsigned short num;
76 REQUIRE(rdata->type == 21);
77 REQUIRE(rdata->length != 0);
79 dns_name_init(&name, NULL);
80 dns_name_init(&prefix, NULL);
82 dns_rdata_toregion(rdata, &region);
83 num = uint16_fromregion(&region);
84 isc_region_consume(&region, 2);
85 sprintf(buf, "%u", num);
86 RETERR(str_totext(buf, target));
87 RETERR(str_totext(" ", target));
88 dns_name_fromregion(&name, &region);
89 sub = name_prefix(&name, tctx->origin, &prefix);
90 return (dns_name_totext(&prefix, sub, target));
93 static inline isc_result_t
94 fromwire_rt(ARGS_FROMWIRE) {
95 dns_name_t name;
96 isc_region_t sregion;
97 isc_region_t tregion;
99 REQUIRE(type == 21);
101 UNUSED(type);
102 UNUSED(rdclass);
104 dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
106 dns_name_init(&name, NULL);
108 isc_buffer_activeregion(source, &sregion);
109 isc_buffer_availableregion(target, &tregion);
110 if (tregion.length < 2)
111 return (ISC_R_NOSPACE);
112 if (sregion.length < 2)
113 return (ISC_R_UNEXPECTEDEND);
114 memmove(tregion.base, sregion.base, 2);
115 isc_buffer_forward(source, 2);
116 isc_buffer_add(target, 2);
117 return (dns_name_fromwire(&name, source, dctx, options, target));
120 static inline isc_result_t
121 towire_rt(ARGS_TOWIRE) {
122 dns_name_t name;
123 dns_offsets_t offsets;
124 isc_region_t region;
125 isc_region_t tr;
127 REQUIRE(rdata->type == 21);
128 REQUIRE(rdata->length != 0);
130 dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
131 isc_buffer_availableregion(target, &tr);
132 dns_rdata_toregion(rdata, &region);
133 if (tr.length < 2)
134 return (ISC_R_NOSPACE);
135 memmove(tr.base, region.base, 2);
136 isc_region_consume(&region, 2);
137 isc_buffer_add(target, 2);
139 dns_name_init(&name, offsets);
140 dns_name_fromregion(&name, &region);
142 return (dns_name_towire(&name, cctx, target));
145 static inline int
146 compare_rt(ARGS_COMPARE) {
147 dns_name_t name1;
148 dns_name_t name2;
149 isc_region_t region1;
150 isc_region_t region2;
151 int order;
153 REQUIRE(rdata1->type == rdata2->type);
154 REQUIRE(rdata1->rdclass == rdata2->rdclass);
155 REQUIRE(rdata1->type == 21);
156 REQUIRE(rdata1->length != 0);
157 REQUIRE(rdata2->length != 0);
159 order = memcmp(rdata1->data, rdata2->data, 2);
160 if (order != 0)
161 return (order < 0 ? -1 : 1);
163 dns_name_init(&name1, NULL);
164 dns_name_init(&name2, NULL);
166 dns_rdata_toregion(rdata1, &region1);
167 dns_rdata_toregion(rdata2, &region2);
169 isc_region_consume(&region1, 2);
170 isc_region_consume(&region2, 2);
172 dns_name_fromregion(&name1, &region1);
173 dns_name_fromregion(&name2, &region2);
175 return (dns_name_rdatacompare(&name1, &name2));
178 static inline isc_result_t
179 fromstruct_rt(ARGS_FROMSTRUCT) {
180 dns_rdata_rt_t *rt = source;
181 isc_region_t region;
183 REQUIRE(type == 21);
184 REQUIRE(source != NULL);
185 REQUIRE(rt->common.rdtype == type);
186 REQUIRE(rt->common.rdclass == rdclass);
188 UNUSED(type);
189 UNUSED(rdclass);
191 RETERR(uint16_tobuffer(rt->preference, target));
192 dns_name_toregion(&rt->host, &region);
193 return (isc_buffer_copyregion(target, &region));
196 static inline isc_result_t
197 tostruct_rt(ARGS_TOSTRUCT) {
198 isc_region_t region;
199 dns_rdata_rt_t *rt = target;
200 dns_name_t name;
202 REQUIRE(rdata->type == 21);
203 REQUIRE(target != NULL);
204 REQUIRE(rdata->length != 0);
206 rt->common.rdclass = rdata->rdclass;
207 rt->common.rdtype = rdata->type;
208 ISC_LINK_INIT(&rt->common, link);
210 dns_name_init(&name, NULL);
211 dns_rdata_toregion(rdata, &region);
212 rt->preference = uint16_fromregion(&region);
213 isc_region_consume(&region, 2);
214 dns_name_fromregion(&name, &region);
215 dns_name_init(&rt->host, NULL);
216 RETERR(name_duporclone(&name, mctx, &rt->host));
218 rt->mctx = mctx;
219 return (ISC_R_SUCCESS);
222 static inline void
223 freestruct_rt(ARGS_FREESTRUCT) {
224 dns_rdata_rt_t *rt = source;
226 REQUIRE(source != NULL);
227 REQUIRE(rt->common.rdtype == 21);
229 if (rt->mctx == NULL)
230 return;
232 dns_name_free(&rt->host, rt->mctx);
233 rt->mctx = NULL;
236 static inline isc_result_t
237 additionaldata_rt(ARGS_ADDLDATA) {
238 dns_name_t name;
239 dns_offsets_t offsets;
240 isc_region_t region;
241 isc_result_t result;
243 REQUIRE(rdata->type == 21);
245 dns_name_init(&name, offsets);
246 dns_rdata_toregion(rdata, &region);
247 isc_region_consume(&region, 2);
248 dns_name_fromregion(&name, &region);
250 result = (add)(arg, &name, dns_rdatatype_x25);
251 if (result != ISC_R_SUCCESS)
252 return (result);
253 result = (add)(arg, &name, dns_rdatatype_isdn);
254 if (result != ISC_R_SUCCESS)
255 return (result);
256 return ((add)(arg, &name, dns_rdatatype_a));
259 static inline isc_result_t
260 digest_rt(ARGS_DIGEST) {
261 isc_region_t r1, r2;
262 isc_result_t result;
263 dns_name_t name;
265 REQUIRE(rdata->type == 21);
267 dns_rdata_toregion(rdata, &r1);
268 r2 = r1;
269 isc_region_consume(&r2, 2);
270 r1.length = 2;
271 result = (digest)(arg, &r1);
272 if (result != ISC_R_SUCCESS)
273 return (result);
274 dns_name_init(&name, NULL);
275 dns_name_fromregion(&name, &r2);
276 return (dns_name_digest(&name, digest, arg));
279 static inline isc_boolean_t
280 checkowner_rt(ARGS_CHECKOWNER) {
282 REQUIRE(type == 21);
284 UNUSED(name);
285 UNUSED(type);
286 UNUSED(rdclass);
287 UNUSED(wildcard);
289 return (ISC_TRUE);
292 static inline isc_boolean_t
293 checknames_rt(ARGS_CHECKNAMES) {
294 isc_region_t region;
295 dns_name_t name;
297 REQUIRE(rdata->type == 21);
299 UNUSED(owner);
301 dns_rdata_toregion(rdata, &region);
302 isc_region_consume(&region, 2);
303 dns_name_init(&name, NULL);
304 dns_name_fromregion(&name, &region);
305 if (!dns_name_ishostname(&name, ISC_FALSE)) {
306 if (bad != NULL)
307 dns_name_clone(&name, bad);
308 return (ISC_FALSE);
310 return (ISC_TRUE);
313 static inline int
314 casecompare_rt(ARGS_COMPARE) {
315 return (compare_rt(rdata1, rdata2));
318 #endif /* RDATA_GENERIC_RT_21_C */