Home | History | Annotate | Line # | Download | only in data
packed_rrset.h revision 1.1.1.4
      1      1.1  christos /*
      2      1.1  christos  * util/data/packed_rrset.h - data storage for a set of resource records.
      3      1.1  christos  *
      4      1.1  christos  * Copyright (c) 2007, NLnet Labs. All rights reserved.
      5      1.1  christos  *
      6      1.1  christos  * This software is open source.
      7      1.1  christos  *
      8      1.1  christos  * Redistribution and use in source and binary forms, with or without
      9      1.1  christos  * modification, are permitted provided that the following conditions
     10      1.1  christos  * are met:
     11      1.1  christos  *
     12      1.1  christos  * Redistributions of source code must retain the above copyright notice,
     13      1.1  christos  * this list of conditions and the following disclaimer.
     14      1.1  christos  *
     15      1.1  christos  * Redistributions in binary form must reproduce the above copyright notice,
     16      1.1  christos  * this list of conditions and the following disclaimer in the documentation
     17      1.1  christos  * and/or other materials provided with the distribution.
     18      1.1  christos  *
     19      1.1  christos  * Neither the name of the NLNET LABS nor the names of its contributors may
     20      1.1  christos  * be used to endorse or promote products derived from this software without
     21      1.1  christos  * specific prior written permission.
     22      1.1  christos  *
     23      1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     24      1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     25      1.1  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     26      1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     27      1.1  christos  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     28      1.1  christos  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
     29      1.1  christos  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     30      1.1  christos  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     31      1.1  christos  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     32      1.1  christos  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     33      1.1  christos  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34      1.1  christos  */
     35      1.1  christos 
     36      1.1  christos /**
     37      1.1  christos  * \file
     38      1.1  christos  *
     39      1.1  christos  * This file contains the data storage for RRsets.
     40      1.1  christos  */
     41      1.1  christos 
     42      1.1  christos #ifndef UTIL_DATA_PACKED_RRSET_H
     43      1.1  christos #define UTIL_DATA_PACKED_RRSET_H
     44      1.1  christos #include "util/storage/lruhash.h"
     45      1.1  christos struct alloc_cache;
     46      1.1  christos struct regional;
     47      1.1  christos 
     48      1.1  christos /** type used to uniquely identify rrsets. Cannot be reused without
     49      1.1  christos  * clearing the cache. */
     50  1.1.1.2  christos typedef uint64_t rrset_id_type;
     51      1.1  christos 
     52      1.1  christos /** this rrset is NSEC and is at zone apex (at child side of zonecut) */
     53      1.1  christos #define PACKED_RRSET_NSEC_AT_APEX 0x1
     54      1.1  christos /** this rrset is A/AAAA and is in-zone-glue (from parent side of zonecut) */
     55      1.1  christos #define PACKED_RRSET_PARENT_SIDE 0x2
     56      1.1  christos /** this rrset is SOA and has the negative ttl (from nxdomain or nodata),
     57      1.1  christos  * this is set on SOA rrsets in the authority section, to keep its TTL separate
     58      1.1  christos  * from the SOA in the answer section from a direct SOA query or ANY query. */
     59      1.1  christos #define PACKED_RRSET_SOA_NEG 0x4
     60  1.1.1.2  christos /** This rrset is considered to have a fixed TTL; its TTL doesn't have to be
     61  1.1.1.2  christos  * updated on encoding in a reply.  This flag is not expected to be set in
     62  1.1.1.2  christos  * cached data. */
     63  1.1.1.2  christos #define PACKED_RRSET_FIXEDTTL 0x80000000
     64      1.1  christos 
     65      1.1  christos /** number of rrs and rrsets for integer overflow protection.  More than
     66      1.1  christos  * this is not really possible (64K packet has much less RRs and RRsets) in
     67      1.1  christos  * a message.  And this is small enough that also multiplied there is no
     68      1.1  christos  * integer overflow. */
     69      1.1  christos #define RR_COUNT_MAX 0xffffff
     70      1.1  christos 
     71      1.1  christos /**
     72      1.1  christos  * The identifying information for an RRset.
     73      1.1  christos  */
     74      1.1  christos struct packed_rrset_key {
     75      1.1  christos 	/**
     76      1.1  christos 	 * The domain name. If not null (for id=0) it is allocated, and
     77      1.1  christos 	 * contains the wireformat domain name.
     78      1.1  christos 	 * This dname is not canonicalized.
     79      1.1  christos 	 */
     80      1.1  christos 	uint8_t* dname;
     81      1.1  christos 	/**
     82      1.1  christos 	 * Length of the domain name, including last 0 root octet.
     83      1.1  christos 	 */
     84      1.1  christos 	size_t dname_len;
     85      1.1  christos 	/**
     86      1.1  christos 	 * Flags. 32bit to be easy for hashing:
     87      1.1  christos 	 * 	o PACKED_RRSET_NSEC_AT_APEX
     88      1.1  christos 	 * 	o PACKED_RRSET_PARENT_SIDE
     89      1.1  christos 	 * 	o PACKED_RRSET_SOA_NEG
     90  1.1.1.2  christos 	 * 	o PACKED_RRSET_FIXEDTTL (not supposed to be cached)
     91      1.1  christos 	 */
     92      1.1  christos 	uint32_t flags;
     93      1.1  christos 	/** the rrset type in network format */
     94      1.1  christos 	uint16_t type;
     95      1.1  christos 	/** the rrset class in network format */
     96      1.1  christos 	uint16_t rrset_class;
     97      1.1  christos };
     98      1.1  christos 
     99      1.1  christos /**
    100      1.1  christos  * This structure contains an RRset. A set of resource records that
    101      1.1  christos  * share the same domain name, type and class.
    102      1.1  christos  *
    103      1.1  christos  * Due to memory management and threading, the key structure cannot be
    104      1.1  christos  * deleted, although the data can be. The id can be set to 0 to store and the
    105      1.1  christos  * structure can be recycled with a new id.
    106      1.1  christos  */
    107      1.1  christos struct ub_packed_rrset_key {
    108      1.1  christos 	/**
    109      1.1  christos 	 * entry into hashtable. Note the lock is never destroyed,
    110      1.1  christos 	 *  even when this key is retired to the cache.
    111      1.1  christos 	 * the data pointer (if not null) points to a struct packed_rrset.
    112      1.1  christos 	 */
    113      1.1  christos 	struct lruhash_entry entry;
    114      1.1  christos 	/**
    115      1.1  christos 	 * the ID of this rrset. unique, based on threadid + sequenceno.
    116      1.1  christos 	 * ids are not reused, except after flushing the cache.
    117      1.1  christos 	 * zero is an unused entry, and never a valid id.
    118      1.1  christos 	 * Check this value after getting entry.lock.
    119      1.1  christos 	 * The other values in this struct may only be altered after changing
    120      1.1  christos 	 * the id (which needs a writelock on entry.lock).
    121      1.1  christos 	 */
    122  1.1.1.2  christos 	rrset_id_type id;
    123      1.1  christos 	/** key data: dname, type and class */
    124      1.1  christos 	struct packed_rrset_key rk;
    125      1.1  christos };
    126      1.1  christos 
    127      1.1  christos /**
    128      1.1  christos  * RRset trustworthiness. Bigger value is more trust. RFC 2181.
    129      1.1  christos  * The rrset_trust_add_noAA, rrset_trust_auth_noAA, rrset_trust_add_AA,
    130      1.1  christos  * are mentioned as the same trustworthiness in 2181, but split up here
    131      1.1  christos  * for ease of processing.
    132      1.1  christos  *
    133      1.1  christos  * rrset_trust_nonauth_ans_AA, rrset_trust_ans_noAA
    134      1.1  christos  * are also mentioned as the same trustworthiness in 2181, but split up here
    135      1.1  christos  * for ease of processing.
    136      1.1  christos  *
    137      1.1  christos  * Added trust_none for a sane initial value, smaller than anything else.
    138      1.1  christos  * Added validated and ultimate trust for keys and rrsig validated content.
    139      1.1  christos  */
    140      1.1  christos enum rrset_trust {
    141      1.1  christos 	/** initial value for trust */
    142      1.1  christos 	rrset_trust_none = 0,
    143      1.1  christos 	/** Additional information from non-authoritative answers */
    144      1.1  christos 	rrset_trust_add_noAA,
    145      1.1  christos 	/** Data from the authority section of a non-authoritative answer */
    146      1.1  christos 	rrset_trust_auth_noAA,
    147      1.1  christos 	/** Additional information from an authoritative answer */
    148      1.1  christos 	rrset_trust_add_AA,
    149      1.1  christos 	/** non-authoritative data from the answer section of authoritative
    150      1.1  christos 	 * answers */
    151      1.1  christos 	rrset_trust_nonauth_ans_AA,
    152      1.1  christos 	/** Data from the answer section of a non-authoritative answer */
    153      1.1  christos 	rrset_trust_ans_noAA,
    154      1.1  christos 	/** Glue from a primary zone, or glue from a zone transfer */
    155      1.1  christos 	rrset_trust_glue,
    156      1.1  christos 	/** Data from the authority section of an authoritative answer */
    157      1.1  christos 	rrset_trust_auth_AA,
    158      1.1  christos 	/** The authoritative data included in the answer section of an
    159      1.1  christos 	 *  authoritative reply */
    160      1.1  christos 	rrset_trust_ans_AA,
    161      1.1  christos 	/** Data from a zone transfer, other than glue */
    162      1.1  christos 	rrset_trust_sec_noglue,
    163      1.1  christos 	/** Data from a primary zone file, other than glue data */
    164      1.1  christos 	rrset_trust_prim_noglue,
    165      1.1  christos 	/** DNSSEC(rfc4034) validated with trusted keys */
    166      1.1  christos 	rrset_trust_validated,
    167      1.1  christos 	/** ultimately trusted, no more trust is possible;
    168      1.1  christos 	 * trusted keys from the unbound configuration setup. */
    169      1.1  christos 	rrset_trust_ultimate
    170      1.1  christos };
    171      1.1  christos 
    172      1.1  christos /**
    173      1.1  christos  * Security status from validation for data.
    174      1.1  christos  * The order is significant; more secure, more proven later.
    175      1.1  christos  */
    176      1.1  christos enum sec_status {
    177      1.1  christos 	/** UNCHECKED means that object has yet to be validated. */
    178      1.1  christos 	sec_status_unchecked = 0,
    179      1.1  christos 	/** BOGUS means that the object (RRset or message) failed to validate
    180      1.1  christos 	 *  (according to local policy), but should have validated. */
    181      1.1  christos 	sec_status_bogus,
    182      1.1  christos 	/** INDETERMINATE means that the object is insecure, but not
    183      1.1  christos 	 * authoritatively so. Generally this means that the RRset is not
    184      1.1  christos 	 * below a configured trust anchor. */
    185      1.1  christos 	sec_status_indeterminate,
    186      1.1  christos 	/** INSECURE means that the object is authoritatively known to be
    187      1.1  christos 	 * insecure. Generally this means that this RRset is below a trust
    188      1.1  christos 	 * anchor, but also below a verified, insecure delegation. */
    189      1.1  christos 	sec_status_insecure,
    190  1.1.1.3  christos 	/** SECURE_SENTINEL_FAIL means that the object (RRset or message)
    191  1.1.1.3  christos 	 * validated according to local policy but did not succeed in the root
    192  1.1.1.3  christos 	 * KSK sentinel test (draft-ietf-dnsop-kskroll-sentinel). */
    193  1.1.1.3  christos 	sec_status_secure_sentinel_fail,
    194      1.1  christos 	/** SECURE means that the object (RRset or message) validated
    195      1.1  christos 	 * according to local policy. */
    196      1.1  christos 	sec_status_secure
    197      1.1  christos };
    198      1.1  christos 
    199      1.1  christos /**
    200      1.1  christos  * RRset data.
    201      1.1  christos  *
    202      1.1  christos  * The data is packed, stored contiguously in memory.
    203  1.1.1.2  christos  *
    204  1.1.1.2  christos  * It is not always stored contiguously, in that case, an unpacked-packed
    205  1.1.1.2  christos  * rrset has the arrays separate.  A bunch of routines work on that, but
    206  1.1.1.2  christos  * the packed rrset that is contiguous is for the rrset-cache and the
    207  1.1.1.2  christos  * cache-response routines in daemon/worker.c.
    208  1.1.1.2  christos  *
    209      1.1  christos  * memory layout:
    210      1.1  christos  *	o base struct
    211      1.1  christos  *	o rr_len size_t array
    212      1.1  christos  *	o rr_data uint8_t* array
    213      1.1  christos  *	o rr_ttl time_t array (after size_t and ptrs because those may be
    214      1.1  christos  *		64bit and this array before those would make them unaligned).
    215      1.1  christos  *		Since the stuff before is 32/64bit, rr_ttl is 32 bit aligned.
    216      1.1  christos  *	o rr_data rdata wireformats
    217      1.1  christos  *	o rrsig_data rdata wireformat(s)
    218      1.1  christos  *
    219      1.1  christos  * Rdata is stored in wireformat. The dname is stored in wireformat.
    220      1.1  christos  * TTLs are stored as absolute values (and could be expired).
    221      1.1  christos  *
    222      1.1  christos  * RRSIGs are stored in the arrays after the regular rrs.
    223      1.1  christos  *
    224      1.1  christos  * You need the packed_rrset_key to know dname, type, class of the
    225      1.1  christos  * resource records in this RRset. (if signed the rrsig gives the type too).
    226      1.1  christos  *
    227      1.1  christos  * On the wire an RR is:
    228      1.1  christos  *	name, type, class, ttl, rdlength, rdata.
    229      1.1  christos  * So we need to send the following per RR:
    230      1.1  christos  *	key.dname, ttl, rr_data[i].
    231      1.1  christos  *	since key.dname ends with type and class.
    232      1.1  christos  *	and rr_data starts with the rdlength.
    233      1.1  christos  *	the ttl value to send changes due to time.
    234      1.1  christos  */
    235      1.1  christos struct packed_rrset_data {
    236  1.1.1.4  christos 	/** Timestamp added to TTLs in the packed data.
    237  1.1.1.4  christos 	 * Needed to support serving original TTLs. */
    238  1.1.1.4  christos 	time_t ttl_add;
    239      1.1  christos 	/** TTL (in seconds like time()) of the rrset.
    240      1.1  christos 	 * Same for all RRs see rfc2181(5.2).  */
    241      1.1  christos 	time_t ttl;
    242      1.1  christos 	/** number of rrs. */
    243      1.1  christos 	size_t count;
    244      1.1  christos 	/** number of rrsigs, if 0 no rrsigs */
    245      1.1  christos 	size_t rrsig_count;
    246      1.1  christos 	/** the trustworthiness of the rrset data */
    247      1.1  christos 	enum rrset_trust trust;
    248      1.1  christos 	/** security status of the rrset data */
    249      1.1  christos 	enum sec_status security;
    250      1.1  christos 	/** length of every rr's rdata, rr_len[i] is size of rr_data[i]. */
    251      1.1  christos 	size_t* rr_len;
    252      1.1  christos 	/** ttl of every rr. rr_ttl[i] ttl of rr i. */
    253      1.1  christos 	time_t *rr_ttl;
    254      1.1  christos 	/**
    255      1.1  christos 	 * Array of pointers to every rr's rdata.
    256      1.1  christos 	 * The rr_data[i] rdata is stored in uncompressed wireformat.
    257      1.1  christos 	 * The first uint16_t of rr_data[i] is network format rdlength.
    258      1.1  christos 	 *
    259      1.1  christos 	 * rr_data[count] to rr_data[count+rrsig_count] contain the rrsig data.
    260      1.1  christos 	 */
    261      1.1  christos 	uint8_t** rr_data;
    262      1.1  christos };
    263      1.1  christos 
    264      1.1  christos /**
    265      1.1  christos  * An RRset can be represented using both key and data together.
    266      1.1  christos  * Split into key and data structures to simplify implementation of
    267      1.1  christos  * caching schemes.
    268      1.1  christos  */
    269      1.1  christos struct packed_rrset {
    270      1.1  christos 	/** domain name, type and class */
    271      1.1  christos 	struct packed_rrset_key* k;
    272      1.1  christos 	/** ttl, count and rdatas (and rrsig) */
    273      1.1  christos 	struct packed_rrset_data* d;
    274      1.1  christos };
    275      1.1  christos 
    276      1.1  christos /**
    277      1.1  christos  * list of packed rrsets
    278      1.1  christos  */
    279      1.1  christos struct packed_rrset_list {
    280      1.1  christos 	/** next in list */
    281      1.1  christos 	struct packed_rrset_list* next;
    282      1.1  christos 	/** rrset key and data */
    283      1.1  christos 	struct packed_rrset rrset;
    284      1.1  christos };
    285      1.1  christos 
    286      1.1  christos /**
    287      1.1  christos  * Delete packed rrset key and data, not entered in hashtables yet.
    288      1.1  christos  * Used during parsing.
    289      1.1  christos  * @param pkey: rrset key structure with locks, key and data pointers.
    290      1.1  christos  * @param alloc: where to return the unfree-able key structure.
    291      1.1  christos  */
    292      1.1  christos void ub_packed_rrset_parsedelete(struct ub_packed_rrset_key* pkey,
    293      1.1  christos 	struct alloc_cache* alloc);
    294      1.1  christos 
    295      1.1  christos /**
    296      1.1  christos  * Memory size of rrset data. RRset data must be filled in correctly.
    297      1.1  christos  * @param data: data to examine.
    298      1.1  christos  * @return size in bytes.
    299      1.1  christos  */
    300      1.1  christos size_t packed_rrset_sizeof(struct packed_rrset_data* data);
    301      1.1  christos 
    302      1.1  christos /**
    303      1.1  christos  * Get TTL of rrset. RRset data must be filled in correctly.
    304      1.1  christos  * @param key: rrset key, with data to examine.
    305      1.1  christos  * @return ttl value.
    306      1.1  christos  */
    307      1.1  christos time_t ub_packed_rrset_ttl(struct ub_packed_rrset_key* key);
    308      1.1  christos 
    309      1.1  christos /**
    310      1.1  christos  * Calculate memory size of rrset entry. For hash table usage.
    311      1.1  christos  * @param key: struct ub_packed_rrset_key*.
    312      1.1  christos  * @param data: struct packed_rrset_data*.
    313      1.1  christos  * @return size in bytes.
    314      1.1  christos  */
    315      1.1  christos size_t ub_rrset_sizefunc(void* key, void* data);
    316      1.1  christos 
    317      1.1  christos /**
    318      1.1  christos  * compares two rrset keys.
    319      1.1  christos  * @param k1: struct ub_packed_rrset_key*.
    320      1.1  christos  * @param k2: struct ub_packed_rrset_key*.
    321      1.1  christos  * @return 0 if equal.
    322      1.1  christos  */
    323      1.1  christos int ub_rrset_compare(void* k1, void* k2);
    324      1.1  christos 
    325      1.1  christos /**
    326      1.1  christos  * compare two rrset data structures.
    327      1.1  christos  * Compared rdata and rrsigdata, not the trust or ttl value.
    328      1.1  christos  * @param d1: data to compare.
    329      1.1  christos  * @param d2: data to compare.
    330      1.1  christos  * @return 1 if equal.
    331      1.1  christos  */
    332      1.1  christos int rrsetdata_equal(struct packed_rrset_data* d1, struct packed_rrset_data* d2);
    333      1.1  christos 
    334      1.1  christos /**
    335      1.1  christos  * Old key to be deleted. RRset keys are recycled via alloc.
    336      1.1  christos  * The id is set to 0. So that other threads, after acquiring a lock always
    337      1.1  christos  * get the correct value, in this case the 0 deleted-special value.
    338      1.1  christos  * @param key: struct ub_packed_rrset_key*.
    339      1.1  christos  * @param userdata: alloc structure to use for recycling.
    340      1.1  christos  */
    341      1.1  christos void ub_rrset_key_delete(void* key, void* userdata);
    342      1.1  christos 
    343      1.1  christos /**
    344      1.1  christos  * Old data to be deleted.
    345      1.1  christos  * @param data: what to delete.
    346      1.1  christos  * @param userdata: user data ptr.
    347      1.1  christos  */
    348      1.1  christos void rrset_data_delete(void* data, void* userdata);
    349      1.1  christos 
    350      1.1  christos /**
    351      1.1  christos  * Calculate hash value for a packed rrset key.
    352      1.1  christos  * @param key: the rrset key with name, type, class, flags.
    353      1.1  christos  * @return hash value.
    354      1.1  christos  */
    355  1.1.1.2  christos hashvalue_type rrset_key_hash(struct packed_rrset_key* key);
    356      1.1  christos 
    357      1.1  christos /**
    358      1.1  christos  * Fixup pointers in fixed data packed_rrset_data blob.
    359      1.1  christos  * After a memcpy of the data for example. Will set internal pointers right.
    360      1.1  christos  * @param data: rrset data structure. Otherwise correctly filled in.
    361      1.1  christos  */
    362      1.1  christos void packed_rrset_ptr_fixup(struct packed_rrset_data* data);
    363      1.1  christos 
    364      1.1  christos /**
    365      1.1  christos  * Fixup TTLs in fixed data packed_rrset_data blob.
    366      1.1  christos  * @param data: rrset data structure. Otherwise correctly filled in.
    367      1.1  christos  * @param add: how many seconds to add, pass time(0) for example.
    368      1.1  christos  */
    369      1.1  christos void packed_rrset_ttl_add(struct packed_rrset_data* data, time_t add);
    370      1.1  christos 
    371      1.1  christos /**
    372      1.1  christos  * Utility procedure to extract CNAME target name from its rdata.
    373      1.1  christos  * Failsafes; it will change passed dname to a valid dname or do nothing.
    374      1.1  christos  * @param rrset: the rrset structure. Must be a CNAME.
    375      1.1  christos  *	Only first RR is used (multiple RRs are technically illegal anyway).
    376      1.1  christos  * 	Also works on type DNAME. Returns target name.
    377      1.1  christos  * @param dname: this pointer is updated to point into the cname rdata.
    378      1.1  christos  *	If a failsafe fails, nothing happens to the pointer (such as the
    379      1.1  christos  *	rdata was not a valid dname, not a CNAME, ...).
    380      1.1  christos  * @param dname_len: length of dname is returned.
    381      1.1  christos  */
    382      1.1  christos void get_cname_target(struct ub_packed_rrset_key* rrset, uint8_t** dname,
    383      1.1  christos 	size_t* dname_len);
    384      1.1  christos 
    385      1.1  christos /**
    386      1.1  christos  * Get a printable string for a rrset trust value
    387      1.1  christos  * @param s: rrset trust value
    388      1.1  christos  * @return printable string.
    389      1.1  christos  */
    390      1.1  christos const char* rrset_trust_to_string(enum rrset_trust s);
    391      1.1  christos 
    392      1.1  christos /**
    393      1.1  christos  * Get a printable string for a security status value
    394      1.1  christos  * @param s: security status
    395      1.1  christos  * @return printable string.
    396      1.1  christos  */
    397      1.1  christos const char* sec_status_to_string(enum sec_status s);
    398      1.1  christos 
    399      1.1  christos /**
    400      1.1  christos  * Print string with neat domain name, type, class from rrset.
    401      1.1  christos  * @param v: at what verbosity level to print this.
    402      1.1  christos  * @param str: string of message.
    403      1.1  christos  * @param rrset: structure with name, type and class.
    404      1.1  christos  */
    405      1.1  christos void log_rrset_key(enum verbosity_value v, const char* str,
    406      1.1  christos 	struct ub_packed_rrset_key* rrset);
    407      1.1  christos 
    408      1.1  christos /**
    409      1.1  christos  * Convert RR from RRset to string.
    410      1.1  christos  * @param rrset: structure with data.
    411      1.1  christos  * @param i: index of rr or RRSIG.
    412      1.1  christos  * @param now: time that is subtracted from ttl before printout. Can be 0.
    413      1.1  christos  * @param dest: destination string buffer. Must be nonNULL.
    414      1.1  christos  * @param dest_len: length of dest buffer (>0).
    415      1.1  christos  * @return false on failure.
    416      1.1  christos  */
    417      1.1  christos int packed_rr_to_string(struct ub_packed_rrset_key* rrset, size_t i,
    418      1.1  christos 	time_t now, char* dest, size_t dest_len);
    419      1.1  christos 
    420      1.1  christos /**
    421      1.1  christos  * Print the string with prefix, one rr per line.
    422      1.1  christos  * @param v: at what verbosity level to print this.
    423      1.1  christos  * @param str: string of message.
    424      1.1  christos  * @param rrset: with name, and rdata, and rrsigs.
    425      1.1  christos  */
    426      1.1  christos void log_packed_rrset(enum verbosity_value v, const char* str,
    427      1.1  christos 	struct ub_packed_rrset_key* rrset);
    428      1.1  christos 
    429      1.1  christos /**
    430      1.1  christos  * Allocate rrset in region - no more locks needed
    431      1.1  christos  * @param key: a (just from rrset cache looked up) rrset key + valid,
    432      1.1  christos  * 	packed data record.
    433      1.1  christos  * @param region: where to alloc the copy
    434      1.1  christos  * @param now: adjust the TTLs to be relative (subtract from all TTLs).
    435      1.1  christos  * @return new region-alloced rrset key or NULL on alloc failure.
    436      1.1  christos  */
    437      1.1  christos struct ub_packed_rrset_key* packed_rrset_copy_region(
    438      1.1  christos 	struct ub_packed_rrset_key* key, struct regional* region,
    439      1.1  christos 	time_t now);
    440      1.1  christos 
    441      1.1  christos /**
    442      1.1  christos  * Allocate rrset with malloc (from region or you are holding the lock).
    443      1.1  christos  * @param key: key with data entry.
    444      1.1  christos  * @param alloc: alloc_cache to create rrset_keys
    445      1.1  christos  * @param now: adjust the TTLs to be absolute (add to all TTLs).
    446      1.1  christos  * @return new region-alloced rrset key or NULL on alloc failure.
    447      1.1  christos  */
    448      1.1  christos struct ub_packed_rrset_key* packed_rrset_copy_alloc(
    449      1.1  christos 	struct ub_packed_rrset_key* key, struct alloc_cache* alloc,
    450      1.1  christos 	time_t now);
    451      1.1  christos 
    452  1.1.1.4  christos /**
    453  1.1.1.4  christos  * Find RR index in packed rrset
    454  1.1.1.4  christos  * Raw comparison, does not canonicalize RDATA
    455  1.1.1.4  christos  * @param d: packed rrset
    456  1.1.1.4  christos  * @param rdata: RDATA of RR to find
    457  1.1.1.4  christos  * @param len: length of rdata
    458  1.1.1.4  christos  * @param index: pointer to int to store index of found RR
    459  1.1.1.4  christos  * @return 1 if RR found, 0 otherwise
    460  1.1.1.4  christos  */
    461  1.1.1.4  christos int
    462  1.1.1.4  christos packed_rrset_find_rr(struct packed_rrset_data* d, uint8_t* rdata, size_t len,
    463  1.1.1.4  christos 	size_t* index);
    464  1.1.1.4  christos 
    465      1.1  christos #endif /* UTIL_DATA_PACKED_RRSET_H */
    466