extern void yang_dnode_set_entry(const struct lyd_node *dnode, void *entry);
/*
- * Find the closest data node that contains an user pointer and return it.
+ * Find the user pointer associated to the given libyang data node.
+ *
+ * The data node is traversed by following the parent pointers until an user
+ * pointer is found or until the root node is reached.
*
* dnode
* libyang data node to operate on.
*
+ * abort_if_not_found
+ * When set to true, abort the program if no user pointer is found.
+ *
+ * As a rule of thumb, this parameter should be set to true in the following
+ * scenarios:
+ * - Calling this function from any northbound configuration callback during
+ * the NB_EV_APPLY phase.
+ * - Calling this function from a 'delete' northbound configuration callback
+ * during any phase.
+ *
+ * In both the above cases, the libyang data node should contain an user
+ * pointer except when there's a bug in the code, in which case it's better
+ * to abort the program right away and eliminate the need for unnecessary
+ * NULL checks.
+ *
+ * In all other cases, this parameter should be set to false and the caller
+ * should check if the function returned NULL or not.
+ *
* Returns:
* User pointer if found, NULL otherwise.
*/
-extern void *yang_dnode_get_entry(const struct lyd_node *dnode);
+extern void *yang_dnode_get_entry(const struct lyd_node *dnode,
+ bool abort_if_not_found);
/*
* Create a new libyang data node.
if (event != NB_EV_APPLY)
return NB_OK;
- rn = yang_dnode_get_entry(dnode);
+ rn = yang_dnode_get_entry(dnode, true);
rdistance = rn->info;
if (rdistance->access_list)
free(rdistance->access_list);
return NB_OK;
/* Set distance value. */
- rn = yang_dnode_get_entry(dnode);
+ rn = yang_dnode_get_entry(dnode, true);
distance = yang_dnode_get_uint8(dnode, NULL);
rdistance = rn->info;
rdistance->distance = distance;
acl_name = yang_dnode_get_string(dnode, NULL);
/* Set access-list */
- rn = yang_dnode_get_entry(dnode);
+ rn = yang_dnode_get_entry(dnode, true);
rdistance = rn->info;
if (rdistance->access_list)
free(rdistance->access_list);
return NB_OK;
/* Reset access-list configuration. */
- rn = yang_dnode_get_entry(dnode);
+ rn = yang_dnode_get_entry(dnode, true);
rdistance = rn->info;
free(rdistance->access_list);
rdistance->access_list = NULL;
direct = yang_dnode_get_enum(dnode, "./direction");
- offset = yang_dnode_get_entry(dnode);
+ offset = yang_dnode_get_entry(dnode, true);
if (offset->direct[direct].alist_name) {
free(offset->direct[direct].alist_name);
offset->direct[direct].alist_name = NULL;
direct = yang_dnode_get_enum(dnode, "../direction");
alist_name = yang_dnode_get_string(dnode, NULL);
- offset = yang_dnode_get_entry(dnode);
+ offset = yang_dnode_get_entry(dnode, true);
if (offset->direct[direct].alist_name)
free(offset->direct[direct].alist_name);
offset->direct[direct].alist_name = strdup(alist_name);
direct = yang_dnode_get_enum(dnode, "../direction");
metric = yang_dnode_get_uint8(dnode, NULL);
- offset = yang_dnode_get_entry(dnode);
+ offset = yang_dnode_get_entry(dnode, true);
offset->direct[direct].metric = metric;
return NB_OK;
if (event != NB_EV_APPLY)
return NB_OK;
- ifp = yang_dnode_get_entry(dnode);
+ ifp = yang_dnode_get_entry(dnode, true);
ri = ifp->info;
ri->split_horizon = yang_dnode_get_enum(dnode, NULL);
if (event != NB_EV_APPLY)
return NB_OK;
- ifp = yang_dnode_get_entry(dnode);
+ ifp = yang_dnode_get_entry(dnode, true);
ri = ifp->info;
ri->v2_broadcast = yang_dnode_get_bool(dnode, NULL);
if (event != NB_EV_APPLY)
return NB_OK;
- ifp = yang_dnode_get_entry(dnode);
+ ifp = yang_dnode_get_entry(dnode, true);
ri = ifp->info;
ri->ri_receive = yang_dnode_get_enum(dnode, NULL);
if (event != NB_EV_APPLY)
return NB_OK;
- ifp = yang_dnode_get_entry(dnode);
+ ifp = yang_dnode_get_entry(dnode, true);
ri = ifp->info;
ri->ri_send = yang_dnode_get_enum(dnode, NULL);
if (event != NB_EV_APPLY)
return NB_OK;
- ifp = yang_dnode_get_entry(dnode);
+ ifp = yang_dnode_get_entry(dnode, true);
ri = ifp->info;
ri->auth_type = yang_dnode_get_enum(dnode, NULL);
if (event != NB_EV_APPLY)
return NB_OK;
- ifp = yang_dnode_get_entry(dnode);
+ ifp = yang_dnode_get_entry(dnode, true);
ri = ifp->info;
ri->md5_auth_len = yang_dnode_get_enum(dnode, NULL);
if (event != NB_EV_APPLY)
return NB_OK;
- ifp = yang_dnode_get_entry(dnode);
+ ifp = yang_dnode_get_entry(dnode, true);
ri = ifp->info;
ri->md5_auth_len = yang_get_default_enum(
"%s/authentication-scheme/md5-auth-length", RIP_IFACE);
if (event != NB_EV_APPLY)
return NB_OK;
- ifp = yang_dnode_get_entry(dnode);
+ ifp = yang_dnode_get_entry(dnode, true);
ri = ifp->info;
if (ri->auth_str)
XFREE(MTYPE_RIP_INTERFACE_STRING, ri->auth_str);
if (event != NB_EV_APPLY)
return NB_OK;
- ifp = yang_dnode_get_entry(dnode);
+ ifp = yang_dnode_get_entry(dnode, true);
ri = ifp->info;
XFREE(MTYPE_RIP_INTERFACE_STRING, ri->auth_str);
if (event != NB_EV_APPLY)
return NB_OK;
- ifp = yang_dnode_get_entry(dnode);
+ ifp = yang_dnode_get_entry(dnode, true);
ri = ifp->info;
if (ri->key_chain)
XFREE(MTYPE_RIP_INTERFACE_STRING, ri->key_chain);
if (event != NB_EV_APPLY)
return NB_OK;
- ifp = yang_dnode_get_entry(dnode);
+ ifp = yang_dnode_get_entry(dnode, true);
ri = ifp->info;
XFREE(MTYPE_RIP_INTERFACE_STRING, ri->key_chain);