Commit graph

88 commits

Author SHA1 Message Date
Christian Hopps 656c4692a0 lib: nb: fix bug with oper-state query on list data
The capacity of the xpath string was not guaranteed to be sufficient to hold all
the key predicates and so would truncate. Calculate the required space and
guarantee that it is available.

Signed-off-by: Christian Hopps <chopps@labn.net>
2025-02-26 13:38:42 +00:00
Christian Hopps 915dcd220d lib: northbound: support pre-built oper state in libyang tree
This also fixes a bug with specific (position specified) queries on keyless
lists. If the `get_next` callback is using the parent entry it will probably
crash as the code is passing the list_entry as both parent and child in the
specific lookup case.

There may currently be no code that uses the parent entry if the child entry is
non-NULL, though.

Signed-off-by: Christian Hopps <chopps@labn.net>
2025-02-24 04:09:17 +00:00
Christian Hopps 2375a11b08 lib: yang: add yang_parse_data function
This is similar to notify and RPC parsers, but this is for normal datastore
data. This is initially used in handling datastore notifications being sent to
another backend client[s].

Signed-off-by: Christian Hopps <chopps@labn.net>
2025-01-18 16:13:53 +00:00
Christian Hopps 8a52b69ca4 lib: northbound: add basic oper-state update functions
Signed-off-by: Christian Hopps <chopps@labn.net>
2025-01-13 23:40:52 -05:00
Christian Hopps e8648a0c72 lib: add flag to have libyang load internal ietf-yang-library module
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>
2024-10-07 03:32:44 +00:00
Christian Hopps 0913d9fc0e lib: constify yang_resolve_snode_xpath results
Signed-off-by: Christian Hopps <chopps@labn.net>

ang
2024-09-17 03:04:59 -04:00
Donald Sharp 286e6f8871 lib: Ensure SA that root cannot be NULL
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-08-22 13:53:47 -04:00
Lu.Mao 87c9060f90 lib: Fix LYD_NEW_PATH_OUTPUT issue to support libyang v3.x
Fix the LYD_NEW_PATH_OUTPUT undeclared error to support the latest libyang v3.x version,
and also compatible with old version.

Signed-off-by: Lu Mao <lu.mao@molex.com>
2024-08-09 17:32:37 -07:00
Christian Hopps 22eccbfab9 lib: fix incorrect use of error checking macro
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-06-06 22:38:48 -04:00
Martin Winter 8e2b2caf65
Merge pull request #15608 from vjardin/libyang3
libyang3 - fondation step 1
2024-05-08 12:48:03 +02:00
Vincent JARDIN 290c6e3184 lib: libyang.so.3 compatibilty layers
Let's support libyang 2.2.8 using libyang.so.3.0.8
It requires the commit ed277585ea from the libyang.

Signed-off-by: Vincent Jardin <vjardin@free.fr>
2024-05-08 01:48:06 +02:00
Igor Ryzhov 5c3e95d422 lib: add native RPC processing to mgmt backend client
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-04-22 16:36:22 +03:00
Igor Ryzhov 03883ee431 tests: add test for NB RPC callback
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-04-22 16:36:22 +03:00
Igor Ryzhov 1196d947d3 mgmtd: add support for native 'edit' operation
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>
2024-03-26 17:00:15 +02:00
Igor Ryzhov fb912e0900 lib: fix initialization of northbound nodes
When actions and notification are defined as descendants of other nodes,
they are not getting initialized, because the iterator skips them. Fix
the iterator to include them when traversing the schema.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-03-10 20:51:55 +02:00
Christian Hopps 4a93d171c2 lib: mgmtd: add xpath arg to notification message
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-02-18 18:53:37 -05:00
Christian Hopps dff28248c3 lib: actually create the tree for the conversion
Before this fix would always return empty results b/c there was no
libyang tree to print to output format.

Signed-off-by: Christian Hopps <chopps@labn.net>
2024-02-15 06:13:08 -05:00
Christian Hopps b8e07049a8 lib: fix memleak on success
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-02-15 06:13:08 -05:00
Igor Ryzhov d94f80fbc4 lib, mgmtd: fix processing of yang notifications
Current code assumes that notification is always sent in stripped JSON
format and therefore notification xpath starts at the third symbol of
notification data. Assuming JSON is more or less fine, because this
representation is internal to FRR, but the assumption about the xpath is
wrong, because it won't work for not top-level notifications. YANG
allows to define notification as a child for some data node deep into
the tree and in this case notification data contains not only the
notification node itself, but also all its parents.

