diff --git a/lib/mgmt_be_client.c b/lib/mgmt_be_client.c index 2ffcd8f9fc2e..c3fb34a7a4d4 100644 --- a/lib/mgmt_be_client.c +++ b/lib/mgmt_be_client.c @@ -1060,7 +1060,7 @@ struct mgmt_be_client *mgmt_be_client_create(const char *client_name, mgmt_be_client_notify_conenct, mgmt_be_client_notify_disconenct, mgmt_be_client_process_msg, MGMTD_BE_MAX_NUM_MSG_PROC, - MGMTD_BE_MAX_NUM_MSG_WRITE, MGMTD_BE_MSG_MAX_LEN, false, + MGMTD_BE_MAX_NUM_MSG_WRITE, MGMTD_BE_MAX_MSG_LEN, false, "BE-client", MGMTD_DBG_BE_CLIENT_CHECK()); MGMTD_BE_CLIENT_DBG("Initialized client '%s'", client_name); diff --git a/lib/mgmt_be_client.h b/lib/mgmt_be_client.h index 3af87a73cd92..8ad482cacf58 100644 --- a/lib/mgmt_be_client.h +++ b/lib/mgmt_be_client.h @@ -20,25 +20,12 @@ extern "C" { * Constants ***************************************************************/ -#define MGMTD_BE_CLIENT_ERROR_STRING_MAX_LEN 32 - -#define MGMTD_BE_DEFAULT_CONN_RETRY_INTVL_SEC 5 - -#define MGMTD_BE_MSG_PROC_DELAY_USEC 10 -#define MGMTD_BE_MAX_NUM_MSG_PROC 500 - -#define MGMTD_BE_MSG_WRITE_DELAY_MSEC 1 +#define MGMTD_BE_MAX_NUM_MSG_PROC 500 #define MGMTD_BE_MAX_NUM_MSG_WRITE 1000 +#define MGMTD_BE_MAX_MSG_LEN (64 * 1024) -#define GMGD_BE_MAX_NUM_REQ_ITEMS 64 - -#define MGMTD_BE_MSG_MAX_LEN 16384 - -#define MGMTD_SOCKET_BE_SEND_BUF_SIZE 65535 -#define MGMTD_SOCKET_BE_RECV_BUF_SIZE MGMTD_SOCKET_BE_SEND_BUF_SIZE - -#define MGMTD_MAX_CFG_CHANGES_IN_BATCH \ - ((10 * MGMTD_BE_MSG_MAX_LEN) / \ +#define MGMTD_MAX_CFG_CHANGES_IN_BATCH \ + ((10 * MGMTD_BE_MAX_MSG_LEN) / \ (MGMTD_MAX_XPATH_LEN + MGMTD_MAX_YANG_VALUE_LEN)) /* @@ -47,11 +34,11 @@ extern "C" { * that gets added to sent message */ #define MGMTD_BE_CFGDATA_PACKING_EFFICIENCY 0.8 -#define MGMTD_BE_CFGDATA_MAX_MSG_LEN \ - (MGMTD_BE_MSG_MAX_LEN * MGMTD_BE_CFGDATA_PACKING_EFFICIENCY) +#define MGMTD_BE_CFGDATA_MAX_MSG_LEN \ + (MGMTD_BE_MAX_MSG_LEN * MGMTD_BE_CFGDATA_PACKING_EFFICIENCY) -#define MGMTD_BE_MAX_BATCH_IDS_IN_REQ \ - (MGMTD_BE_MSG_MAX_LEN - 128) / sizeof(uint64_t) +#define MGMTD_BE_MAX_BATCH_IDS_IN_REQ \ + (MGMTD_BE_MAX_MSG_LEN - 128) / sizeof(uint64_t) #define MGMTD_BE_CONTAINER_NODE_VAL "<>" diff --git a/lib/mgmt_fe_client.c b/lib/mgmt_fe_client.c index c30a0339ebf5..0bea66300449 100644 --- a/lib/mgmt_fe_client.c +++ b/lib/mgmt_fe_client.c @@ -729,7 +729,7 @@ struct mgmt_fe_client *mgmt_fe_client_create(const char *client_name, mgmt_fe_client_notify_connect, mgmt_fe_client_notify_disconnect, mgmt_fe_client_process_msg, MGMTD_FE_MAX_NUM_MSG_PROC, - MGMTD_FE_MAX_NUM_MSG_WRITE, MGMTD_FE_MSG_MAX_LEN, true, + MGMTD_FE_MAX_NUM_MSG_WRITE, MGMTD_FE_MAX_MSG_LEN, true, "FE-client", MGMTD_DBG_FE_CLIENT_CHECK()); MGMTD_FE_CLIENT_DBG("Initialized client '%s'", client_name); diff --git a/lib/mgmt_fe_client.h b/lib/mgmt_fe_client.h index 3a1a1e570578..f3292d18fda1 100644 --- a/lib/mgmt_fe_client.h +++ b/lib/mgmt_fe_client.h @@ -25,22 +25,11 @@ extern "C" { * connections. */ -#define MGMTD_FE_CLIENT_ERROR_STRING_MAX_LEN 32 - -#define MGMTD_FE_DEFAULT_CONN_RETRY_INTVL_SEC 5 - #define MGMTD_FE_MSG_PROC_DELAY_USEC 10 -#define MGMTD_FE_MAX_NUM_MSG_PROC 500 -#define MGMTD_FE_MSG_WRITE_DELAY_MSEC 1 +#define MGMTD_FE_MAX_NUM_MSG_PROC 500 #define MGMTD_FE_MAX_NUM_MSG_WRITE 100 - -#define GMGD_FE_MAX_NUM_REQ_ITEMS 64 - -#define MGMTD_FE_MSG_MAX_LEN 9000 - -#define MGMTD_SOCKET_FE_SEND_BUF_SIZE 65535 -#define MGMTD_SOCKET_FE_RECV_BUF_SIZE MGMTD_SOCKET_FE_SEND_BUF_SIZE +#define MGMTD_FE_MAX_MSG_LEN (64 * 1024) /*************************************************************** * Data-structures diff --git a/lib/mgmt_msg.c b/lib/mgmt_msg.c index b03dbe8cc3e2..23cfbc3b0158 100644 --- a/lib/mgmt_msg.c +++ b/lib/mgmt_msg.c @@ -111,6 +111,11 @@ enum mgmt_msg_rsched mgmt_msg_read(struct mgmt_msg_state *ms, int fd, * therefor the stream is too small to fit the message.. * Resize the stream to fit. */ + if (mhdr->len > MGMT_MSG_MAX_MSG_ALLOC_LEN) { + MGMT_MSG_ERR(ms, "corrupt msg len rcvd %u", + mhdr->len); + return MSR_DISCONNECT; + } news = stream_new(mhdr->len); stream_put(news, mhdr, left); stream_set_endp(news, left); diff --git a/lib/mgmt_msg.h b/lib/mgmt_msg.h index 3195d4a7fb07..6bdc9a6cfc3a 100644 --- a/lib/mgmt_msg.h +++ b/lib/mgmt_msg.h @@ -24,6 +24,8 @@ DECLARE_MTYPE(MSG_CONN); #define MGMT_MSG_VERSION_PROTOBUF 0 #define MGMT_MSG_VERSION_NATIVE 1 +/* The absolute maximum message size (16MB) */ +#define MGMT_MSG_MAX_MSG_ALLOC_LEN (16 * 1024 * 1024) struct mgmt_msg_state { struct stream *ins; diff --git a/lib/northbound.c b/lib/northbound.c index 3b02c08bbfbc..bf5cc912b519 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -2250,7 +2250,7 @@ int nb_oper_data_iterate(const char *xpath, struct yang_translator *translator, __func__, xpath); return ret; } - + assert(dnode); /* * Create a linked list to sort the data nodes starting from the root. @@ -2331,17 +2331,15 @@ int nb_oper_data_iterate(const char *xpath, struct yang_translator *translator, flags, cb, arg, dnode); list_delete(&list_dnodes); - if (dnode) { - while (lyd_parent(dnode)) - dnode = lyd_parent(dnode); + while (lyd_parent(dnode)) + dnode = lyd_parent(dnode); - if (tree && ret == NB_OK) - *tree = dnode; - else { - lyd_free_all(dnode); - if (tree) - *tree = NULL; - } + if (tree && ret == NB_OK) + *tree = dnode; + else { + lyd_free_all(dnode); + if (tree) + *tree = NULL; } return ret; diff --git a/lib/vty.c b/lib/vty.c index 3c80403cce7b..a08a3c873590 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -3657,8 +3657,7 @@ static int vty_mgmt_get_data_result_notified( } if (next_key < 0) { vty_out(vty, "]\n"); - vty_mgmt_resume_response(vty, - success ? CMD_SUCCESS : CMD_WARNING); + vty_mgmt_resume_response(vty, CMD_SUCCESS); } return 0; diff --git a/mgmtd/mgmt_be_adapter.c b/mgmtd/mgmt_be_adapter.c index 0d678452f7da..eb6e79f2a5e9 100644 --- a/mgmtd/mgmt_be_adapter.c +++ b/mgmtd/mgmt_be_adapter.c @@ -735,7 +735,7 @@ struct msg_conn *mgmt_be_create_adapter(int conn_fd, union sockunion *from) mgmt_be_adapter_process_msg, MGMTD_BE_MAX_NUM_MSG_PROC, MGMTD_BE_MAX_NUM_MSG_WRITE, - MGMTD_BE_MSG_MAX_LEN, adapter, + MGMTD_BE_MAX_MSG_LEN, adapter, "BE-adapter"); adapter->conn->debug = DEBUG_MODE_CHECK(&mgmt_debug_be, DEBUG_MODE_ALL); diff --git a/mgmtd/mgmt_fe_adapter.c b/mgmtd/mgmt_fe_adapter.c index 87c67491b6f4..d98444703f21 100644 --- a/mgmtd/mgmt_fe_adapter.c +++ b/mgmtd/mgmt_fe_adapter.c @@ -1344,7 +1344,7 @@ struct msg_conn *mgmt_fe_create_adapter(int conn_fd, union sockunion *from) adapter->conn = msg_server_conn_create( mgmt_loop, conn_fd, mgmt_fe_adapter_notify_disconnect, mgmt_fe_adapter_process_msg, MGMTD_FE_MAX_NUM_MSG_PROC, - MGMTD_FE_MAX_NUM_MSG_WRITE, MGMTD_FE_MSG_MAX_LEN, + MGMTD_FE_MAX_NUM_MSG_WRITE, MGMTD_FE_MAX_MSG_LEN, adapter, "FE-adapter"); adapter->conn->debug = DEBUG_MODE_CHECK(&mgmt_debug_fe, diff --git a/mgmtd/mgmt_txn.c b/mgmtd/mgmt_txn.c index 7e625c73ec0e..ea3236e80b96 100644 --- a/mgmtd/mgmt_txn.c +++ b/mgmtd/mgmt_txn.c @@ -426,7 +426,6 @@ static void mgmt_txn_req_free(struct mgmt_txn_req **txn_req) { int indx; struct mgmt_txn_reqs_head *req_list = NULL; - struct mgmt_txn_reqs_head *pending_list = NULL; enum mgmt_be_client_id id; struct mgmt_be_client_adapter *adapter; struct mgmt_commit_cfg_req *ccreq; @@ -527,13 +526,7 @@ static void mgmt_txn_req_free(struct mgmt_txn_req **txn_req) break; } - if ((*txn_req)->pending_be_proc && pending_list) { - mgmt_txn_reqs_del(pending_list, *txn_req); - MGMTD_TXN_DBG("Removed req-id: %" PRIu64 - " from pending-list (left:%zu)", - (*txn_req)->req_id, - mgmt_txn_reqs_count(pending_list)); - } else if (req_list) { + if (req_list) { mgmt_txn_reqs_del(req_list, *txn_req); MGMTD_TXN_DBG("Removed req-id: %" PRIu64 " from request-list (left:%zu)", @@ -1274,6 +1267,7 @@ static int txn_get_tree_data_done(struct mgmt_txn_ctx *txn, struct mgmt_txn_req *txn_req) { struct txn_req_get_tree *get_tree = txn_req->req.get_tree; + uint64_t req_id = txn_req->req_id; int ret = 0; /* cancel timer and send reply onward */ @@ -1291,11 +1285,9 @@ static int txn_get_tree_data_done(struct mgmt_txn_ctx *txn, if (ret) { MGMTD_TXN_ERR("Error saving the results of GETTREE for txn-id %" PRIu64 " req_id %" PRIu64 " to requested type %u", - txn->txn_id, txn_req->req_id, - get_tree->result_type); + txn->txn_id, req_id, get_tree->result_type); - (void)mgmt_fe_adapter_txn_error(txn->txn_id, txn_req->req_id, - false, ret, + (void)mgmt_fe_adapter_txn_error(txn->txn_id, req_id, false, ret, "Error converting results of GETTREE"); }