00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef RDATA_GENERIC_NSEC3PARAM_51_C
00038 #define RDATA_GENERIC_NSEC3PARAM_51_C
00039
00040 #include <isc/iterated_hash.h>
00041 #include <isc/base32.h>
00042
00043 #define RRTYPE_NSEC3PARAM_ATTRIBUTES (DNS_RDATATYPEATTR_DNSSEC)
00044
00045 static inline isc_result_t
00046 fromtext_nsec3param(ARGS_FROMTEXT) {
00047 isc_token_t token;
00048 unsigned int flags = 0;
00049 unsigned char hashalg;
00050
00051 REQUIRE(type == 51);
00052
00053 UNUSED(type);
00054 UNUSED(rdclass);
00055 UNUSED(callbacks);
00056 UNUSED(origin);
00057 UNUSED(options);
00058
00059
00060 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00061 ISC_FALSE));
00062 RETTOK(dns_hashalg_fromtext(&hashalg, &token.value.as_textregion));
00063 RETERR(uint8_tobuffer(hashalg, target));
00064
00065
00066 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00067 ISC_FALSE));
00068 flags = token.value.as_ulong;
00069 if (flags > 255U)
00070 RETTOK(ISC_R_RANGE);
00071 RETERR(uint8_tobuffer(flags, target));
00072
00073
00074 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
00075 ISC_FALSE));
00076 if (token.value.as_ulong > 0xffffU)
00077 RETTOK(ISC_R_RANGE);
00078 RETERR(uint16_tobuffer(token.value.as_ulong, target));
00079
00080
00081 RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
00082 ISC_FALSE));
00083 if (token.value.as_textregion.length > (255*2))
00084 RETTOK(DNS_R_TEXTTOOLONG);
00085 if (strcmp(DNS_AS_STR(token), "-") == 0) {
00086 RETERR(uint8_tobuffer(0, target));
00087 } else {
00088 RETERR(uint8_tobuffer(strlen(DNS_AS_STR(token)) / 2, target));
00089 RETERR(isc_hex_decodestring(DNS_AS_STR(token), target));
00090 }
00091
00092 return (ISC_R_SUCCESS);
00093 }
00094
00095 static inline isc_result_t
00096 totext_nsec3param(ARGS_TOTEXT) {
00097 isc_region_t sr;
00098 unsigned int i, j;
00099 unsigned char hash;
00100 unsigned char flags;
00101 char buf[sizeof("65535 ")];
00102 isc_uint32_t iterations;
00103
00104 REQUIRE(rdata->type == 51);
00105 REQUIRE(rdata->length != 0);
00106
00107 UNUSED(tctx);
00108
00109 dns_rdata_toregion(rdata, &sr);
00110
00111 hash = uint8_fromregion(&sr);
00112 isc_region_consume(&sr, 1);
00113
00114 flags = uint8_fromregion(&sr);
00115 isc_region_consume(&sr, 1);
00116
00117 iterations = uint16_fromregion(&sr);
00118 isc_region_consume(&sr, 2);
00119
00120 sprintf(buf, "%u ", hash);
00121 RETERR(str_totext(buf, target));
00122
00123 sprintf(buf, "%u ", flags);
00124 RETERR(str_totext(buf, target));
00125
00126 sprintf(buf, "%u ", iterations);
00127 RETERR(str_totext(buf, target));
00128
00129 j = uint8_fromregion(&sr);
00130 isc_region_consume(&sr, 1);
00131 INSIST(j <= sr.length);
00132
00133 if (j != 0) {
00134 i = sr.length;
00135 sr.length = j;
00136 RETERR(isc_hex_totext(&sr, 1, "", target));
00137 sr.length = i - j;
00138 } else
00139 RETERR(str_totext("-", target));
00140
00141 return (ISC_R_SUCCESS);
00142 }
00143
00144 static inline isc_result_t
00145 fromwire_nsec3param(ARGS_FROMWIRE) {
00146 isc_region_t sr, rr;
00147 unsigned int saltlen;
00148
00149 REQUIRE(type == 51);
00150
00151 UNUSED(type);
00152 UNUSED(rdclass);
00153 UNUSED(options);
00154 UNUSED(dctx);
00155
00156 isc_buffer_activeregion(source, &sr);
00157 rr = sr;
00158
00159
00160 if (sr.length < 5U)
00161 RETERR(DNS_R_FORMERR);
00162 saltlen = sr.base[4];
00163 isc_region_consume(&sr, 5);
00164
00165 if (sr.length < saltlen)
00166 RETERR(DNS_R_FORMERR);
00167 isc_region_consume(&sr, saltlen);
00168 RETERR(mem_tobuffer(target, rr.base, rr.length));
00169 isc_buffer_forward(source, rr.length);
00170 return (ISC_R_SUCCESS);
00171 }
00172
00173 static inline isc_result_t
00174 towire_nsec3param(ARGS_TOWIRE) {
00175 isc_region_t sr;
00176
00177 REQUIRE(rdata->type == 51);
00178 REQUIRE(rdata->length != 0);
00179
00180 UNUSED(cctx);
00181
00182 dns_rdata_toregion(rdata, &sr);
00183 return (mem_tobuffer(target, sr.base, sr.length));
00184 }
00185
00186 static inline int
00187 compare_nsec3param(ARGS_COMPARE) {
00188 isc_region_t r1;
00189 isc_region_t r2;
00190
00191 REQUIRE(rdata1->type == rdata2->type);
00192 REQUIRE(rdata1->rdclass == rdata2->rdclass);
00193 REQUIRE(rdata1->type == 51);
00194 REQUIRE(rdata1->length != 0);
00195 REQUIRE(rdata2->length != 0);
00196
00197 dns_rdata_toregion(rdata1, &r1);
00198 dns_rdata_toregion(rdata2, &r2);
00199 return (isc_region_compare(&r1, &r2));
00200 }
00201
00202 static inline isc_result_t
00203 fromstruct_nsec3param(ARGS_FROMSTRUCT) {
00204 dns_rdata_nsec3param_t *nsec3param = source;
00205
00206 REQUIRE(type == 51);
00207 REQUIRE(source != NULL);
00208 REQUIRE(nsec3param->common.rdtype == type);
00209 REQUIRE(nsec3param->common.rdclass == rdclass);
00210
00211 UNUSED(type);
00212 UNUSED(rdclass);
00213
00214 RETERR(uint8_tobuffer(nsec3param->hash, target));
00215 RETERR(uint8_tobuffer(nsec3param->flags, target));
00216 RETERR(uint16_tobuffer(nsec3param->iterations, target));
00217 RETERR(uint8_tobuffer(nsec3param->salt_length, target));
00218 RETERR(mem_tobuffer(target, nsec3param->salt,
00219 nsec3param->salt_length));
00220 return (ISC_R_SUCCESS);
00221 }
00222
00223 static inline isc_result_t
00224 tostruct_nsec3param(ARGS_TOSTRUCT) {
00225 isc_region_t region;
00226 dns_rdata_nsec3param_t *nsec3param = target;
00227
00228 REQUIRE(rdata->type == 51);
00229 REQUIRE(target != NULL);
00230 REQUIRE(rdata->length != 0);
00231
00232 nsec3param->common.rdclass = rdata->rdclass;
00233 nsec3param->common.rdtype = rdata->type;
00234 ISC_LINK_INIT(&nsec3param->common, link);
00235
00236 region.base = rdata->data;
00237 region.length = rdata->length;
00238 nsec3param->hash = uint8_consume_fromregion(®ion);
00239 nsec3param->flags = uint8_consume_fromregion(®ion);
00240 nsec3param->iterations = uint16_consume_fromregion(®ion);
00241
00242 nsec3param->salt_length = uint8_consume_fromregion(®ion);
00243 nsec3param->salt = mem_maybedup(mctx, region.base,
00244 nsec3param->salt_length);
00245 if (nsec3param->salt == NULL)
00246 return (ISC_R_NOMEMORY);
00247 isc_region_consume(®ion, nsec3param->salt_length);
00248
00249 nsec3param->mctx = mctx;
00250 return (ISC_R_SUCCESS);
00251 }
00252
00253 static inline void
00254 freestruct_nsec3param(ARGS_FREESTRUCT) {
00255 dns_rdata_nsec3param_t *nsec3param = source;
00256
00257 REQUIRE(source != NULL);
00258 REQUIRE(nsec3param->common.rdtype == 51);
00259
00260 if (nsec3param->mctx == NULL)
00261 return;
00262
00263 if (nsec3param->salt != NULL)
00264 isc_mem_free(nsec3param->mctx, nsec3param->salt);
00265 nsec3param->mctx = NULL;
00266 }
00267
00268 static inline isc_result_t
00269 additionaldata_nsec3param(ARGS_ADDLDATA) {
00270 REQUIRE(rdata->type == 51);
00271
00272 UNUSED(rdata);
00273 UNUSED(add);
00274 UNUSED(arg);
00275
00276 return (ISC_R_SUCCESS);
00277 }
00278
00279 static inline isc_result_t
00280 digest_nsec3param(ARGS_DIGEST) {
00281 isc_region_t r;
00282
00283 REQUIRE(rdata->type == 51);
00284
00285 dns_rdata_toregion(rdata, &r);
00286 return ((digest)(arg, &r));
00287 }
00288
00289 static inline isc_boolean_t
00290 checkowner_nsec3param(ARGS_CHECKOWNER) {
00291
00292 REQUIRE(type == 51);
00293
00294 UNUSED(name);
00295 UNUSED(type);
00296 UNUSED(rdclass);
00297 UNUSED(wildcard);
00298
00299 return (ISC_TRUE);
00300 }
00301
00302 static inline isc_boolean_t
00303 checknames_nsec3param(ARGS_CHECKNAMES) {
00304
00305 REQUIRE(rdata->type == 51);
00306
00307 UNUSED(rdata);
00308 UNUSED(owner);
00309 UNUSED(bad);
00310
00311 return (ISC_TRUE);
00312 }
00313
00314 static inline int
00315 casecompare_nsec3param(ARGS_COMPARE) {
00316 return (compare_nsec3param(rdata1, rdata2));
00317 }
00318
00319 #endif