]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_evpn.c
Merge pull request #3282 from opensourcerouting/60-fix-bfd-ipv6-unnumbered
[mirror_frr.git] / bgpd / bgp_evpn.c
index 959418658c9587ae8be1afcb8bcbd0ac9a1992ef..9e814516b73dfc31957b280020023ab0c717cac3 100644 (file)
@@ -43,6 +43,7 @@
 #include "bgpd/bgp_ecommunity.h"
 #include "bgpd/bgp_encap_types.h"
 #include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
 #include "bgpd/bgp_aspath.h"
 #include "bgpd/bgp_zebra.h"
 #include "bgpd/bgp_nexthop.h"
@@ -172,7 +173,8 @@ static struct vrf_irt_node *vrf_import_rt_new(struct ecommunity_val *rt)
 
        bgp_def = bgp_get_default();
        if (!bgp_def) {
-               zlog_err("vrf import rt new - def instance not created yet");
+               flog_err(BGP_ERR_NO_DFLT,
+                         "vrf import rt new - def instance not created yet");
                return NULL;
        }
 
@@ -202,7 +204,8 @@ static void vrf_import_rt_free(struct vrf_irt_node *irt)
 
        bgp_def = bgp_get_default();
        if (!bgp_def) {
-               zlog_err("vrf import rt free - def instance not created yet");
+               flog_err(BGP_ERR_NO_DFLT,
+                         "vrf import rt free - def instance not created yet");
                return;
        }
 
@@ -223,7 +226,9 @@ static struct vrf_irt_node *lookup_vrf_import_rt(struct ecommunity_val *rt)
 
        bgp_def = bgp_get_default();
        if (!bgp_def) {
-               zlog_err("vrf import rt lookup - def instance not created yet");
+               flog_err(
+                       BGP_ERR_NO_DFLT,
+                       "vrf import rt lookup - def instance not created yet");
                return NULL;
        }
 
