f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews/*
a134177ed9f82189504191d90f3ed9e97c2b47cbTinderbox User * Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC")
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews */
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#ifndef RDATA_GENERIC_L64_106_C
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define RDATA_GENERIC_L64_106_C
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#include <string.h>
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#include <isc/net.h>
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#define RRTYPE_L64_ATTRIBUTES (0)
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsstatic inline isc_result_t
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsfromtext_l64(ARGS_FROMTEXT) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews isc_token_t token;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews unsigned char locator[NS_LOCATORSZ];
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_l64);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(type);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(rdclass);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(origin);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(options);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(callbacks);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews ISC_FALSE));
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews if (token.value.as_ulong > 0xffffU)
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews RETTOK(ISC_R_RANGE);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews RETERR(uint16_tobuffer(token.value.as_ulong, target));
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews ISC_FALSE));
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews if (locator_pton(DNS_AS_STR(token), locator) != 1)
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews RETTOK(DNS_R_SYNTAX);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (mem_tobuffer(target, locator, NS_LOCATORSZ));
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews}
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsstatic inline isc_result_t
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewstotext_l64(ARGS_TOTEXT) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews isc_region_t region;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews char buf[sizeof("xxxx:xxxx:xxxx:xxxx")];
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews unsigned short num;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_l64);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews REQUIRE(rdata->length == 10);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(tctx);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews dns_rdata_toregion(rdata, &region);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews num = uint16_fromregion(&region);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews isc_region_consume(&region, 2);
ad1317338af79edad878c9c3e4361798503310baMark Andrews snprintf(buf, sizeof(buf), "%u", num);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews RETERR(str_totext(buf, target));
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews RETERR(str_totext(" ", target));
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
ad1317338af79edad878c9c3e4361798503310baMark Andrews snprintf(buf, sizeof(buf), "%x:%x:%x:%x",
ad1317338af79edad878c9c3e4361798503310baMark Andrews region.base[0]<<8 | region.base[1],
ad1317338af79edad878c9c3e4361798503310baMark Andrews region.base[2]<<8 | region.base[3],
ad1317338af79edad878c9c3e4361798503310baMark Andrews region.base[4]<<8 | region.base[5],
ad1317338af79edad878c9c3e4361798503310baMark Andrews region.base[6]<<8 | region.base[7]);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (str_totext(buf, target));
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews}
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsstatic inline isc_result_t
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsfromwire_l64(ARGS_FROMWIRE) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews isc_region_t sregion;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_l64);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(type);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(options);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(rdclass);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(dctx);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews isc_buffer_activeregion(source, &sregion);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews if (sregion.length != 10)
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (DNS_R_FORMERR);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews isc_buffer_forward(source, sregion.length);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (mem_tobuffer(target, sregion.base, sregion.length));
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews}
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsstatic inline isc_result_t
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewstowire_l64(ARGS_TOWIRE) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_l64);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews REQUIRE(rdata->length == 10);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(cctx);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (mem_tobuffer(target, rdata->data, rdata->length));
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews}
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsstatic inline int
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewscompare_l64(ARGS_COMPARE) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews isc_region_t region1;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews isc_region_t region2;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews REQUIRE(rdata1->type == rdata2->type);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews REQUIRE(rdata1->rdclass == rdata2->rdclass);
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata1->type == dns_rdatatype_l64);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews REQUIRE(rdata1->length == 10);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews REQUIRE(rdata2->length == 10);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews dns_rdata_toregion(rdata1, &region1);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews dns_rdata_toregion(rdata2, &region2);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (isc_region_compare(&region1, &region2));
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews}
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsstatic inline isc_result_t
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsfromstruct_l64(ARGS_FROMSTRUCT) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews dns_rdata_l64_t *l64 = source;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_l64);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews REQUIRE(source != NULL);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews REQUIRE(l64->common.rdtype == type);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews REQUIRE(l64->common.rdclass == rdclass);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(type);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(rdclass);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews RETERR(uint16_tobuffer(l64->pref, target));
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (mem_tobuffer(target, l64->l64, sizeof(l64->l64)));
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews}
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsstatic inline isc_result_t
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewstostruct_l64(ARGS_TOSTRUCT) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews isc_region_t region;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews dns_rdata_l64_t *l64 = target;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_l64);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews REQUIRE(target != NULL);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews REQUIRE(rdata->length == 10);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(mctx);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews l64->common.rdclass = rdata->rdclass;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews l64->common.rdtype = rdata->type;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews ISC_LINK_INIT(&l64->common, link);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews dns_rdata_toregion(rdata, &region);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews l64->pref = uint16_fromregion(&region);
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt memmove(l64->l64, region.base, region.length);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (ISC_R_SUCCESS);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews}
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsstatic inline void
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsfreestruct_l64(ARGS_FREESTRUCT) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews dns_rdata_l64_t *l64 = source;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews REQUIRE(source != NULL);
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(l64->common.rdtype == dns_rdatatype_l64);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews}
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsstatic inline isc_result_t
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsadditionaldata_l64(ARGS_ADDLDATA) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_l64);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews REQUIRE(rdata->length == 10);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(rdata);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(add);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(arg);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (ISC_R_SUCCESS);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews}
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsstatic inline isc_result_t
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsdigest_l64(ARGS_DIGEST) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews isc_region_t r;
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_l64);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews REQUIRE(rdata->length == 10);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews dns_rdata_toregion(rdata, &r);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return ((digest)(arg, &r));
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews}
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsstatic inline isc_boolean_t
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewscheckowner_l64(ARGS_CHECKOWNER) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_l64);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(name);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(type);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(rdclass);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(wildcard);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (ISC_TRUE);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews}
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsstatic inline isc_boolean_t
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewschecknames_l64(ARGS_CHECKNAMES) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_l64);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews REQUIRE(rdata->length == 10);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(rdata);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(owner);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews UNUSED(bad);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (ISC_TRUE);
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews}
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewsstatic inline int
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrewscasecompare_l64(ARGS_COMPARE) {
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews return (compare_l64(rdata1, rdata2));
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews}
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews
f1c1aab2c9e720399d66d8db5f40515d47c45ecfMark Andrews#endif /* RDATA_GENERIC_L64_106_C */