X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=lib%2Fprefix.c;h=f5d40d8c0d75a97df386c915a3d757c3997f58d1;hb=450971aa994e68f7c62c4d45065223d5cfc4a22f;hp=ead5444fd0a3b558856d24d209b371d66cff477f;hpb=7348e571b7b0e2616726723bb624d3a15be5f40a;p=mirror_frr.git diff --git a/lib/prefix.c b/lib/prefix.c index ead5444fd..f5d40d8c0 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -27,6 +27,7 @@ #include "memory.h" #include "log.h" #include "jhash.h" +#include "lib_errors.h" DEFINE_MTYPE_STATIC(LIB, PREFIX, "Prefix") @@ -584,8 +585,8 @@ int prefix_match(const struct prefix *n, const struct prefix *p) } /* Set both prefix's head pointer. */ - np = (const uint8_t *)&n->u.prefix; - pp = (const uint8_t *)&p->u.prefix; + np = n->u.val; + pp = p->u.val; offset = n->prefixlen / PNBBY; shift = n->prefixlen % PNBBY; @@ -609,8 +610,8 @@ int prefix_match_network_statement(const struct prefix *n, const uint8_t *np, *pp; /* Set both prefix's head pointer. */ - np = (const uint8_t *)&n->u.prefix; - pp = (const uint8_t *)&p->u.prefix; + np = n->u.val; + pp = p->u.val; offset = n->prefixlen / PNBBY; shift = n->prefixlen % PNBBY; @@ -656,8 +657,9 @@ void prefix_copy(struct prefix *dest, const struct prefix *src) memcpy((void *)dest->u.prefix_flowspec.ptr, (void *)src->u.prefix_flowspec.ptr, len); } else { - zlog_err("prefix_copy(): Unknown address family %d", - src->family); + flog_err(EC_LIB_DEVELOPMENT, + "prefix_copy(): Unknown address family %d", + src->family); assert(0); } } @@ -742,8 +744,8 @@ int prefix_cmp(const struct prefix *p1, const struct prefix *p2) return 1; return 0; } - pp1 = (const uint8_t *)&p1->u.prefix; - pp2 = (const uint8_t *)&p2->u.prefix; + pp1 = p1->u.val; + pp2 = p2->u.val; if (p1->prefixlen != p2->prefixlen) return 1; @@ -774,8 +776,8 @@ int prefix_common_bits(const struct prefix *p1, const struct prefix *p2) uint8_t xor ; /* Set both prefix's head pointer. */ - const uint8_t *pp1 = (const uint8_t *)&p1->u.prefix; - const uint8_t *pp2 = (const uint8_t *)&p2->u.prefix; + const uint8_t *pp1 = p1->u.val; + const uint8_t *pp2 = p2->u.val; if (p1->family == AF_INET) length = IPV4_MAX_BYTELEN; @@ -1197,6 +1199,9 @@ int str2prefix(const char *str, struct prefix *p) { int ret; + if (!str || !p) + return 0; + /* First we try to convert string to struct prefix_ipv4. */ ret = str2prefix_ipv4(str, (struct prefix_ipv4 *)p); if (ret) @@ -1370,17 +1375,6 @@ void prefix_free(struct prefix *p) XFREE(MTYPE_PREFIX, p); } -/* Utility function. Check the string only contains digit - * character. - * FIXME str.[c|h] would be better place for this function. */ -int all_digit(const char *str) -{ - for (; *str != '\0'; str++) - if (!isdigit((int)*str)) - return 0; - return 1; -} - /* Utility function to convert ipv4 prefixes to Classful prefixes */ void apply_classful_mask_ipv4(struct prefix_ipv4 *p) {