--- /dev/null
+/*
+ * Copyright (C) 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/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+
+#ifndef RDATA_GENERIC_ATMRELAY_260_C
+#define RDATA_GENERIC_ATMRELAY_260_C
+
+#include <string.h>
+
+#include <isc/net.h>
+
+#define RRTYPE_ATMRELAY_ATTRIBUTES (0)
+
+static inline isc_result_t
+fromtext_atmrelay(ARGS_FROMTEXT) {
+ isc_token_t token;
+ dns_name_t name;
+ isc_buffer_t buffer;
+ unsigned int discovery;
+ unsigned int gateway;
+ struct in_addr addr;
+ unsigned char addr6[16];
+ isc_region_t region;
+
+ REQUIRE(type == dns_rdatatype_atmrelay);
+
+ UNUSED(type);
+ UNUSED(rdclass);
+ UNUSED(callbacks);
+
+ /*
+ * Precedence.
+ */
+ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
+ false));
+ if (token.value.as_ulong > 0xffU) {
+ RETTOK(ISC_R_RANGE);
+ }
+ RETERR(uint8_tobuffer(token.value.as_ulong, target));
+
+ /*
+ * Discovery.
+ */
+ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
+ false));
+ if (token.value.as_ulong > 1U) {
+ RETTOK(ISC_R_RANGE);
+ }
+ discovery = token.value.as_ulong;
+
+ /*
+ * Gateway type.
+ */
+ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
+ false));
+ if (token.value.as_ulong > 0x7fU)
+ RETTOK(ISC_R_RANGE);
+ RETERR(uint8_tobuffer(token.value.as_ulong | (discovery << 7), target));
+ gateway = token.value.as_ulong;
+
+ if (gateway == 0) {
+ return (ISC_R_SUCCESS);
+ }
+
+ if (gateway > 3) {
+ return (ISC_R_NOTIMPLEMENTED);
+ }
+
+ /*
+ * Gateway.
+ */
+ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
+ false));
+
+ switch (gateway) {
+ case 1:
+ if (inet_pton(AF_INET, DNS_AS_STR(token), &addr) != 1) {
+ RETTOK(DNS_R_BADDOTTEDQUAD);
+ }
+ isc_buffer_availableregion(target, ®ion);
+ if (region.length < 4) {
+ return (ISC_R_NOSPACE);
+ }
+ memmove(region.base, &addr, 4);
+ isc_buffer_add(target, 4);
+ return (ISC_R_SUCCESS);
+
+ case 2:
+ if (inet_pton(AF_INET6, DNS_AS_STR(token), addr6) != 1) {
+ RETTOK(DNS_R_BADAAAA);
+ }
+ isc_buffer_availableregion(target, ®ion);
+ if (region.length < 16) {
+ return (ISC_R_NOSPACE);
+ }
+ memmove(region.base, addr6, 16);
+ isc_buffer_add(target, 16);
+ return (ISC_R_SUCCESS);
+
+ case 3:
+ dns_name_init(&name, NULL);
+ buffer_fromregion(&buffer, &token.value.as_region);
+ if (origin == NULL) {
+ origin = dns_rootname;
+ }
+ return (dns_name_fromtext(&name, &buffer, origin, options,
+ target));
+ default:
+ INSIST(0);
+ ISC_UNREACHABLE();
+ }
+}
+
+static inline isc_result_t
+totext_atmrelay(ARGS_TOTEXT) {
+ isc_region_t region;
+ dns_name_t name;
+ char buf[sizeof("0 255 ")];
+ unsigned char precedence;
+ unsigned char discovery;
+ unsigned char gateway;
+ const char *space;
+
+ UNUSED(tctx);
+
+ REQUIRE(rdata->type == dns_rdatatype_atmrelay);
+ REQUIRE(rdata->length >= 2);
+
+ if ((rdata->data[1] & 0x7f) > 3U)
+ return (ISC_R_NOTIMPLEMENTED);
+
+ /*
+ * Precedence.
+ */
+ dns_rdata_toregion(rdata, ®ion);
+ precedence = uint8_fromregion(®ion);
+ isc_region_consume(®ion, 1);
+ snprintf(buf, sizeof(buf), "%u ", precedence);
+ RETERR(str_totext(buf, target));
+
+ /*
+ * Discovery and Gateway type.
+ */
+ gateway = uint8_fromregion(®ion);
+ discovery = gateway >> 7;
+ gateway &= 0x7f;
+ space = (gateway != 0U) ? " " : "";
+ isc_region_consume(®ion, 1);
+ snprintf(buf, sizeof(buf), "%u %u%s", discovery, gateway, space);
+ RETERR(str_totext(buf, target));
+
+ /*
+ * Gateway.
+ */
+ switch (gateway) {
+ case 0:
+ break;
+ case 1:
+ return (inet_totext(AF_INET, ®ion, target));
+
+ case 2:
+ return (inet_totext(AF_INET6, ®ion, target));
+
+ case 3:
+ dns_name_init(&name, NULL);
+ dns_name_fromregion(&name, ®ion);
+ return (dns_name_totext(&name, false, target));
+
+ default:
+ INSIST(0);
+ ISC_UNREACHABLE();
+ }
+ return (ISC_R_SUCCESS);
+}
+
+static inline isc_result_t
+fromwire_atmrelay(ARGS_FROMWIRE) {
+ dns_name_t name;
+ isc_region_t region;
+
+ REQUIRE(type == dns_rdatatype_atmrelay);
+
+ UNUSED(type);
+ UNUSED(rdclass);
+
+ dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
+
+ isc_buffer_activeregion(source, ®ion);
+ if (region.length < 2)
+ return (ISC_R_UNEXPECTEDEND);
+
+ switch (region.base[1] & 0x7f) {
+ case 0:
+ if (region.length != 2) {
+ return (DNS_R_FORMERR);
+ }
+ isc_buffer_forward(source, region.length);
+ return (mem_tobuffer(target, region.base, region.length));
+
+ case 1:
+ if (region.length != 6) {
+ return (DNS_R_FORMERR);
+ }
+ isc_buffer_forward(source, region.length);
+ return (mem_tobuffer(target, region.base, region.length));
+
+ case 2:
+ if (region.length != 18) {
+ return (DNS_R_FORMERR);
+ }
+ isc_buffer_forward(source, region.length);
+ return (mem_tobuffer(target, region.base, region.length));
+
+ case 3:
+ RETERR(mem_tobuffer(target, region.base, 2));
+ isc_buffer_forward(source, 2);
+ dns_name_init(&name, NULL);
+ return (dns_name_fromwire(&name, source, dctx, options,
+ target));
+
+ default:
+ isc_buffer_forward(source, region.length);
+ return (mem_tobuffer(target, region.base, region.length));
+ }
+}
+
+static inline isc_result_t
+towire_atmrelay(ARGS_TOWIRE) {
+ isc_region_t region;
+
+ REQUIRE(rdata->type == dns_rdatatype_atmrelay);
+ REQUIRE(rdata->length != 0);
+
+ UNUSED(cctx);
+
+ dns_rdata_toregion(rdata, ®ion);
+ return (mem_tobuffer(target, region.base, region.length));
+}
+
+static inline int
+compare_atmrelay(ARGS_COMPARE) {
+ isc_region_t region1;
+ isc_region_t region2;
+
+ REQUIRE(rdata1->type == rdata2->type);
+ REQUIRE(rdata1->rdclass == rdata2->rdclass);
+ REQUIRE(rdata1->type == dns_rdatatype_atmrelay);
+ REQUIRE(rdata1->length >= 2);
+ REQUIRE(rdata2->length >= 2);
+
+ dns_rdata_toregion(rdata1, ®ion1);
+ dns_rdata_toregion(rdata2, ®ion2);
+
+ return (isc_region_compare(®ion1, ®ion2));
+}
+
+static inline isc_result_t
+fromstruct_atmrelay(ARGS_FROMSTRUCT) {
+ dns_rdata_atmrelay_t *atmrelay = source;
+ isc_region_t region;
+ uint32_t n;
+
+ REQUIRE(type == dns_rdatatype_atmrelay);
+ REQUIRE(source != NULL);
+ REQUIRE(atmrelay->common.rdtype == type);
+ REQUIRE(atmrelay->common.rdclass == rdclass);
+
+ UNUSED(type);
+ UNUSED(rdclass);
+
+ RETERR(uint8_tobuffer(atmrelay->precedence, target));
+ n = (atmrelay->discovery ? 0x80 : 0) | atmrelay->gateway_type;
+ RETERR(uint8_tobuffer(n, target));
+
+ switch (atmrelay->gateway_type) {
+ case 0:
+ return (ISC_R_SUCCESS);
+
+ case 1:
+ n = ntohl(atmrelay->in_addr.s_addr);
+ return (uint32_tobuffer(n, target));
+
+ case 2:
+ return (mem_tobuffer(target, atmrelay->in6_addr.s6_addr, 16));
+ break;
+
+ case 3:
+ dns_name_toregion(&atmrelay->gateway, ®ion);
+ return (isc_buffer_copyregion(target, ®ion));
+ break;
+
+ default:
+ return (mem_tobuffer(target, atmrelay->data, atmrelay->length));
+ }
+}
+
+static inline isc_result_t
+tostruct_atmrelay(ARGS_TOSTRUCT) {
+ isc_region_t region;
+ dns_rdata_atmrelay_t *atmrelay = target;
+ dns_name_t name;
+ uint32_t n;
+
+ REQUIRE(rdata->type == dns_rdatatype_atmrelay);
+ REQUIRE(target != NULL);
+ REQUIRE(rdata->length >= 2);
+
+ atmrelay->common.rdclass = rdata->rdclass;
+ atmrelay->common.rdtype = rdata->type;
+ ISC_LINK_INIT(&atmrelay->common, link);
+
+ dns_name_init(&atmrelay->gateway, NULL);
+ atmrelay->data = NULL;
+
+ dns_name_init(&name, NULL);
+ dns_rdata_toregion(rdata, ®ion);
+
+ atmrelay->precedence = uint8_fromregion(®ion);
+ isc_region_consume(®ion, 1);
+
+ atmrelay->gateway_type = uint8_fromregion(®ion);
+ atmrelay->discovery = (atmrelay->gateway_type & 0x80) != 0;
+ atmrelay->gateway_type &= 0x7f;
+ isc_region_consume(®ion, 1);
+
+ switch (atmrelay->gateway_type) {
+ case 0:
+ break;
+
+ case 1:
+ n = uint32_fromregion(®ion);
+ atmrelay->in_addr.s_addr = htonl(n);
+ isc_region_consume(®ion, 4);
+ break;
+
+ case 2:
+ memmove(atmrelay->in6_addr.s6_addr, region.base, 16);
+ isc_region_consume(®ion, 16);
+ break;
+
+ case 3:
+ dns_name_fromregion(&name, ®ion);
+ RETERR(name_duporclone(&name, mctx, &atmrelay->gateway));
+ isc_region_consume(®ion, name_length(&name));
+ break;
+
+ default:
+ if (region.length != 0) {
+ atmrelay->data = mem_maybedup(mctx, region.base,
+ region.length);
+ if (atmrelay->data == NULL) {
+ return (ISC_R_NOMEMORY);
+ }
+ }
+ atmrelay->length = region.length;
+ }
+ atmrelay->mctx = mctx;
+ return (ISC_R_SUCCESS);
+}
+
+static inline void
+freestruct_atmrelay(ARGS_FREESTRUCT) {
+ dns_rdata_atmrelay_t *atmrelay = source;
+
+ REQUIRE(source != NULL);
+ REQUIRE(atmrelay->common.rdtype == dns_rdatatype_atmrelay);
+
+ if (atmrelay->mctx == NULL)
+ return;
+
+ if (atmrelay->gateway_type == 3)
+ dns_name_free(&atmrelay->gateway, atmrelay->mctx);
+
+ if (atmrelay->data != NULL)
+ isc_mem_free(atmrelay->mctx, atmrelay->data);
+
+ atmrelay->mctx = NULL;
+}
+
+static inline isc_result_t
+additionaldata_atmrelay(ARGS_ADDLDATA) {
+
+ REQUIRE(rdata->type == dns_rdatatype_atmrelay);
+
+ UNUSED(rdata);
+ UNUSED(add);
+ UNUSED(arg);
+
+ return (ISC_R_SUCCESS);
+}
+
+static inline isc_result_t
+digest_atmrelay(ARGS_DIGEST) {
+ isc_region_t region;
+
+ REQUIRE(rdata->type == dns_rdatatype_atmrelay);
+
+ dns_rdata_toregion(rdata, ®ion);
+ return ((digest)(arg, ®ion));
+}
+
+static inline bool
+checkowner_atmrelay(ARGS_CHECKOWNER) {
+
+ REQUIRE(type == dns_rdatatype_atmrelay);
+
+ UNUSED(name);
+ UNUSED(type);
+ UNUSED(rdclass);
+ UNUSED(wildcard);
+
+ return (true);
+}
+
+static inline bool
+checknames_atmrelay(ARGS_CHECKNAMES) {
+
+ REQUIRE(rdata->type == dns_rdatatype_atmrelay);
+
+ UNUSED(rdata);
+ UNUSED(owner);
+ UNUSED(bad);
+
+ return (true);
+}
+
+static inline int
+casecompare_atmrelay(ARGS_COMPARE) {
+ isc_region_t region1;
+ isc_region_t region2;
+ dns_name_t name1;
+ dns_name_t name2;
+
+ REQUIRE(rdata1->type == rdata2->type);
+ REQUIRE(rdata1->rdclass == rdata2->rdclass);
+ REQUIRE(rdata1->type == dns_rdatatype_atmrelay);
+ REQUIRE(rdata1->length >= 2);
+ REQUIRE(rdata2->length >= 2);
+
+ dns_rdata_toregion(rdata1, ®ion1);
+ dns_rdata_toregion(rdata2, ®ion2);
+
+ if (memcmp(region1.base, region2.base, 2) != 0 ||
+ (region1.base[1] & 0x7f) != 3)
+ return (isc_region_compare(®ion1, ®ion2));
+
+ dns_name_init(&name1, NULL);
+ dns_name_init(&name2, NULL);
+
+ isc_region_consume(®ion1, 2);
+ isc_region_consume(®ion2, 2);
+
+ dns_name_fromregion(&name1, ®ion1);
+ dns_name_fromregion(&name2, ®ion2);
+
+ return (dns_name_rdatacompare(&name1, &name2));
+}
+
+#endif /* RDATA_GENERIC_ATMRELAY_260_C */
dns_rdatatype_atma, sizeof(dns_rdata_in_atma_t));
}
+/* ATMRELAY RDATA manipulations */
+static void
+atmrelay(void **state) {
+ text_ok_t text_ok[] = {
+ TEXT_INVALID(""),
+ TEXT_INVALID("0"),
+ TEXT_INVALID("0 0"),
+ /* gatway type 0 */
+ TEXT_VALID("0 0 0"),
+ TEXT_VALID("0 1 0"),
+ TEXT_INVALID("0 2 0"), /* discovery out of range */
+ TEXT_VALID("255 1 0"), /* max precendence */
+ TEXT_INVALID("256 1 0"), /* precedence out of range */
+
+ /* IPv4 gateway */
+ TEXT_INVALID("0 0 1"), /* no addresss */
+ TEXT_VALID("0 0 1 0.0.0.0"),
+ TEXT_INVALID("0 0 1 0.0.0.0 x"), /* extra */
+ TEXT_INVALID("0 0 1 0.0.0.0.0"), /* bad addresss */
+ TEXT_INVALID("0 0 1 ::"), /* bad addresss */
+ TEXT_INVALID("0 0 1 ."), /* bad addresss */
+
+ /* IPv6 gateway */
+ TEXT_INVALID("0 0 2"), /* no addresss */
+ TEXT_VALID("0 0 2 ::"),
+ TEXT_INVALID("0 0 2 :: xx"), /* extra */
+ TEXT_INVALID("0 0 2 0.0.0.0"), /* bad addresss */
+ TEXT_INVALID("0 0 2 ."), /* bad addresss */
+
+ /* hostname gateway */
+ TEXT_INVALID("0 0 3"), /* no name */
+ /* IPv4 is a valid name */
+ TEXT_VALID_CHANGED("0 0 3 0.0.0.0", "0 0 3 0.0.0.0."),
+ /* IPv6 is a valid name */
+ TEXT_VALID_CHANGED("0 0 3 ::", "0 0 3 ::."),
+ TEXT_VALID_CHANGED("0 0 3 example", "0 0 3 example."),
+ TEXT_VALID("0 0 3 example."),
+ TEXT_INVALID("0 0 3 example. x"), /* extra */
+
+ /* unknown gateway */
+ TEXT_VALID("\\# 2 0004"),
+ TEXT_VALID("\\# 2 0084"),
+ TEXT_VALID("\\# 2 007F"),
+ TEXT_VALID("\\# 3 000400"),
+ TEXT_VALID("\\# 3 008400"),
+ TEXT_VALID("\\# 3 00FF00"),
+
+ /*
+ * Sentinel.
+ */
+ TEXT_SENTINEL()
+ };
+ wire_ok_t wire_ok[] = {
+ WIRE_INVALID(0x00),
+ WIRE_VALID(0x00, 0x00),
+ WIRE_VALID(0x00, 0x80),
+ WIRE_INVALID(0x00, 0x00, 0x00),
+ WIRE_INVALID(0x00, 0x80, 0x00),
+
+ WIRE_INVALID(0x00, 0x01),
+ WIRE_INVALID(0x00, 0x01, 0x00),
+ WIRE_INVALID(0x00, 0x01, 0x00, 0x00),
+ WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x00),
+ WIRE_VALID(0x00, 0x01, 0x00, 0x00, 0x00, 0x00),
+ WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00),
+
+ WIRE_INVALID(0x00, 0x02),
+ WIRE_INVALID(0x00, 0x02, 0x00),
+ WIRE_VALID(0x00, 0x02, 0x00, 0x01, 0x02, 0x03, 0x04,
+ 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11,
+ 0x12, 0x13, 0x14, 0x15),
+ WIRE_INVALID(0x00, 0x02, 0x00, 0x01, 0x02, 0x03, 0x04,
+ 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11,
+ 0x12, 0x13, 0x14, 0x15, 0x16),
+
+ WIRE_INVALID(0x00, 0x03),
+ WIRE_VALID(0x00, 0x03, 0x00),
+ WIRE_INVALID(0x00, 0x03, 0x00, 0x00), /* extra */
+
+ WIRE_VALID(0x00, 0x04),
+ WIRE_VALID(0x00, 0x04, 0x00),
+ /*
+ * Sentinel.
+ */
+ WIRE_SENTINEL()
+ };
+
+ UNUSED(state);
+
+ check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
+ dns_rdatatype_atmrelay, sizeof(dns_rdata_atmrelay_t));
+}
+
/*
* CSYNC tests.
*
const struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(apl, _setup, _teardown),
cmocka_unit_test_setup_teardown(atma, _setup, _teardown),
+ cmocka_unit_test_setup_teardown(atmrelay, _setup, _teardown),
cmocka_unit_test_setup_teardown(csync, _setup, _teardown),
cmocka_unit_test_setup_teardown(doa, _setup, _teardown),
cmocka_unit_test_setup_teardown(eid, _setup, _teardown),