summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/command.c4
-rw-r--r--lib/command.h4
-rw-r--r--lib/debug.c63
-rw-r--r--lib/debug.h49
-rw-r--r--lib/frrlua.c85
-rw-r--r--lib/frrlua.h3
-rw-r--r--lib/hash.c2
-rw-r--r--lib/libfrr.c3
-rw-r--r--lib/memory.c1
-rw-r--r--lib/memory.h1
-rw-r--r--lib/mgmt_be_client.c30
-rw-r--r--lib/mgmt_be_client.h5
-rw-r--r--lib/mgmt_fe_client.c30
-rw-r--r--lib/mgmt_fe_client.h5
-rw-r--r--lib/northbound.h2
-rw-r--r--lib/northbound_cli.c106
-rw-r--r--lib/northbound_sysrepo.c26
-rw-r--r--lib/termtable.c2
-rw-r--r--lib/termtable.h2
-rw-r--r--lib/vty.c26
-rw-r--r--lib/vty.h7
21 files changed, 228 insertions, 228 deletions
diff --git a/lib/command.c b/lib/command.c
index 51f2529e3e..ac8d60118e 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -17,6 +17,7 @@
#include <lib/version.h>
#include "command.h"
+#include "debug.h"
#include "frrstr.h"
#include "memory.h"
#include "log.h"
@@ -2463,8 +2464,7 @@ 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);
+ debug_status_write(vty);
}
void install_default(enum node_type node)
diff --git a/lib/command.h b/lib/command.h
index cb105c656c..61d09973fd 100644
--- a/lib/command.h
+++ b/lib/command.h
@@ -84,14 +84,12 @@ enum node_type {
CONFIG_NODE, /* Config node. Default mode of config file. */
PREFIX_NODE, /* ip prefix-list node. */
PREFIX_IPV6_NODE, /* ipv6 prefix-list node. */
+ LIB_DEBUG_NODE, /* frrlib debug node. */
DEBUG_NODE, /* Debug node. */
VRF_DEBUG_NODE, /* Vrf Debug node. */
- NORTHBOUND_DEBUG_NODE, /* Northbound Debug node. */
DEBUG_VNC_NODE, /* Debug VNC node. */
RMAP_DEBUG_NODE, /* Route-map debug node */
RESOLVER_DEBUG_NODE, /* Resolver debug node */
- MGMT_BE_DEBUG_NODE, /* mgmtd backend-client debug node */
- MGMT_FE_DEBUG_NODE, /* mgmtd frontend-client debug node */
AAA_NODE, /* AAA node. */
EXTLOG_NODE, /* RFC5424 & co. extended syslog */
KEYCHAIN_NODE, /* Key-chain node. */
diff --git a/lib/debug.c b/lib/debug.c
index 757a47ab99..d25c32d428 100644
--- a/lib/debug.c
+++ b/lib/debug.c
@@ -9,42 +9,75 @@
#include "debug.h"
#include "command.h"
-static struct debug_cb_list_head cb_head;
+static struct debug_list_head debug_head;
-DECLARE_LIST(debug_cb_list, struct debug_callbacks, item);
+DECLARE_LIST(debug_list, struct debug, item);
/* All code in this section should be reentrant and MT-safe */
-DEFUN_NOSH(debug_all, debug_all_cmd, "[no] debug all",
- NO_STR DEBUG_STR "Toggle all debugging output\n")
+DEFUN_NOSH (debug_all,
+ debug_all_cmd,
+ "[no] debug all",
+ NO_STR DEBUG_STR
+ "Toggle all debugging output\n")
{
- struct debug_callbacks *cb;
-
+ struct debug *debug;
bool set = !strmatch(argv[0]->text, "no");
uint32_t mode = DEBUG_NODE2MODE(vty->node);
- frr_each (debug_cb_list, &cb_head, cb)
- cb->debug_set_all(mode, set);
+ frr_each (debug_list, &debug_head, debug) {
+ DEBUG_MODE_SET(debug, mode, set);
+
+ /* If all modes have been turned off, don't preserve options. */
+ if (!DEBUG_MODE_CHECK(debug, DEBUG_MODE_ALL))
+ DEBUG_CLEAR(debug);
+ }
return CMD_SUCCESS;
}
/* ------------------------------------------------------------------------- */
-void debug_init(struct debug_callbacks *cb)
+void debug_status_write(struct vty *vty)
+{
+ struct debug *debug;
+
+ frr_each (debug_list, &debug_head, debug) {
+ if (DEBUG_MODE_CHECK(debug, DEBUG_MODE_ALL))
+ vty_out(vty, " %s debugging is on\n", debug->desc);
+ }
+}
+
+static int config_write_debug(struct vty *vty)
{
- static bool inited = false;
+ struct debug *debug;
- if (!inited) {
- inited = true;
- debug_cb_list_init(&cb_head);
+ frr_each (debug_list, &debug_head, debug) {
+ if (DEBUG_MODE_CHECK(debug, DEBUG_MODE_CONF))
+ vty_out(vty, "%s\n", debug->conf);
}
- debug_cb_list_add_head(&cb_head, cb);
+ return 0;
}
-void debug_init_cli(void)
+static struct cmd_node debug_node = {
+ .name = "debug",
+ .node = LIB_DEBUG_NODE,
+ .prompt = "",
+ .config_write = config_write_debug,
+};
+
+void debug_install(struct debug *debug)
{
+ debug_list_add_tail(&debug_head, debug);
+}
+
+void debug_init(void)
+{
+ debug_list_init(&debug_head);
+
+ install_node(&debug_node);
+
install_element(ENABLE_NODE, &debug_all_cmd);
install_element(CONFIG_NODE, &debug_all_cmd);
}
diff --git a/lib/debug.h b/lib/debug.h
index e9d8a31abd..eee314cff5 100644
--- a/lib/debug.h
+++ b/lib/debug.h
@@ -34,6 +34,7 @@ extern "C" {
#define DEBUG_OPT_NONE 0x00000000
+PREDECL_LIST(debug_list);
/*
* Debugging record.
*
@@ -63,37 +64,18 @@ extern "C" {
* manipulate the flags field in a multithreaded environment results in
* undefined behavior.
*
+ * conf
+ * The configuration string that will be written to the config file.
+ *
* desc
* Human-readable description of this debugging record.
*/
struct debug {
atomic_uint_fast32_t flags;
+ const char *conf;
const char *desc;
-};
-PREDECL_LIST(debug_cb_list);
-/*
- * Callback set for debugging code.
- *
- * debug_set_all
- * Function pointer to call when the user requests that all debugs have a
- * mode set.
- */
-struct debug_callbacks {
- /*
- * Linked list of Callbacks to call
- */
- struct debug_cb_list_item item;
-
- /*
- * flags
- * flags to set on debug flag fields
- *
- * set
- * true: set flags
- * false: unset flags
- */
- void (*debug_set_all)(uint32_t flags, bool set);
+ struct debug_list_item item;
};
/*
@@ -217,22 +199,19 @@ struct debug_callbacks {
#define DEBUGN(name, fmt, ...) DEBUG(notice, name, fmt, ##__VA_ARGS__)
#define DEBUGD(name, fmt, ...) DEBUG(debug, name, fmt, ##__VA_ARGS__)
+/* Show current debugging status. */
+void debug_status_write(struct vty *vty);
+
/*
- * Optional initializer for debugging. Highly recommended.
- *
- * This function installs common debugging commands and allows the caller to
- * specify callbacks to take when these commands are issued, allowing the
- * caller to respond to events such as a request to turn off all debugs.
- *
- * MT-Safe
+ * Register a debug item.
*/
-void debug_init(struct debug_callbacks *cb);
+void debug_install(struct debug *debug);
/*
- * Turn on the cli to turn on/off debugs.
- * Should only be called by libfrr
+ * Initialize debugging.
+ * Should only be called by libfrr.
*/
-void debug_init_cli(void);
+void debug_init(void);
#ifdef __cplusplus
}
diff --git a/lib/frrlua.c b/lib/frrlua.c
index 2cab1a5460..ef081e4bd0 100644
--- a/lib/frrlua.c
+++ b/lib/frrlua.c
@@ -323,7 +323,7 @@ void lua_pushnexthop_group(lua_State *L, const struct nexthop_group *ng)
{
lua_newtable(L);
struct nexthop *nexthop;
- int i = 0;
+ int i = 1;
for (ALL_NEXTHOPS_PTR(ng, nexthop)) {
lua_pushnexthop(L, nexthop);
@@ -382,6 +382,12 @@ static const char *frrlua_log_thunk(lua_State *L)
return lua_tostring(L, 1);
}
+static int frrlua_log_trace(lua_State *L)
+{
+ zlog_debug("%s", frrlua_stackdump(L));
+ return 0;
+}
+
static int frrlua_log_debug(lua_State *L)
{
zlog_debug("%s", frrlua_log_thunk(L));
@@ -413,11 +419,12 @@ static int frrlua_log_error(lua_State *L)
}
static const luaL_Reg log_funcs[] = {
- {"debug", frrlua_log_debug},
- {"info", frrlua_log_info},
- {"notice", frrlua_log_notice},
- {"warn", frrlua_log_warn},
- {"error", frrlua_log_error},
+ { "trace", frrlua_log_trace },
+ { "debug", frrlua_log_debug },
+ { "info", frrlua_log_info },
+ { "notice", frrlua_log_notice },
+ { "warn", frrlua_log_warn },
+ { "error", frrlua_log_error },
{},
};
@@ -432,6 +439,67 @@ void frrlua_export_logging(lua_State *L)
* Debugging.
*/
+void lua_table_dump(lua_State *L, int index, struct buffer *buf, int level)
+{
+ char tmpbuf[64] = {};
+
+ lua_pushnil(L);
+
+ while (lua_next(L, index) != 0) {
+ int key_type;
+ int value_type;
+
+ for (int i = 0; i < level; i++)
+ buffer_putstr(buf, " ");
+
+ key_type = lua_type(L, -2);
+ if (key_type == LUA_TSTRING) {
+ const char *key = lua_tostring(L, -2);
+
+ buffer_putstr(buf, key);
+ buffer_putstr(buf, ": ");
+ } else if (key_type == LUA_TNUMBER) {
+ snprintf(tmpbuf, sizeof(tmpbuf), "%g",
+ lua_tonumber(L, -2));
+ buffer_putstr(buf, tmpbuf);
+ buffer_putstr(buf, ": ");
+ }
+
+ value_type = lua_type(L, -1);
+ switch (value_type) {
+ case LUA_TSTRING:
+ snprintf(tmpbuf, sizeof(tmpbuf), "\"%s\"\n",
+ lua_tostring(L, -1));
+ buffer_putstr(buf, tmpbuf);
+ break;
+ case LUA_TBOOLEAN:
+ snprintf(tmpbuf, sizeof(tmpbuf), "%s\n",
+ lua_toboolean(L, -1) ? "true" : "false");
+ buffer_putstr(buf, tmpbuf);
+ break;
+ case LUA_TNUMBER:
+ snprintf(tmpbuf, sizeof(tmpbuf), "%g\n",
+ lua_tonumber(L, -1));
+ buffer_putstr(buf, tmpbuf);
+ break;
+ case LUA_TTABLE:
+ buffer_putstr(buf, "{\n");
+ lua_table_dump(L, lua_gettop(L), buf, level + 1);
+ for (int i = 0; i < level; i++)
+ buffer_putstr(buf, " ");
+ buffer_putstr(buf, "}\n");
+ break;
+ default:
+ snprintf(tmpbuf, sizeof(tmpbuf), "%s\n",
+ lua_typename(L, value_type));
+ buffer_putstr(buf, tmpbuf);
+ break;
+ }
+
+ lua_pop(L, 1);
+ }
+}
+
char *frrlua_stackdump(lua_State *L)
{
int top = lua_gettop(L);
@@ -458,6 +526,11 @@ char *frrlua_stackdump(lua_State *L)
lua_tonumber(L, i));
buffer_putstr(buf, tmpbuf);
break;
+ case LUA_TTABLE: /* tables */
+ buffer_putstr(buf, "{\n");
+ lua_table_dump(L, i, buf, 1);
+ buffer_putstr(buf, "}\n");
+ break;
default: /* other values */
snprintf(tmpbuf, sizeof(tmpbuf), "%s\n",
lua_typename(L, t));
diff --git a/lib/frrlua.h b/lib/frrlua.h
index dc0f4d9986..e407a4492f 100644
--- a/lib/frrlua.h
+++ b/lib/frrlua.h
@@ -181,6 +181,9 @@ int frrlua_table_get_integer(lua_State *L, const char *key);
*/
void frrlua_export_logging(lua_State *L);
+/* A helper fuction that dumps the Lua stack */
+void lua_table_dump(lua_State *L, int index, struct buffer *buf, int level);
+
/*
* Dump Lua stack to a string.
*
diff --git a/lib/hash.c b/lib/hash.c
index df56243985..edbfeec464 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -444,7 +444,7 @@ DEFUN_NOSH(show_hash_stats,
ttable_colseps(tt, 0, RIGHT, true, '|');
char *table = ttable_dump(tt, "\n");
vty_out(vty, "%s\n", table);
- XFREE(MTYPE_TMP, table);
+ XFREE(MTYPE_TMP_TTABLE, table);
} else
vty_out(vty, "No named hash tables to display.\n");
diff --git a/lib/libfrr.c b/lib/libfrr.c
index 10a9c5d5f2..0a575abac6 100644
--- a/lib/libfrr.c
+++ b/lib/libfrr.c
@@ -809,6 +809,7 @@ struct event_loop *frr_init(void)
vty_init(master, di->log_always);
lib_cmd_init();
+ debug_init();
frr_pthread_init();
#ifdef HAVE_SCRIPTING
@@ -825,8 +826,6 @@ struct event_loop *frr_init(void)
"%s: failed to initialize northbound database",
__func__);
- debug_init_cli();
-
return master;
}
diff --git a/lib/memory.c b/lib/memory.c
index 8fbe5c4093..ac39516edd 100644
--- a/lib/memory.c
+++ b/lib/memory.c
@@ -25,6 +25,7 @@ struct memgroup **mg_insert = &mg_first;
DEFINE_MGROUP(LIB, "libfrr");
DEFINE_MTYPE(LIB, TMP, "Temporary memory");
+DEFINE_MTYPE(LIB, TMP_TTABLE, "Temporary memory for TTABLE");
DEFINE_MTYPE(LIB, BITFIELD, "Bitfield memory");
static inline void mt_count_alloc(struct memtype *mt, size_t size, void *ptr)
diff --git a/lib/memory.h b/lib/memory.h
index 65b99a5fc9..8e8c61da04 100644
--- a/lib/memory.h
+++ b/lib/memory.h
@@ -138,6 +138,7 @@ struct memgroup {
DECLARE_MGROUP(LIB);
DECLARE_MTYPE(TMP);
+DECLARE_MTYPE(TMP_TTABLE);
extern void *qmalloc(struct memtype *mt, size_t size)
diff --git a/lib/mgmt_be_client.c b/lib/mgmt_be_client.c
index 49879f3f53..f03006ad0e 100644
--- a/lib/mgmt_be_client.c
+++ b/lib/mgmt_be_client.c
@@ -116,6 +116,7 @@ struct mgmt_be_client {
frr_each_safe (mgmt_be_txns, &(client_ctx)->txn_head, (txn))
struct debug mgmt_dbg_be_client = {
+ .conf = "debug mgmt client backend",
.desc = "Management backend client operations"
};
@@ -1258,31 +1259,6 @@ DEFPY(debug_mgmt_client_be, debug_mgmt_client_be_cmd,
return CMD_SUCCESS;
}
-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 backend\n");
-
- return 1;
-}
-
-void mgmt_debug_be_client_show_debug(struct vty *vty)
-{
- if (debug_check_be_client())
- 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
-};
-
-static struct cmd_node mgmt_dbg_node = {
- .name = "debug mgmt client backend",
- .node = MGMT_BE_DEBUG_NODE,
- .prompt = "",
- .config_write = mgmt_debug_be_client_config_write,
-};
-
struct mgmt_be_client *mgmt_be_client_create(const char *client_name,
struct mgmt_be_client_cbs *cbs,
uintptr_t user_data,
@@ -1328,8 +1304,8 @@ struct mgmt_be_client *mgmt_be_client_create(const char *client_name,
void mgmt_be_client_lib_vty_init(void)
{
- debug_init(&mgmt_dbg_be_client_cbs);
- install_node(&mgmt_dbg_node);
+ debug_install(&mgmt_dbg_be_client);
+
install_element(ENABLE_NODE, &debug_mgmt_client_be_cmd);
install_element(CONFIG_NODE, &debug_mgmt_client_be_cmd);
}
diff --git a/lib/mgmt_be_client.h b/lib/mgmt_be_client.h
index 7ad0589bdb..6ed8c2a39f 100644
--- a/lib/mgmt_be_client.h
+++ b/lib/mgmt_be_client.h
@@ -122,11 +122,6 @@ mgmt_be_client_create(const char *name, struct mgmt_be_client_cbs *cbs,
extern void mgmt_be_client_lib_vty_init(void);
/*
- * Print enabled debugging commands.
- */
-extern void mgmt_debug_be_client_show_debug(struct vty *vty);
-
-/*
* [Un]-subscribe with MGMTD for one or more YANG subtree(s).
*
* client
diff --git a/lib/mgmt_fe_client.c b/lib/mgmt_fe_client.c
index 8cfb025f72..ced2f2e454 100644
--- a/lib/mgmt_fe_client.c
+++ b/lib/mgmt_fe_client.c
@@ -49,6 +49,7 @@ struct mgmt_fe_client {
frr_each_safe (mgmt_sessions, &(client)->sessions, (session))
struct debug mgmt_dbg_fe_client = {
+ .conf = "debug mgmt client frontend",
.desc = "Management frontend client operations"
};
@@ -805,31 +806,6 @@ DEFPY(debug_mgmt_client_fe, debug_mgmt_client_fe_cmd,
return CMD_SUCCESS;
}
-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 (debug_check_fe_client())
- 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
-};
-
-static struct cmd_node mgmt_dbg_node = {
- .name = "debug mgmt client frontend",
- .node = MGMT_FE_DEBUG_NODE,
- .prompt = "",
- .config_write = mgmt_debug_fe_client_config_write,
-};
-
/*
* Initialize library and try connecting with MGMTD.
*/
@@ -870,8 +846,8 @@ struct mgmt_fe_client *mgmt_fe_client_create(const char *client_name,
void mgmt_fe_client_lib_vty_init(void)
{
- debug_init(&mgmt_dbg_fe_client_cbs);
- install_node(&mgmt_dbg_node);
+ debug_install(&mgmt_dbg_fe_client);
+
install_element(ENABLE_NODE, &debug_mgmt_client_fe_cmd);
install_element(CONFIG_NODE, &debug_mgmt_client_fe_cmd);
}
diff --git a/lib/mgmt_fe_client.h b/lib/mgmt_fe_client.h
index 20c87044a5..2b5a25fa0d 100644
--- a/lib/mgmt_fe_client.h
+++ b/lib/mgmt_fe_client.h
@@ -179,11 +179,6 @@ mgmt_fe_client_create(const char *client_name, struct mgmt_fe_client_cbs *cbs,
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/northbound.h b/lib/northbound.h
index 34d17a587c..da5f5be1ee 100644
--- a/lib/northbound.h
+++ b/lib/northbound.h
@@ -799,8 +799,6 @@ DECLARE_HOOK(nb_notification_send, (const char *xpath, struct list *arguments),
(xpath, arguments));
DECLARE_HOOK(nb_notification_tree_send,
(const char *xpath, const struct lyd_node *tree), (xpath, tree));
-DECLARE_HOOK(nb_client_debug_config_write, (struct vty *vty), (vty));
-DECLARE_HOOK(nb_client_debug_set_all, (uint32_t flags, bool set), (flags, set));
/* Northbound debugging records */
extern struct debug nb_dbg_cbs_config;
diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c
index 4f962cda5c..f9794bee3c 100644
--- a/lib/northbound_cli.c
+++ b/lib/northbound_cli.c
@@ -22,13 +22,19 @@
#include "northbound_db.h"
#include "lib/northbound_cli_clippy.c"
-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"};
+struct debug nb_dbg_cbs_config = { 0, "debug northbound callbacks configuration",
+ "Northbound callbacks: configuration" };
+struct debug nb_dbg_cbs_state = { 0, "debug northbound callbacks state",
+ "Northbound callbacks: state" };
+struct debug nb_dbg_cbs_rpc = { 0, "debug northbound callbacks rpc",
+ "Northbound callbacks: RPCs" };
+struct debug nb_dbg_cbs_notify = { 0, "debug northbound callbacks notify",
+ "Northbound callbacks: notifications" };
+struct debug nb_dbg_notif = { 0, "debug northbound notifications",
+ "Northbound notifications" };
+struct debug nb_dbg_events = { 0, "debug northbound events",
+ "Northbound events" };
+struct debug nb_dbg_libyang = { 0, "debug northbound libyang", "libyang" };
struct nb_config *vty_shared_candidate_config;
static struct event_loop *master;
@@ -1380,7 +1386,7 @@ static int nb_cli_show_transactions(struct vty *vty)
table = ttable_dump(tt, "\n");
vty_out(vty, "%s\n", table);
- XFREE(MTYPE_TMP, table);
+ XFREE(MTYPE_TMP_TTABLE, table);
} else
vty_out(vty, "No configuration transactions to display.\n\n");
@@ -1661,7 +1667,7 @@ DEFPY (show_yang_module,
table = ttable_dump(tt, "\n");
vty_out(vty, "%s\n", table);
- XFREE(MTYPE_TMP, table);
+ XFREE(MTYPE_TMP_TTABLE, table);
} else
vty_out(vty, "No YANG modules to display.\n\n");
@@ -1771,7 +1777,7 @@ DEFPY (show_yang_module_translator,
table = ttable_dump(tt, "\n");
vty_out(vty, "%s\n", table);
- XFREE(MTYPE_TMP, table);
+ XFREE(MTYPE_TMP_TTABLE, table);
} else
vty_out(vty, "No YANG module translators to display.\n\n");
@@ -1842,37 +1848,6 @@ 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_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",
-};
-
-DEFINE_HOOK(nb_client_debug_set_all, (uint32_t flags, bool set), (flags, set));
-
-static void nb_debug_set_all(uint32_t flags, bool set)
-{
- for (unsigned int i = 0; i < array_size(nb_debugs); i++) {
- DEBUG_FLAGS_SET(nb_debugs[i], flags, set);
-
- /* If all modes have been turned off, don't preserve options. */
- if (!DEBUG_MODE_CHECK(nb_debugs[i], DEBUG_MODE_ALL))
- DEBUG_CLEAR(nb_debugs[i]);
- }
-
- hook_call(nb_client_debug_set_all, flags, set);
-}
-
DEFPY (debug_nb,
debug_nb_cmd,
"[no] debug northbound\
@@ -1895,8 +1870,13 @@ DEFPY (debug_nb,
"libyang debugging\n")
{
uint32_t mode = DEBUG_NODE2MODE(vty->node);
+ bool all = false;
+
+ /* no specific debug --> act on all of them */
+ if (strmatch(argv[argc - 1]->text, "northbound"))
+ all = true;
- if (cbs) {
+ if (cbs || all) {
bool none = (!cbs_cfg && !cbs_state && !cbs_rpc && !cbs_notify);
if (none || cbs_cfg)
@@ -1908,45 +1888,18 @@ DEFPY (debug_nb,
if (none || cbs_notify)
DEBUG_MODE_SET(&nb_dbg_cbs_notify, mode, !no);
}
- if (notifications)
+ if (notifications || all)
DEBUG_MODE_SET(&nb_dbg_notif, mode, !no);
- if (events)
+ if (events || all)
DEBUG_MODE_SET(&nb_dbg_events, mode, !no);
- if (libyang) {
+ if (libyang || all) {
DEBUG_MODE_SET(&nb_dbg_libyang, mode, !no);
yang_debugging_set(!no);
}
- /* no specific debug --> act on all of them */
- if (strmatch(argv[argc - 1]->text, "northbound")) {
- nb_debug_set_all(mode, !no);
- yang_debugging_set(!no);
- }
-
return CMD_SUCCESS;
}
-DEFINE_HOOK(nb_client_debug_config_write, (struct vty *vty), (vty));
-
-static int nb_debug_config_write(struct vty *vty)
-{
- for (unsigned int i = 0; i < array_size(nb_debugs); i++)
- if (DEBUG_MODE_CHECK(nb_debugs[i], DEBUG_MODE_CONF))
- vty_out(vty, "%s\n", nb_debugs_conflines[i]);
-
- hook_call(nb_client_debug_config_write, vty);
-
- return 1;
-}
-
-static struct debug_callbacks nb_dbg_cbs = {.debug_set_all = nb_debug_set_all};
-static struct cmd_node nb_debug_node = {
- .name = "northbound debug",
- .node = NORTHBOUND_DEBUG_NODE,
- .prompt = "",
- .config_write = nb_debug_config_write,
-};
-
void nb_cli_install_default(int node)
{
_install_element(node, &show_config_candidate_section_cmd);
@@ -2007,9 +1960,14 @@ void nb_cli_init(struct event_loop *tm)
/* Initialize the shared candidate configuration. */
vty_shared_candidate_config = nb_config_new(NULL);
- debug_init(&nb_dbg_cbs);
+ debug_install(&nb_dbg_cbs_config);
+ debug_install(&nb_dbg_cbs_state);
+ debug_install(&nb_dbg_cbs_rpc);
+ debug_install(&nb_dbg_cbs_notify);
+ debug_install(&nb_dbg_notif);
+ debug_install(&nb_dbg_events);
+ debug_install(&nb_dbg_libyang);
- install_node(&nb_debug_node);
install_element(ENABLE_NODE, &debug_nb_cmd);
install_element(CONFIG_NODE, &debug_nb_cmd);
diff --git a/lib/northbound_sysrepo.c b/lib/northbound_sysrepo.c
index 0ec7610a9a..1f4d036cc2 100644
--- a/lib/northbound_sysrepo.c
+++ b/lib/northbound_sysrepo.c
@@ -19,7 +19,9 @@
#include <sysrepo/values.h>
#include <sysrepo/xpath.h>
-static struct debug nb_dbg_client_sysrepo = {0, "Northbound client: Sysrepo"};
+static struct debug nb_dbg_client_sysrepo = { 0,
+ "debug northbound client sysrepo",
+ "Northbound client: Sysrepo" };
static struct event_loop *master;
static sr_session_ctx_t *session;
@@ -553,29 +555,9 @@ DEFUN (debug_nb_sr,
return CMD_SUCCESS;
}
-static int frr_sr_debug_config_write(struct vty *vty)
-{
- if (DEBUG_MODE_CHECK(&nb_dbg_client_sysrepo, DEBUG_MODE_CONF))
- vty_out(vty, "debug northbound client sysrepo\n");
-
- return 0;
-}
-
-static int frr_sr_debug_set_all(uint32_t flags, bool set)
-{
- DEBUG_FLAGS_SET(&nb_dbg_client_sysrepo, flags, set);
-
- /* If all modes have been turned off, don't preserve options. */
- if (!DEBUG_MODE_CHECK(&nb_dbg_client_sysrepo, DEBUG_MODE_ALL))
- DEBUG_CLEAR(&nb_dbg_client_sysrepo);
-
- return 0;
-}
-
static void frr_sr_cli_init(void)
{
- hook_register(nb_client_debug_config_write, frr_sr_debug_config_write);
- hook_register(nb_client_debug_set_all, frr_sr_debug_set_all);
+ debug_install(&nb_dbg_client_sysrepo);
install_element(ENABLE_NODE, &debug_nb_sr_cmd);
install_element(CONFIG_NODE, &debug_nb_sr_cmd);
diff --git a/lib/termtable.c b/lib/termtable.c
index 88cc25bf68..ce19701389 100644
--- a/lib/termtable.c
+++ b/lib/termtable.c
@@ -363,7 +363,7 @@ char *ttable_dump(struct ttable *tt, const char *newline)
memcpy(&right[0], newline, nl_len);
/* allocate print buffer */
- buf = XCALLOC(MTYPE_TMP, width * (nlines + 1) + 1);
+ buf = XCALLOC(MTYPE_TMP_TTABLE, width * (nlines + 1) + 1);
pos = 0;
if (tt->style.border.top_on) {
diff --git a/lib/termtable.h b/lib/termtable.h
index 0782c82abd..d284c4f376 100644
--- a/lib/termtable.h
+++ b/lib/termtable.h
@@ -270,7 +270,7 @@ void ttable_rowseps(struct ttable *tt, unsigned int row,
*
* Caller must free this string after use with
*
- * XFREE (MTYPE_TMP, str);
+ * XFREE (MTYPE_TMP_TTABLE, str);
*
* @param tt the table to dump
* @param newline the desired newline sequence to use, null terminated.
diff --git a/lib/vty.c b/lib/vty.c
index 0a4a3d2b86..256a3bb3f5 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -345,8 +345,17 @@ int vty_out(struct vty *vty, const char *format, ...)
case VTY_SHELL_SERV:
case VTY_FILE:
default:
+ vty->vty_buf_size_accumulated += strlen(filtered);
/* print without crlf replacement */
buffer_put(vty->obuf, (uint8_t *)filtered, strlen(filtered));
+ /* For every chunk of memory, we invoke vtysh_flush where we
+ * put the data of collective vty->obuf Linked List items on the
+ * socket and free the vty->obuf data.
+ */
+ if (vty->vty_buf_size_accumulated >= VTY_MAX_INTERMEDIATE_FLUSH) {
+ vty->vty_buf_size_accumulated = 0;
+ vtysh_flush(vty);
+ }
break;
}
@@ -2118,6 +2127,8 @@ static void vtysh_accept(struct event *thread)
int client_len;
struct sockaddr_un client;
struct vty *vty;
+ int ret = 0;
+ uint32_t sndbufsize = VTY_SEND_BUF_MAX;
vty_event_serv(VTYSH_SERV, vtyserv);
@@ -2141,6 +2152,20 @@ static void vtysh_accept(struct event *thread)
close(sock);
return;
}
+
+ /*
+ * Increasing the SEND socket buffer size so that the socket can hold
+ * before sending it to VTY shell.
+ */
+ ret = setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&sndbufsize,
+ sizeof(sndbufsize));
+ if (ret < 0) {
+ flog_err(EC_LIB_SOCKET,
+ "Cannot set socket %d send buffer size, %s", sock,
+ safe_strerror(errno));
+ close(sock);
+ return;
+ }
set_cloexec(sock);
#ifdef VTYSH_DEBUG
@@ -2227,6 +2252,7 @@ static int vtysh_flush(struct vty *vty)
vty_close(vty);
return -1;
case BUFFER_EMPTY:
+ vty->vty_buf_size_accumulated = 0;
break;
}
return 0;
diff --git a/lib/vty.h b/lib/vty.h
index c336a816cc..e511e8e79a 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -236,6 +236,7 @@ struct vty {
uintptr_t mgmt_req_pending_data;
bool mgmt_locked_candidate_ds;
bool mgmt_locked_running_ds;
+ uint64_t vty_buf_size_accumulated;
};
static inline void vty_push_context(struct vty *vty, int node, uint64_t id)
@@ -338,6 +339,12 @@ struct vty_arg {
/* Vty read buffer size. */
#define VTY_READ_BUFSIZ 512
+/* Vty max send buffer size */
+#define VTY_SEND_BUF_MAX 16777216
+
+/* Vty flush intermediate size */
+#define VTY_MAX_INTERMEDIATE_FLUSH 131072
+
/* Directory separator. */
#ifndef DIRECTORY_SEP
#define DIRECTORY_SEP '/'