Skip to content

Commit

Permalink
AMTRELAY RR type
Browse files Browse the repository at this point in the history
  • Loading branch information
wtoorop committed Jan 21, 2025
1 parent b913eda commit 4892c59
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 69 deletions.
2 changes: 2 additions & 0 deletions include/zone.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ extern "C" {
#define ZONE_TYPE_AVC (258u)
/** Digital Object Architecture @draft{durand, doa-over-dns} */
#define ZONE_TYPE_DOA (259u)
/** Automatic Multicast Tunneling Relay @rfc{8777} */
#define ZONE_TYPE_AMTRELAY (260u)
/** Resolver Information as Key/Value Pairs @rfc{9606} */
#define ZONE_TYPE_RESINFO (261u)
/** Public wallet address */
Expand Down
1 change: 1 addition & 0 deletions scripts/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ static const tuple_t types_and_classes[] = {
{ "CAA", 257, true },
{ "AVC", 258, true },
{ "DOA", 259, true },
{ "AMTRELAY", 260, true },
{ "RESINFO", 261, true },
{ "WALLET", 262, true },
{ "CLA", 263, true },
Expand Down
66 changes: 33 additions & 33 deletions src/generic/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@ static const struct {
const mnemonic_t *mnemonic;
int32_t code;
} types_and_classes[256] = {
V(0), T(107), V(0), T(46), V(0), T(31), T(17), V(0),
V(0), V(0), V(0), V(0), T(104), T(10), T(52), V(0),
V(0), T(28), T(105), V(0), V(0), V(0), V(0), V(0),
V(0), V(0), V(0), V(0), V(0), T(50), V(0), T(257),
V(0), V(0), V(0), V(0), V(0), T(3), T(45), V(0),
V(0), T(62), T(263), V(0), V(0), V(0), T(66), T(65),
V(0), V(0), T(20), V(0), T(22), T(1), V(0), T(108),
V(0), T(51), V(0), T(12), V(0), V(0), V(0), V(0),
T(262), T(258), V(0), V(0), T(42), V(0), V(0), V(0),
V(0), T(55), T(23), T(11), V(0), V(0), T(27), V(0),
T(21), V(0), V(0), T(18), V(0), V(0), V(0), V(0),
V(0), T(33), C(1), V(0), V(0), V(0), T(266), V(0),
V(0), T(24), T(39), T(30), V(0), V(0), C(3), T(5),
T(16), V(0), T(106), T(64), V(0), V(0), T(35), V(0),
V(0), C(2), T(43), V(0), V(0), C(4), V(0), V(0),
V(0), T(59), T(2), T(109), V(0), V(0), V(0), T(44),
T(7), V(0), V(0), V(0), V(0), V(0), V(0), V(0),
V(0), T(29), V(0), V(0), V(0), V(0), V(0), V(0),
V(0), V(0), V(0), V(0), T(36), T(15), V(0), T(32),
T(26), T(38), T(19), V(0), T(8), V(0), V(0), V(0),
V(0), T(60), T(259), V(0), V(0), V(0), V(0), T(9),
T(256), V(0), V(0), V(0), V(0), V(0), T(6), V(0),
V(0), T(99), V(0), T(265), T(53), V(0), V(0), T(49),
T(37), V(0), V(0), V(0), V(0), V(0), V(0), V(0),
V(0), T(48), V(0), V(0), V(0), T(57), T(58), V(0),
V(0), T(4), V(0), V(0), V(0), V(0), V(0), V(0),
V(0), V(0), V(0), V(0), V(0), V(0), V(0), V(0),
V(0), V(0), T(63), V(0), V(0), V(0), V(0), V(0),
V(0), V(0), V(0), V(0), V(0), V(0), T(56), T(14),
V(0), V(0), V(0), T(13), V(0), T(40), V(0), V(0),
V(0), T(34), V(0), T(25), V(0), V(0), V(0), T(47),
T(61), V(0), V(0), V(0), V(0), V(0), V(0), T(261)
V(0), V(0), V(0), V(0), V(0), V(0), T(34), V(0),
V(0), V(0), T(30), V(0), V(0), T(57), V(0), T(16),
V(0), V(0), T(56), T(14), T(12), V(0), V(0), T(13),
T(61), V(0), T(105), V(0), V(0), V(0), T(32), T(258),
V(0), T(107), T(47), V(0), V(0), V(0), T(17), V(0),
T(257), V(0), V(0), V(0), V(0), V(0), V(0), V(0),
T(65), V(0), V(0), T(18), V(0), T(1), V(0), T(263),
V(0), V(0), V(0), V(0), T(51), V(0), V(0), T(106),
T(3), V(0), V(0), T(31), V(0), V(0), V(0), V(0),
V(0), T(50), T(44), T(104), T(10), V(0), V(0), V(0),
V(0), V(0), T(55), V(0), T(28), V(0), V(0), V(0),
V(0), V(0), V(0), V(0), V(0), V(0), V(0), T(39),
T(35), V(0), V(0), T(5), T(29), T(262), V(0), V(0),
T(109), V(0), V(0), V(0), V(0), V(0), V(0), V(0),
V(0), T(21), V(0), V(0), V(0), V(0), V(0), V(0),
T(37), C(1), T(58), V(0), V(0), V(0), V(0), V(0),
V(0), V(0), V(0), C(3), V(0), T(52), T(11), T(20),
V(0), T(261), V(0), V(0), V(0), T(48), V(0), V(0),
V(0), T(25), C(2), T(43), V(0), V(0), C(4), T(60),
V(0), V(0), T(7), T(2), V(0), V(0), T(46), T(22),
V(0), V(0), V(0), V(0), V(0), V(0), V(0), T(64),
V(0), T(260), V(0), V(0), V(0), V(0), T(38), V(0),
V(0), T(259), T(59), V(0), V(0), V(0), T(42), T(36),
T(8), T(15), V(0), T(26), T(27), T(6), V(0), T(99),
V(0), V(0), V(0), V(0), V(0), V(0), V(0), T(53),
T(9), T(63), T(33), V(0), T(266), T(265), V(0), T(40),
V(0), V(0), T(24), T(19), V(0), V(0), V(0), V(0),
V(0), V(0), V(0), T(108), V(0), V(0), V(0), T(62),
V(0), V(0), V(0), V(0), V(0), T(66), T(4), V(0),
V(0), V(0), T(256), V(0), T(49), V(0), V(0), V(0),
V(0), V(0), T(45), V(0), V(0), T(23), V(0), V(0),
V(0), V(0), V(0), V(0), V(0), V(0), V(0), V(0)
};

#undef V
Expand Down Expand Up @@ -110,7 +110,7 @@ static really_inline uint8_t hash(uint64_t prefix)
prefix = le64toh(prefix);
uint32_t value = (uint32_t)((prefix >> 32) ^ prefix);
// magic value is generated using hash.c, rerun when adding types
return (uint8_t)((value * 3530565426ull) >> 32);
return (uint8_t)((value * 3537259401ull) >> 32);
}

nonnull_all
Expand Down
159 changes: 156 additions & 3 deletions src/generic/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2636,6 +2636,150 @@ static int32_t parse_doa_rdata(
return accept_rr(parser, type, rdata);
}

nonnull_all
static int32_t check_amtrelay_rr(
parser_t *parser, const type_info_t *type, const rdata_t *rdata);

nonnull_all
static int32_t parse_amtrelay_rdata(
parser_t *parser, const type_info_t *type, rdata_t *rdata, token_t *token);

diagnostic_push()
gcc_diagnostic_ignored(missing-field-initializers)
clang_diagnostic_ignored(missing-field-initializers)

static const rdata_info_t amtrelay_ipv4_rdata_fields[] = {
FIELD("precedence"),
FIELD("discovery optional"),
FIELD("type"),
FIELD("relay")
};

static const type_info_t amtrelay_ipv4[] = {
TYPE("AMTRELAY", ZONE_TYPE_AMTRELAY, ZONE_CLASS_IN, FIELDS(amtrelay_ipv4_rdata_fields),
check_amtrelay_rr, parse_amtrelay_rdata),
};

static const rdata_info_t amtrelay_ipv6_rdata_fields[] = {
FIELD("precedence"),
FIELD("discovery optional"),
FIELD("type"),
FIELD("relay")
};

static const type_info_t amtrelay_ipv6[] = {
TYPE("AMTRELAY", ZONE_TYPE_AMTRELAY, ZONE_CLASS_IN, FIELDS(amtrelay_ipv6_rdata_fields),
check_amtrelay_rr, parse_amtrelay_rdata),
};

diagnostic_pop()

nonnull_all
static int32_t check_amtrelay_rr(
parser_t *parser, const type_info_t *type, const rdata_t *rdata)
{
int32_t r;
size_t c = 0;
const size_t n = (uintptr_t)rdata->octets - (uintptr_t)parser->rdata->octets;
const uint8_t *o = parser->rdata->octets;
const type_info_t *t = type;
const rdata_info_t *f = type->rdata.fields;

if ((r = check(&c, check_int8(parser, type, &f[0], o, n))) ||
(r = check(&c, check_int8(parser, type, &f[2], o+c, n-c))))
return r;

switch (parser->rdata->octets[1] & 0x7f) {
case 1: /* IPv4 address */
t = (const type_info_t *)amtrelay_ipv4;
f = amtrelay_ipv4_rdata_fields;
if ((r = check(&c, check_ip4(parser, t, &f[3], o+c, n-c))) < 0)
return r;
break;
case 2: /* IPv6 address */
t = (const type_info_t *)amtrelay_ipv6;
f = amtrelay_ipv6_rdata_fields;
if ((r = check(&c, check_ip6(parser, t, &f[3], o+c, n-c))) < 0)
return r;
break;
case 0: /* no gateway */
break;
case 3: /* domain name */
if ((r = check(&c, check_name(parser, t, &f[3], o+c, n-c))) < 0)
return r;
break;
default:
SYNTAX_ERROR(parser, "Invalid %s", NAME(type));
}
if (c < n)
SYNTAX_ERROR(parser, "Trailing data in %s", NAME(t));
return accept_rr(parser, t, rdata);
}

nonnull_all
static int32_t parse_amtrelay_rdata(
parser_t *parser, const type_info_t *type, rdata_t *rdata, token_t *token)
{
int32_t code;
const rdata_info_t *fields = type->rdata.fields;
uint8_t *octets = rdata->octets;
uint8_t D;

if ((code = have_contiguous(parser, type, &fields[0], token)) < 0)
return code;
if ((code = parse_int8(parser, type, &fields[0], rdata, token)) < 0)
return code;

if ((code = take_contiguous(parser, type, &fields[1], token)) < 0)
return code;
if (token->length != 1)
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(&fields[1]), NAME(type));
switch((char)*token->data) {
case '0':
D = 0x00;
break;
case '1':
D = 0x80;
break;
default :
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(&fields[1]), NAME(type));
}

