1 /*
2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3 *
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.
7 *
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.
15 */
16
17 /* RFC 7477 */
18
19 #ifndef RDATA_GENERIC_CSYNC_62_C
20 #define RDATA_GENERIC_CSYNC_62_C
21
22 static inline isc_result_t
totext_csync(ARGS_TOTEXT)23 totext_csync(ARGS_TOTEXT) {
24 unsigned long num;
25 char buf[sizeof("0123456789")]; /* Also TYPE65535 */
26 isc_region_t sr;
27
28 REQUIRE(rdata->type == dns_rdatatype_csync);
29 REQUIRE(rdata->length >= 6);
30
31 UNUSED(tctx);
32
33 dns_rdata_toregion(rdata, &sr);
34
35 num = uint32_fromregion(&sr);
36 isc_region_consume(&sr, 4);
37 snprintf(buf, sizeof(buf), "%lu", num);
38 RETERR(isc_str_tobuffer(buf, target));
39
40 RETERR(isc_str_tobuffer(" ", target));
41
42 num = uint16_fromregion(&sr);
43 isc_region_consume(&sr, 2);
44 snprintf(buf, sizeof(buf), "%lu", num);
45 RETERR(isc_str_tobuffer(buf, target));
46
47 /*
48 * Don't leave a trailing space when there's no typemap present.
49 */
50 if (sr.length > 0) {
51 RETERR(isc_str_tobuffer(" ", target));
52 }
53 return (typemap_totext(&sr, NULL, target));
54 }
55
56 static /* inline */ isc_result_t
fromwire_csync(ARGS_FROMWIRE)57 fromwire_csync(ARGS_FROMWIRE) {
58 isc_region_t sr;
59
60 REQUIRE(type == dns_rdatatype_csync);
61
62 UNUSED(type);
63 UNUSED(rdclass);
64 UNUSED(options);
65 UNUSED(dctx);
66
67 /*
68 * Serial + Flags
69 */
70 isc_buffer_activeregion(source, &sr);
71 if (sr.length < 6)
72 return (ISC_R_UNEXPECTEDEND);
73
74 RETERR(isc_mem_tobuffer(target, sr.base, 6));
75 isc_buffer_forward(source, 6);
76 isc_region_consume(&sr, 6);
77
78 RETERR(typemap_test(&sr, 1));
79
80 RETERR(isc_mem_tobuffer(target, sr.base, sr.length));
81 isc_buffer_forward(source, sr.length);
82 return (ISC_R_SUCCESS);
83 }
84
85 static inline isc_result_t
towire_csync(ARGS_TOWIRE)86 towire_csync(ARGS_TOWIRE) {
87
88 REQUIRE(rdata->type == dns_rdatatype_csync);
89 REQUIRE(rdata->length >= 6);
90
91 UNUSED(cctx);
92
93 return (isc_mem_tobuffer(target, rdata->data, rdata->length));
94 }
95
96 #endif /* RDATA_GENERIC_CSYNC_62_C */
97