diff options
author | Denis Ovsienko <infrastation@yandex.ru> | 2011-10-18 22:02:52 +0400 |
---|---|---|
committer | Denis Ovsienko <infrastation@yandex.ru> | 2011-11-21 18:32:33 +0400 |
commit | c6cb2d9151fc14f9c2b1b7618695874cc8d97286 (patch) | |
tree | 1b515d8887ae4680f1463d60fd7d116da173660c /lib/prefix.c | |
parent | ed7a62efea6d957b0c5f60ec52644bba062f6c29 (diff) |
lib: optimize apply_mask_ipv6()
Diffstat (limited to 'lib/prefix.c')
-rw-r--r-- | lib/prefix.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/lib/prefix.c b/lib/prefix.c index 1ddbbbe7..c8fd0bd8 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -660,23 +660,13 @@ masklen2ip6 (const int masklen, struct in6_addr *netmask) void apply_mask_ipv6 (struct prefix_ipv6 *p) { - 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; - } + 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; } void |