if ((code = take_contiguous(parser, type, &fields[2], token)) < 0)
return code;
if ((code = parse_int8(parser, type, &fields[2], rdata, token)) < 0)
return code;

if (octets[1]) {
if ((code = take_contiguous(parser, type, &fields[3], token)) < 0)
return code;
switch (octets[1]) {
case 1: /* IPv4 address */
type = (const type_info_t *)amtrelay_ipv4;
fields = type->rdata.fields;
if ((code = parse_ip4(parser, type, &fields[3], rdata, token)) < 0)
return code;
break;
case 2: /* IPv6 address */
type = (const type_info_t *)amtrelay_ipv6;
fields = type->rdata.fields;
if ((code = parse_ip6(parser, type, &fields[3], rdata, token)) < 0)
return code;
break;
case 3: /* domain name */
if ((code = parse_name(parser, type, &fields[3], rdata, token)) < 0)
return code;
break;
default:
SYNTAX_ERROR(parser, "Invalid %s in %s", NAME(&fields[3]), NAME(type));
}
}
octets[1] |= D;
if ((code = take_delimiter(parser, type, token)) < 0)
return code;
return accept_rr(parser, type, rdata);
}

nonnull_all
static int32_t check_generic_rr(
parser_t *parser, const type_info_t *type, const rdata_t *rdata)
Expand Down Expand Up @@ -3137,6 +3281,16 @@ static const rdata_info_t doa_rdata_fields[] = {
FIELD("data")
};

