* Checked yang binding validity which lead to:

* Changed and enhanced several `bad-element` error replies to `unknown-element` with more detailed error-message.
This commit is contained in:
Olof hagsand 2020-07-25 16:09:24 +02:00
parent b56c0220c9
commit 57b104bc25
21 changed files with 106 additions and 70 deletions

View file

@ -624,8 +624,13 @@ from_client_edit_config(clicon_handle h,
xml_spec_set(xc, NULL);
/* Populate XML with Yang spec (why not do this in parser?)
*/
if (xml_bind_yang(xc, YB_MODULE, yspec, NULL) < 0)
if ((ret = xml_bind_yang(xc, YB_MODULE, yspec, &xret)) < 0)
goto done;
if (ret == 0){
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
goto done;
goto ok;
}
/* Maybe validate xml here as in text_modify_top? */
if (xml_apply(xc, CX_ELMNT, xml_non_config_data, &non_config) < 0)
goto done;

View file

@ -217,8 +217,13 @@ startup_common(clicon_handle h,
goto done;
}
/* After upgrading, XML tree needs to be sorted and yang spec populated */
if (xml_bind_yang(xt, YB_MODULE, yspec, NULL) < 0)
if ((ret = xml_bind_yang(xt, YB_MODULE, yspec, &xret)) < 0)
goto done;
if (ret == 0){
if (clicon_xml2cbuf(cbret, xret, 0, 0, -1) < 0)
goto done;
goto fail;
}
if (xml_sort_recurse(xt) < 0)
goto done;
/* Handcraft transition with with only add tree */

View file

@ -149,9 +149,10 @@ netconf_input_packet(clicon_handle h,
free(str0);
if ((xrpc=xpath_first(xreq, NULL, "//rpc")) != NULL){
isrpc++;
if (xml_bind_yang_rpc(xrpc, yspec, NULL) < 0)
if ((ret = xml_bind_yang_rpc(xrpc, yspec, &xret)) < 0)
goto done;
if ((ret = xml_yang_validate_rpc(h, xrpc, &xret)) < 0)
if (ret > 0 &&
(ret = xml_yang_validate_rpc(h, xrpc, &xret)) < 0)
goto done;
if (ret == 0){
clicon_xml2cbuf(cbret, xret, 0, 0, -1);

View file

@ -535,6 +535,7 @@ netconf_create_subscription(clicon_handle h,
*
* This may either be local client-side or backend. If backend send as netconf
* RPC.
* Assume already bound and validated.
* @param[in] h clicon handle
* @param[in] xn Sub-tree (under xorig) at child of rpc: <rpc><xn></rpc>.
* @param[out] xret Return XML, error or OK
@ -542,6 +543,7 @@ netconf_create_subscription(clicon_handle h,
* @retval -1 Error
* @retval 0 OK, not found handler.
* @retval 1 OK, handler called
* @see netconf_input_packet Assume bind and validation made there
*/
static int
netconf_application_rpc(clicon_handle h,
@ -552,7 +554,6 @@ netconf_application_rpc(clicon_handle h,
yang_stmt *yspec = NULL; /* application yspec */
yang_stmt *yrpc = NULL;
yang_stmt *ymod = NULL;
yang_stmt *yinput;
yang_stmt *youtput;
cxobj *xoutput;
cxobj *xerr = NULL;
@ -591,22 +592,7 @@ netconf_application_rpc(clicon_handle h,
yrpc = yang_find(ymod, Y_RPC, xml_name(xn));
/* Check if found */
if (yrpc != NULL){
/* 1. Check xn arguments with input statement. */
if ((yinput = yang_find(yrpc, Y_INPUT, NULL)) != NULL){
xml_spec_set(xn, yinput); /* needed for xml_bind_yang */
if (xml_bind_yang(xn, YB_MODULE, yspec, NULL) < 0)
goto done;
if ((ret = xml_yang_validate_all_top(h, xn, &xerr)) < 0)
goto done;
if (ret > 0 && (ret = xml_yang_validate_add(h, xn, &xerr)) < 0)
goto done;
if (ret == 0){
if (clicon_xml2cbuf(cbret, xerr, 0, 0, -1) < 0)
goto done;
netconf_output_encap(1, cbret, "rpc-error");
goto ok;
}
}
/* No need to check xn arguments with input statement since already bound and validated. */
/* Look for local (client-side) netconf plugins. */
if ((ret = rpc_callback_call(h, xn, cbret, NULL)) < 0)
goto done;
@ -626,9 +612,9 @@ netconf_application_rpc(clicon_handle h,
if ((youtput = yang_find(yrpc, Y_OUTPUT, NULL)) != NULL){
xoutput=xpath_first(*xret, NULL, "/");
xml_spec_set(xoutput, youtput); /* needed for xml_bind_yang */
if (xml_bind_yang(xoutput, YB_MODULE, yspec, NULL) < 0)
if ((ret = xml_bind_yang(xoutput, YB_MODULE, yspec, &xerr)) < 0)
goto done;
if ((ret = xml_yang_validate_all_top(h, xoutput, &xerr)) < 0)
if (ret > 0 && (ret = xml_yang_validate_all_top(h, xoutput, &xerr)) < 0)
goto done;
if (ret > 0 && (ret = xml_yang_validate_add(h, xoutput, &xerr)) < 0)
goto done;

View file

@ -670,9 +670,9 @@ api_operations_post_output(clicon_handle h,
if (youtput != NULL){
xml_spec_set(xoutput, youtput); /* needed for xml_bind_yang */
#ifdef notyet
if (xml_bind_yang(xoutput, YB_MODULE, yspec, NULL) < 0)
if ((ret = xml_bind_yang(xoutput, YB_MODULE, yspec, &xerr)) < 0)
goto done;
if ((ret = xml_yang_validate_all(xoutput, &xerr)) < 0)
if (ret > 0 && (ret = xml_yang_validate_all(xoutput, &xerr)) < 0)
goto done;
if (ret == 1 &&
(ret = xml_yang_validate_add(h, xoutput, &xerr)) < 0)