diff options
author | Donald Sharp <sharpd@nvidia.com> | 2020-11-14 01:35:20 +0100 |
---|---|---|
committer | Donald Sharp <sharpd@nvidia.com> | 2020-11-14 01:35:20 +0100 |
commit | 1782514fb957d86c0e2510f2e76651345c5c9fb1 (patch) | |
tree | d4282946603ca67c78ee17ff03aa7cf890e577bd /zebra/zebra_routemap.c | |
parent | Merge pull request #7474 from eololab/fix-crash-skiplist-debug (diff) | |
download | frr-1782514fb957d86c0e2510f2e76651345c5c9fb1.tar.xz frr-1782514fb957d86c0e2510f2e76651345c5c9fb1.zip |
*: Remove route_map_object_t from the system
The route_map_object_t was being used to track what protocol we were
being called against. But each protocol was only ever calling itself.
So we had a variable that was only ever being passed in from route_map_apply
that had to be carried against and everyone was testing if that variable
was for their own stack.
Clean up this route_map_object_t from the entire system. We should
speed some stuff up. Yes I know not a bunch but this will add up.
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Diffstat (limited to 'zebra/zebra_routemap.c')
-rw-r--r-- | zebra/zebra_routemap.c | 283 |
1 files changed, 121 insertions, 162 deletions
diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 294f2c17f..7b0a1e3d9 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -64,19 +64,17 @@ static void zebra_route_map_set_delay_timer(uint32_t value); * Match function return 1 if match is success else return 0 */ static enum route_map_cmd_result_t -route_match_tag(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_tag(void *rule, const struct prefix *prefix, void *object) { route_tag_t *tag; struct nh_rmap_obj *nh_data; - if (type == RMAP_ZEBRA) { - tag = rule; - nh_data = object; + tag = rule; + nh_data = object; + + if (nh_data->tag == *tag) + return RMAP_MATCH; - if (nh_data->tag == *tag) - return RMAP_MATCH; - } return RMAP_NOMATCH; } @@ -92,25 +90,23 @@ static const struct route_map_rule_cmd route_match_tag_cmd = { /* `match interface IFNAME' */ /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_interface(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_interface(void *rule, const struct prefix *prefix, void *object) { struct nh_rmap_obj *nh_data; char *ifname = rule; ifindex_t ifindex; - if (type == RMAP_ZEBRA) { - if (strcasecmp(ifname, "any") == 0) - return RMAP_MATCH; - nh_data = object; - if (!nh_data || !nh_data->nexthop) - return RMAP_NOMATCH; - ifindex = ifname2ifindex(ifname, nh_data->vrf_id); - if (ifindex == 0) - return RMAP_NOMATCH; - if (nh_data->nexthop->ifindex == ifindex) - return RMAP_MATCH; - } + if (strcasecmp(ifname, "any") == 0) + return RMAP_MATCH; + nh_data = object; + if (!nh_data || !nh_data->nexthop) + return RMAP_NOMATCH; + ifindex = ifname2ifindex(ifname, nh_data->vrf_id); + if (ifindex == 0) + return RMAP_NOMATCH; + if (nh_data->nexthop->ifindex == ifindex) + return RMAP_MATCH; + return RMAP_NOMATCH; } @@ -938,40 +934,35 @@ DEFPY_YANG (show_ipv6_protocol_nht, /* Match function return 1 if match is success else return zero. */ static enum route_map_cmd_result_t -route_match_ip_next_hop(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ip_next_hop(void *rule, const struct prefix *prefix, void *object) { struct access_list *alist; struct nh_rmap_obj *nh_data; struct prefix_ipv4 p; - if (type == RMAP_ZEBRA) { - nh_data = object; - if (!nh_data) - return RMAP_NOMATCH; - - switch (nh_data->nexthop->type) { - case NEXTHOP_TYPE_IFINDEX: - /* Interface routes can't match ip next-hop */ - return RMAP_NOMATCH; - case NEXTHOP_TYPE_IPV4_IFINDEX: - case NEXTHOP_TYPE_IPV4: - p.family = AF_INET; - p.prefix = nh_data->nexthop->gate.ipv4; - p.prefixlen = IPV4_MAX_BITLEN; - break; - default: - return RMAP_NOMATCH; - } - alist = access_list_lookup(AFI_IP, (char *)rule); - if (alist == NULL) - return RMAP_NOMATCH; + nh_data = object; + if (!nh_data) + return RMAP_NOMATCH; - return (access_list_apply(alist, &p) == FILTER_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); + switch (nh_data->nexthop->type) { + case NEXTHOP_TYPE_IFINDEX: + /* Interface routes can't match ip next-hop */ + return RMAP_NOMATCH; + case NEXTHOP_TYPE_IPV4_IFINDEX: + case NEXTHOP_TYPE_IPV4: + p.family = AF_INET; + p.prefix = nh_data->nexthop->gate.ipv4; + p.prefixlen = IPV4_MAX_BITLEN; + break; + default: + return RMAP_NOMATCH; } - return RMAP_NOMATCH; + alist = access_list_lookup(AFI_IP, (char *)rule); + if (alist == NULL) + return RMAP_NOMATCH; + + return (access_list_apply(alist, &p) == FILTER_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } /* Route map `ip next-hop' match statement. `arg' should be @@ -999,39 +990,35 @@ static const struct route_map_rule_cmd route_match_ip_next_hop_cmd = { 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) + void *object) { struct prefix_list *plist; struct nh_rmap_obj *nh_data; struct prefix_ipv4 p; - if (type == RMAP_ZEBRA) { - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data) - return RMAP_NOMATCH; - - switch (nh_data->nexthop->type) { - case NEXTHOP_TYPE_IFINDEX: - /* Interface routes can't match ip next-hop */ - return RMAP_NOMATCH; - case NEXTHOP_TYPE_IPV4_IFINDEX: - case NEXTHOP_TYPE_IPV4: - p.family = AF_INET; - p.prefix = nh_data->nexthop->gate.ipv4; - p.prefixlen = IPV4_MAX_BITLEN; - break; - default: - return RMAP_NOMATCH; - } - plist = prefix_list_lookup(AFI_IP, (char *)rule); - if (plist == NULL) - return RMAP_NOMATCH; + nh_data = (struct nh_rmap_obj *)object; + if (!nh_data) + return RMAP_NOMATCH; - return (prefix_list_apply(plist, &p) == PREFIX_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); + switch (nh_data->nexthop->type) { + case NEXTHOP_TYPE_IFINDEX: + /* Interface routes can't match ip next-hop */ + return RMAP_NOMATCH; + case NEXTHOP_TYPE_IPV4_IFINDEX: + case NEXTHOP_TYPE_IPV4: + p.family = AF_INET; + p.prefix = nh_data->nexthop->gate.ipv4; + p.prefixlen = IPV4_MAX_BITLEN; + break; + default: + return RMAP_NOMATCH; } - return RMAP_NOMATCH; + plist = prefix_list_lookup(AFI_IP, (char *)rule); + if (plist == NULL) + return RMAP_NOMATCH; + + return (prefix_list_apply(plist, &p) == PREFIX_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } static void *route_match_ip_next_hop_prefix_list_compile(const char *arg) @@ -1058,34 +1045,28 @@ static const struct route_map_rule_cmd zero. */ static enum route_map_cmd_result_t route_match_address(afi_t afi, void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct access_list *alist; - if (type == RMAP_ZEBRA) { - alist = access_list_lookup(afi, (char *)rule); - if (alist == NULL) - return RMAP_NOMATCH; + alist = access_list_lookup(afi, (char *)rule); + if (alist == NULL) + return RMAP_NOMATCH; - return (access_list_apply(alist, prefix) == FILTER_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (access_list_apply(alist, prefix) == FILTER_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } static enum route_map_cmd_result_t -route_match_ip_address(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ip_address(void *rule, const struct prefix *prefix, void *object) { - return route_match_address(AFI_IP, rule, prefix, type, object); + return route_match_address(AFI_IP, rule, prefix, object); } static enum route_map_cmd_result_t -route_match_ipv6_address(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) +route_match_ipv6_address(void *rule, const struct prefix *prefix, void *object) { - return route_match_address(AFI_IP6, rule, prefix, type, object); + return route_match_address(AFI_IP6, rule, prefix, object); } /* Route map `ip address' match statement. `arg' should be @@ -1121,28 +1102,23 @@ static const struct route_map_rule_cmd route_match_ipv6_address_cmd = { static enum route_map_cmd_result_t route_match_address_prefix_list(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object, afi_t afi) + void *object, afi_t afi) { struct prefix_list *plist; - if (type == RMAP_ZEBRA) { - plist = prefix_list_lookup(afi, (char *)rule); - if (plist == NULL) - return RMAP_NOMATCH; + plist = prefix_list_lookup(afi, (char *)rule); + if (plist == NULL) + return RMAP_NOMATCH; - return (prefix_list_apply(plist, prefix) == PREFIX_DENY - ? RMAP_NOMATCH - : RMAP_MATCH); - } - return RMAP_NOMATCH; + return (prefix_list_apply(plist, prefix) == PREFIX_DENY ? RMAP_NOMATCH + : RMAP_MATCH); } 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) + void *object) { - return (route_match_address_prefix_list(rule, prefix, type, object, - AFI_IP)); + return (route_match_address_prefix_list(rule, prefix, object, AFI_IP)); } static void *route_match_address_prefix_list_compile(const char *arg) @@ -1165,10 +1141,9 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_ipv6_address_prefix_list(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { - return (route_match_address_prefix_list(rule, prefix, type, object, - AFI_IP6)); + return (route_match_address_prefix_list(rule, prefix, object, AFI_IP6)); } static const struct route_map_rule_cmd @@ -1183,11 +1158,11 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_ipv6_next_hop_type(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { struct nh_rmap_obj *nh_data; - if (type == RMAP_ZEBRA && prefix->family == AF_INET6) { + if (prefix->family == AF_INET6) { nh_data = (struct nh_rmap_obj *)object; if (!nh_data) return RMAP_NOMATCH; @@ -1195,6 +1170,7 @@ route_match_ipv6_next_hop_type(void *rule, const struct prefix *prefix, if (nh_data->nexthop->type == NEXTHOP_TYPE_BLACKHOLE) return RMAP_MATCH; } + return RMAP_NOMATCH; } @@ -1220,15 +1196,11 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_address_prefix_len(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { uint32_t *prefixlen = (uint32_t *)rule; - if (type == RMAP_ZEBRA) { - return ((prefix->prefixlen == *prefixlen) ? RMAP_MATCH - : RMAP_NOMATCH); - } - return RMAP_NOMATCH; + return ((prefix->prefixlen == *prefixlen) ? RMAP_MATCH : RMAP_NOMATCH); } static void *route_match_address_prefix_len_compile(const char *arg) @@ -1277,34 +1249,30 @@ static const struct route_map_rule_cmd static enum route_map_cmd_result_t route_match_ip_nexthop_prefix_len(void *rule, const struct prefix *prefix, - route_map_object_t type, void *object) + void *object) { uint32_t *prefixlen = (uint32_t *)rule; struct nh_rmap_obj *nh_data; struct prefix_ipv4 p; - if (type == RMAP_ZEBRA) { - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data || !nh_data->nexthop) - return RMAP_NOMATCH; + nh_data = (struct nh_rmap_obj *)object; + if (!nh_data || !nh_data->nexthop) + return RMAP_NOMATCH; - switch (nh_data->nexthop->type) { - case NEXTHOP_TYPE_IFINDEX: - /* Interface routes can't match ip next-hop */ - return RMAP_NOMATCH; - case NEXTHOP_TYPE_IPV4_IFINDEX: - case NEXTHOP_TYPE_IPV4: - p.family = AF_INET; - p.prefix = nh_data->nexthop->gate.ipv4; - p.prefixlen = IPV4_MAX_BITLEN; - break; - default: - return RMAP_NOMATCH; - } - return ((p.prefixlen == *prefixlen) ? RMAP_MATCH - : RMAP_NOMATCH); + switch (nh_data->nexthop->type) { + case NEXTHOP_TYPE_IFINDEX: + /* Interface routes can't match ip next-hop */ + return RMAP_NOMATCH; + case NEXTHOP_TYPE_IPV4_IFINDEX: + case NEXTHOP_TYPE_IPV4: + p.family = AF_INET; + p.prefix = nh_data->nexthop->gate.ipv4; + p.prefixlen = IPV4_MAX_BITLEN; + break; + default: + return RMAP_NOMATCH; } - return RMAP_NOMATCH; + return ((p.prefixlen == *prefixlen) ? RMAP_MATCH : RMAP_NOMATCH); } static const struct route_map_rule_cmd @@ -1319,11 +1287,11 @@ static const struct route_map_rule_cmd 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) + void *object) { struct nh_rmap_obj *nh_data; - if (type == RMAP_ZEBRA && prefix->family == AF_INET) { + if (prefix->family == AF_INET) { nh_data = (struct nh_rmap_obj *)object; if (!nh_data) return RMAP_NOMATCH; @@ -1331,6 +1299,7 @@ route_match_ip_next_hop_type(void *rule, const struct prefix *prefix, if (nh_data->nexthop->type == NEXTHOP_TYPE_BLACKHOLE) return RMAP_MATCH; } + return RMAP_NOMATCH; } @@ -1355,21 +1324,17 @@ static const struct route_map_rule_cmd /* `match source-protocol PROTOCOL' */ static enum route_map_cmd_result_t -route_match_source_protocol(void *rule, const struct prefix *p, - route_map_object_t type, void *object) +route_match_source_protocol(void *rule, const struct prefix *p, void *object) { uint32_t *rib_type = (uint32_t *)rule; struct nh_rmap_obj *nh_data; - if (type == RMAP_ZEBRA) { - nh_data = (struct nh_rmap_obj *)object; - if (!nh_data) - return RMAP_NOMATCH; + nh_data = (struct nh_rmap_obj *)object; + if (!nh_data) + return RMAP_NOMATCH; - return ((nh_data->source_protocol == *rib_type) ? RMAP_MATCH - : RMAP_NOMATCH); - } - return RMAP_NOMATCH; + return ((nh_data->source_protocol == *rib_type) ? RMAP_MATCH + : RMAP_NOMATCH); } static void *route_match_source_protocol_compile(const char *arg) @@ -1399,15 +1364,11 @@ static const struct route_map_rule_cmd route_match_source_protocol_cmd = { /* `source-instance` */ static enum route_map_cmd_result_t -route_match_source_instance(void *rule, const struct prefix *p, - route_map_object_t type, void *object) +route_match_source_instance(void *rule, const struct prefix *p, void *object) { uint8_t *instance = (uint8_t *)rule; struct nh_rmap_obj *nh_data; - if (type != RMAP_ZEBRA) - return RMAP_NOMATCH; - nh_data = (struct nh_rmap_obj *)object; if (!nh_data) return RMAP_NOMATCH; @@ -1444,15 +1405,13 @@ static const struct route_map_rule_cmd route_match_source_instance_cmd = { /* Set src. */ static enum route_map_cmd_result_t -route_set_src(void *rule, const struct prefix *prefix, route_map_object_t type, - void *object) +route_set_src(void *rule, const struct prefix *prefix, void *object) { struct nh_rmap_obj *nh_data; - if (type == RMAP_ZEBRA) { - nh_data = (struct nh_rmap_obj *)object; - nh_data->nexthop->rmap_src = *(union g_addr *)rule; - } + nh_data = (struct nh_rmap_obj *)object; + nh_data->nexthop->rmap_src = *(union g_addr *)rule; + return RMAP_OKAY; } @@ -1738,7 +1697,7 @@ zebra_route_map_check(int family, int rib_type, uint8_t instance, if (!rmap && PROTO_RM_NAME(zvrf, family, ZEBRA_ROUTE_MAX)) rmap = PROTO_RM_MAP(zvrf, family, ZEBRA_ROUTE_MAX); if (rmap) { - ret = route_map_apply(rmap, p, RMAP_ZEBRA, &nh_obj); + ret = route_map_apply(rmap, p, &nh_obj); } return (ret); @@ -1782,7 +1741,7 @@ zebra_import_table_route_map_check(int family, int re_type, uint8_t instance, if (re_type >= 0 && re_type < ZEBRA_ROUTE_MAX) rmap = route_map_lookup_by_name(rmap_name); if (rmap) { - ret = route_map_apply(rmap, p, RMAP_ZEBRA, &nh_obj); + ret = route_map_apply(rmap, p, &nh_obj); } return (ret); @@ -1810,7 +1769,7 @@ route_map_result_t zebra_nht_route_map_check(afi_t afi, int client_proto, if (!rmap && NHT_RM_MAP(zvrf, afi, ZEBRA_ROUTE_MAX)) rmap = NHT_RM_MAP(zvrf, afi, ZEBRA_ROUTE_MAX); if (rmap) - ret = route_map_apply(rmap, p, RMAP_ZEBRA, &nh_obj); + ret = route_map_apply(rmap, p, &nh_obj); return ret; } |