]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
CLI keeps its active config pointer explicitly
authorMaria Matejka <mq@ucw.cz>
Thu, 13 Jun 2024 10:29:21 +0000 (12:29 +0200)
committerMaria Matejka <mq@ucw.cz>
Fri, 14 Jun 2024 21:16:07 +0000 (23:16 +0200)
conf/cf-lex.l
conf/conf.c
conf/conf.h
nest/cli.c
nest/cli.h

index b7ecfb7bf829d832b00a528e830c1bf73bd4b12b..556def3184163880f071e36f393311a3b5e7b3bc 100644 (file)
@@ -757,14 +757,14 @@ void f_type_methods_register(void);
 
 /**
  * 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
  *
  * cf_lex_init() initializes the lexical analyzer and prepares it for
  * parsing of a new input.
  */
 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)
   {
@@ -782,7 +782,7 @@ cf_lex_init(int is_cli, struct config *c)
   }
 
   ifs_head = ifs = push_ifs(NULL);
-  if (!is_cli)
+  if (!cli_main_config)
     {
       ifs->file_name = c->file_name;
       ifs->fd = c->file_fd;
@@ -792,15 +792,15 @@ cf_lex_init(int is_cli, struct config *c)
   yyrestart(NULL);
   ifs->buffer = YY_CURRENT_BUFFER;
 
-  if (is_cli)
+  if (cli_main_config)
     BEGIN(CLI);
   else
     BEGIN(INITIAL);
 
   c->root_scope = c->current_scope = cfg_allocz(sizeof(struct sym_scope));
 
-  if (is_cli)
-    c->current_scope->next = config->root_scope;
+  if (cli_main_config)
+    c->current_scope->next = cli_main_config->root_scope;
   else
     c->current_scope->next = &global_filter_scope;
 }
index 90dbb444a278b9f628a5988861239183199be9b8..a7dc7edc4ea7ca0b65d2447b1dab93bc576ccedb 100644 (file)
@@ -138,7 +138,7 @@ config_parse(struct config *c)
   if (setjmp(conf_jmpbuf))
     goto cleanup;
 
-  cf_lex_init(0, c);
+  cf_lex_init(NULL, c);
   sysdep_preconfig(c);
   protos_preconfig(c);
   mpls_preconfig(c);
@@ -170,7 +170,7 @@ cleanup:
  * it parses a CLI command. See the CLI module for more information.
  */
 int
-cli_parse(struct config *c)
+cli_parse(struct config *main_config, struct config *c)
 {
   int done = 0;
   new_config = c;
@@ -178,7 +178,7 @@ cli_parse(struct config *c)
   if (setjmp(conf_jmpbuf))
     goto cleanup;
 
-  cf_lex_init(1, c);
+  cf_lex_init(main_config, c);
   cf_parse();
   done = 1;
 
index 8b8e0c31bc939e0e60dbe3d20759a4e12a89714b..f4f8942e4099b01ff2aee6bacbcb9248fdf125ce 100644 (file)
@@ -81,7 +81,7 @@ extern _Thread_local struct config *new_config;       /* Configuration being parsed */
 
 struct config *config_alloc(const char *name);
 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_old(void);
 int config_commit(struct config *, int type, uint timeout);
@@ -216,7 +216,7 @@ struct include_file_stack {
 extern struct include_file_stack *ifs;
 
 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);
 
 struct symbol *cf_find_symbol_scope(const struct sym_scope *scope, const byte *c);
index 92c4640e856f806653792aadb7b31a9d092ed2d3..c4acb5a7cfbfbd6977f1bb721d80052898d0ea88 100644 (file)
@@ -232,11 +232,13 @@ cli_command(struct cli *c)
   cli_rh_len = strlen(c->rx_buf);
   cli_rh_trick_flag = 0;
   this_cli = c;
+  this_cli->main_config = config;
   lp_flush(c->parser_pool);
-  res = cli_parse(&f);
+  res = cli_parse(config, &f);
   if (!res)
     cli_printf(c, 9001, f.err_msg);
 
+  this_cli->main_config = NULL;
   config_free(&f);
 }
 
index be439ffb9b62980390ff942cd94da7808658cca8..bcc64dc055e43c53f9dee4e67bd25952e31393a6 100644 (file)
@@ -36,6 +36,7 @@ typedef struct cli {
   void (*cont)(struct cli *c);
   void (*cleanup)(struct cli *c);      /* The CLI has closed prematurely */
   void *rover;                         /* Private to continuation routine */
+  struct config *main_config;          /* Main config currently in use */
   int last_reply;
   int restricted;                      /* CLI is restricted to read-only commands */
   struct linpool *parser_pool;         /* Pool used during parsing */