RFC 7895:

* Changed Netconf hello to single capabilty urn:ietf:params:netconf:capability:yang-library:1.0 according to YANG 1.1 RFC7950 Sec 5.6.4.
  * Set by option: CLICON_MODULE_LIBRARY_RFC7895 - enabled by default
  * Option CLICON_MODULE_SET_ID is set and changed when modules change.
This commit is contained in:
Olof hagsand 2018-10-12 18:39:33 +02:00
parent 507e03742d
commit 65c44b41e8
16 changed files with 385 additions and 122 deletions

View file

@ -105,28 +105,37 @@ netconf_hello_dispatch(cxobj *xn)
return retval;
}
/*
* netconf_create_hello
* create capability string (once)
/*! Create Netconf hello. Single cap and defer individual to querying modules
* This follows YANG 1.1 RFC7950 Sec 5.6.4, where a single capability announced
* and a client may query supported modules using RFC 7895 (Yang Module
* Library).
* @param[in] h Clicon handle
* @param[in] cb Msg buffer
* @param[in] session_id Id of client session
*/
int
netconf_create_hello(cbuf *xf, /* msg buffer */
int session_id)
netconf_create_hello(clicon_handle h,
cbuf *cb,
int session_id)
{
int retval = 0;
int retval = -1;
char *module_set_id;
char *ietf_yang_library_revision;
add_preamble(xf);
cprintf(xf, "<hello>");
cprintf(xf, "<capabilities>");
cprintf(xf, "<capability>urn:ietf:params:xml:ns:netconf:base:1.0</capability>\n");
cprintf(xf, "<capability>urn:ietf:params:xml:ns:netconf:capability:candidate:1:0</capability>\n");
cprintf(xf, "<capability>urn:ietf:params:xml:ns:netconf:capability:validate:1.0</capability>\n");
cprintf(xf, "<capability>urn:ietf:params:netconf:capability:xpath:1.0</capability>\n");
cprintf(xf, "<capability>urn:ietf:params:netconf:capability:notification:1.0</capability>\n");
cprintf(xf, "<capability>urn:ietf:params:netconf:capability:startup:1.0</capability>\n");
cprintf(xf, "</capabilities>");
cprintf(xf, "<session-id>%lu</session-id>", (long unsigned int)42+session_id);
cprintf(xf, "</hello>");
add_postamble(xf);
module_set_id = clicon_option_str(h, "CLICON_MODULE_SET_ID");
if ((ietf_yang_library_revision = yang_modules_revision(h)) == NULL)
goto done;
add_preamble(cb);
cprintf(cb, "<hello>");
cprintf(cb, "<capabilities>");
cprintf(cb, "<capability>urn:ietf:params:netconf:capability:yang-library:1.0?revision=\"%s\"&module-set-id=%s</capability>",
ietf_yang_library_revision,
module_set_id);
cprintf(cb, "</capabilities>");
cprintf(cb, "<session-id>%lu</session-id>", (long unsigned int)42+session_id);
cprintf(cb, "</hello>");
add_postamble(cb);
retval = 0;
done:
return retval;
}

View file

@ -40,7 +40,7 @@
/*
* Prototypes
*/
int netconf_create_hello(cbuf *xf, int session_id);
int netconf_create_hello(clicon_handle h, cbuf *cb, int session_id);
int netconf_hello_dispatch(cxobj *xn);

View file

@ -241,28 +241,29 @@ netconf_input_cb(int s,
return retval;
}
/*
* send_hello
* args: s file descriptor to write on (eg 1 - stdout)
/*! Send netconf hello message
* @param[in] h Clicon handle
* @param[in] s File descriptor to write on (eg 1 - stdout)
*/
static int
send_hello(int s)
send_hello(clicon_handle h,
int s)
{
cbuf *xf;
int retval = -1;
int retval = -1;
cbuf *cb;
if ((xf = cbuf_new()) == NULL){
if ((cb = cbuf_new()) == NULL){
clicon_log(LOG_ERR, "%s: cbuf_new", __FUNCTION__);
goto done;
}
if (netconf_create_hello(xf, getpid()) < 0)
if (netconf_create_hello(h, cb, getpid()) < 0)
goto done;
if (netconf_output(s, xf, "hello") < 0)
if (netconf_output(s, cb, "hello") < 0)
goto done;
retval = 0;
done:
if (xf)
cbuf_free(xf);
if (cb)
cbuf_free(cb);
return retval;
}
@ -461,7 +462,7 @@ main(int argc,
*(argv-1) = tmp;
if (!quiet)
send_hello(1);
send_hello(h, 1);
if (event_reg_fd(0, netconf_input_cb, h, "netconf socket") < 0)
goto done;
if (debug)