]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: add ability to supply separate match/set objects to routemaps
authorIgor Ryzhov <iryzhov@nfware.com>
Wed, 8 Sep 2021 17:46:21 +0000 (20:46 +0300)
committermergify-bot <noreply@mergify.io>
Thu, 16 Sep 2021 10:51:57 +0000 (10:51 +0000)
Sometimes it's needed to match by fields of one object but set fields of
another object. The following commit is an example.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
(cherry picked from commit c21258471764b99e7d1a5242bb17918bd7380740)

lib/routemap.c
lib/routemap.h

index 34166c180d90d9c70bf79b697cc6cb2572ea785e..5b0bf7257c9c35de912f1e1302ff008dc0a57812 100644 (file)
@@ -2382,8 +2382,9 @@ void route_map_notify_pentry_dependencies(const char *affected_name,
 
    We need to make sure our route-map processing matches the above
 */
-route_map_result_t route_map_apply(struct route_map *map,
-                                  const struct prefix *prefix, void *object)
+route_map_result_t route_map_apply_ext(struct route_map *map,
+                                      const struct prefix *prefix,
+                                      void *match_object, void *set_object)
 {
        static int recursion = 0;
        enum route_map_cmd_result_t match_ret = RMAP_NOMATCH;
@@ -2410,7 +2411,7 @@ route_map_result_t route_map_apply(struct route_map *map,
 
        if ((!map->optimization_disabled)
            && (map->ipv4_prefix_table || map->ipv6_prefix_table)) {
-               index = route_map_get_index(map, prefix, object,
+               index = route_map_get_index(map, prefix, match_object,
                                            (uint8_t *)&match_ret);
                if (index) {
                        index->applied++;
@@ -2445,7 +2446,7 @@ route_map_result_t route_map_apply(struct route_map *map,
                        index->applied++;
                        /* Apply this index. */
                        match_ret = route_map_apply_match(&index->match_list,
-                                                         prefix, object);
+                                                         prefix, match_object);
                        if (rmap_debug) {
                                zlog_debug(
                                        "Route-map: %s, sequence: %d, prefix: %pFX, result: %s",
@@ -2504,7 +2505,7 @@ route_map_result_t route_map_apply(struct route_map *map,
                                         * return code.
                                         */
                                        (void)(*set->cmd->func_apply)(
-                                               set->value, prefix, object);
+                                               set->value, prefix, set_object);
 
                                /* Call another route-map if available */
                                if (index->nextrm) {
@@ -2516,8 +2517,10 @@ route_map_result_t route_map_apply(struct route_map *map,
                                                       jump to it */
                                        {
                                                recursion++;
-                                               ret = route_map_apply(
-                                                       nextrm, prefix, object);
+                                               ret = route_map_apply_ext(
+                                                       nextrm, prefix,
+                                                       match_object,
+                                                       set_object);
                                                recursion--;
                                        }
 
index 97a62c8ace657cc448c76f132f0ba3c943e71756..fa7e60d1ace318346026b2cb531a763471653a10 100644 (file)
@@ -425,9 +425,12 @@ extern struct route_map *route_map_lookup_by_name(const char *name);
 struct route_map *route_map_lookup_warn_noexist(struct vty *vty, const char *name);
 
 /* Apply route map to the object. */
-extern route_map_result_t route_map_apply(struct route_map *map,
-                                         const struct prefix *prefix,
-                                         void *object);
+extern route_map_result_t route_map_apply_ext(struct route_map *map,
+                                             const struct prefix *prefix,
+                                             void *match_object,
+                                             void *set_object);
+#define route_map_apply(map, prefix, object)                                   \
+       route_map_apply_ext(map, prefix, object, object)
 
 extern void route_map_add_hook(void (*func)(const char *));
 extern void route_map_delete_hook(void (*func)(const char *));