mirror of
				https://git.proxmox.com/git/mirror_frr
				synced 2025-10-31 07:10:00 +00:00 
			
		
		
		
	mgmtd: fully implement debug flags for mgmtd and clients
Signed-off-by: Christian Hopps <chopps@labn.net>
This commit is contained in:
		
							parent
							
								
									13c426150f
								
							
						
					
					
						commit
						cfa0facbf9
					
				| @ -364,3 +364,46 @@ MGMT Show commands | ||||
| .. clicmd:: show mgmt commit-history | ||||
| 
 | ||||
|     This command dumps details of upto last 10 commits handled by MGMTd. | ||||
| 
 | ||||
| 
 | ||||
| MGMT Daemon debug commands | ||||
| ========================== | ||||
| 
 | ||||
| The following debug commands enable debugging within the management daemon: | ||||
| 
 | ||||
| .. clicmd:: [no] debug mgmt backend | ||||
| 
 | ||||
|    Enable[/Disable] debugging messages related to backend operations within the | ||||
|    management daemon. | ||||
| 
 | ||||
| .. clicmd:: [no] debug mgmt datastore | ||||
| 
 | ||||
|    Enable[/Disable] debugging messages related to YANG datastore operations | ||||
|    within the management daemon. | ||||
| 
 | ||||
| .. clicmd:: [no] debug mgmt frontend | ||||
| 
 | ||||
|    Enable[/Disable] debugging messages related to frontend operations within the | ||||
|    management daemon. | ||||
| 
 | ||||
| .. clicmd:: [no] debug mgmt transaction | ||||
| 
 | ||||
|    Enable[/Disable] debugging messages related to transactions within the | ||||
|    management daemon. | ||||
| 
 | ||||
| 
 | ||||
| MGMT Client debug commands | ||||
| ========================== | ||||
| 
 | ||||
| The following debug commands enable debugging within the management front and | ||||
| backend clients: | ||||
| 
 | ||||
| .. clicmd:: [no] debug mgmt client backend | ||||
| 
 | ||||
|    Enable[/Disable] debugging messages related to backend operations inside the | ||||
|    backend mgmtd clients. | ||||
| 
 | ||||
| .. clicmd:: [no] debug mgmt client frontend | ||||
| 
 | ||||
|    Enable[/Disable] debugging messages related to frontend operations inside the | ||||
|    frontend mgmtd clients. | ||||
|  | ||||
| @ -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" | ||||
| @ -2438,6 +2440,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) | ||||
|  | ||||
| @ -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 | ||||
| #include "lib/mgmt_be_client_clippy.c" | ||||
| 
 | ||||
