- 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; int i;
struct redis_moddata* moddata = NULL; struct redis_moddata* moddata = NULL;
redisReply* rep;
int redis_reply_type = 0;
verbose(VERB_ALGO, "redis_init"); verbose(VERB_ALGO, "redis_init");
@ -119,22 +117,29 @@ redis_init(struct module_env* env, struct cachedb_env* cachedb_env)
for(i = 0; i < moddata->numctxs; i++) for(i = 0; i < moddata->numctxs; i++)
moddata->ctxs[i] = redis_connect(moddata); moddata->ctxs[i] = redis_connect(moddata);
cachedb_env->backend_data = moddata; cachedb_env->backend_data = moddata;
if (env->cfg->redis_expire_records) { if(env->cfg->redis_expire_records) {
redisReply* rep = NULL;
int redis_reply_type = 0;
/** check if setex command is supported */ /** 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) { if(!rep) {
/** init failed, no response from redis server*/ /** 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; return 0;
} }
redis_reply_type = rep->type; redis_reply_type = rep->type;
freeReplyObject(rep); freeReplyObject(rep);
switch (redis_reply_type) { switch(redis_reply_type) {
case REDIS_REPLY_STATUS: case REDIS_REPLY_STATUS:
break; break;
default: default:
/** init failed, setex command not supported */ /** 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; return 0;
} }
} }
@ -244,7 +249,7 @@ redis_lookup(struct module_env* env, struct cachedb_env* cachedb_env,
rep = redis_command(env, cachedb_env, cmdbuf, NULL, 0); rep = redis_command(env, cachedb_env, cmdbuf, NULL, 0);
if(!rep) if(!rep)
return 0; return 0;
switch (rep->type) { switch(rep->type) {
case REDIS_REPLY_NIL: case REDIS_REPLY_NIL:
verbose(VERB_ALGO, "redis_lookup: no data cached"); verbose(VERB_ALGO, "redis_lookup: no data cached");
break; break;
@ -278,8 +283,13 @@ redis_store(struct module_env* env, struct cachedb_env* cachedb_env,
{ {
redisReply* rep; redisReply* rep;
int n; int n;
int set_ttl = (int)(env->cfg->redis_expire_records && (!env->cfg->serve_expired || env->cfg->serve_expired_ttl > 0)); int set_ttl = (env->cfg->redis_expire_records &&
char cmdbuf[6+(CACHEDB_HASHSIZE/8)*2+11+3+1]; /* "SETEX " + key + " " + ttl + " %b" or "SET " + key + " %b"*/ (!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) { if (!set_ttl) {
verbose(VERB_ALGO, "redis_store %s (%d bytes)", key, (int)data_len); 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 { } else {
/* add expired ttl time to redis ttl to avoid premature eviction of key */ /* add expired ttl time to redis ttl to avoid premature eviction of key */
ttl += env->cfg->serve_expired_ttl; 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 */ /* 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. This option defaults to 100 milliseconds.
.TP .TP
.B redis-expire-records: \fI<yes or no> .B redis-expire-records: \fI<yes or no>
If redis record expiration is enabled. If yes, unbound sets ttl for redis 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 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 unbound is configured with \fBserve-expired\fR and \fBserve-expired-ttl\fR is 0,
set, this option is internally reverted to "no". Redis SETEX support required this option is internally reverted to "no". Redis SETEX support is required
(redis >= 2.0.0). for this option (Redis >= 2.0.0).
This option defaults to no. This option defaults to no.
.SS DNSTAP Logging Options .SS DNSTAP Logging Options
DNSTAP support, when compiled in, is enabled in the \fBdnstap:\fR section. 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; int redis_server_port;
/** timeout (in ms) for communication with the redis server */ /** timeout (in ms) for communication with the redis server */
int redis_timeout; 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; int redis_expire_records;
#endif #endif
#endif #endif

View file

@ -1,7 +1,7 @@
#include "config.h" #include "config.h"
#include "util/configyyrename.h" #include "util/configyyrename.h"
#line 3 "<stdout>" #line 2 "<stdout>"
#define YY_INT_ALIGNED short int #define YY_INT_ALIGNED short int
@ -2956,7 +2956,7 @@ static void config_end_include(void)
} }
#endif #endif
#line 2958 "<stdout>" #line 2957 "<stdout>"
#define YY_NO_INPUT 1 #define YY_NO_INPUT 1
#line 184 "./util/configlexer.lex" #line 184 "./util/configlexer.lex"
#ifndef YY_NO_UNPUT #ifndef YY_NO_UNPUT
@ -2965,9 +2965,9 @@ static void config_end_include(void)
#ifndef YY_NO_INPUT #ifndef YY_NO_INPUT
#define YY_NO_INPUT 1 #define YY_NO_INPUT 1
#endif #endif
#line 2967 "<stdout>" #line 2966 "<stdout>"
#line 2969 "<stdout>" #line 2968 "<stdout>"
#define INITIAL 0 #define INITIAL 0
#define quotedstring 1 #define quotedstring 1
@ -3189,7 +3189,7 @@ YY_DECL
{ {
#line 204 "./util/configlexer.lex" #line 204 "./util/configlexer.lex"
#line 3191 "<stdout>" #line 3190 "<stdout>"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{ {
@ -4910,7 +4910,7 @@ YY_RULE_SETUP
#line 604 "./util/configlexer.lex" #line 604 "./util/configlexer.lex"
ECHO; ECHO;
YY_BREAK YY_BREAK
#line 4912 "<stdout>" #line 4911 "<stdout>"
case YY_END_OF_BUFFER: 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 /* Bison interface for Yacc-like parsers in C
@ -623,16 +623,15 @@ extern int yydebug;
/* Value type. */ /* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE union YYSTYPE
{ {
#line 66 "./util/configparser.y" /* yacc.c:1921 */ #line 66 "./util/configparser.y"
char* str; char* str;
#line 634 "util/configparser.h" /* yacc.c:1921 */ #line 633 "util/configparser.h"
};
};
typedef union YYSTYPE YYSTYPE; typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 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_ENABLED VAR_IPSECMOD_HOOK VAR_IPSECMOD_IGNORE_BOGUS
%token VAR_IPSECMOD_MAX_TTL VAR_IPSECMOD_WHITELIST VAR_IPSECMOD_STRICT %token VAR_IPSECMOD_MAX_TTL VAR_IPSECMOD_WHITELIST VAR_IPSECMOD_STRICT
%token VAR_CACHEDB VAR_CACHEDB_BACKEND VAR_CACHEDB_SECRETSEED %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_UDP_UPSTREAM_WITHOUT_DOWNSTREAM VAR_FOR_UPSTREAM
%token VAR_AUTH_ZONE VAR_ZONEFILE VAR_MASTER VAR_URL VAR_FOR_DOWNSTREAM %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 %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 contents_cachedb: contents_cachedb content_cachedb
| ; | ;
content_cachedb: cachedb_backend_name | cachedb_secret_seed | 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 cachedb_backend_name: VAR_CACHEDB_BACKEND STRING_ARG
{ {