]> 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)
committerIgor Ryzhov <iryzhov@nfware.com>
Wed, 8 Sep 2021 20:37:50 +0000 (23:37 +0300)
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>
lib/routemap.c
lib/routemap.h

index 594dcf97cb8158f21c49d08f54c6cd7dbd7239c7..5c60b7d1c6d42637bf9cd37fdb25d3b742935f40 100644 (file)
@@ -2488,8 +2488,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;
@@ -2516,7 +2517,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++;
@@ -2551,7 +2552,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",
@@ -2610,7 +2611,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) {
@@ -2622,8 +2623,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 b356dbf52e0755dbd56dec268398f00a55c571ab..2c8eb24537083c337d5b3313828a127a0509dc98 100644 (file)
@@ -443,9 +443,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 *));