C-style update: Unified comment, retvals in order, remove trailing spaces
Changed function name for `clicon_debug` functions
This commit is contained in:
parent
6e314dd96f
commit
62348fc9c7
204 changed files with 6047 additions and 4904 deletions
|
|
@ -99,6 +99,8 @@ static int _netconf_hello_nr = 0;
|
|||
* includes any "xmlns" attributes.
|
||||
* @param[in] xrpc Incoming message on the form <rpc>...
|
||||
* @param[in,out] xrep Reply message on the form <rpc-reply>...
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
netconf_add_request_attr(cxobj *xrpc,
|
||||
|
|
@ -133,9 +135,14 @@ netconf_add_request_attr(cxobj *xrpc,
|
|||
}
|
||||
|
||||
/*! Process netconf hello message
|
||||
*
|
||||
* A server receiving a <hello> message with a <session-id> element MUST
|
||||
* terminate the NETCONF session.
|
||||
* @param[out] eof Request termination
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] xn
|
||||
* @param[out] eof Request termination
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
netconf_hello_msg(clicon_handle h,
|
||||
|
|
@ -152,7 +159,7 @@ netconf_hello_msg(clicon_handle h,
|
|||
int foundbase_11 = 0;
|
||||
char *body;
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
_netconf_hello_nr++;
|
||||
if (xml_find_type(xn, NULL, "session-id", CX_ELMNT) != NULL) {
|
||||
clicon_err(OE_XML, errno, "Server received hello with session-id from client, terminating (see RFC 6241 Sec 8.1");
|
||||
|
|
@ -172,12 +179,12 @@ netconf_hello_msg(clicon_handle h,
|
|||
* event any parameters are encoded at the end of the URI string. */
|
||||
if (strncmp(body, NETCONF_BASE_CAPABILITY_1_0, strlen(NETCONF_BASE_CAPABILITY_1_0)) == 0){ /* RFC 4741 */
|
||||
foundbase_10++;
|
||||
clicon_debug(1, "%s foundbase10", __FUNCTION__);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s foundbase10", __FUNCTION__);
|
||||
}
|
||||
else if (strncmp(body, NETCONF_BASE_CAPABILITY_1_1, strlen(NETCONF_BASE_CAPABILITY_1_1)) == 0 &&
|
||||
clicon_option_int(h, "CLICON_NETCONF_BASE_CAPABILITY") > 0){ /* RFC 6241 */
|
||||
foundbase_11++;
|
||||
clicon_debug(1, "%s foundbase11", __FUNCTION__);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s foundbase11", __FUNCTION__);
|
||||
clicon_data_int_set(h, NETCONF_FRAMING_TYPE, NETCONF_SSH_CHUNKED); /* enable chunked enc */
|
||||
}
|
||||
}
|
||||
|
|
@ -195,6 +202,7 @@ netconf_hello_msg(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! Process incoming Netconf RPC netconf message
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] xreq XML tree containing netconf RPC message
|
||||
* @param[in] yspec YANG spec
|
||||
|
|
@ -223,7 +231,7 @@ netconf_rpc_message(clicon_handle h,
|
|||
/* Copy attributes from incoming request to reply. Skip already present (dont overwrite) */
|
||||
if (netconf_add_request_attr(xrpc, xret) < 0)
|
||||
goto done;
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -239,12 +247,12 @@ netconf_rpc_message(clicon_handle h,
|
|||
if ((ret = xml_bind_yang_rpc(h, xrpc, yspec, &xret)) < 0)
|
||||
goto done;
|
||||
if (ret > 0 &&
|
||||
(ret = xml_yang_validate_rpc(h, xrpc, 0, &xret)) < 0)
|
||||
(ret = xml_yang_validate_rpc(h, xrpc, 0, &xret)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
if (netconf_add_request_attr(xrpc, xret) < 0)
|
||||
goto done;
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -265,7 +273,7 @@ netconf_rpc_message(clicon_handle h,
|
|||
goto done;
|
||||
if (netconf_add_request_attr(xrpc, xret) < 0)
|
||||
goto done;
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -281,7 +289,7 @@ netconf_rpc_message(clicon_handle h,
|
|||
/* Copy attributes from incoming request to reply. Skip already present (dont overwrite) */
|
||||
if (netconf_add_request_attr(xrpc, xc) < 0)
|
||||
goto done;
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -303,6 +311,7 @@ netconf_rpc_message(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! Process incoming a single netconf message parsed as XML
|
||||
*
|
||||
* Identify what netconf message it is
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] xreq XML tree containing netconf
|
||||
|
|
@ -325,8 +334,8 @@ netconf_input_packet(clicon_handle h,
|
|||
cxobj *xret = NULL;
|
||||
netconf_framing_type framing;
|
||||
|
||||
clicon_debug(1, "%s", __FUNCTION__);
|
||||
clicon_debug_xml(1, xreq, "%s", __FUNCTION__);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
clixon_debug_xml(1, xreq, "%s", __FUNCTION__);
|
||||
rpcname = xml_name(xreq);
|
||||
rpcprefix = xml_prefix(xreq);
|
||||
framing = clicon_data_int_get(h, NETCONF_FRAMING_TYPE);
|
||||
|
|
@ -339,7 +348,7 @@ netconf_input_packet(clicon_handle h,
|
|||
goto done;
|
||||
if (netconf_add_request_attr(xreq, xret) < 0)
|
||||
goto done;
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
if ((cbret = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -381,8 +390,11 @@ netconf_input_packet(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! Get netconf message: detect end-of-msg
|
||||
* @param[in] s Socket where input arrived. read from this.
|
||||
* @param[in] arg Clixon handle.
|
||||
*
|
||||
* @param[in] s Socket where input arrived. read from this.
|
||||
* @param[in] arg Clixon handle.
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* This routine continuously reads until no more data on s. There could
|
||||
* be risk of starvation, but the netconf client does little else than
|
||||
* read data so I do not see a danger of true starvation here.
|
||||
|
|
@ -418,7 +430,7 @@ netconf_input_cb(int s,
|
|||
unsigned char *p = buf;
|
||||
ssize_t len;
|
||||
size_t plen;
|
||||
|
||||
|
||||
yspec = clicon_dbspec_yang(h);
|
||||
/* Get unfinished frame */
|
||||
if ((ptr = clicon_hash_value(cdat, NETCONF_FRAME_MSG, &cdatlen)) != NULL){
|
||||
|
|
@ -457,14 +469,14 @@ netconf_input_cb(int s,
|
|||
&eom) < 0)
|
||||
goto done;
|
||||
if (eom == 0){ /* frame not complete */
|
||||
clicon_debug(CLIXON_DBG_DETAIL, "%s: frame: %lu", __FUNCTION__, cbuf_len(cbmsg));
|
||||
clixon_debug(CLIXON_DBG_DETAIL, "%s: frame: %lu", __FUNCTION__, cbuf_len(cbmsg));
|
||||
/* Extra data to read, save data and continue on next round */
|
||||
if (clicon_hash_add(cdat, NETCONF_FRAME_MSG, &cbmsg, sizeof(cbmsg)) == NULL)
|
||||
goto done;
|
||||
cbmsg = NULL;
|
||||
break;
|
||||
}
|
||||
clicon_debug(CLIXON_DBG_MSG, "Recv ext: %s", cbuf_get(cbmsg));
|
||||
clixon_debug(CLIXON_DBG_MSG, "Recv ext: %s", cbuf_get(cbmsg));
|
||||
if ((ret = netconf_input_frame2(cbmsg, YB_RPC, yspec, &xtop, &xerr)) < 0)
|
||||
goto done;
|
||||
cbuf_reset(cbmsg);
|
||||
|
|
@ -499,7 +511,7 @@ netconf_input_cb(int s,
|
|||
}
|
||||
}
|
||||
if (eof){ /* socket closed / read returns 0 */
|
||||
clicon_debug(1, "%s len==0, closing", __FUNCTION__);
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s len==0, closing", __FUNCTION__);
|
||||
clixon_event_unreg_fd(s, netconf_input_cb);
|
||||
close(s);
|
||||
clixon_exit_set(1);
|
||||
|
|
@ -522,16 +534,19 @@ netconf_input_cb(int s,
|
|||
}
|
||||
|
||||
/*! Send netconf hello message
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] s File descriptor to write on (eg 1 - stdout)
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
*/
|
||||
static int
|
||||
send_hello(clicon_handle h,
|
||||
int s,
|
||||
uint32_t id)
|
||||
{
|
||||
int retval = -1;
|
||||
cbuf *cb;
|
||||
int retval = -1;
|
||||
cbuf *cb;
|
||||
netconf_framing_type framing;
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
|
|
@ -553,6 +568,7 @@ send_hello(clicon_handle h,
|
|||
}
|
||||
|
||||
/*! Clean and close all state of netconf process (but dont exit).
|
||||
*
|
||||
* Cannot use h after this
|
||||
* @param[in] h Clixon handle
|
||||
*/
|
||||
|
|
@ -562,7 +578,7 @@ netconf_terminate(clicon_handle h)
|
|||
yang_stmt *yspec;
|
||||
cvec *nsctx;
|
||||
cxobj *x;
|
||||
|
||||
|
||||
if (clixon_exit_get() == 0)
|
||||
clixon_exit_set(1);
|
||||
/* Delete all plugins, and RPC callbacks */
|
||||
|
|
@ -591,7 +607,7 @@ static int
|
|||
netconf_signal_init (clicon_handle h)
|
||||
{
|
||||
int retval = -1;
|
||||
|
||||
|
||||
if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){
|
||||
clicon_err(OE_UNIX, errno, "Setting DIGPIPE signal");
|
||||
goto done;
|
||||
|
|
@ -606,10 +622,11 @@ timeout_fn(int s,
|
|||
void *arg)
|
||||
{
|
||||
clicon_err(OE_EVENTS, ETIMEDOUT, "User request timeout");
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*! Usage help routine
|
||||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] argv0 command line
|
||||
*/
|
||||
|
|
@ -666,12 +683,12 @@ main(int argc,
|
|||
size_t sz;
|
||||
int config_dump = 0;
|
||||
enum format_enum config_dump_format = FORMAT_XML;
|
||||
|
||||
|
||||
/* Create handle */
|
||||
if ((h = clicon_handle_init()) == NULL)
|
||||
return -1;
|
||||
/* In the startup, logs to stderr & debug flag set later */
|
||||
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
|
||||
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
|
||||
|
||||
/* Set username to clixon handle. Use in all communication to backend */
|
||||
if ((pw = getpwuid(getuid())) == NULL){
|
||||
|
|
@ -712,14 +729,14 @@ main(int argc,
|
|||
/*
|
||||
* Logs, error and debug to stderr or syslog, set debug level
|
||||
*/
|
||||
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
|
||||
clicon_debug_init(dbg, NULL);
|
||||
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
|
||||
clixon_debug_init(dbg, NULL);
|
||||
yang_init(h);
|
||||
|
||||
|
||||
/* Find, read and parse configfile */
|
||||
if (clicon_options_main(h) < 0)
|
||||
goto done;
|
||||
|
||||
|
||||
/* Now rest of options */
|
||||
optind = 1;
|
||||
opterr = 0;
|
||||
|
|
@ -822,23 +839,23 @@ main(int argc,
|
|||
/* Setup signal handlers, int particular PIPE that occurs if backend closes / restarts */
|
||||
if (netconf_signal_init(h) < 0)
|
||||
goto done;
|
||||
|
||||
|
||||
/* Initialize plugin module by creating a handle holding plugin and callback lists */
|
||||
if (clixon_plugin_module_init(h) < 0)
|
||||
goto done;
|
||||
/* In case ietf-yang-metadata is loaded by application, handle annotation extension */
|
||||
if (yang_metadata_init(h) < 0)
|
||||
goto done;
|
||||
goto done;
|
||||
/* Create top-level yang spec and store as option */
|
||||
if ((yspec = yspec_new()) == NULL)
|
||||
goto done;
|
||||
clicon_dbspec_yang_set(h, yspec);
|
||||
clicon_dbspec_yang_set(h, yspec);
|
||||
|
||||
/* Load netconf plugins before yangs are loaded (eg extension callbacks) */
|
||||
if ((dir = clicon_netconf_dir(h)) != NULL &&
|
||||
clixon_plugins_load(h, CLIXON_PLUGIN_INIT, dir, NULL) < 0)
|
||||
goto done;
|
||||
|
||||
|
||||
/* Load Yang modules
|
||||
* 1. Load a yang module as a specific absolute filename */
|
||||
if ((str = clicon_yang_main_file(h)) != NULL){
|
||||
|
|
@ -865,7 +882,7 @@ main(int argc,
|
|||
/* Add netconf yang spec, used by netconf client and as internal protocol */
|
||||
if (netconf_module_load(h) < 0)
|
||||
goto done;
|
||||
/* Here all modules are loaded
|
||||
/* Here all modules are loaded
|
||||
* Compute and set canonical namespace context
|
||||
*/
|
||||
if (xml_nsctx_yangspec(yspec, &nsctx_global) < 0)
|
||||
|
|
@ -894,7 +911,7 @@ main(int argc,
|
|||
if (clicon_hello_req(h, "cl:netconf", NULL, &id) < 0)
|
||||
goto done;
|
||||
clicon_session_id_set(h, id);
|
||||
|
||||
|
||||
/* Send hello to northbound client
|
||||
* Note that this is a violation of RDFC 6241 Sec 8.1:
|
||||
* When the NETCONF session is opened, each peer(both client and server) MUST send a <hello..
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue