mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-20 23:00:56 -05:00
Config options for infra cache.
git-svn-id: file:///svn/unbound/trunk@325 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
ccb924d55f
commit
69bfd93616
9 changed files with 142 additions and 60 deletions
|
|
@ -51,6 +51,7 @@
|
|||
#include "util/storage/slabhash.h"
|
||||
#include "services/listen_dnsport.h"
|
||||
#include "services/cache/rrset.h"
|
||||
#include "services/cache/infra.h"
|
||||
#include "util/module.h"
|
||||
#include "iterator/iterator.h"
|
||||
#include <signal.h>
|
||||
|
|
@ -121,26 +122,12 @@ daemon_init()
|
|||
signal_handling_record();
|
||||
checklock_start();
|
||||
daemon->need_to_exit = 0;
|
||||
daemon->msg_cache = slabhash_create(HASH_DEFAULT_SLABS,
|
||||
HASH_DEFAULT_STARTARRAY, HASH_DEFAULT_MAXMEM,
|
||||
msgreply_sizefunc, query_info_compare,
|
||||
query_entry_delete, reply_info_delete, NULL);
|
||||
if(!daemon->msg_cache) {
|
||||
if(!(daemon->env = (struct module_env*)calloc(1,
|
||||
sizeof(*daemon->env)))) {
|
||||
free(daemon);
|
||||
return NULL;
|
||||
}
|
||||
alloc_init(&daemon->superalloc, NULL, 0);
|
||||
daemon->rrset_cache = rrset_cache_create(NULL, &daemon->superalloc);
|
||||
if(!daemon->rrset_cache) {
|
||||
slabhash_delete(daemon->msg_cache);
|
||||
free(daemon);
|
||||
return NULL;
|
||||
}
|
||||
if(!(daemon->env = (struct module_env*)calloc(1,
|
||||
sizeof(*daemon->env)))) {
|
||||
daemon_delete(daemon);
|
||||
return NULL;
|
||||
}
|
||||
return daemon;
|
||||
}
|
||||
|
||||
|
|
@ -173,8 +160,6 @@ static void daemon_setup_modules(struct daemon* daemon)
|
|||
}
|
||||
daemon->modfunc[0] = iter_get_funcblock();
|
||||
daemon->env->cfg = daemon->cfg;
|
||||
daemon->env->msg_cache = daemon->msg_cache;
|
||||
daemon->env->rrset_cache = daemon->rrset_cache;
|
||||
daemon->env->alloc = &daemon->superalloc;
|
||||
daemon->env->worker = NULL;
|
||||
daemon->env->send_query = &worker_send_query;
|
||||
|
|
@ -380,8 +365,11 @@ daemon_delete(struct daemon* daemon)
|
|||
if(!daemon)
|
||||
return;
|
||||
listening_ports_free(daemon->ports);
|
||||
slabhash_delete(daemon->msg_cache);
|
||||
rrset_cache_delete(daemon->rrset_cache);
|
||||
if(daemon->env) {
|
||||
slabhash_delete(daemon->env->msg_cache);
|
||||
rrset_cache_delete(daemon->env->rrset_cache);
|
||||
infra_delete(daemon->env->infra_cache);
|
||||
}
|
||||
alloc_clear(&daemon->superalloc);
|
||||
free(daemon->cwd);
|
||||
free(daemon->pidfile);
|
||||
|
|
|
|||
|
|
@ -74,10 +74,6 @@ struct daemon {
|
|||
int need_to_exit;
|
||||
/** master allocation cache */
|
||||
struct alloc_cache superalloc;
|
||||
/** the message cache, content is struct msgreply_entry* */
|
||||
struct slabhash* msg_cache;
|
||||
/** the rrset cache, content is struct ub_packed_rrset_key* */
|
||||
struct rrset_cache* rrset_cache;
|
||||
/** the module environment master value, copied and changed by threads*/
|
||||
struct module_env* env;
|
||||
/** number of modules active, ids from 0 to num-1. */
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@
|
|||
#include "util/storage/slabhash.h"
|
||||
#include "services/listen_dnsport.h"
|
||||
#include "services/cache/rrset.h"
|
||||
#include "services/cache/infra.h"
|
||||
#include "util/data/msgreply.h"
|
||||
#include "util/module.h"
|
||||
#include <signal.h>
|
||||
|
|
@ -120,22 +121,24 @@ apply_dir(struct daemon* daemon, struct config_file* cfg, int cmdline_verbose)
|
|||
log_err("cwd: malloc failed");
|
||||
}
|
||||
}
|
||||
if(cfg->msg_cache_size != slabhash_get_size(daemon->msg_cache) ||
|
||||
cfg->msg_cache_slabs != daemon->msg_cache->size) {
|
||||
slabhash_delete(daemon->msg_cache);
|
||||
daemon->msg_cache = slabhash_create(cfg->msg_cache_slabs,
|
||||
if(!daemon->env->msg_cache ||
|
||||
cfg->msg_cache_size != slabhash_get_size(daemon->env->msg_cache) ||
|
||||
cfg->msg_cache_slabs != daemon->env->msg_cache->size) {
|
||||
slabhash_delete(daemon->env->msg_cache);
|
||||
daemon->env->msg_cache = slabhash_create(cfg->msg_cache_slabs,
|
||||
HASH_DEFAULT_STARTARRAY, cfg->msg_cache_size,
|
||||
msgreply_sizefunc, query_info_compare,
|
||||
query_entry_delete, reply_info_delete, NULL);
|
||||
if(!daemon->msg_cache) {
|
||||
if(!daemon->env->msg_cache) {
|
||||
fatal_exit("malloc failure updating config settings");
|
||||
}
|
||||
}
|
||||
if((daemon->rrset_cache = rrset_cache_adjust(daemon->rrset_cache,
|
||||
cfg, &daemon->superalloc)) == 0)
|
||||
fatal_exit("malloc failure updating config settings");
|
||||
daemon->env->rrset_cache = daemon->rrset_cache;
|
||||
daemon->env->msg_cache = daemon->msg_cache;
|
||||
if((daemon->env->rrset_cache = rrset_cache_adjust(
|
||||
daemon->env->rrset_cache, cfg, &daemon->superalloc)) == 0)
|
||||
fatal_exit("malloc failure updating config settings");
|
||||
if((daemon->env->infra_cache = infra_adjust(daemon->env->infra_cache,
|
||||
cfg))==0)
|
||||
fatal_exit("malloc failure updating config settings");
|
||||
checkrlimits(cfg);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
- services/cache/rrset.c for rrset cache code.
|
||||
- special rrset_cache LRU updating function that uses the rrset id.
|
||||
- no dependencies calculation when make clean is called.
|
||||
- config settings for infra cache.
|
||||
- daemon code slightly cleaner, only creates caches once.
|
||||
|
||||
15 May 2007: Wouter
|
||||
- host cache code.
|
||||
|
|
|
|||
19
services/cache/infra.c
vendored
19
services/cache/infra.c
vendored
|
|
@ -121,6 +121,25 @@ infra_delete(struct infra_cache* infra)
|
|||
free(infra);
|
||||
}
|
||||
|
||||
struct infra_cache*
|
||||
infra_adjust(struct infra_cache* infra, struct config_file* cfg)
|
||||
{
|
||||
size_t maxmem;
|
||||
if(!infra)
|
||||
return infra_create(cfg);
|
||||
infra->host_ttl = cfg->host_ttl;
|
||||
infra->lame_ttl = cfg->lame_ttl;
|
||||
infra->max_lame = cfg->infra_cache_numlame;
|
||||
maxmem = cfg->infra_cache_numhosts *
|
||||
(sizeof(struct infra_host_key)+sizeof(struct infra_host_data));
|
||||
if(maxmem != slabhash_get_size(infra->hosts) ||
|
||||
cfg->infra_cache_slabs != infra->hosts->size) {
|
||||
infra_delete(infra);
|
||||
infra = infra_create(cfg);
|
||||
}
|
||||
return infra;
|
||||
}
|
||||
|
||||
/** calculate the hash value for a host key */
|
||||
static hashvalue_t
|
||||
hash_addr(struct sockaddr_storage* addr, socklen_t addrlen)
|
||||
|
|
|
|||
13
services/cache/infra.h
vendored
13
services/cache/infra.h
vendored
|
|
@ -114,7 +114,7 @@ struct infra_cache {
|
|||
|
||||
/**
|
||||
* Create infra cache.
|
||||
* @param cfg: config parameters.
|
||||
* @param cfg: config parameters or NULL for defaults.
|
||||
* @return: new infra cache, or NULL.
|
||||
*/
|
||||
struct infra_cache* infra_create(struct config_file* cfg);
|
||||
|
|
@ -125,6 +125,17 @@ struct infra_cache* infra_create(struct config_file* cfg);
|
|||
*/
|
||||
void infra_delete(struct infra_cache* infra);
|
||||
|
||||
/**
|
||||
* Adjust infra cache to use updated configuration settings.
|
||||
* This may clean the cache. Operates a bit like realloc.
|
||||
* There may be no threading or use by other threads.
|
||||
* @param infra: existing cache. If NULL a new infra cache is returned.
|
||||
* @param cfg: config options.
|
||||
* @return the new infra cache pointer or NULL on error.
|
||||
*/
|
||||
struct infra_cache* infra_adjust(struct infra_cache* infra,
|
||||
struct config_file* cfg);
|
||||
|
||||
/**
|
||||
* Lookup host data
|
||||
* @param infra: infrastructure cache.
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ void ub_c_error(const char *message);
|
|||
#define LEXOUT(s)
|
||||
#endif
|
||||
|
||||
#define YDOUT LEXOUT(("v(%s )", yytext))
|
||||
|
||||
struct inc_state {
|
||||
char* filename;
|
||||
int line;
|
||||
|
|
@ -96,30 +98,35 @@ ANY [^\"\n\r\\]|\\.
|
|||
%%
|
||||
{SPACE}* { LEXOUT(("SP ")); /* ignore */ }
|
||||
{SPACE}*{COMMENT}.* { LEXOUT(("comment(%s) ", yytext)); /* ignore */ }
|
||||
server{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_SERVER;}
|
||||
num-threads{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_NUM_THREADS;}
|
||||
verbosity{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_VERBOSITY;}
|
||||
port{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_PORT;}
|
||||
outgoing-port{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_OUTGOING_PORT;}
|
||||
outgoing-range{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_OUTGOING_RANGE;}
|
||||
outgoing-num-tcp{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_OUTGOING_NUM_TCP;}
|
||||
do-ip4{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_DO_IP4;}
|
||||
do-ip6{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_DO_IP6;}
|
||||
do-udp{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_DO_UDP;}
|
||||
do-tcp{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_DO_TCP;}
|
||||
forward-to{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_FORWARD_TO;}
|
||||
forward-to-port{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_FORWARD_TO_PORT;}
|
||||
interface{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_INTERFACE;}
|
||||
chroot{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_CHROOT;}
|
||||
username{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_USERNAME;}
|
||||
directory{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_DIRECTORY;}
|
||||
logfile{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_LOGFILE;}
|
||||
pidfile{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_PIDFILE;}
|
||||
msg-cache-size{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_MSG_CACHE_SIZE;}
|
||||
msg-cache-slabs{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_MSG_CACHE_SLABS;}
|
||||
rrset-cache-size{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_RRSET_CACHE_SIZE;}
|
||||
rrset-cache-slabs{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_RRSET_CACHE_SLABS;}
|
||||
num-queries-per-thread{COLON} { LEXOUT(("v(%s) ", yytext)); return VAR_NUM_QUERIES_PER_THREAD;}
|
||||
server{COLON} { YDOUT; return VAR_SERVER;}
|
||||
num-threads{COLON} { YDOUT; return VAR_NUM_THREADS;}
|
||||
verbosity{COLON} { YDOUT; return VAR_VERBOSITY;}
|
||||
port{COLON} { YDOUT; return VAR_PORT;}
|
||||
outgoing-port{COLON} { YDOUT; return VAR_OUTGOING_PORT;}
|
||||
outgoing-range{COLON} { YDOUT; return VAR_OUTGOING_RANGE;}
|
||||
outgoing-num-tcp{COLON} { YDOUT; return VAR_OUTGOING_NUM_TCP;}
|
||||
do-ip4{COLON} { YDOUT; return VAR_DO_IP4;}
|
||||
do-ip6{COLON} { YDOUT; return VAR_DO_IP6;}
|
||||
do-udp{COLON} { YDOUT; return VAR_DO_UDP;}
|
||||
do-tcp{COLON} { YDOUT; return VAR_DO_TCP;}
|
||||
forward-to{COLON} { YDOUT; return VAR_FORWARD_TO;}
|
||||
forward-to-port{COLON} { YDOUT; return VAR_FORWARD_TO_PORT;}
|
||||
interface{COLON} { YDOUT; return VAR_INTERFACE;}
|
||||
chroot{COLON} { YDOUT; return VAR_CHROOT;}
|
||||
username{COLON} { YDOUT; return VAR_USERNAME;}
|
||||
directory{COLON} { YDOUT; return VAR_DIRECTORY;}
|
||||
logfile{COLON} { YDOUT; return VAR_LOGFILE;}
|
||||
pidfile{COLON} { YDOUT; return VAR_PIDFILE;}
|
||||
msg-cache-size{COLON} { YDOUT; return VAR_MSG_CACHE_SIZE;}
|
||||
msg-cache-slabs{COLON} { YDOUT; return VAR_MSG_CACHE_SLABS;}
|
||||
rrset-cache-size{COLON} { YDOUT; return VAR_RRSET_CACHE_SIZE;}
|
||||
rrset-cache-slabs{COLON} { YDOUT; return VAR_RRSET_CACHE_SLABS;}
|
||||
infra-host-ttl{COLON} { YDOUT; return VAR_INFRA_HOST_TTL;}
|
||||
infra-lame-ttl{COLON} { YDOUT; return VAR_INFRA_LAME_TTL;}
|
||||
infra-cache-slabs{COLON} { YDOUT; return VAR_INFRA_CACHE_SLABS;}
|
||||
infra-cache-numhosts{COLON} { YDOUT; return VAR_INFRA_CACHE_NUMHOSTS;}
|
||||
infra-cache-numlame{COLON} { YDOUT; return VAR_INFRA_CACHE_NUMLAME;}
|
||||
num-queries-per-thread{COLON} { YDOUT; return VAR_NUM_QUERIES_PER_THREAD;}
|
||||
{NEWLINE} { LEXOUT(("NL\n")); cfg_parser->line++;}
|
||||
|
||||
/* Quoted strings. Strip leading and ending quotes */
|
||||
|
|
|
|||
|
|
@ -74,6 +74,8 @@ extern struct config_parser_state* cfg_parser;
|
|||
%token VAR_USERNAME VAR_DIRECTORY VAR_LOGFILE VAR_PIDFILE
|
||||
%token VAR_MSG_CACHE_SIZE VAR_MSG_CACHE_SLABS VAR_NUM_QUERIES_PER_THREAD
|
||||
%token VAR_RRSET_CACHE_SIZE VAR_RRSET_CACHE_SLABS VAR_OUTGOING_NUM_TCP
|
||||
%token VAR_INFRA_HOST_TTL VAR_INFRA_LAME_TTL VAR_INFRA_CACHE_SLABS
|
||||
%token VAR_INFRA_CACHE_NUMHOSTS VAR_INFRA_CACHE_NUMLAME
|
||||
|
||||
%%
|
||||
toplevelvars: /* empty */ | toplevelvars toplevelvar ;
|
||||
|
|
@ -97,7 +99,10 @@ content_server: server_num_threads | server_verbosity | server_port |
|
|||
server_username | server_directory | server_logfile | server_pidfile |
|
||||
server_msg_cache_size | server_msg_cache_slabs |
|
||||
server_num_queries_per_thread | server_rrset_cache_size |
|
||||
server_rrset_cache_slabs | server_outgoing_num_tcp
|
||||
server_rrset_cache_slabs | server_outgoing_num_tcp |
|
||||
server_infra_host_ttl | server_infra_lame_ttl |
|
||||
server_infra_cache_slabs | server_infra_cache_numhosts |
|
||||
server_infra_cache_numlame
|
||||
;
|
||||
server_num_threads: VAR_NUM_THREADS STRING
|
||||
{
|
||||
|
|
@ -306,6 +311,55 @@ server_rrset_cache_slabs: VAR_RRSET_CACHE_SLABS STRING
|
|||
free($2);
|
||||
}
|
||||
;
|
||||
server_infra_host_ttl: VAR_INFRA_HOST_TTL STRING
|
||||
{
|
||||
OUTYY(("P(server_infra_host_ttl:%s)\n", $2));
|
||||
if(atoi($2) == 0 && strcmp($2, "0") != 0)
|
||||
yyerror("number expected");
|
||||
else cfg_parser->cfg->host_ttl = atoi($2);
|
||||
free($2);
|
||||
}
|
||||
;
|
||||
server_infra_lame_ttl: VAR_INFRA_LAME_TTL STRING
|
||||
{
|
||||
OUTYY(("P(server_infra_lame_ttl:%s)\n", $2));
|
||||
if(atoi($2) == 0 && strcmp($2, "0") != 0)
|
||||
yyerror("number expected");
|
||||
else cfg_parser->cfg->lame_ttl = atoi($2);
|
||||
free($2);
|
||||
}
|
||||
;
|
||||
server_infra_cache_numhosts: VAR_INFRA_CACHE_NUMHOSTS STRING
|
||||
{
|
||||
OUTYY(("P(server_infra_cache_numhosts:%s)\n", $2));
|
||||
if(atoi($2) == 0)
|
||||
yyerror("number expected");
|
||||
else cfg_parser->cfg->infra_cache_numhosts = atoi($2);
|
||||
free($2);
|
||||
}
|
||||
;
|
||||
server_infra_cache_numlame: VAR_INFRA_CACHE_NUMLAME STRING
|
||||
{
|
||||
OUTYY(("P(server_infra_cache_numlame:%s)\n", $2));
|
||||
if(atoi($2) == 0)
|
||||
yyerror("number expected");
|
||||
else cfg_parser->cfg->infra_cache_numlame = atoi($2);
|
||||
free($2);
|
||||
}
|
||||
;
|
||||
server_infra_cache_slabs: VAR_INFRA_CACHE_SLABS STRING
|
||||
{
|
||||
OUTYY(("P(server_infra_cache_slabs:%s)\n", $2));
|
||||
if(atoi($2) == 0)
|
||||
yyerror("number expected");
|
||||
else {
|
||||
cfg_parser->cfg->infra_cache_slabs = atoi($2);
|
||||
if(!is_pow2(cfg_parser->cfg->infra_cache_slabs))
|
||||
yyerror("must be a power of 2");
|
||||
}
|
||||
free($2);
|
||||
}
|
||||
;
|
||||
%%
|
||||
|
||||
/* parse helper routines could be here */
|
||||
|
|
|
|||
|
|
@ -69,6 +69,8 @@ struct module_env {
|
|||
struct slabhash* msg_cache;
|
||||
/** shared rrset cache */
|
||||
struct rrset_cache* rrset_cache;
|
||||
/** shared infrastructure cache (edns, lameness) */
|
||||
struct infra_cache* infra_cache;
|
||||
|
||||
/* --- services --- */
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue