mirror of
https://github.com/NLnetLabs/unbound.git
synced 2026-09-30 13:44:58 +02:00
Merge pull request #265 from NLnetLabs/include-toplevel
Introduce include-toplevel configuration option; closes #161.
This commit is contained in:
+5
-1
@@ -5,9 +5,13 @@
|
||||
#
|
||||
# this is a comment.
|
||||
|
||||
#Use this to include other text into the file.
|
||||
# Use this anywhere in the file to include other text into this file.
|
||||
#include: "otherfile.conf"
|
||||
|
||||
# Use this anywhere in the file to include other text, that explicitly starts a
|
||||
# clause, into this file. Text after this directive needs to start a clause.
|
||||
#include-toplevel: "otherfile.conf"
|
||||
|
||||
# The server clause sets the main parameters.
|
||||
server:
|
||||
# whitespace is not necessary, but looks cleaner.
|
||||
|
||||
@@ -77,6 +77,12 @@ for the included files works, relative pathnames for the included names work
|
||||
if the directory where the daemon is started equals its chroot/working
|
||||
directory or is specified before the include statement with directory: dir.
|
||||
Wildcards can be used to include multiple files, see \fIglob\fR(7).
|
||||
.P
|
||||
For a more structural include option, the
|
||||
.B include\-toplevel:
|
||||
directive can be used. This closes whatever clause is currently active (if any)
|
||||
and forces the use of clauses in the included files and right after this
|
||||
directive.
|
||||
.SS "Server Options"
|
||||
These options are part of the
|
||||
.B server:
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
include-toplevel: include.withoutclauses.*
|
||||
server:
|
||||
identity: "top 1"
|
||||
@@ -0,0 +1,5 @@
|
||||
include-toplevel: include.withclauses.*
|
||||
server:
|
||||
identity: "top 1"
|
||||
include: include.withoutclauses.*
|
||||
include-toplevel: include.withoutclauses.*
|
||||
@@ -0,0 +1,6 @@
|
||||
include-toplevel: include.withclauses.*
|
||||
server:
|
||||
identity: "top 1"
|
||||
include: include.withoutclauses.*
|
||||
include-toplevel: include.withclauses.*
|
||||
include: include.withoutclauses.*
|
||||
@@ -0,0 +1,7 @@
|
||||
include-toplevel: include.withclauses.*
|
||||
server:
|
||||
identity: "top 1"
|
||||
include: include.withoutclauses.*
|
||||
include-toplevel: include.withclauses.*
|
||||
include: include.withclauses.*
|
||||
include-toplevel: include.withoutclauses.*
|
||||
@@ -0,0 +1,8 @@
|
||||
include-toplevel: include.withclauses.*
|
||||
server:
|
||||
identity: "top 1"
|
||||
include: include.withoutclauses.*
|
||||
include-toplevel: include.withsomeclauses.*
|
||||
include: include.withclauses.*
|
||||
include-toplevel: include.withclauses.*
|
||||
server: identity: "top 2"
|
||||
@@ -0,0 +1,10 @@
|
||||
include-toplevel: include.withclauses.*
|
||||
include-toplevel: include.withclauses.*
|
||||
server:
|
||||
identity: "top 1"
|
||||
include: include.withoutclauses.*
|
||||
include-toplevel: include.withclauses.*
|
||||
include: include.withclauses.*
|
||||
include-toplevel: include.withclauses.*
|
||||
server: identity: "top 2"
|
||||
include-toplevel: include.includetop.withoutclauses.*
|
||||
@@ -0,0 +1,11 @@
|
||||
include-toplevel: include.withclauses.*
|
||||
include-toplevel: include.withclauses.*
|
||||
server:
|
||||
identity: "top 1"
|
||||
include: include.withoutclauses.*
|
||||
include-toplevel: include.withclauses.*
|
||||
include: include.withclauses.*
|
||||
include-toplevel: include.withclauses.*
|
||||
server: identity: "top 2"
|
||||
include-toplevel: include.includetop.withclauses.*
|
||||
include-toplevel: include.include.withoutclauses.*
|
||||
@@ -0,0 +1,12 @@
|
||||
include-toplevel: include.withclauses.*
|
||||
include-toplevel: include.withclauses.*
|
||||
server:
|
||||
identity: "top 1"
|
||||
include: include.withoutclauses.*
|
||||
include-toplevel: include.withclauses.*
|
||||
include: include.withclauses.*
|
||||
include-toplevel: include.withclauses.*
|
||||
server: identity: "top 2"
|
||||
include-toplevel: include.includetop.withclauses.*
|
||||
include-toplevel: include.include.withclauses.*
|
||||
include-toplevel: include.include.withclauses.*
|
||||
@@ -0,0 +1 @@
|
||||
include: include.withclauses.*
|
||||
@@ -0,0 +1 @@
|
||||
include: include.withclauses.*
|
||||
@@ -0,0 +1 @@
|
||||
include: include.withclauses.*
|
||||
@@ -0,0 +1 @@
|
||||
include: include.withoutclauses.*
|
||||
@@ -0,0 +1 @@
|
||||
include: include.withoutclauses.*
|
||||
@@ -0,0 +1 @@
|
||||
include: include.withoutclauses.*
|
||||
@@ -0,0 +1 @@
|
||||
include-toplevel: include.withclauses.*
|
||||
@@ -0,0 +1 @@
|
||||
include-toplevel: include.withclauses.*
|
||||
@@ -0,0 +1 @@
|
||||
include-toplevel: include.withclauses.*
|
||||
@@ -0,0 +1 @@
|
||||
include-toplevel: include.withoutclauses.*
|
||||
@@ -0,0 +1 @@
|
||||
include-toplevel: include.withoutclauses.*
|
||||
@@ -0,0 +1 @@
|
||||
include-toplevel: include.withoutclauses.*
|
||||
@@ -0,0 +1 @@
|
||||
server: identity: "withclauses1"
|
||||
@@ -0,0 +1 @@
|
||||
server: identity: "withclauses2"
|
||||
@@ -0,0 +1 @@
|
||||
server: identity: "withclauses3"
|
||||
@@ -0,0 +1 @@
|
||||
identity: "withoutclauses1"
|
||||
@@ -0,0 +1 @@
|
||||
identity: "withoutclauses2"
|
||||
@@ -0,0 +1 @@
|
||||
identity: "withoutclauses3"
|
||||
@@ -0,0 +1 @@
|
||||
server: identity: "withsomeclauses1"
|
||||
@@ -0,0 +1 @@
|
||||
identity: "withsomeclauses2"
|
||||
@@ -0,0 +1 @@
|
||||
identity: "withsomeclauses3"
|
||||
+2613
-2495
File diff suppressed because it is too large
Load Diff
+52
-9
@@ -45,11 +45,13 @@ struct inc_state {
|
||||
int line;
|
||||
YY_BUFFER_STATE buffer;
|
||||
struct inc_state* next;
|
||||
int inc_toplevel;
|
||||
};
|
||||
static struct inc_state* config_include_stack = NULL;
|
||||
static int inc_depth = 0;
|
||||
static int inc_prev = 0;
|
||||
static int num_args = 0;
|
||||
static int inc_toplevel = 0;
|
||||
|
||||
void init_cfg_parse(void)
|
||||
{
|
||||
@@ -57,14 +59,15 @@ void init_cfg_parse(void)
|
||||
inc_depth = 0;
|
||||
inc_prev = 0;
|
||||
num_args = 0;
|
||||
inc_toplevel = 0;
|
||||
}
|
||||
|
||||
static void config_start_include(const char* filename)
|
||||
static void config_start_include(const char* filename, int toplevel)
|
||||
{
|
||||
FILE *input;
|
||||
struct inc_state* s;
|
||||
char* nm;
|
||||
if(inc_depth++ > 100000) {
|
||||
if(inc_depth+1 > 100000) {
|
||||
ub_c_error_msg("too many include files");
|
||||
return;
|
||||
}
|
||||
@@ -96,17 +99,20 @@ static void config_start_include(const char* filename)
|
||||
return;
|
||||
}
|
||||
LEXOUT(("switch_to_include_file(%s)\n", filename));
|
||||
inc_depth++;
|
||||
s->filename = cfg_parser->filename;
|
||||
s->line = cfg_parser->line;
|
||||
s->buffer = YY_CURRENT_BUFFER;
|
||||
s->inc_toplevel = inc_toplevel;
|
||||
s->next = config_include_stack;
|
||||
config_include_stack = s;
|
||||
cfg_parser->filename = nm;
|
||||
cfg_parser->line = 1;
|
||||
inc_toplevel = toplevel;
|
||||
yy_switch_to_buffer(yy_create_buffer(input, YY_BUF_SIZE));
|
||||
}
|
||||
|
||||
static void config_start_include_glob(const char* filename)
|
||||
static void config_start_include_glob(const char* filename, int toplevel)
|
||||
{
|
||||
|
||||
/* check for wildcards */
|
||||
@@ -139,19 +145,19 @@ static void config_start_include_glob(const char* filename)
|
||||
globfree(&g);
|
||||
if(r == GLOB_NOMATCH)
|
||||
return; /* no matches for pattern */
|
||||
config_start_include(filename); /* let original deal with it */
|
||||
config_start_include(filename, toplevel); /* let original deal with it */
|
||||
return;
|
||||
}
|
||||
/* process files found, if any */
|
||||
for(i=(int)g.gl_pathc-1; i>=0; i--) {
|
||||
config_start_include(g.gl_pathv[i]);
|
||||
config_start_include(g.gl_pathv[i], toplevel);
|
||||
}
|
||||
globfree(&g);
|
||||
return;
|
||||
}
|
||||
#endif /* HAVE_GLOB */
|
||||
|
||||
config_start_include(filename);
|
||||
config_start_include(filename, toplevel);
|
||||
}
|
||||
|
||||
static void config_end_include(void)
|
||||
@@ -165,6 +171,7 @@ static void config_end_include(void)
|
||||
yy_delete_buffer(YY_CURRENT_BUFFER);
|
||||
yy_switch_to_buffer(s->buffer);
|
||||
config_include_stack = s->next;
|
||||
inc_toplevel = s->inc_toplevel;
|
||||
free(s);
|
||||
}
|
||||
|
||||
@@ -199,7 +206,7 @@ COLON \:
|
||||
DQANY [^\"\n\r\\]|\\.
|
||||
SQANY [^\'\n\r\\]|\\.
|
||||
|
||||
%x quotedstring singlequotedstr include include_quoted val
|
||||
%x quotedstring singlequotedstr include include_quoted val include_toplevel include_toplevel_quoted
|
||||
|
||||
%%
|
||||
<INITIAL,val>{SPACE}* {
|
||||
@@ -566,7 +573,7 @@ tcp-connection-limit{COLON} { YDVAR(2, VAR_TCP_CONNECTION_LIMIT) }
|
||||
<include>\" { LEXOUT(("IQS ")); BEGIN(include_quoted); }
|
||||
<include>{UNQUOTEDLETTER}* {
|
||||
LEXOUT(("Iunquotedstr(%s) ", yytext));
|
||||
config_start_include_glob(yytext);
|
||||
config_start_include_glob(yytext, 0);
|
||||
BEGIN(inc_prev);
|
||||
}
|
||||
<include_quoted><<EOF>> {
|
||||
@@ -579,7 +586,7 @@ tcp-connection-limit{COLON} { YDVAR(2, VAR_TCP_CONNECTION_LIMIT) }
|
||||
<include_quoted>\" {
|
||||
LEXOUT(("IQE "));
|
||||
yytext[yyleng - 1] = '\0';
|
||||
config_start_include_glob(yytext);
|
||||
config_start_include_glob(yytext, 0);
|
||||
BEGIN(inc_prev);
|
||||
}
|
||||
<INITIAL,val><<EOF>> {
|
||||
@@ -588,11 +595,47 @@ tcp-connection-limit{COLON} { YDVAR(2, VAR_TCP_CONNECTION_LIMIT) }
|
||||
if (!config_include_stack) {
|
||||
yyterminate();
|
||||
} else {
|
||||
int prev_toplevel = inc_toplevel;
|
||||
fclose(yyin);
|
||||
config_end_include();
|
||||
if(prev_toplevel) return (VAR_FORCE_TOPLEVEL);
|
||||
}
|
||||
}
|
||||
|
||||
/* include-toplevel: directive */
|
||||
<INITIAL,val>include-toplevel{COLON} {
|
||||
LEXOUT(("v(%s) ", yytext)); inc_prev = YYSTATE; BEGIN(include_toplevel);
|
||||
}
|
||||
<include_toplevel><<EOF>> {
|
||||
yyerror("EOF inside include_toplevel directive");
|
||||
BEGIN(inc_prev);
|
||||
}
|
||||
<include_toplevel>{SPACE}* { LEXOUT(("ITSP ")); /* ignore */ }
|
||||
<include_toplevel>{NEWLINE} { LEXOUT(("NL\n")); cfg_parser->line++; }
|
||||
<include_toplevel>\" { LEXOUT(("ITQS ")); BEGIN(include_toplevel_quoted); }
|
||||
<include_toplevel>{UNQUOTEDLETTER}* {
|
||||
LEXOUT(("ITunquotedstr(%s) ", yytext));
|
||||
config_start_include_glob(yytext, 1);
|
||||
BEGIN(inc_prev);
|
||||
return (VAR_FORCE_TOPLEVEL);
|
||||
}
|
||||
<include_toplevel_quoted><<EOF>> {
|
||||
yyerror("EOF inside quoted string");
|
||||
BEGIN(inc_prev);
|
||||
}
|
||||
<include_toplevel_quoted>{DQANY}* { LEXOUT(("ITSTR(%s) ", yytext)); yymore(); }
|
||||
<include_toplevel_quoted>{NEWLINE} {
|
||||
yyerror("newline before \" in include name");
|
||||
cfg_parser->line++; BEGIN(inc_prev);
|
||||
}
|
||||
<include_toplevel_quoted>\" {
|
||||
LEXOUT(("ITQE "));
|
||||
yytext[yyleng - 1] = '\0';
|
||||
config_start_include_glob(yytext, 1);
|
||||
BEGIN(inc_prev);
|
||||
return (VAR_FORCE_TOPLEVEL);
|
||||
}
|
||||
|
||||
<val>{UNQUOTEDLETTER}* { LEXOUT(("unquotedstr(%s) ", yytext));
|
||||
if(--num_args == 0) { BEGIN(INITIAL); }
|
||||
yylval.str = strdup(yytext); return STRING_ARG; }
|
||||
|
||||
+2002
-1986
File diff suppressed because it is too large
Load Diff
+565
-563
File diff suppressed because it is too large
Load Diff
+10
-4
@@ -69,6 +69,7 @@ extern struct config_parser_state* cfg_parser;
|
||||
|
||||
%token SPACE LETTER NEWLINE COMMENT COLON ANY ZONESTR
|
||||
%token <str> STRING_ARG
|
||||
%token VAR_FORCE_TOPLEVEL
|
||||
%token VAR_SERVER VAR_VERBOSITY VAR_NUM_THREADS VAR_PORT
|
||||
%token VAR_OUTGOING_RANGE VAR_INTERFACE VAR_PREFER_IP4
|
||||
%token VAR_DO_IP4 VAR_DO_IP6 VAR_PREFER_IP6 VAR_DO_UDP VAR_DO_TCP
|
||||
@@ -183,16 +184,21 @@ toplevelvar: serverstart contents_server | stubstart contents_stub |
|
||||
rcstart contents_rc | dtstart contents_dt | viewstart contents_view |
|
||||
dnscstart contents_dnsc | cachedbstart contents_cachedb |
|
||||
ipsetstart contents_ipset | authstart contents_auth |
|
||||
rpzstart contents_rpz | dynlibstart contents_dl
|
||||
rpzstart contents_rpz | dynlibstart contents_dl |
|
||||
force_toplevel
|
||||
;
|
||||
force_toplevel: VAR_FORCE_TOPLEVEL
|
||||
{
|
||||
OUTYY(("\nP(force-toplevel)\n"));
|
||||
}
|
||||
;
|
||||
|
||||
/* server: declaration */
|
||||
serverstart: VAR_SERVER
|
||||
{
|
||||
OUTYY(("\nP(server:)\n"));
|
||||
OUTYY(("\nP(server:)\n"));
|
||||
}
|
||||
;
|
||||
contents_server: contents_server content_server
|
||||
contents_server: contents_server content_server
|
||||
| ;
|
||||
content_server: server_num_threads | server_verbosity | server_port |
|
||||
server_outgoing_range | server_do_ip4 |
|
||||
|
||||
Reference in New Issue
Block a user