On Tue, Jan 24, 2023 at 8:12 AM Alexander Zubkov <gr...@qrator.net> wrote:
> > > On Tue, Jan 24, 2023 at 7:59 AM Ondrej Zajicek <santi...@crfreenet.org> > wrote: > >> On Tue, Jan 24, 2023 at 07:44:47AM +0100, Maria Matejka wrote: >> > >Hello >> > > >> > >I thing that the most elegant way how to handle renaming of objects >> > >during reconfiguration is to allow multiple names / aliases. There >> could >> > >be be more symbols pointing to given object (but the object points back >> > >to its primary name). >> > > >> > >Reconfiguration to rename objects could be done in two steps - in the >> > >first step, the user would add alias for the new name. In the second >> step, >> > >the old name would be removed. >> > >> > I think this keeps the problem with protocol restart when the renaming >> > of "base name" is done. >> >> The primary problem of renaming is matching existing objects with >> definitions from the new config. If that can be done (by finding >> existing objects through aliases), it is just a reconfiguration of >> object property, like any other. I.e. implementation problem instead >> of conceptual problem. >> >> > Adding aliases is an interesting option. But for example now in > protos_commit() it uses WALK_LIST(oc, old->protos), so it walks around old > protos first and then searches for a new ones. So it is not enough to add > another name pointing to the protocol, you need to search for protocol name > and also its aliases in the new protocols, or "invert" walking the lists in > all such places. > Probably might work if it is done in several steps: > 1) name1 > 2) name1 + alias name2 > 3) name2 + alias name1 > 4) name2 > I've checked such modifications (in attached patch), and it seems to work too. The transition with those several steps goes without protocol interruption for changing the names of protocols and tables. The patch adds the config statement: link <alias> to <symbol> It makes "alias" to reference the same entity as "symbol". In this case the transition process is longer, but less intervention in the code is required and it may be less ugly. As a plus, the transition can be done without additional CLI commands, only with a series of configs. On the other hand you can not do aliases CLI-only for the transition, you need them to be present in the new config while it is loading. You can do it in CLI for step 1->2, but for 2->3 it will not work. Renaming, though, needed intervention in the config too, to extend the symbol buffers. I also tried to also do a CLI command for aliasing. But it does not work in this variant, the new symbol does not appear in the table. Probably it is cleaned up after the command finishes. It is strange, because when I tried the same for "rename" version like that: CF_CLI(RENAME, CF_SYM_KNOWN CF_SYM_UNDEFINED, <sym> <new>, [[Rename symbol]]) Then I just copied the name from the undefined symbol to the known symbol. And after that I saw multiple occurence of the name in "show symbols". So I thought the undefined one was left in the table. But now when I run "link" in the cli, I do not see the new symbol in the table afterwards.
diff --git a/conf/cf-lex.l b/conf/cf-lex.l index ceedee8a..6508a9cb 100644 --- a/conf/cf-lex.l +++ b/conf/cf-lex.l @@ -667,6 +667,16 @@ cf_localize_symbol(struct symbol *sym) return cf_new_symbol(sym->name); } +void +cf_alias_symbol(struct symbol *sym, struct symbol *alias) +{ + struct symbol tmp = *sym; + tmp.n = alias->n; + tmp.next = alias->next; + tmp.scope = alias->scope; + *alias = tmp; +} + struct symbol * cf_default_name(char *template, int *counter) { diff --git a/conf/conf.h b/conf/conf.h index b409750e..d7796c5c 100644 --- a/conf/conf.h +++ b/conf/conf.h @@ -192,6 +192,7 @@ struct symbol *cf_find_symbol(const struct config *cfg, const byte *c); struct symbol *cf_get_symbol(const byte *c); struct symbol *cf_default_name(char *template, int *counter); struct symbol *cf_localize_symbol(struct symbol *sym); +void cf_alias_symbol(struct symbol *sym, struct symbol *alias); static inline int cf_symbol_is_local(struct symbol *sym) { return (sym->scope == conf_this_scope) && !conf_this_scope->soft_scopes; } diff --git a/nest/cmds.c b/nest/cmds.c index bcc8d6c2..a4536100 100644 --- a/nest/cmds.c +++ b/nest/cmds.c @@ -142,3 +142,10 @@ cmd_eval(const struct f_line *expr) cli_msg(23, "%s", buf.start); } + +void +cmd_alias_symbol(struct symbol *sym, struct symbol *alias) +{ + cf_alias_symbol(sym, alias); + cli_msg(10, "ok"); +} diff --git a/nest/cmds.h b/nest/cmds.h index 194a9d7f..426501a1 100644 --- a/nest/cmds.h +++ b/nest/cmds.h @@ -19,3 +19,5 @@ void cmd_show_memory(void); struct f_line; void cmd_eval(const struct f_line *expr); + +void cmd_alias_symbol(struct symbol *sym, struct symbol *alias); diff --git a/nest/config.Y b/nest/config.Y index b2aa0906..94e11604 100644 --- a/nest/config.Y +++ b/nest/config.Y @@ -154,6 +154,13 @@ CF_ENUM_PX(T_ENUM_AF, AF_, AFI_, IPV4, IPV6) CF_GRAMMAR +conf: alias ; + +alias: LINK CF_SYM_UNDEFINED TO CF_SYM_KNOWN ';' +{ + cf_alias_symbol($4, $2); +}; + /* Setting of router ID */ conf: rtrid ; @@ -925,6 +932,9 @@ proto_patt2: dynamic_attr: IGP_METRIC { $$ = f_new_dynamic_attr(EAF_TYPE_INT, T_INT, EA_GEN_IGP_METRIC); } ; +CF_CLI(LINK, CF_SYM_UNDEFINED TO CF_SYM_KNOWN, <alias> to <sym>, [[Add alias to symbol]]) +{ cmd_alias_symbol($4, $2); }; + CF_CODE