]> git.puffer.fish Git - mirror/frr.git/commitdiff
*: Cleanup multiple is_default... code
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 31 Aug 2017 19:58:31 +0000 (15:58 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 31 Aug 2017 20:11:17 +0000 (16:11 -0400)
There are 3 different implementations of is_prefix.
Standardize on is_prefix_default and fix it's implementation.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
isisd/isis_redist.c
lib/prefix.h
zebra/redistribute.c
zebra/redistribute.h

index ea94b6580544b6550fa37edd90e727cb0eedf84c..198cf35e686a7e03de78165f257880cdbbe5ebce 100644 (file)
@@ -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)
index 823aed30c32f7650c8149be04824d2ee6a2eb6ee..0732cf12905a6489cf31d65093d711870d1b349f 100644 (file)
@@ -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;
index 5d244db05ac7a226e6d5f12e43074ed6f92a3eff..9db879c181bab3103015533e5c994ec8ca953269 100644 (file)
@@ -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)
index 819b67918b97624a1b82d0c41462adb1a6970851..5edb06c3da7d4e2c5f4d4dbb0d203ed99c3efa7a 100644 (file)
@@ -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 */