Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,24 @@ int32_t zone_check_tlsa_rdata(
return accept_rr(parser);
}

zone_nonnull_all
int32_t zone_check_nid_rdata(
zone_parser_t *parser, const zone_type_info_t *type)
{
int32_t r;
size_t c = 0;
const size_t n = parser->rdata->length;
const uint8_t *o = parser->rdata->octets;
const zone_field_info_t *f = type->rdata.fields;

if ((r = add(&c, check_int16(parser, type, &f[0], o, n))) ||
(r = add(&c, check_ilnp64(parser, type, &f[1], o+c, n-c))))
return r;
if (c != n)
SYNTAX_ERROR(parser, "Invalid %s", TNAME(type));
return accept_rr(parser);
}

zone_nonnull_all
int32_t zone_check_l32_rdata(
zone_parser_t *parser, const zone_type_info_t *type)
Expand Down
30 changes: 29 additions & 1 deletion src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,28 @@ static int32_t parse_zonemd_rdata(
return accept_rr(parser);
}

zone_nonnull_all
extern int32_t zone_check_nid_rdata(
zone_parser_t *parser, const zone_type_info_t *type);

zone_nonnull_all
static zone_really_inline int32_t parse_nid_rdata(
zone_parser_t *parser, const zone_type_info_t *type, token_t *token)
{
int32_t r;

if ((r = parse_int16(parser, type, &type->rdata.fields[0], token)) < 0)
return r;
lex(parser, token);
if ((r = parse_ilnp64(parser, type, &type->rdata.fields[1], token)) < 0)
return r;
lex(parser, token);
if ((r = have_delimiter(parser, type, token)) < 0)
return r;

return accept_rr(parser);
}

zone_nonnull_all
extern int32_t zone_check_l32_rdata(
zone_parser_t *parser, const zone_type_info_t *type);
Expand Down Expand Up @@ -1271,6 +1293,11 @@ static const zone_field_info_t spf_rdata_fields[] = {
FIELD("text", ZONE_STRING, ZONE_SEQUENCE)
};

static const zone_field_info_t nid_rdata_fields[] = {
FIELD("preference", ZONE_INT16, 0),
FIELD("nodeid", ZONE_ILNP64, 0)
};

// RFC6742 specifies the syntax for the locator is compatible with the syntax
// for IPv4 addresses, but then proceeds to provide an example with leading
// zeroes. The example is corrected in the errata.
Expand Down Expand Up @@ -1494,8 +1521,9 @@ static const type_descriptor_t types[] = {
UNKNOWN_TYPE(101),
UNKNOWN_TYPE(102),
UNKNOWN_TYPE(103),
UNKNOWN_TYPE(104),

TYPE("NID", ZONE_NID, ZONE_ANY, FIELDS(nid_rdata_fields),
zone_check_nid_rdata, parse_nid_rdata),
TYPE("L32", ZONE_L32, ZONE_ANY, FIELDS(l32_rdata_fields),
zone_check_l32_rdata, parse_l32_rdata),
TYPE("L64", ZONE_L64, ZONE_ANY, FIELDS(l64_rdata_fields),
Expand Down
9 changes: 9 additions & 0 deletions tests/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,13 @@ static const char spf_generic_text[] =
static const rdata_t spf_rdata =
RDATA(0x0b, 'v', '=', 's', 'p', 'f', '1', ' ', '+', 'a', 'l', 'l');

static const char nid_text[] =
PAD(" NID 10 0014:4fff:ff20:ee64");
static const char nid_generic_text[] =
PAD(" TYPE104 \\# 10 000a 0014 4fff ff20 ee64");
static const rdata_t nid_rdata =
RDATA(0x00, 0x0a, 0x00, 0x14, 0x4f, 0xff, 0xff, 0x20, 0xee, 0x64);

static const char l32_text[] =
PAD(" L32 10 10.1.2.0");
static const char l32_generic_text[] =
Expand Down Expand Up @@ -705,6 +712,8 @@ static const test_t tests[] = {
{ ZONE_ZONEMD, zonemd_generic_text, &zonemd_rdata },
{ ZONE_SPF, spf_text, &spf_rdata },
{ ZONE_SPF, spf_generic_text, &spf_rdata },
{ ZONE_NID, nid_text, &nid_rdata },
{ ZONE_NID, nid_generic_text, &nid_rdata },
{ ZONE_L32, l32_text, &l32_rdata },
{ ZONE_L32, l32_generic_text, &l32_rdata },
{ ZONE_L64, l64_text, &l64_rdata },
Expand Down