Commit graph

90 commits

Author SHA1 Message Date
Mark Stapp 7e1ed59d74 mgmtd: clean up -Wshadow warnings
Clean up various variable-shadow warnings in mgmtd.

Signed-off-by: Mark Stapp <mjs@cisco.com>
2025-04-08 14:41:27 -04:00
Donald Sharp 62f35c7bdb mgmtd: Prevent use after free
ci is picking up this use after free on occasion:

    ERROR: AddressSanitizer: attempting to call malloc_usable_size() for pointer which is not owned: 0x6030001d94a0
        0 0x7fab994b7f04 in __interceptor_malloc_usable_size ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:119
        1 0x7fab994264f6 in __sanitizer::BufferedStackTrace::Unwind(unsigned long, unsigned long, void*, bool, unsigned int) ../../../../src/libsanitizer/sanitizer_common/sanitizer_stacktrace.h:131
        2 0x7fab994264f6 in __asan::asan_malloc_usable_size(void const*, unsigned long, unsigned long) ../../../../src/libsanitizer/asan/asan_allocator.cpp:1058
        3 0x7fab99039bcf in mt_count_free lib/memory.c:78
        4 0x7fab99039bcf in qfree lib/memory.c:130
        5 0x7fab98ff971a in hash_clean lib/hash.c:290
        6 0x56110cdb0e7f in mgmt_txn_hash_destroy mgmtd/mgmt_txn.c:1881
        7 0x56110cdb0e7f in mgmt_txn_destroy mgmtd/mgmt_txn.c:2013
        8 0x56110cd8e5de in mgmt_terminate mgmtd/mgmt.c:91
        9 0x56110cd8e003 in sigint mgmtd/mgmt_main.c:90
        10 0x7fab990bf4b0 in frr_sigevent_process lib/sigevent.c:117
        11 0x7fab990ea7a1 in event_fetch lib/event.c:1740
        12 0x7fab9901a24e in frr_run lib/libfrr.c:1245
        13 0x56110cd8e21f in main mgmtd/mgmt_main.c:290
        14 0x7fab98af9249 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
        15 0x7fab98af9304 in __libc_start_main_impl ../csu/libc-start.c:360
        16 0x56110cd8dd30 in _start (/usr/lib/frr/mgmtd+0x3ad30)

    0x6030001d94a0 is located 0 bytes inside of 24-byte region [0x6030001d94a0,0x6030001d94b8)
    freed by thread T0 here:
        0 0x7fab994b76a8 in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:52
        1 0x7fab99039bf0 in qfree lib/memory.c:131
        2 0x7fab98ff93e1 in hash_release lib/hash.c:227
        3 0x56110cdaabdc in mgmt_txn_unlock mgmtd/mgmt_txn.c:1931
        4 0x56110cdab049 in mgmt_txn_delete mgmtd/mgmt_txn.c:1841
        5 0x56110cdab0ce in mgmt_txn_hash_free mgmtd/mgmt_txn.c:1864
        6 0x7fab98ff970b in hash_clean lib/hash.c:288
        7 0x56110cdb0e7f in mgmt_txn_hash_destroy mgmtd/mgmt_txn.c:1881
        8 0x56110cdb0e7f in mgmt_txn_destroy mgmtd/mgmt_txn.c:2013
        9 0x56110cd8e5de in mgmt_terminate mgmtd/mgmt.c:91
        10 0x56110cd8e003 in sigint mgmtd/mgmt_main.c:90
        11 0x7fab990bf4b0 in frr_sigevent_process lib/sigevent.c:117
        12 0x7fab990ea7a1 in event_fetch lib/event.c:1740
        13 0x7fab9901a24e in frr_run lib/libfrr.c:1245
        14 0x56110cd8e21f in main mgmtd/mgmt_main.c:290
        15 0x7fab98af9249 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

    previously allocated by thread T0 here:
        0 0x7fab994b83b7 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:77
        1 0x7fab990392fd in qcalloc lib/memory.c:106
        2 0x7fab98ff8b4f in hash_get lib/hash.c:156
        3 0x56110cdb13ae in mgmt_txn_create_new mgmtd/mgmt_txn.c:1825
        4 0x56110cdb3b4d in mgmt_txn_notify_be_adapter_conn mgmtd/mgmt_txn.c:2212
        5 0x56110cd91178 in mgmt_be_adapter_conn_init mgmtd/mgmt_be_adapter.c:842
        6 0x7fab990ec6de in event_call lib/event.c:2019
        7 0x7fab9901a243 in frr_run lib/libfrr.c:1246
        8 0x56110cd8e21f in main mgmtd/mgmt_main.c:290
        9 0x7fab98af9249 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

