nxt_30.c revision a134177ed9f82189504191d90f3ed9e97c2b47cb
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews/*
a134177ed9f82189504191d90f3ed9e97c2b47cbTinderbox User * Copyright (C) 1999-2005, 2007, 2009, 2015-2017 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
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/.
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews */
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
4b6dc226f78862286daa69fba761eac9fd5da16aAutomatic Updater/* $Id: nxt_30.c,v 1.65 2009/12/04 22:06:37 tbox Exp $ */
ecd3b66f8c4544a55dd44fddda7c7134b936cd3bJames Brister
ecd3b66f8c4544a55dd44fddda7c7134b936cd3bJames Brister/* reviewed: Wed Mar 15 18:21:15 PST 2000 by brister */
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/* RFC2535 */
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#ifndef RDATA_GENERIC_NXT_30_C
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#define RDATA_GENERIC_NXT_30_C
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
59a6d9effd893036e39e14e775e1c98b0cd22388Andreas Gustafsson/*
59a6d9effd893036e39e14e775e1c98b0cd22388Andreas Gustafsson * The attributes do not include DNS_RDATATYPEATTR_SINGLETON
59a6d9effd893036e39e14e775e1c98b0cd22388Andreas Gustafsson * because we must be able to handle a parent/child NXT pair.
59a6d9effd893036e39e14e775e1c98b0cd22388Andreas Gustafsson */
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews#define RRTYPE_NXT_ATTRIBUTES (0)
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefromtext_nxt(ARGS_FROMTEXT) {
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews isc_token_t token;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_t name;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews isc_buffer_t buffer;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews char *e;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews unsigned char bm[8*1024]; /* 64k bits */
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_rdatatype_t covered;
96594ea32eecb2b75dd0e588f5491079328ce339Andreas Gustafsson dns_rdatatype_t maxcovered = 0;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews isc_boolean_t first = ISC_TRUE;
6e482e595d2b04e65f17851626a61a82efc4bd12David Lawrence long n;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_nxt);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington UNUSED(type);
ecd3b66f8c4544a55dd44fddda7c7134b936cd3bJames Brister UNUSED(rdclass);
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews UNUSED(callbacks);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
34b394b43e2207e8f8f3703f0402422121455638David Lawrence /*
34b394b43e2207e8f8f3703f0402422121455638David Lawrence * Next domain.
34b394b43e2207e8f8f3703f0402422121455638David Lawrence */
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_init(&name, NULL);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence buffer_fromregion(&buffer, &token.value.as_region);
e0a30050c8516a3d54a4f8dcdd88435704a8a3edMark Andrews if (origin == NULL)
e0a30050c8516a3d54a4f8dcdd88435704a8a3edMark Andrews origin = dns_rootname;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target));
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson memset(bm, 0, sizeof(bm));
19c5c23ef6e38965949c996592bd92478da0612cMark Andrews do {
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington isc_tokentype_string, ISC_TRUE));
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews if (token.type != isc_tokentype_string)
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews break;
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews n = strtol(DNS_AS_STR(token), &e, 10);
c46f10e4a1702191b003cf8f8fc5059c15d29c48Mark Andrews if (e != DNS_AS_STR(token) && *e == '\0') {
19c5c23ef6e38965949c996592bd92478da0612cMark Andrews covered = (dns_rdatatype_t)n;
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence } else if (dns_rdatatype_fromtext(&covered,
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews &token.value.as_textregion) == DNS_R_UNKNOWN)
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews RETTOK(DNS_R_UNKNOWN);
19c5c23ef6e38965949c996592bd92478da0612cMark Andrews /*
19c5c23ef6e38965949c996592bd92478da0612cMark Andrews * NXT is only specified for types 1..127.
19c5c23ef6e38965949c996592bd92478da0612cMark Andrews */
19c5c23ef6e38965949c996592bd92478da0612cMark Andrews if (covered < 1 || covered > 127)
34b394b43e2207e8f8f3703f0402422121455638David Lawrence return (ISC_R_RANGE);
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews if (first || covered > maxcovered)
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews maxcovered = covered;
8d3e74b1683f714a484bbcf73249e8ee470e36d7Mark Andrews first = ISC_FALSE;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews bm[covered/8] |= (0x80>>(covered%8));
19c5c23ef6e38965949c996592bd92478da0612cMark Andrews } while (1);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews isc_lex_ungettoken(lexer, &token);
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence if (first)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews n = (maxcovered + 8) / 8;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews return (mem_tobuffer(target, bm, n));
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews}
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencetotext_nxt(ARGS_TOTEXT) {
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews isc_region_t sr;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews unsigned int i, j;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_t name;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_t prefix;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews isc_boolean_t sub;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_nxt);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata->length != 0);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_init(&name, NULL);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_init(&prefix, NULL);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_rdata_toregion(rdata, &sr);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_fromregion(&name, &sr);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews isc_region_consume(&sr, name_length(&name));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson sub = name_prefix(&name, tctx->origin, &prefix);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews RETERR(dns_name_totext(&prefix, sub, target));
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson for (i = 0; i < sr.length; i++) {
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews if (sr.base[i] != 0)
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews for (j = 0; j < 8; j++)
6e482e595d2b04e65f17851626a61a82efc4bd12David Lawrence if ((sr.base[i] & (0x80 >> j)) != 0) {
5436ac555325d888c822f6be8c4fe69d2343d827Andreas Gustafsson dns_rdatatype_t t = i * 8 + j;
9f139761ca06977d1db8051842efc620c15b8199Andreas Gustafsson RETERR(str_totext(" ", target));
5436ac555325d888c822f6be8c4fe69d2343d827Andreas Gustafsson if (dns_rdatatype_isknown(t)) {
a1f16c81a1e54f52745f64555e6affa0add44173David Lawrence RETERR(dns_rdatatype_totext(t,
a1f16c81a1e54f52745f64555e6affa0add44173David Lawrence target));
5436ac555325d888c822f6be8c4fe69d2343d827Andreas Gustafsson } else {
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson char buf[sizeof("65535")];
ad1317338af79edad878c9c3e4361798503310baMark Andrews snprintf(buf, sizeof(buf),
ad1317338af79edad878c9c3e4361798503310baMark Andrews "%u", t);
a1f16c81a1e54f52745f64555e6affa0add44173David Lawrence RETERR(str_totext(buf,
a1f16c81a1e54f52745f64555e6affa0add44173David Lawrence target));
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews }
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews }
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews }
9f139761ca06977d1db8051842efc620c15b8199Andreas Gustafsson return (ISC_R_SUCCESS);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews}
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefromwire_nxt(ARGS_FROMWIRE) {
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews isc_region_t sr;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_t name;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_nxt);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington UNUSED(type);
ecd3b66f8c4544a55dd44fddda7c7134b936cd3bJames Brister UNUSED(rdclass);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
94a08e09db3dc844b6ee4841c368a2d7074a9c3fAndreas Gustafsson dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE);
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_init(&name, NULL);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews RETERR(dns_name_fromwire(&name, source, dctx, options, target));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_activeregion(source, &sr);
182a34004c7c48e2c1626f3ce7e787f413955126Mark Andrews if (sr.length > 0 && (sr.base[0] & 0x80) == 0 &&
182a34004c7c48e2c1626f3ce7e787f413955126Mark Andrews ((sr.length > 16) || sr.base[sr.length - 1] == 0))
182a34004c7c48e2c1626f3ce7e787f413955126Mark Andrews return (DNS_R_BADBITMAP);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews RETERR(mem_tobuffer(target, sr.base, sr.length));
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews isc_buffer_forward(source, sr.length);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews}
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencetowire_nxt(ARGS_TOWIRE) {
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews isc_region_t sr;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_t name;
cdc50af0bff41accc02c613b9c6d8cd41b171ffeBrian Wellington dns_offsets_t offsets;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_nxt);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata->length != 0);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
94a08e09db3dc844b6ee4841c368a2d7074a9c3fAndreas Gustafsson dns_compress_setmethods(cctx, DNS_COMPRESS_NONE);
cdc50af0bff41accc02c613b9c6d8cd41b171ffeBrian Wellington dns_name_init(&name, offsets);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_rdata_toregion(rdata, &sr);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_fromregion(&name, &sr);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews isc_region_consume(&sr, name_length(&name));
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews RETERR(dns_name_towire(&name, cctx, target));
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews return (mem_tobuffer(target, sr.base, sr.length));
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews}
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halleystatic inline int
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencecompare_nxt(ARGS_COMPARE) {
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews isc_region_t r1;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews isc_region_t r2;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_t name1;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_t name2;
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson int order;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews REQUIRE(rdata1->type == rdata2->type);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley REQUIRE(rdata1->rdclass == rdata2->rdclass);
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata1->type == dns_rdatatype_nxt);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata1->length != 0);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata2->length != 0);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_init(&name1, NULL);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_init(&name2, NULL);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_rdata_toregion(rdata1, &r1);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_rdata_toregion(rdata2, &r2);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_fromregion(&name1, &r1);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews dns_name_fromregion(&name2, &r2);
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson order = dns_name_rdatacompare(&name1, &name2);
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson if (order != 0)
41aad56b6cc458cbf7b8483576d990a77ae9bac2Andreas Gustafsson return (order);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
90e303b114e56db5809fdd19805243457fa43cd9Olafur Gudmundsson return (isc_region_compare(&r1, &r2));
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews}
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefromstruct_nxt(ARGS_FROMSTRUCT) {
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews dns_rdata_nxt_t *nxt = source;
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington isc_region_t region;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_nxt);
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews REQUIRE(source != NULL);
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews REQUIRE(nxt->common.rdtype == type);
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews REQUIRE(nxt->common.rdclass == rdclass);
daf99720c90d7f527a12e76e437ae8c95fdf84caAndreas Gustafsson REQUIRE(nxt->typebits != NULL || nxt->len == 0);
182a34004c7c48e2c1626f3ce7e787f413955126Mark Andrews if (nxt->typebits != NULL && (nxt->typebits[0] & 0x80) == 0) {
182a34004c7c48e2c1626f3ce7e787f413955126Mark Andrews REQUIRE(nxt->len <= 16);
182a34004c7c48e2c1626f3ce7e787f413955126Mark Andrews REQUIRE(nxt->typebits[nxt->len - 1] != 0);
182a34004c7c48e2c1626f3ce7e787f413955126Mark Andrews }
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington UNUSED(type);
63cef8bde8b92aeb30ccdcf21d4e44c9be9cc6e3Andreas Gustafsson UNUSED(rdclass);
63cef8bde8b92aeb30ccdcf21d4e44c9be9cc6e3Andreas Gustafsson
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington dns_name_toregion(&nxt->next, &region);
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington RETERR(isc_buffer_copyregion(target, &region));
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington return (mem_tobuffer(target, nxt->typebits, nxt->len));
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews}
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencetostruct_nxt(ARGS_TOSTRUCT) {
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington isc_region_t region;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews dns_rdata_nxt_t *nxt = target;
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington dns_name_t name;
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_nxt);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews REQUIRE(target != NULL);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata->length != 0);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews nxt->common.rdclass = rdata->rdclass;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews nxt->common.rdtype = rdata->type;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews ISC_LINK_INIT(&nxt->common, link);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington dns_name_init(&name, NULL);
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington dns_rdata_toregion(rdata, &region);
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington dns_name_fromregion(&name, &region);
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington isc_region_consume(&region, name_length(&name));
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington dns_name_init(&nxt->next, NULL);
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington RETERR(name_duporclone(&name, mctx, &nxt->next));
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington nxt->len = region.length;
daf99720c90d7f527a12e76e437ae8c95fdf84caAndreas Gustafsson nxt->typebits = mem_maybedup(mctx, region.base, region.length);
daf99720c90d7f527a12e76e437ae8c95fdf84caAndreas Gustafsson if (nxt->typebits == NULL)
daf99720c90d7f527a12e76e437ae8c95fdf84caAndreas Gustafsson goto cleanup;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews nxt->mctx = mctx;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews return (ISC_R_SUCCESS);
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington cleanup:
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington if (mctx != NULL)
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington dns_name_free(&nxt->next, mctx);
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington return (ISC_R_NOMEMORY);
2bc0da0cd874b15593d65338ba96e90ceed13072Mark Andrews}
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halleystatic inline void
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefreestruct_nxt(ARGS_FREESTRUCT) {
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews dns_rdata_nxt_t *nxt = source;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews REQUIRE(source != NULL);
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(nxt->common.rdtype == dns_rdatatype_nxt);
82ca33427bdd4f3bc4ed3431e86bd810fe751674Andreas Gustafsson
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews if (nxt->mctx == NULL)
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews return;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington dns_name_free(&nxt->next, nxt->mctx);
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington if (nxt->typebits != NULL)
e484f9de4f2cdab05d9db4f0bbcdd15d365f0b31Brian Wellington isc_mem_free(nxt->mctx, nxt->typebits);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews nxt->mctx = NULL;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews}
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceadditionaldata_nxt(ARGS_ADDLDATA) {
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_nxt);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
82ca33427bdd4f3bc4ed3431e86bd810fe751674Andreas Gustafsson UNUSED(rdata);
82ca33427bdd4f3bc4ed3431e86bd810fe751674Andreas Gustafsson UNUSED(add);
82ca33427bdd4f3bc4ed3431e86bd810fe751674Andreas Gustafsson UNUSED(arg);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley}
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencedigest_nxt(ARGS_DIGEST) {
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley isc_region_t r;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley dns_name_t name;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_result_t result;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_nxt);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley dns_rdata_toregion(rdata, &r);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley dns_name_init(&name, NULL);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley dns_name_fromregion(&name, &r);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley result = dns_name_digest(&name, digest, arg);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff if (result != ISC_R_SUCCESS)
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley return (result);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley isc_region_consume(&r, name_length(&name));
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley return ((digest)(arg, &r));
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley}
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsstatic inline isc_boolean_t
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewscheckowner_nxt(ARGS_CHECKOWNER) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_nxt);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews UNUSED(name);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews UNUSED(type);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews UNUSED(rdclass);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews UNUSED(wildcard);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews return (ISC_TRUE);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews}
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewsstatic inline isc_boolean_t
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrewschecknames_nxt(ARGS_CHECKNAMES) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_nxt);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews UNUSED(rdata);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews UNUSED(owner);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews UNUSED(bad);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews return (ISC_TRUE);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews}
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrewsstatic inline int
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrewscasecompare_nxt(ARGS_COMPARE) {
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews return (compare_nxt(rdata1, rdata2));
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews}
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#endif /* RDATA_GENERIC_NXT_30_C */