summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libfrr.c2
-rw-r--r--lib/northbound.c19
-rw-r--r--lib/northbound.h22
-rw-r--r--lib/northbound_cli.c11
-rw-r--r--lib/northbound_confd.c2
-rw-r--r--lib/northbound_db.c2
-rw-r--r--lib/northbound_grpc.cpp4
-rw-r--r--lib/northbound_sysrepo.c2
-rw-r--r--lib/prefix.c17
-rw-r--r--lib/prefix.h1
-rw-r--r--lib/vty.c9
-rw-r--r--lib/vty.h2
12 files changed, 50 insertions, 43 deletions
diff --git a/lib/libfrr.c b/lib/libfrr.c
index 0467dc1d7e..d1b7dd133e 100644
--- a/lib/libfrr.c
+++ b/lib/libfrr.c
@@ -992,7 +992,7 @@ static void frr_config_read_in(struct thread *t)
int ret;
context.client = NB_CLIENT_CLI;
- ret = nb_candidate_commit(&context, vty_shared_candidate_config,
+ ret = nb_candidate_commit(context, vty_shared_candidate_config,
true, "Read configuration file", NULL,
errmsg, sizeof(errmsg));
if (ret != NB_OK && ret != NB_ERR_NO_CHANGES)
diff --git a/lib/northbound.c b/lib/northbound.c
index b755264be1..6f2c522a29 100644
--- a/lib/northbound.c
+++ b/lib/northbound.c
@@ -61,7 +61,7 @@ static int nb_callback_configuration(struct nb_context *context,
struct nb_config_change *change,
char *errmsg, size_t errmsg_len);
static struct nb_transaction *
-nb_transaction_new(struct nb_context *context, struct nb_config *config,
+nb_transaction_new(struct nb_context context, struct nb_config *config,
struct nb_config_cbs *changes, const char *comment,
char *errmsg, size_t errmsg_len);
static void nb_transaction_free(struct nb_transaction *transaction);
@@ -835,7 +835,7 @@ int nb_candidate_validate(struct nb_context *context,
return ret;
}
-int nb_candidate_commit_prepare(struct nb_context *context,
+int nb_candidate_commit_prepare(struct nb_context context,
struct nb_config *candidate,
const char *comment,
struct nb_transaction **transaction,
@@ -860,9 +860,8 @@ int nb_candidate_commit_prepare(struct nb_context *context,
return NB_ERR_NO_CHANGES;
}
- if (nb_candidate_validate_code(context, candidate, &changes, errmsg,
- errmsg_len)
- != NB_OK) {
+ if (nb_candidate_validate_code(&context, candidate, &changes, errmsg,
+ errmsg_len) != NB_OK) {
flog_warn(EC_LIB_NB_CANDIDATE_INVALID,
"%s: failed to validate candidate configuration",
__func__);
@@ -913,7 +912,7 @@ void nb_candidate_commit_apply(struct nb_transaction *transaction,
nb_transaction_free(transaction);
}
-int nb_candidate_commit(struct nb_context *context, struct nb_config *candidate,
+int nb_candidate_commit(struct nb_context context, struct nb_config *candidate,
bool save_transaction, const char *comment,
uint32_t *transaction_id, char *errmsg,
size_t errmsg_len)
@@ -1411,13 +1410,13 @@ static int nb_callback_configuration(struct nb_context *context,
}
static struct nb_transaction *
-nb_transaction_new(struct nb_context *context, struct nb_config *config,
+nb_transaction_new(struct nb_context context, struct nb_config *config,
struct nb_config_cbs *changes, const char *comment,
char *errmsg, size_t errmsg_len)
{
struct nb_transaction *transaction;
- if (nb_running_lock_check(context->client, context->user)) {
+ if (nb_running_lock_check(context.client, context.user)) {
strlcpy(errmsg,
"running configuration is locked by another client",
errmsg_len);
@@ -1469,7 +1468,7 @@ static int nb_transaction_process(enum nb_event event,
break;
/* Call the appropriate callback. */
- ret = nb_callback_configuration(transaction->context, event,
+ ret = nb_callback_configuration(&transaction->context, event,
change, errmsg, errmsg_len);
switch (event) {
case NB_EV_PREPARE:
@@ -1584,7 +1583,7 @@ static void nb_transaction_apply_finish(struct nb_transaction *transaction,
/* Call the 'apply_finish' callbacks, sorted by their priorities. */
RB_FOREACH (cb, nb_config_cbs, &cbs)
- nb_callback_apply_finish(transaction->context, cb->nb_node,
+ nb_callback_apply_finish(&transaction->context, cb->nb_node,
cb->dnode, errmsg, errmsg_len);
/* Release memory. */
diff --git a/lib/northbound.h b/lib/northbound.h
index c132daebdb..152810b3a9 100644
--- a/lib/northbound.h
+++ b/lib/northbound.h
@@ -622,22 +622,6 @@ struct nb_context {
/* Northbound user (can be NULL). */
const void *user;
-
- /* Client-specific data. */
-#if 0
- union {
- struct {
- } cli;
- struct {
- } confd;
- struct {
- } sysrepo;
- struct {
- } grpc;
- struct {
- } pcep;
- } client_data;
-#endif
};
/* Northbound configuration. */
@@ -666,7 +650,7 @@ struct nb_config_change {
/* Northbound configuration transaction. */
struct nb_transaction {
- struct nb_context *context;
+ struct nb_context context;
char comment[80];
struct nb_config *config;
struct nb_config_cbs changes;
@@ -927,7 +911,7 @@ extern int nb_candidate_validate(struct nb_context *context,
* the candidate configuration.
* - NB_ERR for other errors.
*/
-extern int nb_candidate_commit_prepare(struct nb_context *context,
+extern int nb_candidate_commit_prepare(struct nb_context context,
struct nb_config *candidate,
const char *comment,
struct nb_transaction **transaction,
@@ -1014,7 +998,7 @@ extern void nb_candidate_commit_apply(struct nb_transaction *transaction,
* the candidate configuration.
* - NB_ERR for other errors.
*/
-extern int nb_candidate_commit(struct nb_context *context,
+extern int nb_candidate_commit(struct nb_context context,
struct nb_config *candidate,
bool save_transaction, const char *comment,
uint32_t *transaction_id, char *errmsg,
diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c
index 0dfa66b37e..fa5884fb78 100644
--- a/lib/northbound_cli.c
+++ b/lib/northbound_cli.c
@@ -46,7 +46,7 @@ static int nb_cli_classic_commit(struct vty *vty)
context.client = NB_CLIENT_CLI;
context.user = vty;
- ret = nb_candidate_commit(&context, vty->candidate_config, true, NULL,
+ ret = nb_candidate_commit(context, vty->candidate_config, true, NULL,
NULL, errmsg, sizeof(errmsg));
switch (ret) {
case NB_OK:
@@ -313,7 +313,7 @@ int nb_cli_confirmed_commit_rollback(struct vty *vty)
context.client = NB_CLIENT_CLI;
context.user = vty;
ret = nb_candidate_commit(
- &context, vty->confirmed_commit_rollback, true,
+ context, vty->confirmed_commit_rollback, true,
"Rollback to previous configuration - confirmed commit has timed out",
&transaction_id, errmsg, sizeof(errmsg));
if (ret == NB_OK) {
@@ -394,9 +394,8 @@ static int nb_cli_commit(struct vty *vty, bool force,
context.client = NB_CLIENT_CLI;
context.user = vty;
- ret = nb_candidate_commit(&context, vty->candidate_config, true,
- comment, &transaction_id, errmsg,
- sizeof(errmsg));
+ ret = nb_candidate_commit(context, vty->candidate_config, true, comment,
+ &transaction_id, errmsg, sizeof(errmsg));
/* Map northbound return code to CLI return code. */
switch (ret) {
@@ -1717,7 +1716,7 @@ static int nb_cli_rollback_configuration(struct vty *vty,
context.client = NB_CLIENT_CLI;
context.user = vty;
- ret = nb_candidate_commit(&context, candidate, true, comment, NULL,
+ ret = nb_candidate_commit(context, candidate, true, comment, NULL,
errmsg, sizeof(errmsg));
nb_config_free(candidate);
switch (ret) {
diff --git a/lib/northbound_confd.c b/lib/northbound_confd.c
index 81ba313e81..2b57ff2707 100644
--- a/lib/northbound_confd.c
+++ b/lib/northbound_confd.c
@@ -311,7 +311,7 @@ static void frr_confd_cdb_read_cb_prepare(int fd, int *subp, int reslen)
*/
transaction = NULL;
context.client = NB_CLIENT_CONFD;
- ret = nb_candidate_commit_prepare(&context, candidate, NULL,
+ ret = nb_candidate_commit_prepare(context, candidate, NULL,
&transaction, errmsg, sizeof(errmsg));
if (ret != NB_OK && ret != NB_ERR_NO_CHANGES) {
enum confd_errcode errcode;
diff --git a/lib/northbound_db.c b/lib/northbound_db.c
index cefcfbcf1f..74abcde955 100644
--- a/lib/northbound_db.c
+++ b/lib/northbound_db.c
@@ -73,7 +73,7 @@ int nb_db_transaction_save(const struct nb_transaction *transaction,
if (!ss)
goto exit;
- client_name = nb_client_name(transaction->context->client);
+ client_name = nb_client_name(transaction->context.client);
/*
* Always record configurations in the XML format, save the default
* values too, as this covers the case where defaults may change.
diff --git a/lib/northbound_grpc.cpp b/lib/northbound_grpc.cpp
index f5d59d92d6..1459146eab 100644
--- a/lib/northbound_grpc.cpp
+++ b/lib/northbound_grpc.cpp
@@ -824,7 +824,7 @@ HandleUnaryCommit(UnaryRpcState<frr::CommitRequest, frr::CommitResponse> *tag)
case frr::CommitRequest::PREPARE:
grpc_debug("`-> Performing PREPARE");
ret = nb_candidate_commit_prepare(
- &context, candidate->config, comment.c_str(),
+ context, candidate->config, comment.c_str(),
&candidate->transaction, errmsg, sizeof(errmsg));
break;
case frr::CommitRequest::ABORT:
@@ -840,7 +840,7 @@ HandleUnaryCommit(UnaryRpcState<frr::CommitRequest, frr::CommitResponse> *tag)
break;
case frr::CommitRequest::ALL:
grpc_debug("`-> Performing ALL");
- ret = nb_candidate_commit(&context, candidate->config, true,
+ ret = nb_candidate_commit(context, candidate->config, true,
comment.c_str(), &transaction_id,
errmsg, sizeof(errmsg));
break;
diff --git a/lib/northbound_sysrepo.c b/lib/northbound_sysrepo.c
index 824d81a51e..096414ff24 100644
--- a/lib/northbound_sysrepo.c
+++ b/lib/northbound_sysrepo.c
@@ -268,7 +268,7 @@ static int frr_sr_config_change_cb_prepare(sr_session_ctx_t *session,
* Validate the configuration changes and allocate all resources
* required to apply them.
*/
- ret = nb_candidate_commit_prepare(&context, candidate, NULL,
+ ret = nb_candidate_commit_prepare(context, candidate, NULL,
&transaction, errmsg, sizeof(errmsg));
if (ret != NB_OK && ret != NB_ERR_NO_CHANGES)
flog_warn(
diff --git a/lib/prefix.c b/lib/prefix.c
index b3d81aa241..a6aae08a6a 100644
--- a/lib/prefix.c
+++ b/lib/prefix.c
@@ -123,6 +123,23 @@ afi_t family2afi(int family)
return 0;
}
+const char *afi2str_lower(afi_t afi)
+{
+ switch (afi) {
+ case AFI_IP:
+ return "ipv4";
+ case AFI_IP6:
+ return "ipv6";
+ case AFI_L2VPN:
+ return "l2vpn";
+ case AFI_MAX:
+ case AFI_UNSPEC:
+ return "bad-value";
+ }
+
+ assert(!"Reached end of function we should never reach");
+}
+
const char *afi2str(afi_t afi)
{
switch (afi) {
diff --git a/lib/prefix.h b/lib/prefix.h
index a6435be1b4..9c57283706 100644
--- a/lib/prefix.h
+++ b/lib/prefix.h
@@ -383,6 +383,7 @@ extern afi_t family2afi(int);
extern const char *family2str(int family);
extern const char *safi2str(safi_t safi);
extern const char *afi2str(afi_t afi);
+extern const char *afi2str_lower(afi_t afi);
static inline afi_t prefix_afi(union prefixconstptr pu)
{
diff --git a/lib/vty.c b/lib/vty.c
index 76dfe9734e..786271abe8 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -297,6 +297,13 @@ int vty_json_no_pretty(struct vty *vty, struct json_object *json)
return vty_json_helper(vty, json, JSON_C_TO_STRING_NOSLASHESCAPE);
}
+void vty_json_empty(struct vty *vty)
+{
+ json_object *json = json_object_new_object();
+
+ vty_json(vty, json);
+}
+
/* Output current time to the vty. */
void vty_time_print(struct vty *vty, int cr)
{
@@ -2413,7 +2420,7 @@ static void vty_read_file(struct nb_config *config, FILE *confp)
context.client = NB_CLIENT_CLI;
context.user = vty;
- ret = nb_candidate_commit(&context, vty->candidate_config, true,
+ ret = nb_candidate_commit(context, vty->candidate_config, true,
"Read configuration file", NULL,
errmsg, sizeof(errmsg));
if (ret != NB_OK && ret != NB_ERR_NO_CHANGES)
diff --git a/lib/vty.h b/lib/vty.h
index b8c677e354..3cab9590f1 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -344,7 +344,7 @@ extern bool vty_set_include(struct vty *vty, const char *regexp);
*/
extern int vty_json(struct vty *vty, struct json_object *json);
extern int vty_json_no_pretty(struct vty *vty, struct json_object *json);
-
+extern void vty_json_empty(struct vty *vty);
/* post fd to be passed to the vtysh client
* fd is owned by the VTY code after this and will be closed when done
*/