mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-11-09 20:58:44 +00:00
CLI keeps its active config pointer explicitly
This commit is contained in:
parent
f5fd70c54a
commit
ea996d8403
@ -757,14 +757,14 @@ void f_type_methods_register(void);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* cf_lex_init - initialize the lexer
|
* cf_lex_init - initialize the lexer
|
||||||
* @is_cli: true if we're going to parse CLI command, false for configuration
|
* @cli_main_config: main configuration structure if we're going to parse CLI command, NULL for new configuration
|
||||||
* @c: configuration structure
|
* @c: configuration structure
|
||||||
*
|
*
|
||||||
* cf_lex_init() initializes the lexical analyzer and prepares it for
|
* cf_lex_init() initializes the lexical analyzer and prepares it for
|
||||||
* parsing of a new input.
|
* parsing of a new input.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
cf_lex_init(int is_cli, struct config *c)
|
cf_lex_init(struct config *cli_main_config, struct config *c)
|
||||||
{
|
{
|
||||||
if (!global_root_scope.readonly)
|
if (!global_root_scope.readonly)
|
||||||
{
|
{
|
||||||
@ -782,7 +782,7 @@ cf_lex_init(int is_cli, struct config *c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ifs_head = ifs = push_ifs(NULL);
|
ifs_head = ifs = push_ifs(NULL);
|
||||||
if (!is_cli)
|
if (!cli_main_config)
|
||||||
{
|
{
|
||||||
ifs->file_name = c->file_name;
|
ifs->file_name = c->file_name;
|
||||||
ifs->fd = c->file_fd;
|
ifs->fd = c->file_fd;
|
||||||
@ -792,15 +792,15 @@ cf_lex_init(int is_cli, struct config *c)
|
|||||||
yyrestart(NULL);
|
yyrestart(NULL);
|
||||||
ifs->buffer = YY_CURRENT_BUFFER;
|
ifs->buffer = YY_CURRENT_BUFFER;
|
||||||
|
|
||||||
if (is_cli)
|
if (cli_main_config)
|
||||||
BEGIN(CLI);
|
BEGIN(CLI);
|
||||||
else
|
else
|
||||||
BEGIN(INITIAL);
|
BEGIN(INITIAL);
|
||||||
|
|
||||||
c->root_scope = c->current_scope = cfg_allocz(sizeof(struct sym_scope));
|
c->root_scope = c->current_scope = cfg_allocz(sizeof(struct sym_scope));
|
||||||
|
|
||||||
if (is_cli)
|
if (cli_main_config)
|
||||||
c->current_scope->next = config->root_scope;
|
c->current_scope->next = cli_main_config->root_scope;
|
||||||
else
|
else
|
||||||
c->current_scope->next = &global_filter_scope;
|
c->current_scope->next = &global_filter_scope;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ config_parse(struct config *c)
|
|||||||
if (setjmp(conf_jmpbuf))
|
if (setjmp(conf_jmpbuf))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
cf_lex_init(0, c);
|
cf_lex_init(NULL, c);
|
||||||
sysdep_preconfig(c);
|
sysdep_preconfig(c);
|
||||||
protos_preconfig(c);
|
protos_preconfig(c);
|
||||||
mpls_preconfig(c);
|
mpls_preconfig(c);
|
||||||
@ -170,7 +170,7 @@ cleanup:
|
|||||||
* it parses a CLI command. See the CLI module for more information.
|
* it parses a CLI command. See the CLI module for more information.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
cli_parse(struct config *c)
|
cli_parse(struct config *main_config, struct config *c)
|
||||||
{
|
{
|
||||||
int done = 0;
|
int done = 0;
|
||||||
new_config = c;
|
new_config = c;
|
||||||
@ -178,7 +178,7 @@ cli_parse(struct config *c)
|
|||||||
if (setjmp(conf_jmpbuf))
|
if (setjmp(conf_jmpbuf))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
cf_lex_init(1, c);
|
cf_lex_init(main_config, c);
|
||||||
cf_parse();
|
cf_parse();
|
||||||
done = 1;
|
done = 1;
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ extern _Thread_local struct config *new_config; /* Configuration being parsed */
|
|||||||
|
|
||||||
struct config *config_alloc(const char *name);
|
struct config *config_alloc(const char *name);
|
||||||
int config_parse(struct config *);
|
int config_parse(struct config *);
|
||||||
int cli_parse(struct config *);
|
int cli_parse(struct config *, struct config *);
|
||||||
void config_free(struct config *);
|
void config_free(struct config *);
|
||||||
void config_free_old(void);
|
void config_free_old(void);
|
||||||
int config_commit(struct config *, int type, uint timeout);
|
int config_commit(struct config *, int type, uint timeout);
|
||||||
@ -216,7 +216,7 @@ struct include_file_stack {
|
|||||||
extern struct include_file_stack *ifs;
|
extern struct include_file_stack *ifs;
|
||||||
|
|
||||||
int cf_lex(void);
|
int cf_lex(void);
|
||||||
void cf_lex_init(int is_cli, struct config *c);
|
void cf_lex_init(struct config *cli_main, struct config *c);
|
||||||
void cf_lex_unwind(void);
|
void cf_lex_unwind(void);
|
||||||
|
|
||||||
struct symbol *cf_find_symbol_scope(const struct sym_scope *scope, const byte *c);
|
struct symbol *cf_find_symbol_scope(const struct sym_scope *scope, const byte *c);
|
||||||
|
@ -232,11 +232,13 @@ cli_command(struct cli *c)
|
|||||||
cli_rh_len = strlen(c->rx_buf);
|
cli_rh_len = strlen(c->rx_buf);
|
||||||
cli_rh_trick_flag = 0;
|
cli_rh_trick_flag = 0;
|
||||||
this_cli = c;
|
this_cli = c;
|
||||||
|
this_cli->main_config = config;
|
||||||
lp_flush(c->parser_pool);
|
lp_flush(c->parser_pool);
|
||||||
res = cli_parse(&f);
|
res = cli_parse(config, &f);
|
||||||
if (!res)
|
if (!res)
|
||||||
cli_printf(c, 9001, f.err_msg);
|
cli_printf(c, 9001, f.err_msg);
|
||||||
|
|
||||||
|
this_cli->main_config = NULL;
|
||||||
config_free(&f);
|
config_free(&f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ typedef struct cli {
|
|||||||
void (*cont)(struct cli *c);
|
void (*cont)(struct cli *c);
|
||||||
void (*cleanup)(struct cli *c); /* The CLI has closed prematurely */
|
void (*cleanup)(struct cli *c); /* The CLI has closed prematurely */
|
||||||
void *rover; /* Private to continuation routine */
|
void *rover; /* Private to continuation routine */
|
||||||
|
struct config *main_config; /* Main config currently in use */
|
||||||
int last_reply;
|
int last_reply;
|
||||||
int restricted; /* CLI is restricted to read-only commands */
|
int restricted; /* CLI is restricted to read-only commands */
|
||||||
struct linpool *parser_pool; /* Pool used during parsing */
|
struct linpool *parser_pool; /* Pool used during parsing */
|
||||||
|
Loading…
Reference in New Issue
Block a user