]> git.puffer.fish Git - matthieu/frr.git/commitdiff
rmap: Add hooks into zebra,ospf,rip for `match ip next-hop type blackhole`
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Fri, 21 Jun 2019 15:51:33 +0000 (18:51 +0300)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Sat, 22 Jun 2019 11:26:21 +0000 (14:26 +0300)
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
ospfd/ospf_routemap.c
ripd/rip_routemap.c
zebra/zebra_routemap.c

index 54009639fc37ea03af10f486c15fbdb3b580182b..e30e099d92f7441442757207492aad1ae35cc90a 100644 (file)
@@ -202,6 +202,40 @@ struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd = {
        route_match_ip_next_hop_prefix_list_compile,
        route_match_ip_next_hop_prefix_list_free};
 
+/* `match ip next-hop type <blackhole>' */
+
+static route_map_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_DENYMATCH;
+
+               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 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. */
@@ -557,6 +591,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);
 
@@ -570,6 +607,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);
 
index b34f944c9e62ab23069c8cdcca84293789c9dd2f..ceeb363dc53d8323e264a6e9c207f009b21787c4 100644 (file)
@@ -231,6 +231,40 @@ static struct route_map_rule_cmd route_match_ip_next_hop_prefix_list_cmd = {
        route_match_ip_next_hop_prefix_list_compile,
        route_match_ip_next_hop_prefix_list_free};
 
+/* `match ip next-hop type <blackhole>' */
+
+static route_map_result_t
+route_match_ip_next_hop_type(void *rule, const struct prefix *prefix,
+                            route_map_object_t type, void *object)
+{
+       struct rip_info *rinfo;
+
+       if (type == RMAP_RIP && prefix->family == AF_INET) {
+               rinfo = (struct rip_info *)object;
+               if (!rinfo)
+                       return RMAP_DENYMATCH;
+
+               if (rinfo->nh.type == NEXTHOP_TYPE_BLACKHOLE)
+                       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 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
@@ -537,6 +571,9 @@ void rip_route_map_init()
        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_metric_hook(generic_match_add);
        route_map_no_match_metric_hook(generic_match_delete);
 
@@ -556,6 +593,7 @@ void rip_route_map_init()
        route_map_install_match(&route_match_interface_cmd);
        route_map_install_match(&route_match_ip_next_hop_cmd);
        route_map_install_match(&route_match_ip_next_hop_prefix_list_cmd);
+       route_map_install_match(&route_match_ip_next_hop_type_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_tag_cmd);
index c9918a7887e3b66abc1cb9520cd6fbcfa3c34eb5..197427dc68188b8b561a2444c36b5264299254b2 100644 (file)
@@ -1231,6 +1231,40 @@ static struct route_map_rule_cmd route_match_ipv6_address_prefix_list_cmd = {
        route_match_address_prefix_list_compile,
        route_match_address_prefix_list_free};
 
+/* `match ipv6 next-hop type <TYPE>' */
+
+static route_map_result_t
+route_match_ipv6_next_hop_type(void *rule, const struct prefix *prefix,
+                              route_map_object_t type, void *object)
+{
+       struct nh_rmap_obj *nh_data;
+
+       if (type == RMAP_ZEBRA && prefix->family == AF_INET6) {
+               nh_data = (struct nh_rmap_obj *)object;
+               if (!nh_data)
+                       return RMAP_DENYMATCH;
+
+               if (nh_data->nexthop->type == NEXTHOP_TYPE_BLACKHOLE)
+                       return RMAP_MATCH;
+       }
+       return RMAP_NOMATCH;
+}
+
+static void *route_match_ipv6_next_hop_type_compile(const char *arg)
+{
+       return XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
+}
+
+static void route_match_ipv6_next_hop_type_free(void *rule)
+{
+       XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
+}
+
+struct route_map_rule_cmd route_match_ipv6_next_hop_type_cmd = {
+       "ipv6 next-hop type", route_match_ipv6_next_hop_type,
+       route_match_ipv6_next_hop_type_compile,
+       route_match_ipv6_next_hop_type_free};
+
 /* `match ip address prefix-len PREFIXLEN' */
 
 static route_map_result_t
@@ -1322,6 +1356,40 @@ static struct route_map_rule_cmd route_match_ip_nexthop_prefix_len_cmd = {
        route_match_address_prefix_len_free     /* reuse */
 };
 
+/* `match ip next-hop type <blackhole>' */
+
+static route_map_result_t
+route_match_ip_next_hop_type(void *rule, const struct prefix *prefix,
+                            route_map_object_t type, void *object)
+{
+       struct nh_rmap_obj *nh_data;
+
+       if (type == RMAP_ZEBRA && prefix->family == AF_INET) {
+               nh_data = (struct nh_rmap_obj *)object;
+               if (!nh_data)
+                       return RMAP_DENYMATCH;
+
+               if (nh_data->nexthop->type == NEXTHOP_TYPE_BLACKHOLE)
+                       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 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 source-protocol PROTOCOL' */
 
 static route_map_result_t route_match_source_protocol(void *rule,
@@ -1877,6 +1945,9 @@ void zebra_route_map_init()
        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);
 
@@ -1886,6 +1957,9 @@ void zebra_route_map_init()
        route_map_match_ipv6_address_prefix_list_hook(generic_match_add);
        route_map_no_match_ipv6_address_prefix_list_hook(generic_match_delete);
 
+       route_map_match_ipv6_next_hop_type_hook(generic_match_add);
+       route_map_no_match_ipv6_next_hop_type_hook(generic_match_delete);
+
        route_map_install_match(&route_match_tag_cmd);
        route_map_install_match(&route_match_interface_cmd);
        route_map_install_match(&route_match_ip_next_hop_cmd);
@@ -1897,6 +1971,8 @@ void zebra_route_map_init()
        route_map_install_match(&route_match_ip_address_prefix_len_cmd);
        route_map_install_match(&route_match_ipv6_address_prefix_len_cmd);
        route_map_install_match(&route_match_ip_nexthop_prefix_len_cmd);
+       route_map_install_match(&route_match_ip_next_hop_type_cmd);
+       route_map_install_match(&route_match_ipv6_next_hop_type_cmd);
        route_map_install_match(&route_match_source_protocol_cmd);
        route_map_install_match(&route_match_source_instance_cmd);