]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgpd.c
Merge pull request #3367 from karamalla0406/frr3333
[mirror_frr.git] / bgpd / bgpd.c
index 32bbb78ef3ebb90ad8d4257b95cb3dea715101eb..48a3b1bb0902a9bfe27cd62bb3ffaf1e3d416cde 100644 (file)
@@ -171,6 +171,7 @@ int bgp_option_set(int flag)
        case BGP_OPT_MULTIPLE_INSTANCE:
        case BGP_OPT_CONFIG_CISCO:
        case BGP_OPT_NO_LISTEN:
+       case BGP_OPT_NO_ZEBRA:
                SET_FLAG(bm->options, flag);
                break;
        default:
@@ -186,6 +187,7 @@ int bgp_option_unset(int flag)
                if (listcount(bm->bgp) > 1)
                        return BGP_ERR_MULTIPLE_INSTANCE_USED;
        /* Fall through.  */
+       case BGP_OPT_NO_ZEBRA:
        case BGP_OPT_NO_FIB:
        case BGP_OPT_CONFIG_CISCO:
                UNSET_FLAG(bm->options, flag);
@@ -272,6 +274,10 @@ void bgp_router_id_zebra_bump(vrf_id_t vrf_id, const struct prefix *router_id)
 {
        struct listnode *node, *nnode;
        struct bgp *bgp;
+       struct in_addr *addr = NULL;
+
+       if (router_id != NULL)
+               addr = (struct in_addr *)&(router_id->u.prefix4);
 
        if (vrf_id == VRF_DEFAULT) {
                /* Router-id change for default VRF has to also update all
@@ -280,17 +286,43 @@ void bgp_router_id_zebra_bump(vrf_id_t vrf_id, const struct prefix *router_id)
                        if (bgp->inst_type == BGP_INSTANCE_TYPE_VRF)
                                continue;
 
-                       bgp->router_id_zebra = router_id->u.prefix4;
-                       if (!bgp->router_id_static.s_addr)
-                               bgp_router_id_set(bgp, &router_id->u.prefix4);
+                       if (addr)
+                               bgp->router_id_zebra = *addr;
+                       else
+                               addr = &bgp->router_id_zebra;
+
+                       if (!bgp->router_id_static.s_addr) {
+                               /* Router ID is updated if there are no active
+                                * peer sessions
+                                */
+                               if (bgp->established_peers == 0) {
+                                       if (BGP_DEBUG(zebra, ZEBRA))
+                                               zlog_debug("RID change : vrf %u, RTR ID %s",
+                                       bgp->vrf_id, inet_ntoa(*addr));
+                                       bgp_router_id_set(bgp, addr);
+                               }
+                       }
                }
        } else {
                bgp = bgp_lookup_by_vrf_id(vrf_id);
                if (bgp) {
-                       bgp->router_id_zebra = router_id->u.prefix4;
+                       if (addr)
+                               bgp->router_id_zebra = *addr;
+                       else
+                               addr = &bgp->router_id_zebra;
+
+                       if (!bgp->router_id_static.s_addr) {
+                               /* Router ID is updated if there are no active
+                                * peer sessions
+                                */
+                               if (bgp->established_peers == 0) {
+                                       if (BGP_DEBUG(zebra, ZEBRA))
+                                               zlog_debug("RID change : vrf %u, RTR ID %s",
+                                       bgp->vrf_id, inet_ntoa(*addr));
+                                       bgp_router_id_set(bgp, addr);
+                               }
+                       }
 
-                       if (!bgp->router_id_static.s_addr)
-                               bgp_router_id_set(bgp, &router_id->u.prefix4);
                }
        }
 }
@@ -3095,6 +3127,8 @@ int bgp_get(struct bgp **bgp_val, as_t *as, const char *name,
        }
 
        bgp = bgp_create(as, name, inst_type);
+       if (bgp_option_check(BGP_OPT_NO_ZEBRA) && name)
+               bgp->vrf_id = vrf_generate_id();
        bgp_router_id_set(bgp, &bgp->router_id_zebra);
        bgp_address_init(bgp);
        bgp_tip_hash_init(bgp);