summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDenis Ovsienko <infrastation@yandex.ru>2011-10-18 18:33:53 +0400
committerDenis Ovsienko <infrastation@yandex.ru>2011-11-21 18:32:23 +0400
commited7a62efea6d957b0c5f60ec52644bba062f6c29 (patch)
treed1f026cfc0fd2c609eaa1cab40b668c031c3ed96 /lib
parent3062d2dab6e8bea9003d67a05d1e018a927d6f1d (diff)
lib: optimize apply_mask_ipv4()
Diffstat (limited to 'lib')
-rw-r--r--lib/prefix.c21
1 files changed, 3 insertions, 18 deletions
diff --git a/lib/prefix.c b/lib/prefix.c
index 075c9dab..1ddbbbe7 100644
--- a/lib/prefix.c
+++ b/lib/prefix.c
@@ -545,27 +545,12 @@ ip_masklen (struct in_addr netmask)
return len;
}
-/* Apply mask to IPv4 prefix. */
+/* Apply mask to IPv4 prefix (network byte order). */
void
apply_mask_ipv4 (struct prefix_ipv4 *p)
{
- u_char *pnt;
- int index;
- int offset;
-
- index = p->prefixlen / 8;
-
- if (index < 4)
- {
- pnt = (u_char *) &p->prefix;
- offset = p->prefixlen % 8;
-
- pnt[index] &= maskbit[offset];
- index++;
-
- while (index < 4)
- pnt[index++] = 0;
- }
+ assert (p->prefixlen >= 0 && p->prefixlen <= IPV4_MAX_BITLEN);
+ p->prefix.s_addr &= maskbytes_network[p->prefixlen];
}
/* If prefix is 0.0.0.0/0 then return 1 else return 0. */