Commit graph

74 commits

Author SHA1 Message Date
Mark Stapp 098d692b6f *: expose and clean up 'noreturn' functions
Enable the -Wmissing-noreturn warning, and resolve warnings
for gcc and clang. Add a FRR_NORETURN macro and use that for
the new changes.

Signed-off-by: Mark Stapp <mjs@cisco.com>
2025-04-24 13:41:23 -04:00
Christian Hopps 2dc8d070d6 mgmtd: validate notify selectors to be xpaths that result to nodes
Also, only message interested backend clients about a path removal when last
supporting session is being removed from a given notification path.

Signed-off-by: Christian Hopps <chopps@labn.net>
2025-04-21 09:22:28 +00:00
Mark Stapp 2aa6e786a2
Merge pull request #18601 from LabNConsulting/chopps/mgmtd-candidate-overwrite
mgmtd: remove bogus "hedge" code which corrupted active candidate DS
2025-04-09 09:51:47 -04:00
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
Christian Hopps b12b4c28b4 mgmtd: remove bogus "hedge" code which corrupted active candidate DS
Say you have 2 mgmtd frontend sessions (2 vtysh's) the first one is long
running and is actively changing the global candidate datastore (DS),
the second one starts and exits, this code would then copy running
back over the candidate, blowing away any changes made by the first
session.

(the long running session could technically be any user)

Instead we need to trust the various cleanup code that already exits.
For example in the commit_cfg_reply on success candidate is copied to
running, and on failure *for implicit commit* running is copied back to
candidate clearing the change. This leaves the non-implicit
configuration changes in this case we actually want candidate to keep
it's changes in transactional cases, in the other case of pending commit
during a file read the code restores candidate (if needed) on exit from
"config terminal", with this call stack:

 vty_config_node_exit()
   nb_cli_pending_commit_check()
     nb_cli_classic_commit()
       nb_candidate_commit_prepare() [fail] -> copy running -> candidate
       nb_candidate_commit_apply() -> copy candidate -> running

fixes #18541

Signed-off-by: Christian Hopps <chopps@labn.net>
2025-04-08 05:39:18 +00:00
Christian Hopps 1f1d166288 lib: mgmtd: only send notify selectors to backends that provide.
- Previously we sent selectors to all backends when a replace was
  done, improve this to only send them to backends that provide
  the selected state.

Signed-off-by: Christian Hopps <chopps@labn.net>
2025-01-18 16:13:54 +00: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 5ffa10aac1 mgmtd: improve debug statement
Signed-off-by: Christian Hopps <chopps@labn.net>
2025-01-06 08:07:36 -05:00
Christian Hopps 764f276022 mgmtd: fix memory leak in FE adapter
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-12-24 03:04:23 -05:00
Christian Hopps c5df98aece mgmtd: add ietf-yang-library support
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-09-17 22:27:36 -04: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 d57a6f761e mgmtd: allow dest DS "running" if implicit lock+commit
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-09-17 03:04:59 -04: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
Christian Hopps e7fc74aa14 mgmtd: fix a couple compilation warnings.
Also an empty (thus non-replace) notify selectors message shouldn't
clear the selectors, it should just do nothing.

Signed-off-by: Christian Hopps <chopps@labn.net>
2024-08-18 05:33:29 -05:00
Christian Hopps 3dad09b228 mgmtd: add native session-req (create/delete) messages
This addition allows for a limited native-message-only front-end
interaction.

Signed-off-by: Christian Hopps <chopps@labn.net>
2024-06-11 10:37:31 -04:00
Christian Hopps 657f1650e6 mgmtd: add front-end notification selector support
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-06-06 22:39:53 -04:00
Christian Hopps a727cc7d76 mgmtd: rpc and action handling both should use rpc map.
The previous idea of using config xpath registrations for actions b/c
the config is the subject of the action is sub-optimal. It splits
handling of YANG "actions" (Action and RPCs) between 2 different
registartion maps for the same category of functionality.

Signed-off-by: Christian Hopps <chopps@labn.net>
2024-05-07 03:34:41 +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
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 31b6d684e1 mgmtd: convert MGMT_FE_ADAPTER_DBG() to __dbg()
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-01-31 20:19:23 -05:00
Igor Ryzhov dda5de0340 mgmtd: fix printing an empty data tree
We don't need to create an actual tree to print an empty tree, libyang
handles NULL just fine. The actual problem is that `yang_dnode_new`
creates a tree by validating it, and the validation creates all implicit
default nodes. Therefore, when called with "with-default" flags, instead
of getting an empty tree, we get a tree with all top-level default set.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-31 02:20:13 +02: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
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
David Lamparter 0d5a2497ca lib, mgmtd: fix wrong mgmtd socket paths
These paths were ignoring the `-N` namespacing option.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2024-01-27 19:01:19 +01: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 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
Igor Ryzhov 25d79af957 lib, mgmtd: add separate get-data request for the frontend
Currently it's the same as get-tree request for the backend, but it is
going to be expanded in the following commits.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-01-14 20:00:22 +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 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 00138ffb47 lib: fix clang SA warnings
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-01-07 15:04:18 +00:00
Christian Hopps 39e0f331d2 lib: mgmtd: increase soft-max msg size to 64K
- remove unused mgmt client/server constants

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 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
Christian Hopps be2424a875 mgmtd: step 4: FE adapter get-tree functionality
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-28 10:41:54 +00:00
Christian Hopps 71ede2db9e mgmtd: enable conn debug when user enables mgmtd debugs
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-05 13:39:40 -05:00
Christian Hopps 76835fd558 lib: mgmtd: only clear pending for the in-progress command
The lock/unlocks are being done short-circuit so they are never pending;
however, the handling of the unlock notification was always resuming the command
if pending was set. In all cases pending is set for another command. For example
implicit commit locks then when notified its done unlocks which was clearing the
set-config pending flag and resuming that command incorrectly.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-07-14 18:24:30 -04:00
anlan_cs c826c838d4 mgmtd: adjust one unnecessary bool convert
It is unnecessary to do the bool calculation for expression.

Signed-off-by: anlan_cs <vic.lan@pica8.com>
2023-07-12 17:29:28 +08:00
Christian Hopps dbb1bc6f35 mgmtd: consolidate getcfg and getdata msgs into "get"
eliminates tons of copy and paste code.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-06-27 18:00:56 -04:00
Christian Hopps df0173ceeb mgmtd: KISS the locking code
Move away from things like "lock if not locked" type code, require the
user has locked prior to geting to that point.

For now we warn if we are taking a lock we already had; however, this
should really be a failure point.

New requirements:

SETCFG -
  not implicit commit - requires user has locked candidate DS and they
    must unlock after

  implicit commit - requires user has locked candidate and running DS
    both locks will be unlocked on reply to the SETCFG

COMMITCFG -
  requires user has locked candidate and running DS and they must unlock
  after

  rollback - this code now get both locks and then does an unlock and
  early return thing on the adapter side. It needs to be un-special
  cased in follow up work that would also include tests for this
  functionality.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-06-19 00:13:28 -04:00
Christian Hopps 04b4ede097 mgmtd: simplify locking, removing read locks
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-06-18 16:17:46 -04:00
Christian Hopps f8500d4849 lib: mgmtd: use short-circuit for locking
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-06-18 16:17:32 -04:00
Christian Hopps 96f9e7853b lib: mgmtd: improvements in logging and commentary
- log names of datastores not numbers
- improve logging for mgmt_msg_read
- Rather than use a bool, instead store the pending const string name of
the command being run that has postponed the CLI. This adds some nice
information to the logging when enabled.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-06-13 04:11:29 -04:00
Christian Hopps 79d40972fd lib: mgmtd: fix/stdize debug message macros
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-06-12 02:32:29 -04:00
Christian Hopps 7a0894b532 mgmtd: Add note to SETCFG_REQ and debug logging
- convert impossible situation into assert

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-05-30 02:09:51 -04:00