Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / bind / dist / lib / dns / rdata / generic / opt_41.c
blob536a33d99bda3bfcd4abecdad42af8705bf8e384
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 1998-2002 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: opt_41.c,v 1.35 2009/12/04 22:06:37 tbox Exp */
22 /* Reviewed: Thu Mar 16 14:06:44 PST 2000 by gson */
24 /* RFC2671 */
26 #ifndef RDATA_GENERIC_OPT_41_C
27 #define RDATA_GENERIC_OPT_41_C
29 #define RRTYPE_OPT_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON | \
30 DNS_RDATATYPEATTR_META | \
31 DNS_RDATATYPEATTR_NOTQUESTION)
33 static inline isc_result_t
34 fromtext_opt(ARGS_FROMTEXT) {
36 * OPT records do not have a text format.
39 REQUIRE(type == 41);
41 UNUSED(type);
42 UNUSED(rdclass);
43 UNUSED(lexer);
44 UNUSED(origin);
45 UNUSED(options);
46 UNUSED(target);
47 UNUSED(callbacks);
49 return (ISC_R_NOTIMPLEMENTED);
52 static inline isc_result_t
53 totext_opt(ARGS_TOTEXT) {
54 isc_region_t r;
55 isc_region_t or;
56 isc_uint16_t option;
57 isc_uint16_t length;
58 char buf[sizeof("64000 64000")];
61 * OPT records do not have a text format.
64 REQUIRE(rdata->type == 41);
66 dns_rdata_toregion(rdata, &r);
67 while (r.length > 0) {
68 option = uint16_fromregion(&r);
69 isc_region_consume(&r, 2);
70 length = uint16_fromregion(&r);
71 isc_region_consume(&r, 2);
72 sprintf(buf, "%u %u", option, length);
73 RETERR(str_totext(buf, target));
74 INSIST(r.length >= length);
75 if (length > 0) {
76 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
77 RETERR(str_totext(" (", target));
78 RETERR(str_totext(tctx->linebreak, target));
79 or = r;
80 or.length = length;
81 RETERR(isc_base64_totext(&or, tctx->width - 2,
82 tctx->linebreak, target));
83 isc_region_consume(&r, length);
84 if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0)
85 RETERR(str_totext(" )", target));
87 if (r.length > 0)
88 RETERR(str_totext(" ", target));
91 return (ISC_R_SUCCESS);
94 static inline isc_result_t
95 fromwire_opt(ARGS_FROMWIRE) {
96 isc_region_t sregion;
97 isc_region_t tregion;
98 isc_uint16_t length;
99 unsigned int total;
101 REQUIRE(type == 41);
103 UNUSED(type);
104 UNUSED(rdclass);
105 UNUSED(dctx);
106 UNUSED(options);
108 isc_buffer_activeregion(source, &sregion);
109 total = 0;
110 while (sregion.length != 0) {
111 if (sregion.length < 4)
112 return (ISC_R_UNEXPECTEDEND);
114 * Eat the 16bit option code. There is nothing to
115 * be done with it currently.
117 isc_region_consume(&sregion, 2);
118 length = uint16_fromregion(&sregion);
119 isc_region_consume(&sregion, 2);
120 total += 4;
121 if (sregion.length < length)
122 return (ISC_R_UNEXPECTEDEND);
123 isc_region_consume(&sregion, length);
124 total += length;
127 isc_buffer_activeregion(source, &sregion);
128 isc_buffer_availableregion(target, &tregion);
129 if (tregion.length < total)
130 return (ISC_R_NOSPACE);
131 memcpy(tregion.base, sregion.base, total);
132 isc_buffer_forward(source, total);
133 isc_buffer_add(target, total);
135 return (ISC_R_SUCCESS);
138 static inline isc_result_t
139 towire_opt(ARGS_TOWIRE) {
141 REQUIRE(rdata->type == 41);
143 UNUSED(cctx);
145 return (mem_tobuffer(target, rdata->data, rdata->length));
148 static inline int
149 compare_opt(ARGS_COMPARE) {
150 isc_region_t r1;
151 isc_region_t r2;
153 REQUIRE(rdata1->type == rdata2->type);
154 REQUIRE(rdata1->rdclass == rdata2->rdclass);
155 REQUIRE(rdata1->type == 41);
157 dns_rdata_toregion(rdata1, &r1);
158 dns_rdata_toregion(rdata2, &r2);
159 return (isc_region_compare(&r1, &r2));
162 static inline isc_result_t
163 fromstruct_opt(ARGS_FROMSTRUCT) {
164 dns_rdata_opt_t *opt = source;
165 isc_region_t region;
166 isc_uint16_t length;
168 REQUIRE(type == 41);
169 REQUIRE(source != NULL);
170 REQUIRE(opt->common.rdtype == type);
171 REQUIRE(opt->common.rdclass == rdclass);
172 REQUIRE(opt->options != NULL || opt->length == 0);
174 UNUSED(type);
175 UNUSED(rdclass);
177 region.base = opt->options;
178 region.length = opt->length;
179 while (region.length >= 4) {
180 isc_region_consume(&region, 2); /* opt */
181 length = uint16_fromregion(&region);
182 isc_region_consume(&region, 2);
183 if (region.length < length)
184 return (ISC_R_UNEXPECTEDEND);
185 isc_region_consume(&region, length);
187 if (region.length != 0)
188 return (ISC_R_UNEXPECTEDEND);
190 return (mem_tobuffer(target, opt->options, opt->length));
193 static inline isc_result_t
194 tostruct_opt(ARGS_TOSTRUCT) {
195 dns_rdata_opt_t *opt = target;
196 isc_region_t r;
198 REQUIRE(rdata->type == 41);
199 REQUIRE(target != NULL);
201 opt->common.rdclass = rdata->rdclass;
202 opt->common.rdtype = rdata->type;
203 ISC_LINK_INIT(&opt->common, link);
205 dns_rdata_toregion(rdata, &r);
206 opt->length = r.length;
207 opt->options = mem_maybedup(mctx, r.base, r.length);
208 if (opt->options == NULL)
209 return (ISC_R_NOMEMORY);
211 opt->offset = 0;
212 opt->mctx = mctx;
213 return (ISC_R_SUCCESS);
216 static inline void
217 freestruct_opt(ARGS_FREESTRUCT) {
218 dns_rdata_opt_t *opt = source;
220 REQUIRE(source != NULL);
221 REQUIRE(opt->common.rdtype == 41);
223 if (opt->mctx == NULL)
224 return;
226 if (opt->options != NULL)
227 isc_mem_free(opt->mctx, opt->options);
228 opt->mctx = NULL;
231 static inline isc_result_t
232 additionaldata_opt(ARGS_ADDLDATA) {
233 REQUIRE(rdata->type == 41);
235 UNUSED(rdata);
236 UNUSED(add);
237 UNUSED(arg);
239 return (ISC_R_SUCCESS);
242 static inline isc_result_t
243 digest_opt(ARGS_DIGEST) {
246 * OPT records are not digested.
249 REQUIRE(rdata->type == 41);
251 UNUSED(rdata);
252 UNUSED(digest);
253 UNUSED(arg);
255 return (ISC_R_NOTIMPLEMENTED);
258 static inline isc_boolean_t
259 checkowner_opt(ARGS_CHECKOWNER) {
261 REQUIRE(type == 41);
263 UNUSED(type);
264 UNUSED(rdclass);
265 UNUSED(wildcard);
267 return (dns_name_equal(name, dns_rootname));
270 static inline isc_boolean_t
271 checknames_opt(ARGS_CHECKNAMES) {
273 REQUIRE(rdata->type == 41);
275 UNUSED(rdata);
276 UNUSED(owner);
277 UNUSED(bad);
279 return (ISC_TRUE);
282 static inline int
283 casecompare_opt(ARGS_COMPARE) {
284 return (compare_opt(rdata1, rdata2));
287 #endif /* RDATA_GENERIC_OPT_41_C */