1 /*
2  * Copyright (C) 2015  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 /* http://www.watson.org/~weiler/INI1999-19.pdf */
18 
19 #ifndef RDATA_GENERIC_TA_32768_C
20 #define RDATA_GENERIC_TA_32768_C
21 
22 #define RRTYPE_TA_ATTRIBUTES 0
23 
24 static inline isc_result_t
fromtext_ta(ARGS_FROMTEXT)25 fromtext_ta(ARGS_FROMTEXT) {
26 
27 	REQUIRE(type == dns_rdatatype_ta);
28 
29 	return (generic_fromtext_ds(rdclass, type, lexer, origin, options,
30 				    target, callbacks));
31 }
32 
33 static inline isc_result_t
totext_ta(ARGS_TOTEXT)34 totext_ta(ARGS_TOTEXT) {
35 
36 	REQUIRE(rdata->type == dns_rdatatype_ta);
37 
38 	return (generic_totext_ds(rdata, tctx, target));
39 }
40 
41 static inline isc_result_t
fromwire_ta(ARGS_FROMWIRE)42 fromwire_ta(ARGS_FROMWIRE) {
43 
44 	REQUIRE(type == dns_rdatatype_ta);
45 
46 	return (generic_fromwire_ds(rdclass, type, source, dctx, options,
47 				    target));
48 }
49 
50 static inline isc_result_t
towire_ta(ARGS_TOWIRE)51 towire_ta(ARGS_TOWIRE) {
52 	isc_region_t sr;
53 
54 	REQUIRE(rdata->type == dns_rdatatype_ta);
55 	REQUIRE(rdata->length != 0);
56 
57 	UNUSED(cctx);
58 
59 	dns_rdata_toregion(rdata, &sr);
60 	return (mem_tobuffer(target, sr.base, sr.length));
61 }
62 
63 static inline int
compare_ta(ARGS_COMPARE)64 compare_ta(ARGS_COMPARE) {
65 	isc_region_t r1;
66 	isc_region_t r2;
67 
68 	REQUIRE(rdata1->type == rdata2->type);
69 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
70 	REQUIRE(rdata1->type == dns_rdatatype_ta);
71 	REQUIRE(rdata1->length != 0);
72 	REQUIRE(rdata2->length != 0);
73 
74 	dns_rdata_toregion(rdata1, &r1);
75 	dns_rdata_toregion(rdata2, &r2);
76 	return (isc_region_compare(&r1, &r2));
77 }
78 
79 static inline isc_result_t
fromstruct_ta(ARGS_FROMSTRUCT)80 fromstruct_ta(ARGS_FROMSTRUCT) {
81 
82 	REQUIRE(type == dns_rdatatype_ta);
83 
84 	return (generic_fromstruct_ds(rdclass, type, source, target));
85 }
86 
87 static inline isc_result_t
tostruct_ta(ARGS_TOSTRUCT)88 tostruct_ta(ARGS_TOSTRUCT) {
89 	dns_rdata_ds_t *ds = target;
90 
91 	REQUIRE(rdata->type == dns_rdatatype_ta);
92 
93 	/*
94 	 * Checked by generic_tostruct_ds().
95 	 */
96 	ds->common.rdclass = rdata->rdclass;
97 	ds->common.rdtype = rdata->type;
98 	ISC_LINK_INIT(&ds->common, link);
99 
100 	return (generic_tostruct_ds(rdata, target, mctx));
101 }
102 
103 static inline void
freestruct_ta(ARGS_FREESTRUCT)104 freestruct_ta(ARGS_FREESTRUCT) {
105 	dns_rdata_ta_t *ds = source;
106 
107 	REQUIRE(ds != NULL);
108 	REQUIRE(ds->common.rdtype == dns_rdatatype_ta);
109 
110 	if (ds->mctx == NULL)
111 		return;
112 
113 	if (ds->digest != NULL)
114 		isc_mem_free(ds->mctx, ds->digest);
115 	ds->mctx = NULL;
116 }
117 
118 static inline isc_result_t
additionaldata_ta(ARGS_ADDLDATA)119 additionaldata_ta(ARGS_ADDLDATA) {
120 	REQUIRE(rdata->type == dns_rdatatype_ta);
121 
122 	UNUSED(rdata);
123 	UNUSED(add);
124 	UNUSED(arg);
125 
126 	return (ISC_R_SUCCESS);
127 }
128 
129 static inline isc_result_t
digest_ta(ARGS_DIGEST)130 digest_ta(ARGS_DIGEST) {
131 	isc_region_t r;
132 
133 	REQUIRE(rdata->type == dns_rdatatype_ta);
134 
135 	dns_rdata_toregion(rdata, &r);
136 
137 	return ((digest)(arg, &r));
138 }
139 
140 static inline isc_boolean_t
checkowner_ta(ARGS_CHECKOWNER)141 checkowner_ta(ARGS_CHECKOWNER) {
142 
143 	REQUIRE(type == dns_rdatatype_ta);
144 
145 	UNUSED(name);
146 	UNUSED(type);
147 	UNUSED(rdclass);
148 	UNUSED(wildcard);
149 
150 	return (ISC_TRUE);
151 }
152 
153 static inline isc_boolean_t
checknames_ta(ARGS_CHECKNAMES)154 checknames_ta(ARGS_CHECKNAMES) {
155 
156 	REQUIRE(rdata->type == dns_rdatatype_ta);
157 
158 	UNUSED(rdata);
159 	UNUSED(owner);
160 	UNUSED(bad);
161 
162 	return (ISC_TRUE);
163 }
164 
165 static inline int
casecompare_ta(ARGS_COMPARE)166 casecompare_ta(ARGS_COMPARE) {
167 	return (compare_ta(rdata1, rdata2));
168 }
169 
170 #endif	/* RDATA_GENERIC_TA_32768_C */
171