Home | History | Annotate | Line # | Download | only in validator
val_kentry.h revision 1.1
      1  1.1  christos /*
      2  1.1  christos  * validator/val_kentry.h - validator key entry definition.
      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 functions for dealing with validator key entries.
     40  1.1  christos  */
     41  1.1  christos 
     42  1.1  christos #ifndef VALIDATOR_VAL_KENTRY_H
     43  1.1  christos #define VALIDATOR_VAL_KENTRY_H
     44  1.1  christos struct packed_rrset_data;
     45  1.1  christos struct regional;
     46  1.1  christos struct ub_packed_rrset_key;
     47  1.1  christos #include "util/storage/lruhash.h"
     48  1.1  christos 
     49  1.1  christos /**
     50  1.1  christos  * A key entry for the validator.
     51  1.1  christos  * This may or may not be a trusted key.
     52  1.1  christos  * This is what is stored in the key cache.
     53  1.1  christos  * This is the key part for the cache; the key entry key.
     54  1.1  christos  */
     55  1.1  christos struct key_entry_key {
     56  1.1  christos 	/** lru hash entry */
     57  1.1  christos 	struct lruhash_entry entry;
     58  1.1  christos 	/** name of the key */
     59  1.1  christos 	uint8_t* name;
     60  1.1  christos 	/** length of name */
     61  1.1  christos 	size_t namelen;
     62  1.1  christos 	/** class of the key, host byteorder */
     63  1.1  christos 	uint16_t key_class;
     64  1.1  christos };
     65  1.1  christos 
     66  1.1  christos /**
     67  1.1  christos  * Key entry for the validator.
     68  1.1  christos  * Contains key status.
     69  1.1  christos  * This is the data part for the cache, the key entry data.
     70  1.1  christos  *
     71  1.1  christos  * Can be in three basic states:
     72  1.1  christos  * 	isbad=0:		good key
     73  1.1  christos  * 	isbad=1:		bad key
     74  1.1  christos  * 	isbad=0 && rrset=0:	insecure space.
     75  1.1  christos  */
     76  1.1  christos struct key_entry_data {
     77  1.1  christos 	/** the TTL of this entry (absolute time) */
     78  1.1  christos 	time_t ttl;
     79  1.1  christos 	/** the key rrdata. can be NULL to signal keyless name. */
     80  1.1  christos 	struct packed_rrset_data* rrset_data;
     81  1.1  christos 	/** not NULL sometimes to give reason why bogus */
     82  1.1  christos 	char* reason;
     83  1.1  christos 	/** list of algorithms signalled, ends with 0, or NULL */
     84  1.1  christos 	uint8_t* algo;
     85  1.1  christos 	/** DNS RR type of the rrset data (host order) */
     86  1.1  christos 	uint16_t rrset_type;
     87  1.1  christos 	/** if the key is bad: Bogus or malformed */
     88  1.1  christos 	uint8_t isbad;
     89  1.1  christos };
     90  1.1  christos 
     91  1.1  christos /** function for lruhash operation */
     92  1.1  christos size_t key_entry_sizefunc(void* key, void* data);
     93  1.1  christos 
     94  1.1  christos /** function for lruhash operation */
     95  1.1  christos int key_entry_compfunc(void* k1, void* k2);
     96  1.1  christos 
     97  1.1  christos /** function for lruhash operation */
     98  1.1  christos void key_entry_delkeyfunc(void* key, void* userarg);
     99  1.1  christos 
    100  1.1  christos /** function for lruhash operation */
    101  1.1  christos void key_entry_deldatafunc(void* data, void* userarg);
    102  1.1  christos 
    103  1.1  christos /** calculate hash for key entry
    104  1.1  christos  * @param kk: key entry. The lruhash entry.hash value is filled in.
    105  1.1  christos  */
    106  1.1  christos void key_entry_hash(struct key_entry_key* kk);
    107  1.1  christos 
    108  1.1  christos /**
    109  1.1  christos  * Copy a key entry, to be region-allocated.
    110  1.1  christos  * @param kkey: the key entry key (and data pointer) to copy.
    111  1.1  christos  * @param region: where to allocate it
    112  1.1  christos  * @return newly region-allocated entry or NULL on a failure to allocate.
    113  1.1  christos  */
    114  1.1  christos struct key_entry_key* key_entry_copy_toregion(struct key_entry_key* kkey,
    115  1.1  christos 	struct regional* region);
    116  1.1  christos 
    117  1.1  christos /**
    118  1.1  christos  * Copy a key entry, malloced.
    119  1.1  christos  * @param kkey: the key entry key (and data pointer) to copy.
    120  1.1  christos  * @return newly allocated entry or NULL on a failure to allocate memory.
    121  1.1  christos  */
    122  1.1  christos struct key_entry_key* key_entry_copy(struct key_entry_key* kkey);
    123  1.1  christos 
    124  1.1  christos /**
    125  1.1  christos  * See if this is a null entry. Does not do locking.
    126  1.1  christos  * @param kkey: must have data pointer set correctly
    127  1.1  christos  * @return true if it is a NULL rrset entry.
    128  1.1  christos  */
    129  1.1  christos int key_entry_isnull(struct key_entry_key* kkey);
    130  1.1  christos 
    131  1.1  christos /**
    132  1.1  christos  * See if this entry is good. Does not do locking.
    133  1.1  christos  * @param kkey: must have data pointer set correctly
    134  1.1  christos  * @return true if it is good.
    135  1.1  christos  */
    136  1.1  christos int key_entry_isgood(struct key_entry_key* kkey);
    137  1.1  christos 
    138  1.1  christos /**
    139  1.1  christos  * See if this entry is bad. Does not do locking.
    140  1.1  christos  * @param kkey: must have data pointer set correctly
    141  1.1  christos  * @return true if it is bad.
    142  1.1  christos  */
    143  1.1  christos int key_entry_isbad(struct key_entry_key* kkey);
    144  1.1  christos 
    145  1.1  christos /**
    146  1.1  christos  * Set reason why a key is bad.
    147  1.1  christos  * @param kkey: bad key.
    148  1.1  christos  * @param reason: string to attach, you must allocate it.
    149  1.1  christos  *    Not safe to call twice unless you deallocate it yourself.
    150  1.1  christos  */
    151  1.1  christos void key_entry_set_reason(struct key_entry_key* kkey, char* reason);
    152  1.1  christos 
    153  1.1  christos /**
    154  1.1  christos  * Get reason why a key is bad.
    155  1.1  christos  * @param kkey: bad key
    156  1.1  christos  * @return pointer to string.
    157  1.1  christos  *    String is part of key entry and is deleted with it.
    158  1.1  christos  */
    159  1.1  christos char* key_entry_get_reason(struct key_entry_key* kkey);
    160  1.1  christos 
    161  1.1  christos /**
    162  1.1  christos  * Create a null entry, in the given region.
    163  1.1  christos  * @param region: where to allocate
    164  1.1  christos  * @param name: the key name
    165  1.1  christos  * @param namelen: length of name
    166  1.1  christos  * @param dclass: class of key entry. (host order);
    167  1.1  christos  * @param ttl: what ttl should the key have. relative.
    168  1.1  christos  * @param now: current time (added to ttl).
    169  1.1  christos  * @return new key entry or NULL on alloc failure
    170  1.1  christos  */
    171  1.1  christos struct key_entry_key* key_entry_create_null(struct regional* region,
    172  1.1  christos 	uint8_t* name, size_t namelen, uint16_t dclass, time_t ttl,
    173  1.1  christos 	time_t now);
    174  1.1  christos 
    175  1.1  christos /**
    176  1.1  christos  * Create a key entry from an rrset, in the given region.
    177  1.1  christos  * @param region: where to allocate.
    178  1.1  christos  * @param name: the key name
    179  1.1  christos  * @param namelen: length of name
    180  1.1  christos  * @param dclass: class of key entry. (host order);
    181  1.1  christos  * @param rrset: data for key entry. This is copied to the region.
    182  1.1  christos  * @param sigalg: signalled algorithm list (or NULL).
    183  1.1  christos  * @param now: current time (added to ttl of rrset)
    184  1.1  christos  * @return new key entry or NULL on alloc failure
    185  1.1  christos  */
    186  1.1  christos struct key_entry_key* key_entry_create_rrset(struct regional* region,
    187  1.1  christos         uint8_t* name, size_t namelen, uint16_t dclass,
    188  1.1  christos 	struct ub_packed_rrset_key* rrset, uint8_t* sigalg, time_t now);
    189  1.1  christos 
    190  1.1  christos /**
    191  1.1  christos  * Create a bad entry, in the given region.
    192  1.1  christos  * @param region: where to allocate
    193  1.1  christos  * @param name: the key name
    194  1.1  christos  * @param namelen: length of name
    195  1.1  christos  * @param dclass: class of key entry. (host order);
    196  1.1  christos  * @param ttl: what ttl should the key have. relative.
    197  1.1  christos  * @param now: current time (added to ttl).
    198  1.1  christos  * @return new key entry or NULL on alloc failure
    199  1.1  christos  */
    200  1.1  christos struct key_entry_key* key_entry_create_bad(struct regional* region,
    201  1.1  christos 	uint8_t* name, size_t namelen, uint16_t dclass, time_t ttl,
    202  1.1  christos 	time_t now);
    203  1.1  christos 
    204  1.1  christos /**
    205  1.1  christos  * Obtain rrset from a key entry, allocated in region.
    206  1.1  christos  * @param kkey: key entry to convert to a rrset.
    207  1.1  christos  * @param region: where to allocate rrset
    208  1.1  christos  * @return rrset copy; if no rrset or alloc error returns NULL.
    209  1.1  christos  */
    210  1.1  christos struct ub_packed_rrset_key* key_entry_get_rrset(struct key_entry_key* kkey,
    211  1.1  christos 	struct regional* region);
    212  1.1  christos 
    213  1.1  christos /**
    214  1.1  christos  * Get keysize of the keyentry.
    215  1.1  christos  * @param kkey: key, must be a good key, with contents.
    216  1.1  christos  * @return size in bits of the key.
    217  1.1  christos  */
    218  1.1  christos size_t key_entry_keysize(struct key_entry_key* kkey);
    219  1.1  christos 
    220  1.1  christos #endif /* VALIDATOR_VAL_KENTRY_H */
    221