From: Donald Sharp Date: Thu, 31 Aug 2017 19:58:31 +0000 (-0400) Subject: *: Cleanup multiple is_default... code X-Git-Tag: frr-4.0-dev~344^2~1 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=f229873a87c97721f198677920d162c7e299f1e3;p=mirror%2Ffrr.git *: Cleanup multiple is_default... code There are 3 different implementations of is_prefix. Standardize on is_prefix_default and fix it's implementation. Signed-off-by: Donald Sharp --- diff --git a/isisd/isis_redist.c b/isisd/isis_redist.c index ea94b65805..198cf35e68 100644 --- a/isisd/isis_redist.c +++ b/isisd/isis_redist.c @@ -64,17 +64,6 @@ static afi_t afi_for_redist_protocol(int protocol) return AFI_IP; } -static int is_default(struct prefix *p) -{ - if (p->family == AF_INET) - if (p->u.prefix4.s_addr == 0 && p->prefixlen == 0) - return 1; - if (p->family == AF_INET6) - if (IN6_IS_ADDR_UNSPECIFIED(&p->u.prefix6) && p->prefixlen == 0) - return 1; - return 0; -} - static struct route_table *get_ext_info(struct isis *i, int family) { int protocol = redist_protocol(family); @@ -286,7 +275,7 @@ void isis_redist_add(int type, struct prefix *p, u_char distance, info->distance = distance; info->metric = metric; - if (is_default(p)) + if (is_default_prefix(p)) type = DEFAULT_ROUTE; for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) @@ -316,7 +305,7 @@ void isis_redist_delete(int type, struct prefix *p) zlog_debug("%s: Removing route %s from %s.", __func__, debug_buf, zebra_route_string(type)); - if (is_default(p)) { + if (is_default_prefix(p)) { /* Don't remove default route but add synthetic route for use * by "default-information originate always". Areas without the * "always" setting will ignore routes with origin @@ -454,7 +443,7 @@ static void isis_redist_set(struct isis_area *area, int level, int family, info = rn->info; if (type == DEFAULT_ROUTE) { - if (!is_default(&rn->p)) + if (!is_default_prefix(&rn->p)) continue; } else { if (info->origin != type) @@ -490,7 +479,7 @@ static void isis_redist_unset(struct isis_area *area, int level, int family, info = rn->info; if (type == DEFAULT_ROUTE) { - if (!is_default(&rn->p)) + if (!is_default_prefix(&rn->p)) continue; } else { if (info->origin != type) diff --git a/lib/prefix.h b/lib/prefix.h index 823aed30c3..0732cf1290 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -379,15 +379,20 @@ static inline int ipv4_martian(struct in_addr *addr) return 0; } -static inline int is_default_prefix(struct prefix *p) +static inline int is_default_prefix(const struct prefix *p) { if (!p) return 0; - if (((p->family == AF_INET) && (p->u.prefix4.s_addr == INADDR_ANY)) - || ((p->family == AF_INET6) - && !memcmp(&p->u.prefix6, &in6addr_any, - sizeof(struct in6_addr)))) + if ((p->family == AF_INET) && + (p->u.prefix4.s_addr == INADDR_ANY) && + (p->prefixlen == 0)) + return 1; + + if ((p->family == AF_INET6) && + (p->prefixlen == 0) && + (!memcmp(&p->u.prefix6, &in6addr_any, + sizeof(struct in6_addr)))) return 1; return 0; diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 5d244db05a..9db879c181 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -63,20 +63,6 @@ int is_zebra_import_table_enabled(afi_t afi, u_int32_t table_id) return 0; } -int is_default(struct prefix *p) -{ - if (p->family == AF_INET) - if (p->u.prefix4.s_addr == 0 && p->prefixlen == 0) - return 1; -#if 0 /* IPv6 default separation is now pending until protocol daemon \ - can handle that. */ - if (p->family == AF_INET6) - if (IN6_IS_ADDR_UNSPECIFIED (&p->u.prefix6) && p->prefixlen == 0) - return 1; -#endif /* 0 */ - return 0; -} - static void zebra_redistribute_default(struct zserv *client, vrf_id_t vrf_id) { int afi; @@ -181,7 +167,7 @@ void redistribute_update(struct prefix *p, struct prefix *src_p, for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client)) { send_redistribute = 0; - if (is_default(p) + if (is_default_prefix(p) && vrf_bitmap_check(client->redist_default, re->vrf_id)) send_redistribute = 1; else if (vrf_bitmap_check(client->redist[afi][ZEBRA_ROUTE_ALL], @@ -240,7 +226,7 @@ void redistribute_delete(struct prefix *p, struct prefix *src_p, } for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client)) { - if ((is_default(p) + if ((is_default_prefix(p) && vrf_bitmap_check(client->redist_default, re->vrf_id)) || vrf_bitmap_check(client->redist[afi][ZEBRA_ROUTE_ALL], re->vrf_id) diff --git a/zebra/redistribute.h b/zebra/redistribute.h index 819b67918b..5edb06c3da 100644 --- a/zebra/redistribute.h +++ b/zebra/redistribute.h @@ -72,6 +72,4 @@ extern int zebra_import_table_config(struct vty *); extern void zebra_import_table_rm_update(void); -extern int is_default(struct prefix *); - #endif /* _ZEBRA_REDISTRIBUTE_H */