]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgpd.c
zebra: Refactor kernel_rtm to be a bit smarter about how it handles options
[mirror_frr.git] / bgpd / bgpd.c
index a078c4f58743b8c7065f241556709a109941cc7e..7a3afbd18d543fa0bf99e30ba168e553c766c152 100644 (file)
 #include "bgpd/bgp_labelpool.h"
 #include "bgpd/bgp_pbr.h"
 #include "bgpd/bgp_addpath.h"
+#include "bgpd/bgp_evpn_private.h"
 
 DEFINE_MTYPE_STATIC(BGPD, PEER_TX_SHUTDOWN_MSG, "Peer shutdown message (TX)");
+DEFINE_MTYPE_STATIC(BGPD, BGP_EVPN_INFO, "BGP EVPN instance information");
 DEFINE_QOBJ_TYPE(bgp_master)
 DEFINE_QOBJ_TYPE(bgp)
 DEFINE_QOBJ_TYPE(peer)
@@ -274,6 +276,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
@@ -282,17 +288,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);
                }
        }
 }
@@ -1432,16 +1464,17 @@ static void bgp_recalculate_afi_safi_bestpaths(struct bgp *bgp, afi_t afi,
                                               safi_t safi)
 {
        struct bgp_node *rn, *nrn;
+       struct bgp_table *table;
 
        for (rn = bgp_table_top(bgp->rib[afi][safi]); rn;
             rn = bgp_route_next(rn)) {
-               if (rn->info != NULL) {
+               table = bgp_node_get_bgp_table_info(rn);
+               if (table != NULL) {
                        /* Special handling for 2-level routing
                         * tables. */
                        if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP
                            || safi == SAFI_EVPN) {
-                               for (nrn = bgp_table_top(
-                                            (struct bgp_table *)(rn->info));
+                               for (nrn = bgp_table_top(table);
                                     nrn; nrn = bgp_route_next(nrn))
                                        bgp_process(bgp, nrn, afi, safi);
                        } else
@@ -2952,6 +2985,9 @@ static struct bgp *bgp_create(as_t *as, const char *name,
        /* assign a unique rd id for auto derivation of vrf's RD */
        bf_assign_index(bm->rd_idspace, bgp->vrf_rd_id);
 
+       bgp->evpn_info = XCALLOC(MTYPE_BGP_EVPN_INFO,
+                                sizeof(struct bgp_evpn_info));
+
        bgp_evpn_init(bgp);
        bgp_pbr_init(bgp);
        return bgp;
@@ -3319,7 +3355,7 @@ void bgp_free(struct bgp *bgp)
                    || safi == SAFI_EVPN) {
                        for (rn = bgp_table_top(bgp->rib[afi][safi]); rn;
                             rn = bgp_route_next(rn)) {
-                               table = (struct bgp_table *)rn->info;
+                               table = bgp_node_get_bgp_table_info(rn);
                                bgp_table_finish(&table);
                        }
                }
@@ -3343,6 +3379,7 @@ void bgp_free(struct bgp *bgp)
 
        bgp_evpn_cleanup(bgp);
        bgp_pbr_cleanup(bgp);
+       XFREE(MTYPE_BGP_EVPN_INFO, bgp->evpn_info);
 
        for (afi = AFI_IP; afi < AFI_MAX; afi++) {
                vpn_policy_direction_t dir;
@@ -7520,7 +7557,7 @@ int bgp_config_write(struct vty *vty)
 
                /* Confederation identifier*/
                if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
-                       vty_out(vty, " bgp confederation identifier %i\n",
+                       vty_out(vty, " bgp confederation identifier %u\n",
                                bgp->confed_id);
 
                /* Confederation peer */
@@ -7927,5 +7964,4 @@ void bgp_terminate(void)
        if (bm->t_rmap_update)
                BGP_TIMER_OFF(bm->t_rmap_update);
 
-       bgp_lp_finish();
 }