@@ -619,7 +624,8 @@ static int bgp_zebra_send_remote_vtep(struct bgp *bgp, struct bgpevpn *vpn,
        if (is_evpn_prefix_ipaddr_v4(p))
                stream_put_in_addr(s, &p->prefix.imet_addr.ip.ipaddr_v4);
        else if (is_evpn_prefix_ipaddr_v6(p)) {
-               zlog_err(
+               flog_err(
+                       BGP_ERR_VTEP_INVALID,
                        "Bad remote IP when trying to %s remote VTEP for VNI %u",
                        add ? "ADD" : "DEL", vpn->vni);
                return -1;
@@ -730,10 +736,13 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr,
        struct ecommunity ecom_sticky;
        struct ecommunity ecom_default_gw;
        struct ecommunity ecom_rmac;
+       struct ecommunity ecom_na;
        struct ecommunity_val eval;
        struct ecommunity_val eval_sticky;
        struct ecommunity_val eval_default_gw;
        struct ecommunity_val eval_rmac;
+       struct ecommunity_val eval_na;
+
        bgp_encap_types tnl_type;
        struct listnode *node, *nnode;
        struct ecommunity *ecom;
@@ -798,6 +807,15 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr,
                        ecommunity_merge(attr->ecommunity, &ecom_default_gw);
        }
 
+       if (attr->router_flag) {
+               memset(&ecom_na, 0, sizeof(ecom_na));
+               encode_na_flag_extcomm(&eval_na, attr->router_flag);
+               ecom_na.size = 1;
+               ecom_na.val = (uint8_t *)eval_na.val;
+               attr->ecommunity = ecommunity_merge(attr->ecommunity,
+                                                  &ecom_na);
+       }
+
        attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
 }
 
@@ -1089,6 +1107,7 @@ static int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn,
 {
        struct bgp_info *old_select, *new_select;
        struct bgp_info_pair old_and_new;
+       struct prefix_evpn *evp;
        afi_t afi = AFI_L2VPN;
        safi_t safi = SAFI_EVPN;
        int ret = 0;
@@ -1100,6 +1119,7 @@ static int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn,
        old_select = old_and_new.old;
        new_select = old_and_new.new;
 
+       evp = (struct prefix_evpn *)&rn->p;
        /* If the best path hasn't changed - see if there is still something to
         * update
         * to zebra RIB.
@@ -1115,6 +1135,10 @@ static int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn,
                                SET_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY);
                        if (old_select->attr->default_gw)
                                SET_FLAG(flags, ZEBRA_MACIP_TYPE_GW);
+                       if (is_evpn_prefix_ipaddr_v6(evp) &&
+                           old_select->attr->router_flag)
+                               SET_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG);
+
                        ret = evpn_zebra_install(
                                bgp, vpn, (struct prefix_evpn *)&rn->p,
                                old_select->attr->nexthop, flags);
@@ -1148,6 +1172,10 @@ static int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn,
                        SET_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY);
                if (new_select->attr->default_gw)
                        SET_FLAG(flags, ZEBRA_MACIP_TYPE_GW);
+               if (is_evpn_prefix_ipaddr_v6(evp) &&
+                   new_select->attr->router_flag)
+                       SET_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG);
+
                ret = evpn_zebra_install(bgp, vpn, (struct prefix_evpn *)&rn->p,
                                         new_select->attr->nexthop, flags);
                /* If an old best existed and it was a "local" route, the only
@@ -1267,11 +1295,12 @@ static int update_evpn_type4_route_entry(struct bgp *bgp,
         * We shouldn't see the same route from any other vtep.
         */
        if (remote_ri) {
-               zlog_err(
-                        "%u ERROR: local es route for ESI: %s Vtep %s also learnt from remote",
-                        bgp->vrf_id,
-                        esi_to_str(&evp->prefix.es_addr.esi, buf, sizeof(buf)),
-                        ipaddr2str(&es->originator_ip, buf1, sizeof(buf1)));
+               flog_err(
+                       BGP_ERR_ES_INVALID,
+                       "%u ERROR: local es route for ESI: %s Vtep %s also learnt from remote",
+                       bgp->vrf_id,
+                       esi_to_str(&evp->prefix.es_addr.esi, buf, sizeof(buf)),
+                       ipaddr2str(&es->originator_ip, buf1, sizeof(buf1)));
                return -1;
        }
 
@@ -1354,10 +1383,12 @@ static int update_evpn_type4_route(struct bgp *bgp,
                                            &attr, 1, &ri,
                                            &route_changed);
        if (ret != 0) {
-               zlog_err("%u ERROR: Failed to updated ES route ESI: %s VTEP %s",
-                        bgp->vrf_id,
-                        esi_to_str(&p->prefix.es_addr.esi, buf, sizeof(buf)),
-                        ipaddr2str(&es->originator_ip, buf1, sizeof(buf1)));
+               flog_err(
+                       BGP_ERR_ES_INVALID,
+                       "%u ERROR: Failed to updated ES route ESI: %s VTEP %s",
+                       bgp->vrf_id,
+                       esi_to_str(&p->prefix.es_addr.esi, buf, sizeof(buf)),
+                       ipaddr2str(&es->originator_ip, buf1, sizeof(buf1)));
        }
 
        assert(ri);
@@ -1695,6 +1726,8 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
        attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV4;
        attr.sticky = CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY) ? 1 : 0;
        attr.default_gw = CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_GW) ? 1 : 0;
+       attr.router_flag = CHECK_FLAG(flags,
+                                     ZEBRA_MACIP_TYPE_ROUTER_FLAG) ? 1 : 0;
 
        /* PMSI is only needed for type-3 routes */
        if (p->prefix.route_type == BGP_EVPN_IMET_ROUTE)
@@ -1712,7 +1745,8 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
        if (p->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE &&
            (is_evpn_prefix_ipaddr_v4(p) ||
             !IN6_IS_ADDR_LINKLOCAL(&p->prefix.macip_addr.ip.ipaddr_v6)) &&
-           CHECK_FLAG(vpn->flags, VNI_FLAG_USE_TWO_LABELS))
+           CHECK_FLAG(vpn->flags, VNI_FLAG_USE_TWO_LABELS) &&
+           bgpevpn_get_l3vni(vpn))
                add_l3_ecomm = 1;
 
        /* Set up extended community. */
@@ -1964,7 +1998,8 @@ static int update_all_type2_routes(struct bgp *bgp, struct bgpevpn *vpn)
        /* Add L3 VNI RTs and RMAC for non IPv6 link-local attributes if
         * using L3 VNI for type-2 routes also.
         */
-       if (CHECK_FLAG(vpn->flags, VNI_FLAG_USE_TWO_LABELS))
+       if (CHECK_FLAG(vpn->flags, VNI_FLAG_USE_TWO_LABELS) &&
+           bgpevpn_get_l3vni(vpn))
                add_l3_ecomm = 1;
 
        build_evpn_route_extcomm(vpn, &attr, add_l3_ecomm);
