summaryrefslogtreecommitdiffstats
path: root/lib/northbound.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* lib: notify on datastore (oper-state) changesChristian Hopps5 days1-0/+5
| | | | Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: northbound: add new get() callback to add lyd_node direcltyChristian Hopps11 days1-2/+4
| | | | | | | | This allows eliminating the superfluous yang_data object (which is getting created used to call lyd_new_term then deleted). Instead just call lyd_new_term() in the callback directly. Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: add flag to have libyang load internal ietf-yang-library moduleChristian Hopps2024-10-071-2/+2
| | | | | | | | | | | | | | | | | | | | Mgmtd makes use of libyang's internal ietf-yang-library module to add support for said module to FRR management. Previously, mgmtd was loading this module explicitly; however, that required that libyang's `ietf-yang-library.yang` module definition file be co-located with FRR's yang files so that it (and ietf-datastore.yang) would be found when searched for by libyang using FRRs search path. This isn't always the case depending on how the user compiles and installs libyang so mgmtd was failing to run in some cases. Instead of doing it the above way we simply tell libyang to load it's internal version of ietf-yang-library when we initialize the libyang context. This required adding a boolean to a couple of the init functions which is why so many files are touched (although all the changes are minimal). Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: mgmtd: add `changed` and `created` to edit-reply msgChristian Hopps2024-09-171-8/+20
| | | | | | - This is used for various return values in RESTCONF Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: mgmtd: cleanup error value for native messagingChristian Hopps2024-09-171-2/+4
| | | | | | - Now if positive it's libyang LY_ERR, otherwise it's `-errno` value. Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: constify yang_resolve_snode_xpath resultsChristian Hopps2024-09-171-1/+1
| | | | | | Signed-off-by: Christian Hopps <chopps@labn.net> ang
* lib: fix style and add more comments to NB codeIgor Ryzhov2024-04-221-6/+14
| | | | Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: rework northbound RPC callbackIgor Ryzhov2024-04-221-5/+2
| | | | | | | 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>
* Merge pull request #15468 from idryzhov/mgmt-native-editChristian Hopps2024-04-221-0/+217
|\ | | | | mgmtd: add support for native 'edit' operation
| * mgmtd: add support for native 'edit' operationIgor Ryzhov2024-03-261-0/+217
| | | | | | | | | | | | | | | | This operation basically implements support for RESTCONF operations. It receives an xpath and a data tree in JSON/XML format, instead of a list of (xpath, value) tuples as required by the current protobuf interface. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* | *: remove confd pluginIgor Ryzhov2024-03-141-2/+0
|/ | | | | | | | | ConfD is not supported anymore and its use is discouraged by developers: https://discuss.tail-f.com/t/confd-premium-no-longer-available-future-of-confd/4552/6 Remove the code and all mentions of ConfD from the documentation. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: fix apply_finish callback in northboundIgor Ryzhov2024-03-051-1/+1
| | | | | | | When a node is top-level, we shouldn't stop the whole processing, we should just skip this single node. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: fix setting temporary log options for libyangIgor Ryzhov2024-02-261-3/+1
| | | | | | | | | | By calling `ly_log_options` with `LY_LOSTORE`, the current code effectively disables libyang logging and never enables it back. The call is done to get the current logging options, but we don't really need that. When looking for a schema node, we don't want neither to log nor to store the error, so simply set the temporary options to 0. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: fix nb callbacks for containers inside choice caseIgor Ryzhov2024-02-241-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Containers inside a choice's case must be treated as presence containers as they can be explicitly created and deleted. They must have `create` and `destroy` callbacks, otherwise the internal data they represent may never be deleted. The issue can be reproduced with the following steps: - create an access-list with destination-network params ``` # access-list test seq 1 permit ip any 10.10.10.0 0.0.0.255 ``` - delete the `destination-network` container ``` # mgmt delete-config /frr-filter:lib/access-list[name='test'][type='ipv4']/entry[sequence='1']/destination-network # mgmt commit apply MGMTD: No changes found to be committed! ``` As the `destination-network` container is non-presence, and all its leafs are mandatory, mgmtd doesn't see any changes to be commited and simply updates its YANG data tree without passing any updates to backend daemons. This commit fixes the issue by requiring `create` and `destroy` callbacks for containers inside choice's cases. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: fix order of northbound operationsIgor Ryzhov2024-02-241-4/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | When ordering operations, destroys must always come before other operations, to correctly cover the change of a "case" in a "choice". The problem can be reproduced with the following commands: ``` access-list test seq 1 permit 10.0.0.0/8 access-list test seq 1 permit host 10.0.0.1 access-list test seq 1 permit 10.0.0.0/8 ``` Before this commit, the order of changes would be the following: - `access-list test seq 1 permit 10.0.0.0/8` - `modify` for `ipv4-prefix` - `access-list test seq 1 permit host 10.0.0.1` - `destroy` for `ipv4-prefix` - `modify` for `host` - `access-list test seq 1 permit 10.0.0.0/8` - `modify` for `ipv4-prefix` - `destroy` for `host` As `destroy` for `host` is called last, it rewrites the fields that were filled by `modify` callback of `ipv4-prefix`. This commit fixes this problem by always calling `destroy` callbacks first. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: fix order of northbound callbacksIgor Ryzhov2024-02-201-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | When ordering the NB callbacks according to their priorities, if the operation is "destroy" we should reverse the order, to destroy the dependants before the dependencies. This fixes the crash, that can be reproduced with the following steps: ``` frr# conf term file-lock frr(config)# affinity-map map bit-position 10 frr(config)# interface test frr(config-if)# link-params frr(config-link-params)# affinity map frr(config-link-params)# exit frr(config-if)# exit frr(config)# mgmt commit apply frr(config)# no affinity-map map frr(config)# interface test frr(config-if)# link-params frr(config-link-params)# no affinity map frr(config-link-params)# exit frr(config-if)# exit frr(config)# mgmt commit apply ``` Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: always call new notification hooks tooChristian Hopps2024-02-151-4/+51
| | | | | | | - call the new notification hooks when backends call the old notification posting API. Signed-off-by: Christian Hopps <chopps@labn.net>
* lib, mgmtd: rework processing of yang notificationsIgor Ryzhov2024-02-111-0/+21
| | | | | | | | | | | | | Currently, YANG notification processing is done using a special type of callbacks registered in backend clients. In this commit, we start using regular northbound infrastructure instead, because it already has a convenient way of registering xpath-specific callbacks without the need for creating additional structures for each necessary notification. We also now pass a notification data to the callback, instead of a plain JSON. This allows to use regular YANG library functions for inspecting notification fields, instead of manually parsing the JSON. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: mgmtd: add YANG notification supportChristian Hopps2024-01-301-0/+17
| | | | Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: add support for "features" when loading YANG modulesIgor Ryzhov2024-01-281-1/+2
| | | | Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: remove leaf-list xpath hack from northboundIgor Ryzhov2024-01-231-20/+6
| | | | | | | | | | | 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>
* mgmtd: remove heavy duplication in mgmtd config readChristian Hopps2024-01-191-9/+16
| | | | | | | Previously each container created all it's decendents before descending into the children and repeating the process. Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: better conditionalize leaf-list predicate xpath additionChristian Hopps2024-01-191-10/+17
| | | | | | | 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>
* lib: libyang logging temp off to avoid unwanted log messageChristian Hopps2024-01-191-1/+10
| | | | | | | We don't want libyang logging when an schema path doesn't exist since this is an acceptable outcome. Signed-off-by: Christian Hopps <chopps@labn.net>
* Merge pull request #14542 from idryzhov/nb-op-cb-splitChristian Hopps2024-01-121-130/+183
|\ | | | | Add more northbound operation types
| * mgmt, lib: implement REPLACE operationIgor Ryzhov2024-01-111-2/+39
| | | | | | | | | | | | | | | | | | | | | | Replace operation removes the current data node configuration and sets the provided value. As current northbound code works only with one xpath at a time, the operation only makes sense to clear the config of a container without deleting it itself. However, the next step is to allow passing JSON-encoded complex values to northbound operations which will make replace operation much more useful. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
| * lib: move dnode creation into a separate functionIgor Ryzhov2024-01-111-28/+33
| | | | | | | | Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
| * mgmt, lib: differentiate DELETE and REMOVE operationsIgor Ryzhov2024-01-111-8/+12
| | | | | | | | | | | | | | | | | | 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>
| * mgmtd, lib: implement CREATE_EXCL operationIgor Ryzhov2024-01-111-2/+7
| | | | | | | | | | | | | | | | Currently, there's no difference between CREATE and MODIFY operations. To be compatible with NETCONF/RESTCONF, add new CREATE_EXCL operation that throws an error if the configuration data already exists. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
| * lib: split nb_operation into two typesIgor Ryzhov2024-01-111-93/+95
| | | | | | | | | | | | | | | | | | | | 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>
* | lib, mgmtd: rename ignore_cbs to ignore_cfg_cbsIgor Ryzhov2024-01-111-17/+17
|/ | | | | | | | Setting this variable to true makes NB ignore only configuration-related callbacks. CLI-related callbacks are still loaded and executed, so rename the variable to make it clearer. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: mgmtd: implement full XPath 1.0 predicate functionalityChristian Hopps2024-01-071-0/+21
| | | | | | | | Allow user to specify full YANG compatible XPath 1.0 predicates. This allows for trimming results of generic queries using functions and other non-key predicates from XPath 1.0 Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: remove unused/replaced oper-state iteration codeChristian Hopps2024-01-041-540/+0
| | | | Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: fix coverity CID 1574981Christian Hopps2023-12-301-11/+9
| | | | Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: northbound: add yielding and batching to oper-state queriesChristian Hopps2023-12-281-26/+75
| | | | Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: create and use libyang tree during oper-state walkChristian Hopps2023-12-281-55/+148
| | | | Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: northbound: improve xpath functionalityChristian Hopps2023-12-281-15/+81
| | | | | | | | | Allow user to leave keys off of a list entry node at the end of the xpath. This will return all list entries. Previously there was no way to just get the list entries. One had to leave off the last list entry node which would then return all list nodes as well as all the siblings at the same level. Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: load nb callbacks even with ignore_cbs setIgor Ryzhov2023-11-211-4/+0
| | | | | | | | | Don't skip NB callbacks loading when ignore_cbs is set for a YANG module. It allows us to use cli_show, cli_show_end and cli_cmp callbacks in mgmtd and output configuration directly from it instead of backend daemons. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: use LYD_VALIDATE_MULTI_ERROR only if availableDavid Lamparter2023-11-201-1/+6
| | | | | | | | | LYD_VALIDATE_MULTI_ERROR was added in libyang 2.1.36. The currently enforced minimum of libyang is 2.0.0. Stick an #ifdef around it. Fixes: 51a2a4b3f471 ("lib: print all errors when validating a config") Cc: Igor Ryzhov <iryzhov@nfware.com> Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: print all errors when validating a configIgor Ryzhov2023-11-151-3/+8
| | | | Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* Merge pull request #14768 from idryzhov/mgmtd-base-xpathDonald Sharp2023-11-131-15/+8
|\ | | | | lib, mgmtd: respect base xpath in mgmtd
| * lib, mgmtd: respect base xpath in mgmtdIgor Ryzhov2023-11-121-15/+8
| | | | | | | | | | | | | | | | | | `nb_cli_apply_changes` can be called with base xpath which should be prepended to xpaths of every change in a transaction. This base xpath is respected by regular northbound CLI but not by mgmtd. This commit fixes the problem. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* | lib: fix possible freeing of libyang dataIgor Ryzhov2023-11-111-3/+5
|/ | | | | | | | mgmtd frees all non-NULL change->value variables at the end of every commit. We shouldn't assign change->value with data returned by libyang to prevent freeing of library-allocated memory. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* Merge pull request #14544 from idryzhov/mgmt-scratch-bufferDonald Sharp2023-11-081-67/+1
|\ | | | | mgmt: delete candidate scratch buffer
| * mgmt: delete candidate scratch bufferIgor Ryzhov2023-10-061-67/+1
| | | | | | | | | | | | | | | | | | | | The code doesn't work at all. It tries to use libyang operation metadata in a regular (not diff) data tree, and regular data trees don't provide this data. Also, for destroy operations, it searches for nodes in the running config, which may not have the deleted nodes if we're not using implicit commits. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* | lib: remove incorrect comment from northboundIgor Ryzhov2023-10-211-5/+0
|/ | | | | | | | | | | This was true when we had only a CLI for configuration. Now mgmtd has a public frontend interface that can be used by external applications, and they can send invalid requests that lead to errors. This is still true for CLI though, so the same comment still stays in `nb_cli_apply_changes_internal`. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
* lib: random make-coverity-happy nitsDavid Lamparter2023-09-201-2/+2
| | | | Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* mgmtd: rm unused/unneeded code add couple commentsChristian Hopps2023-06-051-3/+4
| | | | Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: fix broken "show yang operational-data" functionalityChristian Hopps2023-04-171-2/+2
| | | | | | | | | Previously was using an API that returned the root of the data tree given the users input xpath value, and then used it like it was the leaf node (last not first). So basically this CLI command only worked when one requested the root node of the model. Signed-off-by: Christian Hopps <chopps@labn.net>
* lib: add and use new yang function for finding schema nodesChristian Hopps2023-04-171-1/+1
| | | | | | | | | | | | | | | Add a wrapper around lys_find_xpath which has an unfortunate API returning an allocated set of schema nodes when we only ever expect and want one. Another libyang function `lys_find_path` returns a single node; however, that function can assert/abort on invalid path values so is unsuitable for user input. Replace previous uses of `lys_find_path` with new API when dealing with possible invalid path values (i.e., from a user). Signed-off-by: Christian Hopps <chopps@labn.net>