cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 1999-2002, 2004-2008, 2016 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/.
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff */
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater/* $Id: rdataslab.h,v 1.33 2008/04/01 23:47:10 tbox Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff#ifndef DNS_RDATASLAB_H
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff#define DNS_RDATASLAB_H 1
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff
29747dfe5e073a299b3681e01f5c55540f8bfed7Mark Andrews/*! \file dns/rdataslab.h
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \brief
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * Implements storage of rdatasets into slabs of memory.
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff *
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * MP:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li Clients of this module must impose any required synchronization.
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff *
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * Reliability:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li This module deals with low-level byte streams. Errors in any of
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * the functions are likely to crash the server or corrupt memory.
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li If the caller passes invalid memory references, these functions are
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley * likely to crash the server or corrupt memory.
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley *
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * Resources:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li None.
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff *
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * Security:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li None.
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff *
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * Standards:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li None.
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff */
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff/***
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff *** Imports
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff ***/
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley#include <isc/lang.h>
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff#include <dns/types.h>
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff
904a5734375869ffb504ed8cde6b68cafadb6d64Bob HalleyISC_LANG_BEGINDECLS
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley
012c6d0b9114a2eacd3ec5e61f5cab47993a4d15Mark Andrews#define DNS_RDATASLAB_FORCE 0x1
012c6d0b9114a2eacd3ec5e61f5cab47993a4d15Mark Andrews#define DNS_RDATASLAB_EXACT 0x2
012c6d0b9114a2eacd3ec5e61f5cab47993a4d15Mark Andrews
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews#define DNS_RDATASLAB_OFFLINE 0x01 /* RRSIG is for offline DNSKEY */
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews#define DNS_RDATASLAB_WARNMASK 0x0E /*%< RRSIG(DNSKEY) expired
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews * warnings number mask. */
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews#define DNS_RDATASLAB_WARNSHIFT 1 /*%< How many bits to shift to find
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews * remaining expired warning number. */
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
a76b380643a22f23a67a9df284e86cd7ef7608c1Mark Andrews
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff/***
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff *** Functions
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff ***/
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graffdns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx,
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff isc_region_t *region, unsigned int reservelen);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * Slabify a rdataset. The slab area will be allocated and returned
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * in 'region'.
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff *
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * Requires:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'rdataset' is valid.
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff *
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * Ensures:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'region' will have base pointing to the start of allocated memory,
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * with the slabified region beginning at region->base + reservelen.
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * region->length contains the total length allocated.
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff *
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * Returns:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li ISC_R_SUCCESS - successful completion
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li ISC_R_NOMEMORY - no memory.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li XXX others
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff */
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellingtonvoid
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellingtondns_rdataslab_tordataset(unsigned char *slab, unsigned int reservelen,
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_rdataclass_t rdclass, dns_rdatatype_t rdtype,
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_rdatatype_t covers, dns_ttl_t ttl,
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington dns_rdataset_t *rdataset);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington * Construct an rdataset from a slab.
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington *
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington * Requires:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'slab' points to a slab.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'rdataset' is disassociated.
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington *
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington * Ensures:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'rdataset' is associated and points to a valid rdataest.
8cf24d101a291aa3274e8fd07d1a13cb5fe9976bBrian Wellington */
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halleyunsigned int
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halleydns_rdataslab_size(unsigned char *slab, unsigned int reservelen);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
e800570a5a7572a94604815cd7d7e788c0479ed2Bob Halley * Return the total size of an rdataslab.
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff *
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * Requires:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'slab' points to a slab.
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff *
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff * Returns:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li The number of bytes in the slab, including the reservelen.
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff */
cd82aa8fa32698240ecd6634f11e3052ca7a2448Michael Graff
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrewsunsigned int
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrewsdns_rdataslab_count(unsigned char *slab, unsigned int reservelen);
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews/*%<
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews * Return the number of records in the rdataslab
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews *
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews * Requires:
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews *\li 'slab' points to a slab.
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews *
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews * Returns:
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews *\li The number of records in the slab.
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews */
744c1db6352c4c3f11c8538e4a2a57c8b0e0d570Mark Andrews
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halleydns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab,
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley unsigned int reservelen, isc_mem_t *mctx,
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley dns_rdataclass_t rdclass, dns_rdatatype_t type,
012c6d0b9114a2eacd3ec5e61f5cab47993a4d15Mark Andrews unsigned int flags, unsigned char **tslabp);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley * Merge 'oslab' and 'nslab'.
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley */
5bfea18ff8bfa907b86ba7d17fb38b9cf493ae97Bob Halley
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graffisc_result_t
926cde044f4334f7afd9d1123ab0f01ec93e7e72Bob Halleydns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab,
926cde044f4334f7afd9d1123ab0f01ec93e7e72Bob Halley unsigned int reservelen, isc_mem_t *mctx,
926cde044f4334f7afd9d1123ab0f01ec93e7e72Bob Halley dns_rdataclass_t rdclass, dns_rdatatype_t type,
f8abaa0fae7f75d9601c10b6a4af8dd907494d45Mark Andrews unsigned int flags, unsigned char **tslabp);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
b55c30f2de6e1baaa3a9ba69b92f428f2c255ac3Mark Andrews * Subtract 'sslab' from 'mslab'. If 'exact' is true then all elements
b55c30f2de6e1baaa3a9ba69b92f428f2c255ac3Mark Andrews * of 'sslab' must exist in 'mslab'.
926cde044f4334f7afd9d1123ab0f01ec93e7e72Bob Halley *
926cde044f4334f7afd9d1123ab0f01ec93e7e72Bob Halley * XXX
f8abaa0fae7f75d9601c10b6a4af8dd907494d45Mark Andrews * valid flags are DNS_RDATASLAB_EXACT
926cde044f4334f7afd9d1123ab0f01ec93e7e72Bob Halley */
926cde044f4334f7afd9d1123ab0f01ec93e7e72Bob Halley
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellingtonisc_boolean_t
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellingtondns_rdataslab_equal(unsigned char *slab1, unsigned char *slab2,
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington unsigned int reservelen);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
6434457b0b380aa43d7159299776959a00269d65Michael Graff * Compare two rdataslabs for equality. This does _not_ do a full
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington * DNSSEC comparison.
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington *
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington * Requires:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'slab1' and 'slab2' point to slabs.
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington *
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington * Returns:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li ISC_TRUE if the slabs are equal, ISC_FALSE otherwise.
88b9c12a3cbafc3bebedf50a731bec9ce2f99a13Brian Wellington */
6434457b0b380aa43d7159299776959a00269d65Michael Graffisc_boolean_t
6434457b0b380aa43d7159299776959a00269d65Michael Graffdns_rdataslab_equalx(unsigned char *slab1, unsigned char *slab2,
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater unsigned int reservelen, dns_rdataclass_t rdclass,
6434457b0b380aa43d7159299776959a00269d65Michael Graff dns_rdatatype_t type);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
e672951ed28b2e9cc7a19c3d7fa4a258382f981cAutomatic Updater * Compare two rdataslabs for DNSSEC equality.
6434457b0b380aa43d7159299776959a00269d65Michael Graff *
6434457b0b380aa43d7159299776959a00269d65Michael Graff * Requires:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li 'slab1' and 'slab2' point to slabs.
6434457b0b380aa43d7159299776959a00269d65Michael Graff *
6434457b0b380aa43d7159299776959a00269d65Michael Graff * Returns:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li ISC_TRUE if the slabs are equal, #ISC_FALSE otherwise.
6434457b0b380aa43d7159299776959a00269d65Michael Graff */
6434457b0b380aa43d7159299776959a00269d65Michael Graff
904a5734375869ffb504ed8cde6b68cafadb6d64Bob HalleyISC_LANG_ENDDECLS
904a5734375869ffb504ed8cde6b68cafadb6d64Bob Halley
4be63b1fd8c18dbeca1648d6cf22fa14f057a469David Lawrence#endif /* DNS_RDATASLAB_H */