2 * Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
19 #ifndef RDATA_GENERIC_CSYNC_62_C
20 #define RDATA_GENERIC_CSYNC_62_C
22 #define RRTYPE_CSYNC_ATTRIBUTES 0
24 static inline isc_result_t
25 fromtext_csync(ARGS_FROMTEXT) {
28 REQUIRE(type == dns_rdatatype_csync);
37 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
39 RETERR(uint32_tobuffer(token.value.as_ulong, target));
42 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
44 if (token.value.as_ulong > 0xffffU)
46 RETERR(uint16_tobuffer(token.value.as_ulong, target));
49 return (typemap_fromtext(lexer, target, ISC_TRUE));
52 static inline isc_result_t
53 totext_csync(ARGS_TOTEXT) {
55 char buf[sizeof("0123456789")]; /* Also TYPE65535 */
58 REQUIRE(rdata->type == dns_rdatatype_csync);
59 REQUIRE(rdata->length >= 6);
63 dns_rdata_toregion(rdata, &sr);
65 num = uint32_fromregion(&sr);
66 isc_region_consume(&sr, 4);
67 sprintf(buf, "%lu", num);
68 RETERR(str_totext(buf, target));
70 RETERR(str_totext(" ", target));
72 num = uint16_fromregion(&sr);
73 isc_region_consume(&sr, 2);
74 sprintf(buf, "%lu", num);
75 RETERR(str_totext(buf, target));
77 return (typemap_totext(&sr, NULL, target));
80 static /* inline */ isc_result_t
81 fromwire_csync(ARGS_FROMWIRE) {
84 REQUIRE(type == dns_rdatatype_csync);
94 isc_buffer_activeregion(source, &sr);
96 return (ISC_R_UNEXPECTEDEND);
98 RETERR(mem_tobuffer(target, sr.base, 6));
99 isc_buffer_forward(source, 6);
100 isc_region_consume(&sr, 6);
102 RETERR(typemap_test(&sr, ISC_TRUE));
104 RETERR(mem_tobuffer(target, sr.base, sr.length));
105 isc_buffer_forward(source, sr.length);
106 return (ISC_R_SUCCESS);
109 static inline isc_result_t
110 towire_csync(ARGS_TOWIRE) {
112 REQUIRE(rdata->type == dns_rdatatype_csync);
113 REQUIRE(rdata->length >= 6);
117 return (mem_tobuffer(target, rdata->data, rdata->length));
121 compare_csync(ARGS_COMPARE) {
125 REQUIRE(rdata1->type == rdata2->type);
126 REQUIRE(rdata1->rdclass == rdata2->rdclass);
127 REQUIRE(rdata1->type == dns_rdatatype_csync);
128 REQUIRE(rdata1->length >= 6);
129 REQUIRE(rdata2->length >= 6);
131 dns_rdata_toregion(rdata1, &r1);
132 dns_rdata_toregion(rdata2, &r2);
133 return (isc_region_compare(&r1, &r2));
136 static inline isc_result_t
137 fromstruct_csync(ARGS_FROMSTRUCT) {
138 dns_rdata_csync_t *csync = source;
141 REQUIRE(type == dns_rdatatype_csync);
142 REQUIRE(source != NULL);
143 REQUIRE(csync->common.rdtype == type);
144 REQUIRE(csync->common.rdclass == rdclass);
145 REQUIRE(csync->typebits != NULL || csync->len == 0);
150 RETERR(uint32_tobuffer(csync->serial, target));
151 RETERR(uint16_tobuffer(csync->flags, target));
153 region.base = csync->typebits;
154 region.length = csync->len;
155 RETERR(typemap_test(®ion, ISC_TRUE));
156 return (mem_tobuffer(target, csync->typebits, csync->len));
159 static inline isc_result_t
160 tostruct_csync(ARGS_TOSTRUCT) {
162 dns_rdata_csync_t *csync = target;
164 REQUIRE(rdata->type == dns_rdatatype_csync);
165 REQUIRE(target != NULL);
166 REQUIRE(rdata->length != 0);
168 csync->common.rdclass = rdata->rdclass;
169 csync->common.rdtype = rdata->type;
170 ISC_LINK_INIT(&csync->common, link);
172 dns_rdata_toregion(rdata, ®ion);
174 csync->serial = uint32_fromregion(®ion);
175 isc_region_consume(®ion, 4);
177 csync->flags = uint16_fromregion(®ion);
178 isc_region_consume(®ion, 2);
180 csync->len = region.length;
181 csync->typebits = mem_maybedup(mctx, region.base, region.length);
182 if (csync->typebits == NULL)
186 return (ISC_R_SUCCESS);
189 return (ISC_R_NOMEMORY);
193 freestruct_csync(ARGS_FREESTRUCT) {
194 dns_rdata_csync_t *csync = source;
196 REQUIRE(source != NULL);
197 REQUIRE(csync->common.rdtype == dns_rdatatype_csync);
199 if (csync->mctx == NULL)
202 if (csync->typebits != NULL)
203 isc_mem_free(csync->mctx, csync->typebits);
207 static inline isc_result_t
208 additionaldata_csync(ARGS_ADDLDATA) {
209 REQUIRE(rdata->type == dns_rdatatype_csync);
215 return (ISC_R_SUCCESS);
218 static inline isc_result_t
219 digest_csync(ARGS_DIGEST) {
222 REQUIRE(rdata->type == dns_rdatatype_csync);
224 dns_rdata_toregion(rdata, &r);
225 return ((digest)(arg, &r));
228 static inline isc_boolean_t
229 checkowner_csync(ARGS_CHECKOWNER) {
231 REQUIRE(type == dns_rdatatype_csync);
241 static inline isc_boolean_t
242 checknames_csync(ARGS_CHECKNAMES) {
244 REQUIRE(rdata->type == dns_rdatatype_csync);
254 casecompare_csync(ARGS_COMPARE) {
255 isc_region_t region1;
256 isc_region_t region2;
258 REQUIRE(rdata1->type == rdata2->type);
259 REQUIRE(rdata1->rdclass == rdata2->rdclass);
260 REQUIRE(rdata1->type == dns_rdatatype_csync);
261 REQUIRE(rdata1->length >= 6);
262 REQUIRE(rdata2->length >= 6);
264 dns_rdata_toregion(rdata1, ®ion1);
265 dns_rdata_toregion(rdata2, ®ion2);
266 return (isc_region_compare(®ion1, ®ion2));
268 #endif /* RDATA_GENERIC_CSYNC_62_C */