mirror of
https://github.com/NLnetLabs/unbound.git
synced 2026-02-15 08:37:51 -05:00
target fetch policy setting from config structure.
git-svn-id: file:///svn/unbound/trunk@394 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
1a629da2c3
commit
5543bd63b6
3 changed files with 65 additions and 9 deletions
|
|
@ -55,20 +55,71 @@
|
|||
#include "util/data/msgparse.h"
|
||||
#include "util/random.h"
|
||||
|
||||
/** count number of integers in fetch policy string */
|
||||
static int
|
||||
fetch_count(const char* s)
|
||||
{
|
||||
/* format ::= (sp num)+ sp */
|
||||
/* num ::= [-](0-9)+ */
|
||||
/* sp ::= (space|tab)* */
|
||||
int num = 0;
|
||||
while(*s) {
|
||||
while(*s && isspace(*s))
|
||||
s++;
|
||||
if(!*s) /* end of string */
|
||||
break;
|
||||
if(*s == '-')
|
||||
s++;
|
||||
if(!*s) /* only - not allowed */
|
||||
return 0;
|
||||
if(!isdigit(*s)) /* bad character */
|
||||
return 0;
|
||||
while(*s && isdigit(*s))
|
||||
s++;
|
||||
num++;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
/** fillup fetch policy array */
|
||||
static void
|
||||
fetch_fill(struct iter_env* ie, const char* str)
|
||||
{
|
||||
char* s = (char*)str, *e;
|
||||
int i;
|
||||
for(i=0; i<ie->max_dependency_depth+1; i++) {
|
||||
ie->target_fetch_policy[i] = strtol(s, &e, 10);
|
||||
log_assert(s != e); /* parsed syntax already */
|
||||
s = e;
|
||||
}
|
||||
}
|
||||
|
||||
/** Read config string that represents the target fetch policy */
|
||||
static int
|
||||
read_fetch_policy(struct iter_env* ie, const char* str)
|
||||
{
|
||||
int count = fetch_count(str);
|
||||
if(count < 1) {
|
||||
log_err("Cannot parse target fetch policy: \"%s\"", str);
|
||||
return 0;
|
||||
}
|
||||
ie->max_dependency_depth = count - 1;
|
||||
ie->target_fetch_policy = (int*)calloc(
|
||||
(size_t)ie->max_dependency_depth+1, sizeof(int));
|
||||
if(!ie->target_fetch_policy) {
|
||||
log_err("alloc fetch policy: out of memory");
|
||||
return 0;
|
||||
}
|
||||
fetch_fill(ie, str);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
iter_apply_cfg(struct iter_env* iter_env, struct config_file* cfg)
|
||||
{
|
||||
int i;
|
||||
/* target fetch policy */
|
||||
iter_env->max_dependency_depth = 4;
|
||||
iter_env->target_fetch_policy = (int*)calloc(
|
||||
(size_t)iter_env->max_dependency_depth+1, sizeof(int));
|
||||
if(iter_env->max_dependency_depth >= 1)
|
||||
iter_env->target_fetch_policy[1] = 3;
|
||||
if(iter_env->max_dependency_depth >= 2)
|
||||
iter_env->target_fetch_policy[2] = 1;
|
||||
/* TODO read setting from config */
|
||||
if(!iter_env->target_fetch_policy)
|
||||
if(!read_fetch_policy(iter_env, cfg->target_fetch_policy))
|
||||
return 0;
|
||||
for(i=0; i<iter_env->max_dependency_depth+1; i++)
|
||||
verbose(VERB_DETAIL, "target fetch policy for level %d is %d",
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ config_create()
|
|||
if(!(cfg->directory = strdup("/etc/unbound"))) goto error_exit;
|
||||
if(!(cfg->logfile = strdup(""))) goto error_exit;
|
||||
if(!(cfg->pidfile = strdup("unbound.pid"))) goto error_exit;
|
||||
if(!(cfg->target_fetch_policy = strdup("3 2 1 0 0"))) goto error_exit;
|
||||
cfg->fwd_port = UNBOUND_DNS_PORT;
|
||||
cfg->do_daemonize = 1;
|
||||
cfg->num_ifs = 0;
|
||||
|
|
@ -165,6 +166,7 @@ config_delete(struct config_file* cfg)
|
|||
free(cfg->directory);
|
||||
free(cfg->logfile);
|
||||
free(cfg->pidfile);
|
||||
free(cfg->target_fetch_policy);
|
||||
if(cfg->ifs) {
|
||||
int i;
|
||||
for(i=0; i<cfg->num_ifs; i++)
|
||||
|
|
|
|||
|
|
@ -99,6 +99,9 @@ struct config_file {
|
|||
/** forwarder port */
|
||||
int fwd_port;
|
||||
|
||||
/** the target fetch policy for the iterator */
|
||||
char* target_fetch_policy;
|
||||
|
||||
/** number of interfaces to open. If 0 default all interfaces. */
|
||||
int num_ifs;
|
||||
/** interface description strings (IP addresses) */
|
||||
|
|
|
|||
Loading…
Reference in a new issue