// RFC 8777
// AMTRELAY is different because the rdata depends on the type
static const rdata_info_t amtrelay_rdata_fields[] = {
FIELD("precedence"),
FIELD("discovery optional"),
FIELD("type"),
FIELD("relay"),
};


// RFC 9606
static const rdata_info_t resinfo_rdata_fields[] = {
FIELD("text")
Expand Down Expand Up @@ -3514,9 +3668,8 @@ static const type_info_t types[] = {
check_txt_rr, parse_txt_rdata),
TYPE("DOA", ZONE_TYPE_DOA, ZONE_CLASS_ANY, FIELDS(doa_rdata_fields),
check_doa_rr, parse_doa_rdata),

UNKNOWN_TYPE(260),

TYPE("AMTRELAY", ZONE_TYPE_AMTRELAY, ZONE_CLASS_ANY, FIELDS(amtrelay_rdata_fields),
check_amtrelay_rr, parse_amtrelay_rdata),
TYPE("RESINFO", ZONE_TYPE_RESINFO, ZONE_CLASS_ANY, FIELDS(resinfo_rdata_fields),
check_txt_rr, parse_txt_rdata),
TYPE("WALLET", ZONE_TYPE_WALLET, ZONE_CLASS_ANY, FIELDS(wallet_rdata_fields),
Expand Down
66 changes: 33 additions & 33 deletions src/westmere/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,38 @@ static const struct {
const mnemonic_t *mnemonic;
int32_t code;
} types_and_classes[256] = {
V(0), T(107), V(0), T(46), V(0), T(31), T(17), V(0),
V(0), V(0), V(0), V(0), T(104), T(10), T(52), V(0),
V(0), T(28), T(105), V(0), V(0), V(0), V(0), V(0),
V(0), V(0), V(0), V(0), V(0), T(50), V(0), T(257),
V(0), V(0), V(0), V(0), V(0), T(3), T(45), V(0),
V(0), T(62), T(263), V(0), V(0), V(0), T(66), T(65),
V(0), V(0), T(20), V(0), T(22), T(1), V(0), T(108),
V(0), T(51), V(0), T(12), V(0), V(0), V(0), V(0),
T(262), T(258), V(0), V(0), T(42), V(0), V(0), V(0),
V(0), T(55), T(23), T(11), V(0), V(0), T(27), V(0),
T(21), V(0), V(0), T(18), V(0), V(0), V(0), V(0),
V(0), T(33), C(1), V(0), V(0), V(0), T(266), V(0),
V(0), T(24), T(39), T(30), V(0), V(0), C(3), T(5),
T(16), V(0), T(106), T(64), V(0), V(0), T(35), V(0),
V(0), C(2), T(43), V(0), V(0), C(4), V(0), V(0),
V(0), T(59), T(2), T(109), V(0), V(0), V(0), T(44),
T(7), V(0), V(0), V(0), V(0), V(0), V(0), V(0),
V(0), T(29), V(0), V(0), V(0), V(0), V(0), V(0),
V(0), V(0), V(0), V(0), T(36), T(15), V(0), T(32),
T(26), T(38), T(19), V(0), T(8), V(0), V(0), V(0),
V(0), T(60), T(259), V(0), V(0), V(0), V(0), T(9),
T(256), V(0), V(0), V(0), V(0), V(0), T(6), V(0),
V(0), T(99), V(0), T(265), T(53), V(0), V(0), T(49),
T(37), V(0), V(0), V(0), V(0), V(0), V(0), V(0),
V(0), T(48), V(0), V(0), V(0), T(57), T(58), V(0),
V(0), T(4), V(0), V(0), V(0), V(0), V(0), V(0),
V(0), V(0), V(0), V(0), V(0), V(0), V(0), V(0),
V(0), V(0), T(63), V(0), V(0), V(0), V(0), V(0),
V(0), V(0), V(0), V(0), V(0), V(0), T(56), T(14),
V(0), V(0), V(0), T(13), V(0), T(40), V(0), V(0),
V(0), T(34), V(0), T(25), V(0), V(0), V(0), T(47),
T(61), V(0), V(0), V(0), V(0), V(0), V(0), T(261)
V(0), V(0), V(0), V(0), V(0), V(0), T(34), V(0),
V(0), V(0), T(30), V(0), V(0), T(57), V(0), T(16),
V(0), V(0), T(56), T(14), T(12), V(0), V(0), T(13),
T(61), V(0), T(105), V(0), V(0), V(0), T(32), T(258),
V(0), T(107), T(47), V(0), V(0), V(0), T(17), V(0),
T(257), V(0), V(0), V(0), V(0), V(0), V(0), V(0),
T(65), V(0), V(0), T(18), V(0), T(1), V(0), T(263),
V(0), V(0), V(0), V(0), T(51), V(0), V(0), T(106),
T(3), V(0), V(0), T(31), V(0), V(0), V(0), V(0),
V(0), T(50), T(44), T(104), T(10), V(0), V(0), V(0),
V(0), V(0), T(55), V(0), T(28), V(0), V(0), V(0),
V(0), V(0), V(0), V(0), V(0), V(0), V(0), T(39),
T(35), V(0), V(0), T(5), T(29), T(262), V(0), V(0),
T(109), V(0), V(0), V(0), V(0), V(0), V(0), V(0),
V(0), T(21), V(0), V(0), V(0), V(0), V(0), V(0),
T(37), C(1), T(58), V(0), V(0), V(0), V(0), V(0),
V(0), V(0), V(0), C(3), V(0), T(52), T(11), T(20),
V(0), T(261), V(0), V(0), V(0), T(48), V(0), V(0),
V(0), T(25), C(2), T(43), V(0), V(0), C(4), T(60),
V(0), V(0), T(7), T(2), V(0), V(0), T(46), T(22),
V(0), V(0), V(0), V(0), V(0), V(0), V(0), T(64),
V(0), T(260), V(0), V(0), V(0), V(0), T(38), V(0),
V(0), T(259), T(59), V(0), V(0), V(0), T(42), T(36),
T(8), T(15), V(0), T(26), T(27), T(6), V(0), T(99),
V(0), V(0), V(0), V(0), V(0), V(0), V(0), T(53),
T(9), T(63), T(33), V(0), T(266), T(265), V(0), T(40),
V(0), V(0), T(24), T(19), V(0), V(0), V(0), V(0),
V(0), V(0), V(0), T(108), V(0), V(0), V(0), T(62),
V(0), V(0), V(0), V(0), V(0), T(66), T(4), V(0),
V(0), V(0), T(256), V(0), T(49), V(0), V(0), V(0),
V(0), V(0), T(45), V(0), V(0), T(23), V(0), V(0),
V(0), V(0), V(0), V(0), V(0), V(0), V(0), V(0)
};

#undef V
Expand Down Expand Up @@ -102,7 +102,7 @@ static really_inline uint8_t hash(uint64_t prefix)
{
uint32_t value = (uint32_t)((prefix >> 32) ^ prefix);
// magic value is generated using hash.c, rerun when adding types
return (uint8_t)((value * 3530565426ull) >> 32);
return (uint8_t)((value * 3537259401ull) >> 32);
}

nonnull_all
Expand Down
Loading

0 comments on commit 4892c59

Please sign in to comment.