| #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 */ | ||||
| #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). | ||||
|  */ | ||||
|  | ||||
| @ -191,6 +191,20 @@ mgmt_be_client_name2id(const char *name) | ||||
| 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). | ||||
|  * | ||||
|  | ||||
| @ -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. | ||||
|  */ | ||||
|  | ||||
| @ -133,6 +133,20 @@ struct mgmt_fe_client_params { | ||||
| 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. | ||||
|  * | ||||
|  | ||||
| @ -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 \ | ||||
|  | ||||
| @ -7,6 +7,7 @@ | ||||
|  */ | ||||
| 
 | ||||
| #include <zebra.h> | ||||
| #include "debug.h" | ||||
| #include "mgmtd/mgmt.h" | ||||
| #include "mgmtd/mgmt_be_server.h" | ||||
| #include "mgmtd/mgmt_be_adapter.h" | ||||
| @ -16,10 +17,10 @@ | ||||
| #include "mgmtd/mgmt_history.h" | ||||
| #include "mgmtd/mgmt_memory.h" | ||||
| 
 | ||||
| bool mgmt_debug_be; | ||||
| bool mgmt_debug_fe; | ||||
| bool mgmt_debug_ds; | ||||
| bool mgmt_debug_txn; | ||||
| struct debug mgmt_debug_be = {.desc = "Management backend adapater"}; | ||||
| struct debug mgmt_debug_ds = {.desc = "Management datastore"}; | ||||
| struct debug mgmt_debug_fe = {.desc = "Management frontend adapater"}; | ||||
| struct debug mgmt_debug_txn = {.desc = "Management transaction"}; | ||||
| 
 | ||||
| /* MGMTD process wide configuration.  */ | ||||
| static struct mgmt_master mgmt_master; | ||||
|  | ||||
							
								
								
									
										14
									
								
								mgmtd/mgmt.h
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								mgmtd/mgmt.h
									
									
									
									
									
								
							| @ -9,6 +9,7 @@ | ||||
| #ifndef _FRR_MGMTD_H | ||||
| #define _FRR_MGMTD_H | ||||
| 
 | ||||
| #include "debug.h" | ||||
| #include "vrf.h" | ||||
| #include "defaults.h" | ||||
| #include "stream.h" | ||||
| @ -23,10 +24,15 @@ | ||||
| #define MGMTD_SOCKET_BUF_SIZE 65535 | ||||
| #define MGMTD_MAX_COMMIT_LIST 10 | ||||
| 
 | ||||
| extern bool mgmt_debug_be; | ||||
| extern bool mgmt_debug_fe; | ||||
| extern bool mgmt_debug_ds; | ||||
| extern bool mgmt_debug_txn; | ||||
| extern struct debug mgmt_debug_be; | ||||
| extern struct debug mgmt_debug_ds; | ||||
| extern struct debug mgmt_debug_fe; | ||||
| extern struct debug mgmt_debug_txn; | ||||
| 
 | ||||
| #define MGMT_DEBUG_BE_CHECK() DEBUG_MODE_CHECK(&mgmt_debug_be, DEBUG_MODE_ALL) | ||||
| #define MGMT_DEBUG_DS_CHECK() DEBUG_MODE_CHECK(&mgmt_debug_ds, DEBUG_MODE_ALL) | ||||
| #define MGMT_DEBUG_FE_CHECK() DEBUG_MODE_CHECK(&mgmt_debug_fe, DEBUG_MODE_ALL) | ||||
| #define MGMT_DEBUG_TXN_CHECK() DEBUG_MODE_CHECK(&mgmt_debug_tx, DEBUG_MODE_ALL) | ||||
| 
 | ||||
| struct mgmt_txn_ctx; | ||||
| 
 | ||||
|  | ||||
| @ -18,20 +18,10 @@ | ||||
| #include "mgmt_be_client.h" | ||||
| #include "mgmtd/mgmt_be_adapter.h" | ||||
| 
 | ||||
| #ifdef REDIRECT_DEBUG_TO_STDERR | ||||
| #define MGMTD_BE_ADAPTER_DBG(fmt, ...)                                        \ | ||||
| 	fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__) | ||||
| #define MGMTD_BE_ADAPTER_ERR(fmt, ...)                                        \ | ||||
| 	fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__) | ||||
| #else /* REDIRECT_DEBUG_TO_STDERR */ | ||||
| #define MGMTD_BE_ADAPTER_DBG(fmt, ...)                                        \ | ||||
| 	do {                                                                  \ | ||||
| 		if (mgmt_debug_be)                                            \ | ||||
| 			zlog_debug("%s: " fmt, __func__, ##__VA_ARGS__);      \ | ||||
| 	} while (0) | ||||
| #define MGMTD_BE_ADAPTER_DBG(fmt, ...)                                         \ | ||||
| 	DEBUGD(&mgmt_debug_be, "%s:" fmt, __func__, ##__VA_ARGS__) | ||||
| #define MGMTD_BE_ADAPTER_ERR(fmt, ...)                                        \ | ||||
| 	zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__) | ||||
| #endif /* REDIRECT_DEBUG_TO_STDERR */ | ||||
| 
 | ||||
| #define FOREACH_ADAPTER_IN_LIST(adapter)                                       \ | ||||
| 	frr_each_safe (mgmt_be_adapters, &mgmt_be_adapters, (adapter)) | ||||
| @ -521,7 +511,7 @@ static int mgmt_be_adapter_send_msg(struct mgmt_be_client_adapter *adapter, | ||||
| 		&adapter->mstate, be_msg, | ||||
| 		mgmtd__be_message__get_packed_size(be_msg), | ||||
| 		(size_t(*)(void *, void *))mgmtd__be_message__pack, | ||||
| 		mgmt_debug_be); | ||||
| 		MGMT_DEBUG_BE_CHECK()); | ||||
| 	mgmt_be_adapter_sched_msg_write(adapter); | ||||
| 	return rv; | ||||
| } | ||||
| @ -619,7 +609,7 @@ static void mgmt_be_adapter_proc_msgbufs(struct event *thread) | ||||
| 	struct mgmt_be_client_adapter *adapter = EVENT_ARG(thread); | ||||
| 
 | ||||
