Logo Search packages:      
Sourcecode: unbound version File versions  Download package

config_file.h

Go to the documentation of this file.
/*
 * util/config_file.h - reads and stores the config file for unbound.
 *
 * Copyright (c) 2007, NLnet Labs. All rights reserved.
 *
 * This software is open source.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * 
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 * 
 * Neither the name of the NLNET LABS nor the names of its contributors may
 * be used to endorse or promote products derived from this software without
 * specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * \file
 *
 * This file contains functions for the config file.
 */

#ifndef UTIL_CONFIG_FILE_H
#define UTIL_CONFIG_FILE_H
struct config_stub;
struct config_strlist;
struct config_str2list;

/**
 * The configuration options.
 * Strings are malloced.
 */
00052 struct config_file {
      /** verbosity level as specified in the config file */
00054       int verbosity;

      /** statistics interval (in seconds) */
00057       int stat_interval;
      /** if false, statistics values are reset after printing them */
00059       int stat_cumulative;

      /** number of threads to create */
00062       int num_threads;

      /** port on which queries are answered. */
00065       int port;
      /** do ip4 query support. */
00067       int do_ip4;
      /** do ip6 query support. */
00069       int do_ip6;
      /** do udp query support. */
00071       int do_udp;
      /** do tcp query support. */
00073       int do_tcp;

      /** outgoing port range number of ports (per thread) */
00076       int outgoing_num_ports;
      /** number of outgoing tcp buffers per (per thread) */
00078       size_t outgoing_num_tcp;
      /** number of incoming tcp buffers per (per thread) */
00080       size_t incoming_num_tcp;
      /** allowed udp port numbers, array with 0 if not allowed */
00082       int* outgoing_avail_ports;

      /** number of bytes buffer size for DNS messages */
00085       size_t msg_buffer_size;
      /** size of the message cache */
00087       size_t msg_cache_size;
      /** slabs in the message cache. */
00089       size_t msg_cache_slabs;
      /** number of queries every thread can service */
00091       size_t num_queries_per_thread;
      /** size of the rrset cache */
00093       size_t rrset_cache_size;
      /** slabs in the rrset cache */
00095       size_t rrset_cache_slabs;
      /** host cache ttl in seconds */
00097       int host_ttl;
      /** host is lame for a zone ttl, in seconds */
00099       int lame_ttl;
      /** number of slabs in the infra host cache */
00101       size_t infra_cache_slabs;
      /** max number of hosts in the infra cache */
00103       size_t infra_cache_numhosts;
      /** max size of lame zones per host in the infra cache */
00105       size_t infra_cache_lame_size;

      /** the target fetch policy for the iterator */
00108       char* target_fetch_policy;

      /** automatic interface for incoming messages. Uses ipv6 remapping,
       * and recvmsg/sendmsg ancillary data to detect interfaces, boolean */
00112       int if_automatic;

      /** number of interfaces to open. If 0 default all interfaces. */
00115       int num_ifs;
      /** interface description strings (IP addresses) */
00117       char **ifs;

      /** number of outgoing interfaces to open. 
       * If 0 default all interfaces. */
00121       int num_out_ifs;
      /** outgoing interface description strings (IP addresses) */
00123       char **out_ifs;

      /** the root hints */
00126       struct config_strlist* root_hints;
      /** the stub definitions, linked list */
00128       struct config_stub* stubs;
      /** the forward zone definitions, linked list */
00130       struct config_stub* forwards;
      /** list of donotquery addresses, linked list */
00132       struct config_strlist* donotqueryaddrs;
      /** list of access control entries, linked list */
00134       struct config_str2list* acls;
      /** use default localhost donotqueryaddr entries */
00136       int donotquery_localhost;

      /** harden against very small edns buffer sizes */
00139       int harden_short_bufsize;
      /** harden against very large query sizes */
00141       int harden_large_queries;
      /** harden against spoofed glue (out of zone data) */
00143       int harden_glue;
      /** harden against receiving no DNSSEC data for trust anchor */
00145       int harden_dnssec_stripped;
      /** use 0x20 bits in query as random ID bits */
00147       int use_caps_bits_for_id;

      /** chrootdir, if not "" or chroot will be done */
00150       char* chrootdir;
      /** username to change to, if not "". */
00152       char* username;
      /** working directory */
00154       char* directory;
      /** filename to log to. */
00156       char* logfile;
      /** pidfile to write pid to. */
00158       char* pidfile;

      /** should log messages be sent to syslogd */
00161       int use_syslog;

      /** do not report identity (id.server, hostname.bind) */
00164       int hide_identity;
      /** do not report version (version.server, version.bind) */
00166       int hide_version;
      /** identity, hostname is returned if "". */
00168       char* identity;
      /** version, package version returned if "". */
00170       char* version;

      /** the module configuration string */
00173       char* module_conf;
      
      /** files with trusted DS and DNSKEYs in zonefile format, list */
00176       struct config_strlist* trust_anchor_file_list;
      /** list of trustanchor keys, linked list */
00178       struct config_strlist* trust_anchor_list;
      /** files with trusted DNSKEYs in named.conf format, list */
00180       struct config_strlist* trusted_keys_file_list;

      /** the number of seconds maximal TTL used for RRsets and messages */
00183       int max_ttl;
      /** if not 0, this value is the validation date for RRSIGs */
00185       int32_t val_date_override;
      /** this value sets the number of seconds before revalidating bogus */
00187       int bogus_ttl; 
      /** should validator clean additional section for secure msgs */
00189       int val_clean_additional;
      /** should validator allow bogus messages to go through */
00191       int val_permissive_mode;
      /** nsec3 maximum iterations per key size, string */
00193       char* val_nsec3_key_iterations;

      /** size of the key cache */
00196       size_t key_cache_size;
      /** slabs in the key cache. */
00198       size_t key_cache_slabs;

      /** local zones config */
00201       struct config_str2list* local_zones;
      /** local zones nodefault list */
00203       struct config_strlist* local_zones_nodefault;
      /** local data RRs configged */
00205       struct config_strlist* local_data;

      /** daemonize, i.e. fork into the background. */
00208       int do_daemonize;
};

