From: Denis Ovsienko Date: Sun, 1 Jan 2012 12:33:12 +0000 (+0400) Subject: Revert "lib: optimize apply_mask_ipv6()" X-Git-Tag: frr-2.0-rc1~1947 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=8c7f49d27767886b3706dfca11c1e13abeab7c63;p=matthieu%2Ffrr.git Revert "lib: optimize apply_mask_ipv6()" Experience with IPv4 counterpart of this function suggests, that this way of type-punning is likely to cause errors. --- diff --git a/lib/prefix.c b/lib/prefix.c index c8fd0bd83d..1ddbbbe7e8 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -660,13 +660,23 @@ masklen2ip6 (const int masklen, struct in6_addr *netmask) void apply_mask_ipv6 (struct prefix_ipv6 *p) { - assert (p->prefixlen >= 0 && p->prefixlen <= IPV6_MAX_BITLEN); - u_int32_t *addr_word = (u_int32_t *) &p->prefix; - u_int32_t *mask_word = (u_int32_t *) (maskbytes6 + p->prefixlen); - *addr_word++ &= *mask_word++; - *addr_word++ &= *mask_word++; - *addr_word++ &= *mask_word++; - *addr_word &= *mask_word; + u_char *pnt; + int index; + int offset; + + index = p->prefixlen / 8; + + if (index < 16) + { + pnt = (u_char *) &p->prefix; + offset = p->prefixlen % 8; + + pnt[index] &= maskbit[offset]; + index++; + + while (index < 16) + pnt[index++] = 0; + } } void