0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-15 07:38:43 +00:00
bird/sysdep/unix/config.Y
Maria Jan Matejka f93315c417 Config: Make the parser and lexer reentrant.
This is part of the multithreading journey. The parser and lexer were
using loads of global variables and all of these are now packed into
struct cf_context and others.

Note that the config API has changed:

* cfg_alloc[zu]?(size) is now cf_alloc[zu]?(ctx, size)
* cf_error(msg, ...) is now cf_error(ctx, msg, ...)
* config_parse() and cli_parse() are now called differently
* there is a brand new CF_CTX section in *.Y files which participates
  in struct cf_context construction
2018-09-14 14:44:45 +02:00

137 lines
3.4 KiB
Plaintext

/*
* BIRD -- UNIX Configuration
*
* (c) 1999--2000 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
CF_HDR
#include "sysdep/unix/unix.h"
#include <stdio.h>
CF_DECLS
CF_KEYWORDS(LOG, SYSLOG, ALL, DEBUG, TRACE, INFO, REMOTE, WARNING, ERROR, AUTH, FATAL, BUG, STDERR, SOFT)
CF_KEYWORDS(NAME, CONFIRM, UNDO, CHECK, TIMEOUT, DEBUG, LATENCY, LIMIT, WATCHDOG, WARNING)
%type <i> log_mask log_mask_list log_cat cfg_timeout
%type <g> log_file
%type <t> cfg_name
%type <tf> timeformat_which
%type <t> syslog_name
CF_GRAMMAR
conf: log_config ;
log_config: LOG log_file log_mask ';' {
struct log_config *c = cfg_allocz(sizeof(struct log_config));
c->fh = $2;
c->mask = $3;
add_tail(&ctx->new_config->logfiles, &c->n);
}
;
syslog_name:
NAME text { $$ = $2; }
| { $$ = bird_name; }
;
log_file:
text {
FILE *f = tracked_fopen(ctx->new_config->pool, $1, "a");
if (!f) cf_error(ctx, "Unable to open log file `%s': %m", $1);
$$ = f;
}
| SYSLOG syslog_name { $$ = NULL; ctx->new_config->syslog_name = $2; }
| STDERR { $$ = stderr; }
;
log_mask:
ALL { $$ = ~0; }
| '{' log_mask_list '}' { $$ = $2; }
;
log_mask_list:
log_cat { $$ = 1 << $1; }
| log_mask_list ',' log_cat { $$ = $1 | (1 << $3); }
;
log_cat:
DEBUG { $$ = L_DEBUG[0]; }
| TRACE { $$ = L_TRACE[0]; }
| INFO { $$ = L_INFO[0]; }
| REMOTE { $$ = L_REMOTE[0]; }
| WARNING { $$ = L_WARN[0]; }
| ERROR { $$ = L_ERR[0]; }
| AUTH { $$ = L_AUTH[0]; }
| FATAL { $$ = L_FATAL[0]; }
| BUG { $$ = L_BUG[0]; }
;
conf: mrtdump_base ;
mrtdump_base:
MRTDUMP PROTOCOLS mrtdump_mask ';' { ctx->new_config->proto_default_mrtdump = $3; }
| MRTDUMP text ';' {
FILE *f = tracked_fopen(ctx->new_config->pool, $2, "a");
if (!f) cf_error(ctx, "Unable to open MRTDump file '%s': %m", $2);
ctx->new_config->mrtdump_file = fileno(f);
}
;
conf: debug_unix ;
debug_unix:
DEBUG LATENCY bool { ctx->new_config->latency_debug = $3; }
| DEBUG LATENCY LIMIT expr_us { ctx->new_config->latency_limit = $4; }
| WATCHDOG WARNING expr_us { ctx->new_config->watchdog_warning = $3; }
| WATCHDOG TIMEOUT expr_us { ctx->new_config->watchdog_timeout = ($3 + 999999) TO_S; }
;
/* Unix specific commands */
CF_CLI_HELP(CONFIGURE, ..., [[Reload configuration]])
CF_CLI(CONFIGURE, cfg_name cfg_timeout, [\"<file>\"] [timeout [<sec>]], [[Reload configuration]])
{ cmd_reconfig($2, RECONFIG_HARD, $3); } ;
CF_CLI(CONFIGURE SOFT, cfg_name cfg_timeout, [\"<file>\"] [timeout [<sec>]], [[Reload configuration and ignore changes in filters]])
{ cmd_reconfig($3, RECONFIG_SOFT, $4); } ;
/* Hack to get input completion for 'timeout' */
CF_CLI_CMD(CONFIGURE TIMEOUT, [<sec>], [[Reload configuration with undo timeout]])
CF_CLI_CMD(CONFIGURE SOFT TIMEOUT, [<sec>], [[Reload configuration with undo timeout]])
CF_CLI(CONFIGURE CONFIRM,,, [[Confirm last configuration change - deactivate undo timeout]])
{ cmd_reconfig_confirm(); } ;
CF_CLI(CONFIGURE UNDO,,, [[Undo last configuration change]])
{ cmd_reconfig_undo(); } ;
CF_CLI(CONFIGURE CHECK, cfg_name, [\"<file>\"], [[Parse configuration and check its validity]])
{ cmd_check_config($3); } ;
CF_CLI(DOWN,,, [[Shut the daemon down]])
{ cmd_shutdown(); } ;
cfg_name:
/* empty */ { $$ = NULL; }
| TEXT
;
cfg_timeout:
/* empty */ { $$ = 0; }
| TIMEOUT { $$ = UNIX_DEFAULT_CONFIGURE_TIMEOUT; }
| TIMEOUT expr { $$ = $2; }
;
CF_CODE
CF_END