/**
 * Stub config options
 */
00214 struct config_stub {
      /** next in list */
00216       struct config_stub* next;
      /** domain name (in text) of the stub apex domain */
00218       char* name;
      /** list of stub nameserver hosts (domain name) */
00220       struct config_strlist* hosts;
      /** list of stub nameserver addresses (IP address) */
00222       struct config_strlist* addrs;
};

/**
 * List of strings for config options
 */
00228 struct config_strlist {
      /** next item in list */
00230       struct config_strlist* next;
      /** config option string */
00232       char* str;
};

/**
 * List of two strings for config options
 */
00238 struct config_str2list {
      /** next item in list */
00240       struct config_str2list* next;
      /** first string */
00242       char* str;
      /** second string */
00244       char* str2;
};

/**
 * Create config file structure. Filled with default values.
 * @return: the new structure or NULL on memory error.
 */
struct config_file* config_create();

/**
 * Create config file structure for library use. Filled with default values.
 * @return: the new structure or NULL on memory error.
 */
struct config_file* config_create_forlib();

/**
 * Read the config file from the specified filename.
 * @param config: where options are stored into, must be freshly created.
 * @param filename: name of configfile. If NULL nothing is done.
 * @return: false on error. In that case errno is set, ENOENT means 
 *    file not found.
 */
int config_read(struct config_file* config, char* filename);

/**
 * Destroy the config file structure.
 * @param config: to delete.
 */
void config_delete(struct config_file* config);

/**
 * Apply config to global constants; this routine is called in single thread.
 * @param config: to apply. Side effect: global constants change.
 */
