summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/command.c12
-rw-r--r--lib/flex_algo.c93
-rw-r--r--lib/flex_algo.h10
-rw-r--r--lib/link_state.c16
-rw-r--r--lib/log_vty.c11
-rw-r--r--lib/mgmt_be_client.c165
-rw-r--r--lib/mgmt_be_client.h14
-rw-r--r--lib/mgmt_fe_client.c83
-rw-r--r--lib/mgmt_fe_client.h14
-rw-r--r--lib/subdir.am2
-rw-r--r--lib/vty.c18
-rw-r--r--lib/vty.h1
12 files changed, 312 insertions, 127 deletions
diff --git a/lib/command.c b/lib/command.c
index 97ea200ff4..7a7ce3f5dc 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -31,6 +31,8 @@
#include "jhash.h"
#include "hook.h"
#include "lib_errors.h"
+#include "mgmt_be_client.h"
+#include "mgmt_fe_client.h"
#include "northbound_cli.h"
#include "network.h"
#include "routemap.h"
@@ -1301,6 +1303,14 @@ int config_from_file(struct vty *vty, FILE *fp, unsigned int *line_num)
while (fgets(vty->buf, VTY_BUFSIZ, fp)) {
++(*line_num);
+ if (vty_log_commands) {
+ int len = strlen(vty->buf);
+
+ /* now log the command */
+ zlog_notice("config-from-file# %.*s", len ? len - 1 : 0,
+ vty->buf);
+ }
+
ret = command_config_read_one_line(vty, NULL, *line_num, 0);
if (ret != CMD_SUCCESS && ret != CMD_WARNING
@@ -2438,6 +2448,8 @@ const char *host_config_get(void)
void cmd_show_lib_debugs(struct vty *vty)
{
route_map_show_debug(vty);
+ mgmt_debug_be_client_show_debug(vty);
+ mgmt_debug_fe_client_show_debug(vty);
}
void install_default(enum node_type node)
diff --git a/lib/flex_algo.c b/lib/flex_algo.c
index bafbf8b779..f48117ff1b 100644
--- a/lib/flex_algo.c
+++ b/lib/flex_algo.c
@@ -17,26 +17,42 @@
#include "flex_algo.h"
-DEFINE_MTYPE_STATIC(LIB, FLEX_ALGO, "Flex-Algo Definition");
+DEFINE_MTYPE_STATIC(LIB, FLEX_ALGO_DATABASE, "Flex-Algo database");
+DEFINE_MTYPE_STATIC(LIB, FLEX_ALGO, "Flex-Algo algorithm information");
+
+static void _flex_algo_delete(struct flex_algos *flex_algos,
+ struct flex_algo *fa);
struct flex_algos *flex_algos_alloc(flex_algo_allocator_t allocator,
flex_algo_releaser_t releaser)
{
struct flex_algos *flex_algos;
- flex_algos = XCALLOC(MTYPE_FLEX_ALGO, sizeof(*flex_algos));
+ flex_algos =
+ XCALLOC(MTYPE_FLEX_ALGO_DATABASE, sizeof(struct flex_algos));
flex_algos->flex_algos = list_new();
flex_algos->allocator = allocator;
flex_algos->releaser = releaser;
return flex_algos;
}
+void flex_algos_free(struct flex_algos *flex_algos)
+{
+ struct listnode *node, *nnode;
+ struct flex_algo *fa;
+
+ for (ALL_LIST_ELEMENTS(flex_algos->flex_algos, node, nnode, fa))
+ _flex_algo_delete(flex_algos, fa);
+ list_delete(&flex_algos->flex_algos);
+ XFREE(MTYPE_FLEX_ALGO_DATABASE, flex_algos);
+}
+
struct flex_algo *flex_algo_alloc(struct flex_algos *flex_algos,
uint8_t algorithm, void *arg)
{
struct flex_algo *fa;
- fa = XCALLOC(MTYPE_FLEX_ALGO, sizeof(*fa));
+ fa = XCALLOC(MTYPE_FLEX_ALGO, sizeof(struct flex_algo));
fa->algorithm = algorithm;
if (flex_algos->allocator)
fa->data = flex_algos->allocator(arg);
@@ -47,6 +63,31 @@ struct flex_algo *flex_algo_alloc(struct flex_algos *flex_algos,
return fa;
}
+static void _flex_algo_delete(struct flex_algos *flex_algos,
+ struct flex_algo *fa)
+{
+ if (flex_algos->releaser)
+ flex_algos->releaser(fa->data);
+ admin_group_term(&fa->admin_group_exclude_any);
+ admin_group_term(&fa->admin_group_include_any);
+ admin_group_term(&fa->admin_group_include_all);
+ listnode_delete(flex_algos->flex_algos, fa);
+ XFREE(MTYPE_FLEX_ALGO, fa);
+}
+
+
+void flex_algo_delete(struct flex_algos *flex_algos, uint8_t algorithm)
+{
+ struct listnode *node, *nnode;
+ struct flex_algo *fa;
+
+ for (ALL_LIST_ELEMENTS(flex_algos->flex_algos, node, nnode, fa)) {
+ if (fa->algorithm != algorithm)
+ continue;
+ _flex_algo_delete(flex_algos, fa);
+ }
+}
+
/**
* @brief Look up the local flex-algo object by its algorithm number.
* @param algorithm flex-algo algorithm number
@@ -79,6 +120,12 @@ bool flex_algo_definition_cmp(struct flex_algo *fa1, struct flex_algo *fa2)
return false;
if (fa1->metric_type != fa2->metric_type)
return false;
+ if (fa1->exclude_srlg != fa2->exclude_srlg)
+ return false;
+ if (fa1->flags != fa2->flags)
+ return false;
+ if (fa1->unsupported_subtlv != fa2->unsupported_subtlv)
+ return false;
if (!admin_group_cmp(&fa1->admin_group_exclude_any,
&fa2->admin_group_exclude_any))
@@ -93,25 +140,6 @@ bool flex_algo_definition_cmp(struct flex_algo *fa1, struct flex_algo *fa2)
return true;
}
-void flex_algo_delete(struct flex_algos *flex_algos, uint8_t algorithm)
-{
- struct listnode *node, *nnode;
- struct flex_algo *fa;
-
- for (ALL_LIST_ELEMENTS(flex_algos->flex_algos, node, nnode, fa)) {
- if (fa->algorithm != algorithm)
- continue;
- if (flex_algos->releaser)
- flex_algos->releaser(fa->data);
- admin_group_term(&fa->admin_group_exclude_any);
- admin_group_term(&fa->admin_group_include_any);
- admin_group_term(&fa->admin_group_include_all);
- listnode_delete(flex_algos->flex_algos, fa);
- XFREE(MTYPE_FLEX_ALGO, fa);
- return;
- }
-}
-
/**
* Check SR Algorithm is Flex-Algo
* according to RFC9350 section 4
@@ -140,3 +168,24 @@ char *flex_algo_metric_type_print(char *type_str, size_t sz,
}
return type_str;
}
+
+bool flex_algo_get_state(struct flex_algos *flex_algos, uint8_t algorithm)
+{
+ struct flex_algo *fa = flex_algo_lookup(flex_algos, algorithm);
+
+ if (!fa)
+ return false;
+
+ return fa->state;
+}
+
+void flex_algo_set_state(struct flex_algos *flex_algos, uint8_t algorithm,
+ bool state)
+{
+ struct flex_algo *fa = flex_algo_lookup(flex_algos, algorithm);
+
+ if (!fa)
+ return;
+
+ fa->state = state;
+}
diff --git a/lib/flex_algo.h b/lib/flex_algo.h
index e012f46862..e617e7cae8 100644
--- a/lib/flex_algo.h
+++ b/lib/flex_algo.h
@@ -83,6 +83,11 @@ struct flex_algo {
#define FLEX_ALGO_IP 0x04
uint8_t dataplanes;
+ /* True if the Algorithm is locally enabled (ie. a definition has been
+ * found and is supported).
+ */
+ bool state;
+
/*
* This property can be freely extended among different routing
* protocols. Since Flex-Algo is an IGP protocol agnostic, both IS-IS
@@ -107,6 +112,7 @@ struct flex_algos {
*/
struct flex_algos *flex_algos_alloc(flex_algo_allocator_t allocator,
flex_algo_releaser_t releaser);
+void flex_algos_free(struct flex_algos *flex_algos);
struct flex_algo *flex_algo_alloc(struct flex_algos *flex_algos,
uint8_t algorithm, void *arg);
struct flex_algo *flex_algo_lookup(struct flex_algos *flex_algos,
@@ -118,4 +124,8 @@ bool flex_algo_id_valid(uint16_t algorithm);
char *flex_algo_metric_type_print(char *type_str, size_t sz,
enum flex_algo_metric_type metric_type);
+bool flex_algo_get_state(struct flex_algos *flex_algos, uint8_t algorithm);
+
+void flex_algo_set_state(struct flex_algos *flex_algos, uint8_t algorithm,
+ bool state);
#endif /* _FRR_FLEX_ALGO_H */
diff --git a/lib/link_state.c b/lib/link_state.c
index 752030cd47..58727a568b 100644
--- a/lib/link_state.c
+++ b/lib/link_state.c
@@ -497,7 +497,6 @@ void ls_vertex_del(struct ls_ted *ted, struct ls_vertex *vertex)
/* Then remove Vertex from Link State Data Base and free memory */
vertices_del(&ted->vertices, vertex);
XFREE(MTYPE_LS_DB, vertex);
- vertex = NULL;
}
void ls_vertex_del_all(struct ls_ted *ted, struct ls_vertex *vertex)
@@ -956,7 +955,10 @@ struct ls_subnet *ls_find_subnet(struct ls_ted *ted,
{
struct ls_subnet subnet = {};
- subnet.key = *prefix;
+ if (!prefix)
+ return NULL;
+
+ prefix_copy(&subnet.key, prefix);
return subnets_find(&ted->subnets, &subnet);
}
@@ -1779,9 +1781,10 @@ struct ls_vertex *ls_msg2vertex(struct ls_ted *ted, struct ls_message *msg,
case LS_MSG_EVENT_DELETE:
vertex = ls_find_vertex_by_id(ted, node->adv);
if (vertex) {
- if (delete)
+ if (delete) {
ls_vertex_del_all(ted, vertex);
- else
+ vertex = NULL;
+ } else
vertex->status = DELETE;
}
break;
@@ -1858,9 +1861,10 @@ struct ls_subnet *ls_msg2subnet(struct ls_ted *ted, struct ls_message *msg,
case LS_MSG_EVENT_DELETE:
subnet = ls_find_subnet(ted, &pref->pref);
if (subnet) {
- if (delete)
+ if (delete) {
ls_subnet_del_all(ted, subnet);
- else
+ subnet = NULL;
+ } else
subnet->status = DELETE;
}
break;
diff --git a/lib/log_vty.c b/lib/log_vty.c
index fc28ffc6fa..26e608d16b 100644
--- a/lib/log_vty.c
+++ b/lib/log_vty.c
@@ -34,18 +34,23 @@ static int log_cmdline_syslog_lvl = ZLOG_DISABLED;
static struct zlog_cfg_file zt_file_cmdline = {
.prio_min = ZLOG_DISABLED,
+ .ts_subsec = LOG_TIMESTAMP_PRECISION,
};
static struct zlog_cfg_file zt_file = {
.prio_min = ZLOG_DISABLED,
+ .ts_subsec = LOG_TIMESTAMP_PRECISION,
};
static struct zlog_cfg_filterfile zt_filterfile = {
- .parent = {
- .prio_min = ZLOG_DISABLED,
- },
+ .parent =
+ {
+ .prio_min = ZLOG_DISABLED,
+ .ts_subsec = LOG_TIMESTAMP_PRECISION,
+ },
};
static struct zlog_cfg_file zt_stdout_file = {
.prio_min = ZLOG_DISABLED,
+ .ts_subsec = LOG_TIMESTAMP_PRECISION,
};
static struct zlog_cfg_5424 zt_stdout_journald = {
.prio_min = ZLOG_DISABLED,
diff --git a/lib/mgmt_be_client.c b/lib/mgmt_be_client.c
index 7437eedfc7..9427f7cf3d 100644
--- a/lib/mgmt_be_client.c
+++ b/lib/mgmt_be_client.c
@@ -6,29 +6,25 @@
*/
#include <zebra.h>
+#include "debug.h"
#include "libfrr.h"
#include "mgmtd/mgmt.h"
#include "mgmt_be_client.h"
#include "mgmt_msg.h"
#include "mgmt_pb.h"
#include "network.h"
+#include "northbound.h"
#include "stream.h"
#include "sockopt.h"
-#ifdef REDIRECT_DEBUG_TO_STDERR
-#define MGMTD_BE_CLIENT_DBG(fmt, ...) \
- fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__)
-#define MGMTD_BE_CLIENT_ERR(fmt, ...) \
- fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__)
-#else /* REDIRECT_DEBUG_TO_STDERR */
+#include "lib/mgmt_be_client_clippy.c"
+
#define MGMTD_BE_CLIENT_DBG(fmt, ...) \
- do { \
- if (mgmt_debug_be_client) \
- zlog_debug("%s: " fmt, __func__, ##__VA_ARGS__); \
- } while (0)
+ DEBUGD(&mgmt_dbg_be_client, "%s:" fmt, __func__, ##__VA_ARGS__)
#define MGMTD_BE_CLIENT_ERR(fmt, ...) \
zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__)
-#endif /* REDIRECT_DEBUG_TO_STDERR */
+#define MGMTD_DBG_BE_CLIENT_CHECK() \
+ DEBUG_MODE_CHECK(&mgmt_dbg_be_client, DEBUG_MODE_ALL)
DEFINE_MTYPE_STATIC(LIB, MGMTD_BE_BATCH,
"MGMTD backend transaction batch data");
@@ -118,8 +114,6 @@ struct mgmt_be_client_ctx {
struct nb_config *candidate_config;
struct nb_config *running_config;
- unsigned long num_batch_find;
- unsigned long avg_batch_find_tm;
unsigned long num_edit_nb_cfg;
unsigned long avg_edit_nb_cfg_tm;
unsigned long num_prep_nb_cfg;
@@ -136,7 +130,7 @@ struct mgmt_be_client_ctx {
#define FOREACH_BE_TXN_IN_LIST(client_ctx, txn) \
frr_each_safe (mgmt_be_txns, &(client_ctx)->txn_head, (txn))
-static bool mgmt_debug_be_client;
+struct debug mgmt_dbg_be_client = {0, "Management backend client operations"};
static struct mgmt_be_client_ctx mgmt_be_client_ctx = {
.conn_fd = -1,
@@ -479,7 +473,6 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn)
bool error;
char err_buf[BUFSIZ];
size_t num_processed;
- bool debug_be = mgmt_debug_be_client;
int err;
assert(txn && txn->client_ctx);
@@ -499,8 +492,8 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn)
* interested in validating it.
*/
error = false;
- if (debug_be)
- gettimeofday(&edit_nb_cfg_start, NULL);
+
+ gettimeofday(&edit_nb_cfg_start, NULL);
nb_candidate_edit_config_changes(
client_ctx->candidate_config,
txn_req->req.set_cfg.cfg_changes,
@@ -516,16 +509,14 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn)
err_buf);
return -1;
}
- if (debug_be) {
- gettimeofday(&edit_nb_cfg_end, NULL);
- edit_nb_cfg_tm = timeval_elapsed(
- edit_nb_cfg_end, edit_nb_cfg_start);
- client_ctx->avg_edit_nb_cfg_tm =
- ((client_ctx->avg_edit_nb_cfg_tm
- * client_ctx->num_edit_nb_cfg)
- + edit_nb_cfg_tm)
- / (client_ctx->num_edit_nb_cfg + 1);
- }
+ gettimeofday(&edit_nb_cfg_end, NULL);
+ edit_nb_cfg_tm = timeval_elapsed(edit_nb_cfg_end,
+ edit_nb_cfg_start);
+ client_ctx->avg_edit_nb_cfg_tm =
+ ((client_ctx->avg_edit_nb_cfg_tm *
+ client_ctx->num_edit_nb_cfg) +
+ edit_nb_cfg_tm) /
+ (client_ctx->num_edit_nb_cfg + 1);
client_ctx->num_edit_nb_cfg++;
}
@@ -540,8 +531,8 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn)
*/
nb_ctx.client = NB_CLIENT_CLI;
nb_ctx.user = (void *)client_ctx->client_params.user_data;
- if (debug_be)
- gettimeofday(&prep_nb_cfg_start, NULL);
+
+ gettimeofday(&prep_nb_cfg_start, NULL);
err = nb_candidate_commit_prepare(nb_ctx, client_ctx->candidate_config,
"MGMTD Backend Txn", &txn->nb_txn,
#ifdef MGMTD_LOCAL_VALIDATIONS_ENABLED
@@ -569,16 +560,13 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn)
"Prepared configs for Txn %llx, %u Batches! successfully!",
(unsigned long long)txn->txn_id,
(uint32_t)num_processed);
- if (debug_be) {
- gettimeofday(&prep_nb_cfg_end, NULL);
- prep_nb_cfg_tm =
- timeval_elapsed(prep_nb_cfg_end, prep_nb_cfg_start);
- client_ctx->avg_prep_nb_cfg_tm =
- ((client_ctx->avg_prep_nb_cfg_tm
- * client_ctx->num_prep_nb_cfg)
- + prep_nb_cfg_tm)
- / (client_ctx->num_prep_nb_cfg + 1);
- }
+
+ gettimeofday(&prep_nb_cfg_end, NULL);
+ prep_nb_cfg_tm = timeval_elapsed(prep_nb_cfg_end, prep_nb_cfg_start);
+ client_ctx->avg_prep_nb_cfg_tm = ((client_ctx->avg_prep_nb_cfg_tm *
+ client_ctx->num_prep_nb_cfg) +
+ prep_nb_cfg_tm) /
+ (client_ctx->num_prep_nb_cfg + 1);
client_ctx->num_prep_nb_cfg++;
FOREACH_BE_TXN_BATCH_IN_LIST (txn, batch) {
@@ -593,12 +581,10 @@ static int mgmt_be_txn_cfg_prepare(struct mgmt_be_txn_ctx *txn)
}
}
- if (debug_be)
- MGMTD_BE_CLIENT_DBG(
- "Avg-nb-edit-duration %lu uSec, nb-prep-duration %lu (avg: %lu) uSec, batch size %u",
- client_ctx->avg_edit_nb_cfg_tm, prep_nb_cfg_tm,
- client_ctx->avg_prep_nb_cfg_tm,
- (uint32_t)num_processed);
+ MGMTD_BE_CLIENT_DBG(
+ "Avg-nb-edit-duration %lu uSec, nb-prep-duration %lu (avg: %lu) uSec, batch size %u",
+ client_ctx->avg_edit_nb_cfg_tm, prep_nb_cfg_tm,
+ client_ctx->avg_prep_nb_cfg_tm, (uint32_t)num_processed);
if (error)
mgmt_be_txn_cfg_abort(txn);
@@ -736,7 +722,6 @@ static int mgmt_be_txn_proc_cfgapply(struct mgmt_be_txn_ctx *txn)
char err_buf[BUFSIZ];
size_t num_processed;
static uint64_t batch_ids[MGMTD_BE_MAX_BATCH_IDS_IN_REQ];
- bool debug_be = mgmt_debug_be_client;
assert(txn && txn->client_ctx);
client_ctx = txn->client_ctx;
@@ -747,20 +732,16 @@ static int mgmt_be_txn_proc_cfgapply(struct mgmt_be_txn_ctx *txn)
/*
* Now apply all the batches we have applied in one go.
*/
- if (debug_be)
- gettimeofday(&apply_nb_cfg_start, NULL);
+ gettimeofday(&apply_nb_cfg_start, NULL);
(void)nb_candidate_commit_apply(txn->nb_txn, true, &txn->nb_txn_id,
err_buf, sizeof(err_buf) - 1);
- if (debug_be) {
- gettimeofday(&apply_nb_cfg_end, NULL);
- apply_nb_cfg_tm =
- timeval_elapsed(apply_nb_cfg_end, apply_nb_cfg_start);
- client_ctx->avg_apply_nb_cfg_tm =
- ((client_ctx->avg_apply_nb_cfg_tm
- * client_ctx->num_apply_nb_cfg)
- + apply_nb_cfg_tm)
- / (client_ctx->num_apply_nb_cfg + 1);
- }
+ gettimeofday(&apply_nb_cfg_end, NULL);
+
+ apply_nb_cfg_tm = timeval_elapsed(apply_nb_cfg_end, apply_nb_cfg_start);
+ client_ctx->avg_apply_nb_cfg_tm = ((client_ctx->avg_apply_nb_cfg_tm *
+ client_ctx->num_apply_nb_cfg) +
+ apply_nb_cfg_tm) /
+ (client_ctx->num_apply_nb_cfg + 1);
client_ctx->num_apply_nb_cfg++;
txn->nb_txn = NULL;
@@ -789,10 +770,8 @@ static int mgmt_be_txn_proc_cfgapply(struct mgmt_be_txn_ctx *txn)
mgmt_be_send_apply_reply(client_ctx, txn->txn_id, batch_ids,
num_processed, true, NULL);
- if (debug_be)
- MGMTD_BE_CLIENT_DBG("Nb-apply-duration %lu (avg: %lu) uSec",
- apply_nb_cfg_tm,
- client_ctx->avg_apply_nb_cfg_tm);
+ MGMTD_BE_CLIENT_DBG("Nb-apply-duration %lu (avg: %lu) uSec",
+ apply_nb_cfg_tm, client_ctx->avg_apply_nb_cfg_tm);
return 0;
}
@@ -903,7 +882,7 @@ static void mgmt_be_client_proc_msgbufs(struct event *thread)
struct mgmt_be_client_ctx *client_ctx = EVENT_ARG(thread);
if (mgmt_msg_procbufs(&client_ctx->mstate, mgmt_be_client_process_msg,
- client_ctx, mgmt_debug_be_client))
+ client_ctx, MGMTD_DBG_BE_CLIENT_CHECK()))
mgmt_be_client_register_event(client_ctx, MGMTD_BE_PROC_MSG);
}
@@ -913,7 +892,7 @@ static void mgmt_be_client_read(struct event *thread)
enum mgmt_msg_rsched rv;
rv = mgmt_msg_read(&client_ctx->mstate, client_ctx->conn_fd,
- mgmt_debug_be_client);
+ MGMTD_DBG_BE_CLIENT_CHECK());
if (rv == MSR_DISCONNECT) {
mgmt_be_server_disconnect(client_ctx, true);
return;
@@ -958,7 +937,7 @@ static int mgmt_be_client_send_msg(struct mgmt_be_client_ctx *client_ctx,
&client_ctx->mstate, be_msg,
mgmtd__be_message__get_packed_size(be_msg),
(size_t(*)(void *, void *))mgmtd__be_message__pack,
- mgmt_debug_be_client);
+ MGMTD_DBG_BE_CLIENT_CHECK());
mgmt_be_client_sched_msg_write(client_ctx);
return rv;
}
@@ -969,7 +948,7 @@ static void mgmt_be_client_write(struct event *thread)
enum mgmt_msg_wsched rv;
rv = mgmt_msg_write(&client_ctx->mstate, client_ctx->conn_fd,
- mgmt_debug_be_client);
+ MGMTD_DBG_BE_CLIENT_CHECK());
if (rv == MSW_SCHED_STREAM)
mgmt_be_client_register_event(client_ctx, MGMTD_BE_CONN_WRITE);
else if (rv == MSW_DISCONNECT)
@@ -1017,7 +996,7 @@ static int mgmt_be_send_subscr_req(struct mgmt_be_client_ctx *client_ctx,
static void mgmt_be_server_connect(struct mgmt_be_client_ctx *client_ctx)
{
- const char *dbgtag = mgmt_debug_be_client ? "BE-client" : NULL;
+ const char *dbgtag = MGMTD_DBG_BE_CLIENT_CHECK() ? "BE-client" : NULL;
assert(client_ctx->conn_fd == -1);
client_ctx->conn_fd = mgmt_msg_connect(
@@ -1097,7 +1076,47 @@ mgmt_be_client_schedule_conn_retry(struct mgmt_be_client_ctx *client_ctx,
&client_ctx->conn_retry_tmr);
}
-extern struct nb_config *running_config;
+DEFPY(debug_mgmt_client_be, debug_mgmt_client_be_cmd,
+ "[no] debug mgmt client backend",
+ NO_STR DEBUG_STR MGMTD_STR
+ "client\n"
+ "backend\n")
+{
+ uint32_t mode = DEBUG_NODE2MODE(vty->node);
+
+ DEBUG_MODE_SET(&mgmt_dbg_be_client, mode, !no);
+
+ return CMD_SUCCESS;
+}
+
+static void mgmt_debug_client_be_set_all(uint32_t flags, bool set)
+{
+ DEBUG_FLAGS_SET(&mgmt_dbg_be_client, flags, set);
+}
+
+static int mgmt_debug_be_client_config_write(struct vty *vty)
+{
+ if (DEBUG_MODE_CHECK(&mgmt_dbg_be_client, DEBUG_MODE_CONF))
+ vty_out(vty, "debug mgmt client frontend\n");
+
+ return 1;
+}
+
+void mgmt_debug_be_client_show_debug(struct vty *vty)
+{
+ if (MGMTD_DBG_BE_CLIENT_CHECK())
+ vty_out(vty, "debug mgmt client backend\n");
+}
+
+static struct debug_callbacks mgmt_dbg_be_client_cbs = {
+ .debug_set_all = mgmt_debug_client_be_set_all};
+
+static struct cmd_node mgmt_dbg_node = {
+ .name = "mgmt backend client",
+ .node = DEBUG_NODE,
+ .prompt = "",
+ .config_write = mgmt_debug_be_client_config_write,
+};
/*
* Initialize library and try connecting with MGMTD.
@@ -1134,6 +1153,16 @@ uintptr_t mgmt_be_client_lib_init(struct mgmt_be_client_params *params,
return (uintptr_t)&mgmt_be_client_ctx;
}
+
+void mgmt_be_client_lib_vty_init(void)
+{
+ debug_init(&mgmt_dbg_be_client_cbs);
+ install_node(&mgmt_dbg_node);
+ install_element(ENABLE_NODE, &debug_mgmt_client_be_cmd);
+ install_element(CONFIG_NODE, &debug_mgmt_client_be_cmd);
+}
+
+
/*
* Subscribe with MGMTD for one or more YANG subtree(s).
*/
diff --git a/lib/mgmt_be_client.h b/lib/mgmt_be_client.h
index db427457a4..d4f2d86fdf 100644
--- a/lib/mgmt_be_client.h
+++ b/lib/mgmt_be_client.h
@@ -192,6 +192,20 @@ extern uintptr_t mgmt_be_client_lib_init(struct mgmt_be_client_params *params,
struct event_loop *master_thread);
/*
+ * Initialize library vty (adds debug support).
+ *
+ * This call should be added to your component when enabling other vty code to
+ * enable mgmtd client debugs. When adding, one needs to also add a their
+ * component in `xref2vtysh.py` as well.
+ */
+extern void mgmt_be_client_lib_vty_init(void);
+
+/*
+ * Print enabled debugging commands.
+ */
+extern void mgmt_debug_be_client_show_debug(struct vty *vty);
+
+/*
* Subscribe with MGMTD for one or more YANG subtree(s).
*
* lib_hndl
diff --git a/lib/mgmt_fe_client.c b/lib/mgmt_fe_client.c
index 7cb9aa3def..b8266bfa82 100644
--- a/lib/mgmt_fe_client.c
+++ b/lib/mgmt_fe_client.c
@@ -6,6 +6,7 @@
*/
#include <zebra.h>
+#include "debug.h"
#include "memory.h"
#include "libfrr.h"
#include "mgmt_fe_client.h"
@@ -15,20 +16,14 @@
#include "stream.h"
#include "sockopt.h"
-#ifdef REDIRECT_DEBUG_TO_STDERR
-#define MGMTD_FE_CLIENT_DBG(fmt, ...) \
- fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__)
-#define MGMTD_FE_CLIENT_ERR(fmt, ...) \
- fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__)
-#else /* REDIRECT_DEBUG_TO_STDERR */
-#define MGMTD_FE_CLIENT_DBG(fmt, ...) \
- do { \
- if (mgmt_debug_fe_client) \
- zlog_debug("%s: " fmt, __func__, ##__VA_ARGS__); \
- } while (0)
-#define MGMTD_FE_CLIENT_ERR(fmt, ...) \
+#include "lib/mgmt_fe_client_clippy.c"
+
+#define MGMTD_FE_CLIENT_DBG(fmt, ...) \
+ DEBUGD(&mgmt_dbg_fe_client, "%s:" fmt, __func__, ##__VA_ARGS__)
+#define MGMTD_FE_CLIENT_ERR(fmt, ...) \
zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__)
-#endif /* REDIRECT_DEBUG_TO_STDERR */
+#define MGMTD_DBG_FE_CLIENT_CHECK() \
+ DEBUG_MODE_CHECK(&mgmt_dbg_fe_client, DEBUG_MODE_ALL)
struct mgmt_fe_client_ctx;
@@ -69,7 +64,7 @@ struct mgmt_fe_client_ctx {
#define FOREACH_SESSION_IN_LIST(client_ctx, session) \
frr_each_safe (mgmt_sessions, &(client_ctx)->client_sessions, (session))
-static bool mgmt_debug_fe_client;
+struct debug mgmt_dbg_fe_client = {0, "Management frontend client operations"};
static struct mgmt_fe_client_ctx mgmt_fe_client_ctx = {
.conn_fd = -1,
@@ -169,7 +164,7 @@ static int mgmt_fe_client_send_msg(struct mgmt_fe_client_ctx *client_ctx,
&client_ctx->mstate, fe_msg,
mgmtd__fe_message__get_packed_size(fe_msg),
(size_t(*)(void *, void *))mgmtd__fe_message__pack,
- mgmt_debug_fe_client);
+ MGMTD_DBG_FE_CLIENT_CHECK());
mgmt_fe_client_sched_msg_write(client_ctx);
return rv;
}
@@ -181,7 +176,7 @@ static void mgmt_fe_client_write(struct event *thread)
client_ctx = (struct mgmt_fe_client_ctx *)EVENT_ARG(thread);
rv = mgmt_msg_write(&client_ctx->mstate, client_ctx->conn_fd,
- mgmt_debug_fe_client);
+ MGMTD_DBG_FE_CLIENT_CHECK());
if (rv == MSW_SCHED_STREAM)
mgmt_fe_client_register_event(client_ctx, MGMTD_FE_CONN_WRITE);
else if (rv == MSW_DISCONNECT)
@@ -679,7 +674,7 @@ static void mgmt_fe_client_proc_msgbufs(struct event *thread)
client_ctx = (struct mgmt_fe_client_ctx *)EVENT_ARG(thread);
if (mgmt_msg_procbufs(&client_ctx->mstate, mgmt_fe_client_process_msg,
- client_ctx, mgmt_debug_fe_client))
+ client_ctx, MGMTD_DBG_FE_CLIENT_CHECK()))
mgmt_fe_client_register_event(client_ctx, MGMTD_FE_PROC_MSG);
}
@@ -691,7 +686,7 @@ static void mgmt_fe_client_read(struct event *thread)
client_ctx = (struct mgmt_fe_client_ctx *)EVENT_ARG(thread);
rv = mgmt_msg_read(&client_ctx->mstate, client_ctx->conn_fd,
- mgmt_debug_fe_client);
+ MGMTD_DBG_FE_CLIENT_CHECK());
if (rv == MSR_DISCONNECT) {
mgmt_fe_server_disconnect(client_ctx, true);
return;
@@ -703,7 +698,7 @@ static void mgmt_fe_client_read(struct event *thread)
static void mgmt_fe_server_connect(struct mgmt_fe_client_ctx *client_ctx)
{
- const char *dbgtag = mgmt_debug_fe_client ? "FE-client" : NULL;
+ const char *dbgtag = MGMTD_DBG_FE_CLIENT_CHECK() ? "FE-client" : NULL;
assert(client_ctx->conn_fd == -1);
client_ctx->conn_fd = mgmt_msg_connect(
@@ -779,6 +774,48 @@ static void mgmt_fe_client_schedule_conn_retry(
&client_ctx->conn_retry_tmr);
}
+DEFPY(debug_mgmt_client_fe, debug_mgmt_client_fe_cmd,
+ "[no] debug mgmt client frontend",
+ NO_STR DEBUG_STR MGMTD_STR
+ "client\n"
+ "frontend\n")
+{
+ uint32_t mode = DEBUG_NODE2MODE(vty->node);
+
+ DEBUG_MODE_SET(&mgmt_dbg_fe_client, mode, !no);
+
+ return CMD_SUCCESS;
+}
+
+static void mgmt_debug_client_fe_set_all(uint32_t flags, bool set)
+{
+ DEBUG_FLAGS_SET(&mgmt_dbg_fe_client, flags, set);
+}
+
+static int mgmt_debug_fe_client_config_write(struct vty *vty)
+{
+ if (DEBUG_MODE_CHECK(&mgmt_dbg_fe_client, DEBUG_MODE_CONF))
+ vty_out(vty, "debug mgmt client frontend\n");
+
+ return CMD_SUCCESS;
+}
+
+void mgmt_debug_fe_client_show_debug(struct vty *vty)
+{
+ if (MGMTD_DBG_FE_CLIENT_CHECK())
+ vty_out(vty, "debug mgmt client frontend\n");
+}
+
+static struct debug_callbacks mgmt_dbg_fe_client_cbs = {
+ .debug_set_all = mgmt_debug_client_fe_set_all};
+
+static struct cmd_node mgmt_dbg_node = {
+ .name = "mgmt client frontend",
+ .node = DEBUG_NODE,
+ .prompt = "",
+ .config_write = mgmt_debug_fe_client_config_write,
+};
+
/*
* Initialize library and try connecting with MGMTD.
*/
@@ -809,6 +846,14 @@ uintptr_t mgmt_fe_client_lib_init(struct mgmt_fe_client_params *params,
return (uintptr_t)&mgmt_fe_client_ctx;
}
+void mgmt_fe_client_lib_vty_init(void)
+{
+ debug_init(&mgmt_dbg_fe_client_cbs);
+ install_node(&mgmt_dbg_node);
+ install_element(ENABLE_NODE, &debug_mgmt_client_fe_cmd);
+ install_element(CONFIG_NODE, &debug_mgmt_client_fe_cmd);
+}
+
/*
* Create a new Session for a Frontend Client connection.
*/
diff --git a/lib/mgmt_fe_client.h b/lib/mgmt_fe_client.h
index aa3371f03c..94867787d9 100644
--- a/lib/mgmt_fe_client.h
+++ b/lib/mgmt_fe_client.h
@@ -134,6 +134,20 @@ extern uintptr_t mgmt_fe_client_lib_init(struct mgmt_fe_client_params *params,
struct event_loop *master_thread);
/*
+ * Initialize library vty (adds debug support).
+ *
+ * This call should be added to your component when enabling other vty code to
+ * enable mgmtd client debugs. When adding, one needs to also add a their
+ * component in `xref2vtysh.py` as well.
+ */
+extern void mgmt_fe_client_lib_vty_init(void);
+
+/*
+ * Print enabled debugging commands.
+ */
+extern void mgmt_debug_fe_client_show_debug(struct vty *vty);
+
+/*
* Create a new Session for a Frontend Client connection.
*
* lib_hndl
diff --git a/lib/subdir.am b/lib/subdir.am
index 7ae82d5a69..c046c3c43c 100644
--- a/lib/subdir.am
+++ b/lib/subdir.am
@@ -179,6 +179,8 @@ clippy_scan += \
lib/filter_cli.c \
lib/if_rmap.c \
lib/log_vty.c \
+ lib/mgmt_be_client.c \
+ lib/mgmt_fe_client.c \
lib/nexthop_group.c \
lib/northbound_cli.c \
lib/plist.c \
diff --git a/lib/vty.c b/lib/vty.c
index c6134fe07f..d6a0dba206 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -125,8 +125,8 @@ static int no_password_check = 0;
/* Integrated configuration file path */
static char integrate_default[] = SYSCONFDIR INTEGRATE_DEFAULT_CONFIG;
-static bool do_log_commands;
-static bool do_log_commands_perm;
+bool vty_log_commands;
+static bool vty_log_commands_perm;
void vty_mgmt_resume_response(struct vty *vty, bool success)
{
@@ -508,7 +508,7 @@ static int vty_command(struct vty *vty, char *buf)
/*
* Log non empty command lines
*/
- if (do_log_commands &&
+ if (vty_log_commands &&
strncmp(buf, "echo PING", strlen("echo PING")) != 0)
cp = buf;
if (cp != NULL) {
@@ -3160,15 +3160,15 @@ DEFPY (log_commands,
"Log all commands\n")
{
if (no) {
- if (do_log_commands_perm) {
+ if (vty_log_commands_perm) {
vty_out(vty,
"Daemon started with permanent logging turned on for commands, ignoring\n");
return CMD_WARNING;
}
- do_log_commands = false;
+ vty_log_commands = false;
} else
- do_log_commands = true;
+ vty_log_commands = true;
return CMD_SUCCESS;
}
@@ -3196,7 +3196,7 @@ static int vty_config_write(struct vty *vty)
vty_endframe(vty, "exit\n");
- if (do_log_commands)
+ if (vty_log_commands)
vty_out(vty, "log commands\n");
vty_out(vty, "!\n");
@@ -3677,8 +3677,8 @@ void vty_init(struct event_loop *master_thread, bool do_command_logging)
install_element(CONFIG_NODE, &log_commands_cmd);
if (do_command_logging) {
- do_log_commands = true;
- do_log_commands_perm = true;
+ vty_log_commands = true;
+ vty_log_commands_perm = true;
}
install_element(ENABLE_NODE, &terminal_monitor_cmd);
diff --git a/lib/vty.h b/lib/vty.h
index 5114238f6a..560748d91d 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -335,6 +335,7 @@ struct vty_arg {
#endif
extern struct nb_config *vty_mgmt_candidate_config;
+extern bool vty_log_commands;
/* Prototypes. */
extern void vty_init(struct event_loop *m, bool do_command_logging);