]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_nht.c
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / bgpd / bgp_nht.c
index f3d9bd1a82f429d3e214aef2fb93d88fbc70a286..d7b14298815906f13374302195d5a60791083f8c 100644 (file)
@@ -6,7 +6,7 @@
 #include <zebra.h>
 
 #include "command.h"
-#include "thread.h"
+#include "frrevent.h"
 #include "prefix.h"
 #include "zclient.h"
 #include "stream.h"
@@ -38,7 +38,7 @@ extern struct zclient *zclient;
 static void register_zebra_rnh(struct bgp_nexthop_cache *bnc);
 static void unregister_zebra_rnh(struct bgp_nexthop_cache *bnc);
 static int make_prefix(int afi, struct bgp_path_info *pi, struct prefix *p);
-static void bgp_nht_ifp_initial(struct thread *thread);
+static void bgp_nht_ifp_initial(struct event *thread);
 
 static int bgp_isvalid_nexthop(struct bgp_nexthop_cache *bnc)
 {
@@ -547,7 +547,7 @@ static void bgp_process_nexthop_update(struct bgp_nexthop_cache *bnc,
                char bnc_buf[BNC_FLAG_DUMP_SIZE];
 
                zlog_debug(
-                       "%s(%u): Rcvd NH update %pFX(%u)%u) - metric %d/%d #nhops %d/%d flags %s",
+                       "%s(%u): Rcvd NH update %pFX(%u)(%u) - metric %d/%d #nhops %d/%d flags %s",
                        bnc->bgp->name_pretty, bnc->bgp->vrf_id, &nhr->prefix,
                        bnc->ifindex, bnc->srte_color, nhr->metric, bnc->metric,
                        nhr->nexthop_num, bnc->nexthop_num,
@@ -759,10 +759,10 @@ void bgp_nht_ifp_down(struct interface *ifp)
        bgp_nht_ifp_handle(ifp, false);
 }
 
-static void bgp_nht_ifp_initial(struct thread *thread)
+static void bgp_nht_ifp_initial(struct event *thread)
 {
-       ifindex_t ifindex = THREAD_VAL(thread);
-       struct bgp *bgp = THREAD_ARG(thread);
+       ifindex_t ifindex = EVENT_VAL(thread);
+       struct bgp *bgp = EVENT_ARG(thread);
        struct interface *ifp = if_lookup_by_index(ifindex, bgp->vrf_id);
 
        if (!ifp)
@@ -814,8 +814,8 @@ void bgp_nht_interface_events(struct peer *peer)
                return;
 
        if (bnc->ifindex)
-               thread_add_event(bm->master, bgp_nht_ifp_initial, bnc->bgp,
-                                bnc->ifindex, NULL);
+               event_add_event(bm->master, bgp_nht_ifp_initial, bnc->bgp,
+                               bnc->ifindex, NULL);
 }
 
 void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id)
@@ -849,7 +849,7 @@ void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id)
        if (!bnc_nhc) {
                if (BGP_DEBUG(nht, NHT))
                        zlog_debug(
-                               "parse nexthop update(%pFX(%u)(%s)): bnc info not found for nexthop cache",
+                               "parse nexthop update %pFX(%u)(%s): bnc info not found for nexthop cache",
                                &nhr.prefix, nhr.srte_color, bgp->name_pretty);
        } else
                bgp_process_nexthop_update(bnc_nhc, &nhr, false);
@@ -860,7 +860,7 @@ void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id)
        if (!bnc_import) {
                if (BGP_DEBUG(nht, NHT))
                        zlog_debug(
-                               "parse nexthop update(%pFX(%u)(%s)): bnc info not found for import check",
+                               "parse nexthop update %pFX(%u)(%s): bnc info not found for import check",
                                &nhr.prefix, nhr.srte_color, bgp->name_pretty);
        } else
                bgp_process_nexthop_update(bnc_import, &nhr, true);
@@ -1137,10 +1137,21 @@ void evaluate_paths(struct bgp_nexthop_cache *bnc)
        }
 
        LIST_FOREACH (path, &(bnc->paths), nh_thread) {
-               if (!(path->type == ZEBRA_ROUTE_BGP
-                     && ((path->sub_type == BGP_ROUTE_NORMAL)
-                         || (path->sub_type == BGP_ROUTE_STATIC)
-                         || (path->sub_type == BGP_ROUTE_IMPORTED))))
+               if (path->type == ZEBRA_ROUTE_BGP &&
+                   (path->sub_type == BGP_ROUTE_NORMAL ||
+                    path->sub_type == BGP_ROUTE_STATIC ||
+                    path->sub_type == BGP_ROUTE_IMPORTED))
+                       /* evaluate the path */
+                       ;
+               else if (path->sub_type == BGP_ROUTE_REDISTRIBUTE) {
+                       /* evaluate the path for redistributed routes
+                        * except those from VNC
+                        */
+                       if ((path->type == ZEBRA_ROUTE_VNC) ||
+                           (path->type == ZEBRA_ROUTE_VNC_DIRECT))
+                               continue;
+               } else
+                       /* don't evaluate the path */
                        continue;
 
                dest = path->net;
@@ -1242,6 +1253,16 @@ void evaluate_paths(struct bgp_nexthop_cache *bnc)
                         */
                        vpn_leak_from_vrf_update(bgp_get_default(), bgp_path,
                                                 path);
+               else if (path->sub_type == BGP_ROUTE_REDISTRIBUTE &&
+                        safi == SAFI_UNICAST &&
+                        (bgp_path->inst_type == BGP_INSTANCE_TYPE_VRF ||
+                         bgp_path->inst_type == BGP_INSTANCE_TYPE_DEFAULT))
+                       /* redistribute routes are always valid
+                        * if nht is called with redistribute routes, the vpn
+                        * exportation needs to be triggered
+                        */
+                       vpn_leak_from_vrf_update(bgp_get_default(), bgp_path,
+                                                path);
                else if (path_valid != bnc_is_valid_nexthop) {
                        if (path_valid) {
                                /* No longer valid, clear flag; also for EVPN