Netconf monitoring RFC 6022 Sessions (https://github.com/clicon/clixon/issues/370)
- statistics and transport/source-host parameters - extended internal NETCONF hello with transport and source-host attributes clixon-lib,yang - Moved all extended internal NETCONF attributes to the clicon-lib namespace C-API: - wrapped most attribute creation into new fn xml_add_attr()
This commit is contained in:
parent
7558d40faa
commit
3916fa919c
36 changed files with 883 additions and 402 deletions
|
|
@ -405,7 +405,6 @@ restconf_insert_attributes(cxobj *xdata,
|
|||
cvec *qvec)
|
||||
{
|
||||
int retval = -1;
|
||||
cxobj *xa;
|
||||
char *instr;
|
||||
char *pstr;
|
||||
yang_stmt *y;
|
||||
|
|
@ -422,12 +421,7 @@ restconf_insert_attributes(cxobj *xdata,
|
|||
/* First add xmlns:yang attribute */
|
||||
if (xmlns_set(xdata, "yang", YANG_XML_NAMESPACE) < 0)
|
||||
goto done;
|
||||
/* Then add insert attribute */
|
||||
if ((xa = xml_new("insert", xdata, CX_ATTR)) == NULL)
|
||||
goto done;
|
||||
if (xml_prefix_set(xa, "yang") < 0)
|
||||
goto done;
|
||||
if (xml_value_set(xa, instr) < 0)
|
||||
if (xml_add_attr(xdata, "insert", instr, "yang", NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
if ((pstr = cvec_find_str(qvec, "point")) != NULL){
|
||||
|
|
@ -439,11 +433,7 @@ restconf_insert_attributes(cxobj *xdata,
|
|||
attrname="key";
|
||||
else
|
||||
attrname="value";
|
||||
/* Then add value/key attribute */
|
||||
if ((xa = xml_new(attrname, xdata, CX_ATTR)) == NULL)
|
||||
goto done;
|
||||
if (xml_prefix_set(xa, "yang") < 0)
|
||||
goto done;
|
||||
|
||||
if ((ret = api_path2xpath(pstr, ys_spec(y), &xpath, &nsc, NULL)) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
|
|
@ -471,7 +461,7 @@ restconf_insert_attributes(cxobj *xdata,
|
|||
p++;
|
||||
cprintf(cb, "%s", p);
|
||||
}
|
||||
if (xml_value_set(xa, cbuf_get(cb)) < 0)
|
||||
if (xml_add_attr(xdata, attrname, cbuf_get(cb), "yang", NULL) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* Add prefix/namespaces used in attributes */
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ restconf_main_config(clicon_handle h,
|
|||
else {
|
||||
/* Loop to wait for backend starting, try again if not done */
|
||||
while (1){
|
||||
if (clicon_hello_req(h, &id) < 0){
|
||||
if (clicon_hello_req(h, "cl:restconf", NULL, &id) < 0){
|
||||
if (errno == ENOENT){
|
||||
fprintf(stderr, "waiting");
|
||||
sleep(1);
|
||||
|
|
|
|||
|
|
@ -634,7 +634,7 @@ restconf_clixon_backend(clicon_handle h,
|
|||
|
||||
/* Loop to wait for backend starting, try again if not done */
|
||||
while (1){
|
||||
if (clicon_hello_req(h, &id) < 0){
|
||||
if (clicon_hello_req(h, "cl:restconf", NULL, &id) < 0){
|
||||
if (errno == ENOENT){
|
||||
fprintf(stderr, "waiting");
|
||||
sleep(1);
|
||||
|
|
|
|||
|
|
@ -384,24 +384,12 @@ api_data_write(clicon_handle h,
|
|||
/* Add operation create as attribute. If that fails with Conflict, then
|
||||
* try "replace" (see comment in function header)
|
||||
*/
|
||||
if ((xa = xml_new("operation", xdata, CX_ATTR)) == NULL)
|
||||
if (xml_add_attr(xdata, "operation", xml_operation2str(op), NETCONF_BASE_PREFIX, NULL) < 0)
|
||||
goto done;
|
||||
if (xml_prefix_set(xa, NETCONF_BASE_PREFIX) < 0)
|
||||
if (xml_add_attr(xdata, "objectcreate",
|
||||
plain_patch?"false":"true",
|
||||
CLIXON_LIB_PREFIX, CLIXON_LIB_NS) < 0)
|
||||
goto done;
|
||||
if (xml_value_set(xa, xml_operation2str(op)) < 0) /* XXX here is where op is used */
|
||||
goto done;
|
||||
if ((xa = xml_new("objectcreate", xdata, CX_ATTR)) == NULL)
|
||||
goto done;
|
||||
if (plain_patch){
|
||||
/* RFC 8040 4.6. PATCH:
|
||||
* If the target resource instance does not exist, the server MUST NOT create it.
|
||||
*/
|
||||
if (xml_value_set(xa, "false") < 0)
|
||||
goto done;
|
||||
}
|
||||
else
|
||||
if (xml_value_set(xa, "true") < 0)
|
||||
goto done;
|
||||
/* Top-of tree, no api-path
|
||||
* Replace xparent with x, ie bottom of api-path with data
|
||||
*/
|
||||
|
|
@ -512,16 +500,20 @@ api_data_write(clicon_handle h,
|
|||
} /* api-path != NULL */
|
||||
/* For internal XML protocol: add username attribute for access control
|
||||
*/
|
||||
username = clicon_username_get(h);
|
||||
/* Create text buffer for transfer to backend */
|
||||
if ((cbx = cbuf_new()) == NULL)
|
||||
goto done;
|
||||
cprintf(cbx, "<rpc xmlns=\"%s\" username=\"%s\" xmlns:%s=\"%s\" %s>",
|
||||
NETCONF_BASE_NAMESPACE,
|
||||
username?username:"",
|
||||
cprintf(cbx, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
cprintf(cbx, " xmlns:%s=\"%s\"", NETCONF_BASE_PREFIX, NETCONF_BASE_NAMESPACE);
|
||||
if ((username = clicon_username_get(h)) != NULL){
|
||||
cprintf(cbx, " %s:username=\"%s\"", CLIXON_LIB_PREFIX, username);
|
||||
cprintf(cbx, " xmlns:%s=\"%s\"", CLIXON_LIB_PREFIX, CLIXON_LIB_NS);
|
||||
}
|
||||
cprintf(cbx, " xmlns:%s=\"%s\"",
|
||||
NETCONF_BASE_PREFIX,
|
||||
NETCONF_BASE_NAMESPACE, /* bind nc to netconf namespace */
|
||||
NETCONF_MESSAGE_ID_ATTR);
|
||||
NETCONF_BASE_NAMESPACE); /* bind nc to netconf namespace */
|
||||
cprintf(cbx, " %s", NETCONF_MESSAGE_ID_ATTR); /* XXX: use incrementing sequence */
|
||||
cprintf(cbx, ">");
|
||||
cprintf(cbx, "<edit-config");
|
||||
/* RFC8040 Sec 1.4:
|
||||
* If this is a "data" request and the NETCONF server supports :startup,
|
||||
|
|
@ -532,9 +524,11 @@ api_data_write(clicon_handle h,
|
|||
if ((IETF_DS_NONE == ds) &&
|
||||
if_feature(yspec, "ietf-netconf", "startup") &&
|
||||
!clicon_option_bool(h, "CLICON_RESTCONF_STARTUP_DONTUPDATE")){
|
||||
cprintf(cbx, " copystartup=\"true\"");
|
||||
cprintf(cbx, " %s:copystartup=\"true\"", CLIXON_LIB_PREFIX);
|
||||
cprintf(cbx, " xmlns:%s=\"%s\"", CLIXON_LIB_PREFIX, CLIXON_LIB_NS);
|
||||
}
|
||||
cprintf(cbx, " autocommit=\"true\"");
|
||||
cprintf(cbx, " %s:autocommit=\"true\" xmlns:%s=\"%s\"",
|
||||
CLIXON_LIB_PREFIX, CLIXON_LIB_PREFIX, CLIXON_LIB_NS);
|
||||
cprintf(cbx, "><target><candidate /></target>");
|
||||
cprintf(cbx, "<default-operation>none</default-operation>");
|
||||
if (clixon_xml2cbuf(cbx, xtop, 0, 0, -1, 0) < 0)
|
||||
|
|
@ -759,14 +753,17 @@ api_data_delete(clicon_handle h,
|
|||
goto done;
|
||||
/* For internal XML protocol: add username attribute for access control
|
||||
*/
|
||||
username = clicon_username_get(h);
|
||||
cprintf(cbx, "<rpc xmlns=\"%s\" username=\"%s\" xmlns:%s=\"%s\" %s>",
|
||||
NETCONF_BASE_NAMESPACE,
|
||||
username?username:"",
|
||||
cprintf(cbx, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
cprintf(cbx, " xmlns:%s=\"%s\"", NETCONF_BASE_PREFIX, NETCONF_BASE_NAMESPACE);
|
||||
if ((username = clicon_username_get(h)) != NULL){
|
||||
cprintf(cbx, " %s:username=\"%s\"", CLIXON_LIB_PREFIX, username);
|
||||
cprintf(cbx, " xmlns:%s=\"%s\"", CLIXON_LIB_PREFIX, CLIXON_LIB_NS);
|
||||
}
|
||||
cprintf(cbx, " xmlns:%s=\"%s\"",
|
||||
NETCONF_BASE_PREFIX,
|
||||
NETCONF_BASE_NAMESPACE,
|
||||
NETCONF_MESSAGE_ID_ATTR); /* bind nc to netconf namespace */
|
||||
|
||||
NETCONF_BASE_NAMESPACE);
|
||||
cprintf(cbx, " %s", NETCONF_MESSAGE_ID_ATTR); /* XXX: use incrementing sequence */
|
||||
cprintf(cbx, ">");
|
||||
cprintf(cbx, "<edit-config");
|
||||
/* RFC8040 Sec 1.4:
|
||||
* If this is a "data" request and the NETCONF server supports :startup,
|
||||
|
|
@ -777,9 +774,11 @@ api_data_delete(clicon_handle h,
|
|||
if ((IETF_DS_NONE == ds) &&
|
||||
if_feature(yspec, "ietf-netconf", "startup") &&
|
||||
!clicon_option_bool(h, "CLICON_RESTCONF_STARTUP_DONTUPDATE")){
|
||||
cprintf(cbx, " copystartup=\"true\"");
|
||||
cprintf(cbx, " xmlns:%s=\"%s\"", CLIXON_LIB_PREFIX, CLIXON_LIB_NS);
|
||||
cprintf(cbx, " %s:copystartup=\"true\"", CLIXON_LIB_PREFIX);
|
||||
}
|
||||
cprintf(cbx, " autocommit=\"true\"");
|
||||
cprintf(cbx, " %s:autocommit=\"true\" xmlns:%s=\"%s\"",
|
||||
CLIXON_LIB_PREFIX, CLIXON_LIB_PREFIX, CLIXON_LIB_NS);
|
||||
cprintf(cbx, "><target><candidate /></target>");
|
||||
cprintf(cbx, "<default-operation>none</default-operation>");
|
||||
if (clixon_xml2cbuf(cbx, xtop, 0, 0, -1, 0) < 0)
|
||||
|
|
|
|||
|
|
@ -337,14 +337,15 @@ api_data_post(clicon_handle h,
|
|||
}
|
||||
/* For internal XML protocol: add username attribute for access control
|
||||
*/
|
||||
username = clicon_username_get(h);
|
||||
cprintf(cbx, "<rpc xmlns=\"%s\" username=\"%s\" xmlns:%s=\"%s\" %s>",
|
||||
NETCONF_BASE_NAMESPACE,
|
||||
username?username:"",
|
||||
NETCONF_BASE_PREFIX,
|
||||
NETCONF_BASE_NAMESPACE,
|
||||
NETCONF_MESSAGE_ID_ATTR); /* bind nc to netconf namespace */
|
||||
|
||||
cprintf(cbx, "<rpc xmlns=\"%s\"", NETCONF_BASE_NAMESPACE);
|
||||
if ((username = clicon_username_get(h)) != NULL){
|
||||
cprintf(cbx, " %s:username=\"%s\" xmlns:%s=\"%s\"",
|
||||
NETCONF_BASE_PREFIX,
|
||||
username?username:"",
|
||||
NETCONF_BASE_PREFIX,
|
||||
NETCONF_BASE_NAMESPACE);
|
||||
}
|
||||
cprintf(cbx, " %s>", NETCONF_MESSAGE_ID_ATTR); /* bind nc to netconf namespace */
|
||||
cprintf(cbx, "<edit-config");
|
||||
/* RFC8040 Sec 1.4:
|
||||
* If this is a "data" request and the NETCONF server supports :startup,
|
||||
|
|
@ -355,9 +356,11 @@ api_data_post(clicon_handle h,
|
|||
if ((IETF_DS_NONE == ds) &&
|
||||
if_feature(yspec, "ietf-netconf", "startup") &&
|
||||
!clicon_option_bool(h, "CLICON_RESTCONF_STARTUP_DONTUPDATE")){
|
||||
cprintf(cbx, " copystartup=\"true\"");
|
||||
cprintf(cbx, " xmlns:%s=\"%s\"", CLIXON_LIB_PREFIX, CLIXON_LIB_NS);
|
||||
cprintf(cbx, " %s:copystartup=\"true\"", CLIXON_LIB_PREFIX);
|
||||
}
|
||||
cprintf(cbx, " autocommit=\"true\"");
|
||||
cprintf(cbx, " %s:autocommit=\"true\" xmlns:%s=\"%s\"",
|
||||
CLIXON_LIB_PREFIX, CLIXON_LIB_PREFIX, CLIXON_LIB_NS);
|
||||
cprintf(cbx, "><target><candidate /></target>");
|
||||
cprintf(cbx, "<default-operation>none</default-operation>");
|
||||
if (clixon_xml2cbuf(cbx, xtop, 0, 0, -1, 0) < 0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue