]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_routemap.c
Merge pull request #5549 from donaldsharp/automated
[mirror_frr.git] / ospfd / ospf_routemap.c
index d725837fec5f46b197a309725507c70720b8f456..c89fd3597f284a0af020b2c1c03e9be111bb2d69 100644 (file)
@@ -126,7 +126,7 @@ static void ospf_route_map_event(const char *name)
 
 /* `match ip netxthop ' */
 /* Match function return 1 if match is success else return zero. */
-static enum route_map_match_result_t
+static enum route_map_cmd_result_t
 route_match_ip_nexthop(void *rule, const struct prefix *prefix,
                       route_map_object_t type, void *object)
 {
@@ -164,13 +164,16 @@ static void route_match_ip_nexthop_free(void *rule)
 }
 
 /* Route map commands for metric matching. */
-struct route_map_rule_cmd route_match_ip_nexthop_cmd = {
-       "ip next-hop", route_match_ip_nexthop, route_match_ip_nexthop_compile,
-       route_match_ip_nexthop_free};
+static const struct route_map_rule_cmd route_match_ip_nexthop_cmd = {
+       "ip next-hop",
+       route_match_ip_nexthop,
+       route_match_ip_nexthop_compile,
+       route_match_ip_nexthop_free
+};
 
 /* `match ip next-hop prefix-list PREFIX_LIST' */
 
-static enum route_map_match_result_t
+static enum route_map_cmd_result_t
 route_match_ip_next_hop_prefix_list(void *rule, const struct prefix *prefix,
                                    route_map_object_t type, void *object)
 {
@@ -204,15 +207,55 @@ static void route_match_ip_next_hop_prefix_list_free(void *rule)
        XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
 }
 
-struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd = {
-       "ip next-hop prefix-list", route_match_ip_next_hop_prefix_list,
+static const struct route_map_rule_cmd
+               route_match_ip_next_hop_prefix_list_cmd = {
+       "ip next-hop prefix-list",
+       route_match_ip_next_hop_prefix_list,
        route_match_ip_next_hop_prefix_list_compile,
-       route_match_ip_next_hop_prefix_list_free};
+       route_match_ip_next_hop_prefix_list_free
+};
+
+/* `match ip next-hop type <blackhole>' */
+
+static enum route_map_cmd_result_t
+route_match_ip_next_hop_type(void *rule, const struct prefix *prefix,
+                            route_map_object_t type, void *object)
+{
+       struct external_info *ei = object;
+
+       if (type == RMAP_OSPF && prefix->family == AF_INET) {
+               ei = (struct external_info *)object;
+               if (!ei)
+                       return RMAP_NOMATCH;
+
+               if (ei->nexthop.s_addr == INADDR_ANY && !ei->ifindex)
+                       return RMAP_MATCH;
+       }
+       return RMAP_NOMATCH;
+}
+
+static void *route_match_ip_next_hop_type_compile(const char *arg)
+{
+       return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
+}
+
+static void route_match_ip_next_hop_type_free(void *rule)
+{
+       XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
+}
+
+static const struct route_map_rule_cmd
+               route_match_ip_next_hop_type_cmd = {
+       "ip next-hop type",
+       route_match_ip_next_hop_type,
+       route_match_ip_next_hop_type_compile,
+       route_match_ip_next_hop_type_free
+};
 
 /* `match ip address IP_ACCESS_LIST' */
 /* Match function should return 1 if match is success else return
    zero. */
-static enum route_map_match_result_t
+static enum route_map_cmd_result_t
 route_match_ip_address(void *rule, const struct prefix *prefix,
                       route_map_object_t type, void *object)
 {
@@ -245,12 +288,15 @@ static void route_match_ip_address_free(void *rule)
 }
 
 /* Route map commands for ip address matching. */
-struct route_map_rule_cmd route_match_ip_address_cmd = {
-       "ip address", route_match_ip_address, route_match_ip_address_compile,
-       route_match_ip_address_free};
+static const struct route_map_rule_cmd route_match_ip_address_cmd = {
+       "ip address",
+       route_match_ip_address,
+       route_match_ip_address_compile,
+       route_match_ip_address_free
+};
 
 /* `match ip address prefix-list PREFIX_LIST' */
-static enum route_map_match_result_t
+static enum route_map_cmd_result_t
 route_match_ip_address_prefix_list(void *rule, const struct prefix *prefix,
                                   route_map_object_t type, void *object)
 {
@@ -278,15 +324,18 @@ static void route_match_ip_address_prefix_list_free(void *rule)
        XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
 }
 
-struct route_map_rule_cmd route_match_ip_address_prefix_list_cmd = {
-       "ip address prefix-list", route_match_ip_address_prefix_list,
+static const struct route_map_rule_cmd
+               route_match_ip_address_prefix_list_cmd = {
+       "ip address prefix-list",
+       route_match_ip_address_prefix_list,
        route_match_ip_address_prefix_list_compile,
-       route_match_ip_address_prefix_list_free};
+       route_match_ip_address_prefix_list_free
+};
 
 /* `match interface IFNAME' */
 /* Match function should return 1 if match is success else return
    zero. */
