]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: forbid modification of bgp instance type
authorIgor Ryzhov <iryzhov@nfware.com>
Mon, 26 Apr 2021 12:46:58 +0000 (15:46 +0300)
committerIgor Ryzhov <iryzhov@nfware.com>
Thu, 29 Apr 2021 13:50:29 +0000 (16:50 +0300)
If a user issues the following commands:
```
router bgp 65000 vrf red
router bgp 65000 view red
```
bgpd ends up having NB config inconsistent with actual data.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
bgpd/bgp_nb_config.c
bgpd/bgp_vty.c

index 18a4ec90534ea3b27ae4d017d52c0b164fa08664..e753d87a380a8b05d13686a9d494367b4494da36 100644 (file)
@@ -1483,12 +1483,27 @@ int bgp_global_global_config_timers_keepalive_modify(
  */
 int bgp_global_instance_type_view_modify(struct nb_cb_modify_args *args)
 {
+       struct bgp *bgp;
+
        switch (args->event) {
        case NB_EV_VALIDATE:
+               /*
+                * Changing instance type is not allowed, but we must allow it
+                * once, when the BGP instance is created the first time.
+                * If the instance already exists - return the validation
+                * error.
+                */
+               bgp = nb_running_get_entry_non_rec(args->dnode->parent->parent,
+                                                  NULL, false);
+               if (bgp) {
+                       snprintf(args->errmsg, args->errmsg_len,
+                                "Changing instance type is not allowed");
+                       return NB_ERR_VALIDATION;
+               }
+               break;
        case NB_EV_PREPARE:
        case NB_EV_ABORT:
        case NB_EV_APPLY:
-               /* TODO: implement me. */
                break;
        }
 
index 1e465d2620f91f1dc20795db56c541843b6cd341..d82c92915470860bc65b5d8f2b33ca0f52ae4e73 100644 (file)
@@ -1388,6 +1388,10 @@ DEFUN_YANG_NOSH(router_bgp,
                        nb_cli_enqueue_change(vty,
                                              "./global/instance-type-view",
                                              NB_OP_MODIFY, "true");
+               } else {
+                       nb_cli_enqueue_change(vty,
+                                             "./global/instance-type-view",
+                                             NB_OP_MODIFY, "false");
                }
 
                ret = nb_cli_apply_changes(vty, base_xpath);