1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2018 NetDEF, Inc.
7 #ifndef _FRR_NORTHBOUND_H_
8 #define _FRR_NORTHBOUND_H_
13 #include "openbsd-tree.h"
15 #include "yang_translator.h"
21 /* Forward declaration(s). */
25 /* Northbound events. */
28 * The configuration callback is supposed to verify that the changes are
29 * valid and can be applied.
34 * The configuration callback is supposed to prepare all resources
35 * required to apply the changes.
40 * Transaction has failed, the configuration callback needs to release
41 * all resources previously allocated.
46 * The configuration changes need to be applied. The changes can't be
47 * rejected at this point (errors are logged and ignored).
53 * Northbound operations.
55 * Refer to the documentation comments of nb_callbacks for more details.
77 * Northbound callbacks parameters.
80 struct nb_cb_create_args
{
81 /* Context of the configuration transaction. */
82 struct nb_context
*context
;
85 * The transaction phase. Refer to the documentation comments of
86 * nb_event for more details.
90 /* libyang data node that is being created. */
91 const struct lyd_node
*dnode
;
94 * Pointer to store resource(s) allocated during the NB_EV_PREPARE
95 * phase. The same pointer can be used during the NB_EV_ABORT and
96 * NB_EV_APPLY phases to either release or make use of the allocated
97 * resource(s). It's set to NULL when the event is NB_EV_VALIDATE.
99 union nb_resource
*resource
;
101 /* Buffer to store human-readable error message in case of error. */
104 /* Size of errmsg. */
108 struct nb_cb_modify_args
{
109 /* Context of the configuration transaction. */
110 struct nb_context
*context
;
113 * The transaction phase. Refer to the documentation comments of
114 * nb_event for more details.
118 /* libyang data node that is being modified. */
119 const struct lyd_node
*dnode
;
122 * Pointer to store resource(s) allocated during the NB_EV_PREPARE
123 * phase. The same pointer can be used during the NB_EV_ABORT and
124 * NB_EV_APPLY phases to either release or make use of the allocated
125 * resource(s). It's set to NULL when the event is NB_EV_VALIDATE.
127 union nb_resource
*resource
;
129 /* Buffer to store human-readable error message in case of error. */
132 /* Size of errmsg. */
136 struct nb_cb_destroy_args
{
137 /* Context of the configuration transaction. */
138 struct nb_context
*context
;
141 * The transaction phase. Refer to the documentation comments of
142 * nb_event for more details.
146 /* libyang data node that is being deleted. */
147 const struct lyd_node
*dnode
;
149 /* Buffer to store human-readable error message in case of error. */
152 /* Size of errmsg. */
156 struct nb_cb_move_args
{
157 /* Context of the configuration transaction. */
158 struct nb_context
*context
;
161 * The transaction phase. Refer to the documentation comments of
162 * nb_event for more details.
166 /* libyang data node that is being moved. */
167 const struct lyd_node
*dnode
;
169 /* Buffer to store human-readable error message in case of error. */
172 /* Size of errmsg. */
176 struct nb_cb_pre_validate_args
{
177 /* Context of the configuration transaction. */
178 struct nb_context
*context
;
180 /* libyang data node associated with the 'pre_validate' callback. */
181 const struct lyd_node
*dnode
;
183 /* Buffer to store human-readable error message in case of error. */
186 /* Size of errmsg. */
190 struct nb_cb_apply_finish_args
{
191 /* Context of the configuration transaction. */
192 struct nb_context
*context
;
194 /* libyang data node associated with the 'apply_finish' callback. */
195 const struct lyd_node
*dnode
;
197 /* Buffer to store human-readable error message in case of error. */
200 /* Size of errmsg. */
204 struct nb_cb_get_elem_args
{
205 /* YANG data path of the data we want to get. */
208 /* Pointer to list entry (might be NULL). */
209 const void *list_entry
;
212 struct nb_cb_get_next_args
{
213 /* Pointer to parent list entry. */
214 const void *parent_list_entry
;
216 /* Pointer to (leaf-)list entry. */
217 const void *list_entry
;
220 struct nb_cb_get_keys_args
{
221 /* Pointer to list entry. */
222 const void *list_entry
;
225 * Structure to be filled based on the attributes of the provided list
228 struct yang_list_keys
*keys
;
231 struct nb_cb_lookup_entry_args
{
232 /* Pointer to parent list entry. */
233 const void *parent_list_entry
;
235 /* Structure containing the keys of the list entry. */
236 const struct yang_list_keys
*keys
;
239 struct nb_cb_rpc_args
{
240 /* XPath of the YANG RPC or action. */
243 /* Read-only list of input parameters. */
244 const struct list
*input
;
246 /* List of output parameters to be populated by the callback. */
249 /* Buffer to store human-readable error message in case of error. */
252 /* Size of errmsg. */
257 * Set of configuration callbacks that can be associated to a northbound node.
259 struct nb_callbacks
{
261 * Configuration callback.
263 * A presence container, list entry, leaf-list entry or leaf of type
264 * empty has been created.
266 * For presence-containers and list entries, the callback is supposed to
267 * initialize the default values of its children (if any) from the YANG
271 * Refer to the documentation comments of nb_cb_create_args for
275 * - NB_OK on success.
276 * - NB_ERR_VALIDATION when a validation error occurred.
277 * - NB_ERR_RESOURCE when the callback failed to allocate a resource.
278 * - NB_ERR_INCONSISTENCY when an inconsistency was detected.
279 * - NB_ERR for other errors.
281 int (*create
)(struct nb_cb_create_args
*args
);
284 * Configuration callback.
286 * The value of a leaf has been modified.
288 * List keys don't need to implement this callback. When a list key is
289 * modified, the northbound treats this as if the list was deleted and a
290 * new one created with the updated key value.
293 * Refer to the documentation comments of nb_cb_modify_args for
297 * - NB_OK on success.
298 * - NB_ERR_VALIDATION when a validation error occurred.
299 * - NB_ERR_RESOURCE when the callback failed to allocate a resource.
300 * - NB_ERR_INCONSISTENCY when an inconsistency was detected.
301 * - NB_ERR for other errors.
303 int (*modify
)(struct nb_cb_modify_args
*args
);
306 * Configuration callback.
308 * A presence container, list entry, leaf-list entry or optional leaf
311 * The callback is supposed to delete the entire configuration object,
312 * including its children when they exist.
315 * Refer to the documentation comments of nb_cb_destroy_args for
319 * - NB_OK on success.
320 * - NB_ERR_VALIDATION when a validation error occurred.
321 * - NB_ERR_INCONSISTENCY when an inconsistency was detected.
322 * - NB_ERR for other errors.
324 int (*destroy
)(struct nb_cb_destroy_args
*args
);
327 * Configuration callback.
329 * A list entry or leaf-list entry has been moved. Only applicable when
330 * the "ordered-by user" statement is present.
333 * Refer to the documentation comments of nb_cb_move_args for
337 * - NB_OK on success.
338 * - NB_ERR_VALIDATION when a validation error occurred.
339 * - NB_ERR_INCONSISTENCY when an inconsistency was detected.
340 * - NB_ERR for other errors.
342 int (*move
)(struct nb_cb_move_args
*args
);
345 * Optional configuration callback.
347 * This callback can be used to validate subsections of the
348 * configuration being committed before validating the configuration
349 * changes themselves. It's useful to perform more complex validations
350 * that depend on the relationship between multiple nodes.
353 * Refer to the documentation comments of nb_cb_pre_validate_args for
357 * - NB_OK on success.
358 * - NB_ERR_VALIDATION when a validation error occurred.
360 int (*pre_validate
)(struct nb_cb_pre_validate_args
*args
);
363 * Optional configuration callback.
365 * The 'apply_finish' callbacks are called after all other callbacks
366 * during the apply phase (NB_EV_APPLY). These callbacks are called only
367 * under one of the following two cases:
368 * - The data node has been created or modified (but not deleted);
369 * - Any change was made within the descendants of the data node (e.g. a
370 * child leaf was modified, created or deleted).
372 * In the second case above, the 'apply_finish' callback is called only
373 * once even if multiple changes occurred within the descendants of the
377 * Refer to the documentation comments of nb_cb_apply_finish_args for
380 void (*apply_finish
)(struct nb_cb_apply_finish_args
*args
);
383 * Operational data callback.
385 * The callback function should return the value of a specific leaf,
386 * leaf-list entry or inform if a typeless value (presence containers or
387 * leafs of type empty) exists or not.
390 * Refer to the documentation comments of nb_cb_get_elem_args for
394 * Pointer to newly created yang_data structure, or NULL to indicate
395 * the absence of data.
397 struct yang_data
*(*get_elem
)(struct nb_cb_get_elem_args
*args
);
400 * Operational data callback for YANG lists and leaf-lists.
402 * The callback function should return the next entry in the list or
403 * leaf-list. The 'list_entry' parameter will be NULL on the first
407 * Refer to the documentation comments of nb_cb_get_next_args for
411 * Pointer to the next entry in the (leaf-)list, or NULL to signal
412 * that the end of the (leaf-)list was reached.
414 const void *(*get_next
)(struct nb_cb_get_next_args
*args
);
417 * Operational data callback for YANG lists.
419 * The callback function should fill the 'keys' parameter based on the
420 * given list_entry. Keyless lists don't need to implement this
424 * Refer to the documentation comments of nb_cb_get_keys_args for
428 * NB_OK on success, NB_ERR otherwise.
430 int (*get_keys
)(struct nb_cb_get_keys_args
*args
);
433 * Operational data callback for YANG lists.
435 * The callback function should return a list entry based on the list
436 * keys given as a parameter. Keyless lists don't need to implement this
440 * Refer to the documentation comments of nb_cb_lookup_entry_args for
444 * Pointer to the list entry if found, or NULL if not found.
446 const void *(*lookup_entry
)(struct nb_cb_lookup_entry_args
*args
);
449 * RPC and action callback.
451 * Both 'input' and 'output' are lists of 'yang_data' structures. The
452 * callback should fetch all the input parameters from the 'input' list,
453 * and add output parameters to the 'output' list if necessary.
456 * Refer to the documentation comments of nb_cb_rpc_args for details.
459 * NB_OK on success, NB_ERR otherwise.
461 int (*rpc
)(struct nb_cb_rpc_args
*args
);
464 * Optional callback to compare the data nodes when printing
465 * the CLI commands associated with them.
468 * The first data node to compare.
471 * The second data node to compare.
474 * <0 when the CLI command for the dnode1 should be printed first
475 * >0 when the CLI command for the dnode2 should be printed first
476 * 0 when there is no difference
478 int (*cli_cmp
)(const struct lyd_node
*dnode1
,
479 const struct lyd_node
*dnode2
);
482 * Optional callback to show the CLI command associated to the given
486 * The vty terminal to dump the configuration to.
489 * libyang data node that should be shown in the form of a CLI
493 * Specify whether to display default configuration values or not.
494 * This parameter can be ignored most of the time since the
495 * northbound doesn't call this callback for default leaves or
496 * non-presence containers that contain only default child nodes.
497 * The exception are commands associated to multiple configuration
498 * nodes, in which case it might be desirable to hide one or more
499 * parts of the command when this parameter is set to false.
501 void (*cli_show
)(struct vty
*vty
, const struct lyd_node
*dnode
,
505 * Optional callback to show the CLI node end for lists or containers.
508 * The vty terminal to dump the configuration to.
511 * libyang data node that should be shown in the form of a CLI
514 void (*cli_show_end
)(struct vty
*vty
, const struct lyd_node
*dnode
);
517 struct nb_dependency_callbacks
{
518 void (*get_dependant_xpath
)(const struct lyd_node
*dnode
, char *xpath
);
519 void (*get_dependency_xpath
)(const struct lyd_node
*dnode
, char *xpath
);
523 * Northbound-specific data that is allocated for each schema node of the native
527 /* Back pointer to the libyang schema node. */
528 const struct lysc_node
*snode
;
530 /* Data path of this YANG node. */
531 char xpath
[XPATH_MAXLEN
];
533 /* Priority - lower priorities are processed first. */
536 struct nb_dependency_callbacks dep_cbs
;
538 /* Callbacks implemented for this node. */
539 struct nb_callbacks cbs
;
542 * Pointer to the parent node (disconsidering non-presence containers).
544 struct nb_node
*parent
;
546 /* Pointer to the nearest parent list, if any. */
547 struct nb_node
*parent_list
;
553 /* ConfD hash value corresponding to this YANG path. */
557 /* The YANG container or list contains only config data. */
558 #define F_NB_NODE_CONFIG_ONLY 0x01
559 /* The YANG list doesn't contain key leafs. */
560 #define F_NB_NODE_KEYLESS_LIST 0x02
563 * HACK: old gcc versions (< 5.x) have a bug that prevents C99 flexible arrays
564 * from working properly on shared libraries. For those compilers, use a fixed
565 * size array to work around the problem.
567 #define YANG_MODULE_MAX_NODES 2000
569 struct frr_yang_module_info
{
570 /* YANG module name. */
573 /* Northbound callbacks. */
575 /* Data path of this YANG node. */
578 /* Callbacks implemented for this node. */
579 struct nb_callbacks cbs
;
581 /* Priority - lower priorities are processed first. */
583 #if defined(__GNUC__) && ((__GNUC__ - 0) < 5) && !defined(__clang__)
584 } nodes
[YANG_MODULE_MAX_NODES
+ 1];
590 /* Northbound error codes. */
599 NB_ERR_INCONSISTENCY
,
602 /* Default priority. */
603 #define NB_DFLT_PRIORITY (UINT32_MAX / 2)
605 /* Default maximum of configuration rollbacks to store. */
606 #define NB_DLFT_MAX_CONFIG_ROLLBACKS 20
608 /* Northbound clients. */
618 /* Northbound context. */
620 /* Northbound client. */
621 enum nb_client client
;
623 /* Northbound user (can be NULL). */
626 /* Client-specific data. */
643 /* Northbound configuration. */
645 struct lyd_node
*dnode
;
649 /* Northbound configuration callback. */
650 struct nb_config_cb
{
651 RB_ENTRY(nb_config_cb
) entry
;
652 enum nb_operation operation
;
654 const struct nb_node
*nb_node
;
655 const struct lyd_node
*dnode
;
657 RB_HEAD(nb_config_cbs
, nb_config_cb
);
658 RB_PROTOTYPE(nb_config_cbs
, nb_config_cb
, entry
, nb_config_cb_compare
);
660 /* Northbound configuration change. */
661 struct nb_config_change
{
662 struct nb_config_cb cb
;
663 union nb_resource resource
;
667 /* Northbound configuration transaction. */
668 struct nb_transaction
{
669 struct nb_context
*context
;
671 struct nb_config
*config
;
672 struct nb_config_cbs changes
;
675 /* Callback function used by nb_oper_data_iterate(). */
676 typedef int (*nb_oper_data_cb
)(const struct lysc_node
*snode
,
677 struct yang_translator
*translator
,
678 struct yang_data
*data
, void *arg
);
680 /* Iterate over direct child nodes only. */
681 #define NB_OPER_DATA_ITER_NORECURSE 0x0001
684 DECLARE_HOOK(nb_notification_send
, (const char *xpath
, struct list
*arguments
),
686 DECLARE_HOOK(nb_client_debug_config_write
, (struct vty
*vty
), (vty
));
687 DECLARE_HOOK(nb_client_debug_set_all
, (uint32_t flags
, bool set
), (flags
, set
));
689 /* Northbound debugging records */
690 extern struct debug nb_dbg_cbs_config
;
691 extern struct debug nb_dbg_cbs_state
;
692 extern struct debug nb_dbg_cbs_rpc
;
693 extern struct debug nb_dbg_notif
;
694 extern struct debug nb_dbg_events
;
695 extern struct debug nb_dbg_libyang
;
697 /* Global running configuration. */
698 extern struct nb_config
*running_config
;
700 /* Wrappers for the northbound callbacks. */
701 extern struct yang_data
*nb_callback_get_elem(const struct nb_node
*nb_node
,
703 const void *list_entry
);
704 extern const void *nb_callback_get_next(const struct nb_node
*nb_node
,
705 const void *parent_list_entry
,
706 const void *list_entry
);
707 extern int nb_callback_get_keys(const struct nb_node
*nb_node
,
708 const void *list_entry
,
709 struct yang_list_keys
*keys
);
710 extern const void *nb_callback_lookup_entry(const struct nb_node
*nb_node
,
711 const void *parent_list_entry
,
712 const struct yang_list_keys
*keys
);
713 extern int nb_callback_rpc(const struct nb_node
*nb_node
, const char *xpath
,
714 const struct list
*input
, struct list
*output
,
715 char *errmsg
, size_t errmsg_len
);
718 * Create a northbound node for all YANG schema nodes.
720 void nb_nodes_create(void);
723 * Delete all northbound nodes from all YANG schema nodes.
725 void nb_nodes_delete(void);
728 * Find the northbound node corresponding to a YANG data path.
731 * XPath to search for (with or without predicates).
734 * Pointer to northbound node if found, NULL otherwise.
736 extern struct nb_node
*nb_node_find(const char *xpath
);
738 extern void nb_node_set_dependency_cbs(const char *dependency_xpath
,
739 const char *dependant_xpath
,
740 struct nb_dependency_callbacks
*cbs
);
742 bool nb_node_has_dependency(struct nb_node
*node
);
745 * Create a new northbound configuration.
748 * Pointer to a libyang data node containing the configuration data. If NULL
749 * is given, an empty configuration will be created.
752 * Pointer to newly created northbound configuration.
754 extern struct nb_config
*nb_config_new(struct lyd_node
*dnode
);
757 * Delete a northbound configuration.
760 * Pointer to the config that is going to be deleted.
762 extern void nb_config_free(struct nb_config
*config
);
765 * Duplicate a northbound configuration.
768 * Northbound configuration to duplicate.
771 * Pointer to duplicated configuration.
773 extern struct nb_config
*nb_config_dup(const struct nb_config
*config
);
776 * Merge one configuration into another.
779 * Configuration to merge to.
782 * Configuration to merge config_dst with.
785 * Specify whether config_src should be deleted or not after the merge
789 * NB_OK on success, NB_ERR otherwise.
791 extern int nb_config_merge(struct nb_config
*config_dst
,
792 struct nb_config
*config_src
, bool preserve_source
);
795 * Replace one configuration by another.
798 * Configuration to be replaced.
801 * Configuration to replace config_dst.
804 * Specify whether config_src should be deleted or not after the replace
807 extern void nb_config_replace(struct nb_config
*config_dst
,
808 struct nb_config
*config_src
,
809 bool preserve_source
);
812 * Edit a candidate configuration.
815 * Candidate configuration to edit.
818 * Northbound node associated to the configuration being edited.
821 * Operation to apply.
824 * XPath of the configuration node being edited.
827 * Previous value of the configuration node. Should be used only when the
828 * operation is NB_OP_MOVE, otherwise this parameter is ignored.
831 * New value of the configuration node.
834 * - NB_OK on success.
835 * - NB_ERR_NOT_FOUND when the element to be deleted was not found.
836 * - NB_ERR for other errors.
838 extern int nb_candidate_edit(struct nb_config
*candidate
,
839 const struct nb_node
*nb_node
,
840 enum nb_operation operation
, const char *xpath
,
841 const struct yang_data
*previous
,
842 const struct yang_data
*data
);
845 * Check if a candidate configuration is outdated and needs to be updated.
848 * Candidate configuration to check.
851 * true if the candidate is outdated, false otherwise.
853 extern bool nb_candidate_needs_update(const struct nb_config
*candidate
);
856 * Update a candidate configuration by rebasing the changes on top of the latest
857 * running configuration. Resolve conflicts automatically by giving preference
858 * to the changes done in the candidate configuration.
861 * Candidate configuration to update.
864 * NB_OK on success, NB_ERR otherwise.
866 extern int nb_candidate_update(struct nb_config
*candidate
);
869 * Validate a candidate configuration. Perform both YANG syntactic/semantic
870 * validation and code-level validation using the northbound callbacks.
872 * WARNING: the candidate can be modified as part of the validation process
873 * (e.g. add default nodes).
876 * Context of the northbound transaction.
879 * Candidate configuration to validate.
882 * Buffer to store human-readable error message in case of error.
888 * NB_OK on success, NB_ERR_VALIDATION otherwise.
890 extern int nb_candidate_validate(struct nb_context
*context
,
891 struct nb_config
*candidate
, char *errmsg
,
895 * Create a new configuration transaction but do not commit it yet. Only
896 * validate the candidate and prepare all resources required to apply the
897 * configuration changes.
900 * Context of the northbound transaction.
903 * Candidate configuration to commit.
906 * Optional comment describing the commit.
909 * Output parameter providing the created transaction when one is created
910 * successfully. In this case, it must be either aborted using
911 * nb_candidate_commit_abort() or committed using
912 * nb_candidate_commit_apply().
915 * Buffer to store human-readable error message in case of error.
921 * - NB_OK on success.
922 * - NB_ERR_NO_CHANGES when the candidate is identical to the running
924 * - NB_ERR_LOCKED when there's already another transaction in progress.
925 * - NB_ERR_VALIDATION when the candidate fails the validation checks.
926 * - NB_ERR_RESOURCE when the system fails to allocate resources to apply
927 * the candidate configuration.
928 * - NB_ERR for other errors.
930 extern int nb_candidate_commit_prepare(struct nb_context
*context
,
931 struct nb_config
*candidate
,
933 struct nb_transaction
**transaction
,
934 char *errmsg
, size_t errmsg_len
);
937 * Abort a previously created configuration transaction, releasing all resources
938 * allocated during the preparation phase.
941 * Candidate configuration to abort. It's consumed by this function.
944 * Buffer to store human-readable error message in case of error.
949 extern void nb_candidate_commit_abort(struct nb_transaction
*transaction
,
950 char *errmsg
, size_t errmsg_len
);
953 * Commit a previously created configuration transaction.
956 * Configuration transaction to commit. It's consumed by this function.
959 * Specify whether the transaction should be recorded in the transactions log
963 * Optional output parameter providing the ID of the committed transaction.
966 * Buffer to store human-readable error message in case of error.
971 extern void nb_candidate_commit_apply(struct nb_transaction
*transaction
,
972 bool save_transaction
,
973 uint32_t *transaction_id
, char *errmsg
,
977 * Create a new transaction to commit a candidate configuration. This is a
978 * convenience function that performs the two-phase commit protocol
979 * transparently to the user. The cost is reduced flexibility, since
980 * network-wide and multi-daemon transactions require the network manager to
981 * take into account the results of the preparation phase of multiple managed
985 * Context of the northbound transaction.
988 * Candidate configuration to commit. It's preserved regardless if the commit
989 * operation fails or not.
992 * Specify whether the transaction should be recorded in the transactions log
996 * Optional comment describing the commit.
999 * Optional output parameter providing the ID of the committed transaction.
1002 * Buffer to store human-readable error message in case of error.
1008 * - NB_OK on success.
1009 * - NB_ERR_NO_CHANGES when the candidate is identical to the running
1011 * - NB_ERR_LOCKED when there's already another transaction in progress.
1012 * - NB_ERR_VALIDATION when the candidate fails the validation checks.
1013 * - NB_ERR_RESOURCE when the system fails to allocate resources to apply
1014 * the candidate configuration.
1015 * - NB_ERR for other errors.
1017 extern int nb_candidate_commit(struct nb_context
*context
,
1018 struct nb_config
*candidate
,
1019 bool save_transaction
, const char *comment
,
1020 uint32_t *transaction_id
, char *errmsg
,
1024 * Lock the running configuration.
1027 * Northbound client.
1030 * Northbound user (can be NULL).
1033 * 0 on success, -1 when the running configuration is already locked.
1035 extern int nb_running_lock(enum nb_client client
, const void *user
);
1038 * Unlock the running configuration.
1041 * Northbound client.
1044 * Northbound user (can be NULL).
1047 * 0 on success, -1 when the running configuration is already unlocked or
1048 * locked by another client/user.
1050 extern int nb_running_unlock(enum nb_client client
, const void *user
);
1053 * Check if the running configuration is locked or not for the given
1057 * Northbound client.
1060 * Northbound user (can be NULL).
1063 * 0 if the running configuration is unlocked or if the client/user owns the
1064 * lock, -1 otherwise.
1066 extern int nb_running_lock_check(enum nb_client client
, const void *user
);
1069 * Iterate over operational data.
1072 * Data path of the YANG data we want to iterate over.
1075 * YANG module translator (might be NULL).
1078 * NB_OPER_DATA_ITER_ flags to control how the iteration is performed.
1081 * Function to call with each data node.
1084 * Arbitrary argument passed as the fourth parameter in each call to 'cb'.
1087 * NB_OK on success, NB_ERR otherwise.
1089 extern int nb_oper_data_iterate(const char *xpath
,
1090 struct yang_translator
*translator
,
1091 uint32_t flags
, nb_oper_data_cb cb
, void *arg
);
1094 * Validate if the northbound operation is valid for the given node.
1097 * Operation we want to check.
1100 * libyang schema node we want to check.
1103 * true if the operation is valid, false otherwise.
1105 extern bool nb_operation_is_valid(enum nb_operation operation
,
1106 const struct lysc_node
*snode
);
1109 * Send a YANG notification. This is a no-op unless the 'nb_notification_send'
1110 * hook was registered by a northbound plugin.
1113 * XPath of the YANG notification.
1116 * Linked list containing the arguments that should be sent. This list is
1117 * deleted after being used.
1120 * NB_OK on success, NB_ERR otherwise.
1122 extern int nb_notification_send(const char *xpath
, struct list
*arguments
);
1125 * Associate a user pointer to a configuration node.
1127 * This should be called by northbound 'create' callbacks in the NB_EV_APPLY
1131 * libyang data node - only its XPath is used.
1134 * Arbitrary user-specified pointer.
1136 extern void nb_running_set_entry(const struct lyd_node
*dnode
, void *entry
);
1139 * Move an entire tree of user pointer nodes.
1141 * Suppose we have xpath A/B/C/D, with user pointers associated to C and D. We
1142 * need to move B to be under Z, so the new xpath is Z/B/C/D. Because user
1143 * pointers are indexed with their absolute path, We need to move all user
1144 * pointers at and below B to their new absolute paths; this function does
1148 * base xpath of tree to move (A/B)
1151 * base xpath of new location of tree (Z/B)
1153 extern void nb_running_move_tree(const char *xpath_from
, const char *xpath_to
);
1156 * Unset the user pointer associated to a configuration node.
1158 * This should be called by northbound 'destroy' callbacks in the NB_EV_APPLY
1162 * libyang data node - only its XPath is used.
1165 * The user pointer that was unset.
1167 extern void *nb_running_unset_entry(const struct lyd_node
*dnode
);
1170 * Find the user pointer (if any) associated to a configuration node.
1172 * The XPath associated to the configuration node can be provided directly or
1173 * indirectly through a libyang data node.
1175 * If an user point is not found, this function follows the parent nodes in the
1176 * running configuration until an user pointer is found or until the root node
1180 * libyang data node - only its XPath is used (can be NULL if 'xpath' is
1184 * XPath of the configuration node (can be NULL if 'dnode' is provided).
1186 * abort_if_not_found
1187 * When set to true, abort the program if no user pointer is found.
1189 * As a rule of thumb, this parameter should be set to true in the following
1191 * - Calling this function from any northbound configuration callback during
1192 * the NB_EV_APPLY phase.
1193 * - Calling this function from a 'delete' northbound configuration callback
1196 * In both the above cases, the given configuration node should contain an
1197 * user pointer except when there's a bug in the code, in which case it's
1198 * better to abort the program right away and eliminate the need for
1199 * unnecessary NULL checks.
1201 * In all other cases, this parameter should be set to false and the caller
1202 * should check if the function returned NULL or not.
1205 * User pointer if found, NULL otherwise.
1207 extern void *nb_running_get_entry(const struct lyd_node
*dnode
,
1208 const char *xpath
, bool abort_if_not_found
);
1211 * Same as 'nb_running_get_entry', but doesn't search within parent nodes
1212 * recursively if an user point is not found.
1214 extern void *nb_running_get_entry_non_rec(const struct lyd_node
*dnode
,
1216 bool abort_if_not_found
);
1219 * Return a human-readable string representing a northbound event.
1225 * String representation of the given northbound event.
1227 extern const char *nb_event_name(enum nb_event event
);
1230 * Return a human-readable string representing a northbound operation.
1233 * Northbound operation.
1236 * String representation of the given northbound operation.
1238 extern const char *nb_operation_name(enum nb_operation operation
);
1241 * Return a human-readable string representing a northbound error.
1247 * String representation of the given northbound error.
1249 extern const char *nb_err_name(enum nb_error error
);
1252 * Return a human-readable string representing a northbound client.
1255 * Northbound client.
1258 * String representation of the given northbound client.
1260 extern const char *nb_client_name(enum nb_client client
);
1263 * Validate all northbound callbacks.
1265 * Some errors, like missing callbacks or invalid priorities, are fatal and
1266 * can't be recovered from. Other errors, like unneeded callbacks, are logged
1267 * but otherwise ignored.
1269 * Whenever a YANG module is loaded after startup, *all* northbound callbacks
1270 * need to be validated and not only the callbacks from the newly loaded module.
1271 * This is because augmentations can change the properties of the augmented
1272 * module, making mandatory the implementation of additional callbacks.
1274 void nb_validate_callbacks(void);
1277 * Initialize the northbound layer. Should be called only once during the
1278 * daemon initialization process.
1281 * Array of YANG modules to parse and initialize.
1284 * Size of the modules array.
1287 * Set this to record the transactions in the transaction log.
1289 extern void nb_init(struct thread_master
*tm
,
1290 const struct frr_yang_module_info
*const modules
[],
1291 size_t nmodules
, bool db_enabled
);
1294 * Finish the northbound layer gracefully. Should be called only when the daemon
1297 extern void nb_terminate(void);
1303 #endif /* _FRR_NORTHBOUND_H_ */