-static enum route_map_match_result_t
+static enum route_map_cmd_result_t
 route_match_interface(void *rule, const struct prefix *prefix,
                      route_map_object_t type, void *object)
 {
@@ -319,12 +368,15 @@ static void route_match_interface_free(void *rule)
 }
 
 /* Route map commands for ip address matching. */
-struct route_map_rule_cmd route_match_interface_cmd = {
-       "interface", route_match_interface, route_match_interface_compile,
-       route_match_interface_free};
+static const struct route_map_rule_cmd route_match_interface_cmd = {
+       "interface",
+       route_match_interface,
+       route_match_interface_compile,
+       route_match_interface_free
+};
 
 /* Match function return 1 if match is success else return zero. */
-static enum route_map_match_result_t
+static enum route_map_cmd_result_t
 route_match_tag(void *rule, const struct prefix *prefix,
                route_map_object_t type, void *object)
 {
@@ -342,8 +394,10 @@ route_match_tag(void *rule, const struct prefix *prefix,
 }
 
 /* Route map commands for tag matching. */
-static struct route_map_rule_cmd route_match_tag_cmd = {
-       "tag", route_match_tag, route_map_rule_tag_compile,
+static const struct route_map_rule_cmd route_match_tag_cmd = {
+       "tag",
+       route_match_tag,
+       route_map_rule_tag_compile,
        route_map_rule_tag_free,
 };
 
@@ -355,7 +409,7 @@ struct ospf_metric {
 
 /* `set metric METRIC' */
 /* Set metric to attribute. */
-static enum route_map_match_result_t
+static enum route_map_cmd_result_t
 route_set_metric(void *rule, const struct prefix *prefix,
                 route_map_object_t type, void *object)
 {
@@ -428,14 +482,16 @@ static void route_set_metric_free(void *rule)
 }
 
 /* Set metric rule structure. */
-struct route_map_rule_cmd route_set_metric_cmd = {
-       "metric", route_set_metric, route_set_metric_compile,
+static const struct route_map_rule_cmd route_set_metric_cmd = {
+       "metric",
+       route_set_metric,
+       route_set_metric_compile,
        route_set_metric_free,
 };
 
 /* `set metric-type TYPE' */
 /* Set metric-type to attribute. */
-static enum route_map_match_result_t
+static enum route_map_cmd_result_t
 route_set_metric_type(void *rule, const struct prefix *prefix,
                      route_map_object_t type, void *object)
 {
@@ -479,12 +535,14 @@ static void route_set_metric_type_free(void *rule)
 }
 
 /* Set metric rule structure. */
-struct route_map_rule_cmd route_set_metric_type_cmd = {
-       "metric-type", route_set_metric_type, route_set_metric_type_compile,
+static const struct route_map_rule_cmd route_set_metric_type_cmd = {
+       "metric-type",
+       route_set_metric_type,
+       route_set_metric_type_compile,
        route_set_metric_type_free,
 };
 
-static enum route_map_match_result_t
+static enum route_map_cmd_result_t
 route_set_tag(void *rule, const struct prefix *prefix, route_map_object_t type,
              void *object)
 {
@@ -503,8 +561,10 @@ route_set_tag(void *rule, const struct prefix *prefix, route_map_object_t type,
 }
 
 /* Route map commands for tag set. */
-static struct route_map_rule_cmd route_set_tag_cmd = {
-       "tag", route_set_tag, route_map_rule_tag_compile,
+static const struct route_map_rule_cmd route_set_tag_cmd = {
+       "tag",
+       route_set_tag,
+       route_map_rule_tag_compile,
        route_map_rule_tag_free,
 };
 
@@ -562,6 +622,9 @@ void ospf_route_map_init(void)
        route_map_match_ip_next_hop_prefix_list_hook(generic_match_add);
        route_map_no_match_ip_next_hop_prefix_list_hook(generic_match_delete);
 
+       route_map_match_ip_next_hop_type_hook(generic_match_add);
+       route_map_no_match_ip_next_hop_type_hook(generic_match_delete);
+
        route_map_match_tag_hook(generic_match_add);
        route_map_no_match_tag_hook(generic_match_delete);
 
@@ -575,6 +638,7 @@ void ospf_route_map_init(void)
        route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd);
        route_map_install_match(&route_match_ip_address_cmd);
        route_map_install_match(&route_match_ip_address_prefix_list_cmd);
+       route_map_install_match(&route_match_ip_next_hop_type_cmd);
        route_map_install_match(&route_match_interface_cmd);
        route_map_install_match(&route_match_tag_cmd);