mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-31 11:59:36 -05:00
implemented review feedback
renamed option from 'redis-set-ttl' to 'redis-expire-records'
This commit is contained in:
parent
b130a8b459
commit
c25eb2c4c8
9 changed files with 1728 additions and 1718 deletions
|
|
@ -94,6 +94,7 @@ redis_init(struct module_env* env, struct cachedb_env* cachedb_env)
|
|||
int i;
|
||||
struct redis_moddata* moddata = NULL;
|
||||
redisReply* rep;
|
||||
int redis_reply_type = 0;
|
||||
|
||||
verbose(VERB_ALGO, "redis_init");
|
||||
|
||||
|
|
@ -118,18 +119,20 @@ redis_init(struct module_env* env, struct cachedb_env* cachedb_env)
|
|||
for(i = 0; i < moddata->numctxs; i++)
|
||||
moddata->ctxs[i] = redis_connect(moddata);
|
||||
cachedb_env->backend_data = moddata;
|
||||
|
||||
if (env->cfg->redis_set_ttl) {
|
||||
if (env->cfg->redis_expire_records) {
|
||||
/** check if setex command is supported */
|
||||
rep = redis_command(env, cachedb_env, "SETEX __UNBOUND_REDIS_CHECK__ 1 none", NULL, 0);
|
||||
if(!rep)
|
||||
if(!rep) {
|
||||
/** init failed, no response from redis server*/
|
||||
log_err("redis_init: failed to init redis, could not connect to server");
|
||||
log_err("redis_init: failed to init redis, the redis-expire-records option requires the SETEX command (redis >= 2.0.0)");
|
||||
return 0;
|
||||
switch (rep->type) {
|
||||
}
|
||||
redis_reply_type = rep->type;
|
||||
freeReplyObject(rep);
|
||||
switch (redis_reply_type) {
|
||||
case REDIS_REPLY_ERROR:
|
||||
/** init failed, setex command not supported */
|
||||
log_err("redis_init: failed to init redis, setex command not supported?");
|
||||
log_err("redis_init: failed to init redis, the redis-expire-records option requires the SETEX command (redis >= 2.0.0)");
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -275,15 +278,14 @@ redis_store(struct module_env* env, struct cachedb_env* cachedb_env,
|
|||
{
|
||||
redisReply* rep;
|
||||
int n;
|
||||
int set_ttl = (int)(env->cfg->redis_set_ttl && (!env->cfg->serve_expired || env->cfg->serve_expired_ttl > 0));
|
||||
char cmdbuf[4+(CACHEDB_HASHSIZE/8)*2+3+((2+11)*set_ttl)+1]; /* "SETEX " + key + " " + ttl + " %b" */
|
||||
int set_ttl = (int)(env->cfg->redis_expire_records && (!env->cfg->serve_expired || env->cfg->serve_expired_ttl > 0));
|
||||
char cmdbuf[6+(CACHEDB_HASHSIZE/8)*2+11+3+1]; /* "SETEX " + key + " " + ttl + " %b" or "SET " + key + " %b"*/
|
||||
|
||||
if (!set_ttl) {
|
||||
verbose(VERB_ALGO, "redis_store %s (%d bytes)", key, (int)data_len);
|
||||
/* build command to set to a binary safe string */
|
||||
n = snprintf(cmdbuf, sizeof(cmdbuf), "SET %s %%b", key);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* add expired ttl time to redis ttl to avoid premature eviction of key */
|
||||
ttl += env->cfg->serve_expired_ttl;
|
||||
verbose(VERB_ALGO, "redis_store %s (%d bytes) with ttl %u", key, (int)data_len, (uint32_t)ttl);
|
||||
|
|
|
|||
|
|
@ -2128,11 +2128,12 @@ if the Redis server does not have the requested data, and will try to
|
|||
re-establish a new connection later.
|
||||
This option defaults to 100 milliseconds.
|
||||
.TP
|
||||
.B redis-set-ttl: \fI<yes or no>
|
||||
If redis ttl is enabled. If yes, unbound sets ttl for redis records so
|
||||
that redis can evict keys that have expired automatically. If unbound
|
||||
is configured to serve expired entries and there is no expired ttl set,
|
||||
this option is internally reverted to "no".
|
||||
.B redis-expire-records: \fI<yes or no>
|
||||
If redis record expiration is enabled. If yes, unbound sets ttl for redis
|
||||
records so that redis can evict keys that have expired automatically. If
|
||||
unbound is configured to serve expired entries and there is no expired ttl
|
||||
set, this option is internally reverted to "no". Redis SETEX support required
|
||||
(redis >= 2.0.0).
|
||||
This option defaults to no.
|
||||
.SS DNSTAP Logging Options
|
||||
DNSTAP support, when compiled in, is enabled in the \fBdnstap:\fR section.
|
||||
|
|
|
|||
|
|
@ -337,7 +337,7 @@ config_create(void)
|
|||
if(!(cfg->redis_server_host = strdup("127.0.0.1"))) goto error_exit;
|
||||
cfg->redis_timeout = 100;
|
||||
cfg->redis_server_port = 6379;
|
||||
cfg->redis_set_ttl = 0;
|
||||
cfg->redis_expire_records = 0;
|
||||
#endif /* USE_REDIS */
|
||||
#endif /* USE_CACHEDB */
|
||||
#ifdef USE_IPSET
|
||||
|
|
@ -1136,7 +1136,7 @@ config_get_option(struct config_file* cfg, const char* opt,
|
|||
else O_STR(opt, "redis-server-host", redis_server_host)
|
||||
else O_DEC(opt, "redis-server-port", redis_server_port)
|
||||
else O_DEC(opt, "redis-timeout", redis_timeout)
|
||||
else O_YNO(opt, "redis-set-ttl", redis_set_ttl)
|
||||
else O_YNO(opt, "redis-expire-records", redis_expire_records)
|
||||
#endif /* USE_REDIS */
|
||||
#endif /* USE_CACHEDB */
|
||||
#ifdef USE_IPSET
|
||||
|
|
|
|||
|
|
@ -599,7 +599,7 @@ struct config_file {
|
|||
/** timeout (in ms) for communication with the redis server */
|
||||
int redis_timeout;
|
||||
/** set redis ttl value based on dns response ttl */
|
||||
int redis_set_ttl;
|
||||
int redis_expire_records;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
|||
3379
util/configlexer.c
3379
util/configlexer.c
File diff suppressed because it is too large
Load diff
|
|
@ -500,7 +500,7 @@ secret-seed{COLON} { YDVAR(1, VAR_CACHEDB_SECRETSEED) }
|
|||
redis-server-host{COLON} { YDVAR(1, VAR_CACHEDB_REDISHOST) }
|
||||
redis-server-port{COLON} { YDVAR(1, VAR_CACHEDB_REDISPORT) }
|
||||
redis-timeout{COLON} { YDVAR(1, VAR_CACHEDB_REDISTIMEOUT) }
|
||||
redis-set-ttl{COLON} { YDVAR(1, VAR_CACHEDB_REDISSETTTL) }
|
||||
redis-expire-records{COLON} { YDVAR(1, VAR_CACHEDB_REDISEXPIRERECORDS) }
|
||||
ipset{COLON} { YDVAR(0, VAR_IPSET) }
|
||||
name-v4{COLON} { YDVAR(1, VAR_IPSET_NAME_V4) }
|
||||
name-v6{COLON} { YDVAR(1, VAR_IPSET_NAME_V6) }
|
||||
|
|
|
|||
|
|
@ -381,7 +381,7 @@ extern int yydebug;
|
|||
VAR_CACHEDB_REDISHOST = 503,
|
||||
VAR_CACHEDB_REDISPORT = 504,
|
||||
VAR_CACHEDB_REDISTIMEOUT = 505,
|
||||
VAR_CACHEDB_REDISSETTTL = 506,
|
||||
VAR_CACHEDB_REDISEXPIRERECORDS = 506,
|
||||
VAR_UDP_UPSTREAM_WITHOUT_DOWNSTREAM = 507,
|
||||
VAR_FOR_UPSTREAM = 508,
|
||||
VAR_AUTH_ZONE = 509,
|
||||
|
|
@ -668,7 +668,7 @@ extern int yydebug;
|
|||
#define VAR_CACHEDB_REDISHOST 503
|
||||
#define VAR_CACHEDB_REDISPORT 504
|
||||
#define VAR_CACHEDB_REDISTIMEOUT 505
|
||||
#define VAR_CACHEDB_REDISSETTTL 506
|
||||
#define VAR_CACHEDB_REDISEXPIRERECORDS 506
|
||||
#define VAR_UDP_UPSTREAM_WITHOUT_DOWNSTREAM 507
|
||||
#define VAR_FOR_UPSTREAM 508
|
||||
#define VAR_AUTH_ZONE 509
|
||||
|
|
@ -1207,7 +1207,7 @@ static const char *const yytname[] =
|
|||
"VAR_IPSECMOD_MAX_TTL", "VAR_IPSECMOD_WHITELIST", "VAR_IPSECMOD_STRICT",
|
||||
"VAR_CACHEDB", "VAR_CACHEDB_BACKEND", "VAR_CACHEDB_SECRETSEED",
|
||||
"VAR_CACHEDB_REDISHOST", "VAR_CACHEDB_REDISPORT",
|
||||
"VAR_CACHEDB_REDISTIMEOUT", "VAR_CACHEDB_REDISSETTTL",
|
||||
"VAR_CACHEDB_REDISTIMEOUT", "VAR_CACHEDB_REDISEXPIRERECORDS",
|
||||
"VAR_UDP_UPSTREAM_WITHOUT_DOWNSTREAM", "VAR_FOR_UPSTREAM",
|
||||
"VAR_AUTH_ZONE", "VAR_ZONEFILE", "VAR_MASTER", "VAR_URL",
|
||||
"VAR_FOR_DOWNSTREAM", "VAR_FALLBACK_ENABLED", "VAR_TLS_ADDITIONAL_PORT",
|
||||
|
|
@ -1342,7 +1342,7 @@ static const char *const yytname[] =
|
|||
"dnsc_dnscrypt_nonce_cache_size", "dnsc_dnscrypt_nonce_cache_slabs",
|
||||
"cachedbstart", "contents_cachedb", "content_cachedb",
|
||||
"cachedb_backend_name", "cachedb_secret_seed", "redis_server_host",
|
||||
"redis_server_port", "redis_timeout", "redis_set_ttl",
|
||||
"redis_server_port", "redis_timeout", "redis_expire_records",
|
||||
"server_tcp_connection_limit", "ipsetstart", "contents_ipset",
|
||||
"content_ipset", "ipset_name_v4", "ipset_name_v6", YY_NULLPTR
|
||||
};
|
||||
|
|
@ -6331,10 +6331,10 @@ yyreduce:
|
|||
#line 3147 "./util/configparser.y" /* yacc.c:1652 */
|
||||
{
|
||||
#if defined(USE_CACHEDB) && defined(USE_REDIS)
|
||||
OUTYY(("P(redis_set_ttl:%s)\n", (yyvsp[0].str)));
|
||||
OUTYY(("P(redis_expire_records:%s)\n", (yyvsp[0].str)));
|
||||
if(strcmp((yyvsp[0].str), "yes") != 0 && strcmp((yyvsp[0].str), "no") != 0)
|
||||
yyerror("expected yes or no.");
|
||||
else cfg_parser->cfg->redis_set_ttl = (strcmp((yyvsp[0].str), "yes")==0);
|
||||
else cfg_parser->cfg->redis_expire_records = (strcmp((yyvsp[0].str), "yes")==0);
|
||||
#else
|
||||
OUTYY(("P(Compiled without cachedb or redis, ignoring)\n"));
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ extern int yydebug;
|
|||
VAR_CACHEDB_REDISHOST = 503,
|
||||
VAR_CACHEDB_REDISPORT = 504,
|
||||
VAR_CACHEDB_REDISTIMEOUT = 505,
|
||||
VAR_CACHEDB_REDISSETTTL = 506,
|
||||
VAR_CACHEDB_REDISEXPIRERECORDS = 506,
|
||||
VAR_UDP_UPSTREAM_WITHOUT_DOWNSTREAM = 507,
|
||||
VAR_FOR_UPSTREAM = 508,
|
||||
VAR_AUTH_ZONE = 509,
|
||||
|
|
@ -584,7 +584,7 @@ extern int yydebug;
|
|||
#define VAR_CACHEDB_REDISHOST 503
|
||||
#define VAR_CACHEDB_REDISPORT 504
|
||||
#define VAR_CACHEDB_REDISTIMEOUT 505
|
||||
#define VAR_CACHEDB_REDISSETTTL 506
|
||||
#define VAR_CACHEDB_REDISEXPIRERECORDS 506
|
||||
#define VAR_UDP_UPSTREAM_WITHOUT_DOWNSTREAM 507
|
||||
#define VAR_FOR_UPSTREAM 508
|
||||
#define VAR_AUTH_ZONE 509
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ extern struct config_parser_state* cfg_parser;
|
|||
%token VAR_IPSECMOD_ENABLED VAR_IPSECMOD_HOOK VAR_IPSECMOD_IGNORE_BOGUS
|
||||
%token VAR_IPSECMOD_MAX_TTL VAR_IPSECMOD_WHITELIST VAR_IPSECMOD_STRICT
|
||||
%token VAR_CACHEDB VAR_CACHEDB_BACKEND VAR_CACHEDB_SECRETSEED
|
||||
%token VAR_CACHEDB_REDISHOST VAR_CACHEDB_REDISPORT VAR_CACHEDB_REDISTIMEOUT VAR_CACHEDB_REDISSETTTL
|
||||
%token VAR_CACHEDB_REDISHOST VAR_CACHEDB_REDISPORT VAR_CACHEDB_REDISTIMEOUT VAR_CACHEDB_REDISEXPIRERECORDS
|
||||
%token VAR_UDP_UPSTREAM_WITHOUT_DOWNSTREAM VAR_FOR_UPSTREAM
|
||||
%token VAR_AUTH_ZONE VAR_ZONEFILE VAR_MASTER VAR_URL VAR_FOR_DOWNSTREAM
|
||||
%token VAR_FALLBACK_ENABLED VAR_TLS_ADDITIONAL_PORT VAR_LOW_RTT VAR_LOW_RTT_PERMIL
|
||||
|
|
@ -3077,7 +3077,7 @@ cachedbstart: VAR_CACHEDB
|
|||
contents_cachedb: contents_cachedb content_cachedb
|
||||
| ;
|
||||
content_cachedb: cachedb_backend_name | cachedb_secret_seed |
|
||||
redis_server_host | redis_server_port | redis_timeout | redis_set_ttl
|
||||
redis_server_host | redis_server_port | redis_timeout | redis_expire_records
|
||||
;
|
||||
cachedb_backend_name: VAR_CACHEDB_BACKEND STRING_ARG
|
||||
{
|
||||
|
|
@ -3143,13 +3143,13 @@ redis_timeout: VAR_CACHEDB_REDISTIMEOUT STRING_ARG
|
|||
free($2);
|
||||
}
|
||||
;
|
||||
redis_set_ttl: VAR_CACHEDB_REDISSETTTL STRING_ARG
|
||||
redis_expire_records: VAR_CACHEDB_REDISEXPIRERECORDS STRING_ARG
|
||||
{
|
||||
#if defined(USE_CACHEDB) && defined(USE_REDIS)
|
||||
OUTYY(("P(redis_set_ttl:%s)\n", $2));
|
||||
OUTYY(("P(redis_expire_records:%s)\n", $2));
|
||||
if(strcmp($2, "yes") != 0 && strcmp($2, "no") != 0)
|
||||
yyerror("expected yes or no.");
|
||||
else cfg_parser->cfg->redis_set_ttl = (strcmp($2, "yes")==0);
|
||||
else cfg_parser->cfg->redis_expire_records = (strcmp($2, "yes")==0);
|
||||
#else
|
||||
OUTYY(("P(Compiled without cachedb or redis, ignoring)\n"));
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue