mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-05 11:48:50 +00:00
lib: change type of inner
to struct lyd_node *
, cleaner code
Signed-off-by: Christian Hopps <chopps@labn.net>
This commit is contained in:
parent
32a4c4019e
commit
7b7725f7b8
@ -51,7 +51,7 @@ PREDECL_LIST(nb_op_walks);
|
||||
* This is our information about a node on the branch we are looking at
|
||||
*/
|
||||
struct nb_op_node_info {
|
||||
struct lyd_node_inner *inner;
|
||||
struct lyd_node *inner;
|
||||
const struct lysc_node *schema; /* inner schema in case we rm inner */
|
||||
struct yang_list_keys keys; /* if list, keys to locate element */
|
||||
const void *list_entry; /* opaque entry from user or NULL */
|
||||
@ -183,7 +183,7 @@ static struct lyd_node *ys_root_node(struct nb_op_yield_state *ys)
|
||||
{
|
||||
if (!darr_len(ys->node_infos))
|
||||
return NULL;
|
||||
return &ys->node_infos[0].inner->node;
|
||||
return ys->node_infos[0].inner;
|
||||
}
|
||||
|
||||
static void ys_trim_xpath(struct nb_op_yield_state *ys)
|
||||
@ -210,7 +210,7 @@ static void ys_free_inner(struct nb_op_yield_state *ys,
|
||||
struct nb_op_node_info *ni)
|
||||
{
|
||||
if (!CHECK_FLAG(ni->schema->nodetype, LYS_CASE | LYS_CHOICE))
|
||||
lyd_free_tree(&ni->inner->node);
|
||||
lyd_free_tree(ni->inner);
|
||||
ni->inner = NULL;
|
||||
}
|
||||
|
||||
@ -415,7 +415,7 @@ static enum nb_error nb_op_ys_finalize_node_info(struct nb_op_yield_state *ys,
|
||||
uint index)
|
||||
{
|
||||
struct nb_op_node_info *ni = &ys->node_infos[index];
|
||||
struct lyd_node_inner *inner = ni->inner;
|
||||
struct lyd_node *inner = ni->inner;
|
||||
struct nb_node *nn = ni->schema->priv;
|
||||
bool yield_ok = ys->finish != NULL;
|
||||
|
||||
@ -425,13 +425,13 @@ static enum nb_error nb_op_ys_finalize_node_info(struct nb_op_yield_state *ys,
|
||||
ni->list_entry = index == 0 ? NULL : ni[-1].list_entry;
|
||||
|
||||
/* Assert that we are walking the rightmost branch */
|
||||
assert(!inner->parent || &inner->node == inner->parent->child->prev);
|
||||
assert(!inner->parent || inner == inner->parent->child->prev);
|
||||
|
||||
if (CHECK_FLAG(inner->schema->nodetype,
|
||||
LYS_CASE | LYS_CHOICE | LYS_CONTAINER)) {
|
||||
/* containers have only zero or one child on a branch of a tree */
|
||||
inner = (struct lyd_node_inner *)inner->child;
|
||||
assert(!inner || inner->prev == &inner->node);
|
||||
inner = ((struct lyd_node_inner *)inner)->child;
|
||||
assert(!inner || inner->prev == inner);
|
||||
ni->lookup_next_ok = yield_ok &&
|
||||
(index == 0 || ni[-1].lookup_next_ok);
|
||||
return NB_OK;
|
||||
@ -442,7 +442,7 @@ static enum nb_error nb_op_ys_finalize_node_info(struct nb_op_yield_state *ys,
|
||||
ni->lookup_next_ok = yield_ok && ni->has_lookup_next &&
|
||||
(index == 0 || ni[-1].lookup_next_ok);
|
||||
|
||||
nb_op_get_keys(inner, &ni->keys);
|
||||
nb_op_get_keys((struct lyd_node_inner *)inner, &ni->keys);
|
||||
|
||||
/* A list entry cannot be present in a tree w/o it's keys */
|
||||
assert(ni->keys.num == yang_snode_num_keys(inner->schema));
|
||||
@ -489,7 +489,7 @@ static enum nb_error nb_op_ys_finalize_node_info(struct nb_op_yield_state *ys,
|
||||
static enum nb_error nb_op_ys_init_node_infos(struct nb_op_yield_state *ys)
|
||||
{
|
||||
struct nb_op_node_info *ni;
|
||||
struct lyd_node_inner *inner;
|
||||
struct lyd_node *inner;
|
||||
struct lyd_node *node = NULL;
|
||||
enum nb_error ret;
|
||||
uint i, len;
|
||||
@ -521,9 +521,9 @@ static enum nb_error nb_op_ys_init_node_infos(struct nb_op_yield_state *ys)
|
||||
if (!node)
|
||||
return NB_ERR_NOT_FOUND;
|
||||
|
||||
inner = (struct lyd_node_inner *)node;
|
||||
inner = node;
|
||||
for (len = 1; inner->parent; len++)
|
||||
inner = inner->parent;
|
||||
inner = &inner->parent->node;
|
||||
|
||||
darr_append_nz_mt(ys->node_infos, len, MTYPE_NB_NODE_INFOS);
|
||||
|
||||
@ -531,8 +531,8 @@ static enum nb_error nb_op_ys_init_node_infos(struct nb_op_yield_state *ys)
|
||||
* For each node find the prefix of the xpath query that identified it
|
||||
* -- save the prefix length.
|
||||
*/
|
||||
inner = (struct lyd_node_inner *)node;
|
||||
for (i = len; i > 0; i--, inner = inner->parent) {
|
||||
inner = node;
|
||||
for (i = len; i > 0; i--, inner = &inner->parent->node) {
|
||||
ni = &ys->node_infos[i - 1];
|
||||
ni->inner = inner;
|
||||
ni->schema = inner->schema;
|
||||
@ -542,7 +542,7 @@ static enum nb_error nb_op_ys_init_node_infos(struct nb_op_yield_state *ys)
|
||||
* since the number of nodes is small and only done once per
|
||||
* query.
|
||||
*/
|
||||
tmp = yang_dnode_get_path(&inner->node, NULL, 0);
|
||||
tmp = yang_dnode_get_path(inner, NULL, 0);
|
||||
ni->xpath_len = strlen(tmp);
|
||||
|
||||
/* Replace users supplied xpath with the libyang returned value */
|
||||
@ -563,7 +563,7 @@ static enum nb_error nb_op_ys_init_node_infos(struct nb_op_yield_state *ys)
|
||||
ret = nb_op_ys_finalize_node_info(ys, i);
|
||||
if (ret != NB_OK) {
|
||||
if (ys->node_infos[0].inner)
|
||||
lyd_free_all(&ys->node_infos[0].inner->node);
|
||||
lyd_free_all(ys->node_infos[0].inner);
|
||||
darr_free(ys->node_infos);
|
||||
return ret;
|
||||
}
|
||||
@ -610,8 +610,8 @@ static enum nb_error nb_op_iter_leaf(struct nb_op_yield_state *ys,
|
||||
return NB_OK;
|
||||
|
||||
/* Add a dnode to our tree */
|
||||
err = lyd_new_term(&ni->inner->node, snode->module, snode->name,
|
||||
data->value, false, NULL);
|
||||
err = lyd_new_term(ni->inner, snode->module, snode->name, data->value,
|
||||
false, NULL);
|
||||
if (err) {
|
||||
yang_data_free(data);
|
||||
return NB_ERR_RESOURCE;
|
||||
@ -652,7 +652,7 @@ static enum nb_error nb_op_iter_leaflist(struct nb_op_yield_state *ys,
|
||||
continue;
|
||||
|
||||
/* Add a dnode to our tree */
|
||||
err = lyd_new_term(&ni->inner->node, snode->module, snode->name,
|
||||
err = lyd_new_term(ni->inner, snode->module, snode->name,
|
||||
data->value, false, NULL);
|
||||
if (err) {
|
||||
yang_data_free(data);
|
||||
@ -917,6 +917,13 @@ static enum nb_error __walk(struct nb_op_yield_state *ys, bool is_resume)
|
||||
if (!walk_stem_tip)
|
||||
return NB_ERR_NOT_FOUND;
|
||||
|
||||
if (ys->schema_path[0]->nodetype == LYS_CHOICE) {
|
||||
flog_err(EC_LIB_NB_OPERATIONAL_DATA,
|
||||
"%s: unable to walk root level choice node from module: %s",
|
||||
__func__, ys->schema_path[0]->module->name);
|
||||
return NB_ERR;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we are resuming then start with the list container on top.
|
||||
* Otherwise get the first child of the container we are walking,
|
||||
@ -972,7 +979,7 @@ static enum nb_error __walk(struct nb_op_yield_state *ys, bool is_resume)
|
||||
* remove the node from the tree.
|
||||
*/
|
||||
if (sib->nodetype == LYS_CONTAINER &&
|
||||
!lyd_child(&ni->inner->node) &&
|
||||
!lyd_child(ni->inner) &&
|
||||
!nb_op_empty_container_ok(sib, ys->xpath,
|
||||
ni->list_entry))
|
||||
ys_free_inner(ys, ni);
|
||||
@ -1061,11 +1068,11 @@ static enum nb_error __walk(struct nb_op_yield_state *ys, bool is_resume)
|
||||
|
||||
if (sib->nodetype != LYS_CONTAINER) {
|
||||
/* Case/choice use parent inner. */
|
||||
node = &ni->inner->node;
|
||||
/* TODO: thus we don't support root level choice */
|
||||
node = ni->inner;
|
||||
} else {
|
||||
err = lyd_new_inner(&ni->inner->node,
|
||||
sib->module, sib->name,
|
||||
false, &node);
|
||||
err = lyd_new_inner(ni->inner, sib->module,
|
||||
sib->name, false, &node);
|
||||
if (err) {
|
||||
ret = NB_ERR_RESOURCE;
|
||||
goto done;
|
||||
@ -1074,7 +1081,7 @@ static enum nb_error __walk(struct nb_op_yield_state *ys, bool is_resume)
|
||||
|
||||
/* push this choice/container node on top of the stack */
|
||||
ni = darr_appendz(ys->node_infos);
|
||||
ni->inner = (struct lyd_node_inner *)node;
|
||||
ni->inner = node;
|
||||
ni->schema = sib;
|
||||
ni->lookup_next_ok = ni[-1].lookup_next_ok;
|
||||
ni->list_entry = ni[-1].list_entry;
|
||||
@ -1172,7 +1179,7 @@ static enum nb_error __walk(struct nb_op_yield_state *ys, bool is_resume)
|
||||
at_clevel <= darr_lasti(ys->query_tokens) &&
|
||||
!ys->non_specific_predicate[at_clevel] &&
|
||||
nb_op_schema_path_has_predicate(ys, at_clevel)) {
|
||||
err = lyd_new_path(&pni->inner->node, NULL,
|
||||
err = lyd_new_path(pni->inner, NULL,
|
||||
ys->query_tokens[at_clevel],
|
||||
NULL, 0, &node);
|
||||
if (!err)
|
||||
@ -1295,7 +1302,7 @@ static enum nb_error __walk(struct nb_op_yield_state *ys, bool is_resume)
|
||||
* and do not reap if true.
|
||||
*/
|
||||
if (!list_start && ni->inner &&
|
||||
!lyd_child_no_keys(&ni->inner->node) &&
|
||||
!lyd_child_no_keys(ni->inner) &&
|
||||
/* not the top element with a key match */
|
||||
!((darr_ilen(ys->node_infos) ==
|
||||
darr_ilen(ys->schema_path) - 1) &&
|
||||
@ -1434,8 +1441,10 @@ static enum nb_error __walk(struct nb_op_yield_state *ys, bool is_resume)
|
||||
*/
|
||||
|
||||
if (!node) {
|
||||
err = yang_lyd_new_list(ni[-1].inner, sib,
|
||||
&ni->keys, &node);
|
||||
err = yang_lyd_new_list((struct lyd_node_inner *)
|
||||
ni[-1]
|
||||
.inner,
|
||||
sib, &ni->keys, &node);
|
||||
if (err) {
|
||||
darr_pop(ys->node_infos);
|
||||
ret = NB_ERR_RESOURCE;
|
||||
@ -1446,7 +1455,7 @@ static enum nb_error __walk(struct nb_op_yield_state *ys, bool is_resume)
|
||||
/*
|
||||
* Save the new list entry with the list node info
|
||||
*/
|
||||
ni->inner = (struct lyd_node_inner *)node;
|
||||
ni->inner = node;
|
||||
ni->schema = node->schema;
|
||||
ni->list_entry = list_entry;
|
||||
ni->niters += 1;
|
||||
@ -1550,13 +1559,13 @@ static void nb_op_trim_yield_state(struct nb_op_yield_state *ys)
|
||||
assert(ni->has_lookup_next);
|
||||
|
||||
DEBUGD(&nb_dbg_events, "NB oper-state: deleting tree at level %d", i);
|
||||
__free_siblings(&ni->inner->node);
|
||||
__free_siblings(ni->inner);
|
||||
ys_free_inner(ys, ni);
|
||||
|
||||
while (--i > 0) {
|
||||
DEBUGD(&nb_dbg_events,
|
||||
"NB oper-state: deleting siblings at level: %d", i);
|
||||
__free_siblings(&ys->node_infos[i].inner->node);
|
||||
__free_siblings(ys->node_infos[i].inner);
|
||||
}
|
||||
DEBUGD(&nb_dbg_events, "NB oper-state: stop trimming: new top: %d",
|
||||
(int)darr_lasti(ys->node_infos));
|
||||
|
Loading…
Reference in New Issue
Block a user