Commit Graph

13 Commits

Author SHA1 Message Date
Renato Westphal
f65fb6b4b4 lib: fix "use of uninitialised value" valgrind warning
When FRR is built without the --enable-config-rollbacks option,
the nb_db_transaction_save() function does nothing and the
"transaction_id" output parameter is left uninitialized. For
this reason, all northbound clients should initialize the
"transaction_id" argument before calling nb_candidate_commit() or
nb_candidate_commit_apply() (except when a NULL pointer is given,
which is the case of the confd and sysrepo plugins).

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-14 16:32:23 -02:00
Renato Westphal
3cb4162cfe lib: fix segfault on freebsd when using vsnprintf() incorrectly
FreeBSD's libc segfaults when vsnprintf() is called with a null
format string. Add a null check before calling vsnprintf() to
resolve this problem.

Fixes #3537

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-01-02 22:32:13 -02:00
Emanuele Di Pascale
8427e0e674 lib: copy xpaths when enqueing changes
Just copying th const char* of the xpath means that if we
are enqueing multiple changes from a buffer, the last xpath
addedd will overwrite all of the previous references.
Copying the xpath to a buffer simplifies the API when
retrofitting the commands.

Signed-off-by: Emanuele Di Pascale <emanuele@voltanet.io>
2018-12-18 15:15:26 +01:00
Donald Sharp
64b81b3a64
Merge pull request #3442 from opensourcerouting/confirmed-commits
lib: add support for confirmed commits
2018-12-09 09:35:49 -05:00
Renato Westphal
18bf258a0d lib: implement the "show" command
The "show" command will be available in the configuration mode and
all configuration subnodes. It's used to display the section of
the candidate configuration being edited, instead of displaying
the entire candidate configuration like when "show configuration
candidate" is used. The goal is to add more convenience when editing
huge configurations.

When the transactional CLI mode is not used, the candidate
configuration and the running configuration are identical, hence in
this case we can say that the "show" command displays the section
of the running configuration being edited.

Example:
ripd(config)# show
Configuration:
!
frr version 6.1-dev
frr defaults traditional
!
interface eth0
 ip rip split-horizon poisoned-reverse
 ip rip authentication mode md5
 ip rip authentication string supersecret
!
interface eth1
 ip rip receive version 1
 ip rip send version 1
!
router rip
 allow-ecmp
 route 10.0.1.0/24
 route 10.0.2.0/24
!
end
ripd(config)#
ripd(config)#
ripd(config)# interface eth0
ripd(config-if)# show
!
interface eth0
 ip rip split-horizon poisoned-reverse
 ip rip authentication mode md5
 ip rip authentication string supersecret
!
ripd(config-if)# exit
ripd(config)#
ripd(config)#
ripd(config)# router rip
ripd(config-router)# show
!
router rip
 allow-ecmp
 route 10.0.1.0/24
 route 10.0.2.0/24
!
ripd(config-router)#

The "show" command only works for daemons converted to the new
northbound model. vtysh support will be implemented at a later
time as it will require some level of coordination between vtysh
and the FRR daemons.

Fixes #3148.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-12-07 11:29:58 -02:00
Renato Westphal
fbdc1c0a84 lib: add support for confirmed commits
Confirmed commits allow the user to request an automatic rollback to
the previous configuration if the commit operation is not confirmed
within a number of minutes. This is particularly useful when the user
is accessing the CLI through the network (e.g. using SSH) and any
configuration change might cause an unexpected loss of connectivity
between the user and the managed device (e.g. misconfiguration of a
routing protocol). By using a confirmed commit, the user can rest
assured the connectivity will be restored after the given timeout
expires, avoiding the need to access the router physically to fix
the problem.

When "commit confirmed TIMEOUT" is used, a new "commit" command is
expected to confirm the previous commit before the given timeout
expires. If "commit confirmed TIMEOUT" is used while there's already
a confirmed-commit in progress, the confirmed-commit timeout is
reset to the new value.

In the current implementation, if other users perform commits while
there's a confirmed-commit in progress, all commits are rolled back
when the confirmed-commit timeout expires. It's recommended to use
the "configure exclusive" configuration mode to prevent unexpected
outcomes when using confirmed commits.

