- Changes for PR #206 (formatting and remade lex and yacc output).

This commit is contained in:
George Thessalonikefs 2020-04-01 17:14:58 +02:00
parent 20aa782ce5
commit 557a309f9d
7 changed files with 688 additions and 673 deletions

View file

@ -93,8 +93,6 @@ 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");
@ -120,11 +118,16 @@ redis_init(struct module_env* env, struct cachedb_env* cachedb_env)
moddata->ctxs[i] = redis_connect(moddata);
cachedb_env->backend_data = moddata;
if(env->cfg->redis_expire_records) {
redisReply* rep = NULL;
int redis_reply_type = 0;
/** check if setex command is supported */
rep = redis_command(env, cachedb_env, "SETEX __UNBOUND_REDIS_CHECK__ 1 none", NULL, 0);
rep = redis_command(env, cachedb_env,
"SETEX __UNBOUND_REDIS_CHECK__ 1 none", NULL, 0);
if(!rep) {
/** init failed, no response from redis server*/
log_err("redis_init: failed to init redis, the redis-expire-records option requires the SETEX command (redis >= 2.0.0)");
log_err("redis_init: failed to init redis, the "
"redis-expire-records option requires the SETEX command "
"(redis >= 2.0.0)");
return 0;
}
redis_reply_type = rep->type;
@ -134,7 +137,9 @@ redis_init(struct module_env* env, struct cachedb_env* cachedb_env)
break;
default:
/** init failed, 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)");
log_err("redis_init: failed to init redis, the "
"redis-expire-records option requires the SETEX command "
"(redis >= 2.0.0)");
return 0;
}
}
@ -278,8 +283,13 @@ redis_store(struct module_env* env, struct cachedb_env* cachedb_env,
{
redisReply* rep;
int n;
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"*/
int set_ttl = (env->cfg->redis_expire_records &&
(!env->cfg->serve_expired || env->cfg->serve_expired_ttl > 0));
/* Supported commands:
* - "SET " + key + " %b"
* - "SETEX " + key + " " + ttl + " %b"
*/
char cmdbuf[6+(CACHEDB_HASHSIZE/8)*2+11+3+1];
if (!set_ttl) {
verbose(VERB_ALGO, "redis_store %s (%d bytes)", key, (int)data_len);
@ -288,9 +298,11 @@ redis_store(struct module_env* env, struct cachedb_env* cachedb_env,
} 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);
verbose(VERB_ALGO, "redis_store %s (%d bytes) with ttl %u",
key, (int)data_len, (uint32_t)ttl);
/* build command to set to a binary safe string */
n = snprintf(cmdbuf, sizeof(cmdbuf), "SETEX %s %u %%b", key, (uint32_t)ttl);
n = snprintf(cmdbuf, sizeof(cmdbuf), "SETEX %s %u %%b", key,
(uint32_t)ttl);
}

View file

@ -2132,11 +2132,11 @@ re-establish a new connection later.
This option defaults to 100 milliseconds.
.TP
.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).
If Redis record expiration is enabled. If yes, unbound sets timeout for Redis
records so that Redis can evict keys that have expired automatically. If
unbound is configured with \fBserve-expired\fR and \fBserve-expired-ttl\fR is 0,
this option is internally reverted to "no". Redis SETEX support is required
for this option (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.

View file

@ -598,7 +598,7 @@ struct config_file {
int redis_server_port;
/** timeout (in ms) for communication with the redis server */
int redis_timeout;
/** set redis ttl value based on dns response ttl */
/** set timeout on redis records based on DNS response ttl */
int redis_expire_records;
#endif
#endif

View file

@ -1,7 +1,7 @@
#include "config.h"
#include "util/configyyrename.h"
#line 3 "<stdout>"
#line 2 "<stdout>"
#define YY_INT_ALIGNED short int
@ -2956,7 +2956,7 @@ static void config_end_include(void)
}
#endif
#line 2958 "<stdout>"
#line 2957 "<stdout>"
#define YY_NO_INPUT 1
#line 184 "./util/configlexer.lex"
#ifndef YY_NO_UNPUT
@ -2965,9 +2965,9 @@ static void config_end_include(void)
#ifndef YY_NO_INPUT
#define YY_NO_INPUT 1
#endif
#line 2967 "<stdout>"
#line 2966 "<stdout>"
#line 2969 "<stdout>"
#line 2968 "<stdout>"
#define INITIAL 0
#define quotedstring 1
@ -3189,7 +3189,7 @@ YY_DECL
{
#line 204 "./util/configlexer.lex"
#line 3191 "<stdout>"
#line 3190 "<stdout>"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
@ -4910,7 +4910,7 @@ YY_RULE_SETUP
#line 604 "./util/configlexer.lex"
ECHO;
YY_BREAK
#line 4912 "<stdout>"
#line 4911 "<stdout>"
case YY_END_OF_BUFFER:
{

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
/* A Bison parser, made by GNU Bison 3.3.2. */
/* A Bison parser, made by GNU Bison 3.4.1. */
/* Bison interface for Yacc-like parsers in C
@ -623,16 +623,15 @@ extern int yydebug;
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
{
#line 66 "./util/configparser.y" /* yacc.c:1921 */
#line 66 "./util/configparser.y"
char* str;
#line 634 "util/configparser.h" /* yacc.c:1921 */
};
#line 633 "util/configparser.h"
};
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1

View file

@ -161,7 +161,8 @@ 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_REDISEXPIRERECORDS
%token VAR_CACHEDB_REDISHOST VAR_CACHEDB_REDISPORT VAR_CACHEDB_REDISTIMEOUT
%token 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 +3078,8 @@ 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_expire_records
redis_server_host | redis_server_port | redis_timeout |
redis_expire_records
;
cachedb_backend_name: VAR_CACHEDB_BACKEND STRING_ARG
{