To fix the issue, parse the notification data and get its xpath from its
schema node.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-10 01:00:24 +02:00
Igor Ryzhov 066bb6dc2d lib: add ietf-yang-metadata to the list of built-in modules
We don't need to manually load built-in modules. This fixes the
following warning in mgmtd:
```
YANG model "ietf-yang-metadata@*" "*@*"not embedded, trying external file
```

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-04 22:27:28 +02:00
Christian Hopps 25bb8b203c lib: mgmtd: add YANG notification support
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-01-30 04:57:10 -05:00
Igor Ryzhov fe76036002 lib: fix yang_dnode_dup
When duplicating nodes, we should always keep flags, especially the
LYD_NEW flag that indicates not validated data. This allows to select a
new choice's case without the need to explicitly remove the existing one.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-28 23:28:40 +02:00
Igor Ryzhov 3625360d88 lib: add support for "features" when loading YANG modules
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-28 23:28:40 +02:00
David Lamparter bbd858935f build: homologize path handling
Use consistent `e_somepath` names for expanded versions of `somepath`.
Also remove all paths from `config.h` and put them into
`lib/config_paths.h` - this is to make more obvious when someone is
doing something probably not quite properly structured.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-01-27 19:02:52 +01:00
Igor Ryzhov e39b60bac1 lib: add yang function for counting data nodes
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-26 12:34:23 -05:00
Igor Ryzhov 2b7d9532c8 lib: fix yang_lyd_trim_xpath
We should traverse all top-level siblings, not only the first one.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-14 19:08:15 +02:00
Christian Hopps 29f2a300a3 lib: fix coverity issues
** CID 1575504:  Insecure data handling  (TAINTED_SCALAR) (maybe)
** CID 1575505:  Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
** CID 1575506:  Integer handling issues  (CONSTANT_EXPRESSION_RESULT)
** CID 1575507:  Null pointer dereferences  (REVERSE_INULL)

Signed-off-by: Christian Hopps <chopps@labn.net>
2024-01-11 18:14:58 +00:00
Christian Hopps 1e4229fc1f lib: use libyang functions if they are present
Add configure.ac tests for libyang functions, if not present supply the
functionality ourselves in yang.[ch]

Signed-off-by: Christian Hopps <chopps@labn.net>
2024-01-07 15:17:56 +00:00
Christian Hopps cf67a7e265 lib: mgmtd: implement full XPath 1.0 predicate functionality
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>
2024-01-07 15:17:30 +00:00
Christian Hopps b8b5290105 lib: fixes required after rebasing
lib: fix checkpatch warnings
lib: darr: disable check
mgmtd: fix initialization

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-28 18:17:24 +00:00
Christian Hopps 356c01b121 lib: yang: add yang_get_node_keys() function
- comment out unused mem-leaking function.
- improve yang_dnode_get_path return type

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-28 17:52:57 +00:00
Christian Hopps db0211d48a lib: yang: add new functions
- yang_get_key_preds
- yang_lyd_new_list

A function like new_list was added recently to libyang,
this is a compat version.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-28 17:52:57 +00:00
Christian Hopps 80cac370d0 lib: yang: add tree "printing" utility functions
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-26 08:34:56 -05:00
Igor Ryzhov 81cb39a934 lib: fix printing multiple yang errors
When printing multiple YANG errors, we should print paths for all of
them, not only for the last one.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-11-15 03:27:32 +01:00
Christian Hopps 3184f63a90 lib: yang: restore old API use now that it's fixed
This also avoids a bug in the workaround function if the set variable
wasn't set to NULL the Debug version of libyang would sigsegv.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-11-06 17:44:58 -05:00
Christian Hopps 9e0241c8fb lib: add and use new yang function for finding schema nodes
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>
2023-04-17 01:43:48 -04:00
Yash Ranjan 74335ceb27 mgmtd: Add MGMT Transaction Framework
This commit introduces the MGMT Transaction framework that takes
management requests from one (or more) frontend client sessions,
translates them into transactions and drives them to completion
in co-oridination with one (or more) backend client daemons
involved in the request.

This commit includes the following functionalities in the changeset:
1. Introduces the actual Transaction module. Commands added related to
   transaction are:
   a. show mgmt transaction all
2. Adds support for commit rollback feature which stores upto the 10
   commit buffers. Each commit has a commit-id which can be used to
   rollback to the exact configuration state.
   Commands supported for this feature are:
   a. show mgmt commit-history
   b. mgmt rollback commit-id COMMIT_ID
3. Add hidden commands to enable record various performance metrics:
   a. mgmt performance-measurement
   b. mgmt reset-statistic

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-03-21 22:08:32 -04:00
Donald Sharp 8383d53e43
Merge pull request #12780 from opensourcerouting/spdx-license-id
*: convert to SPDX License identifiers
2023-02-17 09:43:05 -05:00
Louis Scalbert 05a12619dd lib,yang,zebra: add affinity-map support
Add the affinity-map global command to zebra. The syntax is:

