From 60ce7b12bd27be36c766d895e43ecfe17a0e0d90 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Wed, 20 Jun 2018 20:53:34 +0200 Subject: [PATCH] * Prefix of rpc was ignored * https://github.com/clicon/clixon/issues/30 --- CHANGELOG.md | 2 ++ apps/netconf/netconf_rpc.c | 18 +++++++++++++----- apps/restconf/restconf_methods.c | 9 +++++++-- lib/src/clixon_yang.c | 18 +++++++++++------- test/test_netconf.sh | 6 +++--- test/test_restconf.sh | 3 +++ 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b72a6ad..ff1a1db6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ * See FAQ and example ### Corrected Bugs +* Prefix of rpc was ignored + * https://github.com/clicon/clixon/issues/30 * Added cli returna value also for single commands (eg -1) * Fixed JSON unbalanced braces resulting in assert. diff --git a/apps/netconf/netconf_rpc.c b/apps/netconf/netconf_rpc.c index ac341c03..da50636e 100644 --- a/apps/netconf/netconf_rpc.c +++ b/apps/netconf/netconf_rpc.c @@ -888,12 +888,19 @@ netconf_application_rpc(clicon_handle h, goto done; } cbuf_reset(cb); - // if (xml_namespace(xn)) - cprintf(cb, "/%s:%s", xml_namespace(xn), xml_name(xn)); - // else - // cprintf(cb, "/%s", xml_name(xn)); /* XXX not accepdted by below */ + if (xml_namespace(xn) == NULL){ + xml_parse_va(xret, NULL, "" + "operation-failed" + "rpc" + "error" + "%s" + "Not recognized" + "", xml_name(xn)); + goto ok; + } + cprintf(cb, "/%s:%s", xml_namespace(xn), xml_name(xn)); /* Find yang rpc statement, return yang rpc statement if found */ - if (yang_abs_schema_nodeid(yspec, cbuf_get(cb), Y_RPC, &yrpc) < 0) + if (yang_abs_schema_nodeid(yspec, cbuf_get(cb), Y_RPC, &yrpc) < 0) goto done; /* Check if found */ if (yrpc != NULL){ @@ -937,6 +944,7 @@ netconf_application_rpc(clicon_handle h, retval = 1; /* handled by callback */ goto done; } + ok: retval = 0; done: if (cb) diff --git a/apps/restconf/restconf_methods.c b/apps/restconf/restconf_methods.c index 5aeded27..142105d0 100644 --- a/apps/restconf/restconf_methods.c +++ b/apps/restconf/restconf_methods.c @@ -1048,8 +1048,13 @@ api_operations_post(clicon_handle h, clicon_debug(1, "%s oppath: %s", __FUNCTION__, oppath); /* Find yang rpc statement, return yang rpc statement if found */ - if (yang_abs_schema_nodeid(yspec, oppath, Y_RPC, &yrpc) < 0) - goto done; + if (yang_abs_schema_nodeid(yspec, oppath, Y_RPC, &yrpc) < 0){ + if (netconf_operation_failed_xml(&xerr, "protocol", "yang node not found") < 0) + goto done; + if (api_return_err(h, r, xerr, pretty, use_xml) < 0) + goto done; + goto ok; + } if (yrpc == NULL){ if (netconf_operation_failed_xml(&xerr, "protocol", "yang node not found") < 0) goto done; diff --git a/lib/src/clixon_yang.c b/lib/src/clixon_yang.c index 76a8ff98..8960fdca 100644 --- a/lib/src/clixon_yang.c +++ b/lib/src/clixon_yang.c @@ -2082,16 +2082,16 @@ schema_nodeid_vec(yang_node *yn, * Assume schema nodeid:s have prefixes, (actually the first). * @see yang_desc_schema_nodeid * @see RFC7950 6.5 - o schema node: A node in the schema tree. One of action, container, - leaf, leaf-list, list, choice, case, rpc, input, output, - notification, anydata, and anyxml. + * o schema node: A node in the schema tree. One of action, container, + * leaf, leaf-list, list, choice, case, rpc, input, output, + * notification, anydata, and anyxml. * Used in yang: deviation, top-level augment */ int -yang_abs_schema_nodeid(yang_spec *yspec, - char *schema_nodeid, +yang_abs_schema_nodeid(yang_spec *yspec, + char *schema_nodeid, enum rfc_6020 keyword, - yang_stmt **yres) + yang_stmt **yres) { int retval = -1; char **vec = NULL; @@ -2136,7 +2136,6 @@ yang_abs_schema_nodeid(yang_spec *yspec, } } if (ymod == NULL){ /* Try with topnode */ - if ((ys = yang_find_topnode(yspec, id, YC_SCHEMANODE)) == NULL){ clicon_err(OE_YANG, 0, "Module with id:%s:%s not found", prefix,id); goto done; @@ -2145,6 +2144,11 @@ yang_abs_schema_nodeid(yang_spec *yspec, clicon_err(OE_YANG, 0, "Module with id:%s:%s not found2", prefix,id); goto done; } + if ((yprefix = yang_find((yang_node*)ymod, Y_PREFIX, NULL)) != NULL && + strcmp(yprefix->ys_argument, prefix) != 0){ + clicon_err(OE_YANG, 0, "Module with id:%s:%s not found", prefix,id); + goto done; + } } if (schema_nodeid_vec((yang_node*)ymod, vec+1, nvec-1, keyword, yres) < 0) goto done; diff --git a/test/test_netconf.sh b/test/test_netconf.sh index 02982e5a..e0364e1a 100755 --- a/test/test_netconf.sh +++ b/test/test_netconf.sh @@ -199,11 +199,11 @@ expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "ipv4ipv4]]>]]>" "^ipv4" -new "netconf rpc w/o namespace" -expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "ipv4ipv4]]>]]>" "^ipv4" +new "netconf rpc without namespace" +expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "ipv4ipv4]]>]]>" "^ipv4" new "netconf empty rpc" -expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" +expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "]]>]]>" "^]]>]]>$" new "netconf client-side rpc" expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "example]]>]]>" "^ok]]>]]>$" diff --git a/test/test_restconf.sh b/test/test_restconf.sh index d1ff4ade..5008ad80 100755 --- a/test/test_restconf.sh +++ b/test/test_restconf.sh @@ -275,6 +275,9 @@ if [ -z "$match" ]; then err "$expect" "$ret" fi +new2 "restconf rpc using wrong prefix" +expecteq "$(curl -s -X POST -d '{"input":{"routing-instance-name":"ipv4"}}' http://localhost/restconf/operations/wrong:fib-route)" '{"ietf-restconf:errors" : {"error": {"rpc-error": {"error-tag": "operation-failed","error-type": "protocol","error-severity": "error","error-message": "yang node not found"}}}} ' + new "restconf local client rpc using POST xml" ret=$(curl -s -X POST -H "Accept: application/yang-data+xml" -d '{"input":{"request":"example"}}' http://localhost/restconf/operations/ex:client-rpc) expect="ok"