void config_apply(struct config_file* config);

/**
 * Set the given keyword to the given value.
 * @param config: where to store config
 * @param option: option name, including the ':' character.
 * @param value: value, this string is copied if needed, or parsed.
 *    The caller owns the value string.
 * @return 0 on error (malloc or syntax error).
 */
int config_set_option(struct config_file* config, const char* option,
      const char* value);

/**
 * Insert string into strlist.
 * @param head: pointer to strlist head variable.
 * @param item: new item. malloced by caller. If NULL the insertion fails.
 * @return: true on success.
 */
int cfg_strlist_insert(struct config_strlist** head, char* item);

/**
 * Insert string into str2list.
 * @param head: pointer to str2list head variable.
 * @param item: new item. malloced by caller. If NULL the insertion fails.
 * @param i2: 2nd string, malloced by caller. If NULL the insertion fails.
 * @return: true on success.
 */
int cfg_str2list_insert(struct config_str2list** head, char* item, char* i2);

/**
 * Delete items in config string list.
 * @param list: list.
 */
void config_delstrlist(struct config_strlist* list);

/**
 * Delete items in config double string list.
 * @param list: list.
 */
void config_deldblstrlist(struct config_str2list* list);

/**
 * Delete items in config stub list.
 * @param list: list.
 */
void config_delstubs(struct config_stub* list);

/**
 * Convert 14digit to time value
 * @param str: string of 14 digits
 * @return time value or 0 for error.
 */
uint32_t cfg_convert_timeval(const char* str);

/**
 * Count number of values in the string.
 * format ::= (sp num)+ sp
 * num ::= [-](0-9)+
 * sp ::= (space|tab)*
 *
 * @param str: string
 * @return: 0 on parse error, or empty string, else
 *    number of integer values in the string.
 */
int cfg_count_numbers(const char* str);

/**
 * Convert a 'nice' memory or file size into a bytecount
 * From '100k' to 102400. and so on. Understands kKmMgG.
 * k=1024, m=1024*1024, g=1024*1024*1024.
 * @param str: string
 * @param res: result is stored here, size in bytes.
 * @return: true if parsed correctly, or 0 on a parse error (and an error 
 * is logged).
 */
int cfg_parse_memsize(const char* str, size_t* res);

/**
 * Mark "number" or "low-high" as available or not in ports array.
 * @param str: string in input
 * @param allow: give true if this range is permitted.
 * @param avail: the array from cfg.
 * @param num: size of the array (65536).
 * @return: true if parsed correctly, or 0 on a parse error (and an error 
 * is logged).
 */
int cfg_mark_ports(const char* str, int allow, int* avail, int num);

/**
 * Get a condensed list of ports returned. allocated.
 * @param cfg: config file.
 * @param avail: the available ports array is returned here.
 * @return: number of ports in array or 0 on error.
 */
int cfg_condense_ports(struct config_file* cfg, int** avail);

/**
 * Scan ports available
 * @param avail: the array from cfg.
 * @param num: size of the array (65536).
 * @return the number of ports available for use.
 */
int cfg_scan_ports(int* avail, int num);

/**
 * Used during options parsing
 */
00386 struct config_parser_state {
      /** name of file being parser */
00388       char* filename;
      /** line number in the file, starts at 1 */
00390       int line;
      /** number of errors encountered */
00392       int errors;
      /** the result of parsing is stored here. */
00394       struct config_file* cfg;
};

/** global config parser object used during config parsing */
extern struct config_parser_state* cfg_parser;
/** parsing helpers: print error with file and line numbers */
void ub_c_error(const char* msg);
/** parsing helpers: print error with file and line numbers */
void ub_c_error_msg(const char* fmt, ...) ATTR_FORMAT(printf, 1, 2);

#endif /* UTIL_CONFIG_FILE_H */

Generated by  Doxygen 1.6.0   Back to index