> affinity-map NAME bit-position (0-1023)

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
2023-02-09 15:48:21 +01:00
David Lamparter acddc0ed3c *: auto-convert to SPDX License IDs
Done with a combination of regex'ing and banging my head against a wall.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-02-09 14:09:11 +01:00
David Lamparter 908e4c85b8 lib: avoid pointless search for built-in IETF YANG
This causes confusing/annoying log messages at startup otherwise:
`YANG model "ietf-inet-types@*" "*@*"not embedded, trying external file`

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-17 09:46:15 +01:00
Christian Hopps 3bb513c399 lib: adapt to version 2 of libyang
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-05-13 16:24:48 -04:00
David Lamparter bf8d3d6aca *: require semicolon after DEFINE_MTYPE & co
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>
2021-03-17 06:18:17 +01:00
Sebastien Merle 4d7b695d3a pathd: New SR-TE policy management daemon
This new daemon manages Segment-Routing Traffic-Engineering
(SR-TE) Policies and installs them into zebra. It provides
the usual yang support and vtysh commands to define or change
SR-TE Policies.

In a nutshell SR-TE Policies provide the possibility to steer
traffic through a (possibly dynamic) list of Segment Routing
segments to the endpoint of the policy. This list of segments
is part of a Candidate Path which again belongs to the SR-TE
Policy. SR-TE Policies are uniquely identified by their color
and endpoint. The color can be used to e.g. match BGP
communities on incoming traffic.

There can be multiple Candidate Paths for a single
policy, the active Candidate Path is chosen according to
certain conditions of which the most important is its
preference. Candidate Paths can be explicit (fixed list of
segments) or dynamic (list of segment comes from e.g. PCEP, see
below).

Configuration example:

segment-routing
 traffic-eng
  segment-list SL
   index 10 mpls label 1111
   index 20 mpls label 2222
  !
  policy color 4 endpoint 10.10.10.4
   name POL4
   binding-sid 104
   candidate-path preference 100 name exp explicit segment-list SL
   candidate-path preference 200 name dyn dynamic
  !
 !
!

There is an important connection between dynamic Candidate
Paths and the overall topic of Path Computation. Later on for
pathd a dynamic module will be introduced that is capable
of communicating via the PCEP protocol with a PCE (Path
Computation Element) which again is capable of calculating
paths according to its local TED (Traffic Engineering Database).
This dynamic module will be able to inject the mentioned
dynamic Candidate Paths into pathd based on calculated paths
from a PCE.

https://tools.ietf.org/html/draft-ietf-spring-segment-routing-policy-06

Co-authored-by: Sebastien Merle <sebastien@netdef.org>
Co-authored-by: Renato Westphal <renato@opensourcerouting.org>
Co-authored-by: GalaxyGorilla <sascha@netdef.org>
Co-authored-by: Emanuele Di Pascale <emanuele@voltanet.io>
Signed-off-by: Sebastien Merle <sebastien@netdef.org>
2020-12-18 16:34:02 +01:00
Rafael Zalamena 4e32d023cd lib: prevent libyang abstraction memory leak
Call `ly_set_free()` on `YANG_ITER_STOP` as well.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2020-12-09 09:57:28 -03:00
Donald Sharp cac886dd53
Merge pull request #6145 from patrasar/pim_nb_code_upstream
pimd: northbound backend code
2020-11-19 11:03:00 -05:00
Sarita Patra cf740d2e72 pimd: Northbound implementation for msdp mesh group, msdp peer commands
ip_msdp_peer
no_ip_msdp_peer
ip_msdp_mesh_group_member
no_ip_msdp_mesh_group_member
ip_msdp_mesh_group_source
no_ip_msdp_mesh_group_source
no_ip_msdp_mesh_group

Yang Model:
  augment /frr-routing:routing/frr-routing:control-plane-protocols/frr-routing:control-plane-protocol:
    +--rw pim
       +--rw address-family* [address-family]
          +--rw address-family          identityref
          +--rw msdp-mesh-group!
          |  +--rw mesh-group-name?   string
          |  +--rw member-ip*         ietf-inet-types:ip-address
          |  +--rw source-ip?         ietf-inet-types:ip-address
          +--rw msdp-peer* [peer-ip]
          |  +--rw peer-ip      ietf-inet-types:ip-address
          |  +--rw source-ip?   ietf-inet-types:ip-address

Signed-off-by: Sarita Patra <saritap@vmware.com>
2020-11-06 03:42:00 -08:00
Renato Westphal 8d869d378b lib: combine two YANG schema iteration functions into one
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-23 18:18:22 -03:00
Renato Westphal 9bde0b2569 lib: fix iteration over schema nodes of a single YANG module
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 8a923b4851 where the
gen_northbound_callbacks tool was generating duplicate callbacks
for certain modules.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2020-10-23 18:18:22 -03:00
Renato Westphal 8a923b4851 lib: better support for nested YANG augmentations
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>
2020-09-11 15:46:40 -03:00