NETCONF hello error handling, changed YANG PATCH enabling, refactored static linking

NETCONF hello errors, such as wrong session-id, prefix, namespace terminates session
  * Instead of returning an rpc-error reply
Changed YANG PATCH enabling:
  * Now: `./configure --enable-yang-patch`
  * Before: set YANG_PATCH constant in `include/clixon_custom.h`
Refactored Makefile for static linking
This commit is contained in:
Olof hagsand 2021-10-05 11:34:09 +02:00
parent 8f55b8490d
commit 26d37352f4
14 changed files with 166 additions and 98 deletions

View file

@ -48,6 +48,8 @@
#include <signal.h>
#include <fcntl.h>
#include <time.h>
#include <pwd.h>
#include <libgen.h>
#include <syslog.h>
#include <sys/time.h>
#include <sys/socket.h>
@ -56,9 +58,7 @@
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pwd.h>
#include <netinet/in.h>
#include <libgen.h>
/* cligen */
#include <cligen/cligen.h>
@ -119,7 +119,7 @@ netconf_add_request_attr(cxobj *xrpc,
return retval;
}
/*
/*! Process netconf hello message
* A server receiving a <hello> message with a <session-id> element MUST
* terminate the NETCONF session.
*/
@ -309,22 +309,20 @@ netconf_input_packet(clicon_handle h,
goto done;
}
else if (strcmp(rpcname, "hello") == 0){
/* Only accept resolved NETCONF base namespace */
/* Only accept resolved NETCONF base namespace -> terminate*/
if (namespace == NULL || strcmp(namespace, NETCONF_BASE_NAMESPACE) != 0){
clicon_err(OE_XML, EFAULT, "No appropriate namespace associated with prefix:%s", rpcprefix);
cc_closed++;
clicon_err(OE_XML, EFAULT, "No appropriate namespace associated with namespace:%s",
namespace);
goto done;
}
if (netconf_hello_msg(h, xreq) < 0)
goto done;
}
else{
if ((cbret = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
if (netconf_unknown_element(cbret, "protocol", rpcname, "Unrecognized netconf operation")< 0)
goto done;
netconf_output_encap(1, cbret, "rpc-error");
else{ /* Shouldnt happen should be caught by yang bind check in netconf_input_frame */
cc_closed++;
clicon_err(OE_NETCONF, 0, "Unrecognized netconf operation %s", rpcname);
goto done;
}
ok:
retval = 0;

View file

@ -421,11 +421,11 @@ main(int argc,
if (yang_spec_parse_module(h, "ietf-restconf", NULL, yspec)< 0)
goto done;
#ifdef YANG_PATCH
#ifdef CLIXON_YANG_PATCH
/* Load yang restconf patch module */
if (yang_spec_parse_module(h, "ietf-yang-patch", NULL, yspec)< 0)
goto done;
#endif // YANG_PATCH
#endif
/* Add netconf yang spec, used as internal protocol */
if (netconf_module_load(h) < 0)

View file

@ -1770,11 +1770,11 @@ restconf_clixon_init(clicon_handle h,
if (yang_spec_parse_module(h, "ietf-restconf", NULL, yspec)< 0)
goto done;
#ifdef YANG_PATCH
#ifdef CLIXON_YANG_PATCH
/* Load yang restconf patch module */
if (yang_spec_parse_module(h, "ietf-yang-patch", NULL, yspec)< 0)
goto done;
#endif // YANG_PATCH
#endif
/* Add netconf yang spec, used as internal protocol */
if (netconf_module_load(h) < 0)

View file

@ -677,7 +677,7 @@ api_data_patch(clicon_handle h,
break;
case YANG_PATCH_JSON: /* RFC 8072 patch */
case YANG_PATCH_XML:
#ifdef YANG_PATCH
#ifdef CLIXON_YANG_PATCH
ret = api_data_yang_patch(h, req, api_path0, pcvec, pi, qvec, data, pretty,
media_in, media_out, ds);
#else

View file

@ -67,7 +67,7 @@
#include "restconf_methods_post.h"
#include "restconf_methods_patch.h"
#ifdef YANG_PATCH
#ifdef CLIXON_YANG_PATCH
enum yang_patch_op{
YANG_PATCH_OP_CREATE,
@ -124,7 +124,7 @@ yang_patch_xml2json_modified_cbuf(cxobj *x_simple_patch)
// Insert a '[' after the first '{' to get the JSON to match what api_data_post/write() expect
json_simple_patch_tmp = cbuf_get(cb);
len = strlen(json_simple_patch_tmp);
for (int l = 0; l < strlen(len); l++) {
for (int l = 0; l < len; l++) {
char c = json_simple_patch_tmp[l];
if (c == '{') {
brace_count++;
@ -848,7 +848,7 @@ api_data_yang_patch(clicon_handle h,
return retval;
}
#else // YANG_PATCH
#else // CLIXON_YANG_PATCH
int
api_data_yang_patch(clicon_handle h,
@ -866,4 +866,4 @@ api_data_yang_patch(clicon_handle h,
clicon_err(OE_RESTCONF, 0, "Not implemented");
return -1;
}
#endif // YANG_PATCH
#endif // CLIXON_YANG_PATCH