| 	if (mgmt_msg_procbufs(&adapter->mstate, mgmt_be_adapter_process_msg, | ||||
| 			      adapter, mgmt_debug_be)) | ||||
| 			      adapter, MGMT_DEBUG_BE_CHECK())) | ||||
| 		mgmt_be_adapter_register_event(adapter, MGMTD_BE_PROC_MSG); | ||||
| } | ||||
| 
 | ||||
| @ -630,7 +620,8 @@ static void mgmt_be_adapter_read(struct event *thread) | ||||
| 
 | ||||
| 	adapter = (struct mgmt_be_client_adapter *)EVENT_ARG(thread); | ||||
| 
 | ||||
| 	rv = mgmt_msg_read(&adapter->mstate, adapter->conn_fd, mgmt_debug_be); | ||||
| 	rv = mgmt_msg_read(&adapter->mstate, adapter->conn_fd, | ||||
| 			   MGMT_DEBUG_BE_CHECK()); | ||||
| 	if (rv == MSR_DISCONNECT) { | ||||
| 		mgmt_be_adapter_disconnect(adapter); | ||||
| 		return; | ||||
| @ -645,7 +636,8 @@ static void mgmt_be_adapter_write(struct event *thread) | ||||
| 	struct mgmt_be_client_adapter *adapter = EVENT_ARG(thread); | ||||
| 	enum mgmt_msg_wsched rv; | ||||
| 
 | ||||
| 	rv = mgmt_msg_write(&adapter->mstate, adapter->conn_fd, mgmt_debug_be); | ||||
| 	rv = mgmt_msg_write(&adapter->mstate, adapter->conn_fd, | ||||
| 			    MGMT_DEBUG_BE_CHECK()); | ||||
| 	if (rv == MSW_SCHED_STREAM) | ||||
| 		mgmt_be_adapter_register_event(adapter, MGMTD_BE_CONN_WRITE); | ||||
| 	else if (rv == MSW_DISCONNECT) | ||||
|  | ||||
| @ -13,20 +13,10 @@ | ||||
| #include "mgmtd/mgmt_be_server.h" | ||||
| #include "mgmtd/mgmt_be_adapter.h" | ||||
| 
 | ||||
| #ifdef REDIRECT_DEBUG_TO_STDERR | ||||
| #define MGMTD_BE_SRVR_DBG(fmt, ...)                                         \ | ||||
| 	fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__) | ||||
| #define MGMTD_BE_SRVR_ERR(fmt, ...)                                         \ | ||||
| 	fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__) | ||||
| #else /* REDIRECT_DEBUG_TO_STDERR */ | ||||
| #define MGMTD_BE_SRVR_DBG(fmt, ...)                                            \ | ||||
| 	do {                                                                   \ | ||||
| 		if (mgmt_debug_be)                                             \ | ||||
| 			zlog_debug("%s: " fmt, __func__, ##__VA_ARGS__);       \ | ||||
| 	} while (0) | ||||
| 	DEBUGD(&mgmt_debug_be, "%s:" fmt, __func__, ##__VA_ARGS__) | ||||
| #define MGMTD_BE_SRVR_ERR(fmt, ...)                                         \ | ||||
| 	zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__) | ||||
| #endif /* REDIRECT_DEBUG_TO_STDERR */ | ||||
| 
 | ||||
| static int mgmt_be_listen_fd = -1; | ||||
| static struct event_loop *mgmt_be_listen_tm; | ||||
|  | ||||
| @ -15,20 +15,10 @@ | ||||
| #include "mgmtd/mgmt_txn.h" | ||||
| #include "libyang/libyang.h" | ||||
| 
 | ||||
| #ifdef REDIRECT_DEBUG_TO_STDERR | ||||
| #define MGMTD_DS_DBG(fmt, ...)                                                 \ | ||||
| 	fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__) | ||||
| #define MGMTD_DS_ERR(fmt, ...)                                                 \ | ||||
| 	fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__) | ||||
| #else /* REDIRECT_DEBUG_TO_STDERR */ | ||||
| #define MGMTD_DS_DBG(fmt, ...)                                                 \ | ||||
| 	do {                                                                   \ | ||||
| 		if (mgmt_debug_ds)                                             \ | ||||
| 			zlog_debug("%s: " fmt, __func__, ##__VA_ARGS__);       \ | ||||
| 	} while (0) | ||||
| 	DEBUGD(&mgmt_debug_ds, "%s:" fmt, __func__, ##__VA_ARGS__) | ||||
| #define MGMTD_DS_ERR(fmt, ...)                                                 \ | ||||
| 	zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__) | ||||
| #endif /* REDIRECT_DEBUG_TO_STDERR */ | ||||
| 
 | ||||
| struct mgmt_ds_ctx { | ||||
| 	Mgmtd__DatastoreId ds_id; | ||||
|  | ||||
| @ -19,20 +19,10 @@ | ||||
| #include "mgmtd/mgmt_memory.h" | ||||
| #include "mgmtd/mgmt_fe_adapter.h" | ||||
| 
 | ||||
| #ifdef REDIRECT_DEBUG_TO_STDERR | ||||
| #define MGMTD_FE_ADAPTER_DBG(fmt, ...)                                       \ | ||||
| 	fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__) | ||||
| #define MGMTD_FE_ADAPTER_ERR(fmt, ...)                                       \ | ||||
| 	fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__) | ||||
| #else /* REDIRECT_DEBUG_TO_STDERR */ | ||||
| #define MGMTD_FE_ADAPTER_DBG(fmt, ...)                                       \ | ||||
| 	do {                                                                 \ | ||||
| 		if (mgmt_debug_fe)                                           \ | ||||
| 			zlog_debug("%s: " fmt, __func__, ##__VA_ARGS__);     \ | ||||
| 	} while (0) | ||||
| #define MGMTD_FE_ADAPTER_DBG(fmt, ...)                                         \ | ||||
| 	DEBUGD(&mgmt_debug_fe, "%s:" fmt, __func__, ##__VA_ARGS__) | ||||
| #define MGMTD_FE_ADAPTER_ERR(fmt, ...)                                       \ | ||||
| 	zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__) | ||||
| #endif /* REDIRECT_DEBUG_TO_STDERR */ | ||||
| 
 | ||||
| #define FOREACH_ADAPTER_IN_LIST(adapter)                                       \ | ||||
| 	frr_each_safe (mgmt_fe_adapters, &mgmt_fe_adapters, (adapter)) | ||||
| @ -399,7 +389,7 @@ mgmt_fe_adapter_send_msg(struct mgmt_fe_client_adapter *adapter, | ||||
| 		&adapter->mstate, fe_msg, | ||||
| 		mgmtd__fe_message__get_packed_size(fe_msg), | ||||
| 		(size_t(*)(void *, void *))mgmtd__fe_message__pack, | ||||
| 		mgmt_debug_fe); | ||||
| 		MGMT_DEBUG_FE_CHECK()); | ||||
| 	mgmt_fe_adapter_sched_msg_write(adapter); | ||||
| 	return rv; | ||||
| } | ||||
| @ -1439,7 +1429,7 @@ static void mgmt_fe_adapter_proc_msgbufs(struct event *thread) | ||||
| 	struct mgmt_fe_client_adapter *adapter = EVENT_ARG(thread); | ||||
| 
 | ||||
