* 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.
141 lines
4 KiB
C
141 lines
4 KiB
C
/*
|
|
*
|
|
***** BEGIN LICENSE BLOCK *****
|
|
|
|
Copyright (C) 2009-2018 Olof Hagsand and Benny Holmgren
|
|
|
|
This file is part of CLIXON.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
|
|
Alternatively, the contents of this file may be used under the terms of
|
|
the GNU General Public License Version 3 or later (the "GPL"),
|
|
in which case the provisions of the GPL are applicable instead
|
|
of those above. If you wish to allow use of your version of this file only
|
|
under the terms of the GPL, and not to allow others to
|
|
use your version of this file under the terms of Apache License version 2,
|
|
indicate your decision by deleting the provisions above and replace them with
|
|
the notice and other provisions required by the GPL. If you do not delete
|
|
the provisions above, a recipient may use your version of this file under
|
|
the terms of any one of the Apache License version 2 or the GPL.
|
|
|
|
***** END LICENSE BLOCK *****
|
|
|
|
*
|
|
* Code for handling netconf hello messages
|
|
*****************************************************************************/
|
|
/*
|
|
Capabilities are advertised in messages sent by each peer during
|
|
session establishment. When the NETCONF session is opened, each peer
|
|
(both client and server) MUST send a <hello> element containing a
|
|
list of that peer's capabilities. Each peer MUST send at least the
|
|
base NETCONF capability, "urn:ietf:params:netconf:base:1.0".
|
|
<hello>
|
|
<capabilities>
|
|
<capability>URI</capability>
|
|
</capabilities>
|
|
|
|
</hello>
|
|
*/
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "clixon_config.h" /* generated by config & autoconf */
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <errno.h>
|
|
#include <signal.h>
|
|
#include <fcntl.h>
|
|
#include <time.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/time.h>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <sys/param.h>
|
|
#include <assert.h>
|
|
|
|
/* cligen */
|
|
#include <cligen/cligen.h>
|
|
|
|
/* clicon */
|
|
#include <clixon/clixon.h>
|
|
|
|
#include "netconf_lib.h"
|
|
#include "netconf_hello.h"
|
|
|
|
static int
|
|
netconf_hello(cxobj *xn)
|
|
{
|
|
#ifdef nyi
|
|
cxobj *x;
|
|
|
|
x = NULL;
|
|
|
|
while ((x = xpath_each(xn, "//capability", x)) != NULL) {
|
|
|
|
}
|
|
#endif
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
netconf_hello_dispatch(cxobj *xn)
|
|
{
|
|
cxobj *xp;
|
|
int retval = -1;
|
|
|
|
if ((xp = xpath_first(xn, "//hello")) != NULL)
|
|
retval = netconf_hello(xp);
|
|
return retval;
|
|
}
|
|
|
|
/*! 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(clicon_handle h,
|
|
cbuf *cb,
|
|
int session_id)
|
|
{
|
|
int retval = -1;
|
|
char *module_set_id;
|
|
char *ietf_yang_library_revision;
|
|
|
|
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;
|
|
}
|