When an user exits from the configuration mode while there's a
confirmed-commit in progress, the commit is automatically rolled
back and the user is notified about it. In the future we might
want to prompt the user if he or she really wants to exit from the
configuration mode when there's a pending confirmed commit.

Needless to say, confirmed commit only work for configuration
commands converted to the new northbound model. vtysh support will
be implemented at a later time.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-12-07 11:11:33 -02:00
Donald Sharp
0ee78eafbd
Merge pull request #3378 from opensourcerouting/remove-config-lock
*: remove the configuration lock from all daemons
2018-11-30 18:50:49 -05:00
Russ White
9f7b49e105
Merge pull request #3342 from opensourcerouting/nb-operational-data
Northbound: improved support for YANG-modeled operational data
2018-11-29 15:19:38 -05:00
Renato Westphal
1a4bc045de lib, tests: major rework in the operational-data callbacks
The northbound infrastructure for operational data was subpar compared
to the infrastructure for configuration data. This commit addresses most
of the existing problems, making it possible to write operational-data
callbacks for more complex YANG models.

Summary of the changes:
* Add support for nested YANG lists.
* Add support for leaf-lists.
* Add support for leafs of type "empty".
* Introduce the "show yang operational-data XPATH" command, and write an
  unit test for it. The main purpose of this command is to make it
  easier to test the operational-data northbound callbacks.
* Introduce the nb_oper_data_iterate() function, that can be used
  to iterate over operational data. Make the CLI and sysrepo use this
  function.
* Since ConfD has a very peculiar API, it can't reuse the
  nb_oper_data_iterate() like the other northbound clients. In this
  case, adapt the existing ConfD callbacks to support the new features
  (and make some performance improvements in the process).

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 18:28:53 -02:00
Renato Westphal
db452508bf lib, tools: use CHECK_FLAG/SET_FLAG more often in the northbound code
Cosmetic change to improve code readability a bit. No binary changes.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 17:35:58 -02:00
Renato Westphal
f344c66ea3 *: remove the configuration lock from all daemons
A while ago all FRR configuration commands were converted to use the
QOBJ infrastructure to keep track of configuration objects. This
means the configuration lock isn't necessary anymore because the
QOBJ code detects when someones tries to edit a configuration object
that was deleted and react accordingly (log an error and abort the
command).  The possibility of accessing dangling pointers doesn't
exist anymore since vty->index was removed.

Summary of the changes:
* remove the configuration lock and the vty_config_lockless() function.
* rename vty_config_unlock() to vty_config_exit() since we need to
  clean up a few things when exiting from the configuration mode.
* rename vty_config_lock() to vty_config_enter() to remove code
  duplication that existed between the three different "configuration"
  commands (terminal, private and exclusive).

Configuration commands converted to the new northbound model don't
need the configuration lock either since the northbound API also
detects when someone tries to edit a configuration object that
doesn't exist anymore.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 16:47:35 -02:00
Renato Westphal
a6233bfcb3 lib, ripd: rework API for converted CLI commands
When editing the candidate configuration, the northbound must ensure
that either all changes made by a command are accepted or none are.
This is done to prevent inconsistent states where only parts of a
command are applied in the event any error happens.

The previous API for converted commands, the nb_cli_cfg_change()
function, required callers to pass an array containing all changes
that needed to be applied in the candidate configuration. The
problem with this API is that it was very inconvenient for complex
commands, which change different configuration options depending
on several factors.  This required users to manipulate the array
of configuration changes using low-level primitives, making it
complicated to implement some commands.

To solve this problem, introduce a new API based on the two following
functions:
- nb_cli_enqueue_change()
- nb_cli_apply_changes()

The first function is used to enqueue configuration changes, one
at time. Then the nb_cli_apply_changes() function is used to apply
all the enqueued configuration changes.

To implement this, a static-sized array was allocated in the "vty"
structure, along with a counter of enqueued changes. This eliminates
the need to declare an array of configuration changes in every
converted CLI command, simplifying things quite considerably.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-11-26 15:57:23 -02:00
Renato Westphal
1c2facd12d lib: introduce new northbound API
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-10-27 16:16:12 -02:00