]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: fix display of candidate configurations
authorRenato Westphal <renato@opensourcerouting.org>
Thu, 7 Nov 2019 16:20:06 +0000 (13:20 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Sat, 30 Nov 2019 00:30:01 +0000 (21:30 -0300)
Commit 5e6a9350c16 implemented an optimization where candidate
configurations are validated only before being displayed. The
validation is done only to create default child nodes (due to
how libyang works) and any possible error is ignored (candidate
configurations can be invalid/incomplete).

The problem is that we were calling lyd_validate() only when the
CLI "with-defaults" option was used. But some cli_show() callbacks
assume that default nodes exist and can crash when displaying a
candidate configuration that isn't validated. To fix this, call
lyd_validate() before displaying candidate configuration even when
"with-defaults" is not used (that was a micro-optimization that
shouldn't have been done).

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
lib/northbound_cli.c

index d3e788d5d39ad6f00b36dbef5b69dd37b2d89f5e..009e5bd8242515f3dcb8749e4ab79cf56b517fd2 100644 (file)
@@ -432,12 +432,12 @@ void nb_cli_show_config_prepare(struct nb_config *config, bool with_defaults)
        lyd_schema_sort(config->dnode, 1);
 
        /*
-        * When "with-defaults" is used, call lyd_validate() only to create
-        * default child nodes, ignoring any possible validation error. This
-        * doesn't need to be done when displaying the running configuration
-        * since it's always fully validated.
+        * Call lyd_validate() only to create default child nodes, ignoring
+        * any possible validation error. This doesn't need to be done when
+        * displaying the running configuration since it's always fully
+        * validated.
         */
-       if (with_defaults && config != running_config)
+       if (config != running_config)
                (void)lyd_validate(&config->dnode,
                                   LYD_OPT_CONFIG | LYD_OPT_WHENAUTODEL,
                                   ly_native_ctx);