| 	if (mgmt_msg_procbufs(&adapter->mstate, mgmt_fe_adapter_process_msg, | ||||
| 			      adapter, mgmt_debug_fe)) | ||||
| 			      adapter, MGMT_DEBUG_FE_CHECK())) | ||||
| 		mgmt_fe_adapter_register_event(adapter, MGMTD_FE_PROC_MSG); | ||||
| } | ||||
| 
 | ||||
| @ -1448,7 +1438,8 @@ static void mgmt_fe_adapter_read(struct event *thread) | ||||
| 	struct mgmt_fe_client_adapter *adapter = EVENT_ARG(thread); | ||||
| 	enum mgmt_msg_rsched rv; | ||||
| 
 | ||||
| 	rv = mgmt_msg_read(&adapter->mstate, adapter->conn_fd, mgmt_debug_fe); | ||||
| 	rv = mgmt_msg_read(&adapter->mstate, adapter->conn_fd, | ||||
| 			   MGMT_DEBUG_FE_CHECK()); | ||||
| 	if (rv == MSR_DISCONNECT) { | ||||
| 		mgmt_fe_adapter_disconnect(adapter); | ||||
| 		return; | ||||
| @ -1463,7 +1454,8 @@ static void mgmt_fe_adapter_write(struct event *thread) | ||||
| 	struct mgmt_fe_client_adapter *adapter = EVENT_ARG(thread); | ||||
| 	enum mgmt_msg_wsched rv; | ||||
| 
 | ||||
| 	rv = mgmt_msg_write(&adapter->mstate, adapter->conn_fd, mgmt_debug_fe); | ||||
| 	rv = mgmt_msg_write(&adapter->mstate, adapter->conn_fd, | ||||
| 			    MGMT_DEBUG_FE_CHECK()); | ||||
| 	if (rv == MSW_SCHED_STREAM) | ||||
| 		mgmt_fe_adapter_register_event(adapter, MGMTD_FE_CONN_WRITE); | ||||
| 	else if (rv == MSW_DISCONNECT) | ||||
|  | ||||
| @ -13,20 +13,10 @@ | ||||
| #include "mgmtd/mgmt_fe_server.h" | ||||
| #include "mgmtd/mgmt_fe_adapter.h" | ||||
| 
 | ||||
| #ifdef REDIRECT_DEBUG_TO_STDERR | ||||
| #define MGMTD_FE_SRVR_DBG(fmt, ...)                                        \ | ||||
| 	fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__) | ||||
| #define MGMTD_FE_SRVR_ERR(fmt, ...)                                        \ | ||||
| 	fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__) | ||||
| #else /* REDIRECT_DEBUG_TO_STDERR */ | ||||
| #define MGMTD_FE_SRVR_DBG(fmt, ...)                                            \ | ||||
| 	do {                                                                   \ | ||||
| 		if (mgmt_debug_fe)                                             \ | ||||
| 			zlog_debug("%s: " fmt, __func__, ##__VA_ARGS__);       \ | ||||
| 	} while (0) | ||||
| 	DEBUGD(&mgmt_debug_fe, "%s:" fmt, __func__, ##__VA_ARGS__) | ||||
| #define MGMTD_FE_SRVR_ERR(fmt, ...)                                        \ | ||||
| 	zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__) | ||||
| #endif /* REDIRECT_DEBUG_TO_STDERR */ | ||||
| 
 | ||||
| static int mgmt_fe_listen_fd = -1; | ||||
| static struct event_loop *mgmt_fe_listen_tm; | ||||
|  | ||||
| @ -14,20 +14,10 @@ | ||||
| #include "mgmtd/mgmt_memory.h" | ||||
| #include "mgmtd/mgmt_txn.h" | ||||
| 
 | ||||
| #ifdef REDIRECT_DEBUG_TO_STDERR | ||||
| #define MGMTD_TXN_DBG(fmt, ...)                                               \ | ||||
| 	fprintf(stderr, "%s: " fmt "\n", __func__, ##__VA_ARGS__) | ||||
| #define MGMTD_TXN_ERR(fmt, ...)                                               \ | ||||
| 	fprintf(stderr, "%s: ERROR, " fmt "\n", __func__, ##__VA_ARGS__) | ||||
| #else /* REDIRECT_DEBUG_TO_STDERR */ | ||||
| #define MGMTD_TXN_DBG(fmt, ...)                                                \ | ||||
| 	do {                                                                   \ | ||||
| 		if (mgmt_debug_txn)                                            \ | ||||
| 			zlog_debug("%s: " fmt, __func__, ##__VA_ARGS__);       \ | ||||
| 	} while (0) | ||||
| #define MGMTD_TXN_ERR(fmt, ...)                                               \ | ||||
| 	DEBUGD(&mgmt_debug_txn, "%s:" fmt, __func__, ##__VA_ARGS__) | ||||
| #define MGMTD_TXN_ERR(fmt, ...)                                                \ | ||||
| 	zlog_err("%s: ERROR: " fmt, __func__, ##__VA_ARGS__) | ||||
| #endif /* REDIRECT_DEBUG_TO_STDERR */ | ||||
| 
 | ||||
| #define MGMTD_TXN_LOCK(txn) mgmt_txn_lock(txn, __FILE__, __LINE__) | ||||
| #define MGMTD_TXN_UNLOCK(txn) mgmt_txn_unlock(txn, __FILE__, __LINE__) | ||||
|  | ||||
| @ -380,7 +380,7 @@ DEFPY(mgmt_rollback, | ||||
| 	return CMD_SUCCESS; | ||||
| } | ||||
| 
 | ||||
| static int config_write_mgmt_debug(struct vty *vty); | ||||
| int config_write_mgmt_debug(struct vty *vty); | ||||
| static struct cmd_node debug_node = { | ||||
| 	.name = "debug", | ||||
| 	.node = DEBUG_NODE, | ||||
| @ -388,27 +388,25 @@ static struct cmd_node debug_node = { | ||||
| 	.config_write = config_write_mgmt_debug, | ||||
| }; | ||||
| 
 | ||||
| static int config_write_mgmt_debug_helper(struct vty *vty, bool config) | ||||
| static int write_mgmt_debug_helper(struct vty *vty, bool config) | ||||
| { | ||||
| 	int n = mgmt_debug_be + mgmt_debug_fe + mgmt_debug_ds + mgmt_debug_txn; | ||||
| 	uint32_t mode = config ? DEBUG_MODE_CONF : DEBUG_MODE_ALL; | ||||
| 	bool be = DEBUG_MODE_CHECK(&mgmt_debug_be, mode); | ||||
| 	bool ds = DEBUG_MODE_CHECK(&mgmt_debug_ds, mode); | ||||
| 	bool fe = DEBUG_MODE_CHECK(&mgmt_debug_fe, mode); | ||||
| 	bool txn = DEBUG_MODE_CHECK(&mgmt_debug_txn, mode); | ||||
| 
 | ||||
| 	if (!n) | ||||
| 	if (!(be || ds || fe || txn)) | ||||
| 		return 0; | ||||
| 
 | ||||
| 	if (config && mgmt_debug_be && mgmt_debug_fe && mgmt_debug_ds && | ||||
| 	    mgmt_debug_txn) { | ||||
| 		vty_out(vty, "debug mgmt all\n"); | ||||
| 		return 0; | ||||
| 	} | ||||
| 
 | ||||
| 	vty_out(vty, "debug mgmt"); | ||||
| 	if (mgmt_debug_be) | ||||
| 	if (be) | ||||
| 		vty_out(vty, " backend"); | ||||
| 	if (mgmt_debug_ds) | ||||
| 	if (ds) | ||||
| 		vty_out(vty, " datastore"); | ||||
| 	if (mgmt_debug_fe) | ||||
| 	if (fe) | ||||
| 		vty_out(vty, " frontend"); | ||||
| 	if (mgmt_debug_txn) | ||||
| 	if (txn) | ||||
| 		vty_out(vty, " transaction"); | ||||
| 
 | ||||
| 	vty_out(vty, "\n"); | ||||
| @ -416,17 +414,17 @@ static int config_write_mgmt_debug_helper(struct vty *vty, bool config) | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| static int config_write_mgmt_debug(struct vty *vty) | ||||
| int config_write_mgmt_debug(struct vty *vty) | ||||
| { | ||||
| 	return config_write_mgmt_debug_helper(vty, true); | ||||
| 	return write_mgmt_debug_helper(vty, true); | ||||
| } | ||||
| 
 | ||||
| DEFUN_NOSH(show_debugging_mgmt, show_debugging_mgmt_cmd, | ||||
| DEFPY_NOSH(show_debugging_mgmt, show_debugging_mgmt_cmd, | ||||
| 	   "show debugging [mgmt]", SHOW_STR DEBUG_STR "MGMT Information\n") | ||||
| { | ||||
| 	vty_out(vty, "MGMT debugging status:\n"); | ||||
| 
 | ||||
| 	config_write_mgmt_debug_helper(vty, false); | ||||
| 	write_mgmt_debug_helper(vty, false); | ||||
| 
 | ||||
| 	cmd_show_lib_debugs(vty); | ||||
| 
 | ||||
| @ -434,27 +432,23 @@ DEFUN_NOSH(show_debugging_mgmt, show_debugging_mgmt_cmd, | ||||
| } | ||||
| 
 | ||||
| DEFPY(debug_mgmt, debug_mgmt_cmd, | ||||
|       "[no$no] debug mgmt <all$all|{backend$be|datastore$ds|frontend$fe|transaction$txn}>", | ||||
|       "[no$no] debug mgmt {backend$be|datastore$ds|frontend$fe|transaction$txn}", | ||||
|       NO_STR DEBUG_STR MGMTD_STR | ||||
|       "All debug\n" | ||||
|       "Back-end debug\n" | ||||
|       "Backend debug\n" | ||||
|       "Datastore debug\n" | ||||
|       "Front-end debug\n" | ||||
|       "Frontend debug\n" | ||||
|       "Transaction debug\n") | ||||
| { | ||||
| 	bool set = !no; | ||||
| 
 | ||||
| 	if (all) | ||||
| 		be = fe = ds = txn = set ? all : NULL; | ||||
| 	uint32_t mode = DEBUG_NODE2MODE(vty->node); | ||||
| 
 | ||||
| 	if (be) | ||||
| 		mgmt_debug_be = set; | ||||
| 		DEBUG_MODE_SET(&mgmt_debug_be, mode, !no); | ||||
| 	if (ds) | ||||
| 		mgmt_debug_ds = set; | ||||
| 		DEBUG_MODE_SET(&mgmt_debug_ds, mode, !no); | ||||
| 	if (fe) | ||||
| 		mgmt_debug_fe = set; | ||||
| 		DEBUG_MODE_SET(&mgmt_debug_fe, mode, !no); | ||||
| 	if (txn) | ||||
| 		mgmt_debug_txn = set; | ||||
| 		DEBUG_MODE_SET(&mgmt_debug_txn, mode, !no); | ||||
| 
 | ||||
| 	return CMD_SUCCESS; | ||||
| } | ||||
| @ -530,6 +524,7 @@ void mgmt_vty_init(void) | ||||
| 
 | ||||
| 	install_element(ENABLE_NODE, &show_debugging_mgmt_cmd); | ||||
| 
 | ||||
| 	mgmt_fe_client_lib_vty_init(); | ||||
| 	/*
 | ||||
| 	 * TODO: Register and handlers for auto-completion here. | ||||
| 	 */ | ||||
|  | ||||
| @ -37,6 +37,8 @@ daemon_flags = { | ||||
|     "lib/filter_cli.c": "VTYSH_ACL", | ||||
|     "lib/if.c": "VTYSH_INTERFACE", | ||||
|     "lib/keychain.c": "VTYSH_RIPD|VTYSH_EIGRPD|VTYSH_OSPF6D", | ||||
|     "lib/mgmt_be_client.c": "VTYSH_STATICD", | ||||
|     "lib/mgmt_fe_client.c": "VTYSH_MGMTD", | ||||
|     "lib/lib_vty.c": "VTYSH_ALL", | ||||
|     "lib/log_vty.c": "VTYSH_ALL", | ||||
|     "lib/nexthop_group.c": "VTYSH_NH_GROUP", | ||||
|  | ||||
| @ -13,6 +13,7 @@ | ||||
| #include "nexthop.h" | ||||
| #include "table.h" | ||||
| #include "srcdest_table.h" | ||||
| #include "mgmt_be_client.h" | ||||
| #include "mpls.h" | ||||
| #include "northbound.h" | ||||
| #include "libfrr.h" | ||||
| @ -1553,4 +1554,6 @@ void static_vty_init(void) | ||||
| 
 | ||||
| 	install_element(ENABLE_NODE, &debug_staticd_cmd); | ||||
| 	install_element(CONFIG_NODE, &debug_staticd_cmd); | ||||
| 
 | ||||
| 	mgmt_be_client_lib_vty_init(); | ||||
| } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Christian Hopps
						Christian Hopps