The only time that mgmt_txn_hash_free is called is in hash_clean.
There are other places that mgmt_txn_unlock/delete are called and
hash_release should be called.  Let's just notice when mgmtd is
being called from the hash_clean and not call hash_release (since
we know it is being released already)

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2025-02-26 12:34:05 -05:00
Christian Hopps 255026c2ce mgmtd: add notify selectors to filter datastore notifications
- Additionally push the selectors down to the backends

Signed-off-by: Christian Hopps <chopps@labn.net>
2025-01-13 23:40:52 -05:00
Christian Hopps b097a966cb lib: mgmtd: add changed and created to edit-reply msg
- This is used for various return values in RESTCONF

Signed-off-by: Christian Hopps <chopps@labn.net>
2024-09-17 05:31:00 -04:00
Christian Hopps 96db155acd lib: mgmtd: cleanup error value for native messaging
- Now if positive it's libyang LY_ERR, otherwise it's `-errno` value.

Signed-off-by: Christian Hopps <chopps@labn.net>
2024-09-17 03:04:59 -04:00
Donald Sharp baa0a1df5b *: Fix spelling errors found
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2024-08-15 09:19:37 -04:00
Christian Hopps 7afd7d99f2 lib: move non-error from __log_err to __dbg
Additionally, print `errmsg_if_any` in successful debug messages
if non-NULL.

fixes #16386 #16043

Signed-off-by: Christian Hopps <chopps@labn.net>
2024-07-22 07:54:50 -04:00
Christian Hopps 2661c0f62b mgmtd: some cleanup from original RPC commit
- Fix memleak on multiple errstr returns (multiple clients) Allow the
- multiple clients to all return results and merge them (as with other
  operations like get tree).

Signed-off-by: Christian Hopps <chopps@labn.net>
2024-05-07 14:54:57 +00:00
Igor Ryzhov cb6c182852 mgmtd: add native RPC processing
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-04-22 16:36:22 +03:00
Igor Ryzhov 5b219644ae mgmtd: add backend xpath map for RPC
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 d4c4b0939f mgmtd: remove unused event type
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-03-22 16:43:18 +02:00
Igor Ryzhov bbaf34b117 mgmtd: change error message
Make the wording clearer about what's going on.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-03-06 23:57:30 +02:00
Christian Hopps 40e51d2257 mgmtd: remove unused commit phase SEND_CFG
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-02-12 07:57:28 -05:00
Igor Ryzhov 0db4d555e9 mgmtd, vtysh: fix possible conflict when reading the config
When FRR starts, after mgmtd is initialized, backend clients connect to
it and request their config. To supply the config, mgmtd creates a
configuration transaction. At the same time, `vtysh -b` tries to read
the startup config and configure mgmtd, which also creates a
configuration transaction. If these two actions happen at the exact same
time, there's a conflict between them, because only a single
configuration translaction is allowed. Because of that, vtysh fails and
the config is completely ignored.

When starting the config reading, vtysh locks candidate and running
datastores in mgmtd. This commit adds locking of running datastore when
initializing the backend client. It allows to retry locking on the vtysh
side and read the config only when the lock is aquired instead of
failing.