@@ -1993,11 +2028,13 @@ static int update_all_type2_routes(struct bgp *bgp, struct bgpevpn *vpn)
                                update_evpn_route_entry(bgp, vpn, afi, safi, rn,
                                                        &attr_sticky, 0, 1, &ri,
                                                        0);
-                       else if (evpn_route_is_def_gw(bgp, rn))
+                       else if (evpn_route_is_def_gw(bgp, rn)) {
+                               if (is_evpn_prefix_ipaddr_v6(evp))
+                                       attr_def_gw.router_flag = 1;
                                update_evpn_route_entry(bgp, vpn, afi, safi, rn,
                                                        &attr_def_gw, 0, 1, &ri,
                                                        0);
-                       else
+                       else
                                update_evpn_route_entry(bgp, vpn, afi, safi, rn,
                                                        &attr, 0, 1, &ri, 0);
                }
@@ -2190,10 +2227,9 @@ static int delete_routes_for_es(struct bgp *bgp, struct evpnes *es)
        build_evpn_type4_prefix(&p, &es->esi, es->originator_ip.ipaddr_v4);
        ret = delete_evpn_type4_route(bgp, es, &p);
        if (ret) {
-               zlog_err(
-                       "%u failed to delete type-4 route for ESI %s",
-                       bgp->vrf_id,
-                       esi_to_str(&es->esi, buf, sizeof(buf)));
+               flog_err(BGP_ERR_EVPN_ROUTE_DELETE,
+                         "%u failed to delete type-4 route for ESI %s",
+                         bgp->vrf_id, esi_to_str(&es->esi, buf, sizeof(buf)));
        }
 
        /* Delete all routes from per ES table */
