]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_evpn.c
Merge branch 'master' into evpn-symmetric-routing
[mirror_frr.git] / bgpd / bgp_evpn.c
index 34fe8811a5adda481338b520f6a6ad1bdb4fb7db..12cc425bd36e5d6d850db63c69ed2756a25a31c5 100644 (file)
@@ -687,7 +687,8 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr,
                attr->ecommunity = ecommunity_merge(attr->ecommunity, ecom);
 
        /* Add the export RTs for L3VNI - currently only supported for IPV4 host
-        * routes */
+        * routes
+        */
        if (afi == AFI_IP) {
                vrf_export_rtl = bgpevpn_get_vrf_export_rtl(vpn);
                if (vrf_export_rtl && !list_isempty(vrf_export_rtl)) {
@@ -974,7 +975,8 @@ static int update_evpn_type5_route_entry(struct bgp *bgp_def,
        }
 
        /* create a new route entry if one doesnt exist.
-          Otherwise see if route attr has changed */
+          Otherwise see if route attr has changed
+        */
        if (!local_ri) {
 
                /* route has changed as this is the first entry */
@@ -1204,7 +1206,9 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
        attr.mp_nexthop_global_in = vpn->originator_ip;
        attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV4;
        attr.sticky = CHECK_FLAG(flags, ZEBRA_MAC_TYPE_STICKY) ? 1 : 0;
+  attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL);
        bgpevpn_get_rmac(vpn, &attr.rmac);
+       vni2label(vpn->vni, &(attr.label));
 
        /* Set up RT and ENCAP extended community. */
        build_evpn_route_extcomm(vpn, &attr,
@@ -1696,7 +1700,7 @@ static int install_evpn_route_entry_in_vrf(struct bgp *bgp_vrf,
        memset(pp, 0, sizeof(struct prefix));
        if (evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE)
                ip_prefix_from_type2_prefix(evp, pp);
-       else if(evp->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE)
+       else if (evp->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE)
                ip_prefix_from_type5_prefix(evp, pp);
 
        if (bgp_debug_zebra(NULL)) {
@@ -1854,7 +1858,10 @@ static int uninstall_evpn_route_entry_in_vrf(struct bgp *bgp_vrf,
        char buf1[PREFIX_STRLEN];
 
        memset(pp, 0, sizeof(struct prefix));
-       ip_prefix_from_type2_prefix(evp, pp);
+       if (evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE)
+               ip_prefix_from_type2_prefix(evp, pp);
+       else if (evp->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE)
+               ip_prefix_from_type5_prefix(evp, pp);
 
        if (bgp_debug_zebra(NULL)) {
                zlog_debug("uninstalling evpn prefix %s as ip prefix %s in vrf %s",
@@ -2108,7 +2115,8 @@ static int install_uninstall_routes_for_vrf(struct bgp *bgp_vrf,
                        struct prefix_evpn *evp = (struct prefix_evpn *)&rn->p;
 
                        /* if not mac-ip route skip this route */
-                       if (evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE)
+                       if (!(evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE ||
+                             evp->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE))
                                continue;
 
                        /* if not a mac+ip route skip this route */
@@ -2118,7 +2126,8 @@ static int install_uninstall_routes_for_vrf(struct bgp *bgp_vrf,
 
                        for (ri = rn->info; ri; ri = ri->next) {
                                /* Consider "valid" remote routes applicable for
-                                * this VRF. */
+                                * this VRF.
+                                */
                                if (!(CHECK_FLAG(ri->flags, BGP_INFO_VALID)
                                      && ri->type == ZEBRA_ROUTE_BGP
                                      && ri->sub_type == BGP_ROUTE_NORMAL))
@@ -2227,7 +2236,8 @@ static int install_uninstall_routes_for_vni(struct bgp *bgp,
 }
 
 /* Install any existing remote routes applicable for this VRF into VRF RIB. This
- * is invoked upon l3vni-add or l3vni import rt change */
+ * is invoked upon l3vni-add or l3vni import rt change
+ */
 static int install_routes_for_vrf(struct bgp *bgp_vrf)
 {
        install_uninstall_routes_for_vrf(bgp_vrf, 1);
@@ -2413,14 +2423,16 @@ static int install_uninstall_evpn_route(struct bgp *bgp, afi_t afi, safi_t safi,
                        continue;
 
                /* Import route into matching l2-vnis (type-2/type-3 routes go
-                * into l2vni table) */
+                * into l2vni table)
+                */
                irt = lookup_import_rt(bgp, eval);
                if (irt && irt->vnis)
                        install_uninstall_route_in_vnis(bgp, afi, safi, evp, ri,
                                                        irt->vnis, import);
 
                /* Import route into matching l3-vnis (type-2/type-5 routes go
-                * into l3vni/vrf table) */
+                * into l3vni/vrf table)
+                */
                vrf_irt = lookup_vrf_import_rt(eval);
                if (vrf_irt && vrf_irt->vrfs)
                        install_uninstall_route_in_vrfs(bgp, afi, safi, evp, ri,
@@ -2936,7 +2948,8 @@ static void evpn_mpattr_encode_type5(struct stream *s, struct prefix *p,
        p_evpn_p = &(p->u.prefix_evpn);
 
        /* len denites the total len of IP and GW-IP in the route
-          IP and GW-IP have to be both ipv4 or ipv6 */
+          IP and GW-IP have to be both ipv4 or ipv6
+        */
        if (IS_IPADDR_V4(&p_evpn_p->ip))
                len = 8; /* IP and GWIP are both ipv4 */
        else
@@ -3260,7 +3273,7 @@ void bgp_evpn_unconfigure_export_rt_for_vrf(struct bgp *bgp_vrf,
                list_delete_node(bgp_vrf->vrf_export_rtl, node_to_del);
 
        /* fall back to auto-generated RT if this was the last RT */
-       if (list_isempty(bgp_vrf->vrf_export_rtl)) {
+       if (bgp_vrf->vrf_export_rtl && list_isempty(bgp_vrf->vrf_export_rtl)) {
                UNSET_FLAG(bgp_vrf->vrf_flags, BGP_VRF_EXPORT_RT_CFGD);
                evpn_auto_rt_export_add_for_vrf(bgp_vrf);
        }
@@ -3280,11 +3293,13 @@ void bgp_evpn_handle_router_id_update(struct bgp *bgp, int withdraw)
        if (withdraw) {
 
                /* delete and withdraw all the type-5 routes
-                  stored in the global table for this vrf */
+                  stored in the global table for this vrf
+                */
                withdraw_router_id_vrf(bgp);
 
                /* delete all the VNI routes (type-2/type-3) routes for all the
-                * L2-VNIs */
+                * L2-VNIs
+                */
                hash_iterate(bgp->vnihash,
                             (void (*)(struct hash_backet *,
                                       void *))withdraw_router_id_vni,
@@ -3292,11 +3307,13 @@ void bgp_evpn_handle_router_id_update(struct bgp *bgp, int withdraw)
        } else {
 
                /* advertise all routes in the vrf as type-5 routes with the new
-                * RD */
+                * RD
+                */
                update_router_id_vrf(bgp);
 
                /* advertise all the VNI routes (type-2/type-3) routes with the
-                * new RD*/
+                * new RD
+                */
                hash_iterate(bgp->vnihash,
                             (void (*)(struct hash_backet *,
                                       void *))update_router_id_vni,
@@ -4063,7 +4080,8 @@ int bgp_evpn_local_l3vni_add(vni_t l3vni,
        as_t as = 0;
 
        /* get the default instamce - required to get the AS number for VRF
-        * auto-creation*/
+        * auto-creatio
+        */
        bgp_def = bgp_get_default();
        if (!bgp_def) {
                zlog_err("Cannot process L3VNI  %u ADD - default BGP instance not yet created",
@@ -4155,7 +4173,8 @@ int bgp_evpn_local_l3vni_del(vni_t l3vni,
        }
 
        /* unimport remote routes from VRF, if it is AUTO vrf bgp_delete will
-        * take care of uninstalling the routes from zebra */
+        * take care of uninstalling the routes from zebra
+        */
        if (!CHECK_FLAG(bgp_vrf->vrf_flags, BGP_VRF_AUTO))
                uninstall_routes_for_vrf(bgp_vrf);
 
@@ -4344,13 +4363,10 @@ void bgp_evpn_cleanup(struct bgp *bgp)
        bgp->vnihash = NULL;
        if (bgp->vrf_import_rtl)
                list_delete_and_null(&bgp->vrf_import_rtl);
-       bgp->vrf_import_rtl = NULL;
        if (bgp->vrf_export_rtl)
                list_delete_and_null(&bgp->vrf_export_rtl);
-       bgp->vrf_export_rtl = NULL;
        if (bgp->l2vnis)
                list_delete_and_null(&bgp->l2vnis);
-       bgp->l2vnis = NULL;
        bf_release_index(bm->rd_idspace, bgp->vrf_rd_id);
 }