This change also prevents running datastore from being changed during
initialization of backend clients. This could lead to a desynchronized
state between mgmtd and backends.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-02-07 18:37:29 +02:00
Igor Ryzhov a2caf2b5e1
Merge pull request #15268 from LabNConsulting/chopps/quieter-code
lowercase and localize debug/err macros
2024-02-01 10:54:30 +02:00
Christian Hopps ecd13c615b mgmtd: convert MGMT_TXN_DBG() to __dbg()
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-01-31 20:18:55 -05:00
Igor Ryzhov e13c590abe mgmtd: add ability to choose datastore to get data from
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-31 02:20:13 +02:00
Igor Ryzhov 4317c8ffa6 mgmtd: add support for with-defaults parameter to get-data
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-31 02:20:13 +02:00
Igor Ryzhov be9209a7e4 mgmtd: fix get-data transaction hangup
When no data requests were sent to the backends, return immediately,
instead of waiting for a timeout. This can happen if backends providing
the requested data are not connected to mgmtd.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-28 01:18:10 +02:00
Igor Ryzhov d79ca934eb mgmtd: fix commit request overwrite
There are places, where we can receive an existing commit transaction.
If we don't check that the request already exists, it gets overwritten
and we start having problems with transaction refcounters. Forbid having
multiple configuration sessions simultaneously.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-26 12:34:46 -05:00
Igor Ryzhov b92ad5046e mgmtd: fix memleak
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-26 12:34:46 -05:00
Igor Ryzhov 771c8f3b2a mgmtd: cleanup txn without scheduling
If the transaction is not cleaned up immediately, it can be still
referenced by some threds. If it's a commit thread and it's executed
before the actual cleanup, mgmtd crashes because of the missing
commit_cfg_req.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-26 12:34:46 -05:00
Igor Ryzhov 42b815f488 mgmtd: fix sending the same value to multiple clients
The value should not be cleared after sending it to the first client,
otherwise other clients receive an empty string.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-26 12:34:46 -05:00
Igor Ryzhov ed57daf60a mgmtd: remove unguarded debug log
The log doesn't provide any valuable information, so removing it instead
of adding a check.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-23 12:36:22 +02:00
Christian Hopps 9e34d817fc lib: better conditionalize leaf-list predicate xpath addition
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-19 15:27:24 +00:00
Igor Ryzhov 9859f308d2 lib, mgmtd: add ability to request the exact node in get-data request
RESTCONF expects to receive the exact node as a result, not the whole
data tree.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-15 10:27:33 +02:00
Igor Ryzhov e1cdb38ee6 lib, mgmtd: add ability to set content type in get-data request
Like in RESTCONF GET request and NETCONF get-data request, make it
possible to request state-only, config-only, or all data.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-15 10:27:33 +02:00
Donatas Abraitis fd690b9bc4
Merge pull request #15135 from idryzhov/mgmt-unused
mgmtd: remove unused/redundant variables
2024-01-13 21:08:24 +02:00
Igor Ryzhov 64d9f2f70d mgmtd: remove redundant next_phase variable
next_phase is always curr_phase + 1. It's not necessary to maintain it
separately. Also rename curr_phase to phase.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-12 13:29:15 +02:00
Christian Hopps 20d0d475cb
Merge pull request #14542 from idryzhov/nb-op-cb-split
Add more northbound operation types
2024-01-12 06:07:57 -05:00
Igor Ryzhov 2148f70b1a mgmtd: remove unused pending_be_proc variable
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-11 23:08:01 +02:00
Igor Ryzhov 0eac9b6f07 mgmtd: don't try to send config to disconnected clients
When determining the interested backend clients for a configuration
change, don't consider disconnected clients. This fixes a crash in
`mgmt_txn_send_be_txn_create` when trying to send data to a non-existing
adapter.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-11 22:56:42 +02:00
Igor Ryzhov d726114790 mgmt, lib: implement REPLACE operation
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>
2024-01-11 15:06:53 +02:00
Igor Ryzhov 3c2598a26f mgmt, lib: differentiate DELETE and REMOVE operations
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-11 15:06:53 +02:00
Igor Ryzhov 76e4eb84dd mgmtd, lib: implement CREATE_EXCL operation
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>
2024-01-11 15:06:53 +02:00
Igor Ryzhov 5d1a314038 lib: split nb_operation into two types
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>
2024-01-11 15:06:50 +02: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 30e63f2900 mgmtd: fix coverity CID 1574980
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-30 16:03:45 +00:00
Christian Hopps 913892e2ad mgmtd: fix coverity CID 1574978
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-30 16:03:45 +00:00
Christian Hopps 4e0147a05e lib: add dedicated API functions for native msgs
- reorg native message header

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-28 17:53:40 +00:00
Christian Hopps ad1ccb6e62 lib: northbound: add yielding and batching to oper-state queries
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-28 17:52:57 +00:00
Christian Hopps 9cd8693363 mgmtd: step 6: remove old unfinished get-data code
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-28 10:41:54 +00:00
Christian Hopps 8df542b219 mgmtd: step 5: add get-tree txn functionality
Adds the guts of the get-tree functionality that is called by or calls
the FE and BE code for get-tree processing.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-28 10:41:54 +00:00
Igor Ryzhov c81776c8e9 mgmtd: validate candidate yang tree before creating a config diff
The candidate yang tree should be validated before `nb_config_diff` is
called. `nb_config_diff` ignores all prohibited operations and can
provide an empty change list because of this. For example, if a user
deletes a mandatory node from the candidate datastore and tries to make
a commit, they'll receive the "No changes found to be committed!" error,
because such a change is ignored by `nb_config_diff`. Instead, mgmtd
should tell the user that their candidate datastore is not valid and
can't be commited.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-11-30 03:10:09 +02:00
Igor Ryzhov 354b3c4328 mgmtd: fix reply when running ds is not locked
At this stage, we should send a SET_CFG reply, not COMMIT_CFG reply.
Commit request is not yet initialized.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-11-21 23:18:40 +02:00
Christian Hopps 94659cf9e5
Merge pull request #14657 from idryzhov/mgmtd-remove-batch-ids
mgmtd, lib: remove batch ids from all messages
2023-11-18 05:59:44 +01:00
Igor Ryzhov b8a2efbf2f lib, mgmtd: respect base xpath in mgmtd
`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>
2023-11-12 20:28:08 +02:00
Igor Ryzhov b3b5951ee7 mgmtd, lib: remove batch ids from all messages
Batch IDs are only used to verify that all messages were received and
processed by a backend. It's not necessary to do that as we use reliable
stream transport - messages can't be dropped or received out of order.

This commit also fixes possible race condition that can happen if
one backend process messages slower than other backends.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-11-12 03:20:54 +02:00