Merge pull request #14914 from idryzhov/mgmt-validate

mgmtd: validate candidate yang tree before creating a config diff
This commit is contained in:
Donatas Abraitis 2023-12-01 09:01:05 +02:00 committed by GitHub
commit 05567badb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1034,6 +1034,23 @@ static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn)
goto mgmt_txn_prepare_config_done;
}
/*
* Validate YANG contents of the source DS and get the diff
* between source and destination DS contents.
*/
char err_buf[BUFSIZ] = { 0 };
ret = nb_candidate_validate_yang(nb_config, true, err_buf,
sizeof(err_buf) - 1);
if (ret != NB_OK) {
if (strncmp(err_buf, " ", strlen(err_buf)) == 0)
strlcpy(err_buf, "Validation failed", sizeof(err_buf));
(void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_INVALID_PARAM,
err_buf);
ret = -1;
goto mgmt_txn_prepare_config_done;
}
nb_config_diff(mgmt_ds_get_nb_config(txn->commit_cfg_req->req.commit_cfg
.dst_ds_ctx),
nb_config, &changes);
@ -1056,29 +1073,13 @@ static int mgmt_txn_prepare_config(struct mgmt_txn_ctx *txn)
gettimeofday(&txn->commit_cfg_req->req.commit_cfg.cmt_stats
->validate_start,
NULL);
/*
* Validate YANG contents of the source DS and get the diff
* between source and destination DS contents.
*/
char err_buf[1024] = { 0 };
nb_ctx.client = NB_CLIENT_MGMTD_SERVER;
nb_ctx.user = (void *)txn;
ret = nb_candidate_validate_yang(nb_config, true, err_buf,
sizeof(err_buf) - 1);
if (ret != NB_OK) {
if (strncmp(err_buf, " ", strlen(err_buf)) == 0)
strlcpy(err_buf, "Validation failed", sizeof(err_buf));
(void)mgmt_txn_send_commit_cfg_reply(txn, MGMTD_INVALID_PARAM,
err_buf);
ret = -1;
goto mgmt_txn_prepare_config_done;
}
/*
* Perform application level validations locally on the MGMTD
* process by calling application specific validation routines
* loaded onto MGMTD process using libraries.
*/
nb_ctx.client = NB_CLIENT_MGMTD_SERVER;
nb_ctx.user = (void *)txn;
ret = nb_candidate_validate_code(&nb_ctx, nb_config, &changes, err_buf,
sizeof(err_buf) - 1);
if (ret != NB_OK) {