Merge branch 'snmp'
This commit is contained in:
commit
1d78241115
47 changed files with 8494 additions and 46 deletions
|
|
@ -124,6 +124,7 @@ static struct errvec EV[] = {
|
|||
{"Undefined", OE_UNDEF},
|
||||
/* From here error extensions using clixon_err_cat_reg */
|
||||
{"OpenSSL error", OE_SSL},
|
||||
{"SNMP error", OE_SNMP},
|
||||
{"Nghttp2 error", OE_NGHTTP2},
|
||||
{NULL, -1}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ static const map_str2int yang_regexp_map[] = {
|
|||
* @param[in] dbglevel Debug level
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* @note CLICON_FEATURE and CLICON_YANG_DIR are treated specially since they are lists
|
||||
* @note CLICON_FEATURE, CLICON_YANG_DIR and CLICON_SNMP_MIB are treated specially since they are lists
|
||||
*/
|
||||
int
|
||||
clicon_option_dump(clicon_handle h,
|
||||
|
|
@ -161,7 +161,7 @@ clicon_option_dump(clicon_handle h,
|
|||
else
|
||||
clicon_debug(dbglevel, "%s = NULL", keys[i]);
|
||||
}
|
||||
/* Next print CLICON_FEATURE and CLICON_YANG_DIR from config tree
|
||||
/* Next print CLICON_FEATURE, CLICON_YANG_DIR and CLICON_SNMP_DIR from config tree
|
||||
* Since they are lists they are placed in the config tree.
|
||||
*/
|
||||
x = NULL;
|
||||
|
|
@ -176,6 +176,12 @@ clicon_option_dump(clicon_handle h,
|
|||
continue;
|
||||
clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x));
|
||||
}
|
||||
x = NULL;
|
||||
while ((x = xml_child_each(clicon_conf_xml(h), x, CX_ELMNT)) != NULL) {
|
||||
if (strcmp(xml_name(x), "CLICON_SNMP_MIB") != 0)
|
||||
continue;
|
||||
clicon_debug(dbglevel, "%s =\t \"%s\"", xml_name(x), xml_body(x));
|
||||
}
|
||||
retval = 0;
|
||||
done:
|
||||
if (keys)
|
||||
|
|
@ -333,7 +339,8 @@ parse_configfile(clicon_handle h,
|
|||
continue;
|
||||
/* List options for configure options that are lists or leaf-lists: append to main */
|
||||
if (strcmp(name,"CLICON_FEATURE")==0 ||
|
||||
strcmp(name,"CLICON_YANG_DIR")==0){
|
||||
strcmp(name,"CLICON_YANG_DIR")==0 ||
|
||||
strcmp(name,"CLICON_SNMP_MIB")==0){
|
||||
if (xml_addsub(xt, xec) < 0)
|
||||
goto done;
|
||||
continue;
|
||||
|
|
@ -381,6 +388,8 @@ parse_configfile(clicon_handle h,
|
|||
continue;
|
||||
if (strcmp(name,"CLICON_YANG_DIR")==0)
|
||||
continue;
|
||||
if (strcmp(name,"CLICON_SNMP_MIB")==0)
|
||||
continue;
|
||||
if (clicon_hash_add(copt,
|
||||
name,
|
||||
body,
|
||||
|
|
@ -424,7 +433,8 @@ clicon_option_add(clicon_handle h,
|
|||
cxobj *x;
|
||||
|
||||
if (strcmp(name, "CLICON_FEATURE")==0 ||
|
||||
strcmp(name, "CLICON_YANG_DIR")==0){
|
||||
strcmp(name, "CLICON_YANG_DIR")==0 ||
|
||||
strcmp(name, "CLICON_SNMP_MIB")==0){
|
||||
if ((x = clicon_conf_xml(h)) == NULL){
|
||||
clicon_err(OE_UNIX, ENOENT, "option %s not found (clicon_conf_xml_set has not been called?)", name);
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -386,6 +386,8 @@ yang2api_path_fmt_1(yang_stmt *ys,
|
|||
* @param[in] ys Yang statement
|
||||
* @param[in] inclkey If set include key leaf (eg last leaf d in ex)
|
||||
* @param[out] api_path_fmt XML api path. Needs to be freed after use.
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
* "api-path" is "URI-encoded path expression" definition in RFC8040 3.5.3
|
||||
*/
|
||||
int
|
||||
|
|
@ -424,7 +426,7 @@ yang2api_path_fmt(yang_stmt *ys,
|
|||
* @param[in] api_path_fmt XML key format, eg /aaa/%s/name
|
||||
* @param[in] cvv cligen variable vector, one for every wildchar in api_path_fmt
|
||||
* @param[out] api_path api_path, eg /aaa/17. Free after use
|
||||
* @param[out] cvvi 1..cvv-len. Index into cvv of last cvv entry used, For example,
|
||||
* @param[out] cvv_i 1..cvv-len. Index into cvv of last cvv entry used, For example,
|
||||
* if same as len of cvv, all were used, if < some entries were not
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
|
|
@ -902,7 +904,7 @@ api_path2xpath(char *api_path,
|
|||
* @param[in] nodeclass Set to schema nodes, data nodes, etc
|
||||
* @param[in] strict Break if api-path is not "complete" otherwise ignore and continue
|
||||
* @param[out] xbotp Resulting xml tree
|
||||
* @param[out] ybotp Yang spec matching xpathp
|
||||
* @param[out] ybotp Yang spec matching xpathp
|
||||
* @param[out] xerr Netconf error message (if retval=0)
|
||||
* @retval 1 OK
|
||||
* @retval 0 Invalid api_path or associated XML, netconf error
|
||||
|
|
@ -1144,7 +1146,7 @@ api_path2xml_vec(char **vec,
|
|||
* @param[in,out] xtop Incoming XML tree
|
||||
* @param[in] nodeclass Set to schema nodes, data nodes, etc
|
||||
* @param[in] strict Break if api-path is not "complete" otherwise ignore and continue
|
||||
* @param[out] xbotp Resulting xml tree (end of xpath)
|
||||
* @param[out] xbotp Resulting xml tree (end of xpath) (optional)
|
||||
* @param[out] ybotp Yang spec matching xbotp
|
||||
* @param[out] xerr Netconf error message (if retval=0)
|
||||
* @retval 1 OK
|
||||
|
|
|
|||
|
|
@ -186,7 +186,7 @@ clicon_rpc_msg(clicon_handle h,
|
|||
#ifdef RPC_USERNAME_ASSERT
|
||||
assert(strstr(msg->op_body, "username")!=NULL); /* XXX */
|
||||
#endif
|
||||
clicon_debug(1, "%s request:%s", __FUNCTION__, msg->op_body);
|
||||
clicon_debug(2, "%s request:%s", __FUNCTION__, msg->op_body);
|
||||
/* Create a socket and connect to it, either UNIX, IPv4 or IPv6 per config options */
|
||||
if (clicon_rpc_msg_once(h, msg, &retdata, &eof, &s) < 0)
|
||||
goto done;
|
||||
|
|
@ -215,7 +215,7 @@ clicon_rpc_msg(clicon_handle h,
|
|||
goto done;
|
||||
#endif
|
||||
}
|
||||
clicon_debug(1, "%s retdata:%s", __FUNCTION__, retdata);
|
||||
clicon_debug(2, "%s retdata:%s", __FUNCTION__, retdata);
|
||||
|
||||
if (retdata){
|
||||
/* Cannot populate xret here because need to know RPC name (eg "lock") in order to associate yang
|
||||
|
|
@ -581,7 +581,7 @@ clicon_rpc_get_config(clicon_handle h,
|
|||
* @note xml arg need to have <config> as top element
|
||||
* @code
|
||||
* if (clicon_rpc_edit_config(h, "running", OP_MERGE,
|
||||
* "<config><a>4</a></config>") < 0)
|
||||
* "<config><a xmlns="urn:example:clixon">4</a></config>") < 0)
|
||||
* err;
|
||||
* @endcode
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1810,6 +1810,74 @@ xml_merge(cxobj *x0,
|
|||
goto done;
|
||||
}
|
||||
|
||||
/*! Given a YANG (enum) type node and a value, return the string containing corresponding int str
|
||||
*
|
||||
* @param[in] ytype YANG type noden
|
||||
* @param[in] valstr Integer string value
|
||||
* @param[out] enumstr Value of enum, dont free
|
||||
*/
|
||||
int
|
||||
yang_valstr2enum(yang_stmt *ytype,
|
||||
char *valstr,
|
||||
char **enumstr)
|
||||
{
|
||||
int retval = -1;
|
||||
yang_stmt *yenum = NULL;
|
||||
yang_stmt *yval;
|
||||
|
||||
if (enumstr == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "str is NULL");
|
||||
goto done;
|
||||
}
|
||||
while ((yenum = yn_each(ytype, yenum)) != NULL) {
|
||||
if ((yval = yang_find(yenum, Y_VALUE, NULL)) == NULL)
|
||||
goto done;
|
||||
if (strcmp(yang_argument_get(yval), valstr) == 0)
|
||||
break;
|
||||
}
|
||||
if (yenum)
|
||||
*enumstr = yang_argument_get(yenum);
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Given a YANG (enum) type node and a value, return the string containing corresponding int str
|
||||
*
|
||||
* @param[in] ytype YANG type noden
|
||||
* @param[in] enumstr Value of enum
|
||||
* @param[out] valstr Corresponding string containing an int (direct pointer, dont free)
|
||||
* @retval 1 OK, result in valstr
|
||||
* @retval 0 Invalid, not found
|
||||
* @retval -1 Error
|
||||
*/
|
||||
int
|
||||
yang_enum2valstr(yang_stmt *ytype,
|
||||
char *enumstr,
|
||||
char **valstr)
|
||||
{
|
||||
int retval = -1;
|
||||
yang_stmt *yenum;
|
||||
yang_stmt *yval;
|
||||
|
||||
if (valstr == NULL){
|
||||
clicon_err(OE_UNIX, EINVAL, "valstr is NULL");
|
||||
goto done;
|
||||
}
|
||||
if ((yenum = yang_find(ytype, Y_ENUM, enumstr)) == NULL)
|
||||
goto fail;
|
||||
/* Should assign value if yval not found */
|
||||
if ((yval = yang_find(yenum, Y_VALUE, NULL)) == NULL)
|
||||
goto done;
|
||||
*valstr = yang_argument_get(yval);
|
||||
retval = 1;
|
||||
done:
|
||||
return retval;
|
||||
fail:
|
||||
retval = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/*! Get integer value from xml node from yang enumeration
|
||||
* @param[in] node XML node in a tree
|
||||
* @param[out] val Integer value returned
|
||||
|
|
@ -1832,9 +1900,8 @@ yang_enum_int_value(cxobj *node,
|
|||
yang_stmt *ys;
|
||||
yang_stmt *ytype;
|
||||
yang_stmt *yrestype; /* resolved type */
|
||||
yang_stmt *yenum;
|
||||
yang_stmt *yval;
|
||||
char *reason = NULL;
|
||||
char *intstr = NULL;
|
||||
|
||||
if (node == NULL)
|
||||
goto done;
|
||||
|
|
@ -1853,20 +1920,16 @@ yang_enum_int_value(cxobj *node,
|
|||
}
|
||||
if (yrestype==NULL || strcmp(yang_argument_get(yrestype), "enumeration"))
|
||||
goto done;
|
||||
if ((yenum = yang_find(yrestype, Y_ENUM, xml_body(node))) == NULL)
|
||||
goto done;
|
||||
/* Should assign value if yval not found */
|
||||
if ((yval = yang_find(yenum, Y_VALUE, NULL)) == NULL)
|
||||
if (yang_enum2valstr(yrestype, xml_body(node), &intstr) < 0)
|
||||
goto done;
|
||||
/* reason is string containing why int could not be parsed */
|
||||
if (parse_int32(yang_argument_get(yval), val, &reason) < 0)
|
||||
if (parse_int32(intstr, val, &reason) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/*! Given XML tree x0 with marked nodes, copy marked nodes to new tree x1
|
||||
* Two marks are used: XML_FLAG_MARK and XML_FLAG_CHANGE
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1364,7 +1364,7 @@ yang_find_prefix_by_namespace(yang_stmt *ys,
|
|||
goto done;
|
||||
}
|
||||
|
||||
/*! Given a yang statement and local prefi valid in module , find namespace
|
||||
/*! Given a yang statement and local prefix valid in module, find namespace
|
||||
*
|
||||
* @param[in] ys Yang statement in module tree (or module itself)
|
||||
* @param[in] prefix Local prefix to access module with (direct pointer)
|
||||
|
|
@ -3661,7 +3661,7 @@ yang_anydata_add(yang_stmt *yp,
|
|||
|
||||
/*! Find extension argument and return if extension exists and its argument value
|
||||
*
|
||||
* @param[in] ys Yang statement where unknown statement may occur referncing to extension
|
||||
* @param[in] ys Yang statement where unknown statement may occur referencing to extension
|
||||
* @param[in] name Name of the extension
|
||||
* @param[in] ns The namespace of the module where the extension is defined
|
||||
* @param[out] exist The extension exists.
|
||||
|
|
@ -3678,7 +3678,7 @@ yang_anydata_add(yang_stmt *yp,
|
|||
* // use extension value
|
||||
* }
|
||||
* @endcode
|
||||
* @see ys_populate_unknown Called when parsing YANGo
|
||||
* @see ys_populate_unknown Called when parsing YANG
|
||||
*/
|
||||
int
|
||||
yang_extension_value(yang_stmt *ys,
|
||||
|
|
|
|||
|
|
@ -474,7 +474,7 @@ ys_do_refine(yang_stmt *yr,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Yang node yg is a leaf in yang node list yn
|
||||
/*! Check if Yang node y is a leaf in yang node list yp
|
||||
* Could be made to a generic function used elsewhere as well
|
||||
* @param[in] y Yang leaf
|
||||
* @param[in] yp Yang list parent
|
||||
|
|
@ -504,7 +504,6 @@ ys_iskey(yang_stmt *y,
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*! Helper function to yang_expand_grouping
|
||||
* @param[in] yn Yang parent node of uses ststement
|
||||
* @param[in] ys Uses statement
|
||||
|
|
@ -790,7 +789,10 @@ yang_parse_str(char *str,
|
|||
if (yang_scan_exit(&yy) < 0)
|
||||
goto done;
|
||||
}
|
||||
ymod = yy.yy_module;
|
||||
if ((ymod = yy.yy_module) == NULL){
|
||||
clicon_err(OE_YANG, 0, "No module in YANG %s", name);
|
||||
goto done;
|
||||
}
|
||||
/* Add filename for debugging and errors, see also ys_linenum on (each symbol?) */
|
||||
if (yang_filename_set(ymod, name) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue