Merge pull request #6728 from idryzhov/vtysh-fixes

[7.4] cherry-pick vtysh fixes
This commit is contained in:
Donatas Abraitis 2020-07-15 12:11:40 +03:00 committed by GitHub
commit 40858a3c7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,7 +34,7 @@ DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CONFIG_LINE, "Vtysh configuration line")
vector configvec; vector configvec;
PREDECL_RBTREE_UNIQ(config_master); PREDECL_LIST(config_master);
struct config { struct config {
/* Configuration node name. */ /* Configuration node name. */
@ -72,11 +72,6 @@ static struct config *config_new(void)
return config; return config;
} }
static int config_cmp(const struct config *c1, const struct config *c2)
{
return strcmp(c1->name, c2->name);
}
static void config_del(struct config *config) static void config_del(struct config *config)
{ {
list_delete(&config->line); list_delete(&config->line);
@ -84,13 +79,15 @@ static void config_del(struct config *config)
XFREE(MTYPE_VTYSH_CONFIG, config); XFREE(MTYPE_VTYSH_CONFIG, config);
} }
DECLARE_RBTREE_UNIQ(config_master, struct config, rbt_item, config_cmp) DECLARE_LIST(config_master, struct config, rbt_item)
static struct config *config_get(int index, const char *line) static struct config *config_get(int index, const char *line)
{ {
struct config *config; struct config *config, *config_loop;
struct config_master_head *master; struct config_master_head *master;
config = config_loop = NULL;
master = vector_lookup_ensure(configvec, index); master = vector_lookup_ensure(configvec, index);
if (!master) { if (!master) {
@ -99,8 +96,12 @@ static struct config *config_get(int index, const char *line)
vector_set_index(configvec, index, master); vector_set_index(configvec, index, master);
} }
const struct config config_ref = { .name = (char *)line }; frr_each (config_master, master, config_loop) {
config = config_master_find(master, &config_ref); if (strcmp(config_loop->name, line) == 0) {
config = config_loop;
break;
}
}
if (!config) { if (!config) {
config = config_new(); config = config_new();
@ -109,7 +110,7 @@ static struct config *config_get(int index, const char *line)
config->line->cmp = (int (*)(void *, void *))line_cmp; config->line->cmp = (int (*)(void *, void *))line_cmp;
config->name = XSTRDUP(MTYPE_VTYSH_CONFIG_LINE, line); config->name = XSTRDUP(MTYPE_VTYSH_CONFIG_LINE, line);
config->index = index; config->index = index;
config_master_add(master, config); config_master_add_tail(master, config);
} }
return config; return config;
} }