5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/*
a134177ed9f82189504191d90f3ed9e97c2b47cbTinderbox User * Copyright (C) 1998-2002, 2004, 2007, 2009, 2011, 2012, 2014-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/.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews/* $Id$ */
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff/* Reviewed: Thu Mar 16 15:18:32 PST 2000 by explorer */
3761c433912beabe43abeed2c3513b6201c59f64Mark Andrews
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#ifndef RDATA_GENERIC_SOA_6_C
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#define RDATA_GENERIC_SOA_6_C
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff#define RRTYPE_SOA_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON)
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefromtext_soa(ARGS_FROMTEXT) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_token_t token;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t name;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_t buffer;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews int i;
90880946803188d7c6b3ca7dea69761eb21241c2Mark Andrews isc_uint32_t n;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews isc_boolean_t ok;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_soa);
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington UNUSED(type);
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington UNUSED(rdclass);
bddfe77128b0f16af263ff149db40f0d885f43d0Mark Andrews UNUSED(callbacks);
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington
e0a30050c8516a3d54a4f8dcdd88435704a8a3edMark Andrews if (origin == NULL)
e0a30050c8516a3d54a4f8dcdd88435704a8a3edMark Andrews origin = dns_rootname;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson for (i = 0; i < 2; i++) {
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington isc_tokentype_string,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews dns_name_init(&name, NULL);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence buffer_fromregion(&buffer, &token.value.as_region);
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews RETTOK(dns_name_fromtext(&name, &buffer, origin,
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews options, target));
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews ok = ISC_TRUE;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if ((options & DNS_RDATA_CHECKNAMES) != 0)
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews switch (i) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews case 0:
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews ok = dns_name_ishostname(&name, ISC_FALSE);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews break;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews case 1:
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews ok = dns_name_ismailbox(&name);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews break;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews }
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews RETTOK(DNS_R_BADNAME);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if (!ok && callbacks != NULL)
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews warn_badname(&name, lexer, callbacks);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
90880946803188d7c6b3ca7dea69761eb21241c2Mark Andrews RETERR(uint32_tobuffer(token.value.as_ulong, target));
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff
90880946803188d7c6b3ca7dea69761eb21241c2Mark Andrews for (i = 0; i < 4; i++) {
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington RETERR(isc_lex_getmastertoken(lexer, &token,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington isc_tokentype_string,
add4043305ca411202ed9cf1929a4179016515ceBrian Wellington ISC_FALSE));
9ac7076ebad044afb15e9e2687e3696868778538Mark Andrews RETTOK(dns_counter_fromtext(&token.value.as_textregion, &n));
90880946803188d7c6b3ca7dea69761eb21241c2Mark Andrews RETERR(uint32_tobuffer(n, target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencestatic const char *soa_fieldnames[5] = {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson "serial", "refresh", "retry", "expire", "minimum"
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff};
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencetotext_soa(ARGS_TOTEXT) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t dregion;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t mname;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t rname;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t prefix;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_boolean_t sub;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews int i;
9ce72fc748cc7c2b738147f9736e00a96474be1bBrian Wellington isc_boolean_t multiline;
af669cb4fd7ecfb67ed145b176e5e764b249573bMark Andrews isc_boolean_t comm;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_soa);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata->length != 0);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
9f139761ca06977d1db8051842efc620c15b8199Andreas Gustafsson multiline = ISC_TF((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0);
e502b133d630bda0ee64c1e2ce6729d96750d8abMark Andrews if (multiline)
af669cb4fd7ecfb67ed145b176e5e764b249573bMark Andrews comm = ISC_TF((tctx->flags & DNS_STYLEFLAG_RRCOMMENT) != 0);
e502b133d630bda0ee64c1e2ce6729d96750d8abMark Andrews else
af669cb4fd7ecfb67ed145b176e5e764b249573bMark Andrews comm = ISC_FALSE;
bf33eb0b522801792a6663b0360bc94b9e9b77c2Automatic Updater
9ce72fc748cc7c2b738147f9736e00a96474be1bBrian Wellington
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&mname, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&rname, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&prefix, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_rdata_toregion(rdata, &dregion);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&mname, &dregion);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_consume(&dregion, name_length(&mname));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&rname, &dregion);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_consume(&dregion, name_length(&rname));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson sub = name_prefix(&mname, tctx->origin, &prefix);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews RETERR(dns_name_totext(&prefix, sub, target));
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews RETERR(str_totext(" ", target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson sub = name_prefix(&rname, tctx->origin, &prefix);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews RETERR(dns_name_totext(&prefix, sub, target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
9ce72fc748cc7c2b738147f9736e00a96474be1bBrian Wellington if (multiline)
9ce72fc748cc7c2b738147f9736e00a96474be1bBrian Wellington RETERR(str_totext(" (" , target));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(str_totext(tctx->linebreak, target));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson for (i = 0; i < 5; i++) {
e502b133d630bda0ee64c1e2ce6729d96750d8abMark Andrews char buf[sizeof("0123456789 ; ")];
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned long num;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews num = uint32_fromregion(&dregion);
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff isc_region_consume(&dregion, 4);
ad1317338af79edad878c9c3e4361798503310baMark Andrews snprintf(buf, sizeof(buf), comm ? "%-10lu ; " : "%lu", num);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews RETERR(str_totext(buf, target));
af669cb4fd7ecfb67ed145b176e5e764b249573bMark Andrews if (comm) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(str_totext(soa_fieldnames[i], target));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson /* Print times in week/day/hour/minute/second form */
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (i >= 1) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(str_totext(" (", target));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(dns_ttl_totext(num, ISC_TRUE, target));
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff RETERR(str_totext(")", target));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson }
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(str_totext(tctx->linebreak, target));
9ce72fc748cc7c2b738147f9736e00a96474be1bBrian Wellington } else if (i < 4) {
e502b133d630bda0ee64c1e2ce6729d96750d8abMark Andrews RETERR(str_totext(tctx->linebreak, target));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
9ce72fc748cc7c2b738147f9736e00a96474be1bBrian Wellington if (multiline)
9f139761ca06977d1db8051842efc620c15b8199Andreas Gustafsson RETERR(str_totext(")", target));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefromwire_soa(ARGS_FROMWIRE) {
bf33eb0b522801792a6663b0360bc94b9e9b77c2Automatic Updater dns_name_t mname;
bf33eb0b522801792a6663b0360bc94b9e9b77c2Automatic Updater dns_name_t rname;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t sregion;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t tregion;
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_soa);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington UNUSED(type);
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington UNUSED(rdclass);
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington
94a08e09db3dc844b6ee4841c368a2d7074a9c3fAndreas Gustafsson dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews
bf33eb0b522801792a6663b0360bc94b9e9b77c2Automatic Updater dns_name_init(&mname, NULL);
bf33eb0b522801792a6663b0360bc94b9e9b77c2Automatic Updater dns_name_init(&rname, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
bf33eb0b522801792a6663b0360bc94b9e9b77c2Automatic Updater RETERR(dns_name_fromwire(&mname, source, dctx, options, target));
bf33eb0b522801792a6663b0360bc94b9e9b77c2Automatic Updater RETERR(dns_name_fromwire(&rname, source, dctx, options, target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_activeregion(source, &sregion);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &tregion);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (sregion.length < 20)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_UNEXPECTEDEND);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (tregion.length < 20)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt memmove(tregion.base, sregion.base, 20);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_forward(source, 20);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_add(target, 20);
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencetowire_soa(ARGS_TOWIRE) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t sregion;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t tregion;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t mname;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t rname;
cdc50af0bff41accc02c613b9c6d8cd41b171ffeBrian Wellington dns_offsets_t moffsets;
cdc50af0bff41accc02c613b9c6d8cd41b171ffeBrian Wellington dns_offsets_t roffsets;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_soa);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata->length != 0);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
94a08e09db3dc844b6ee4841c368a2d7074a9c3fAndreas Gustafsson dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews
cdc50af0bff41accc02c613b9c6d8cd41b171ffeBrian Wellington dns_name_init(&mname, moffsets);
cdc50af0bff41accc02c613b9c6d8cd41b171ffeBrian Wellington dns_name_init(&rname, roffsets);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_rdata_toregion(rdata, &sregion);
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&mname, &sregion);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_consume(&sregion, name_length(&mname));
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews RETERR(dns_name_towire(&mname, cctx, target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&rname, &sregion);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_consume(&sregion, name_length(&rname));
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews RETERR(dns_name_towire(&rname, cctx, target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence isc_buffer_availableregion(target, &tregion);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (tregion.length < 20)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_NOSPACE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
e851ea826066ac5a5b01c2c23218faa0273a12e8Evan Hunt memmove(tregion.base, sregion.base, 20);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_add(target, 20);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halleystatic inline int
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencecompare_soa(ARGS_COMPARE) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t region1;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t region2;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t name1;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t name2;
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson int order;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews REQUIRE(rdata1->type == rdata2->type);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley REQUIRE(rdata1->rdclass == rdata2->rdclass);
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata1->type == dns_rdatatype_soa);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata1->length != 0);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata2->length != 0);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&name1, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&name2, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_rdata_toregion(rdata1, &region1);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews dns_rdata_toregion(rdata2, &region2);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&name1, &region1);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&name2, &region2);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson order = dns_name_rdatacompare(&name1, &name2);
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson if (order != 0)
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson return (order);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews isc_region_consume(&region1, name_length(&name1));
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews isc_region_consume(&region2, name_length(&name2));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&name1, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&name2, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&name1, &region1);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_fromregion(&name2, &region2);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson order = dns_name_rdatacompare(&name1, &name2);
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson if (order != 0)
e6c22f37d8df55a9f66b479a22717e179bcf79a3Andreas Gustafsson return (order);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews isc_region_consume(&region1, name_length(&name1));
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews isc_region_consume(&region2, name_length(&name2));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
90e303b114e56db5809fdd19805243457fa43cd9Olafur Gudmundsson return (isc_region_compare(&region1, &region2));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefromstruct_soa(ARGS_FROMSTRUCT) {
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews dns_rdata_soa_t *soa = source;
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews isc_region_t region;
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_soa);
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews REQUIRE(source != NULL);
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews REQUIRE(soa->common.rdtype == type);
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews REQUIRE(soa->common.rdclass == rdclass);
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews
ae114ded82e773a4d9058f833f964a17514712a8Brian Wellington UNUSED(type);
63cef8bde8b92aeb30ccdcf21d4e44c9be9cc6e3Andreas Gustafsson UNUSED(rdclass);
63cef8bde8b92aeb30ccdcf21d4e44c9be9cc6e3Andreas Gustafsson
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews dns_name_toregion(&soa->origin, &region);
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews RETERR(isc_buffer_copyregion(target, &region));
c38b92000c0f1a95daaad5468777e165b8047de9Mark Andrews dns_name_toregion(&soa->contact, &region);
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews RETERR(isc_buffer_copyregion(target, &region));
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews RETERR(uint32_tobuffer(soa->serial, target));
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews RETERR(uint32_tobuffer(soa->refresh, target));
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews RETERR(uint32_tobuffer(soa->retry, target));
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews RETERR(uint32_tobuffer(soa->expire, target));
373ce67419680a398ba3dc51a14a486caaf0afb0Mark Andrews return (uint32_tobuffer(soa->minimum, target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencetostruct_soa(ARGS_TOSTRUCT) {
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews isc_region_t region;
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews dns_rdata_soa_t *soa = target;
05f90cac85760b4edef2962209df49ea019c180fMark Andrews dns_name_t name;
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews isc_result_t result;
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_soa);
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews REQUIRE(target != NULL);
b589e90689c6e87bf9608424ca8d99571c18bc61Mark Andrews REQUIRE(rdata->length != 0);
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews
d981ca645597116d227a48bf37cc5edc061c854dBob Halley soa->common.rdclass = rdata->rdclass;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews soa->common.rdtype = rdata->type;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews ISC_LINK_INIT(&soa->common, link);
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews
05f90cac85760b4edef2962209df49ea019c180fMark Andrews
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews dns_rdata_toregion(rdata, &region);
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff dns_name_init(&name, NULL);
05f90cac85760b4edef2962209df49ea019c180fMark Andrews dns_name_fromregion(&name, &region);
05f90cac85760b4edef2962209df49ea019c180fMark Andrews isc_region_consume(&region, name_length(&name));
05f90cac85760b4edef2962209df49ea019c180fMark Andrews dns_name_init(&soa->origin, NULL);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews RETERR(name_duporclone(&name, mctx, &soa->origin));
05f90cac85760b4edef2962209df49ea019c180fMark Andrews
05f90cac85760b4edef2962209df49ea019c180fMark Andrews dns_name_fromregion(&name, &region);
05f90cac85760b4edef2962209df49ea019c180fMark Andrews isc_region_consume(&region, name_length(&name));
c38b92000c0f1a95daaad5468777e165b8047de9Mark Andrews dns_name_init(&soa->contact, NULL);
c38b92000c0f1a95daaad5468777e165b8047de9Mark Andrews result = name_duporclone(&name, mctx, &soa->contact);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews if (result != ISC_R_SUCCESS)
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews goto cleanup;
05f90cac85760b4edef2962209df49ea019c180fMark Andrews
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews soa->serial = uint32_fromregion(&region);
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews isc_region_consume(&region, 4);
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews soa->refresh = uint32_fromregion(&region);
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews isc_region_consume(&region, 4);
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews soa->retry = uint32_fromregion(&region);
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews isc_region_consume(&region, 4);
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews soa->expire = uint32_fromregion(&region);
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews isc_region_consume(&region, 4);
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews soa->minimum = uint32_fromregion(&region);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews soa->mctx = mctx;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews cleanup:
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews if (mctx != NULL)
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews dns_name_free(&soa->origin, mctx);
9281e7aa775026dc47c01745fdcc438645146877Mark Andrews return (ISC_R_NOMEMORY);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halleystatic inline void
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencefreestruct_soa(ARGS_FREESTRUCT) {
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews dns_rdata_soa_t *soa = source;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews REQUIRE(source != NULL);
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(soa->common.rdtype == dns_rdatatype_soa);
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff
206c71aae4cca0c94d67e271196b6658d293886bMark Andrews if (soa->mctx == NULL)
206c71aae4cca0c94d67e271196b6658d293886bMark Andrews return;
206c71aae4cca0c94d67e271196b6658d293886bMark Andrews
05f90cac85760b4edef2962209df49ea019c180fMark Andrews dns_name_free(&soa->origin, soa->mctx);
c38b92000c0f1a95daaad5468777e165b8047de9Mark Andrews dns_name_free(&soa->contact, soa->mctx);
05f90cac85760b4edef2962209df49ea019c180fMark Andrews soa->mctx = NULL;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews}
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrenceadditionaldata_soa(ARGS_ADDLDATA) {
90f9d00f087ddb4442d1ebf628c1bcaff18226a0Andreas Gustafsson UNUSED(rdata);
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff UNUSED(add);
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff UNUSED(arg);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_soa);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff return (ISC_R_SUCCESS);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley}
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffstatic inline isc_result_t
6d12fdf96621801e80f3f4c2a8a569fe48766a20David Lawrencedigest_soa(ARGS_DIGEST) {
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley isc_region_t r;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley dns_name_t name;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_soa);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley dns_rdata_toregion(rdata, &r);
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley dns_name_init(&name, NULL);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley dns_name_fromregion(&name, &r);
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff RETERR(dns_name_digest(&name, digest, arg));
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley isc_region_consume(&r, name_length(&name));
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley dns_name_init(&name, NULL);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley dns_name_fromregion(&name, &r);
8dd2e6e7c1328ba00d734ce939777e06d9a15493Michael Graff RETERR(dns_name_digest(&name, digest, arg));
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_soa(ARGS_CHECKOWNER) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(type == dns_rdatatype_soa);
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_soa(ARGS_CHECKNAMES) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews isc_region_t region;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_name_t name;
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
b0ba1a6059b6d6c4b3aa77d8bc84cc443b981e01Mukund Sivaraman REQUIRE(rdata->type == dns_rdatatype_soa);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews UNUSED(owner);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_rdata_toregion(rdata, &region);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_name_init(&name, NULL);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_name_fromregion(&name, &region);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if (!dns_name_ishostname(&name, ISC_FALSE)) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if (bad != NULL)
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_name_clone(&name, bad);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews return (ISC_FALSE);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews }
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews isc_region_consume(&region, name_length(&name));
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_name_fromregion(&name, &region);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if (!dns_name_ismailbox(&name)) {
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews if (bad != NULL)
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews dns_name_clone(&name, bad);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews return (ISC_FALSE);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews }
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews return (ISC_TRUE);
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews}
2047977ce2dfcfe3a0fa2d638c3242841310fad3Mark Andrews
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrewsstatic inline int
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrewscasecompare_soa(ARGS_COMPARE) {
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews return (compare_soa(rdata1, rdata2));
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews}
3d17a3ba61a303d5c4d9867068d0fbe9f24d2988Mark Andrews
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#endif /* RDATA_GENERIC_SOA_6_C */