summaryrefslogtreecommitdiffstats
path: root/lib/northbound.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* lib: Do not use sizeof() on `size_t errmsg_len`.zyxwvu Shi2021-11-181-2/+1
| | | | | | | This prevents caller from getting complete validation message. Signed-off-by: zyxwvu Shi <i@shiyc.cn>
* lib: do not attempt to create default nodes from NULL tree nodeChristian Hopps2021-06-121-2/+2
| | | | | | Perform same NULL check for dependent node creation code too. Signed-off-by: Christian Hopps <chopps@labn.net>
* northbound: KISS always batch yang config (file read), it's fasterChristian Hopps2021-06-021-7/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The backoff code assumed that yang operations always completed quickly. It checked for > 100 YANG modeled commands happening in under 1 second to enable batching. If 100 yang modeled commands always take longer than 1 second batching is never enabled. This is the exact opposite of what we want to happen since batching speeds the operations up. Here are the results for libyang2 code without and with batching. | action | 1K rts | 2K rts | 1K rts | 2K rts | 20k rts | | | nobatch | nobatch | batch | batch | batch | | Add IPv4 | .881 | 1.28 | .703 | 1.04 | 8.16 | | Add Same IPv4 | 28.7 | 113 | .590 | .860 | 6.09 | | Rem 1/2 IPv4 | .376 | .442 | .379 | .435 | 1.44 | | Add Same IPv4 | 28.7 | 113 | .576 | .841 | 6.02 | | Rem All IPv4 | 17.4 | 71.8 | .559 | .813 | 5.57 | (IPv6 numbers are basically the same as iPv4, a couple percent slower) Clearly we need this. Please note the growth (1K to 2K) w/o batching is non-linear and 100 times slower than batched. Notes on code: The use of the new `nb_cli_apply_changes_clear_pending` is to commit any pending changes (including the current one). This is done when the code would not correctly handle a single diff that included the current changes with possible following changes. For example, a "no" command followed by a new value to replace it would be merged into a change, and the code would not deal well with that. A good example of this is BGP neighbor peer-group changing. The other use is after entering a router level (e.g., "router bgp") where the follow-on command handlers expect that router object to now exists. The code eventually needs to be cleaned up to not fail in these cases, but that is for future NB cleanup. Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: fix northbound merge code (libyang)Christian Hopps2021-05-201-1/+1
| | | | | | | | lyd_merge_tree replaces dest siblings with source siblings, not what we want. Instead lyd_merge_siblings to keep both. Instead lyd_merge_siblings to keep both. Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: fix coverity warningsIgor Ryzhov2021-05-191-0/+2
| | | | | | CID 1504894 Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: adapt to version 2 of libyangChristian Hopps2021-05-131-136/+241
| | | | | | | | | Compile with v2.0.0 tag of `libyang2` branch of: https://github.com/CESNET/libyang staticd init load time of 10k routes now 6s vs ly1 time of 150s Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: get rid of flog() usage in NB codeDavid Lamparter2021-03-221-20/+20
| | | | | | | | This parametrized use of flog with variable EC and priority doesn't mesh particularly well with the xref code & there isn't really much reason to not use fixed/constant calls like this. Signed-off-by: David Lamparter <equinox@diac24.net>
* *: require semicolon after DEFINE_MTYPE & coDavid Lamparter2021-03-171-3/+3
| | | | | | | | | | | | | | | | | Back when I put this together in 2015, ISO C11 was still reasonably new and we couldn't require it just yet. Without ISO C11, there is no "good" way (only bad hacks) to require a semicolon after a macro that ends with a function definition. And if you added one anyway, you'd get "spurious semicolon" warnings on some compilers... With C11, `_Static_assert()` at the end of a macro will make it so that the semicolon is properly required, consumed, and not warned about. Consistently requiring semicolons after "file-level" macros matches Linux kernel coding style and helps some editors against mis-syntax'ing these macros. Signed-off-by: David Lamparter <equinox@diac24.net>
* lib: fix crash when iterating over nb operational dataIgor Ryzhov2021-02-261-0/+10
| | | | | | | | | Example: ``` show yang operational-data /frr-routing:routing/control-plane-protocols/control-plane-protocol[type='frr-staticd:staticd'][name='staticd'][vrf='default'] staticd ``` Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: add ability to register dependencies between northbound nodesIgor Ryzhov2021-02-221-4/+56
| | | | Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: add API to load YANG modules on demandRenato Westphal2020-10-231-15/+25
| | | | | | | | | | Make it possible to load YANG modules outside the main northbound initialization. The primary use case is to support YANG modules that are specific to an FRR plugin. Example: only load the PCEP YANG module when the corresponding FRR plugin is loaded. Other use cases might arise in the future. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* lib: combine two YANG schema iteration functions into oneRenato Westphal2020-10-231-3/+3
| | | | | | | | | | Combine yang_snodes_iterate_module() and yang_snodes_iterate_all() into an unified yang_snodes_iterate() function, where the first "module" parameter is optional. There's no point in having two separate YANG schema iteration functions anymore now that they are too similar. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* lib: fix iteration over schema nodes of a single YANG moduleRenato Westphal2020-10-231-4/+8
| | | | | | | | | | | | | | | | | | | | | The only safe way to iterate over all schema nodes of a given YANG module is by iterating over all schema nodes of all YANG modules and filter out the nodes that belong to other modules. The original yang_snodes_iterate_module() code did the following: 1 - Iterate over all top-level schema nodes of the given module; 2 - Iterate over all augmentations of the given module. While that iteration strategy is more efficient, it does't handle well more complex YANG hierarchies containing nested augmentations or self-augmenting modules. Any iteration that isn't done on the resolved YANG data hierarchy is fragile and prone to errors. Fixes regression introduced by commit 8a923b48513316b where the gen_northbound_callbacks tool was generating duplicate callbacks for certain modules. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* *: add errmsg to nb rpcChirag Shah2020-10-051-1/+4
| | | | | | | | | | | | | | | Display human readable error message in northbound rpc transaction failure. In case of vtysh nb client, the error message will be displayed to user. Testing: bharat# clear evpn dup-addr vni 1002 ip 11.11.11.11 Error type: generic error Error description: Requested IP's associated MAC aa:aa:aa:aa:aa:aa is still in duplicate state Signed-off-by: Chirag Shah <chirag@nvidia.com>
* lib: Tell the compiler we don't care about the return codeDonald Sharp2020-09-241-3/+3
| | | | | | | | When calling yang_snodes_iterate_subtree we don't care about the return code. So explicitly say we don't care so that SA tools can be on the same page as us. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
* Merge pull request #7079 from opensourcerouting/nested-yang-augmentationsDonald Sharp2020-09-191-2/+3
|\ | | | | lib: better support for nested YANG augmentations
| * lib: better support for nested YANG augmentationsRenato Westphal2020-09-111-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change the way the YANG schema node iteration functions work so that the northbound layer won't have issues with more complex YANG modules that contain multiple levels of YANG augmentations or modules that augment themselves indirectly (by augmenting groupings). Summary of the changes: * Change the yang_snodes_iterate_subtree() function to always follow augmentations and add an optional "module" parameter to narrow down the iteration to nodes of a single module (which is necessary in some cases). Also, remove the YANG_ITER_ALLOW_AUGMENTATIONS flag as it's no longer necessary. * Change yang_snodes_iterate_all() to do a DFS iteration on the resolved YANG data hierarchy instead of iterating over each module and their augmentations sequentially. Reported-by: Rafael Zalamena <rzalamena@opensourcerouting.org> Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* | lib: fix crashes with leafrefs that point to non-implemented modulesRenato Westphal2020-09-111-2/+14
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Whenever libyang loads a module that contains a leafref, it will also implicitly load the module of the referring node if it's not loaded already. That makes sense as otherwise it wouldn't be possible to validate the leafref value correctly. The problem is that loading a module implicitly violates the assumption of the northbound layer that all loaded modules are implemented (i.e. they have a northbound node associated to each schema node). This means that loading a module that isn't implemented can lead to crashes as the "priv" pointer of schema nodes is no longer guaranteed to be valid. To fix this problem, add a few null checks to ignore data nodes associated to non-implemented modules. The side effect of this change is harmless. If a daemon receives configuration it doesn't support (e.g. BFD peers on staticd), that configuration will be stored but otherwise ignored. This can only happen when using a northbound client like gRPC, as the CLI will never send to a daemon a command it doesn't support. This minor problem should go away in the long run as FRR migrates to a centralized management model, at which point the YANG-modeled configuration of all daemons will be maintained in a single place. Finally, update some daemons to stop implementing YANG modules they don't need to (i.e. revert 1b741a01c and a74b47f5). Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* *: record transaction based on control flagChirag Shah2020-08-201-2/+6
| | | | | | | | | | | In case of config rollback is enabled, record northbound transaction based on a control flag. The actual frr daemons would set the flag to true via nb_init from frr_init. This will allow test daemon to bypass recording transacation to db. Signed-off-by: Chirag Shah <chirag@nvidia.com>
* Merge pull request #6945 from qlyoung/nb-more-messagesRenato Westphal2020-08-201-1/+5
|\ | | | | More gRPC logging + errmsg for no changes
| * lib: fill nb errmsg when no changes during prepQuentin Young2020-08-191-1/+5
| | | | | | | | | | | | | | During the prep phase to apply a northbound commit, if no changes were detected make sure we fill the error message buffer to explain this. Signed-off-by: Quentin Young <qlyoung@nvidia.com>
* | lib: don't ignore error messages generated during the commit apply phaseRenato Westphal2020-08-151-11/+9
|/ | | | | | | | | | | | | | | | | | | | | While a configuration transaction can't be rejected once it reaches the APPLY phase, we should allow NB callbacks to generate error or warning messages when a configuration change is being applied. That should be useful, for example, to return warnings back to the user informing that the applied configuration has some kind of inconsistency or is missing something in order to be effectively activated. The infrastructure for this was already present, but the northbound layer was ignoring all errors/warnings generated during the apply/abort phases instead of returning them to the user. This commit changes that. In the gRPC plugin, extend the Commit() RPC adding a new "error_message" field to the response type. This is necessary to allow errors/warnings to be returned even when the commit operation succeeds (since grpc::Status::OK doesn't support error messages like the other status codes). Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* lib: add possibility to search non-recursively for NB node entriesGalaxyGorilla2020-08-071-3/+22
| | | | Signed-off-by: GalaxyGorilla <sascha@netdef.org>
* Merge pull request #6414 from opensourcerouting/nb-error-handlingSantosh P K2020-06-101-85/+285
|\ | | | | NB context + enhanced error handling
| * lib: detect and log unexpected return values from northbound callbacksRenato Westphal2020-05-291-5/+135
| | | | | | | | | | | | | | | | | | | | | | | | Each northbound callback has a set of valid return values, some of which might depend on the transaction phase. The valid return values for each callback are documented in the northbound main header. Add some code to detect when a callback returns an unexpected value and log the occurrence. This should help us to identify and fix such problems. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
| * lib: return human-readable error messages to the northbound clientsRenato Westphal2020-05-291-59/+109
| | | | | | | | | | | | | | | | | | | | Instead of returning only error codes (e.g. NB_ERR_VALIDATION) to the northbound clients, do better than that and also return a human-readable error message. This should make FRR more automation-friendly since operators won't need to dig into system logs to find out what went wrong in the case of an error. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
| * lib: introduce the northbound context structureRenato Westphal2020-05-291-36/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The new northbound context structure contains information about the client performing a configuration transaction. This information will be made available to all configuration callbacks through the args->context parameter. The usefulness of this structure comes from the fact that it can be used as a communication channel (both input and output) between the northbound callbacks and the northbound clients. This can be done through its "client_data" field which contains client-specific data. This should cover some very specific scenarios where a northbound callback should perform an action only if the configuration change is coming from a given client. An example would be sending a PCEP response to a PCE when an SR-TE policy is created or modified through the PCEP northbound client (for that to happen, the northbound callbacks need to have access to the PCEP request ID, which needs to be available). Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
| * lib: northbound style fixesRenato Westphal2020-05-291-6/+5
| | | | | | | | Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* | lib: move all userdata when changing node xpathQuentin Young2020-06-051-0/+24
|/ | | | | | | All userdata pointers need to be rekeyed to their new xpaths, not just the one associated with the dnode being moved. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* *: change the signature of the northbound callbacks to be more flexibleRenato Westphal2020-04-231-11/+56
| | | | | | | | | | | | | | | | | | | | | Having a fixed set of parameters for each northbound callback isn't a good idea since it makes it difficult to add new parameters whenever that becomes necessary, as several hundreds or thousands of existing callbacks need to be updated accordingly. To remediate this issue, this commit changes the signature of all northbound callbacks to have a single parameter: a pointer to a 'nb_cb_x_args' structure (where x is different for each type of callback). These structures encapsulate all real parameters (both input and output) the callbacks need to have access to. And adding a new parameter to a given callback is as simple as adding a new field to the corresponding 'nb_cb_x_args' structure, without needing to update any instance of that callback in any daemon. This commit includes a .cocci semantic patch that can be used to update old code to the new format automatically. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* lib: create a wrapper function for all northbound callbacksRenato Westphal2020-04-231-93/+129
| | | | | | | | The intention here is to keep the code more organized. These wrappers should be used by the northbound clients only, and never directly by any YANG backend code. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* lib: consolidate flexible array hack in a single placeRenato Westphal2020-04-041-0/+7
| | | | | | | | | | | | | | | | | Old gcc versions (< 5.x) have a bug that prevents C99 flexible arrays from working properly on shared libraries. We already have a hack in place to work around this problem, but it needs to be replicated in every declaration of a frr_yang_module_info variable within libfrr. This clearly isn't a good solution if we consider that many more libfrr YANG modules are about to come in the future. This commit introduces a different workaround that operates within the northbound layer itself, such that implementers of libfrr YANG modules won't need to worry about this problem anymore. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* *: Use short version of bool expressionsDonatas Abraitis2020-03-041-1/+1
| | | | Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
* *: make frr_yang_module_info constDavid Lamparter2019-11-301-1/+2
| | | | Signed-off-by: David Lamparter <equinox@diac24.net>
* lib: reduce memory allocation when processing large config transactionsRenato Westphal2019-10-121-13/+13
| | | | | | | | | | | | 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>
* lib: fix processing of the 'apply_finish' callbacksRenato Westphal2019-10-121-5/+22
| | | | | | | | 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>
* lib: avoid expensive operations when editing a candidate configRenato Westphal2019-10-121-11/+0
| | | | | | | | | | | | | | | | | 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>
* lib: add an exception in the northbound for operational data callbacksRenato Westphal2019-09-181-1/+12
| | | | | | | | | | | | | | | | | | 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>
* lib: fix ordering issues in the northboundRenato Westphal2019-09-181-13/+18
| | | | | | | | | | | | | | | | | | 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>
* lib: fix corner case when iterating over YANG-modeled operational dataRenato Westphal2019-09-181-3/+21
| | | | | | | | 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>
* Revert "lib: introduce a read-write lock for northbound configurations"Renato Westphal2019-09-181-97/+54
| | | | | | | | | | | | | | | | | 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.
* lib: introduce new 'pre_validate' northbound callbackRenato Westphal2019-09-181-6/+44
| | | | | | | | | | | | | 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>
* lib: add frr_with_mutex() block-wrapperDavid Lamparter2019-09-031-9/+4
| | | | | | | | | 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>
* Merge pull request #4088 from opensourcerouting/bump-libyang-requirement-versJafar Al-Gharaibeh2019-07-091-9/+2
|\ | | | | build, lib: bump libyang requirement version to >= 0.16.105 (-r3)
| * lib: use flag from new libyang version to simplify the codeRenato Westphal2019-07-021-9/+2
| | | | | | | | | | | | | | | | | | 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>
* | lib: fix a couple of yang validation issuesRenato Westphal2019-07-021-2/+5
|/ | | | | | | | | | | | | | | 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>
* lib: Fix gcc 9 warning -> error issueDonald Sharp2019-05-311-1/+1
| | | | | | | | | | | | | | | | | | | 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>
* lib: hashing functions should take const argumentsQuentin Young2019-05-141-1/+1
| | | | | | | | | | 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>
* lib: add new gRPC-based northbound pluginRenato Westphal2019-04-261-0/+2
| | | | | | | This is an experimental plugin for now. Full documentation will come later. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* lib: introduce a read-write lock for northbound configurationsRenato Westphal2019-04-261-54/+98
| | | | | | | | | | | | 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>