soa_6.c revision 3d17a3ba61a303d5c4d9867068d0fbe9f24d2988
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/*
54db0529dcab47d08996454a076c5e4a0d75e5d2Mark Andrews * Copyright (C) 2004, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Copyright (C) 1998-2002 Internet Software Consortium.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Permission to use, copy, modify, and/or distribute this software for any
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * copyright notice and this permission notice appear in all copies.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews *
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
05f90cac85760b4edef2962209df49ea019c180fMark Andrews/* $Id: soa_6.c,v 1.64 2009/12/04 21:09:34 marka Exp $ */
3761c433912beabe43abeed2c3513b6201c59f64Mark Andrews
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews/* Reviewed: Thu Mar 16 15:18:32 PST 2000 by explorer */
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#ifndef RDATA_GENERIC_SOA_6_C
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley#define RDATA_GENERIC_SOA_6_C
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews#define RRTYPE_SOA_ATTRIBUTES (DNS_RDATATYPEATTR_SINGLETON)
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrewsstatic inline isc_result_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsfromtext_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;
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews isc_uint32_t n;
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews isc_boolean_t ok;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(type == 6);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews UNUSED(type);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews UNUSED(rdclass);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews UNUSED(callbacks);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews origin = (origin != NULL) ? origin : dns_rootname;
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews for (i = 0; i < 2; i++) {
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews RETERR(isc_lex_getmastertoken(lexer, &token,
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews isc_tokentype_string,
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews ISC_FALSE));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&name, NULL);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews buffer_fromregion(&buffer, &token.value.as_region);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews RETTOK(dns_name_fromtext(&name, &buffer, origin,
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews options, target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ok = ISC_TRUE;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if ((options & DNS_RDATA_CHECKNAMES) != 0)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews switch (i) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews case 0:
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ok = dns_name_ishostname(&name, ISC_FALSE);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson break;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson case 1:
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson ok = dns_name_ismailbox(&name);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson break;
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson }
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETTOK(DNS_R_BADNAME);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (!ok && callbacks != NULL)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews warn_badname(&name, lexer, callbacks);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ISC_FALSE));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(uint32_tobuffer(token.value.as_ulong, target));
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews for (i = 0; i < 4; i++) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(isc_lex_getmastertoken(lexer, &token,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_tokentype_string,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews ISC_FALSE));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETTOK(dns_counter_fromtext(&token.value.as_textregion, &n));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(uint32_tobuffer(n, target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (ISC_R_SUCCESS);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic const char *soa_fieldnames[5] = {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews "serial", "refresh", "retry", "expire", "minimum"
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson};
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic inline isc_result_t
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrewstotext_soa(ARGS_TOTEXT) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t dregion;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_name_t mname;
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews dns_name_t rname;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t prefix;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_boolean_t sub;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson int i;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_boolean_t multiline;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_boolean_t comment;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(rdata->type == 6);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson REQUIRE(rdata->length != 0);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews multiline = ISC_TF((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson if (multiline)
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson comment = ISC_TF((tctx->flags & DNS_STYLEFLAG_COMMENT) != 0);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews else
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson comment = ISC_FALSE;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_name_init(&mname, NULL);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_name_init(&rname, NULL);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_name_init(&prefix, NULL);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_rdata_toregion(rdata, &dregion);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_name_fromregion(&mname, &dregion);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_region_consume(&dregion, name_length(&mname));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dns_name_fromregion(&rname, &dregion);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson isc_region_consume(&dregion, name_length(&rname));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson sub = name_prefix(&mname, tctx->origin, &prefix);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(dns_name_totext(&prefix, sub, target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson RETERR(str_totext(" ", target));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson sub = name_prefix(&rname, tctx->origin, &prefix);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(dns_name_totext(&prefix, sub, target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (multiline)
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley RETERR(str_totext(" (" , target));
d981ca645597116d227a48bf37cc5edc061c854dBob Halley RETERR(str_totext(tctx->linebreak, target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews for (i = 0; i < 5; i++) {
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews char buf[sizeof("0123456789 ; ")];
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews unsigned long num;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews num = uint32_fromregion(&dregion);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_consume(&dregion, 4);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews sprintf(buf, comment ? "%-10lu ; " : "%lu", num);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(str_totext(buf, target));
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews if (comment) {
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews RETERR(str_totext(soa_fieldnames[i], target));
d981ca645597116d227a48bf37cc5edc061c854dBob Halley /* Print times in week/day/hour/minute/second form */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (i >= 1) {
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews RETERR(str_totext(" (", target));
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews RETERR(dns_ttl_totext(num, ISC_TRUE, target));
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews RETERR(str_totext(")", target));
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews }
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews RETERR(str_totext(tctx->linebreak, target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews } else if (i < 4) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(str_totext(tctx->linebreak, target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews }
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews }
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (multiline)
26b0f58b6c4d65bc8b131debf40b8c376c2978bfBob Halley RETERR(str_totext(")", target));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (ISC_R_SUCCESS);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews}
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic inline isc_result_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsfromwire_soa(ARGS_FROMWIRE) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t mname;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t rname;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t sregion;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t tregion;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(type == 6);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley UNUSED(type);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews UNUSED(rdclass);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_decompress_setmethods(dctx, DNS_COMPRESS_GLOBAL14);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&mname, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&rname, NULL);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews RETERR(dns_name_fromwire(&mname, source, dctx, options, target));
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews RETERR(dns_name_fromwire(&rname, source, dctx, options, target));
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews isc_buffer_activeregion(source, &sregion);
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews isc_buffer_availableregion(target, &tregion);
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (sregion.length < 20)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (ISC_R_UNEXPECTEDEND);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (tregion.length < 20)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (ISC_R_NOSPACE);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews memcpy(tregion.base, sregion.base, 20);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews isc_buffer_forward(source, 20);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_add(target, 20);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (ISC_R_SUCCESS);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews}
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
bfb2a81b65579882a80855c279cedc45aebd62e8Mark Andrewsstatic inline isc_result_t
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewstowire_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;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_offsets_t moffsets;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_offsets_t roffsets;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley REQUIRE(rdata->type == 6);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(rdata->length != 0);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&mname, moffsets);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&rname, roffsets);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews dns_rdata_toregion(rdata, &sregion);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews dns_name_fromregion(&mname, &sregion);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_consume(&sregion, name_length(&mname));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark 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
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_availableregion(target, &tregion);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (tregion.length < 20)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (ISC_R_NOSPACE);
7c0539bea56022274da04263eb41fbb5b8835c38Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews memcpy(tregion.base, sregion.base, 20);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_add(target, 20);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (ISC_R_SUCCESS);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews}
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic inline int
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewscompare_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;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews int order;
7c0539bea56022274da04263eb41fbb5b8835c38Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(rdata1->type == rdata2->type);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(rdata1->rdclass == rdata2->rdclass);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews REQUIRE(rdata1->type == 6);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews REQUIRE(rdata1->length != 0);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews REQUIRE(rdata2->length != 0);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews dns_name_init(&name1, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&name2, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley dns_rdata_toregion(rdata1, &region1);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley dns_rdata_toregion(rdata2, &region2);
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews dns_name_fromregion(&name1, &region1);
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews dns_name_fromregion(&name2, &region2);
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews
d981ca645597116d227a48bf37cc5edc061c854dBob Halley order = dns_name_rdatacompare(&name1, &name2);
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews if (order != 0)
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews return (order);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_consume(&region1, name_length(&name1));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_consume(&region2, name_length(&name2));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_init(&name1, NULL);
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley dns_name_init(&name2, NULL);
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews dns_name_fromregion(&name1, &region1);
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews dns_name_fromregion(&name2, &region2);
05f90cac85760b4edef2962209df49ea019c180fMark Andrews
05f90cac85760b4edef2962209df49ea019c180fMark Andrews order = dns_name_rdatacompare(&name1, &name2);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews if (order != 0)
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews return (order);
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews
f7b99290c31abeb20c55fc55391510450ce60423Mark Andrews isc_region_consume(&region1, name_length(&name1));
d981ca645597116d227a48bf37cc5edc061c854dBob Halley isc_region_consume(&region2, name_length(&name2));
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews return (isc_region_compare(&region1, &region2));
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews}
05f90cac85760b4edef2962209df49ea019c180fMark Andrews
05f90cac85760b4edef2962209df49ea019c180fMark Andrewsstatic inline isc_result_t
05f90cac85760b4edef2962209df49ea019c180fMark Andrewsfromstruct_soa(ARGS_FROMSTRUCT) {
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews dns_rdata_soa_t *soa = source;
05f90cac85760b4edef2962209df49ea019c180fMark Andrews isc_region_t region;
05f90cac85760b4edef2962209df49ea019c180fMark Andrews
05f90cac85760b4edef2962209df49ea019c180fMark Andrews REQUIRE(type == 6);
05f90cac85760b4edef2962209df49ea019c180fMark Andrews REQUIRE(source != NULL);
05f90cac85760b4edef2962209df49ea019c180fMark Andrews REQUIRE(soa->common.rdtype == type);
05f90cac85760b4edef2962209df49ea019c180fMark Andrews REQUIRE(soa->common.rdclass == rdclass);
05f90cac85760b4edef2962209df49ea019c180fMark Andrews
05f90cac85760b4edef2962209df49ea019c180fMark Andrews UNUSED(type);
05f90cac85760b4edef2962209df49ea019c180fMark Andrews UNUSED(rdclass);
05f90cac85760b4edef2962209df49ea019c180fMark Andrews
05f90cac85760b4edef2962209df49ea019c180fMark Andrews dns_name_toregion(&soa->origin, &region);
05f90cac85760b4edef2962209df49ea019c180fMark Andrews RETERR(isc_buffer_copyregion(target, &region));
05f90cac85760b4edef2962209df49ea019c180fMark Andrews dns_name_toregion(&soa->contact, &region);
05f90cac85760b4edef2962209df49ea019c180fMark Andrews RETERR(isc_buffer_copyregion(target, &region));
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews RETERR(uint32_tobuffer(soa->serial, target));
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews RETERR(uint32_tobuffer(soa->refresh, target));
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews RETERR(uint32_tobuffer(soa->retry, target));
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews RETERR(uint32_tobuffer(soa->expire, target));
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews return (uint32_tobuffer(soa->minimum, target));
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews}
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrewsstatic inline isc_result_t
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrewstostruct_soa(ARGS_TOSTRUCT) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_region_t region;
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews dns_rdata_soa_t *soa = target;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_name_t name;
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews isc_result_t result;
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews REQUIRE(rdata->type == 6);
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews REQUIRE(target != NULL);
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews REQUIRE(rdata->length != 0);
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews soa->common.rdclass = rdata->rdclass;
05f90cac85760b4edef2962209df49ea019c180fMark Andrews soa->common.rdtype = rdata->type;
05f90cac85760b4edef2962209df49ea019c180fMark Andrews ISC_LINK_INIT(&soa->common, link);
05f90cac85760b4edef2962209df49ea019c180fMark Andrews
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews dns_rdata_toregion(rdata, &region);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley dns_name_init(&name, NULL);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley dns_name_fromregion(&name, &region);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley isc_region_consume(&region, name_length(&name));
d981ca645597116d227a48bf37cc5edc061c854dBob Halley dns_name_init(&soa->origin, NULL);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley RETERR(name_duporclone(&name, mctx, &soa->origin));
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
d981ca645597116d227a48bf37cc5edc061c854dBob Halley dns_name_fromregion(&name, &region);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley isc_region_consume(&region, name_length(&name));
d981ca645597116d227a48bf37cc5edc061c854dBob Halley dns_name_init(&soa->contact, NULL);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley result = name_duporclone(&name, mctx, &soa->contact);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley if (result != ISC_R_SUCCESS)
d981ca645597116d227a48bf37cc5edc061c854dBob Halley goto cleanup;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley soa->serial = uint32_fromregion(&region);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley isc_region_consume(&region, 4);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley soa->refresh = uint32_fromregion(&region);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley isc_region_consume(&region, 4);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley soa->retry = uint32_fromregion(&region);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley isc_region_consume(&region, 4);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley soa->expire = uint32_fromregion(&region);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley isc_region_consume(&region, 4);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley soa->minimum = uint32_fromregion(&region);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley soa->mctx = mctx;
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley return (ISC_R_SUCCESS);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley cleanup:
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley if (mctx != NULL)
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley dns_name_free(&soa->origin, mctx);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley return (ISC_R_NOMEMORY);
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley}
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halleystatic inline void
854d0238dbc2908490197984b3b9d558008a53dfMark Andrewsfreestruct_soa(ARGS_FREESTRUCT) {
dns_rdata_soa_t *soa = source;
REQUIRE(source != NULL);
REQUIRE(soa->common.rdtype == 6);
if (soa->mctx == NULL)
return;
dns_name_free(&soa->origin, soa->mctx);
dns_name_free(&soa->contact, soa->mctx);
soa->mctx = NULL;
}
static inline isc_result_t
additionaldata_soa(ARGS_ADDLDATA) {
UNUSED(rdata);
UNUSED(add);
UNUSED(arg);
REQUIRE(rdata->type == 6);
return (ISC_R_SUCCESS);
}
static inline isc_result_t
digest_soa(ARGS_DIGEST) {
isc_region_t r;
dns_name_t name;
REQUIRE(rdata->type == 6);
dns_rdata_toregion(rdata, &r);
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &r);
RETERR(dns_name_digest(&name, digest, arg));
isc_region_consume(&r, name_length(&name));
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &r);
RETERR(dns_name_digest(&name, digest, arg));
isc_region_consume(&r, name_length(&name));
return ((digest)(arg, &r));
}
static inline isc_boolean_t
checkowner_soa(ARGS_CHECKOWNER) {
REQUIRE(type == 6);
UNUSED(name);
UNUSED(type);
UNUSED(rdclass);
UNUSED(wildcard);
return (ISC_TRUE);
}
static inline isc_boolean_t
checknames_soa(ARGS_CHECKNAMES) {
isc_region_t region;
dns_name_t name;
REQUIRE(rdata->type == 6);
UNUSED(owner);
dns_rdata_toregion(rdata, &region);
dns_name_init(&name, NULL);
dns_name_fromregion(&name, &region);
if (!dns_name_ishostname(&name, ISC_FALSE)) {
if (bad != NULL)
dns_name_clone(&name, bad);
return (ISC_FALSE);
}
isc_region_consume(&region, name_length(&name));
dns_name_fromregion(&name, &region);
if (!dns_name_ismailbox(&name)) {
if (bad != NULL)
dns_name_clone(&name, bad);
return (ISC_FALSE);
}
return (ISC_TRUE);
}
static inline int
casecompare_soa(ARGS_COMPARE) {
return (compare_soa(rdata1, rdata2));
}
#endif /* RDATA_GENERIC_SOA_6_C */