summaryrefslogtreecommitdiff
path: root/lib/northbound_cli.c
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2020-04-27 13:13:57 -0300
committerRenato Westphal <renato@opensourcerouting.org>2020-05-28 19:22:54 -0300
commit13d6b9c1343a1f925e3ffd7be0938bf1f395b461 (patch)
tree93f50208c9c3e0403fb01b697234b815f7889a50 /lib/northbound_cli.c
parent1be4decb04be48d73ea90f6feb0f33af25499c19 (diff)
lib: introduce the northbound context structure
The new northbound context structure contains information about the client performing a configuration transaction. This information will be made available to all configuration callbacks through the args->context parameter. The usefulness of this structure comes from the fact that it can be used as a communication channel (both input and output) between the northbound callbacks and the northbound clients. This can be done through its "client_data" field which contains client-specific data. This should cover some very specific scenarios where a northbound callback should perform an action only if the configuration change is coming from a given client. An example would be sending a PCEP response to a PCE when an SR-TE policy is created or modified through the PCEP northbound client (for that to happen, the northbound callbacks need to have access to the PCEP request ID, which needs to be available). Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/northbound_cli.c')
-rw-r--r--lib/northbound_cli.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c
index d4467facaf..544b2434eb 100644
--- a/lib/northbound_cli.c
+++ b/lib/northbound_cli.c
@@ -169,8 +169,12 @@ int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt, ...)
/* Do an implicit "commit" when using the classic CLI mode. */
if (frr_get_cli_mode() == FRR_CLI_CLASSIC) {
- ret = nb_candidate_commit(vty->candidate_config, NB_CLIENT_CLI,
- vty, false, NULL, NULL);
+ struct nb_context context = {};
+
+ context.client = NB_CLIENT_CLI;
+ context.user = vty;
+ ret = nb_candidate_commit(&context, vty->candidate_config,
+ false, NULL, NULL);
if (ret != NB_OK && ret != NB_ERR_NO_CHANGES) {
vty_out(vty, "%% Configuration failed: %s.\n\n",
nb_err_name(ret));
@@ -217,12 +221,16 @@ void nb_cli_confirmed_commit_clean(struct vty *vty)
int nb_cli_confirmed_commit_rollback(struct vty *vty)
{
+ struct nb_context context = {};
uint32_t transaction_id;
int ret;
+
/* Perform the rollback. */
+ context.client = NB_CLIENT_CLI;
+ context.user = vty;
ret = nb_candidate_commit(
- vty->confirmed_commit_rollback, NB_CLIENT_CLI, vty, true,
+ &context, vty->confirmed_commit_rollback, true,
"Rollback to previous configuration - confirmed commit has timed out",
&transaction_id);
if (ret == NB_OK)
@@ -252,6 +260,7 @@ static int nb_cli_confirmed_commit_timeout(struct thread *thread)
static int nb_cli_commit(struct vty *vty, bool force,
unsigned int confirmed_timeout, char *comment)
{
+ struct nb_context context = {};
uint32_t transaction_id = 0;
int ret;
@@ -295,8 +304,10 @@ static int nb_cli_commit(struct vty *vty, bool force,
&vty->t_confirmed_commit_timeout);
}
- ret = nb_candidate_commit(vty->candidate_config, NB_CLIENT_CLI, vty,
- true, comment, &transaction_id);
+ context.client = NB_CLIENT_CLI;
+ context.user = vty;
+ ret = nb_candidate_commit(&context, vty->candidate_config, true,
+ comment, &transaction_id);
/* Map northbound return code to CLI return code. */
switch (ret) {
@@ -690,9 +701,12 @@ DEFPY (config_commit_check,
"Commit changes into the running configuration\n"
"Check if the configuration changes are valid\n")
{
+ struct nb_context context = {};
int ret;
- ret = nb_candidate_validate(vty->candidate_config);
+ context.client = NB_CLIENT_CLI;
+ context.user = vty;
+ ret = nb_candidate_validate(&context, vty->candidate_config);
if (ret != NB_OK) {
vty_out(vty,
"%% Failed to validate candidate configuration.\n\n");
@@ -1530,6 +1544,7 @@ DEFPY (show_yang_module_translator,
static int nb_cli_rollback_configuration(struct vty *vty,
uint32_t transaction_id)
{
+ struct nb_context context = {};
struct nb_config *candidate;
char comment[80];
int ret;
@@ -1544,8 +1559,9 @@ static int nb_cli_rollback_configuration(struct vty *vty,
snprintf(comment, sizeof(comment), "Rollback to transaction %u",
transaction_id);
- ret = nb_candidate_commit(candidate, NB_CLIENT_CLI, vty, true, comment,
- NULL);
+ context.client = NB_CLIENT_CLI;
+ context.user = vty;
+ ret = nb_candidate_commit(&context, candidate, true, comment, NULL);
nb_config_free(candidate);
switch (ret) {
case NB_OK: