Commit Graph

5792 Commits

Author SHA1 Message Date
Donald Sharp
c5ecee63ac
Merge pull request #15517 from idryzhov/fix-yang-notif-actions
lib: fix initialization of northbound nodes
2024-03-11 15:47:17 -04:00
Donald Sharp
c514e84979
Merge pull request #15516 from opensourcerouting/freebsd-printf-sync-20240310
lib/printf: pick up ISO C23 / N2680 from FreeBSD
2024-03-11 10:32:32 -04: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
David Lamparter
a7ab0c943d lib/printf: update README
Make a note that `%w[f](8|16|32|64)d` was picked up.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-03-10 15:29:17 +01:00
Dag-Erling Smørgrav
c917023380 lib/printf: Implement N2680.
This adds specific width length modifiers in the form of wN and wfN
(where N is 8, 16, 32, or 64) which allow printing intN_t and
int_fastN_t without resorting to casts or PRI macros.

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D41725

FRR changes only include printf(), scanf/strtol are not locally
implemented in FRR.  Also added "(void) 0" to empty "else ..." to
avoid a compiler warning.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
(cherry picked from FreeBSD commit bce0bef3c6abab92c7ac8cc23b7cc632a382721e)
2024-03-10 15:29:17 +01:00
David Lamparter
5f16c640c2 lib: allow recirculating/relaying log messages
This is primarily intended for ldpd with its split-process architecture.
The LDE/LDPE subprocesses currently lose the extended zlog
functionality.

The zlog_live target already encapsulates all necessary bits for vtysh.
Reuse it for a relay function to be used in the main ldpd process.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-03-10 12:42:02 +01:00
Donald Sharp
7e058c201a
Merge pull request #15469 from LabNConsulting/chopps/keychain-yang
add ietf-key-chain YANG module support
2024-03-08 08:15:02 -05:00
Igor Ryzhov
18da736949 lib: fix order of interfaces in the config
Add missing cli_cmp callback. Without it, interfaces are not sorted and
printed in order they were created.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-03-06 21:41:35 +02:00
Donatas Abraitis
dfe570e988
Merge pull request #15487 from idryzhov/nb-apply-finish
lib: fix apply_finish callback in northbound
2024-03-06 08:44:09 +02:00
Igor Ryzhov
1853ccdb0f vty: change output of errors from mgmtd
Make errors look the same way as in regular non-mgmtd vty. We don't need
to show information about some internal request names.

Before:
```
ERROR: SET_CONFIG request failed, Error: YANG error(s):
 Path: Data location "/frr-affinity-map:lib/affinity-maps/affinity-map[name='a']".
 Error: Unique data leaf(s) "value" not satisfied in "/frr-affinity-map:lib/affinity-maps/affinity-map[name='b']" and "/frr-affinity-map:lib/affinity-maps/affinity-map[name='a']".
```

After:
```
% Configuration failed.

YANG error(s):
 Path: Data location "/frr-affinity-map:lib/affinity-maps/affinity-map[name='b']".
 Error: Unique data leaf(s) "value" not satisfied in "/frr-affinity-map:lib/affinity-maps/affinity-map[name='a']" and "/frr-affinity-map:lib/affinity-maps/affinity-map[name='b']".
```

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-03-05 17:56:21 +02:00
Igor Ryzhov
8287fbe453 lib: fix apply_finish callback in northbound
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>
2024-03-05 15:30:37 +02:00
Christian Hopps
4caffbda8e lib: add keychain northbound support
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-03-04 20:00:15 -05:00
Igor Ryzhov
cb6032d6b3 lib: fix infinite loop in __darr_in_vsprintf
`darr_avail` returns the available capacity excluding the already
existing terminating NULL byte. Take this into account when using
`darr_avail`. Otherwise, if the error length is a power of 2, the
capacity is never enough and the function stucks in an infinite loop.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-03-05 02:08:30 +02:00
Igor Ryzhov
ee0c1cc1e4 lib: fix __darr_in_vsprintf
If the initial darr capacity is not enough for the output, the `ap` is
reused multiple times, which is wrong, because it may be altered by
`vsnprintf`. Make a copy of `ap` each time instead of reusing.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-03-04 02:24:26 +02:00
Christian Hopps
29dba445b4 lib: add automatic xpath-based completion
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-03-03 17:59:36 -05:00
Christian Hopps
0f6538263d yang: Add initial model and generated code.
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-03-01 13:12:23 -05:00
Donatas Abraitis
7ad689b601
Merge pull request #15427 from idryzhov/fix-filter-nb-update
lib: fix access/prefix-list entry update
2024-02-27 13:39:05 +02:00
Igor Ryzhov
3cd6ddaec6 lib: fix setting temporary log options for libyang
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>
2024-02-26 11:30:57 +02:00
Igor Ryzhov
0bc2ab8598 lib: fix prefix-list entry update
When a prefix-list entry is updated, current NB code calls the
replacement code multiple times, once per each updated field. It means
that when multiple fields of an entry are changed in a single commit,
the replacement is done with an interim state of a prefix-list instead
of a final one. To fix the issue, we should call the replacement code
once, after all fields of an entry are updated.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-26 01:04:57 +02:00
Igor Ryzhov
a9460ae713 lib: fix access-list entry update
When an access-list entry is updated, current NB code calls notification
hooks for each updated field. It means that when multiple fields of an
entry are changed in a single commit, the hooks are run with an interim
state of an access-list instead of a final one. To fix the issue, we
should call the hooks once, after all fields of an entry are updated.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-26 01:04:57 +02:00
Christian Hopps
2aa6a67ec3
Merge pull request #15423 from idryzhov/fix-nb-choice
lib: fix processing of choices in northbound
2024-02-25 16:54:16 -05:00
Igor Ryzhov
0b905f7404 lib: fix nb callbacks for containers inside choice case
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>
2024-02-24 01:39:18 +02:00
Igor Ryzhov
38b85e0c2b lib: fix order of northbound operations
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>
2024-02-24 01:39:18 +02:00
Igor Ryzhov
13359c5cc9 lib: fix processing of notifications on mgmt fe client
Notifications are sent by mgmtd for each session of a client, so they
should be processed once per each session.

Also, add session_id parameter to an async_notification callback as all
other callbacks have this parameter.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-23 18:53:46 +02:00
Christian Hopps
37588ece04
Merge pull request #15401 from idryzhov/fix-nb-crash
Fix order of NB callbacks (and a crash)
2024-02-21 00:16:47 -05:00
Igor Ryzhov
01f371a677 lib: fix order of northbound callbacks
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>
2024-02-20 22:32:52 +02:00
Igor Ryzhov
323caf1d70 lib: add missing priority for affinity map callbacks
Other objects depend on affinity-maps being created before them by using
leafref with require-instance true. Set the priority to ensure that.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-20 22:27:29 +02:00
Donald Sharp
605009d729
Merge pull request #15393 from idryzhov/fix-base64
lib: fix base64 encoding
2024-02-20 10:20:28 -05:00
Russ White
8dbfc57ec6
Merge pull request #15377 from opensourcerouting/fix/bgpd_evpn_route_map
lib: Do not convert EVPN prefixes into IPv4/IPv6 if not needed
2024-02-20 10:17:46 -05:00
Igor Ryzhov
77149fabaa lib: fix base64 encoding
Remove adding of line feeds when encondig. We're using these functions
only for encoding binary data for storing in YANG data tree.

According to RFC 7950, section 9.8.2:
```
9.8.2.  Lexical Representation

   Binary values are encoded with the base64 encoding scheme (see
   Section 4 in [RFC4648]).
```

According to mentioned RFC 4648, section 3.1:
```
   Implementations MUST NOT add line feeds to base-encoded data unless
   the specification referring to this document explicitly directs base
   encoders to add line feeds after a specific number of characters.
```

Therefore, line feeds must not be added to the encoded data.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-19 15:35:22 +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
1d4ea437e4 lib: always call new notification hooks too
- call the new notification hooks when backends call the old notification
posting API.

Signed-off-by: Christian Hopps <chopps@labn.net>
2024-02-15 13:03:25 -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
Donatas Abraitis
439b739495 lib: Do not convert EVPN prefixes into IPv4/IPv6 if not needed
Convert only when this is really needed, e.g. `match ip address prefix-list ...`.

Otherwise, we can't have mixed match clauses, like:

```
match ip address prefix-list p1
match evpn route-type prefix
```

This won't work, because the prefix is already converted, and we can't extract
route type, vni, etc. from the original EVPN prefix.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-02-15 12:07:43 +02:00
Russ White
e74c3b0746
Merge pull request #15320 from donaldsharp/vtysh_limit_fds
lib, ospfclient, vtysh: Allow for a minimum fd poll size
2024-02-13 09:50:00 -05:00
Igor Ryzhov
3ac3a6605d lib, mgmtd: rework processing of yang notifications
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>
2024-02-11 13:26:52 +02: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
Donald Sharp
fcf1ab9c21
Merge pull request #15325 from opensourcerouting/fix/show_getsockopt
bgpd: Do not show TCP MSS if the socket is broken
2024-02-08 10:33:34 -05:00
Christian Hopps
ab3d0846bd
Merge pull request #15286 from idryzhov/fix-mgmt-startup
Fix conflict in mgmtd on startup
2024-02-07 16:04:11 -05:00
Donatas Abraitis
65497556ed bgpd: Do not show TCP MSS if the socket is broken
Just avoid calling for TCP MSS socket option if it's not in use.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2024-02-07 23:03:37 +02:00
Igor Ryzhov
2574f03a13 vtysh: remove resync workaround when exiting to config node
When exiting from a level below the config node, like `router rip`,
vtysh executes a resync by sending "end" and "conf term [file-lock]"
commands to all the daemons. As statet in the description comment, it's
done "in case one of the daemons is somewhere else". I don't think this
actually ever happens, but even if it is, it is a bug in a daemon that
needs to be fixed. This resync was okay before the introduction of
mgmtd, but now it unlocks and locks back the datastores during the
configuration reading process, which can lead to a failure which is
explained in the previous commit.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-07 18:37:29 +02:00
Donald Sharp
729dd6f626 lib, ospfclient, tests, vtysh: Allow for a minimum fd poll size
There exists cases where just honoring the FD_LIMIT size
as given to us by the operating system makes no sense.
Let's just make a switch to allow for this for things
like vtysh and ospfclient which will never have 1k files
open at any given time.

Fixes: #15315
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-02-07 10:38:02 -05:00
Donald Sharp
87b69cdd74
Merge pull request #15294 from okda-networks/sysrepo_set_sess_err
lib: set change errmsg in sysrepo session
2024-02-05 14:59:45 -05:00
Donald Sharp
cac925f005
Merge pull request #15291 from idryzhov/mgmtd-yang-embed
lib, mgmtd: fix missing embedded modules
2024-02-05 07:34:38 -05:00
Donald Sharp
015c11646d
Merge pull request #15297 from idryzhov/mgmtd--n
mgmtd: fix missing -n flag and help
2024-02-05 07:31:11 -05: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
Igor Ryzhov
c1b4976786 *: use af-specific autocompletion for prefix-lists when possible
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-04 22:26:48 +02:00
Igor Ryzhov
7ef83dcf0c lib: fix autocompletion for prefix-lists
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-04 22:26:48 +02:00
Igor Ryzhov
9c5f0ea98d lib: fix autocompletion for access-lists
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-04 22:26:48 +02:00