1 /*
2  * Copyright (C) 2004, 2005, 2007, 2009, 2011-2013, 2015  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2003  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 /* $Id$ */
19 
20 /*
21  * Reviewed: Wed Mar 15 16:47:10 PST 2000 by halley.
22  */
23 
24 /* RFC2535 */
25 
26 #ifndef RDATA_GENERIC_DNSKEY_48_C
27 #define RDATA_GENERIC_DNSKEY_48_C
28 
29 #include <dst/dst.h>
30 
31 #define RRTYPE_DNSKEY_ATTRIBUTES (DNS_RDATATYPEATTR_DNSSEC)
32 
33 static inline isc_result_t
fromtext_dnskey(ARGS_FROMTEXT)34 fromtext_dnskey(ARGS_FROMTEXT) {
35 
36 	REQUIRE(type == dns_rdatatype_dnskey);
37 
38 	return (generic_fromtext_key(rdclass, type, lexer, origin,
39 				     options, target, callbacks));
40 }
41 
42 static inline isc_result_t
totext_dnskey(ARGS_TOTEXT)43 totext_dnskey(ARGS_TOTEXT) {
44 
45 	REQUIRE(rdata != NULL);
46 	REQUIRE(rdata->type == dns_rdatatype_dnskey);
47 
48 	return (generic_totext_key(rdata, tctx, target));
49 }
50 
51 static inline isc_result_t
fromwire_dnskey(ARGS_FROMWIRE)52 fromwire_dnskey(ARGS_FROMWIRE) {
53 
54 	REQUIRE(type == dns_rdatatype_dnskey);
55 
56 	return (generic_fromwire_key(rdclass, type, source, dctx,
57 				     options, target));
58 }
59 
60 static inline isc_result_t
towire_dnskey(ARGS_TOWIRE)61 towire_dnskey(ARGS_TOWIRE) {
62 	isc_region_t sr;
63 
64 	REQUIRE(rdata != NULL);
65 	REQUIRE(rdata->type == dns_rdatatype_dnskey);
66 	REQUIRE(rdata->length != 0);
67 
68 	UNUSED(cctx);
69 
70 	dns_rdata_toregion(rdata, &sr);
71 	return (mem_tobuffer(target, sr.base, sr.length));
72 }
73 
74 static inline int
compare_dnskey(ARGS_COMPARE)75 compare_dnskey(ARGS_COMPARE) {
76 	isc_region_t r1;
77 	isc_region_t r2;
78 
79 	REQUIRE(rdata1 != NULL);
80 	REQUIRE(rdata2 != NULL);
81 	REQUIRE(rdata1->type == rdata2->type);
82 	REQUIRE(rdata1->rdclass == rdata2->rdclass);
83 	REQUIRE(rdata1->type == dns_rdatatype_dnskey);
84 	REQUIRE(rdata1->length != 0);
85 	REQUIRE(rdata2->length != 0);
86 
87 	dns_rdata_toregion(rdata1, &r1);
88 	dns_rdata_toregion(rdata2, &r2);
89 	return (isc_region_compare(&r1, &r2));
90 }
91 
92 static inline isc_result_t
fromstruct_dnskey(ARGS_FROMSTRUCT)93 fromstruct_dnskey(ARGS_FROMSTRUCT) {
94 
95 	REQUIRE(type == dns_rdatatype_dnskey);
96 
97 	return (generic_fromstruct_key(rdclass, type, source, target));
98 }
99 
100 static inline isc_result_t
tostruct_dnskey(ARGS_TOSTRUCT)101 tostruct_dnskey(ARGS_TOSTRUCT) {
102 	dns_rdata_dnskey_t *dnskey = target;
103 
104 	REQUIRE(dnskey != NULL);
105 	REQUIRE(rdata != NULL);
106 	REQUIRE(rdata->type == dns_rdatatype_dnskey);
107 
108 	dnskey->common.rdclass = rdata->rdclass;
109 	dnskey->common.rdtype = rdata->type;
110 	ISC_LINK_INIT(&dnskey->common, link);
111 
112 	return (generic_tostruct_key(rdata, target, mctx));
113 }
114 
115 static inline void
freestruct_dnskey(ARGS_FREESTRUCT)116 freestruct_dnskey(ARGS_FREESTRUCT) {
117 	dns_rdata_dnskey_t *dnskey = (dns_rdata_dnskey_t *) source;
118 
119 	REQUIRE(dnskey != NULL);
120 	REQUIRE(dnskey->common.rdtype == dns_rdatatype_dnskey);
121 
122 	generic_freestruct_key(source);
123 }
124 
125 static inline isc_result_t
additionaldata_dnskey(ARGS_ADDLDATA)126 additionaldata_dnskey(ARGS_ADDLDATA) {
127 
128 	REQUIRE(rdata->type == dns_rdatatype_dnskey);
129 
130 	UNUSED(rdata);
131 	UNUSED(add);
132 	UNUSED(arg);
133 
134 	return (ISC_R_SUCCESS);
135 }
136 
137 static inline isc_result_t
digest_dnskey(ARGS_DIGEST)138 digest_dnskey(ARGS_DIGEST) {
139 	isc_region_t r;
140 
141 	REQUIRE(rdata != NULL);
142 	REQUIRE(rdata->type == dns_rdatatype_dnskey);
143 
144 	dns_rdata_toregion(rdata, &r);
145 
146 	return ((digest)(arg, &r));
147 }
148 
149 static inline isc_boolean_t
checkowner_dnskey(ARGS_CHECKOWNER)150 checkowner_dnskey(ARGS_CHECKOWNER) {
151 
152 	REQUIRE(type == dns_rdatatype_dnskey);
153 
154 	UNUSED(name);
155 	UNUSED(type);
156 	UNUSED(rdclass);
157 	UNUSED(wildcard);
158 
159 	return (ISC_TRUE);
160 }
161 
162 static inline isc_boolean_t
checknames_dnskey(ARGS_CHECKNAMES)163 checknames_dnskey(ARGS_CHECKNAMES) {
164 
165 	REQUIRE(rdata != NULL);
166 	REQUIRE(rdata->type == dns_rdatatype_dnskey);
167 
168 	UNUSED(rdata);
169 	UNUSED(owner);
170 	UNUSED(bad);
171 
172 	return (ISC_TRUE);
173 }
174 
175 static inline int
casecompare_dnskey(ARGS_COMPARE)176 casecompare_dnskey(ARGS_COMPARE) {
177 
178 	/*
179 	 * Treat ALG 253 (private DNS) subtype name case sensistively.
180 	 */
181 	return (compare_dnskey(rdata1, rdata2));
182 }
183 
184 #endif	/* RDATA_GENERIC_DNSKEY_48_C */
185