diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2020-06-04 19:26:42 -0400 |
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2020-06-04 20:24:52 -0400 |
| commit | f7c20aa1fd5b997a6c545f0f064b82ad8a5cd3ce (patch) | |
| tree | c02e2394dbbff468c651e803ee144d6e818fc649 /lib/northbound.c | |
| parent | f981d44931ced06f594b33c54a27d6d843ad0379 (diff) | |
lib: move all userdata when changing node xpath
All userdata pointers need to be rekeyed to their new xpaths, not just
the one associated with the dnode being moved.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/northbound.c')
| -rw-r--r-- | lib/northbound.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/northbound.c b/lib/northbound.c index 18bd4f5fd8..e393c33928 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -30,6 +30,7 @@ #include "northbound.h" #include "northbound_cli.h" #include "northbound_db.h" +#include "frrstr.h" DEFINE_MTYPE_STATIC(LIB, NB_NODE, "Northbound Node") DEFINE_MTYPE_STATIC(LIB, NB_CONFIG, "Northbound Configuration") @@ -1789,6 +1790,29 @@ void nb_running_set_entry(const struct lyd_node *dnode, void *entry) config->entry = entry; } +void nb_running_move_tree(const char *xpath_from, const char *xpath_to) +{ + struct nb_config_entry *entry; + struct list *entries = hash_to_list(running_config_entries); + struct listnode *ln; + + for (ALL_LIST_ELEMENTS_RO(entries, ln, entry)) { + if (!frrstr_startswith(entry->xpath, xpath_from)) + continue; + + hash_release(running_config_entries, entry); + + char *newpath = + frrstr_replace(entry->xpath, xpath_from, xpath_to); + strlcpy(entry->xpath, newpath, sizeof(entry->xpath)); + XFREE(MTYPE_TMP, newpath); + + hash_get(running_config_entries, entry, hash_alloc_intern); + } + + list_delete(&entries); +} + static void *nb_running_unset_entry_helper(const struct lyd_node *dnode) { struct nb_config_entry *config, s; |
