summaryrefslogtreecommitdiff
path: root/lib/northbound_sysrepo.c
AgeCommit message (Collapse)Author
2024-08-27lib: common debug config outputIgor Ryzhov
Implement common code for debug config output and remove daemon-specific code that is duplicated everywhere. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-08-27lib: rework debug initIgor Ryzhov
The debug library allows to register a `debug_set_all` callback which should enable all debugs in a daemon. This callback is implemented exactly the same in each daemon. Instead of duplicating the code, rework the lib to allow registration of each debug type, and implement the common code only once in the lib. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-04-22lib: rework northbound RPC callbackIgor Ryzhov
Change input/output arguments of the RPC callback from lists of (xpath/value) tuples to YANG data trees. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-03-11lib: Remove MTYPE_SYSREPO it is not usedDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-02-03lib: set change errmsg in sysrepo sessionali-aqrabawi
this will enable sysrepo based cli users to know what went wrong when config change fails Signed-off-by: ali-aqrabawi <aaqrabaw@okdanetworks.com>
2024-01-23lib: remove leaf-list xpath hack from northboundIgor Ryzhov
Currently, when editing a leaf-list, `nb_candidate_edit` expects to receive it's xpath without a predicate and the value in a separate argument, and then creates the full xpath. This hack is complicated, because it depends on the operation and on the caller being a backend or not. Instead, let's require to always include the predicate in a leaf-list xpath. Update all the usages in the code accordingly. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-19lib: better conditionalize leaf-list predicate xpath additionChristian Hopps
If we're in the backend we already have the predicate added by mgmtd -- don't add it again. Signed-off-by: Christian Hopps <chopps@labn.net>
2024-01-11mgmt, lib: differentiate DELETE and REMOVE operationsIgor Ryzhov
Currently, there's a single operation type which doesn't return error if the object doesn't exists. To be compatible with NETCONF/RESTCONF, we should support differentiate between DELETE (fails when object doesn't exist) and REMOVE (doesn't fail if the object doesn't exist). Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-11lib: split nb_operation into two typesIgor Ryzhov
Currently, nb_operation enum means two different things - edit operation type (frontend part), and callback type (backend part). These types overlap, but they are not identical. We need to add more operation types to support NETCONF/RESTCONF integration, so it's better to have separate enums to identify different entities. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-12-28lib: northbound: add yielding and batching to oper-state queriesChristian Hopps
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-28lib: create and use libyang tree during oper-state walkChristian Hopps
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-04-17lib: always check for error, don't count on dnode being NULLChristian Hopps
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-03-24*: Convert `struct event_master` to `struct event_loop`Donald Sharp
Let's find a better name for it. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert THREAD_XXX macros to EVENT_XXX macrosDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert struct thread_master to struct event_master and it's ilkDonald Sharp
Convert the `struct thread_master` to `struct event_master` across the code base. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Convert thread_add_XXX functions to event_add_XXXDonald Sharp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-24*: Rename `struct thread` to `struct event`Donald Sharp
Effectively a massive search and replace of `struct thread` to `struct event`. Using the term `thread` gives people the thought that this event system is a pthread when it is not Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2023-03-21mgmtd: Add MGMT Backend Interface FrameworkChristian Hopps
This commit introduces the MGMT Backend Interface which can be used by back-end management client daemons like BGPd, Staticd, Zebra to connect with new FRR Management daemon (MGMTd) and utilize the new FRR Management Framework to let any Frontend clients to retrieve any operational data or manipulate any configuration data owned by the individual Backend daemon component. This commit includes the following functionalities in the changeset: 1. Add new Backend server for Backend daemons connect to. 2. Add a C-based Backend client library which can be used by daemons to communicate with MGMTd via the Backend interface. 3. Maintain a backend adapter for each connection from an appropriate Backend client to facilitate client requests and track one or more transactions initiated from Frontend client sessions that involves the backend client component. 4. Add the following commands to inspect various Backend client related information a. show mgmt backend-adapter all b. show mgmt backend-yang-xpath-registry c. show mgmt yang-xpath-subscription Co-authored-by: Pushpasis Sarkar <pushpasis@gmail.com> Co-authored-by: Abhinay Ramesh <rabhinay@vmware.com> Co-authored-by: Ujwal P <ujwalp@vmware.com> Signed-off-by: Yash Ranjan <ranjany@vmware.com>
2023-02-23lib: fix init. use of nb_context to be by value not by referenceChristian Hopps
Pass context argument by value on initialization to be clear that the value is used/saved but not a pointer to the value. Previously the northbound code was incorrectly holding a pointer to stack allocated context structs. However, the structure definition also had some musings (ifdef'd out code) and a comment that might be taken to imply that user data could follow the structure and thus be maintained by the code; it won't; so it can't; so get rid of the disabled misleading code/text from the structure definition. The common use case worked b/c the transaction which cached the pointer was created and freed inside a single function call (`nb_condidate_commit`) that executed below the stack allocation. All other use cases (grpc, confd, sysrepo, and -- coming soon -- mgmtd) were bugs. Signed-off-by: Christian Hopps <chopps@labn.net>
2023-02-09*: auto-convert to SPDX License IDsDavid Lamparter
Done with a combination of regex'ing and banging my head against a wall. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-06-09lib: Update sysrepo code with the latest API changesDonatas Abraitis
* sr_event_notif_send -> sr_notif_send * sr_process_events -> sr_subscription_process_events * sr_oper_get_items_subscribe -> sr_oper_get_subscribe * Removed SR_SUBSCR_CTX_REUSE flag from the code at all Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2022-03-15lib: support to sysrepo-2.0.41Fabio Antonini
northbound_sysrepo.c fixed to use the newer APIs from sysrepo 2.0.41 Signed-off-by: Fabio Antonini <f.antonini@tiesse.com>
2022-02-23*: Change thread->func to return void instead of intDonald Sharp
The int return value is never used. Modify the code base to just return a void instead. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-10-07*: don't pass pointers to a local variables to thread_add_*Igor Ryzhov
We should never pass pointers to local variables to thread_add_* family. When an event is executed, the library writes into this pointer, which means it writes into some random memory on a stack. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-05-13lib: adapt to version 2 of libyangChristian Hopps
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>
2021-04-22lib: rename very_late_init hook to config_postDavid Lamparter
very_late_init doesn't really say what this does, config_post is much more descriptive. (A config_pre is coming in a jiffy.) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-04-21build: make builddir include path consistentDavid Lamparter
... by referencing all autogenerated headers relative to the root directory. (90% of the changes here is `version.h`.) Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-03-17*: require semicolon after FRR_DAEMON_INFO & co.David Lamparter
... again ... Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-17*: require semicolon after DEFINE_MTYPE & coDavid Lamparter
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>
2020-10-23lib: combine two YANG schema iteration functions into oneRenato Westphal
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>
2020-10-23lib: fix iteration over schema nodes of a single YANG moduleRenato Westphal
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>
2020-10-05*: add errmsg to nb rpcChirag Shah
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>
2020-09-15lib: simplify handling of the sysrepo startup configurationRenato Westphal
In the new Sysrepo, all SR_EV_ENABLED notifications are followed by SR_EV_DONE notifications (assuming no errors occur), so there's no need to special case the SR_EV_ENABLED event anymore (e.g. do full transactions in one step). While here, add a few more guarded debug messages to facilitate troubleshooting. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-09-15lib: fix handling of deleted nodes in the sysrepo pluginRenato Westphal
Make the sysrepo plugin ignore the deletion of configuration nodes that don't exist anymore instead of logging an error and rejecting the changes. This is necessary because Sysrepo delivers delete notifications for all nodes of a deleted data tree instead of delivering a single delete notification of the top-level subtree node (which would suffice for the northbound layer). Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-09-15lib: postpone the sysrepo plugin initializationRenato Westphal
From Sysrepo's documentation: "Note: do not use fork() after creating a connection. Sysrepo internally stores PID of every created connection and this way a mismatch of PID and connection is created". Introduce a new "frr_very_late_init" hook in libfrr that is only called after the daemon is forked (when the '-d' option is used) and after the configuration is read. This way we can initialize the sysrepo plugin correctly even when the daemon is daemonized, and after the Sysrepo CLI commands are processed (only "debug northbound client sysrepo" for now). Fixes #7062 Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-08-20lib: adapt plugin to use new Sysrepo versionRenato Westphal
Sysrepo recently underwent a complete rewrite, where some substantial architectural changes were made (the most important one being the extinction of the sysrepod daemon). While most of the existing API was preserved, quite a few backward-incompatible changes [1] were introduced (mostly simplifications). This commit adapts our sysrepo northbound plugin to those API changes in order for it to be compatible with the latest Sysrepo version. Additional notes: * The old Sysrepo version is EOL and not supported anymore. * The new Sysrepo version requires libyang 1.x. Closes #6936 [1] https://github.com/sysrepo/sysrepo/blob/devel/CHANGES Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-08-14lib: don't ignore error messages generated during the commit apply phaseRenato Westphal
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>
2020-05-28lib: return human-readable error messages to the northbound clientsRenato Westphal
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>
2020-05-28lib: introduce the northbound context structureRenato Westphal
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>
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-04lib: Fix erroneously setting pointer values_cnt as NULLBi-Ruei, Chiu
It should be : *values_cnt = 0; not values_cnt = 0; Signed-off-by: Bi-Ruei, Chiu <biruei.chiu@gmail.com>
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-18lib: sync sysrepo module with latest API changesRenato Westphal
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-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>
2018-12-07lib: fix NETCONF network-wide transactions for confd and sysrepoRenato Westphal
ConfD and Sysrepo implement configuration transactions using a two-phase commit protocol (prepare + abort/apply). For network-wide transactions to work, ConfD and Sysrepo move to the second phase of the commit protocol only after receiving the results of the first phase from all devices involved in the transaction. If all devices succeed in the 'prepare' phase, then all of them move to the 'apply' phase and the transaction is committed. On the other hand, if any device fails in the 'prepare' phase, all of them move to 'abort' phase and the transaction is aborted. The confd and sysrepo plugins were implementing the full two-phase commit protocol upon receiving a request to validate the configuration changes and allocate all resources required to apply them (first phase). The notifications to abort or apply the changes (second phase) were being ignored since everything was being done in the first phase for simplicity. This wasn't a problem for single-device transactions, but it is for transactions involving multiple devices. Rework the code a bit to do things properly and fix this problem. 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: 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, 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>