soa_6.c revision 6d12fdf96621801e80f3f4c2a8a569fe48766a20
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer/*
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer * Copyright (C) 1998, 1999, 2000 Internet Software Consortium.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Permission to use, copy, modify, and distribute this software for any
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * purpose with or without fee is hereby granted, provided that the above
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * copyright notice and this permission notice appear in all copies.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews *
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * SOFTWARE.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews */
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews
1d32b1df372d6be6bac6450739b9e5ea23819995Evan Hunt/* $Id: soa_6.c,v 1.39 2000/06/01 18:26:33 tale Exp $ */
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer/* Reviewed: Thu Mar 16 15:18:32 PST 2000 by explorer */
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer#ifndef RDATA_GENERIC_SOA_6_C
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer#define RDATA_GENERIC_SOA_6_C
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer#define RRTYPE_SOA_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON)
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Huntstatic inline isc_result_t
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Huntfromtext_soa(ARGS_FROMTEXT) {
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt isc_token_t token;
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt dns_name_t name;
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt isc_buffer_t buffer;
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt int i;
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt isc_uint32_t n;
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt UNUSED(rdclass);
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt REQUIRE(type == 6);
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt origin = (origin != NULL) ? origin : dns_rootname;
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt for (i = 0 ; i < 2 ; i++) {
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt RETERR(gettoken(lexer, &token, isc_tokentype_string,
30a60d2aff0ec1810262a8b8efc532e28b32bd57Evan Hunt ISC_FALSE));
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer dns_name_init(&name, NULL);
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer buffer_fromregion(&buffer, &token.value.as_region);
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer RETERR(dns_name_fromtext(&name, &buffer, origin,
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence downcase, target));
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer }
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer RETERR(gettoken(lexer, &token, isc_tokentype_number, ISC_FALSE));
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence RETERR(uint32_tobuffer(token.value.as_ulong, target));
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer for (i = 0; i < 4; i++) {
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer RETERR(gettoken(lexer, &token, isc_tokentype_string,
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence ISC_FALSE));
fdebae839745f79a7550aeb49d15a930523ec483David Lawrence RETERR(dns_counter_fromtext(&token.value.as_textregion, &n));
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt RETERR(uint32_tobuffer(n, target));
28002bd7cb4baa0eab9f47e1e51069c5ea7ea5d4Andreas Gustafsson }
28002bd7cb4baa0eab9f47e1e51069c5ea7ea5d4Andreas Gustafsson
1d32b1df372d6be6bac6450739b9e5ea23819995Evan Hunt return (ISC_R_SUCCESS);
1d32b1df372d6be6bac6450739b9e5ea23819995Evan Hunt}
28002bd7cb4baa0eab9f47e1e51069c5ea7ea5d4Andreas Gustafsson
28002bd7cb4baa0eab9f47e1e51069c5ea7ea5d4Andreas Gustafssonstatic const char *soa_fieldnames[5] = {
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt "serial", "refresh", "retry", "expire", "minimum"
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt};
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrencestatic inline isc_result_t
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyertotext_soa(ARGS_TOTEXT) {
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer isc_region_t dregion;
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer dns_name_t mname;
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence dns_name_t rname;
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer dns_name_t prefix;
2de413d956c9f065958aaeebf5cd3a420e55939cMichael Sawyer isc_boolean_t sub;
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer int i;
c634c94d673f1bab17e7f65d332f989b683e712cDavid Lawrence
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer REQUIRE(rdata->type == 6);
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer
c3c6770e537ea916265c78d0294ad108233e17c1Michael Sawyer dns_name_init(&mname, NULL);
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt dns_name_init(&rname, NULL);
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt dns_name_init(&prefix, NULL);
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt dns_rdata_toregion(rdata, &dregion);
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt dns_name_fromregion(&mname, &dregion);
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt isc_region_consume(&dregion, name_length(&mname));
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt dns_name_fromregion(&rname, &dregion);
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt isc_region_consume(&dregion, name_length(&rname));
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt sub = name_prefix(&mname, tctx->origin, &prefix);
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt RETERR(dns_name_totext(&prefix, sub, target));
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt RETERR(str_totext(" ", target));
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt sub = name_prefix(&rname, tctx->origin, &prefix);
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt RETERR(dns_name_totext(&prefix, sub, target));
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt RETERR(str_totext(" (" , target));
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt RETERR(str_totext(tctx->linebreak, target));
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt for (i = 0; i < 5 ; i++) {
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt char buf[sizeof "2147483647"];
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt unsigned long num;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt unsigned int numlen;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt num = uint32_fromregion(&dregion);
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt isc_region_consume(&dregion, 4);
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt numlen = sprintf(buf, "%lu", num);
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt INSIST(numlen > 0 && numlen < sizeof "2147483647");
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt RETERR(str_totext(buf, target));
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt if ((tctx->flags & (DNS_STYLEFLAG_MULTILINE |
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt DNS_STYLEFLAG_COMMENT)) ==
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt (DNS_STYLEFLAG_MULTILINE |
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt DNS_STYLEFLAG_COMMENT)) {
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt RETERR(str_totext(" ; " + numlen, target));
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt RETERR(str_totext(soa_fieldnames[i], target));
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt /* Print times in week/day/hour/minute/second form */
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt if (i >= 1) {
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt RETERR(str_totext(" (", target));
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt RETERR(dns_ttl_totext(num, ISC_TRUE, target));
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt RETERR(str_totext(")", target));
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt }
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt RETERR(str_totext(tctx->linebreak, target));
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt } else {
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt RETERR(str_totext(" ", target));
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt }
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt }
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt RETERR(str_totext(")", target));
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt return (ISC_R_SUCCESS);
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt}
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Huntstatic inline isc_result_t
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Huntfromwire_soa(ARGS_FROMWIRE) {
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt dns_name_t mname;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt dns_name_t rname;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt isc_region_t sregion;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt isc_region_t tregion;
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt UNUSED(rdclass);
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt REQUIRE(type == 6);
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt dns_name_init(&mname, NULL);
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt dns_name_init(&rname, NULL);
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt
47e70d820ed07895a25e5b3520adf953114ac01eEvan Hunt RETERR(dns_name_fromwire(&mname, source, dctx, downcase, target));
b5b934a0bb46aded1552a17473652b5a7f4a3274Evan Hunt RETERR(dns_name_fromwire(&rname, source, dctx, downcase, target));
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt isc_buffer_activeregion(source, &sregion);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt isc_buffer_availableregion(target, &tregion);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt if (sregion.length < 20)
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt return (ISC_R_UNEXPECTEDEND);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt if (tregion.length < 20)
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt return (ISC_R_NOSPACE);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt memcpy(tregion.base, sregion.base, 20);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt isc_buffer_forward(source, 20);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt isc_buffer_add(target, 20);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt return (ISC_R_SUCCESS);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt}
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Huntstatic inline isc_result_t
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunttowire_soa(ARGS_TOWIRE) {
2a6d60615cf07b164533dbb6bb1dce84ed2d037dEvan Hunt isc_region_t sregion;
2a6d60615cf07b164533dbb6bb1dce84ed2d037dEvan Hunt isc_region_t tregion;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt dns_name_t mname;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt dns_name_t rname;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt REQUIRE(rdata->type == 6);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt dns_name_init(&mname, NULL);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt dns_name_init(&rname, NULL);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt dns_rdata_toregion(rdata, &sregion);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt dns_name_fromregion(&mname, &sregion);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt isc_region_consume(&sregion, name_length(&mname));
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt RETERR(dns_name_towire(&mname, cctx, target));
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt dns_name_fromregion(&rname, &sregion);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt isc_region_consume(&sregion, name_length(&rname));
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt RETERR(dns_name_towire(&rname, cctx, target));
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt isc_buffer_availableregion(target, &tregion);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt if (tregion.length < 20)
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt return (ISC_R_NOSPACE);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt memcpy(tregion.base, sregion.base, 20);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt isc_buffer_add(target, 20);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt return (ISC_R_SUCCESS);
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt}
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Huntstatic inline int
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Huntcompare_soa(ARGS_COMPARE) {
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt isc_region_t region1;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt isc_region_t region2;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt dns_name_t name1;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt dns_name_t name2;
6de9744cf9c64be2145f663e4051196a4eaa9d45Evan Hunt int order;
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt REQUIRE(rdata1->type == rdata2->type);
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt REQUIRE(rdata1->rdclass == rdata2->rdclass);
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt REQUIRE(rdata1->type == 6);
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt dns_name_init(&name1, NULL);
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt dns_name_init(&name2, NULL);
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt dns_rdata_toregion(rdata1, &region1);
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt dns_rdata_toregion(rdata2, &region2);
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt
cba23be7ba724b527f6a60c14caaeca9502fbc79Evan Hunt dns_name_fromregion(&name1, &region1);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews dns_name_fromregion(&name2, &region2);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews order = dns_name_rdatacompare(&name1, &name2);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews if (order != 0)
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews return (order);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews isc_region_consume(&region1, name_length(&name1));
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews isc_region_consume(&region2, name_length(&name2));
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews dns_name_init(&name1, NULL);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews dns_name_init(&name2, NULL);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews dns_name_fromregion(&name1, &region1);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews dns_name_fromregion(&name2, &region2);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews order = dns_name_rdatacompare(&name1, &name2);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews if (order != 0)
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews return (order);
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews isc_region_consume(&region1, name_length(&name1));
a69070d8fab55dbc63ba9f96c9d3e34f0ea9119aMark Andrews isc_region_consume(&region2, name_length(&name2));
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer return (compare_region(&region1, &region2));
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer}
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyerstatic inline isc_result_t
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyerfromstruct_soa(ARGS_FROMSTRUCT) {
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer dns_rdata_soa_t *soa = source;
c5272fb3303425f794dab68f734f6a2a45dce01eMichael Sawyer isc_region_t region;
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer REQUIRE(type == 6);
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer REQUIRE(source != NULL);
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer REQUIRE(soa->common.rdtype == type);
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer REQUIRE(soa->common.rdclass == rdclass);
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer
2de413d956c9f065958aaeebf5cd3a420e55939cMichael Sawyer dns_name_toregion(&soa->origin, &region);
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer RETERR(isc_buffer_copyregion(target, &region));
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer dns_name_toregion(&soa->mname, &region);
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer RETERR(isc_buffer_copyregion(target, &region));
6b9c29ec578de7fda057bd3b893ccda176378b1bMichael Sawyer RETERR(uint32_tobuffer(soa->serial, target));
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer RETERR(uint32_tobuffer(soa->refresh, target));
1b003261c2dd3e32778337c7a2788e4829066bd9Andreas Gustafsson RETERR(uint32_tobuffer(soa->retry, target));
1b003261c2dd3e32778337c7a2788e4829066bd9Andreas Gustafsson RETERR(uint32_tobuffer(soa->expire, target));
1b003261c2dd3e32778337c7a2788e4829066bd9Andreas Gustafsson return (uint32_tobuffer(soa->minimum, target));
1b003261c2dd3e32778337c7a2788e4829066bd9Andreas Gustafsson}
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafssonstatic inline isc_result_t
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafssontostruct_soa(ARGS_TOSTRUCT) {
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson isc_region_t region;
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson dns_rdata_soa_t *soa = target;
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson dns_name_t name;
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson isc_result_t result;
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson
3ad7f12f7439471a0922ed3952221e93aef9db69Andreas Gustafsson REQUIRE(rdata->type == 6);
0759eb6a0dab024873df528b0ffad804ea31615dMichael Sawyer REQUIRE(target != NULL);
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer soa->common.rdclass = rdata->rdclass;
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer soa->common.rdtype = rdata->type;
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer ISC_LINK_INIT(&soa->common, link);
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer dns_rdata_toregion(rdata, &region);
dc9c461b27df798ba7c3d9ba1446840c5f85553bMichael Sawyer
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson dns_name_init(&name, NULL);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson dns_name_fromregion(&name, &region);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson isc_region_consume(&region, name_length(&name));
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt dns_name_init(&soa->origin, NULL);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson RETERR(name_duporclone(&name, mctx, &soa->origin));
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson dns_name_fromregion(&name, &region);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson isc_region_consume(&region, name_length(&name));
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson dns_name_init(&soa->mname, NULL);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson result = name_duporclone(&name, mctx, &soa->mname);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson if (result != ISC_R_SUCCESS)
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson goto cleanup;
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson soa->serial = uint32_fromregion(&region);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson isc_region_consume(&region, 4);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson soa->refresh = uint32_fromregion(&region);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson isc_region_consume(&region, 4);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson
9069215eac23e32f4ef1c8e44ad7ff2865cfcdacEvan Hunt soa->retry = uint32_fromregion(&region);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson isc_region_consume(&region, 4);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson soa->expire = uint32_fromregion(&region);
1d32b1df372d6be6bac6450739b9e5ea23819995Evan Hunt isc_region_consume(&region, 4);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson soa->minimum = uint32_fromregion(&region);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson soa->mctx = mctx;
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson return (ISC_R_SUCCESS);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson cleanup:
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson if (mctx != NULL)
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson dns_name_free(&soa->origin, mctx);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson return (ISC_R_NOMEMORY);
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson}
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafssonstatic inline void
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafssonfreestruct_soa(ARGS_FREESTRUCT) {
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson dns_rdata_soa_t *soa = source;
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson
5337a9e53c7df1ef40d70528f2360c5e4cb9a7d1Andreas Gustafsson REQUIRE(source != NULL);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews REQUIRE(soa->common.rdtype == 6);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews if (soa->mctx == NULL)
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews return;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews dns_name_free(&soa->origin, soa->mctx);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews dns_name_free(&soa->mname, soa->mctx);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews soa->mctx = NULL;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews}
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrewsstatic inline isc_result_t
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrewsadditionaldata_soa(ARGS_ADDLDATA) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews UNUSED(rdata);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews UNUSED(add);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews UNUSED(arg);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews REQUIRE(rdata->type == 6);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews return (ISC_R_SUCCESS);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews}
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrewsstatic inline isc_result_t
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrewsdigest_soa(ARGS_DIGEST) {
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews isc_region_t r;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews dns_name_t name;
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews REQUIRE(rdata->type == 6);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews dns_rdata_toregion(rdata, &r);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews dns_name_init(&name, NULL);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews dns_name_fromregion(&name, &r);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews RETERR(dns_name_digest(&name, digest, arg));
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews isc_region_consume(&r, name_length(&name));
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews dns_name_init(&name, NULL);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews dns_name_fromregion(&name, &r);
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews RETERR(dns_name_digest(&name, digest, arg));
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews isc_region_consume(&r, name_length(&name));
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews return ((digest)(arg, &r));
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews}
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews#endif /* RDATA_GENERIC_SOA_6_C */
8aee18709f238406719768b8a6b843a15c5075f8Mark Andrews