summaryrefslogtreecommitdiff
path: root/lib/northbound.c
AgeCommit message (Collapse)Author
2020-03-04*: Use short version of bool expressionsDonatas Abraitis
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2019-11-30*: make frr_yang_module_info constDavid Lamparter
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-10-11lib: reduce memory allocation when processing large config transactionsRenato Westphal
Remove the xpath field from the nb_config_cb structure in order to reduce its size. This allows the northbound to spend less time allocating memory during the processing of large configuration transactions. To make this work, use yang_dnode_get_path() to obtain the xpath from the dnode field whenever necessary. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-10-11lib: fix processing of the 'apply_finish' callbacksRenato Westphal
Commit 6b5d6e2dbc88 changed how we order configuration callbacks and introduced a regression in the processing of the 'apply_finish' callbacks. Fix this. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-10-11lib: avoid expensive operations when editing a candidate configRenato Westphal
nb_candidate_edit() was calling both the lyd_schema_sort() and lyd_validate() functions whenever a new node was added to the candidate configuration. This was done to ensure the candidate is always ready to be displayed correctly (libyang only creates default child nodes during the validation process, and data nodes aren't guaranteed to be ordered by default). The problem is that the two aforementioned functions are too expensive to be called in the northbound hot path. Instead, it makes more sense to call them only before displaying the configuration (in which case a recursive sort needs to be done). Introduce the nb_cli_show_config_prepare() to achieve that purpose. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-09-18lib: add an exception in the northbound for operational data callbacksRenato Westphal
During initialization, the northbound detects if any required callback is missing (fatal error) or if any unneeded callback is present (warning). There are three callbacks, however, that should require special handling: get_next(), get_keys() and lookup_entry(). These callbacks are normally unneeded for configuration lists. But, if a configuration list is augmented with new state nodes by another module, then the three callbacks mentioned above become required. In this case, never log a warning when these callbacks are implemented when they are not needed, since this depends on context (e.g. some daemons might augment "frr-interface" while others don't). Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-09-18lib: fix ordering issues in the northboundRenato Westphal
When a configuration transaction is being performed, the northbound uses a red-black tree to store the configuration changes that need to be processed. The problem is that we were sorting the configuration changes based on their XPaths (and callback priorities). This means the original order of the changes wasn't being respected, which is a problem for lists that use the "ordered-by user" statement. To fix this, add a new "seq" member to the "nb_config_cb" structure so that we can preserve the order of the configuration changes as told by libyang. Since none of the FRR modules use "ordered-by user" lists so far, no daemon was affected by this problem. Reported-by: Martin Winter <mwinter@opensourcerouting.org> Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-09-18lib: fix corner case when iterating over YANG-modeled operational dataRenato Westphal
When updating the XPath during the iteration of operational data, include the namespace of the augmenting module when necessary. Reported-by: Quentin Young <qlyoung@cumulusnetworks.com> Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-09-18Revert "lib: introduce a read-write lock for northbound configurations"Renato Westphal
Adding a lock to protect the global running configuration doesn't help much since the FRR daemons are not prepared to process configuration changes in a pthread that is not the main one (a whole lot of new protections would be necessary to prevent race conditions). This means the lock added by commit 83981138 only adds more complexity for no benefit. Remove it now to simplify the code. All northbound clients, including the gRPC one, should either run in the main pthread or use synchronization primitives to process configuration transactions in the main pthread. This reverts commit 83981138fe8c1e0a40b8dede74eca65449dda5de.
2019-09-18lib: introduce new 'pre_validate' northbound callbackRenato Westphal
This callback can be used to validate subsections of the configuration being committed before validating the configuration changes themselves. It's useful to perform more complex validations that depend on the relationship between multiple nodes. Only YANG-level validation (performed by libyang) and the NB_EV_VALIDATE validation (that can be used to validate individual configuration changes) proved to be insufficient in some cases. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-09-03lib: add frr_with_mutex() block-wrapperDavid Lamparter
frr_with_mutex(...) { ... } locks and automatically unlocks the listed mutex(es) when the block is exited. This adds a bit of safety against forgetting the unlock in error paths & co. and makes the code a slight bit more readable. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2019-07-09Merge pull request #4088 from opensourcerouting/bump-libyang-requirement-versJafar Al-Gharaibeh
build, lib: bump libyang requirement version to >= 0.16.105 (-r3)
2019-07-02lib: use flag from new libyang version to simplify the codeRenato Westphal
When using the LYD_PATH_OPT_NOPARENTRET flag, lyd_new_path() returns the path-referenced node instead of the first created node. This flag wasn't available in libyang 0.16-r1 so we couldn't use it before. Use it now to simplify the code where possible. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-07-01lib: fix a couple of yang validation issuesRenato Westphal
libyang-0.16-r3 contains a commit[1] that changed the autodelete behavior of subtrees when validating data. A few FRR commands were affected by this change since they relied on the old autodelete behavior. To fix these commands, use the LYD_OPT_WHENAUTODEL flag when validating data to restore the old autodelete behavior (which adds a lot of convenience for us). [1] https://github.com/CESNET/libyang/commit/bbc43b1b4 Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-05-31lib: Fix gcc 9 warning -> error issueDonald Sharp
gcc is complaing about this with --enable-dev and --enable-werror: In function 'nb_log_callback', inlined from 'nb_transaction_apply_finish' at lib/northbound.c:1106:4: lib/northbound.c:777:2: error: '%s' directive argument is null [-Werror=format-overflow=] 777 | zlog_debug( | ^~~~~~~~~~~ 778 | "northbound callback: event [%s] op [%s] xpath [%s] value [%s]", | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 779 | nb_event_name(event), nb_operation_name(operation), xpath, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 780 | value); | ~~~~~~ CC lib/ringbuf.lo Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-14lib: hashing functions should take const argumentsQuentin Young
It doesn't make much sense for a hash function to modify its argument, so const the hash input. BGP does it in a couple places, those cast away the const. Not great but not any worse than it was. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2019-04-26lib: add new gRPC-based northbound pluginRenato Westphal
This is an experimental plugin for now. Full documentation will come later. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-26lib: introduce a read-write lock for northbound configurationsRenato Westphal
The upcoming gRPC-based northbound plugin will run on a separate pthread, and it will need to have access to the running configuration global variable. Introduce a rw-lock to control concurrent access to the running configuration. Add the lock inside the "nb_config" structure so that it can be used to protect candidate configurations as well (this might be necessary depending on the threading scheme of future northbound plugins). Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-26lib: add API to allow northbound clients to lock/unlock the running ↵Renato Westphal
configuration The ability to lock the running configuration to prevent other users from changing it is a very important one. We already supported the "configure exclusive" command but the lock was applied to the CLI users only (other clients like ConfD could still commit configuration transactions, ignoring the CLI lock). This commit introduces a global lock for the running configuration that is shared by all northbound clients, and provides a public API to manipulate it. This way other northbound clients will also be able to lock/unlock the running configuration if required (the upcoming gRPC northbound plugin will have RPCs for that). NOTE: this is a management-level lock for the running configuration, not to be confused with low-level locks used to avoid data races. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-22Merge pull request #4161 from opensourcerouting/nb-performanceQuentin Young
lib: rework management of user pointers in the northbound layer
2019-04-18lib: make nb_candidate_edit() more flexibleRenato Westphal
Certain operations, like removing non-presence containers or modifying list keys, are not considered to be valid from the perspective of the northbound layer. This is because we want to implement a minimum set of northbound configuration callbacks and use them to process all possible configuration changes. The removal of a np-container [1], for example, can be processed by calling the "delete" callback of all of its child nodes (recursion is used for np-container child nodes). Similarly, the modification of a list key can be processed as if the corresponding list entry was removed and readded with updated key values. This strategy saves us the burden of implementing lots of extra configuration callbacks. That said, the nb_operation_is_valid() function shouldn't be used for anything other than checking which callbacks are valid for which YANG nodes. Using it in the nb_candidate_edit() function is inappropriate as we want as much flexibility as possible when editing a candidate configuration. We should allow CLI commands, for example, to remove np-containers (the northbound layer will then figure out which callbacks need to be called when this candidate is committed). Remove the check. [1] We can't do the same for presence containers since they have a "create" callback associated with them. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-18lib: introduce flog() to simplify the northbound code a little bitRenato Westphal
flog() is a small wrapper around zlog() that can be useful in a few places to reduce code duplication. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-18lib: don't initialize the northbound database in the unit testsRenato Westphal
Move call to nb_db_init() from nb_init() to frr_init() so that only the FRR daemons will initialize the northbound database. This should fix a few warnings when running some unit tests. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-18lib: rework management of user pointers in the northbound layerRenato Westphal
Introduce a hash table to keep track of user pointers associated to configuration entries. The previous strategy was to embed the user pointers inside libyang data nodes, but this solution incurred a substantial performance overhead. The user pointers embedded in candidate configurations could be lost while the configuration was being edited, so they needed to be regenerated before the candidate could be committed. This was done by the nb_candidate_restore_priv_pointers() function, which was extremely expensive for large configurations. The new hash table solves this performance problem. The yang_dnode_[gs]et_entry() functions were renamed and moved from yang.[ch] to northbound.[ch], which is a more appropriate place for them. This patch also introduces the nb_running_unset_entry() function, the counterpart of nb_running_set_entry() (unsetting user pointers was done automatically before, now it needs to be done manually). As a consequence of these changes, we shouldn't need support for libyang private pointers anymore (-DENABLE_LYD_PRIV=ON). But it's probably a good idea to keep requiring this feature as we might need it in the future for other things (e.g. disable configuration settings without removing them). Fixes #4136. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-04-15lib: add fine-grained debugging in the northboundRenato Westphal
Split the "debug northbound" command into the following commands: * debug northbound callbacks configuration * debug northbound callbacks state * debug northbound callbacks rpc * debug northbound notifications * debug northbound events * debug northbound client confd * debug northbound client sysrepo If "debug northbound" is entered alone, all of its suboptions are enabled. This commit also adds code to debug state/rpc callbacks and notifications (only configuration callbacks were logged before). Use the debugging infrastructure from "lib/debug.h" in order to benefit from its facilities (e.g. MT-safe debugging) and avoid code duplication. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-03-02lib: fix removal of yang non-presence containersRenato Westphal
Non-presence containers don't have "destroy" callbacks. So, once a np-container is deleted, we need to call the "destroy" callbacks of its child nodes instead. This commit doesn't fix any real problem as of now since all np-containers from the FRR YANG modules contain or one more mandatory child nodes, so they can't be deleted (libyang will add missing np-containers when validating data). Nevertheless, upcoming YANG modules should benefit from this change. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-03-02lib: simplify code that calculates configuration diffsRenato Westphal
This is just a small refactoring to reduce code duplication. No behavior changes intended. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-02-11libs, rip, isis: change northbound operation enum to DESTROYMark Stapp
Change the northbound lib operation from DELETE to DESTROY; make the required changes in the users of the northbound, in the cli, rip, ripng, and isis. Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-02-11libs, daemons: changes to permit c++ compilationMark Stapp
Some misc changes to resolve some c++ compilation errors. The goal is only to permit an external module - a plugin, for example - to see frr headers, not to support or encourage contributions in c++. The changes include: avoiding use of keywords like 'new', 'delete'; cleaning up implicit type-casting from 'void *' in several places. Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-01-14lib: don't abort when incomplete xpath is given by the userRenato Westphal
Instead of aborting when an incomplete xpath is given to the nb_oper_data_iterate() function, just return an error so that the callers have a chance to treat this error. Aborting based on invalid user input is never the right thing to do. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-14lib: fix "may be used uninitialized" build warningRenato Westphal
We are already handling all possible four cases from the "nb_event" enumeration, so this problem can't happen in practice. Initialize the "ref" variable to zero to silence the warning. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-12-18lib: add NB phase-specific error codesEmanuele Di Pascale
As suggested by Renato, add error codes that are specific to the various phases of a northbound callback. These can be used by the daemons when logging an error. The reasoning is that validation errors typically mean that there is an inconsistency in the configuration, a prepare error means that we are running out of resources, and abort/apply errors are bugs that need to be reported to the devs. Signed-off-by: Emanuele Di Pascale <emanuele@voltanet.io>
2018-12-12lib: Fix string size issue with clangDonald Sharp
Newer versions of clang are failing on xpath length not being sufficiently sized to hold all possible data that could be thrown at it. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-12-09lib, tests: add support for keyless YANG listsRenato Westphal
YANG allows lists without keys for operational data, in which case the list elements are uniquely identified using a positional index (starting from one). This commit does the following: * Remove the need to implement the 'get_keys' and 'lookup_entry' callbacks for keyless lists. * Extend nb_oper_data_iter_list() so that it special-cases keyless lists appropriately. Since both the CLI and the sysrepo plugin use nb_oper_data_iterate() to fetch operational data, both these northbound clients automatically gain the ability to understand keyless lists without additional changes. * Extend the confd plugin to special-case keyless lists as well. This was a bit painful to implement given ConfD's clumsy API, but keyless lists should work ok now. * Update the "test_oper_data" unit test to test keyless YANG lists in addition to regular lists. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-12-07lib: add support for confirmed commitsRenato Westphal
Confirmed commits allow the user to request an automatic rollback to the previous configuration if the commit operation is not confirmed within a number of minutes. This is particularly useful when the user is accessing the CLI through the network (e.g. using SSH) and any configuration change might cause an unexpected loss of connectivity between the user and the managed device (e.g. misconfiguration of a routing protocol). By using a confirmed commit, the user can rest assured the connectivity will be restored after the given timeout expires, avoiding the need to access the router physically to fix the problem. When "commit confirmed TIMEOUT" is used, a new "commit" command is expected to confirm the previous commit before the given timeout expires. If "commit confirmed TIMEOUT" is used while there's already a confirmed-commit in progress, the confirmed-commit timeout is reset to the new value. In the current implementation, if other users perform commits while there's a confirmed-commit in progress, all commits are rolled back when the confirmed-commit timeout expires. It's recommended to use the "configure exclusive" configuration mode to prevent unexpected outcomes when using confirmed commits. When an user exits from the configuration mode while there's a confirmed-commit in progress, the commit is automatically rolled back and the user is notified about it. In the future we might want to prompt the user if he or she really wants to exit from the configuration mode when there's a pending confirmed commit. Needless to say, confirmed commit only work for configuration commands converted to the new northbound model. vtysh support will be implemented at a later time. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26lib, tests: major rework in the operational-data callbacksRenato Westphal
The northbound infrastructure for operational data was subpar compared to the infrastructure for configuration data. This commit addresses most of the existing problems, making it possible to write operational-data callbacks for more complex YANG models. Summary of the changes: * Add support for nested YANG lists. * Add support for leaf-lists. * Add support for leafs of type "empty". * Introduce the "show yang operational-data XPATH" command, and write an unit test for it. The main purpose of this command is to make it easier to test the operational-data northbound callbacks. * Introduce the nb_oper_data_iterate() function, that can be used to iterate over operational data. Make the CLI and sysrepo use this function. * Since ConfD has a very peculiar API, it can't reuse the nb_oper_data_iterate() like the other northbound clients. In this case, adapt the existing ConfD callbacks to support the new features (and make some performance improvements in the process). Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26lib: add support for YANG lists with mixed config and state dataRenato Westphal
A YANG list that contains both configuration and state data must have the following callbacks: create(), delete(), get_next(), get_keys() and lookup_entry(). Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26lib: rework the yang schema node iteration functionsRenato Westphal
* Rename yang_snodes_iterate() to yang_snodes_iterate_subtree() and expose it in the public API. * Rename yang_module_snodes_iterate() to yang_snodes_iterate_module(). * Rename yang_all_snodes_iterate() to yang_snodes_iterate_all(). * Make it possible to stop the iteration at any time by returning YANG_ITER_STOP in the iteration callbacks. * Make the iteration callbacks accept only one user argument and not two. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26lib: remove entire data tree on yang_dnode_free()Renato Westphal
For convenience, make yang_dnode_free() remove the entire data tree and not only the data node given as a parameter. Also, add a null-pointer check on nb_config_replace() before calling yang_dnode_free(). Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26lib, tools: use CHECK_FLAG/SET_FLAG more often in the northbound codeRenato Westphal
Cosmetic change to improve code readability a bit. No binary changes. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26lib: make it possible to create YANG data nodes containing state dataRenato Westphal
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>
2018-10-27lib: add a new northbound plugin for SysrepoRenato Westphal
This plugin leverages the northbound API to integrate FRR with Sysrepo, a YANG-based configuration and operational state data store. The plugin is linked to the libsysrepo library and communicates with the sysrepod daemon using GPB (Google Protocol Buffers) over AF_UNIX sockets. The integration consists mostly of glue code that calls the appropriate FRR northbound callbacks in response to events triggered by the sysrepod daemon (e.g. request to change the configuration or to fetch operational data). To build the sysrepo plugin, provide the --enable-sysrepo option to the configure script while building FRR (the libsysrepo library needs to be installed in the system). When installed, the sysrepo plugin will be available for all FRR daemons and can be loaded using the -M (or --module) command line option. Example: bgpd -M sysrepo. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-10-27lib: add a new northbound plugin for ConfDRenato Westphal
This plugin leverages the northbound API to integrate FRR with the ConfD management agent. The plugin is linked to the libconfd library and communicates with the confd daemon using local TCP sockets. The integration consists mostly of glue code that calls the appropriate FRR northbound callbacks in response to events triggered by the confd daemon (e.g. request to change the configuration or to fetch operational data). By integrating FRR with the libconfd library, FRR can be managed using all northbound interfaces provided by ConfD, including NETCONF, RESTCONF and their Web API. The ConfD CDB API is used to handle configuration changes and the ConfD Data Provider API is used to provide operational data, process RPCs and send notifications. Support for configuration management using the ConfD Data Provider API is not available at this point. The ConfD optional 'get_object()' and 'get_next_object()' callbacks were implemented for optimal performance when fetching operational data. This plugins requires ConfD 6.5 or later since it uses the new leaf-list API introduced in ConfD 6.5. To install the plugin, the --enable-confd option should be given to the configure script, specifying the location where ConfD is installed. Example: ./configure --enable-confd=/root/confd-6.6 When installed, the confd plugin will be available for all FRR daemons and can be loaded using the -M (or --module) command line option. Example: zebra -M confd. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-10-27lib: introduce new northbound APIRenato Westphal
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>