]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #3415 from pguibert6WIND/flowspec_support_nh_tracking
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 9 Jan 2019 20:41:16 +0000 (15:41 -0500)
committerGitHub <noreply@github.com>
Wed, 9 Jan 2019 20:41:16 +0000 (15:41 -0500)
Flowspec support nh tracking

bgpd/bgp_flowspec_util.c
bgpd/bgp_flowspec_util.h
bgpd/bgp_nht.c
bgpd/bgp_pbr.c
bgpd/bgp_pbr.h

index c6386dcdb56df55dab52f963dbfe97d9b565b28f..cd5bec6267ff73dd707e31a09725c5659aad6925 100644 (file)
@@ -23,6 +23,7 @@
 #include "prefix.h"
 #include "lib_errors.h"
 
+#include "bgp_route.h"
 #include "bgp_table.h"
 #include "bgp_flowspec_util.h"
 #include "bgp_flowspec_private.h"
@@ -581,3 +582,27 @@ int bgp_flowspec_match_rules_fill(uint8_t *nlri_content, int len,
        }
        return error;
 }
+
+/* return 1 if FS entry invalid or no NH IP */
+int bgp_flowspec_get_first_nh(struct bgp *bgp, struct bgp_path_info *pi,
+                             struct prefix *p)
+{
+       struct bgp_pbr_entry_main api;
+       int i;
+       struct bgp_node *rn = pi->net;
+       struct bgp_pbr_entry_action *api_action;
+
+       memset(&api, 0, sizeof(struct bgp_pbr_entry_main));
+       if (bgp_pbr_build_and_validate_entry(&rn->p, pi, &api) < 0)
+               return 1;
+       for (i = 0; i < api.action_num; i++) {
+               api_action = &api.actions[i];
+               if (api_action->action != ACTION_REDIRECT_IP)
+                       continue;
+               p->family = AF_INET;
+               p->prefixlen = IPV4_MAX_BITLEN;
+               p->u.prefix4 = api_action->u.zr.redirect_ip_v4;
+               return 0;
+       }
+       return 1;
+}
index 9bf05847d3aeb879d5cbb140f0c74329cd42cd93..2ce911da4e8d1b6b260ba611023164a9d529b3b0 100644 (file)
@@ -54,4 +54,8 @@ extern bool bgp_flowspec_contains_prefix(struct prefix *pfs,
                                         struct prefix *input,
                                         int prefix_check);
 
+extern int bgp_flowspec_get_first_nh(struct bgp *bgp,
+                                    struct bgp_path_info *pi,
+                                    struct prefix *nh);
+
 #endif /* _FRR_BGP_FLOWSPEC_UTIL_H */
index b6ef5a55c5377fde6590c93734412a03bef6d939..2b4ad22b9392441d4b8909c01fb751b85acd99db 100644 (file)
@@ -42,6 +42,7 @@
 #include "bgpd/bgp_nht.h"
 #include "bgpd/bgp_fsm.h"
 #include "bgpd/bgp_zebra.h"
+#include "bgpd/bgp_flowspec_util.h"
 
 extern struct zclient *zclient;
 
@@ -533,7 +534,15 @@ static int make_prefix(int afi, struct bgp_path_info *pi, struct prefix *p)
                             && (pi->sub_type == BGP_ROUTE_STATIC))
                                    ? 1
                                    : 0;
-
+       struct bgp_node *net = pi->net;
+       struct prefix *p_orig = &net->p;
+
+       if (p_orig->family == AF_FLOWSPEC) {
+               if (!pi->peer)
+                       return -1;
+               return bgp_flowspec_get_first_nh(pi->peer->bgp,
+                                                pi, p);
+       }
        memset(p, 0, sizeof(struct prefix));
        switch (afi) {
        case AFI_IP:
index f0a0e615e625ef2673d11f18a51a77607bc335e7..f0021547015706fb4a79b55bacb514b231dede4e 100644 (file)
@@ -626,7 +626,7 @@ static int bgp_pbr_validate_policy_route(struct bgp_pbr_entry_main *api)
 }
 
 /* return -1 if build or validation failed */
-static int bgp_pbr_build_and_validate_entry(struct prefix *p,
+int bgp_pbr_build_and_validate_entry(struct prefix *p,
                                            struct bgp_path_info *path,
                                            struct bgp_pbr_entry_main *api)
 {
index 84095f9ab9456441acd95cd39915d622e5bd5f6a..45c3c9ea13750f8b61a9a85415242a4a49f7c876 100644 (file)
@@ -290,4 +290,7 @@ extern void bgp_pbr_reset(struct bgp *bgp, afi_t afi);
 extern struct bgp_pbr_interface *bgp_pbr_interface_lookup(const char *name,
                                   struct bgp_pbr_interface_head *head);
 
+extern int bgp_pbr_build_and_validate_entry(struct prefix *p,
+                                           struct bgp_path_info *path,
+                                           struct bgp_pbr_entry_main *api);
 #endif /* __BGP_PBR_H__ */