@@ -2850,7 +2886,8 @@ static int install_uninstall_routes_for_es(struct bgp *bgp,
                                                bgp, es, evp, ri);
 
                                if (ret) {
-                                       zlog_err(
+                                       flog_err(
+                                               BGP_ERR_EVPN_FAIL,
                                                "Failed to %s EVPN %s route in ESI %s",
                                                install ? "install"
                                                        : "uninstall",
@@ -2929,7 +2966,8 @@ static int install_uninstall_routes_for_vrf(struct bgp *bgp_vrf, int install)
                                                        bgp_vrf, evp, ri);
 
                                        if (ret) {
-                                               zlog_err(
+                                               flog_err(
+                                                       BGP_ERR_EVPN_FAIL,
                                                        "Failed to %s EVPN %s route in VRF %s",
                                                        install ? "install"
                                                                : "uninstall",
@@ -3002,7 +3040,8 @@ static int install_uninstall_routes_for_vni(struct bgp *bgp,
                                                        bgp, vpn, evp, ri);
 
                                        if (ret) {
-                                               zlog_err(
+                                               flog_err(
+                                                       BGP_ERR_EVPN_FAIL,
                                                        "%u: Failed to %s EVPN %s route in VNI %u",
                                                        bgp->vrf_id,
                                                        install ? "install"
@@ -3104,11 +3143,11 @@ static int install_uninstall_route_in_es(struct bgp *bgp, struct evpnes *es,
                ret = uninstall_evpn_route_entry_in_es(bgp, es, evp, ri);
 
        if (ret) {
-               zlog_err("%u: Failed to %s EVPN %s route in ESI %s",
-                        bgp->vrf_id, install ? "install" : "uninstall",
-                        "ES",
-                        esi_to_str(&evp->prefix.es_addr.esi, buf,
-                                   sizeof(buf)));
+               flog_err(
+                       BGP_ERR_EVPN_FAIL,
+                       "%u: Failed to %s EVPN %s route in ESI %s", bgp->vrf_id,
+                       install ? "install" : "uninstall", "ES",
+                       esi_to_str(&evp->prefix.es_addr.esi, buf, sizeof(buf)));
                return ret;
        }
        return 0;
@@ -3147,11 +3186,12 @@ static int install_uninstall_route_in_vrfs(struct bgp *bgp_def, afi_t afi,
                                                                ri);
 
                if (ret) {
-                       zlog_err("%u: Failed to %s prefix %s in VRF %s",
-                                bgp_def->vrf_id,
-                                install ? "install" : "uninstall",
-                                prefix2str(evp, buf, sizeof(buf)),
-                                vrf_id_to_name(bgp_vrf->vrf_id));
+                       flog_err(BGP_ERR_EVPN_FAIL,
+                                 "%u: Failed to %s prefix %s in VRF %s",
+                                 bgp_def->vrf_id,
+                                 install ? "install" : "uninstall",
+                                 prefix2str(evp, buf, sizeof(buf)),
+                                 vrf_id_to_name(bgp_vrf->vrf_id));
                        return ret;
                }
        }
@@ -3182,12 +3222,14 @@ static int install_uninstall_route_in_vnis(struct bgp *bgp, afi_t afi,
                        ret = uninstall_evpn_route_entry(bgp, vpn, evp, ri);
 
                if (ret) {
-                       zlog_err("%u: Failed to %s EVPN %s route in VNI %u",
-                                bgp->vrf_id, install ? "install" : "uninstall",
-                                evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE
-                                        ? "MACIP"
-                                        : "IMET",
-                                vpn->vni);
+                       flog_err(
+                               BGP_ERR_EVPN_FAIL,
+                               "%u: Failed to %s EVPN %s route in VNI %u",
+                               bgp->vrf_id, install ? "install" : "uninstall",
+                               evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE
+                                       ? "MACIP"
+                                       : "IMET",
+                               vpn->vni);
                        return ret;
                }
        }
@@ -3500,14 +3542,7 @@ static int delete_withdraw_vni_routes(struct bgp *bgp, struct bgpevpn *vpn)
  */
 static void update_router_id_vni(struct hash_backet *backet, struct bgp *bgp)
 {
-       struct bgpevpn *vpn;
-
-       vpn = (struct bgpevpn *)backet->data;
-
-       if (!vpn) {
-               zlog_warn("%s: VNI hash entry for VNI not found", __FUNCTION__);
-               return;
-       }
+       struct bgpevpn *vpn = (struct bgpevpn *)backet->data;
 
        /* Skip VNIs with configured RD. */
        if (is_rd_configured(vpn))
@@ -3525,14 +3560,7 @@ static void update_router_id_vni(struct hash_backet *backet, struct bgp *bgp)
  */
 static void withdraw_router_id_vni(struct hash_backet *backet, struct bgp *bgp)
 {
-       struct bgpevpn *vpn;
-
-       vpn = (struct bgpevpn *)backet->data;
-
-       if (!vpn) {
-               zlog_warn("%s: VNI hash entry for VNI not found", __FUNCTION__);
-               return;
-       }
+       struct bgpevpn *vpn = (struct bgpevpn *)backet->data;
 
        /* Skip VNIs with configured RD. */
        if (is_rd_configured(vpn))
@@ -3566,8 +3594,9 @@ static int process_type2_route(struct peer *peer, afi_t afi, safi_t safi,
         */
        if (psize != 33 && psize != 37 && psize != 49 && psize != 36
            && psize != 40 && psize != 52) {
-               zlog_err("%u:%s - Rx EVPN Type-2 NLRI with invalid length %d",
-                        peer->bgp->vrf_id, peer->host, psize);
+               flog_err(BGP_ERR_EVPN_ROUTE_INVALID,
+                         "%u:%s - Rx EVPN Type-2 NLRI with invalid length %d",
+                         peer->bgp->vrf_id, peer->host, psize);
                return -1;
        }
 
@@ -3602,7 +3631,8 @@ static int process_type2_route(struct peer *peer, afi_t afi, safi_t safi,
                memcpy(&p.prefix.macip_addr.mac.octet, pfx, ETH_ALEN);
                pfx += ETH_ALEN;
        } else {
-               zlog_err(
+               flog_err(
+                       BGP_ERR_EVPN_ROUTE_INVALID,
                        "%u:%s - Rx EVPN Type-2 NLRI with unsupported MAC address length %d",
                        peer->bgp->vrf_id, peer->host, macaddr_len);
                return -1;
@@ -3613,7 +3643,8 @@ static int process_type2_route(struct peer *peer, afi_t afi, safi_t safi,
        ipaddr_len = *pfx++;
        if (ipaddr_len != 0 && ipaddr_len != IPV4_MAX_BITLEN
            && ipaddr_len != IPV6_MAX_BITLEN) {
-               zlog_err(
+               flog_err(
+                       BGP_ERR_EVPN_ROUTE_INVALID,
                        "%u:%s - Rx EVPN Type-2 NLRI with unsupported IP address length %d",
                        peer->bgp->vrf_id, peer->host, ipaddr_len);
                return -1;
@@ -3674,8 +3705,9 @@ static int process_type3_route(struct peer *peer, afi_t afi, safi_t safi,
         * IP len (1) and IP (4 or 16).
         */
        if (psize != 17 && psize != 29) {
-               zlog_err("%u:%s - Rx EVPN Type-3 NLRI with invalid length %d",
-                        peer->bgp->vrf_id, peer->host, psize);
+               flog_err(BGP_ERR_EVPN_ROUTE_INVALID,
+                         "%u:%s - Rx EVPN Type-3 NLRI with invalid length %d",
+                         peer->bgp->vrf_id, peer->host, psize);
                return -1;
        }
 
@@ -3715,7 +3747,8 @@ static int process_type3_route(struct peer *peer, afi_t afi, safi_t safi,
                p.prefix.imet_addr.ip.ipa_type = IPADDR_V4;
                memcpy(&p.prefix.imet_addr.ip.ip.addr, pfx, IPV4_MAX_BYTELEN);
        } else {
-               zlog_err(
+               flog_err(
+                       BGP_ERR_EVPN_ROUTE_INVALID,
                        "%u:%s - Rx EVPN Type-3 NLRI with unsupported IP address length %d",
                        peer->bgp->vrf_id, peer->host, ipaddr_len);
                return -1;
@@ -3751,8 +3784,9 @@ static int process_type4_route(struct peer *peer, afi_t afi, safi_t safi,
         *  RD (8), ESI (10), ip-len (1), ip (4 or 16)
         */
        if (psize != 23 && psize != 35) {
-               zlog_err("%u:%s - Rx EVPN Type-4 NLRI with invalid length %d",
-                        peer->bgp->vrf_id, peer->host, psize);
+               flog_err(BGP_ERR_EVPN_ROUTE_INVALID,
+                         "%u:%s - Rx EVPN Type-4 NLRI with invalid length %d",
+                         peer->bgp->vrf_id, peer->host, psize);
                return -1;
        }
 
@@ -3772,7 +3806,8 @@ static int process_type4_route(struct peer *peer, afi_t afi, safi_t safi,
        if (ipaddr_len == IPV4_MAX_BITLEN) {
                memcpy(&vtep_ip, pfx, IPV4_MAX_BYTELEN);
        } else {
-               zlog_err(
+               flog_err(
+                       BGP_ERR_EVPN_ROUTE_INVALID,
                        "%u:%s - Rx EVPN Type-4 NLRI with unsupported IP address length %d",
                        peer->bgp->vrf_id, peer->host, ipaddr_len);
                return -1;
@@ -3814,8 +3849,9 @@ static int process_type5_route(struct peer *peer, afi_t afi, safi_t safi,
         * Note that the IP and GW should both be IPv4 or both IPv6.
         */
        if (psize != 34 && psize != 58) {
-               zlog_err("%u:%s - Rx EVPN Type-5 NLRI with invalid length %d",
-                        peer->bgp->vrf_id, peer->host, psize);
+               flog_err(BGP_ERR_EVPN_ROUTE_INVALID,
+                         "%u:%s - Rx EVPN Type-5 NLRI with invalid length %d",
+                         peer->bgp->vrf_id, peer->host, psize);
                return -1;
        }
 
@@ -3846,7 +3882,8 @@ static int process_type5_route(struct peer *peer, afi_t afi, safi_t safi,
        /* Fetch IP prefix length. */
        ippfx_len = *pfx++;
        if (ippfx_len > IPV6_MAX_BITLEN) {
-               zlog_err(
+               flog_err(
+                       BGP_ERR_EVPN_ROUTE_INVALID,
                        "%u:%s - Rx EVPN Type-5 NLRI with invalid IP Prefix length %d",
                        peer->bgp->vrf_id, peer->host, ippfx_len);
                return -1;
@@ -3967,9 +4004,8 @@ static void cleanup_vni_on_disable(struct hash_backet *backet, struct bgp *bgp)
  */
 static void free_vni_entry(struct hash_backet *backet, struct bgp *bgp)
 {
-       struct bgpevpn *vpn;
+       struct bgpevpn *vpn = (struct bgpevpn *)backet->data;
 
-       vpn = (struct bgpevpn *)backet->data;
        delete_all_vni_routes(bgp, vpn);
        bgp_evpn_free(bgp, vpn);
 }
@@ -4041,11 +4077,6 @@ static void update_autort_vni(struct hash_backet *backet, struct bgp *bgp)
 {
        struct bgpevpn *vpn = backet->data;
 
-       if (!vpn) {
-               zlog_warn("%s: VNI hash entry for VNI not found", __PRETTY_FUNCTION__);
-               return;
-       }
-
        if (!is_import_rt_configured(vpn)) {
                if (is_vni_live(vpn))
                        bgp_evpn_uninstall_routes(bgp, vpn);
@@ -4078,7 +4109,8 @@ void bgp_evpn_withdraw_type5_route(struct bgp *bgp_vrf, struct prefix *p,
        build_type5_prefix_from_ip_prefix(&evp, p);
        ret = delete_evpn_type5_route(bgp_vrf, &evp);
        if (ret) {
-               zlog_err(
+               flog_err(
+                       BGP_ERR_EVPN_ROUTE_DELETE,
                        "%u failed to delete type-5 route for prefix %s in vrf %s",
                        bgp_vrf->vrf_id, prefix2str(p, buf, sizeof(buf)),
                        vrf_id_to_name(bgp_vrf->vrf_id));
@@ -4124,8 +4156,9 @@ void bgp_evpn_advertise_type5_route(struct bgp *bgp_vrf, struct prefix *p,
        build_type5_prefix_from_ip_prefix(&evp, p);
        ret = update_evpn_type5_route(bgp_vrf, &evp, src_attr);
        if (ret)
-               zlog_err("%u: Failed to create type-5 route for prefix %s",
-                        bgp_vrf->vrf_id, prefix2str(p, buf, sizeof(buf)));
+               flog_err(BGP_ERR_EVPN_ROUTE_CREATE,
+                         "%u: Failed to create type-5 route for prefix %s",
+                         bgp_vrf->vrf_id, prefix2str(p, buf, sizeof(buf)));
 }
 
 /* Inject all prefixes of a particular address-family (currently, IPv4 or
@@ -4639,7 +4672,6 @@ int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
        int addpath_encoded;
        int psize = 0;
        uint8_t rtype;
-       uint8_t rlen;
        struct prefix p;
 
        /* Start processing the NLRI - there may be multiple in the MP_REACH */
@@ -4673,7 +4705,7 @@ int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
                        return -1;
 
                rtype = *pnt++;
-               psize = rlen = *pnt++;
+               psize = *pnt++;
 
                /* When packet overflow occur return immediately. */
                if (pnt + psize > lim)
@@ -4684,7 +4716,8 @@ int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
                        if (process_type2_route(peer, afi, safi,
                                                withdraw ? NULL : attr, pnt,
                                                psize, addpath_id)) {
-                               zlog_err(
+                               flog_err(
+                                       BGP_ERR_EVPN_FAIL,
                                        "%u:%s - Error in processing EVPN type-2 NLRI size %d",
                                        peer->bgp->vrf_id, peer->host, psize);
                                return -1;
@@ -4695,7 +4728,8 @@ int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
                        if (process_type3_route(peer, afi, safi,
                                                withdraw ? NULL : attr, pnt,
                                                psize, addpath_id)) {
-                               zlog_err(
+                               flog_err(
+                                       BGP_ERR_PKT_PROCESS,
                                        "%u:%s - Error in processing EVPN type-3 NLRI size %d",
                                        peer->bgp->vrf_id, peer->host, psize);
                                return -1;
@@ -4706,7 +4740,8 @@ int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
                        if (process_type4_route(peer, afi, safi,
                                                withdraw ? NULL : attr, pnt,
                                                psize, addpath_id)) {
-                               zlog_err(
+                               flog_err(
+                                       BGP_ERR_PKT_PROCESS,
                                        "%u:%s - Error in processing EVPN type-4 NLRI size %d",
                                        peer->bgp->vrf_id, peer->host, psize);
                                return -1;
@@ -4716,7 +4751,8 @@ int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
                case BGP_EVPN_IP_PREFIX_ROUTE:
                        if (process_type5_route(peer, afi, safi, attr, pnt,
                                                psize, addpath_id, withdraw)) {
-                               zlog_err(
+                               flog_err(
+                                       BGP_ERR_PKT_PROCESS,
                                        "%u:%s - Error in processing EVPN type-5 NLRI size %d",
                                        peer->bgp->vrf_id, peer->host, psize);
                                return -1;
@@ -4895,6 +4931,23 @@ void bgp_evpn_derive_auto_rd(struct bgp *bgp, struct bgpevpn *vpn)
        UNSET_FLAG(vpn->flags, VNI_FLAG_RD_CFGD);
 }
 
+/*
+ * Lookup L3-VNI
+ */
+bool bgp_evpn_lookup_l3vni_l2vni_table(vni_t vni)
+{
+       struct list *inst = bm->bgp;
+       struct listnode *node;
+       struct bgp *bgp_vrf;
+
+       for (ALL_LIST_ELEMENTS_RO(inst, node, bgp_vrf)) {
+               if (bgp_vrf->l3vni == vni)
+                       return true;
+       }
+
+       return false;
+}
+
 /*
  * Lookup VNI.
  */
@@ -5179,7 +5232,8 @@ int bgp_evpn_local_macip_add(struct bgp *bgp, vni_t vni, struct ethaddr *mac,
                char buf[ETHER_ADDR_STRLEN];
                char buf2[INET6_ADDRSTRLEN];
 
-               zlog_err(
+               flog_err(
+                       BGP_ERR_EVPN_ROUTE_CREATE,
                        "%u:Failed to create Type-2 route, VNI %u %s MAC %s IP %s (flags: 0x%x)",
                        bgp->vrf_id, vpn->vni,
                        CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY)
@@ -5196,13 +5250,12 @@ int bgp_evpn_local_macip_add(struct bgp *bgp, vni_t vni, struct ethaddr *mac,
 static void link_l2vni_hash_to_l3vni(struct hash_backet *backet,
                                     struct bgp *bgp_vrf)
 {
-       struct bgpevpn *vpn = NULL;
+       struct bgpevpn *vpn = (struct bgpevpn *)backet->data;
        struct bgp *bgp_def = NULL;
 
        bgp_def = bgp_get_default();
        assert(bgp_def);
 
-       vpn = (struct bgpevpn *)backet->data;
        if (vpn->tenant_vrf_id == bgp_vrf->vrf_id)
                bgpevpn_link_to_l3vni(vpn);
 }
@@ -5216,12 +5269,13 @@ int bgp_evpn_local_l3vni_add(vni_t l3vni, vrf_id_t vrf_id, struct ethaddr *rmac,
        struct bgpevpn *vpn = NULL;
        as_t as = 0;
 
-       /* get the default instamce - required to get the AS number for VRF
+       /* get the default instance - required to get the AS number for VRF
         * auto-creatio
         */
        bgp_def = bgp_get_default();
        if (!bgp_def) {
-               zlog_err(
+               flog_err(
+                       BGP_ERR_NO_DFLT,
                        "Cannot process L3VNI  %u ADD - default BGP instance not yet created",
                        l3vni);
                return -1;
@@ -5238,13 +5292,16 @@ int bgp_evpn_local_l3vni_add(vni_t l3vni, vrf_id_t vrf_id, struct ethaddr *rmac,
                              BGP_INSTANCE_TYPE_VRF);
                switch (ret) {
                case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
-                       zlog_err("'bgp multiple-instance' not present\n");
+                       flog_err(BGP_ERR_MULTI_INSTANCE,
+                                 "'bgp multiple-instance' not present\n");
                        return -1;
                case BGP_ERR_AS_MISMATCH:
-                       zlog_err("BGP is already running; AS is %u\n", as);
+                       flog_err(BGP_ERR_EVPN_AS_MISMATCH,
+                                 "BGP is already running; AS is %u\n", as);
                        return -1;
                case BGP_ERR_INSTANCE_MISMATCH:
-                       zlog_err("BGP instance name and AS number mismatch\n");
+                       flog_err(BGP_ERR_EVPN_INSTANCE_MISMATCH,
+                                 "BGP instance name and AS number mismatch\n");
                        return -1;
                }
 
@@ -5305,7 +5362,8 @@ int bgp_evpn_local_l3vni_del(vni_t l3vni, vrf_id_t vrf_id)
 
        bgp_vrf = bgp_lookup_by_vrf_id(vrf_id);
        if (!bgp_vrf) {
-               zlog_err(
+               flog_err(
+                       BGP_ERR_NO_DFLT,
                        "Cannot process L3VNI %u Del - Could not find BGP instance",
                        l3vni);
                return -1;
@@ -5313,17 +5371,19 @@ int bgp_evpn_local_l3vni_del(vni_t l3vni, vrf_id_t vrf_id)
 
        bgp_def = bgp_get_default();
        if (!bgp_def) {
-               zlog_err(
+               flog_err(
+                       BGP_ERR_NO_DFLT,
                        "Cannot process L3VNI %u Del - Could not find default BGP instance",
                        l3vni);
                return -1;
        }
 
-       /* unimport remote routes from VRF, if it is AUTO vrf bgp_delete will
-        * take care of uninstalling the routes from zebra
+       /* Remove remote routes from BGT VRF even if BGP_VRF_AUTO is configured,
+        * bgp_delete would not remove/decrement bgp_info of the ip_prefix
+        * routes. This will uninstalling the routes from zebra and decremnt the
+        * bgp info count.
         */
-       if (!CHECK_FLAG(bgp_vrf->vrf_flags, BGP_VRF_AUTO))
-               uninstall_routes_for_vrf(bgp_vrf);
+       uninstall_routes_for_vrf(bgp_vrf);
 
        /* delete/withdraw all type-5 routes */
        delete_withdraw_vrf_routes(bgp_vrf);
@@ -5442,7 +5502,8 @@ int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni,
        if (!vpn) {
                vpn = bgp_evpn_new(bgp, vni, originator_ip, tenant_vrf_id);
                if (!vpn) {
-                       zlog_err(
+                       flog_err(
+                               BGP_ERR_VNI,
                                "%u: Failed to allocate VNI entry for VNI %u - at Add",
                                bgp->vrf_id, vni);
                        return -1;
@@ -5465,8 +5526,9 @@ int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni,
        /* Create EVPN type-3 route and schedule for processing. */
        build_evpn_type3_prefix(&p, vpn->originator_ip);
        if (update_evpn_route(bgp, vpn, &p, 0)) {
-               zlog_err("%u: Type3 route creation failure for VNI %u",
-                        bgp->vrf_id, vni);
+               flog_err(BGP_ERR_EVPN_ROUTE_CREATE,
+                         "%u: Type3 route creation failure for VNI %u",
+                         bgp->vrf_id, vni);
                return -1;
        }
 
@@ -5494,7 +5556,8 @@ int bgp_evpn_local_es_del(struct bgp *bgp,
        struct evpnes *es = NULL;
 
        if (!bgp->esihash) {
-               zlog_err("%u: ESI hash not yet created", bgp->vrf_id);
+               flog_err(BGP_ERR_ES_CREATE, "%u: ESI hash not yet created",
+                         bgp->vrf_id);
                return -1;
        }
 
@@ -5530,7 +5593,8 @@ int bgp_evpn_local_es_add(struct bgp *bgp,
        struct prefix_evpn p;
 
        if (!bgp->esihash) {
-               zlog_err("%u: ESI hash not yet created", bgp->vrf_id);
+               flog_err(BGP_ERR_ES_CREATE, "%u: ESI hash not yet created",
+                         bgp->vrf_id);
                return -1;
        }
 
@@ -5539,7 +5603,8 @@ int bgp_evpn_local_es_add(struct bgp *bgp,
        if (!es) {
                es = bgp_evpn_es_new(bgp, esi, originator_ip);
                if (!es) {
-                       zlog_err(
+                       flog_err(
+                               BGP_ERR_ES_CREATE,
                                "%u: Failed to allocate ES entry for ESI %s - at Local ES Add",
                                bgp->vrf_id, esi_to_str(esi, buf, sizeof(buf)));
                        return -1;
@@ -5550,8 +5615,9 @@ int bgp_evpn_local_es_add(struct bgp *bgp,
 
        build_evpn_type4_prefix(&p, esi, originator_ip->ipaddr_v4);
        if (update_evpn_type4_route(bgp, es, &p)) {
-               zlog_err("%u: Type4 route creation failure for ESI %s",
-                        bgp->vrf_id, esi_to_str(esi, buf, sizeof(buf)));
+               flog_err(BGP_ERR_EVPN_ROUTE_CREATE,
+                         "%u: Type4 route creation failure for ESI %s",
+                         bgp->vrf_id, esi_to_str(esi, buf, sizeof(buf)));
                return -1;
        }