]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: optimize apply_mask_ipv6()
authorDenis Ovsienko <infrastation@yandex.ru>
Tue, 18 Oct 2011 18:02:52 +0000 (22:02 +0400)
committerDenis Ovsienko <infrastation@yandex.ru>
Mon, 21 Nov 2011 14:32:33 +0000 (18:32 +0400)
lib/prefix.c

index 1ddbbbe7e8df4dde578202bf23de9466c6e96efd..c8fd0bd83d255f0abc6c1b1f93c70953d021baa0 100644 (file)
@@ -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