Annotation of src/external/mpl/bind/dist/lib/dns/rdata/generic/afsdb_18.c, Revision 1.1.1.6
1.1 christos 1: /* $NetBSD$ */
2:
3: /*
4: * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5: *
1.1.1.6 ! christos 6: * SPDX-License-Identifier: MPL-2.0
! 7: *
1.1 christos 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
1.1.1.5 christos 10: * file, you can obtain one at https://mozilla.org/MPL/2.0/.
1.1 christos 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_AFSDB_18_C
19: #define RDATA_GENERIC_AFSDB_18_C
20:
21: #define RRTYPE_AFSDB_ATTRIBUTES (0)
22:
1.1.1.6 ! christos 23: static isc_result_t
1.1 christos 24: fromtext_afsdb(ARGS_FROMTEXT) {
25: isc_token_t token;
26: isc_buffer_t buffer;
27: dns_name_t name;
1.1.1.2 christos 28: bool ok;
1.1 christos 29:
30: REQUIRE(type == dns_rdatatype_afsdb);
31:
32: UNUSED(type);
33: UNUSED(rdclass);
34: UNUSED(callbacks);
35:
36: /*
37: * Subtype.
38: */
39: RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
1.1.1.2 christos 40: false));
1.1.1.4 christos 41: if (token.value.as_ulong > 0xffffU) {
1.1 christos 42: RETTOK(ISC_R_RANGE);
1.1.1.4 christos 43: }
1.1 christos 44: RETERR(uint16_tobuffer(token.value.as_ulong, target));
45:
46: /*
47: * Hostname.
48: */
49: RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
1.1.1.2 christos 50: false));
1.1 christos 51: dns_name_init(&name, NULL);
52: buffer_fromregion(&buffer, &token.value.as_region);
1.1.1.4 christos 53: if (origin == NULL) {
1.1 christos 54: origin = dns_rootname;
1.1.1.4 christos 55: }
1.1 christos 56: RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
1.1.1.2 christos 57: ok = true;
1.1.1.4 christos 58: if ((options & DNS_RDATA_CHECKNAMES) != 0) {
1.1.1.2 christos 59: ok = dns_name_ishostname(&name, false);
1.1.1.4 christos 60: }
61: if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) {
1.1 christos 62: RETTOK(DNS_R_BADNAME);
1.1.1.4 christos 63: }
64: if (!ok && callbacks != NULL) {
1.1 christos 65: warn_badname(&name, lexer, callbacks);
1.1.1.4 christos 66: }
1.1 christos 67: return (ISC_R_SUCCESS);
68: }
69:
1.1.1.6 ! christos 70: static isc_result_t
1.1 christos 71: totext_afsdb(ARGS_TOTEXT) {
72: dns_name_t name;
73: dns_name_t prefix;
74: isc_region_t region;
75: char buf[sizeof("64000 ")];
1.1.1.2 christos 76: bool sub;
1.1 christos 77: unsigned int num;
78:
79: REQUIRE(rdata->type == dns_rdatatype_afsdb);
80: REQUIRE(rdata->length != 0);
81:
82: dns_name_init(&name, NULL);
83: dns_name_init(&prefix, NULL);
84:
85: dns_rdata_toregion(rdata, ®ion);
86: num = uint16_fromregion(®ion);
87: isc_region_consume(®ion, 2);
88: snprintf(buf, sizeof(buf), "%u ", num);
89: RETERR(str_totext(buf, target));
90: dns_name_fromregion(&name, ®ion);
91: sub = name_prefix(&name, tctx->origin, &prefix);
92: return (dns_name_totext(&prefix, sub, target));
93: }
94:
1.1.1.6 ! christos 95: static isc_result_t
1.1 christos 96: fromwire_afsdb(ARGS_FROMWIRE) {
97: dns_name_t name;
98: isc_region_t sr;
99: isc_region_t tr;
100:
101: REQUIRE(type == dns_rdatatype_afsdb);
102:
103: UNUSED(type);
104: UNUSED(rdclass);
105:
106: dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
107:
108: dns_name_init(&name, NULL);
109:
110: isc_buffer_activeregion(source, &sr);
111: isc_buffer_availableregion(target, &tr);
1.1.1.4 christos 112: if (tr.length < 2) {
1.1 christos 113: return (ISC_R_NOSPACE);
1.1.1.4 christos 114: }
115: if (sr.length < 2) {
1.1 christos 116: return (ISC_R_UNEXPECTEDEND);
1.1.1.4 christos 117: }
1.1 christos 118: memmove(tr.base, sr.base, 2);
119: isc_buffer_forward(source, 2);
120: isc_buffer_add(target, 2);
121: return (dns_name_fromwire(&name, source, dctx, options, target));
122: }
123:
1.1.1.6 ! christos 124: static isc_result_t
1.1 christos 125: towire_afsdb(ARGS_TOWIRE) {
126: isc_region_t tr;
127: isc_region_t sr;
128: dns_name_t name;
129: dns_offsets_t offsets;
130:
131: REQUIRE(rdata->type == dns_rdatatype_afsdb);
132: REQUIRE(rdata->length != 0);
133:
134: dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
135: isc_buffer_availableregion(target, &tr);
136: dns_rdata_toregion(rdata, &sr);
1.1.1.4 christos 137: if (tr.length < 2) {
1.1 christos 138: return (ISC_R_NOSPACE);
1.1.1.4 christos 139: }
1.1 christos 140: memmove(tr.base, sr.base, 2);
141: isc_region_consume(&sr, 2);
142: isc_buffer_add(target, 2);
143:
144: dns_name_init(&name, offsets);
145: dns_name_fromregion(&name, &sr);
146:
147: return (dns_name_towire(&name, cctx, target));
148: }
149:
1.1.1.6 ! christos 150: static int
1.1 christos 151: compare_afsdb(ARGS_COMPARE) {
152: int result;
153: dns_name_t name1;
154: dns_name_t name2;
155: isc_region_t region1;
156: isc_region_t region2;
157:
158: REQUIRE(rdata1->type == rdata2->type);
159: REQUIRE(rdata1->rdclass == rdata2->rdclass);
160: REQUIRE(rdata1->type == dns_rdatatype_afsdb);
161: REQUIRE(rdata1->length != 0);
162: REQUIRE(rdata2->length != 0);
163:
164: result = memcmp(rdata1->data, rdata2->data, 2);
1.1.1.4 christos 165: if (result != 0) {
1.1 christos 166: return (result < 0 ? -1 : 1);
1.1.1.4 christos 167: }
1.1 christos 168:
169: dns_name_init(&name1, NULL);
170: dns_name_init(&name2, NULL);
171:
172: dns_rdata_toregion(rdata1, ®ion1);
173: dns_rdata_toregion(rdata2, ®ion2);
174:
175: isc_region_consume(®ion1, 2);
176: isc_region_consume(®ion2, 2);
177:
178: dns_name_fromregion(&name1, ®ion1);
179: dns_name_fromregion(&name2, ®ion2);
180:
181: return (dns_name_rdatacompare(&name1, &name2));
182: }
183:
1.1.1.6 ! christos 184: static isc_result_t
1.1 christos 185: fromstruct_afsdb(ARGS_FROMSTRUCT) {
186: dns_rdata_afsdb_t *afsdb = source;
187: isc_region_t region;
188:
189: REQUIRE(type == dns_rdatatype_afsdb);
1.1.1.3 christos 190: REQUIRE(afsdb != NULL);
1.1 christos 191: REQUIRE(afsdb->common.rdclass == rdclass);
192: REQUIRE(afsdb->common.rdtype == type);
193:
194: UNUSED(type);
195: UNUSED(rdclass);
196:
197: RETERR(uint16_tobuffer(afsdb->subtype, target));
198: dns_name_toregion(&afsdb->server, ®ion);
199: return (isc_buffer_copyregion(target, ®ion));
200: }
201:
1.1.1.6 ! christos 202: static isc_result_t
1.1 christos 203: tostruct_afsdb(ARGS_TOSTRUCT) {
204: isc_region_t region;
205: dns_rdata_afsdb_t *afsdb = target;
206: dns_name_t name;
207:
208: REQUIRE(rdata->type == dns_rdatatype_afsdb);
1.1.1.3 christos 209: REQUIRE(afsdb != NULL);
1.1 christos 210: REQUIRE(rdata->length != 0);
211:
212: afsdb->common.rdclass = rdata->rdclass;
213: afsdb->common.rdtype = rdata->type;
214: ISC_LINK_INIT(&afsdb->common, link);
215:
216: dns_name_init(&afsdb->server, NULL);
217:
218: dns_rdata_toregion(rdata, ®ion);
219:
220: afsdb->subtype = uint16_fromregion(®ion);
221: isc_region_consume(®ion, 2);
222:
223: dns_name_init(&name, NULL);
224: dns_name_fromregion(&name, ®ion);
225:
226: RETERR(name_duporclone(&name, mctx, &afsdb->server));
227: afsdb->mctx = mctx;
228: return (ISC_R_SUCCESS);
229: }
230:
1.1.1.6 ! christos 231: static void
1.1 christos 232: freestruct_afsdb(ARGS_FREESTRUCT) {
233: dns_rdata_afsdb_t *afsdb = source;
234:
1.1.1.3 christos 235: REQUIRE(afsdb != NULL);
1.1 christos 236: REQUIRE(afsdb->common.rdtype == dns_rdatatype_afsdb);
237:
1.1.1.4 christos 238: if (afsdb->mctx == NULL) {
1.1 christos 239: return;
1.1.1.4 christos 240: }
1.1 christos 241:
242: dns_name_free(&afsdb->server, afsdb->mctx);
243: afsdb->mctx = NULL;
244: }
245:
1.1.1.6 ! christos 246: static isc_result_t
1.1 christos 247: additionaldata_afsdb(ARGS_ADDLDATA) {
248: dns_name_t name;
249: dns_offsets_t offsets;
250: isc_region_t region;
251:
252: REQUIRE(rdata->type == dns_rdatatype_afsdb);
253:
254: dns_name_init(&name, offsets);
255: dns_rdata_toregion(rdata, ®ion);
256: isc_region_consume(®ion, 2);
257: dns_name_fromregion(&name, ®ion);
258:
259: return ((add)(arg, &name, dns_rdatatype_a));
260: }
261:
1.1.1.6 ! christos 262: static isc_result_t
1.1 christos 263: digest_afsdb(ARGS_DIGEST) {
264: isc_region_t r1, r2;
265: dns_name_t name;
266:
267: REQUIRE(rdata->type == dns_rdatatype_afsdb);
268:
269: dns_rdata_toregion(rdata, &r1);
270: r2 = r1;
271: isc_region_consume(&r2, 2);
272: r1.length = 2;
273: RETERR((digest)(arg, &r1));
274: dns_name_init(&name, NULL);
275: dns_name_fromregion(&name, &r2);
276:
277: return (dns_name_digest(&name, digest, arg));
278: }
279:
1.1.1.6 ! christos 280: static bool
1.1 christos 281: checkowner_afsdb(ARGS_CHECKOWNER) {
282: REQUIRE(type == dns_rdatatype_afsdb);
283:
284: UNUSED(name);
285: UNUSED(type);
286: UNUSED(rdclass);
287: UNUSED(wildcard);
288:
1.1.1.2 christos 289: return (true);
1.1 christos 290: }
291:
1.1.1.6 ! christos 292: static bool
1.1 christos 293: checknames_afsdb(ARGS_CHECKNAMES) {
294: isc_region_t region;
295: dns_name_t name;
296:
297: REQUIRE(rdata->type == dns_rdatatype_afsdb);
298:
299: UNUSED(owner);
300:
301: dns_rdata_toregion(rdata, ®ion);
302: isc_region_consume(®ion, 2);
303: dns_name_init(&name, NULL);
304: dns_name_fromregion(&name, ®ion);
1.1.1.2 christos 305: if (!dns_name_ishostname(&name, false)) {
1.1.1.4 christos 306: if (bad != NULL) {
1.1 christos 307: dns_name_clone(&name, bad);
1.1.1.4 christos 308: }
1.1.1.2 christos 309: return (false);
1.1 christos 310: }
1.1.1.2 christos 311: return (true);
1.1 christos 312: }
313:
1.1.1.6 ! christos 314: static int
1.1 christos 315: casecompare_afsdb(ARGS_COMPARE) {
316: return (compare_afsdb(rdata1, rdata2));
317: }
1.1.1.4 christos 318: #endif /* RDATA_GENERIC_AFSDB_18_C */
CVSweb <webmaster@jp.NetBSD.org>