forked from Mirror/frr
lib: make it possible to create YANG data nodes containing state data
By default the data nodes created by yang_dnode_new() could contain only configuration data (LYD_OPT_CONFIG). Add a 'config_only' option to yang_dnode_new() so that it can create data nodes containing both configuration and state data. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
parent
80243aef05
commit
5e02643a64
|
@ -189,7 +189,7 @@ struct nb_config *nb_config_new(struct lyd_node *dnode)
|
|||
if (dnode)
|
||||
config->dnode = dnode;
|
||||
else
|
||||
config->dnode = yang_dnode_new(ly_native_ctx);
|
||||
config->dnode = yang_dnode_new(ly_native_ctx, true);
|
||||
config->version = 0;
|
||||
|
||||
return config;
|
||||
|
|
10
lib/yang.c
10
lib/yang.c
|
@ -496,12 +496,18 @@ void *yang_dnode_get_entry(const struct lyd_node *dnode)
|
|||
abort();
|
||||
}
|
||||
|
||||
struct lyd_node *yang_dnode_new(struct ly_ctx *ly_ctx)
|
||||
struct lyd_node *yang_dnode_new(struct ly_ctx *ly_ctx, bool config_only)
|
||||
{
|
||||
struct lyd_node *dnode;
|
||||
int options;
|
||||
|
||||
if (config_only)
|
||||
options = LYD_OPT_CONFIG;
|
||||
else
|
||||
options = LYD_OPT_DATA | LYD_OPT_DATA_NO_YANGLIB;
|
||||
|
||||
dnode = NULL;
|
||||
if (lyd_validate(&dnode, LYD_OPT_CONFIG, ly_ctx) != 0) {
|
||||
if (lyd_validate(&dnode, options, ly_ctx) != 0) {
|
||||
/* Should never happen. */
|
||||
flog_err(EC_LIB_LIBYANG, "%s: lyd_validate() failed", __func__);
|
||||
exit(1);
|
||||
|
|
|
@ -371,10 +371,14 @@ extern void *yang_dnode_get_entry(const struct lyd_node *dnode);
|
|||
* ly_ctx
|
||||
* libyang context to operate on.
|
||||
*
|
||||
* config
|
||||
* Specify whether the data node will contain only configuration data (true)
|
||||
* or both configuration data and state data (false).
|
||||
*
|
||||
* Returns:
|
||||
* Pointer to newly created libyang data node.
|
||||
*/
|
||||
extern struct lyd_node *yang_dnode_new(struct ly_ctx *ly_ctx);
|
||||
extern struct lyd_node *yang_dnode_new(struct ly_ctx *ly_ctx, bool config_only);
|
||||
|
||||
/*
|
||||
* Duplicate a libyang data node.
|
||||
|
|
|
@ -351,7 +351,7 @@ int yang_translate_dnode(const struct yang_translator *translator, int dir,
|
|||
ly_ctx = ly_native_ctx;
|
||||
else
|
||||
ly_ctx = translator->ly_ctx;
|
||||
new = yang_dnode_new(ly_ctx);
|
||||
new = yang_dnode_new(ly_ctx, false);
|
||||
|
||||
/* Iterate over all nodes from the data tree. */
|
||||
LY_TREE_FOR (*dnode, root) {
|
||||
|
|
Loading…
Reference in a new issue