summaryrefslogtreecommitdiffstats
path: root/lib/northbound_cli.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/northbound_cli.c')
-rw-r--r--lib/northbound_cli.c71
1 files changed, 54 insertions, 17 deletions
diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c
index 8003679..8809ec2 100644
--- a/lib/northbound_cli.c
+++ b/lib/northbound_cli.c
@@ -5,6 +5,7 @@
*/
#include <zebra.h>
+#include <sys/stat.h>
#include "libfrr.h"
#include "lib/version.h"
@@ -24,6 +25,7 @@
struct debug nb_dbg_cbs_config = {0, "Northbound callbacks: configuration"};
struct debug nb_dbg_cbs_state = {0, "Northbound callbacks: state"};
struct debug nb_dbg_cbs_rpc = {0, "Northbound callbacks: RPCs"};
+struct debug nb_dbg_cbs_notify = {0, "Northbound callbacks: notifications"};
struct debug nb_dbg_notif = {0, "Northbound notifications"};
struct debug nb_dbg_events = {0, "Northbound events"};
struct debug nb_dbg_libyang = {0, "libyang debugging"};
@@ -145,10 +147,9 @@ static int nb_cli_apply_changes_internal(struct vty *vty,
VTY_CHECK_XPATH;
- nb_candidate_edit_config_changes(
- vty->candidate_config, vty->cfg_changes, vty->num_cfg_changes,
- xpath_base, VTY_CURR_XPATH, vty->xpath_index, buf, sizeof(buf),
- &error);
+ nb_candidate_edit_config_changes(vty->candidate_config, vty->cfg_changes,
+ vty->num_cfg_changes, xpath_base,
+ false, buf, sizeof(buf), &error);
if (error) {
/*
* Failure to edit the candidate configuration should never
@@ -180,8 +181,26 @@ static int nb_cli_apply_changes_internal(struct vty *vty,
return CMD_SUCCESS;
}
+static void create_xpath_base_abs(struct vty *vty, char *xpath_base_abs,
+ size_t xpath_base_abs_size,
+ const char *xpath_base)
+{
+ memset(xpath_base_abs, 0, xpath_base_abs_size);
+
+ if (xpath_base[0] == 0)
+ xpath_base = ".";
+
+ /* If base xpath is relative, prepend current vty xpath. */
+ if (vty->xpath_index > 0 && xpath_base[0] == '.') {
+ strlcpy(xpath_base_abs, VTY_CURR_XPATH, xpath_base_abs_size);
+ xpath_base++; /* skip '.' */
+ }
+ strlcat(xpath_base_abs, xpath_base, xpath_base_abs_size);
+}
+
int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt, ...)
{
+ char xpath_base_abs[XPATH_MAXLEN] = {};
char xpath_base[XPATH_MAXLEN] = {};
bool implicit_commit;
int ret;
@@ -195,6 +214,9 @@ int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt, ...)
va_end(ap);
}
+ create_xpath_base_abs(vty, xpath_base_abs, sizeof(xpath_base_abs),
+ xpath_base);
+
if (vty_mgmt_should_process_cli_apply_changes(vty)) {
VTY_CHECK_XPATH;
@@ -202,18 +224,20 @@ int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt, ...)
return CMD_SUCCESS;
implicit_commit = vty_needs_implicit_commit(vty);
- ret = vty_mgmt_send_config_data(vty, implicit_commit);
+ ret = vty_mgmt_send_config_data(vty, xpath_base_abs,
+ implicit_commit);
if (ret >= 0 && !implicit_commit)
vty->mgmt_num_pending_setcfg++;
return ret;
}
- return nb_cli_apply_changes_internal(vty, xpath_base, false);
+ return nb_cli_apply_changes_internal(vty, xpath_base_abs, false);
}
int nb_cli_apply_changes_clear_pending(struct vty *vty,
const char *xpath_base_fmt, ...)
{
+ char xpath_base_abs[XPATH_MAXLEN] = {};
char xpath_base[XPATH_MAXLEN] = {};
bool implicit_commit;
int ret;
@@ -227,6 +251,9 @@ int nb_cli_apply_changes_clear_pending(struct vty *vty,
va_end(ap);
}
+ create_xpath_base_abs(vty, xpath_base_abs, sizeof(xpath_base_abs),
+ xpath_base);
+
if (vty_mgmt_should_process_cli_apply_changes(vty)) {
VTY_CHECK_XPATH;
/*
@@ -238,13 +265,14 @@ int nb_cli_apply_changes_clear_pending(struct vty *vty,
* conversions to mgmtd require full proper implementations.
*/
implicit_commit = vty_needs_implicit_commit(vty);
- ret = vty_mgmt_send_config_data(vty, implicit_commit);
+ ret = vty_mgmt_send_config_data(vty, xpath_base_abs,
+ implicit_commit);
if (ret >= 0 && !implicit_commit)
vty->mgmt_num_pending_setcfg++;
return ret;
}
- return nb_cli_apply_changes_internal(vty, xpath_base, true);
+ return nb_cli_apply_changes_internal(vty, xpath_base_abs, true);
}
int nb_cli_rpc(struct vty *vty, const char *xpath, struct list *input,
@@ -1411,11 +1439,9 @@ static int nb_cli_oper_data_cb(const struct lysc_node *snode,
}
exit:
- yang_data_free(data);
return NB_OK;
error:
- yang_data_free(data);
return NB_ERR;
}
@@ -1464,9 +1490,14 @@ DEFPY (show_yang_operational_data,
ly_ctx = ly_native_ctx;
/* Obtain data. */
- dnode = yang_dnode_new(ly_ctx, false);
- ret = nb_oper_data_iterate(xpath, translator, 0, nb_cli_oper_data_cb,
- dnode);
+ if (translator) {
+ dnode = yang_dnode_new(ly_ctx, false);
+ ret = nb_oper_iterate_legacy(xpath, translator, 0,
+ nb_cli_oper_data_cb, dnode, NULL);
+ } else {
+ dnode = NULL;
+ ret = nb_oper_iterate_legacy(xpath, NULL, 0, NULL, NULL, &dnode);
+ }
if (ret != NB_OK) {
if (format == LYD_JSON)
vty_out(vty, "{}\n");
@@ -1474,7 +1505,8 @@ DEFPY (show_yang_operational_data,
/* embed ly_last_errmsg() when we get newer libyang */
vty_out(vty, "<!-- Not found -->\n");
}
- yang_dnode_free(dnode);
+ if (dnode)
+ yang_dnode_free(dnode);
return CMD_WARNING;
}
@@ -1741,13 +1773,15 @@ DEFPY (rollback_config,
/* Debug CLI commands. */
static struct debug *nb_debugs[] = {
&nb_dbg_cbs_config, &nb_dbg_cbs_state, &nb_dbg_cbs_rpc,
- &nb_dbg_notif, &nb_dbg_events, &nb_dbg_libyang,
+ &nb_dbg_cbs_notify, &nb_dbg_notif, &nb_dbg_events,
+ &nb_dbg_libyang,
};
static const char *const nb_debugs_conflines[] = {
"debug northbound callbacks configuration",
"debug northbound callbacks state",
"debug northbound callbacks rpc",
+ "debug northbound callbacks notify",
"debug northbound notifications",
"debug northbound events",
"debug northbound libyang",
@@ -1772,7 +1806,7 @@ DEFPY (debug_nb,
debug_nb_cmd,
"[no] debug northbound\
[<\
- callbacks$cbs [{configuration$cbs_cfg|state$cbs_state|rpc$cbs_rpc}]\
+ callbacks$cbs [{configuration$cbs_cfg|state$cbs_state|rpc$cbs_rpc|notify$cbs_notify}]\
|notifications$notifications\
|events$events\
|libyang$libyang\
@@ -1785,13 +1819,14 @@ DEFPY (debug_nb,
"State\n"
"RPC\n"
"Notifications\n"
+ "Notifications\n"
"Events\n"
"libyang debugging\n")
{
uint32_t mode = DEBUG_NODE2MODE(vty->node);
if (cbs) {
- bool none = (!cbs_cfg && !cbs_state && !cbs_rpc);
+ bool none = (!cbs_cfg && !cbs_state && !cbs_rpc && !cbs_notify);
if (none || cbs_cfg)
DEBUG_MODE_SET(&nb_dbg_cbs_config, mode, !no);
@@ -1799,6 +1834,8 @@ DEFPY (debug_nb,
DEBUG_MODE_SET(&nb_dbg_cbs_state, mode, !no);
if (none || cbs_rpc)
DEBUG_MODE_SET(&nb_dbg_cbs_rpc, mode, !no);
+ if (none || cbs_notify)
+ DEBUG_MODE_SET(&nb_dbg_cbs_notify, mode, !no);
}
if (notifications)
DEBUG_MODE_SET(&nb_dbg_notif, mode, !no);