summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/northbound.c6
-rw-r--r--lib/northbound.h53
-rw-r--r--lib/northbound_oper.c8
3 files changed, 49 insertions, 18 deletions
diff --git a/lib/northbound.c b/lib/northbound.c
index a385cc9ece..c67ed924a9 100644
--- a/lib/northbound.c
+++ b/lib/northbound.c
@@ -273,9 +273,11 @@ static unsigned int nb_node_validate_cbs(const struct nb_node *nb_node)
error += nb_node_validate_cb(nb_node, NB_CB_APPLY_FINISH,
!!nb_node->cbs.apply_finish, true);
error += nb_node_validate_cb(nb_node, NB_CB_GET_ELEM,
- !!nb_node->cbs.get_elem, false);
+ (nb_node->cbs.get_elem || nb_node->cbs.get), false);
error += nb_node_validate_cb(nb_node, NB_CB_GET_NEXT,
- !!nb_node->cbs.get_next, false);
+ (nb_node->cbs.get_next ||
+ (nb_node->snode->nodetype == LYS_LEAFLIST && nb_node->cbs.get)),
+ false);
error += nb_node_validate_cb(nb_node, NB_CB_GET_KEYS,
!!nb_node->cbs.get_keys, false);
error += nb_node_validate_cb(nb_node, NB_CB_LOOKUP_ENTRY,
diff --git a/lib/northbound.h b/lib/northbound.h
index 97a1d31e57..42f763c3ef 100644
--- a/lib/northbound.h
+++ b/lib/northbound.h
@@ -21,6 +21,7 @@ extern "C" {
/* Forward declaration(s). */
struct vty;
struct debug;
+struct nb_node;
struct nb_yang_xpath_tag {
uint32_t ns;
@@ -102,6 +103,20 @@ enum nb_cb_operation {
NB_CB_NOTIFY,
};
+/* Northbound error codes. */
+enum nb_error {
+ NB_OK = 0,
+ NB_ERR,
+ NB_ERR_NO_CHANGES,
+ NB_ERR_NOT_FOUND,
+ NB_ERR_EXISTS,
+ NB_ERR_LOCKED,
+ NB_ERR_VALIDATION,
+ NB_ERR_RESOURCE,
+ NB_ERR_INCONSISTENCY,
+ NB_YIELD,
+};
+
union nb_resource {
int fd;
void *ptr;
@@ -426,6 +441,25 @@ struct nb_callbacks {
void (*apply_finish)(struct nb_cb_apply_finish_args *args);
/*
+ * Operational data callback (new direct tree add method).
+ *
+ * The callback function should create a new lyd_node (leaf) or
+ * lyd_node's (leaf list) for the value and attach to parent.
+ *
+ * nb_node
+ * The node representing the leaf or leaf list
+ * list_entry
+ * List entry from get_next (or NULL).
+ * parent
+ * The parent lyd_node to attach the leaf data to.
+ *
+ * Returns:
+ * Returns an nb_error if the data could not be added to the tree.
+ */
+ enum nb_error (*get)(const struct nb_node *nb_node, const void *list_entry,
+ struct lyd_node *parent);
+
+ /*
* Operational data callback.
*
* The callback function should return the value of a specific leaf,
@@ -672,20 +706,6 @@ struct frr_yang_module_info {
#endif
};
-/* Northbound error codes. */
-enum nb_error {
- NB_OK = 0,
- NB_ERR,
- NB_ERR_NO_CHANGES,
- NB_ERR_NOT_FOUND,
- NB_ERR_EXISTS,
- NB_ERR_LOCKED,
- NB_ERR_VALIDATION,
- NB_ERR_RESOURCE,
- NB_ERR_INCONSISTENCY,
- NB_YIELD,
-};
-
/* Default priority. */
#define NB_DFLT_PRIORITY (UINT32_MAX / 2)
@@ -814,8 +834,9 @@ extern struct debug nb_dbg_libyang;
extern struct nb_config *running_config;
/* Wrappers for the northbound callbacks. */
-extern struct yang_data *nb_callback_get_elem(const struct nb_node *nb_node,
- const char *xpath,
+extern struct yang_data *nb_callback_has_new_get_elem(const struct nb_node *nb_node);
+
+extern struct yang_data *nb_callback_get_elem(const struct nb_node *nb_node, const char *xpath,
const void *list_entry);
extern const void *nb_callback_get_next(const struct nb_node *nb_node,
const void *parent_list_entry,
diff --git a/lib/northbound_oper.c b/lib/northbound_oper.c
index a3ff360780..ce529cd26b 100644
--- a/lib/northbound_oper.c
+++ b/lib/northbound_oper.c
@@ -584,6 +584,10 @@ static enum nb_error nb_op_iter_leaf(struct nb_op_yield_state *ys,
if (lysc_is_key(snode))
return NB_OK;
+ /* Check for new simple get */
+ if (nb_node->cbs.get)
+ return nb_node->cbs.get(nb_node, ni->list_entry, ni->inner);
+
data = nb_callback_get_elem(nb_node, xpath, ni->list_entry);
if (data == NULL)
return NB_OK;
@@ -617,6 +621,10 @@ static enum nb_error nb_op_iter_leaflist(struct nb_op_yield_state *ys,
if (CHECK_FLAG(snode->flags, LYS_CONFIG_W))
return NB_OK;
+ /* Check for new simple get */
+ if (nb_node->cbs.get)
+ return nb_node->cbs.get(nb_node, ni->list_entry, ni->inner);
+
do {
struct yang_data *data;