Commit 41721883 authored by Michał Kępień's avatar Michał Kępień
Browse files

[master] Add support for DOA

4761.	[protocol]	Add support for DOA. [RT #45612]
parent 6bdb69ac
4761. [protocol] Add support for DOA. [RT #45612]
4760. [func] Add glue cache statistics counters. [RT #46028]
 
4759. [func] Add logging channel "trust-anchor-telementry" to
......
......@@ -429,7 +429,17 @@ caa03 CAA 128 tbs ""
; type 258
avc AVC foo:bar
; type 259 -- 32767 (unassigned)
; type 259
doa01 DOA ( 1234567890 1234567890 1 "image/gif"
R0lGODlhKAAZAOMCAGZmZgBmmf///zOZzMz//5nM/zNmmWbM/5nMzMzMzACZ////
/////////////////yH5BAEKAA8ALAAAAAAoABkAAATH8IFJK5U2a4337F5ogRkp
noCJrly7PrCKyh8c3HgAhzT35MDbbtO7/IJIHbGiOiaTxVTpSVWWLqNq1UVyapNS
1wd3OAxug0LhnCubcVhsxysQnOt4ATpvvzHlFzl1AwODhWeFAgRpen5/UhheAYMF
dUB4SFcpGEGGdQeCAqBBLTuSk30EeXd9pEsAbKGxjHqDSE0Sp6ixN4N1BJmbc7lI
hmsBich1awPAjkY1SZR8bJWrz382SGqIBQQFQd4IsUTaX+ceuudPEQA7 )
doa02 DOA 0 1 2 "" aHR0cHM6Ly93d3cuaXNjLm9yZy8=
; type 260 -- 32767 (unassigned)
; type 32768
ta TA 30795 1 1 (
......
......@@ -72,5 +72,6 @@ EUI64
URI
CAA
AVC
DOA
TA
DLV
......@@ -31,6 +31,8 @@ dlv.example. 3600 IN DLV 30795 1 1 310D27F4D82C1FC2400704EA9939FE6E1CEAA3B9
dname01.example. 3600 IN DNAME dname-target.
dname02.example. 3600 IN DNAME dname-target.example.
dname03.example. 3600 IN DNAME .
doa01.example. 3600 IN DOA 1234567890 1234567890 1 "image/gif" R0lGODlhKAAZAOMCAGZmZgBmmf///zOZzMz//5nM/zNmmWbM/5nMzMzMzACZ/////////////////////yH5BAEKAA8ALAAAAAAoABkAAATH8IFJK5U2a4337F5ogRkpnoCJrly7PrCKyh8c3HgAhzT35MDbbtO7/IJIHbGiOiaTxVTpSVWWLqNq1UVyapNS1wd3OAxug0LhnCubcVhsxysQnOt4ATpvvzHlFzl1AwODhWeFAgRpen5/UhheAYMFdUB4SFcpGEGGdQeCAqBBLTuSk30EeXd9pEsAbKGxjHqDSE0Sp6ixN4N1BJmbc7lIhmsBich1awPAjkY1SZR8bJWrz382SGqIBQQFQd4IsUTaX+ceuudPEQA7
doa02.example. 3600 IN DOA 0 1 2 "" aHR0cHM6Ly93d3cuaXNjLm9yZy8=
ds01.example. 3600 IN NS ns42.example.
ds01.example. 3600 IN DS 12892 5 2 26584835CA80C81C91999F31CFAF2A0E89D4FF1C8FAFD0DDB31A85C7 19277C13
ds02.example. 3600 IN NS ns43.example.
......
......@@ -31,6 +31,8 @@ dlv.example. 3600 IN DLV 30795 1 1 310D27F4D82C1FC2400704EA9939FE6E1CEAA3B9
dname01.example. 3600 IN DNAME dname-target.
dname02.example. 3600 IN DNAME dname-target.example.
dname03.example. 3600 IN DNAME .
doa01.example. 3600 IN DOA 1234567890 1234567890 1 "image/gif" R0lGODlhKAAZAOMCAGZmZgBmmf///zOZzMz//5nM/zNmmWbM/5nMzMzMzACZ/////////////////////yH5BAEKAA8ALAAAAAAoABkAAATH8IFJK5U2a4337F5ogRkpnoCJrly7PrCKyh8c3HgAhzT35MDbbtO7/IJIHbGiOiaTxVTpSVWWLqNq1UVyapNS1wd3OAxug0LhnCubcVhsxysQnOt4ATpvvzHlFzl1AwODhWeFAgRpen5/UhheAYMFdUB4SFcpGEGGdQeCAqBBLTuSk30EeXd9pEsAbKGxjHqDSE0Sp6ixN4N1BJmbc7lIhmsBich1awPAjkY1SZR8bJWrz382SGqIBQQFQd4IsUTaX+ceuudPEQA7
doa02.example. 3600 IN DOA 0 1 2 "" aHR0cHM6Ly93d3cuaXNjLm9yZy8=
ds01.example. 3600 IN NS ns42.example.
ds01.example. 3600 IN DS 12892 5 2 26584835CA80C81C91999F31CFAF2A0E89D4FF1C8FAFD0DDB31A85C7 19277C13
ds02.example. 3600 IN NS ns43.example.
......
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* 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/.
*/
#ifndef RDATA_GENERIC_DOA_259_C
#define RDATA_GENERIC_DOA_259_C
#define RRTYPE_DOA_ATTRIBUTES (0)
static inline isc_result_t
fromtext_doa(ARGS_FROMTEXT) {
isc_token_t token;
REQUIRE(type == dns_rdatatype_doa);
UNUSED(rdclass);
UNUSED(origin);
UNUSED(options);
UNUSED(callbacks);
/*
* DOA-ENTERPRISE
*/
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
ISC_FALSE));
RETERR(uint32_tobuffer(token.value.as_ulong, target));
/*
* DOA-TYPE
*/
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
ISC_FALSE));
RETERR(uint32_tobuffer(token.value.as_ulong, target));
/*
* DOA-LOCATION
*/
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
ISC_FALSE));
if (token.value.as_ulong > 0xffU) {
RETTOK(ISC_R_RANGE);
}
RETERR(uint8_tobuffer(token.value.as_ulong, target));
/*
* DOA-MEDIA-TYPE
*/
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring,
ISC_FALSE));
RETTOK(txt_fromtext(&token.value.as_textregion, target));
/*
* DOA-DATA
*/
RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
ISC_FALSE));
if (strcmp(DNS_AS_STR(token), "-") == 0) {
return (ISC_R_SUCCESS);
} else {
isc_lex_ungettoken(lexer, &token);
return (isc_base64_tobuffer(lexer, target, -1));
}
}
static inline isc_result_t
totext_doa(ARGS_TOTEXT) {
char buf[sizeof("4294967295 ")];
isc_region_t region;
isc_uint32_t n;
REQUIRE(rdata != NULL);
REQUIRE(rdata->type == dns_rdatatype_doa);
REQUIRE(rdata->length != 0);
UNUSED(tctx);
dns_rdata_toregion(rdata, &region);
/*
* DOA-ENTERPRISE
*/
n = uint32_fromregion(&region);
isc_region_consume(&region, 4);
snprintf(buf, sizeof(buf), "%u ", n);
RETERR(str_totext(buf, target));
/*
* DOA-TYPE
*/
n = uint32_fromregion(&region);
isc_region_consume(&region, 4);
snprintf(buf, sizeof(buf), "%u ", n);
RETERR(str_totext(buf, target));
/*
* DOA-LOCATION
*/
n = uint8_fromregion(&region);
isc_region_consume(&region, 1);
snprintf(buf, sizeof(buf), "%u ", n);
RETERR(str_totext(buf, target));
/*
* DOA-MEDIA-TYPE
*/
RETERR(txt_totext(&region, ISC_TRUE, target));
RETERR(str_totext(" ", target));
/*
* DOA-DATA
*/
if (region.length == 0) {
return (str_totext("-", target));
} else {
return (isc_base64_totext(&region, 60, "", target));
}
}
static inline isc_result_t
fromwire_doa(ARGS_FROMWIRE) {
isc_region_t region;
UNUSED(rdclass);
UNUSED(dctx);
UNUSED(options);
REQUIRE(type == dns_rdatatype_doa);
isc_buffer_activeregion(source, &region);
/*
* DOA-MEDIA-TYPE may be an empty <character-string> (i.e.,
* comprising of just the length octet) and DOA-DATA can have
* zero length.
*/
if (region.length < 4 + 4 + 1 + 1) {
return (ISC_R_UNEXPECTEDEND);
}
/*
* Check whether DOA-MEDIA-TYPE length is not malformed.
*/
if (region.base[9] > region.length - 10) {
return (ISC_R_UNEXPECTEDEND);
}
isc_buffer_forward(source, region.length);
return (mem_tobuffer(target, region.base, region.length));
}
static inline isc_result_t
towire_doa(ARGS_TOWIRE) {
isc_region_t region;
UNUSED(cctx);
REQUIRE(rdata != NULL);
REQUIRE(rdata->type == dns_rdatatype_doa);
REQUIRE(rdata->length != 0);
dns_rdata_toregion(rdata, &region);
return (mem_tobuffer(target, region.base, region.length));
}
static inline int
compare_doa(ARGS_COMPARE) {
isc_region_t r1;
isc_region_t r2;
REQUIRE(rdata1 != NULL);
REQUIRE(rdata2 != NULL);
REQUIRE(rdata1->type == rdata2->type);
REQUIRE(rdata1->type == dns_rdatatype_doa);
REQUIRE(rdata1->rdclass == rdata2->rdclass);
REQUIRE(rdata1->length != 0);
REQUIRE(rdata2->length != 0);
dns_rdata_toregion(rdata1, &r1);
dns_rdata_toregion(rdata2, &r2);
return (isc_region_compare(&r1, &r2));
}
static inline isc_result_t
fromstruct_doa(ARGS_FROMSTRUCT) {
dns_rdata_doa_t *doa = source;
REQUIRE(type == dns_rdatatype_doa);
REQUIRE(source != NULL);
REQUIRE(doa->common.rdtype == dns_rdatatype_doa);
REQUIRE(doa->common.rdclass == rdclass);
RETERR(uint32_tobuffer(doa->enterprise, target));
RETERR(uint32_tobuffer(doa->type, target));
RETERR(uint8_tobuffer(doa->location, target));
RETERR(uint8_tobuffer(doa->mediatype_len, target));
RETERR(mem_tobuffer(target, doa->mediatype, doa->mediatype_len));
return (mem_tobuffer(target, doa->data, doa->data_len));
}
static inline isc_result_t
tostruct_doa(ARGS_TOSTRUCT) {
dns_rdata_doa_t *doa = target;
isc_region_t region;
REQUIRE(rdata != NULL);
REQUIRE(rdata->type == dns_rdatatype_doa);
REQUIRE(rdata->length != 0);
doa->common.rdclass = rdata->rdclass;
doa->common.rdtype = rdata->type;
ISC_LINK_INIT(&doa->common, link);
dns_rdata_toregion(rdata, &region);
/*
* DOA-ENTERPRISE
*/
if (region.length < 4) {
return (ISC_R_UNEXPECTEDEND);
}
doa->enterprise = uint32_fromregion(&region);
isc_region_consume(&region, 4);
/*
* DOA-TYPE
*/
if (region.length < 4) {
return (ISC_R_UNEXPECTEDEND);
}
doa->type = uint32_fromregion(&region);
isc_region_consume(&region, 4);
/*
* DOA-LOCATION
*/
if (region.length < 1) {
return (ISC_R_UNEXPECTEDEND);
}
doa->location = uint8_fromregion(&region);
isc_region_consume(&region, 1);
/*
* DOA-MEDIA-TYPE
*/
if (region.length < 1) {
return (ISC_R_UNEXPECTEDEND);
}
doa->mediatype_len = uint8_fromregion(&region);
isc_region_consume(&region, 1);
INSIST(doa->mediatype_len <= region.length);
doa->mediatype = mem_maybedup(mctx, region.base, doa->mediatype_len);
if (doa->mediatype == NULL) {
goto cleanup;
}
isc_region_consume(&region, doa->mediatype_len);
/*
* DOA-DATA
*/
doa->data_len = region.length;
doa->data = NULL;
if (doa->data_len > 0) {
doa->data = mem_maybedup(mctx, region.base, doa->data_len);
if (doa->data == NULL) {
goto cleanup;
}
isc_region_consume(&region, doa->data_len);
}
doa->mctx = mctx;
return (ISC_R_SUCCESS);
cleanup:
if (mctx != NULL && doa->mediatype != NULL) {
isc_mem_free(mctx, doa->mediatype);
}
return (ISC_R_NOMEMORY);
}
static inline void
freestruct_doa(ARGS_FREESTRUCT) {
dns_rdata_doa_t *doa = source;
REQUIRE(source != NULL);
REQUIRE(doa->common.rdtype == dns_rdatatype_doa);
if (doa->mctx == NULL) {
return;
}
if (doa->mediatype != NULL) {
isc_mem_free(doa->mctx, doa->mediatype);
}
if (doa->data != NULL) {
isc_mem_free(doa->mctx, doa->data);
}
doa->mctx = NULL;
}
static inline isc_result_t
additionaldata_doa(ARGS_ADDLDATA) {
UNUSED(rdata);
UNUSED(add);
UNUSED(arg);
REQUIRE(rdata->type == dns_rdatatype_doa);
return (ISC_R_SUCCESS);
}
static inline isc_result_t
digest_doa(ARGS_DIGEST) {
isc_region_t r;
REQUIRE(rdata->type == dns_rdatatype_doa);
dns_rdata_toregion(rdata, &r);
return ((digest)(arg, &r));
}
static inline isc_boolean_t
checkowner_doa(ARGS_CHECKOWNER) {
UNUSED(name);
UNUSED(type);
UNUSED(rdclass);
UNUSED(wildcard);
REQUIRE(type == dns_rdatatype_doa);
return (ISC_TRUE);
}
static inline isc_boolean_t
checknames_doa(ARGS_CHECKNAMES) {
UNUSED(rdata);
UNUSED(owner);
UNUSED(bad);
REQUIRE(rdata->type == dns_rdatatype_doa);
return (ISC_TRUE);
}
static inline int
casecompare_doa(ARGS_COMPARE) {
return (compare_doa(rdata1, rdata2));
}
#endif /* RDATA_GENERIC_DOA_259_C */
/*
* Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
*
* 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/.
*/
#ifndef GENERIC_DOA_259_H
#define GENERIC_DOA_259_H 1
typedef struct dns_rdata_doa {
dns_rdatacommon_t common;
isc_mem_t * mctx;
unsigned char * mediatype;
unsigned char * data;
isc_uint32_t enterprise;
isc_uint32_t type;
isc_uint16_t data_len;
isc_uint8_t location;
isc_uint8_t mediatype_len;
} dns_rdata_doa_t;
#endif /* GENERIC_DOA_259_H */
......@@ -31,9 +31,10 @@
* An array of these structures is passed to check_text_ok().
*/
struct text_ok {
const char *data; /* RDATA in text format */
isc_boolean_t ok; /* is this RDATA valid? */
int lineno; /* source line in which RDATA is defined */
const char *text_in; /* text passed to fromtext_*() */
const char *text_out; /* text expected from totext_*();
NULL indicates text_in is invalid */
int lineno; /* source line defining this RDATA */
};
typedef struct text_ok text_ok_t;
......@@ -41,10 +42,10 @@ typedef struct text_ok text_ok_t;
* An array of these structures is passed to check_wire_ok().
*/
struct wire_ok {
unsigned char data[64]; /* RDATA in wire format */
size_t len; /* octets of data to parse */
isc_boolean_t ok; /* is this RDATA valid? */
int lineno; /* source line in which RDATA is defined */
unsigned char data[512]; /* RDATA in wire format */
size_t len; /* octets of data to parse */
isc_boolean_t ok; /* is this RDATA valid? */
int lineno; /* source line defining this RDATA */
};
typedef struct wire_ok wire_ok_t;
......@@ -52,8 +53,10 @@ typedef struct wire_ok wire_ok_t;
***** Convenience macros for creating the above structures
*****/
#define TEXT_VALID(data) { data, ISC_TRUE, __LINE__ }
#define TEXT_INVALID(data) { data, ISC_FALSE, __LINE__ }
#define TEXT_VALID_CHANGED(data_in, data_out) \
{ data_in, data_out, __LINE__ }
#define TEXT_VALID(data) { data, data, __LINE__ }
#define TEXT_INVALID(data) { data, NULL, __LINE__ }
#define TEXT_SENTINEL() TEXT_INVALID(NULL)
#define VARGC(...) (sizeof((unsigned char[]){ __VA_ARGS__ }))
......@@ -130,14 +133,17 @@ check_struct_conversions(dns_rdata_t *rdata, size_t structsize, int lineno) {
}
/*
* Test whether supplied RDATA in text format is properly handled as having
* either valid or invalid syntax for an RR of given rdclass and type.
* Check whether converting supplied text form RDATA into uncompressed wire
* form succeeds (tests fromtext_*()). If so, try converting it back into text
* form and see if it results in the original text (tests totext_*()).
*/
static void
check_text_ok_single(const text_ok_t *text_ok, dns_rdataclass_t rdclass,
dns_rdatatype_t type, size_t structsize) {
dns_rdatatype_t type, size_t structsize)
{
isc_buffer_t source, target;
unsigned char buf[1024];
unsigned char buf_fromtext[1024];
char buf_totext[1024] = { 0 };
isc_lex_t *lex = NULL;
isc_result_t result;
dns_rdata_t rdata;
......@@ -148,45 +154,76 @@ check_text_ok_single(const text_ok_t *text_ok, dns_rdataclass_t rdclass,
*/
result = isc_lex_create(mctx, 64, &lex);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
length = strlen(text_ok->data);
isc_buffer_constinit(&source, text_ok->data, length);
length = strlen(text_ok->text_in);
isc_buffer_constinit(&source, text_ok->text_in, length);
isc_buffer_add(&source, length);
result = isc_lex_openbuffer(lex, &source);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
/*
* Initialize target structures.
*/
isc_buffer_init(&target, buf, sizeof(buf));
isc_buffer_init(&target, buf_fromtext, sizeof(buf_fromtext));
dns_rdata_init(&rdata);
/*
* Try converting RDATA text into uncompressed wire form.
* Try converting text form RDATA into uncompressed wire form.
*/
result = dns_rdata_fromtext(&rdata, rdclass, type, lex, dns_rootname,
0, NULL, &target, NULL);
/*
* Destroy lexer now to simplify error handling below.
*/
isc_lex_destroy(&lex);
/*
* Check whether result is as expected.
*/
if (text_ok->ok)
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
else
ATF_REQUIRE(result != ISC_R_SUCCESS);
if (text_ok->text_out != NULL) {
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
"line %d: '%s': "
"expected success, got failure",
text_ok->lineno, text_ok->text_in);
} else {
ATF_REQUIRE_MSG(result != ISC_R_SUCCESS,
"line %d: '%s': "
"expected failure, got success",
text_ok->lineno, text_ok->text_in);
}
/*
* If text was parsed correctly, perform additional two-way
* rdata <-> type-specific struct conversion checks.
* If text form RDATA was not parsed correctly, performing any
* additional checks is pointless.
*/
if (result == ISC_R_SUCCESS)
check_struct_conversions(&rdata, structsize, text_ok->lineno);
isc_lex_destroy(&lex);
if (result != ISC_R_SUCCESS) {
return;
}
/*
* Try converting uncompressed wire form RDATA back into text form and
* check whether the resulting text is the same as the original one.
*/
isc_buffer_init(&target, buf_totext, sizeof(buf_totext));
result = dns_rdata_totext(&rdata, NULL, &target);
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
"line %d: '%s': "
"failed to convert rdata back to text form",
text_ok->lineno, text_ok->text_in);
ATF_REQUIRE_EQ_MSG(strcmp(buf_totext, text_ok->text_out), 0,
"line %d: '%s': "
"converts back to '%s', expected '%s'",
text_ok->lineno, text_ok->text_in, buf_totext,
text_ok->text_out);
/*
* Perform two-way conversion checks between uncompressed wire form and
* type-specific struct.
*/
check_struct_conversions(&rdata, structsize, text_ok->lineno);
}
/*
* Test whether supplied RDATA in wire format is properly handled as being
* either valid or invalid for an RR of given rdclass and type.
* Test whether supplied wire form RDATA is properly handled as being either
* valid or invalid for an RR of given rdclass and type.
*/
static void
check_wire_ok_single(const wire_ok_t *wire_ok, dns_rdataclass_t rdclass,
dns_rdatatype_t type, size_t structsize) {
dns_rdatatype_t type, size_t structsize)
{
isc_buffer_t source, target;
unsigned char buf[1024];
dns_decompress_t dctx;
......@@ -215,7 +252,7 @@ check_wire_ok_single(const wire_ok_t *wire_ok, dns_rdataclass_t rdclass,
/*
* Check whether result is as expected.
*/
if (wire_ok->ok)
if (wire_ok->ok) {
ATF_REQUIRE_EQ_MSG(result, ISC_R_SUCCESS,
"line %d: %s (%lu): "
"expected success, got failure",
......@@ -223,7 +260,7 @@ check_wire_ok_single(const wire_ok_t *wire_ok, dns_rdataclass_t rdclass,
dns_test_tohex(wire_ok->data, wire_ok->len,
hex, sizeof(hex)),
wire_ok->len);
else
} else {
ATF_REQUIRE_MSG(result != ISC_R_SUCCESS,
"line %d: %s (%lu): "
"expected failure, got success",
......@@ -231,30 +268,34 @@ check_wire_ok_single(const wire_ok_t *wire_ok, dns_rdataclass_t rdclass,
dns_test_tohex(wire_ok->data, wire_ok->len,
hex, sizeof(hex)),
wire_ok->len);
}
/*
* If data was parsed correctly, perform additional two-way
* rdata <-> type-specific struct conversion checks.
* If data was parsed correctly, perform two-way conversion checks
* between uncompressed wire form and type-specific struct.
*/
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
check_struct_conversions(&rdata, structsize, wire_ok->lineno);