]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zebra_routemap.c
libs, daemons: use const in route-map apply
[mirror_frr.git] / zebra / zebra_routemap.c
index 10ba88880a8935363f93d59715a9aecc6181371e..0b48e87b1b7a173aca12301bc32f57a9a6e0b40f 100644 (file)
@@ -31,6 +31,7 @@
 #include "plist.h"
 #include "nexthop.h"
 #include "vrf.h"
+#include "frrstr.h"
 
 #include "zebra/zserv.h"
 #include "zebra/redistribute.h"
@@ -136,7 +137,8 @@ static int zebra_route_match_delete(struct vty *vty, const char *command,
 /* 'match tag TAG'
  * Match function return 1 if match is success else return 0
  */
-static route_map_result_t route_match_tag(void *rule, struct prefix *prefix,
+static route_map_result_t route_match_tag(void *rule,
+                                         const struct prefix *prefix,
                                          route_map_object_t type, void *object)
 {
        route_tag_t *tag;
@@ -162,7 +164,7 @@ static struct route_map_rule_cmd route_match_tag_cmd = {
 /* `match interface IFNAME' */
 /* Match function return 1 if match is success else return zero. */
 static route_map_result_t route_match_interface(void *rule,
-                                               struct prefix *prefix,
+                                               const struct prefix *prefix,
                                                route_map_object_t type,
                                                void *object)
 {
@@ -878,7 +880,7 @@ DEFUN (show_ipv6_protocol_nht,
 
 /* Match function return 1 if match is success else return zero. */
 static route_map_result_t route_match_ip_next_hop(void *rule,
-                                                 struct prefix *prefix,
+                                                 const struct prefix *prefix,
                                                  route_map_object_t type,
                                                  void *object)
 {
@@ -936,7 +938,7 @@ static struct route_map_rule_cmd route_match_ip_next_hop_cmd = {
 /* `match ip next-hop prefix-list PREFIX_LIST' */
 
 static route_map_result_t
-route_match_ip_next_hop_prefix_list(void *rule, struct prefix *prefix,
+route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix,
                                    route_map_object_t type, void *object)
 {
        struct prefix_list *plist;
@@ -992,7 +994,7 @@ static struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd = {
 /* Match function should return 1 if match is success else return
    zero. */
 static route_map_result_t route_match_ip_address(void *rule,
-                                                struct prefix *prefix,
+                                                const struct prefix *prefix,
                                                 route_map_object_t type,
                                                 void *object)
 {
@@ -1031,7 +1033,7 @@ static struct route_map_rule_cmd route_match_ip_address_cmd = {
 /* `match ip address prefix-list PREFIX_LIST' */
 
 static route_map_result_t
-route_match_ip_address_prefix_list(void *rule, struct prefix *prefix,
+route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix,
                                   route_map_object_t type, void *object)
 {
        struct prefix_list *plist;
@@ -1067,7 +1069,7 @@ static struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd = {
 /* `match ip address prefix-len PREFIXLEN' */
 
 static route_map_result_t
-route_match_address_prefix_len(void *rule, struct prefix *prefix,
+route_match_address_prefix_len(void *rule, const struct prefix *prefix,
                               route_map_object_t type, void *object)
 {
        uint32_t *prefixlen = (uint32_t *)rule;
@@ -1121,7 +1123,7 @@ static struct route_map_rule_cmd route_match_ipv6_address_prefix_len_cmd = {
 /* `match ip nexthop prefix-len PREFIXLEN' */
 
 static route_map_result_t
-route_match_ip_nexthop_prefix_len(void *rule, struct prefix *prefix,
+route_match_ip_nexthop_prefix_len(void *rule, const struct prefix *prefix,
                                  route_map_object_t type, void *object)
 {
        uint32_t *prefixlen = (uint32_t *)rule;
@@ -1161,7 +1163,7 @@ static struct route_map_rule_cmd route_match_ip_nexthop_prefix_len_cmd = {
 /* `match source-protocol PROTOCOL' */
 
 static route_map_result_t route_match_source_protocol(void *rule,
-                                                     struct prefix *prefix,
+                                                     const struct prefix *p,
                                                      route_map_object_t type,
                                                      void *object)
 {
@@ -1203,7 +1205,7 @@ static struct route_map_rule_cmd route_match_source_protocol_cmd = {
 
 /* `source-instance` */
 static route_map_result_t route_match_source_instance(void *rule,
-                                                     struct prefix *prefix,
+                                                     const struct prefix *p,
                                                      route_map_object_t type,
                                                      void *object)
 {
@@ -1245,7 +1247,7 @@ static struct route_map_rule_cmd route_match_source_instance_cmd = {
 /* `set src A.B.C.D' */
 
 /* Set src. */
-static route_map_result_t route_set_src(void *rule, struct prefix *prefix,
+static route_map_result_t route_set_src(void *rule, const struct prefix *prefix,
                                        route_map_object_t type, void *object)
 {
        struct nh_rmap_obj *nh_data;
@@ -1282,6 +1284,13 @@ static struct route_map_rule_cmd route_set_src_cmd = {
        "src", route_set_src, route_set_src_compile, route_set_src_free,
 };
 
+static void zebra_route_map_process_update_cb(char *rmap_name)
+{
+       if (IS_ZEBRA_DEBUG_EVENT)
+               zlog_debug("Event handler for route-map: %s",
+                          rmap_name);
+}
+
 static int zebra_route_map_update_timer(struct thread *thread)
 {
        zebra_t_rmap_update = NULL;
@@ -1294,6 +1303,13 @@ static int zebra_route_map_update_timer(struct thread *thread)
                        "%u: Routemap update-timer fired, scheduling RIB processing",
                        VRF_DEFAULT);
 
+       route_map_walk_update_list(zebra_route_map_process_update_cb);
+
+       /*
+        * This code needs to be updated to be:
+        * 1) VRF Aware <sigh>
+        * 2) Route-map aware
+        */
        zebra_import_table_rm_update();
        rib_update(VRF_DEFAULT, RIB_UPDATE_RMAP_CHANGE);
        zebra_evaluate_rnh(0, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL);
@@ -1322,7 +1338,8 @@ void zebra_route_map_write_delay_timer(struct vty *vty)
 }
 
 route_map_result_t zebra_route_map_check(int family, int rib_type,
-                                        uint8_t instance, struct prefix *p,
+                                        uint8_t instance,
+                                        const struct prefix *p,
                                         struct nexthop *nexthop,
                                         vrf_id_t vrf_id, route_tag_t tag)
 {
@@ -1368,7 +1385,8 @@ void zebra_del_import_table_route_map(afi_t afi, uint32_t table)
 
 route_map_result_t
 zebra_import_table_route_map_check(int family, int re_type, uint8_t instance,
-                                  struct prefix *p, struct nexthop *nexthop,
+                                  const struct prefix *p,
+                                  struct nexthop *nexthop,
                                   vrf_id_t vrf_id, route_tag_t tag,
                                   const char *rmap_name)
 {
@@ -1393,7 +1411,7 @@ zebra_import_table_route_map_check(int family, int re_type, uint8_t instance,
 }
 
 route_map_result_t zebra_nht_route_map_check(int family, int client_proto,
-                                            struct prefix *p,
+                                            const struct prefix *p,
                                             struct route_entry *re,
                                             struct nexthop *nexthop)
 {
@@ -1413,11 +1431,10 @@ route_map_result_t zebra_nht_route_map_check(int family, int client_proto,
        if (!rmap && nht_rm[family][ZEBRA_ROUTE_MAX])
                rmap = route_map_lookup_by_name(
                        nht_rm[family][ZEBRA_ROUTE_MAX]);
-       if (rmap) {
+       if (rmap)
                ret = route_map_apply(rmap, p, RMAP_ZEBRA, &nh_obj);
-       }
 
-       return (ret);
+       return ret;
 }
 
 static void zebra_route_map_mark_update(const char *rmap_name)
@@ -1433,20 +1450,26 @@ static void zebra_route_map_mark_update(const char *rmap_name)
 
 static void zebra_route_map_add(const char *rmap_name)
 {
-       zebra_route_map_mark_update(rmap_name);
+       if (route_map_mark_updated(rmap_name) == 0)
+               zebra_route_map_mark_update(rmap_name);
+
        route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_ADDED);
 }
 
 static void zebra_route_map_delete(const char *rmap_name)
 {
-       zebra_route_map_mark_update(rmap_name);
+       if (route_map_mark_updated(rmap_name) == 0)
+               zebra_route_map_mark_update(rmap_name);
+
        route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_DELETED);
 }
 
 static void zebra_route_map_event(route_map_event_t event,
                                  const char *rmap_name)
 {
-       zebra_route_map_mark_update(rmap_name);
+       if (route_map_mark_updated(rmap_name) == 0)
+               zebra_route_map_mark_update(rmap_name);
+
        route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_ADDED);
 }