]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: fix crash on "no import vrf" if no default bgp instance
authorDon Slice <dslice@cumulusnetworks.com>
Wed, 11 Apr 2018 16:12:39 +0000 (16:12 +0000)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 25 Apr 2018 16:39:17 +0000 (12:39 -0400)
Tripped over a crash running the cli_crawler that occurred when the
sequence was doing "import vrf NAME" and "no import vrf NAME" inside
a vrf but a default bgp instance had not been created.  This fix
auto-creates the default instance if the "import vrf NAME" is
entered and a default instance does not exist.

Ticket: CM-20532
Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com>
bgpd/bgp_vty.c

index 49b39d5ec2fc2a4552e681634d18a4b013eb6d5e..5d154772452103ad175f0f6701a4cddd5989b7a5 100644 (file)
@@ -6664,7 +6664,9 @@ DEFPY (bgp_imexport_vrf,
 {
        VTY_DECLVAR_CONTEXT(bgp, bgp);
        struct listnode *node;
-       struct bgp *vrf_bgp;
+       struct bgp *vrf_bgp, *bgp_default;
+       int32_t ret = 0;
+       as_t as = bgp->as;
        bool remove = false;
        int32_t idx = 0;
        char *vname;
@@ -6678,19 +6680,26 @@ DEFPY (bgp_imexport_vrf,
        afi = bgp_node_afi(vty);
        safi = bgp_node_safi(vty);
 
+       bgp_default = bgp_get_default();
+       if (!bgp_default) {
+               /* Auto-create assuming the same AS */
+               ret = bgp_get(&bgp_default, &as, NULL,
+                             BGP_INSTANCE_TYPE_DEFAULT);
+
+               if (ret) {
+                       vty_out(vty,
+                               "VRF default is not configured as a bgp instance\n");
+                       return CMD_WARNING;
+               }
+       }
+
        vrf_bgp = bgp_lookup_by_name(import_name);
        if (!vrf_bgp) {
-               int32_t ret = 0;
-               as_t as = bgp->as;
-
-               if (strcmp(import_name, BGP_DEFAULT_NAME) == 0) {
-                       vrf_bgp = bgp_get_default();
-                       if (!vrf_bgp)
-                               ret = bgp_get(&vrf_bgp, &as, NULL, BGP_INSTANCE_TYPE_DEFAULT);
-               } else {
+               if (strcmp(import_name, BGP_DEFAULT_NAME) == 0)
+                       vrf_bgp = bgp_default;
+               else
                        /* Auto-create assuming the same AS */
                        ret = bgp_get(&vrf_bgp, &as, import_name, bgp_type);
-               }
 
                if (ret) {
                        vty_out(vty,