2015-09-18 23:45:12 +10:00
|
|
|
/*
|
2018-02-23 09:53:12 +01:00
|
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
2015-09-18 23:45:12 +10:00
|
|
|
*
|
2016-06-27 14:56:38 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2018-02-23 09:53:12 +01:00
|
|
|
*
|
|
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
|
|
* information regarding copyright ownership.
|
2015-09-18 23:45:12 +10:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* RFC 7477 */
|
|
|
|
|
|
|
|
#ifndef RDATA_GENERIC_CSYNC_62_C
|
|
|
|
#define RDATA_GENERIC_CSYNC_62_C
|
|
|
|
|
|
|
|
#define RRTYPE_CSYNC_ATTRIBUTES 0
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
static inline isc_result_t fromtext_csync(ARGS_FROMTEXT)
|
|
|
|
{
|
2015-09-18 23:45:12 +10:00
|
|
|
isc_token_t token;
|
|
|
|
|
|
|
|
REQUIRE(type == dns_rdatatype_csync);
|
|
|
|
|
|
|
|
UNUSED(type);
|
|
|
|
UNUSED(rdclass);
|
|
|
|
UNUSED(origin);
|
|
|
|
UNUSED(options);
|
|
|
|
UNUSED(callbacks);
|
|
|
|
|
|
|
|
/* Serial. */
|
|
|
|
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
|
2018-04-17 08:29:14 -07:00
|
|
|
false));
|
2015-09-18 23:45:12 +10:00
|
|
|
RETERR(uint32_tobuffer(token.value.as_ulong, target));
|
|
|
|
|
|
|
|
/* Flags. */
|
|
|
|
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
|
2018-04-17 08:29:14 -07:00
|
|
|
false));
|
2020-02-13 21:48:23 +01:00
|
|
|
if (token.value.as_ulong > 0xffffU) {
|
2015-09-18 23:45:12 +10:00
|
|
|
RETTOK(ISC_R_RANGE);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-09-18 23:45:12 +10:00
|
|
|
RETERR(uint16_tobuffer(token.value.as_ulong, target));
|
|
|
|
|
|
|
|
/* Type Map */
|
2018-04-17 08:29:14 -07:00
|
|
|
return (typemap_fromtext(lexer, target, true));
|
2015-09-18 23:45:12 +10:00
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
static inline isc_result_t totext_csync(ARGS_TOTEXT)
|
|
|
|
{
|
2015-09-18 23:45:12 +10:00
|
|
|
unsigned long num;
|
2020-02-12 13:59:18 +01:00
|
|
|
char buf[sizeof("0123456789")]; /* Also TYPE65535 */
|
|
|
|
isc_region_t sr;
|
2015-09-18 23:45:12 +10:00
|
|
|
|
|
|
|
REQUIRE(rdata->type == dns_rdatatype_csync);
|
|
|
|
REQUIRE(rdata->length >= 6);
|
|
|
|
|
|
|
|
UNUSED(tctx);
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata, &sr);
|
|
|
|
|
|
|
|
num = uint32_fromregion(&sr);
|
|
|
|
isc_region_consume(&sr, 4);
|
2017-10-03 14:54:19 +11:00
|
|
|
snprintf(buf, sizeof(buf), "%lu", num);
|
2015-09-18 23:45:12 +10:00
|
|
|
RETERR(str_totext(buf, target));
|
|
|
|
|
|
|
|
RETERR(str_totext(" ", target));
|
|
|
|
|
|
|
|
num = uint16_fromregion(&sr);
|
|
|
|
isc_region_consume(&sr, 2);
|
2017-10-03 14:54:19 +11:00
|
|
|
snprintf(buf, sizeof(buf), "%lu", num);
|
2015-09-18 23:45:12 +10:00
|
|
|
RETERR(str_totext(buf, target));
|
|
|
|
|
2018-05-23 18:40:48 +05:30
|
|
|
/*
|
|
|
|
* Don't leave a trailing space when there's no typemap present.
|
|
|
|
*/
|
|
|
|
if (sr.length > 0) {
|
|
|
|
RETERR(str_totext(" ", target));
|
|
|
|
}
|
2015-09-18 23:45:12 +10:00
|
|
|
return (typemap_totext(&sr, NULL, target));
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
static /* inline */ isc_result_t fromwire_csync(ARGS_FROMWIRE)
|
|
|
|
{
|
2015-09-18 23:45:12 +10:00
|
|
|
isc_region_t sr;
|
|
|
|
|
|
|
|
REQUIRE(type == dns_rdatatype_csync);
|
|
|
|
|
|
|
|
UNUSED(type);
|
|
|
|
UNUSED(rdclass);
|
|
|
|
UNUSED(options);
|
|
|
|
UNUSED(dctx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Serial + Flags
|
|
|
|
*/
|
|
|
|
isc_buffer_activeregion(source, &sr);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (sr.length < 6) {
|
2015-09-18 23:45:12 +10:00
|
|
|
return (ISC_R_UNEXPECTEDEND);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-09-18 23:45:12 +10:00
|
|
|
|
|
|
|
RETERR(mem_tobuffer(target, sr.base, 6));
|
|
|
|
isc_buffer_forward(source, 6);
|
|
|
|
isc_region_consume(&sr, 6);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
RETERR(typemap_test(&sr, true));
|
2015-09-18 23:45:12 +10:00
|
|
|
|
|
|
|
RETERR(mem_tobuffer(target, sr.base, sr.length));
|
|
|
|
isc_buffer_forward(source, sr.length);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
static inline isc_result_t towire_csync(ARGS_TOWIRE)
|
|
|
|
{
|
2015-09-18 23:45:12 +10:00
|
|
|
REQUIRE(rdata->type == dns_rdatatype_csync);
|
|
|
|
REQUIRE(rdata->length >= 6);
|
|
|
|
|
|
|
|
UNUSED(cctx);
|
|
|
|
|
|
|
|
return (mem_tobuffer(target, rdata->data, rdata->length));
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
static inline int compare_csync(ARGS_COMPARE)
|
|
|
|
{
|
2015-09-18 23:45:12 +10:00
|
|
|
isc_region_t r1;
|
|
|
|
isc_region_t r2;
|
|
|
|
|
|
|
|
REQUIRE(rdata1->type == rdata2->type);
|
|
|
|
REQUIRE(rdata1->rdclass == rdata2->rdclass);
|
|
|
|
REQUIRE(rdata1->type == dns_rdatatype_csync);
|
|
|
|
REQUIRE(rdata1->length >= 6);
|
|
|
|
REQUIRE(rdata2->length >= 6);
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata1, &r1);
|
|
|
|
dns_rdata_toregion(rdata2, &r2);
|
|
|
|
return (isc_region_compare(&r1, &r2));
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
static inline isc_result_t fromstruct_csync(ARGS_FROMSTRUCT)
|
|
|
|
{
|
2015-09-18 23:45:12 +10:00
|
|
|
dns_rdata_csync_t *csync = source;
|
2020-02-12 13:59:18 +01:00
|
|
|
isc_region_t region;
|
2015-09-18 23:45:12 +10:00
|
|
|
|
|
|
|
REQUIRE(type == dns_rdatatype_csync);
|
2019-09-27 10:40:51 +02:00
|
|
|
REQUIRE(csync != NULL);
|
2015-09-18 23:45:12 +10:00
|
|
|
REQUIRE(csync->common.rdtype == type);
|
|
|
|
REQUIRE(csync->common.rdclass == rdclass);
|
|
|
|
REQUIRE(csync->typebits != NULL || csync->len == 0);
|
|
|
|
|
|
|
|
UNUSED(type);
|
|
|
|
UNUSED(rdclass);
|
|
|
|
|
|
|
|
RETERR(uint32_tobuffer(csync->serial, target));
|
|
|
|
RETERR(uint16_tobuffer(csync->flags, target));
|
|
|
|
|
|
|
|
region.base = csync->typebits;
|
|
|
|
region.length = csync->len;
|
2018-04-17 08:29:14 -07:00
|
|
|
RETERR(typemap_test(®ion, true));
|
2015-09-18 23:45:12 +10:00
|
|
|
return (mem_tobuffer(target, csync->typebits, csync->len));
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
static inline isc_result_t tostruct_csync(ARGS_TOSTRUCT)
|
|
|
|
{
|
|
|
|
isc_region_t region;
|
2015-09-18 23:45:12 +10:00
|
|
|
dns_rdata_csync_t *csync = target;
|
|
|
|
|
|
|
|
REQUIRE(rdata->type == dns_rdatatype_csync);
|
2019-09-27 10:40:51 +02:00
|
|
|
REQUIRE(csync != NULL);
|
2015-09-18 23:45:12 +10:00
|
|
|
REQUIRE(rdata->length != 0);
|
|
|
|
|
|
|
|
csync->common.rdclass = rdata->rdclass;
|
|
|
|
csync->common.rdtype = rdata->type;
|
|
|
|
ISC_LINK_INIT(&csync->common, link);
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata, ®ion);
|
|
|
|
|
|
|
|
csync->serial = uint32_fromregion(®ion);
|
|
|
|
isc_region_consume(®ion, 4);
|
|
|
|
|
|
|
|
csync->flags = uint16_fromregion(®ion);
|
|
|
|
isc_region_consume(®ion, 2);
|
|
|
|
|
|
|
|
csync->len = region.length;
|
|
|
|
csync->typebits = mem_maybedup(mctx, region.base, region.length);
|
2020-02-13 21:48:23 +01:00
|
|
|
if (csync->typebits == NULL) {
|
2015-09-18 23:45:12 +10:00
|
|
|
goto cleanup;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-09-18 23:45:12 +10:00
|
|
|
|
|
|
|
csync->mctx = mctx;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
cleanup:
|
2015-09-18 23:45:12 +10:00
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
static inline void freestruct_csync(ARGS_FREESTRUCT)
|
|
|
|
{
|
2015-09-18 23:45:12 +10:00
|
|
|
dns_rdata_csync_t *csync = source;
|
|
|
|
|
2019-09-27 10:40:51 +02:00
|
|
|
REQUIRE(csync != NULL);
|
2015-09-18 23:45:12 +10:00
|
|
|
REQUIRE(csync->common.rdtype == dns_rdatatype_csync);
|
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (csync->mctx == NULL) {
|
2015-09-18 23:45:12 +10:00
|
|
|
return;
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-09-18 23:45:12 +10:00
|
|
|
|
2020-02-13 21:48:23 +01:00
|
|
|
if (csync->typebits != NULL) {
|
2015-09-18 23:45:12 +10:00
|
|
|
isc_mem_free(csync->mctx, csync->typebits);
|
2020-02-13 21:48:23 +01:00
|
|
|
}
|
2015-09-18 23:45:12 +10:00
|
|
|
csync->mctx = NULL;
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
static inline isc_result_t additionaldata_csync(ARGS_ADDLDATA)
|
|
|
|
{
|
2015-09-18 23:45:12 +10:00
|
|
|
REQUIRE(rdata->type == dns_rdatatype_csync);
|
|
|
|
|
|
|
|
UNUSED(rdata);
|
|
|
|
UNUSED(add);
|
|
|
|
UNUSED(arg);
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
static inline isc_result_t digest_csync(ARGS_DIGEST)
|
|
|
|
{
|
2015-09-18 23:45:12 +10:00
|
|
|
isc_region_t r;
|
|
|
|
|
|
|
|
REQUIRE(rdata->type == dns_rdatatype_csync);
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata, &r);
|
|
|
|
return ((digest)(arg, &r));
|
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
static inline bool checkowner_csync(ARGS_CHECKOWNER)
|
|
|
|
{
|
|
|
|
REQUIRE(type == dns_rdatatype_csync);
|
2015-09-18 23:45:12 +10:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
UNUSED(name);
|
|
|
|
UNUSED(type);
|
|
|
|
UNUSED(rdclass);
|
|
|
|
UNUSED(wildcard);
|
2015-09-18 23:45:12 +10:00
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
return (true);
|
2015-09-18 23:45:12 +10:00
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
static inline bool checknames_csync(ARGS_CHECKNAMES)
|
|
|
|
{
|
2015-09-18 23:45:12 +10:00
|
|
|
REQUIRE(rdata->type == dns_rdatatype_csync);
|
|
|
|
|
|
|
|
UNUSED(rdata);
|
|
|
|
UNUSED(owner);
|
|
|
|
UNUSED(bad);
|
|
|
|
|
2018-04-17 08:29:14 -07:00
|
|
|
return (true);
|
2015-09-18 23:45:12 +10:00
|
|
|
}
|
|
|
|
|
2020-02-12 13:59:18 +01:00
|
|
|
static inline int casecompare_csync(ARGS_COMPARE)
|
|
|
|
{
|
2015-09-18 23:45:12 +10:00
|
|
|
isc_region_t region1;
|
|
|
|
isc_region_t region2;
|
|
|
|
|
|
|
|
REQUIRE(rdata1->type == rdata2->type);
|
|
|
|
REQUIRE(rdata1->rdclass == rdata2->rdclass);
|
|
|
|
REQUIRE(rdata1->type == dns_rdatatype_csync);
|
|
|
|
REQUIRE(rdata1->length >= 6);
|
|
|
|
REQUIRE(rdata2->length >= 6);
|
|
|
|
|
|
|
|
dns_rdata_toregion(rdata1, ®ion1);
|
|
|
|
dns_rdata_toregion(rdata2, ®ion2);
|
|
|
|
return (isc_region_compare(®ion1, ®ion2));
|
|
|
|
}
|
2020-02-12 13:59:18 +01:00
|
|
|
#endif /* RDATA_GENERIC_CSYNC_62_C */
|