]> 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 25b458a8e5e56c83c4faaf3a9c22b1e3017882a4..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"
 #include "bgpd/bgp_flowspec_util.h"
 #include "bgpd/bgp_evpn.h"
 #include "bgpd/bgp_rd.h"
+#include "bgpd/bgp_mplsvpn.h"
 
 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)
 {
@@ -149,6 +150,8 @@ void bgp_unlink_nexthop(struct bgp_path_info *path)
 {
        struct bgp_nexthop_cache *bnc = path->nexthop;
 
+       bgp_mplsvpn_path_nh_label_unlink(path);
+
        if (!bnc)
                return;
 
@@ -324,7 +327,7 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop,
                 * Gather the ifindex for if up/down events to be
                 * tagged into this fun
                 */
-               if (afi == AFI_IP6 &&
+               if (afi == AFI_IP6 && peer->conf_if &&
                    IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)) {
                        ifindex = peer->su.sin6.sin6_scope_id;
                        if (ifindex == 0) {
@@ -544,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,
@@ -756,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)
@@ -811,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)
@@ -846,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);
@@ -857,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);
@@ -1134,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;
@@ -1230,7 +1244,26 @@ void evaluate_paths(struct bgp_nexthop_cache *bnc)
                        SET_FLAG(path->flags, BGP_PATH_IGP_CHANGED);
 
                path_valid = CHECK_FLAG(path->flags, BGP_PATH_VALID);
-               if (path_valid != bnc_is_valid_nexthop) {
+               if (path->type == ZEBRA_ROUTE_BGP &&
+                   path->sub_type == BGP_ROUTE_STATIC &&
+                   !CHECK_FLAG(bgp_path->flags, BGP_FLAG_IMPORT_CHECK))
+                       /* static routes with 'no bgp network import-check' are
+                        * always valid. if nht is called with static routes,
+                        * the vpn exportation needs to be triggered
+                        */
+                       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
                                 * routes, unimport from VRFs if needed.
@@ -1243,6 +1276,12 @@ void evaluate_paths(struct bgp_nexthop_cache *bnc)
                                    bgp_evpn_is_prefix_nht_supported(bgp_dest_get_prefix(dest)))
                                        bgp_evpn_unimport_route(bgp_path,
                                                afi, safi, bgp_dest_get_prefix(dest), path);
+                               if (safi == SAFI_UNICAST &&
+                                   (bgp_path->inst_type !=
+                                    BGP_INSTANCE_TYPE_VIEW))
+                                       vpn_leak_from_vrf_withdraw(
+                                               bgp_get_default(), bgp_path,
+                                               path);
                        } else {
                                /* Path becomes valid, set flag; also for EVPN
                                 * routes, import from VRFs if needed.
@@ -1255,6 +1294,12 @@ void evaluate_paths(struct bgp_nexthop_cache *bnc)
                                    bgp_evpn_is_prefix_nht_supported(bgp_dest_get_prefix(dest)))
                                        bgp_evpn_import_route(bgp_path,
                                                afi, safi, bgp_dest_get_prefix(dest), path);
+                               if (safi == SAFI_UNICAST &&
+                                   (bgp_path->inst_type !=
+                                    BGP_INSTANCE_TYPE_VIEW))
+                                       vpn_leak_from_vrf_update(
+                                               bgp_get_default(), bgp_path,
+                                               path);
                        }
                }